From fc087f6419ef090427378e78331c50088503caab Mon Sep 17 00:00:00 2001 From: Josep Torra Date: Mon, 1 Oct 2012 10:59:08 +0200 Subject: [PATCH] opensles: initial attempt to reduce the src latency --- sys/opensles/openslesringbuffer.c | 24 ++++++++---------------- sys/opensles/openslessrc.c | 4 ++++ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/sys/opensles/openslesringbuffer.c b/sys/opensles/openslesringbuffer.c index ffbc3878cb..0eced53847 100644 --- a/sys/opensles/openslesringbuffer.c +++ b/sys/opensles/openslesringbuffer.c @@ -38,8 +38,6 @@ _do_init (GType type) GST_BOILERPLATE_FULL (GstOpenSLESRingBuffer, gst_opensles_ringbuffer, GstRingBuffer, GST_TYPE_RING_BUFFER, _do_init); -#define RECORDER_QUEUE_SIZE 2 - /* * Some generic helper functions */ @@ -125,7 +123,7 @@ _opensles_recorder_acquire (GstRingBuffer * rb, GstRingBufferSpec * spec) /* Configure audio sink */ SLDataLocator_AndroidSimpleBufferQueue loc_bq = { - SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, RECORDER_QUEUE_SIZE + SL_DATALOCATOR_ANDROIDSIMPLEBUFFERQUEUE, 2 }; SLDataSink audioSink = { &loc_bq, &format }; @@ -173,10 +171,6 @@ _opensles_recorder_acquire (GstRingBuffer * rb, GstRingBufferSpec * spec) 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; failed: @@ -198,6 +192,11 @@ _opensles_recorder_cb (SLAndroidSimpleBufferQueueItf bufferQueue, void *context) gint seg; 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 */ if (!gst_ring_buffer_prepare_read (rb, &seg, &ptr, &len)) { GST_WARNING_OBJECT (rb, "No segment available"); @@ -213,10 +212,6 @@ _opensles_recorder_cb (SLAndroidSimpleBufferQueueItf bufferQueue, void *context) (guint32) result); return; } - - /* FIXME: we advance here and behaviour might be racy with the reading - * thread */ - gst_ring_buffer_advance (rb, 1); } static gboolean @@ -224,7 +219,6 @@ _opensles_recorder_start (GstRingBuffer * rb) { GstOpenSLESRingBuffer *thiz = GST_OPENSLES_RING_BUFFER_CAST (rb); SLresult result; - gint i; /* Register callback on the buffer queue */ if (!thiz->is_queue_callback_registered) { @@ -238,10 +232,8 @@ _opensles_recorder_start (GstRingBuffer * rb) thiz->is_queue_callback_registered = TRUE; } - /* Preroll the buffer queue by enqueing segments */ - for (i = 0; i < RECORDER_QUEUE_SIZE; i++) { - _opensles_recorder_cb (NULL, rb); - } + /* Preroll one buffer */ + _opensles_recorder_cb (NULL, rb); /* Start recording */ result = diff --git a/sys/opensles/openslessrc.c b/sys/opensles/openslessrc.c index 3b920ed056..df697aba17 100644 --- a/sys/opensles/openslessrc.c +++ b/sys/opensles/openslessrc.c @@ -104,4 +104,8 @@ gst_opensles_src_class_init (GstOpenSLESSrcClass * klass) static void 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; }