Add stream volume control using sio_setvol and sio_onvol.
Most gstreamer applications will pick this up rather than doing volume control inside the pipeline, meaning much lower latency on volume changes. with help and encouragement from ajacoutot@ and ratchov@
This commit is contained in:
parent
f122666ec3
commit
5d463b63e4
@ -1,7 +1,9 @@
|
||||
# $OpenBSD: Makefile,v 1.30 2014/10/07 16:05:11 ajacoutot Exp $
|
||||
# $OpenBSD: Makefile,v 1.31 2014/11/02 21:18:27 jmatthew Exp $
|
||||
|
||||
COMMENT= base elements for GStreamer
|
||||
|
||||
REVISION= 1
|
||||
|
||||
DISTNAME= gst-plugins-base-${V}
|
||||
PKGNAME= ${GST_PKGNAME_PREFIX}-plugins-base-${V}
|
||||
|
||||
|
@ -88,6 +88,15 @@ gst_sndio_getcaps (struct gstsndio *sio, GstCaps * filter)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gst_sndio_onvol (void *arg, unsigned int vol)
|
||||
{
|
||||
struct gstsndio *sio = arg;
|
||||
sio->volume = vol;
|
||||
g_object_notify (G_OBJECT (sio->obj), "mute");
|
||||
g_object_notify (G_OBJECT (sio->obj), "volume");
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_sndio_open (struct gstsndio *sio, gint mode)
|
||||
{
|
||||
@ -123,6 +132,7 @@ gst_sndio_open (struct gstsndio *sio, gint mode)
|
||||
sio->hdl = NULL;
|
||||
return FALSE;
|
||||
}
|
||||
sio_onvol (sio->hdl, gst_sndio_onvol, sio);
|
||||
|
||||
caps = gst_caps_new_empty ();
|
||||
s = gst_structure_new ("audio/x-raw", (char *)NULL, (void *)NULL);
|
||||
@ -359,6 +369,13 @@ gst_sndio_set_property (struct gstsndio *sio, guint prop_id,
|
||||
g_free (sio->device);
|
||||
sio->device = g_value_dup_string (value);
|
||||
break;
|
||||
case PROP_VOLUME:
|
||||
sio_setvol (sio->hdl, g_value_get_double (value) * SIO_MAXVOL);
|
||||
break;
|
||||
case PROP_MUTE:
|
||||
if (g_value_get_boolean (value))
|
||||
sio_setvol (sio->hdl, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -372,6 +389,12 @@ gst_sndio_get_property (struct gstsndio *sio, guint prop_id,
|
||||
case PROP_DEVICE:
|
||||
g_value_set_string (value, sio->device);
|
||||
break;
|
||||
case PROP_VOLUME:
|
||||
g_value_set_double (value, (gdouble)sio->volume / SIO_MAXVOL);
|
||||
break;
|
||||
case PROP_MUTE:
|
||||
g_value_set_boolean (value, (sio->volume == 0));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (sio->obj, prop_id, pspec);
|
||||
}
|
||||
|
@ -20,11 +20,14 @@
|
||||
#include <gst/gst.h>
|
||||
#include <gst/audio/gstaudiosink.h>
|
||||
#include <gst/audio/gstaudiosrc.h>
|
||||
#include <gst/audio/streamvolume.h>
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_DEVICE
|
||||
PROP_DEVICE,
|
||||
PROP_VOLUME,
|
||||
PROP_MUTE
|
||||
};
|
||||
|
||||
#define GST_SNDIO_CAPS_STRING \
|
||||
@ -49,6 +52,7 @@ struct gstsndio {
|
||||
gint mode;
|
||||
gint bpf; /* bytes per frame */
|
||||
gint delay; /* bytes stored in the audio fifo */
|
||||
guint volume; /* volume level */
|
||||
GstCaps *cur_caps; /* saved capabilities of opened device */
|
||||
GObject *obj; /* for logging */
|
||||
};
|
||||
|
@ -49,7 +49,8 @@ static GstStaticPadTemplate sndiosink_factory =
|
||||
GST_STATIC_CAPS (GST_SNDIO_CAPS_STRING)
|
||||
);
|
||||
|
||||
G_DEFINE_TYPE (GstSndioSink, gst_sndiosink, GST_TYPE_AUDIO_SINK);
|
||||
G_DEFINE_TYPE_WITH_CODE (GstSndioSink, gst_sndiosink, GST_TYPE_AUDIO_SINK,
|
||||
G_IMPLEMENT_INTERFACE (GST_TYPE_STREAM_VOLUME, NULL));
|
||||
|
||||
static void gst_sndiosink_finalize (GObject * object);
|
||||
static GstCaps *gst_sndiosink_getcaps (GstBaseSink * bsink,
|
||||
@ -214,4 +215,12 @@ gst_sndiosink_class_init (GstSndioSinkClass * klass)
|
||||
g_param_spec_string ("device", "Device",
|
||||
"sndio device as defined in sndio(7)",
|
||||
SIO_DEVANY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property (gobject_class, PROP_VOLUME,
|
||||
g_param_spec_double ("volume", "Volume",
|
||||
"Linear volume of this stream, 1.0=100%", 0.0, 1.0,
|
||||
1.0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property (gobject_class, PROP_MUTE,
|
||||
g_param_spec_boolean ("mute", "Mute",
|
||||
"Mute state of this stream", FALSE,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
@ -43,7 +43,8 @@ GST_DEBUG_CATEGORY_EXTERN (gst_sndio_debug);
|
||||
#define GST_CAT_DEFAULT gst_sndio_debug
|
||||
|
||||
#define gst_sndiosrc_parent_class parent_class
|
||||
G_DEFINE_TYPE (GstSndioSrc, gst_sndiosrc, GST_TYPE_AUDIO_SRC);
|
||||
G_DEFINE_TYPE_WITH_CODE (GstSndioSrc, gst_sndiosrc, GST_TYPE_AUDIO_SRC,
|
||||
G_IMPLEMENT_INTERFACE (GST_TYPE_STREAM_VOLUME, NULL));
|
||||
|
||||
static void gst_sndiosrc_finalize (GObject * object);
|
||||
static GstCaps *gst_sndiosrc_getcaps (GstBaseSrc * bsrc, GstCaps * filter);
|
||||
@ -213,4 +214,12 @@ gst_sndiosrc_class_init (GstSndioSrcClass * klass)
|
||||
g_param_spec_string ("device", "Device",
|
||||
"sndio device as defined in sndio(7)",
|
||||
SIO_DEVANY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property (gobject_class, PROP_VOLUME,
|
||||
g_param_spec_double ("volume", "Volume",
|
||||
"Linear volume of this stream, 1.0=100%", 0.0, 1.0,
|
||||
1.0, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
g_object_class_install_property (gobject_class, PROP_MUTE,
|
||||
g_param_spec_boolean ("mute", "Mute",
|
||||
"Mute state of this stream", FALSE,
|
||||
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user