[gst-cvs] gst-plugins-base: ringbuffer: Improve audiosink startup performance
Wim Taymans
wtay at kemper.freedesktop.org
Mon Aug 24 04:30:27 PDT 2009
Module: gst-plugins-base
Branch: master
Commit: 8ad8591e41cbff2eb3fb8c1008a84c1b7241912e
URL: http://cgit.freedesktop.org/gstreamer/gst-plugins-base/commit/?id=8ad8591e41cbff2eb3fb8c1008a84c1b7241912e
Author: Eero Nurkkala <ext-eero.nurkkala at nokia.com>
Date: Mon Aug 24 13:27:55 2009 +0200
ringbuffer: Improve audiosink startup performance
When we start the ringbuffer, immediatly continue processing samples if the
writer prepared some for us.
Fixes #545807
---
gst-libs/gst/audio/gstringbuffer.c | 27 +++++++++++++++++++--------
1 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/gst-libs/gst/audio/gstringbuffer.c b/gst-libs/gst/audio/gstringbuffer.c
index 92fa39e..971bd00 100644
--- a/gst-libs/gst/audio/gstringbuffer.c
+++ b/gst-libs/gst/audio/gstringbuffer.c
@@ -1399,6 +1399,9 @@ gst_ring_buffer_clear_all (GstRingBuffer * buf)
static gboolean
wait_segment (GstRingBuffer * buf)
{
+ gint segments;
+ gboolean wait = TRUE;
+
/* buffer must be started now or we deadlock since nobody is reading */
if (G_UNLIKELY (g_atomic_int_get (&buf->state) !=
GST_RING_BUFFER_STATE_STARTED)) {
@@ -1407,7 +1410,13 @@ wait_segment (GstRingBuffer * buf)
goto no_start;
GST_DEBUG_OBJECT (buf, "start!");
+ segments = g_atomic_int_get (&buf->segdone);
gst_ring_buffer_start (buf);
+
+ /* After starting, the writer may have wrote segments already and then we
+ * don't need to wait anymore */
+ if (G_LIKELY (g_atomic_int_get (&buf->segdone) != segments))
+ wait = FALSE;
}
/* take lock first, then update our waiting flag */
@@ -1419,16 +1428,18 @@ wait_segment (GstRingBuffer * buf)
GST_RING_BUFFER_STATE_STARTED))
goto not_started;
- if (g_atomic_int_compare_and_exchange (&buf->waiting, 0, 1)) {
- GST_DEBUG_OBJECT (buf, "waiting..");
- GST_RING_BUFFER_WAIT (buf);
+ if (G_LIKELY (wait)) {
+ if (g_atomic_int_compare_and_exchange (&buf->waiting, 0, 1)) {
+ GST_DEBUG_OBJECT (buf, "waiting..");
+ GST_RING_BUFFER_WAIT (buf);
- if (G_UNLIKELY (buf->abidata.ABI.flushing))
- goto flushing;
+ if (G_UNLIKELY (buf->abidata.ABI.flushing))
+ goto flushing;
- if (G_UNLIKELY (g_atomic_int_get (&buf->state) !=
- GST_RING_BUFFER_STATE_STARTED))
- goto not_started;
+ if (G_UNLIKELY (g_atomic_int_get (&buf->state) !=
+ GST_RING_BUFFER_STATE_STARTED))
+ goto not_started;
+ }
}
GST_OBJECT_UNLOCK (buf);
More information about the Gstreamer-commits
mailing list