opensles: initial attempt to reduce the src latency

This commit is contained in:
Josep Torra 2012-10-01 10:59:08 +02:00 committed by Sebastian Dröge
parent 920354eb0d
commit fc087f6419
2 changed files with 12 additions and 16 deletions

View file

@ -38,8 +38,6 @@ _do_init (GType type)
GST_BOILERPLATE_FULL (GstOpenSLESRingBuffer, gst_opensles_ringbuffer, GST_BOILERPLATE_FULL (GstOpenSLESRingBuffer, gst_opensles_ringbuffer,
GstRingBuffer, GST_TYPE_RING_BUFFER, _do_init); GstRingBuffer, GST_TYPE_RING_BUFFER, _do_init);
#define RECORDER_QUEUE_SIZE 2
/* /*
* Some generic helper functions * Some generic helper functions
*/ */
@ -125,7 +123,7 @@ _opensles_recorder_acquire (GstRingBuffer * rb, GstRingBufferSpec * spec)
/* Configure audio sink */ /* Configure audio sink */
SLDataLocator_AndroidSimpleBufferQueue loc_bq = { SLDataLocator_AndroidSimpleBufferQueue loc_bq = {
SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, RECORDER_QUEUE_SIZE SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2
}; };
SLDataSink audioSink = { &loc_bq, &format }; SLDataSink audioSink = { &loc_bq, &format };
@ -173,10 +171,6 @@ _opensles_recorder_acquire (GstRingBuffer * rb, GstRingBufferSpec * spec)
goto failed; 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;
return TRUE; return TRUE;
failed: failed:
@ -198,6 +192,11 @@ _opensles_recorder_cb (SLAndroidSimpleBufferQueueItf bufferQueue, void *context)
gint seg; gint seg;
gint len; gint len;
/* Advance only when we are called by the callback function */
if (bufferQueue) {
gst_ring_buffer_advance (rb, 1);
}
/* Get a segment form the GStreamer ringbuffer to write in */ /* Get a segment form the GStreamer ringbuffer to write in */
if (!gst_ring_buffer_prepare_read (rb, &seg, &ptr, &len)) { if (!gst_ring_buffer_prepare_read (rb, &seg, &ptr, &len)) {
GST_WARNING_OBJECT (rb, "No segment available"); GST_WARNING_OBJECT (rb, "No segment available");
@ -213,10 +212,6 @@ _opensles_recorder_cb (SLAndroidSimpleBufferQueueItf bufferQueue, void *context)
(guint32) result); (guint32) result);
return; return;
} }
/* FIXME: we advance here and behaviour might be racy with the reading
* thread */
gst_ring_buffer_advance (rb, 1);
} }
static gboolean static gboolean
@ -224,7 +219,6 @@ _opensles_recorder_start (GstRingBuffer * rb)
{ {
GstOpenSLESRingBuffer *thiz = GST_OPENSLES_RING_BUFFER_CAST (rb); GstOpenSLESRingBuffer *thiz = GST_OPENSLES_RING_BUFFER_CAST (rb);
SLresult result; SLresult result;
gint i;
/* Register callback on the buffer queue */ /* Register callback on the buffer queue */
if (!thiz->is_queue_callback_registered) { if (!thiz->is_queue_callback_registered) {
@ -238,10 +232,8 @@ _opensles_recorder_start (GstRingBuffer * rb)
thiz->is_queue_callback_registered = TRUE; thiz->is_queue_callback_registered = TRUE;
} }
/* Preroll the buffer queue by enqueing segments */ /* Preroll one buffer */
for (i = 0; i < RECORDER_QUEUE_SIZE; i++) { _opensles_recorder_cb (NULL, rb);
_opensles_recorder_cb (NULL, rb);
}
/* Start recording */ /* Start recording */
result = result =

View file

@ -104,4 +104,8 @@ gst_opensles_src_class_init (GstOpenSLESSrcClass * klass)
static void static void
gst_opensles_src_init (GstOpenSLESSrc * src, GstOpenSLESSrcClass * gclass) gst_opensles_src_init (GstOpenSLESSrc * src, GstOpenSLESSrcClass * gclass)
{ {
/* Override some default values to fit on the AudioFlinger behaviour of
* processing 20ms buffers as minimum buffer size. */
GST_BASE_AUDIO_SRC (src)->buffer_time = 400000;
GST_BASE_AUDIO_SRC (src)->latency_time = 20000;
} }