From 8601862e27584ded9b459feb1fbaf9cf1ad77b78 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Mon, 29 Jun 2009 15:14:07 +0200 Subject: [PATCH] ringbuffer: add vmethod to clear the ringbuffer Add a vmethod so that subclasses can be notified when they should clear the data in the ringbuffer. --- gst-libs/gst/audio/gstringbuffer.c | 34 ++++++++++++++++++++++++---------- gst-libs/gst/audio/gstringbuffer.h | 5 ++++- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/gst-libs/gst/audio/gstringbuffer.c b/gst-libs/gst/audio/gstringbuffer.c index 920a2be..ed1d7ae 100644 --- a/gst-libs/gst/audio/gstringbuffer.c +++ b/gst-libs/gst/audio/gstringbuffer.c @@ -52,6 +52,7 @@ static void gst_ring_buffer_dispose (GObject * object); static void gst_ring_buffer_finalize (GObject * object); static gboolean gst_ring_buffer_pause_unlocked (GstRingBuffer * buf); +static void default_clear_all (GstRingBuffer * buf); static guint default_commit (GstRingBuffer * buf, guint64 * sample, guchar * data, gint in_samples, gint out_samples, gint * accum); @@ -102,6 +103,7 @@ gst_ring_buffer_class_init (GstRingBufferClass * klass) gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_ring_buffer_dispose); gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_ring_buffer_finalize); + gstringbuffer_class->clear_all = GST_DEBUG_FUNCPTR (default_clear_all); gstringbuffer_class->commit = GST_DEBUG_FUNCPTR (default_commit); } @@ -1014,9 +1016,10 @@ gst_ring_buffer_set_flushing (GstRingBuffer * buf, gboolean flushing) GST_OBJECT_LOCK (buf); buf->abidata.ABI.flushing = flushing; - gst_ring_buffer_clear_all (buf); if (flushing) { gst_ring_buffer_pause_unlocked (buf); + } else { + gst_ring_buffer_clear_all (buf); } GST_OBJECT_UNLOCK (buf); } @@ -1357,6 +1360,22 @@ gst_ring_buffer_set_sample (GstRingBuffer * buf, guint64 sample) buf->segbase); } +static void +default_clear_all (GstRingBuffer * buf) +{ + gint i; + + /* not fatal, we just are not negotiated yet */ + if (G_UNLIKELY (buf->spec.segtotal <= 0)) + return; + + GST_DEBUG_OBJECT (buf, "clear all segments"); + + for (i = 0; i < buf->spec.segtotal; i++) { + gst_ring_buffer_clear (buf, i); + } +} + /** * gst_ring_buffer_clear_all: * @buf: the #GstRingBuffer to clear @@ -1368,19 +1387,14 @@ gst_ring_buffer_set_sample (GstRingBuffer * buf, guint64 sample) void gst_ring_buffer_clear_all (GstRingBuffer * buf) { - gint i; + GstRingBufferClass *rclass; g_return_if_fail (GST_IS_RING_BUFFER (buf)); - /* not fatal, we just are not negotiated yet */ - if (G_UNLIKELY (buf->spec.segtotal <= 0)) - return; - - GST_DEBUG_OBJECT (buf, "clear all segments"); + rclass = GST_RING_BUFFER_GET_CLASS (buf); - for (i = 0; i < buf->spec.segtotal; i++) { - gst_ring_buffer_clear (buf, i); - } + if (G_LIKELY (rclass->clear_all)) + rclass->clear_all (buf); } diff --git a/gst-libs/gst/audio/gstringbuffer.h b/gst-libs/gst/audio/gstringbuffer.h index 6bfda21..aced65c 100644 --- a/gst-libs/gst/audio/gstringbuffer.h +++ b/gst-libs/gst/audio/gstringbuffer.h @@ -301,6 +301,7 @@ struct _GstRingBuffer { * @activate: activate the thread that starts pulling and monitoring the * consumed segments in the device. Since 0.10.22 * @commit: write samples into the ringbuffer + * @clear_all: clear the entire ringbuffer Since 0.10.24 * * The vmethods that subclasses can override to implement the ringbuffer. */ @@ -327,8 +328,10 @@ struct _GstRingBufferClass { guchar * data, gint in_samples, gint out_samples, gint * accum); + void (*clear_all) (GstRingBuffer * buf); + /*< private >*/ - gpointer _gst_reserved[GST_PADDING - 2]; + gpointer _gst_reserved[GST_PADDING - 3]; }; GType gst_ring_buffer_get_type(void); -- 2.7.4