From e846919fe91c76734e67a4fcaefecb21922af899 Mon Sep 17 00:00:00 2001 From: Edgard Lima Date: Thu, 6 Oct 2005 15:15:04 +0000 Subject: [PATCH] gst-libs/gst/audio/: Fixed gstbaseaudiosrc adding ring buffer sync to it. Original commit message from CVS: * gst-libs/gst/audio/gstbaseaudiosrc.c: (gst_base_audio_src_event), (gst_base_audio_src_create), (gst_base_audio_src_change_state): * gst-libs/gst/audio/gstbaseaudiosrc.h: * gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_read): patch from Edgard Lima Fixed gstbaseaudiosrc adding ring buffer sync to it. --- ChangeLog | 9 +++++++++ gst-libs/gst/audio/gstbaseaudiosrc.c | 18 ++++++++++++++++-- gst-libs/gst/audio/gstbaseaudiosrc.h | 3 +++ gst-libs/gst/audio/gstringbuffer.c | 5 +++-- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3dc2c2b915..dd617589e8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2005-10-06 Wim Taymans + + * gst-libs/gst/audio/gstbaseaudiosrc.c: (gst_base_audio_src_event), + (gst_base_audio_src_create), (gst_base_audio_src_change_state): + * gst-libs/gst/audio/gstbaseaudiosrc.h: + * gst-libs/gst/audio/gstringbuffer.c: (gst_ring_buffer_read): + patch from Edgard Lima + Fixed gstbaseaudiosrc adding ring buffer sync to it. + 2005-10-06 Wim Taymans * ext/ogg/gstoggdemux.c: (gst_ogg_demux_loop): diff --git a/gst-libs/gst/audio/gstbaseaudiosrc.c b/gst-libs/gst/audio/gstbaseaudiosrc.c index ae18b6ede9..726e6db465 100644 --- a/gst-libs/gst/audio/gstbaseaudiosrc.c +++ b/gst-libs/gst/audio/gstbaseaudiosrc.c @@ -289,8 +289,12 @@ gst_base_audio_src_event (GstBaseSrc * bsrc, GstEvent * event) switch (GST_EVENT_TYPE (event)) { case GST_EVENT_FLUSH_START: gst_ring_buffer_pause (src->ringbuffer); + gst_ring_buffer_clear_all (src->ringbuffer); break; case GST_EVENT_FLUSH_STOP: + /* always resync on sample after a flush */ + src->next_sample = -1; + gst_ring_buffer_clear_all (src->ringbuffer); break; default: break; @@ -306,6 +310,7 @@ gst_base_audio_src_create (GstPushSrc * psrc, GstBuffer ** outbuf) guchar *data; guint len; guint res; + guint64 sample; if (!gst_ring_buffer_is_acquired (src->ringbuffer)) goto wrong_state; @@ -315,10 +320,18 @@ gst_base_audio_src_create (GstPushSrc * psrc, GstBuffer ** outbuf) data = GST_BUFFER_DATA (buf); len = GST_BUFFER_SIZE (buf); - res = gst_ring_buffer_read (src->ringbuffer, -1, data, len); + if (src->next_sample != -1) { + sample = src->next_sample; + } else { + sample = 0; + } + + res = gst_ring_buffer_read (src->ringbuffer, sample, data, len); if (res == -1) goto stopped; + src->next_sample = sample + len / src->ringbuffer->spec.bytes_per_sample; + gst_buffer_set_caps (buf, GST_PAD_CAPS (GST_BASE_SRC_PAD (psrc))); *outbuf = buf; @@ -378,6 +391,7 @@ gst_base_audio_src_change_state (GstElement * element, } if (!gst_ring_buffer_open_device (src->ringbuffer)) return GST_STATE_CHANGE_FAILURE; + src->next_sample = 0; break; case GST_STATE_CHANGE_READY_TO_PAUSED: break; @@ -394,8 +408,8 @@ gst_base_audio_src_change_state (GstElement * element, gst_ring_buffer_pause (src->ringbuffer); break; case GST_STATE_CHANGE_PAUSED_TO_READY: - gst_ring_buffer_stop (src->ringbuffer); gst_ring_buffer_release (src->ringbuffer); + src->next_sample = 0; break; case GST_STATE_CHANGE_READY_TO_NULL: gst_ring_buffer_close_device (src->ringbuffer); diff --git a/gst-libs/gst/audio/gstbaseaudiosrc.h b/gst-libs/gst/audio/gstbaseaudiosrc.h index 7019d90189..bf539fbc0b 100644 --- a/gst-libs/gst/audio/gstbaseaudiosrc.h +++ b/gst-libs/gst/audio/gstbaseaudiosrc.h @@ -57,6 +57,9 @@ struct _GstBaseAudioSrc { GstClockTime buffer_time; GstClockTime latency_time; + /* the next sample to write */ + guint64 next_sample; + /* clock */ GstClock *clock; diff --git a/gst-libs/gst/audio/gstringbuffer.c b/gst-libs/gst/audio/gstringbuffer.c index 6ac0ba4d31..daa1027511 100644 --- a/gst-libs/gst/audio/gstringbuffer.c +++ b/gst-libs/gst/audio/gstringbuffer.c @@ -1065,9 +1065,10 @@ gst_ring_buffer_read (GstRingBuffer * buf, guint64 sample, guchar * data, /* segment too far ahead, we need to drop */ if (diff < 0) { - /* we need to drop one segment at a time, pretend we wrote a - * segment. */ + /* we need to drop one segment at a time, pretend we read an + * empty segment. */ readlen = MIN (segsize, len); + memcpy (data, buf->empty_seg, readlen); goto next; }