diff options
author | Josep Torra <n770galaxy@gmail.com> | 2012-09-26 12:32:44 +0200 |
---|---|---|
committer | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2012-10-18 14:03:08 +0200 |
commit | b00049a9f60f7f8cf25a44031bc695f32f68b5fe (patch) | |
tree | 1c3f6aee9d3ae75808e0abfe3d617bec2ec676b4 /sys/opensles | |
parent | f00d5a5cace6af8b2ca02482b6d75f35f03089c9 (diff) | |
download | gstreamer-plugins-bad-b00049a9f60f7f8cf25a44031bc695f32f68b5fe.tar.gz |
opensles: rework on start/stop operations and callback function handling
Diffstat (limited to 'sys/opensles')
-rw-r--r-- | sys/opensles/openslesringbuffer.c | 83 |
1 files changed, 54 insertions, 29 deletions
diff --git a/sys/opensles/openslesringbuffer.c b/sys/opensles/openslesringbuffer.c index e716261bc..e6d55e2fe 100644 --- a/sys/opensles/openslesringbuffer.c +++ b/sys/opensles/openslesringbuffer.c @@ -198,15 +198,6 @@ _opensles_recorder_acquire (GstRingBuffer * rb, GstRingBufferSpec * spec) goto failed; } - /* Register callback on the buffer queue */ - result = (*thiz->bufferQueue)->RegisterCallback (thiz->bufferQueue, - _opensles_enqueue_cb, rb); - if (result != SL_RESULT_SUCCESS) { - GST_ERROR_OBJECT (thiz, "bufferQueue.RegisterCallback failed(0x%08x)", - (guint32) result); - goto failed; - } - /* Define our ringbuffer in terms of number of buffers and buffer size. */ spec->segsize = (spec->rate * spec->bytes_per_sample) >> 2; spec->segtotal = 16; @@ -224,27 +215,21 @@ _opensles_recorder_start (GstRingBuffer * rb) SLresult result; gint i; - /* in case already recording, stop recording and clear buffer queue */ - result = - (*thiz->recorderRecord)->SetRecordState (thiz->recorderRecord, - SL_RECORDSTATE_STOPPED); + /* Register callback on the buffer queue */ + result = (*thiz->bufferQueue)->RegisterCallback (thiz->bufferQueue, + _opensles_enqueue_cb, rb); if (result != SL_RESULT_SUCCESS) { - GST_ERROR_OBJECT (thiz, "recorder.SetRecordState failed(0x%08x)", + GST_ERROR_OBJECT (thiz, "bufferQueue.RegisterCallback failed(0x%08x)", (guint32) result); return FALSE; } - result = (*thiz->bufferQueue)->Clear (thiz->bufferQueue); - if (result != SL_RESULT_SUCCESS) { - GST_ERROR_OBJECT (thiz, "bq.Clear failed(0x%08x)", (guint32) result); - return FALSE; - } /* Fill the queue by enqueing buffers */ for (i = 0; i < RECORDER_QUEUE_SIZE; i++) { _opensles_enqueue_cb (NULL, rb); } - /* start recording */ + /* Start recording */ result = (*thiz->recorderRecord)->SetRecordState (thiz->recorderRecord, SL_RECORDSTATE_RECORDING); @@ -262,6 +247,7 @@ _opensles_recorder_stop (GstRingBuffer * rb) GstOpenSLESRingBuffer *thiz = GST_OPENSLES_RING_BUFFER_CAST (rb); SLresult result; + /* Stop recording */ result = (*thiz->recorderRecord)->SetRecordState (thiz->recorderRecord, SL_RECORDSTATE_STOPPED); @@ -270,6 +256,24 @@ _opensles_recorder_stop (GstRingBuffer * rb) (guint32) result); return FALSE; } + + /* Unregister callback on the buffer queue */ + result = (*thiz->bufferQueue)->RegisterCallback (thiz->bufferQueue, + NULL, NULL); + if (result != SL_RESULT_SUCCESS) { + GST_ERROR_OBJECT (thiz, "bufferQueue.RegisterCallback failed(0x%08x)", + (guint32) result); + return FALSE; + } + + /* Reset the queue */ + result = (*thiz->bufferQueue)->Clear (thiz->bufferQueue); + if (result != SL_RESULT_SUCCESS) { + GST_ERROR_OBJECT (thiz, "bufferQueue.Clear failed(0x%08x)", + (guint32) result); + return FALSE; + } + return TRUE; } @@ -379,15 +383,6 @@ _opensles_player_acquire (GstRingBuffer * rb, GstRingBufferSpec * spec) goto failed; } - /* Register callback on the buffer queue */ - result = (*thiz->bufferQueue)->RegisterCallback (thiz->bufferQueue, - _opensles_enqueue_cb, rb); - if (result != SL_RESULT_SUCCESS) { - GST_ERROR_OBJECT (thiz, "bufferQueue.RegisterCallback failed(0x%08x)", - (guint32) result); - goto failed; - } - /* Get the volume interface */ result = (*thiz->playerObject)->GetInterface (thiz->playerObject, SL_IID_VOLUME, &thiz->playerVolume); @@ -418,11 +413,21 @@ _opensles_player_start (GstRingBuffer * rb) SLresult result; gint i; + /* Register callback on the buffer queue */ + result = (*thiz->bufferQueue)->RegisterCallback (thiz->bufferQueue, + _opensles_enqueue_cb, rb); + if (result != SL_RESULT_SUCCESS) { + GST_ERROR_OBJECT (thiz, "bufferQueue.RegisterCallback failed(0x%08x)", + (guint32) result); + return FALSE; + } + /* Fill the queue by enqueing buffers */ for (i = 0; i < PLAYER_QUEUE_SIZE; i++) { _opensles_enqueue_cb (NULL, rb); } + /* Change player state into PLAYING */ result = (*thiz->playerPlay)->SetPlayState (thiz->playerPlay, SL_PLAYSTATE_PLAYING); @@ -457,14 +462,34 @@ _opensles_player_stop (GstRingBuffer * rb) GstOpenSLESRingBuffer *thiz = GST_OPENSLES_RING_BUFFER_CAST (rb); SLresult result; + /* Change player state into STOPPED */ result = (*thiz->playerPlay)->SetPlayState (thiz->playerPlay, SL_PLAYSTATE_STOPPED); + if (result != SL_RESULT_SUCCESS) { GST_ERROR_OBJECT (thiz, "player.SetPlayState failed(0x%08x)", (guint32) result); return FALSE; } + + /* Unregister callback on the buffer queue */ + result = (*thiz->bufferQueue)->RegisterCallback (thiz->bufferQueue, + NULL, NULL); + if (result != SL_RESULT_SUCCESS) { + GST_ERROR_OBJECT (thiz, "bufferQueue.RegisterCallback failed(0x%08x)", + (guint32) result); + return FALSE; + } + + /* Reset the queue */ + result = (*thiz->bufferQueue)->Clear (thiz->bufferQueue); + if (result != SL_RESULT_SUCCESS) { + GST_ERROR_OBJECT (thiz, "bufferQueue.Clear failed(0x%08x)", + (guint32) result); + return FALSE; + } + return TRUE; } |