opensles: add the mute property and handle volume/mute changes on the fly

This commit is contained in:
Josep Torra 2012-09-20 18:41:50 +02:00 committed by Sebastian Dröge
parent f06688c7b2
commit 85bd75a2b1
5 changed files with 62 additions and 3 deletions

View file

@ -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)
{

View file

@ -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__ */

View file

@ -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;
}

View file

@ -41,6 +41,7 @@ struct _GstOpenSLESSink
GstBaseAudioSink sink;
gfloat volume;
gboolean mute;
};
struct _GstOpenSLESSinkClass

View file

@ -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",