From 557c2c9be1f9156a66df88fa6cc725ffa5a73615 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Tue, 3 Mar 2015 22:56:37 +0530 Subject: [PATCH] audiobasesink: Reset audio clock if necessary When the ringbuffer is deactivated and then acquired, if the audio clock provided by the sink gets reset to zero, we need to add an offset to the clock to make sure that subsequent samples are written out at the right times. While we need to leave this to derived classes to take care of when they provide their own clock (since that clock may or may not be reset to zero), we can do this ourselves if we know the provided clock is our own (which does reset to zero on a re-acquire). --- gst-libs/gst/audio/gstaudiobasesink.c | 21 +++++++++++++++------ gst-libs/gst/audio/gstaudiosink.c | 5 ----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/gst-libs/gst/audio/gstaudiobasesink.c b/gst-libs/gst/audio/gstaudiobasesink.c index ece99d44b0..233efcb4df 100644 --- a/gst-libs/gst/audio/gstaudiobasesink.c +++ b/gst-libs/gst/audio/gstaudiobasesink.c @@ -380,6 +380,14 @@ clock_disabled: } } +static gboolean +gst_audio_base_sink_is_self_provided_clock (GstAudioBaseSink * sink) +{ + return (sink->provided_clock && GST_IS_AUDIO_CLOCK (sink->provided_clock) && + GST_AUDIO_CLOCK_CAST (sink->provided_clock)->func == + (GstAudioClockGetTimeFunc) gst_audio_base_sink_get_time); +} + static gboolean gst_audio_base_sink_query_pad (GstBaseSink * bsink, GstQuery * query) { @@ -887,6 +895,11 @@ gst_audio_base_sink_setcaps (GstBaseSink * bsink, GstCaps * caps) if (!gst_audio_ring_buffer_acquire (sink->ringbuffer, spec)) goto acquire_error; + /* If we use our own clock, we need to adjust the offset since it will now + * restart from zero */ + if (gst_audio_base_sink_is_self_provided_clock (sink)) + gst_audio_clock_reset (GST_AUDIO_CLOCK (sink->provided_clock), 0); + /* We need to resync since the ringbuffer restarted */ gst_audio_base_sink_reset_sync (sink); @@ -2224,9 +2237,7 @@ gst_audio_base_sink_change_state (GstElement * element, /* Only post clock-provide messages if this is the clock that * we've created. If the subclass has overriden it the subclass * should post this messages whenever necessary */ - if (sink->provided_clock && GST_IS_AUDIO_CLOCK (sink->provided_clock) && - GST_AUDIO_CLOCK_CAST (sink->provided_clock)->func == - (GstAudioClockGetTimeFunc) gst_audio_base_sink_get_time) + if (gst_audio_base_sink_is_self_provided_clock (sink)) gst_element_post_message (element, gst_message_new_clock_provide (GST_OBJECT_CAST (element), sink->provided_clock, TRUE)); @@ -2264,9 +2275,7 @@ gst_audio_base_sink_change_state (GstElement * element, /* Only post clock-lost messages if this is the clock that * we've created. If the subclass has overriden it the subclass * should post this messages whenever necessary */ - if (sink->provided_clock && GST_IS_AUDIO_CLOCK (sink->provided_clock) && - GST_AUDIO_CLOCK_CAST (sink->provided_clock)->func == - (GstAudioClockGetTimeFunc) gst_audio_base_sink_get_time) + if (gst_audio_base_sink_is_self_provided_clock (sink)) gst_element_post_message (element, gst_message_new_clock_lost (GST_OBJECT_CAST (element), sink->provided_clock)); diff --git a/gst-libs/gst/audio/gstaudiosink.c b/gst-libs/gst/audio/gstaudiosink.c index f18b1c740c..0604f59161 100644 --- a/gst-libs/gst/audio/gstaudiosink.c +++ b/gst-libs/gst/audio/gstaudiosink.c @@ -399,7 +399,6 @@ gst_audio_sink_ring_buffer_acquire (GstAudioRingBuffer * buf, GstAudioSink *sink; GstAudioSinkClass *csink; gboolean result = FALSE; - GstAudioClock *clock; sink = GST_AUDIO_SINK (GST_OBJECT_PARENT (buf)); csink = GST_AUDIO_SINK_GET_CLASS (sink); @@ -409,10 +408,6 @@ gst_audio_sink_ring_buffer_acquire (GstAudioRingBuffer * buf, if (!result) goto could_not_prepare; - /* our clock will now start from 0 again */ - clock = GST_AUDIO_CLOCK (GST_AUDIO_BASE_SINK (sink)->provided_clock); - gst_audio_clock_reset (clock, 0); - /* set latency to one more segment as we need some headroom */ spec->seglatency = spec->segtotal + 1;