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).
This commit is contained in:
Arun Raghavan 2015-03-03 22:56:37 +05:30 committed by Arun Raghavan
parent 4643d34a7a
commit 557c2c9be1
2 changed files with 15 additions and 11 deletions

View file

@ -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));

View file

@ -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;