opensles: make the volume property actually work

This commit is contained in:
Josep Torra 2012-09-20 18:04:29 +02:00 committed by Sebastian Dröge
parent 0291953997
commit f06688c7b2
4 changed files with 48 additions and 2 deletions

View file

@ -299,6 +299,29 @@ _opensles_player_cb (SLAndroidSimpleBufferQueueItf bufferQueue, void *context)
gst_ring_buffer_advance (rb, 1);
}
static gboolean
_opensles_player_change_volume (GstRingBuffer * rb)
{
GstOpenSLESRingBuffer *thiz;
SLresult result;
thiz = GST_OPENSLES_RING_BUFFER_CAST (rb);
if (thiz->playerVolume) {
gint millibel = (1.0 - thiz->volume) * -5000.0;
result =
(*thiz->playerVolume)->SetVolumeLevel (thiz->playerVolume, millibel);
if (result != SL_RESULT_SUCCESS) {
GST_ERROR_OBJECT (thiz, "player.SetVolumeLevel failed(0x%08x)",
(guint32) result);
return FALSE;
}
GST_DEBUG_OBJECT (thiz, "changed volume to %d", millibel);
}
return TRUE;
}
static gboolean
_opensles_player_acquire (GstRingBuffer * rb, GstRingBufferSpec * spec)
{
@ -375,6 +398,9 @@ _opensles_player_acquire (GstRingBuffer * rb, GstRingBufferSpec * spec)
goto failed;
}
/* Configure the volume state */
_opensles_player_change_volume (rb);
/* Define our ringbuffer in terms of number of buffers and buffer size. */
spec->segsize = (spec->rate * spec->bytes_per_sample);
spec->segtotal = 4;
@ -462,11 +488,13 @@ gst_opensles_ringbuffer_new (RingBufferMode mode)
thiz->start = _opensles_recorder_start;
thiz->pause = _opensles_recorder_stop;
thiz->stop = _opensles_recorder_stop;
thiz->change_volume = NULL;
} else if (mode == RB_MODE_SINK_PCM) {
thiz->acquire = _opensles_player_acquire;
thiz->start = _opensles_player_start;
thiz->pause = _opensles_player_pause;
thiz->stop = _opensles_player_stop;
thiz->change_volume = _opensles_player_change_volume;
}
}
@ -474,6 +502,20 @@ gst_opensles_ringbuffer_new (RingBufferMode mode)
return GST_RING_BUFFER (thiz);
}
void
gst_opensles_ringbuffer_set_volume (GstRingBuffer * rb, gfloat volume)
{
GstOpenSLESRingBuffer *thiz;
thiz = GST_OPENSLES_RING_BUFFER_CAST (rb);
thiz->volume = volume;
if (thiz->change_volume) {
thiz->change_volume (rb);
}
}
static gboolean
gst_opensles_ringbuffer_open_device (GstRingBuffer * rb)
{

View file

@ -75,6 +75,7 @@ struct _GstOpenSLESRingBuffer
SLObjectItf playerObject;
SLPlayItf playerPlay;
SLVolumeItf playerVolume;
gfloat volume;
/* recorder interfaces */
SLObjectItf recorderObject;
@ -89,6 +90,7 @@ struct _GstOpenSLESRingBuffer
StateFunc start;
StateFunc pause;
StateFunc stop;
StateFunc change_volume;
};
struct _GstOpenSLESRingBufferClass
@ -98,6 +100,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);
G_END_DECLS
#endif /* __OPENSLESRINGBUFFER_H__ */

View file

@ -81,10 +81,11 @@ gst_opensles_sink_base_init (gpointer g_class)
static GstRingBuffer *
gst_opensles_sink_create_ringbuffer (GstBaseAudioSink * base)
{
GstOpenSLESSink *sink = GST_OPENSLES_SINK (base);
GstRingBuffer *rb;
rb = gst_opensles_ringbuffer_new (RB_MODE_SINK_PCM);
gst_opensles_ringbuffer_set_volume (rb, sink->volume);
return rb;
}

View file

@ -40,7 +40,7 @@ struct _GstOpenSLESSink
{
GstBaseAudioSink sink;
double volume;
gfloat volume;
};
struct _GstOpenSLESSinkClass