From 85bd75a2b1f252f778958a4d87acfe0b74751efa Mon Sep 17 00:00:00 2001 From: Josep Torra Date: Thu, 20 Sep 2012 18:41:50 +0200 Subject: [PATCH] opensles: add the mute property and handle volume/mute changes on the fly --- sys/opensles/openslesringbuffer.c | 38 ++++++++++++++++++++++++++++++- sys/opensles/openslesringbuffer.h | 3 +++ sys/opensles/openslessink.c | 21 +++++++++++++++++ sys/opensles/openslessink.h | 1 + sys/opensles/openslessrc.c | 2 -- 5 files changed, 62 insertions(+), 3 deletions(-) diff --git a/sys/opensles/openslesringbuffer.c b/sys/opensles/openslesringbuffer.c index e8d7e822aa5..c1738421618 100644 --- a/sys/opensles/openslesringbuffer.c +++ b/sys/opensles/openslesringbuffer.c @@ -322,6 +322,27 @@ _opensles_player_change_volume (GstRingBuffer * rb) return TRUE; } +static gboolean +_opensles_player_change_mute (GstRingBuffer * rb) +{ + GstOpenSLESRingBuffer *thiz; + SLresult result; + + thiz = GST_OPENSLES_RING_BUFFER_CAST (rb); + + if (thiz->playerVolume) { + result = (*thiz->playerVolume)->SetMute (thiz->playerVolume, thiz->mute); + if (result != SL_RESULT_SUCCESS) { + GST_ERROR_OBJECT (thiz, "player.SetMute failed(0x%08x)", + (guint32) result); + return FALSE; + } + GST_DEBUG_OBJECT (thiz, "changed mute to %d", thiz->mute); + } + + return TRUE; +} + static gboolean _opensles_player_acquire (GstRingBuffer * rb, GstRingBufferSpec * spec) { @@ -398,8 +419,9 @@ _opensles_player_acquire (GstRingBuffer * rb, GstRingBufferSpec * spec) goto failed; } - /* Configure the volume state */ + /* Configure the volume and mute state */ _opensles_player_change_volume (rb); + _opensles_player_change_mute (rb); /* Define our ringbuffer in terms of number of buffers and buffer size. */ spec->segsize = (spec->rate * spec->bytes_per_sample); @@ -516,6 +538,20 @@ gst_opensles_ringbuffer_set_volume (GstRingBuffer * rb, gfloat volume) } } +void +gst_opensles_ringbuffer_set_mute (GstRingBuffer * rb, gboolean mute) +{ + GstOpenSLESRingBuffer *thiz; + + thiz = GST_OPENSLES_RING_BUFFER_CAST (rb); + + thiz->mute = mute; + + if (thiz->change_mute) { + thiz->change_mute (rb); + } +} + static gboolean gst_opensles_ringbuffer_open_device (GstRingBuffer * rb) { diff --git a/sys/opensles/openslesringbuffer.h b/sys/opensles/openslesringbuffer.h index 822929d7977..ac126aedaf3 100644 --- a/sys/opensles/openslesringbuffer.h +++ b/sys/opensles/openslesringbuffer.h @@ -76,6 +76,7 @@ struct _GstOpenSLESRingBuffer SLPlayItf playerPlay; SLVolumeItf playerVolume; gfloat volume; + gboolean mute; /* recorder interfaces */ SLObjectItf recorderObject; @@ -91,6 +92,7 @@ struct _GstOpenSLESRingBuffer StateFunc pause; StateFunc stop; StateFunc change_volume; + StateFunc change_mute; }; struct _GstOpenSLESRingBufferClass @@ -101,6 +103,7 @@ struct _GstOpenSLESRingBufferClass GType gst_opensles_ringbuffer_get_type (void); GstRingBuffer *gst_opensles_ringbuffer_new (RingBufferMode mode); void gst_opensles_ringbuffer_set_volume (GstRingBuffer * rb, gfloat volume); +void gst_opensles_ringbuffer_set_mute (GstRingBuffer * rb, gboolean mute); G_END_DECLS #endif /* __OPENSLESRINGBUFFER_H__ */ diff --git a/sys/opensles/openslessink.c b/sys/opensles/openslessink.c index 364e94431fc..0368c374a0c 100644 --- a/sys/opensles/openslessink.c +++ b/sys/opensles/openslessink.c @@ -30,10 +30,12 @@ enum { PROP_0, PROP_VOLUME, + PROP_MUTE, PROP_LAST }; #define DEFAULT_VOLUME 1.0 +#define DEFAULT_MUTE FALSE #define RATES "8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 64000, 88200, 96000, 192000" @@ -86,6 +88,7 @@ gst_opensles_sink_create_ringbuffer (GstBaseAudioSink * base) rb = gst_opensles_ringbuffer_new (RB_MODE_SINK_PCM); gst_opensles_ringbuffer_set_volume (rb, sink->volume); + gst_opensles_ringbuffer_set_mute (rb, sink->mute); return rb; } @@ -94,10 +97,20 @@ gst_opensles_sink_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { GstOpenSLESSink *sink = GST_OPENSLES_SINK (object); + GstRingBuffer *rb = GST_BASE_AUDIO_SINK (sink)->ringbuffer; switch (prop_id) { case PROP_VOLUME: sink->volume = g_value_get_double (value); + if (rb && GST_IS_OPENSLES_RING_BUFFER (rb)) { + gst_opensles_ringbuffer_set_volume (rb, sink->volume); + } + break; + case PROP_MUTE: + sink->mute = g_value_get_boolean (value); + if (rb && GST_IS_OPENSLES_RING_BUFFER (rb)) { + gst_opensles_ringbuffer_set_mute (rb, sink->mute); + } break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); @@ -114,6 +127,9 @@ gst_opensles_sink_get_property (GObject * object, guint prop_id, case PROP_VOLUME: g_value_set_double (value, sink->volume); break; + case PROP_MUTE: + g_value_set_boolean (value, sink->mute); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; @@ -138,6 +154,10 @@ gst_opensles_sink_class_init (GstOpenSLESSinkClass * klass) g_param_spec_double ("volume", "Volume", "Volume of this stream", 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", + DEFAULT_MUTE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + gstbaseaudiosink_class->create_ringbuffer = GST_DEBUG_FUNCPTR (gst_opensles_sink_create_ringbuffer); } @@ -146,4 +166,5 @@ static void gst_opensles_sink_init (GstOpenSLESSink * sink, GstOpenSLESSinkClass * gclass) { sink->volume = DEFAULT_VOLUME; + sink->mute = DEFAULT_MUTE; } diff --git a/sys/opensles/openslessink.h b/sys/opensles/openslessink.h index 4b3494a2377..da9e6064bff 100644 --- a/sys/opensles/openslessink.h +++ b/sys/opensles/openslessink.h @@ -41,6 +41,7 @@ struct _GstOpenSLESSink GstBaseAudioSink sink; gfloat volume; + gboolean mute; }; struct _GstOpenSLESSinkClass diff --git a/sys/opensles/openslessrc.c b/sys/opensles/openslessrc.c index 95f97276669..6de93561479 100644 --- a/sys/opensles/openslessrc.c +++ b/sys/opensles/openslessrc.c @@ -26,8 +26,6 @@ GST_DEBUG_CATEGORY_STATIC (opensles_src_debug); #define GST_CAT_DEFAULT opensles_src_debug -#define DEFAULT_VOLUME 1.0 - #define RATES "8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, 64000, 88200, 96000, 192000" static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",