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;