From ce67ac6373e52591a2555578e25e3ae1d5e9d83c Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 3 Apr 2008 10:37:03 +0000 Subject: [PATCH] gst-libs/gst/audio/gstbaseaudiosink.c: Guard against over and underflows because of clock slaving. Original commit message from CVS: * gst-libs/gst/audio/gstbaseaudiosink.c: (gst_base_audio_sink_skew_slaving), (gst_base_audio_sink_render): Guard against over and underflows because of clock slaving. When we are using our own clock, still compensate for any calibrations that we might have done to our clock. --- ChangeLog | 8 ++++++++ gst-libs/gst/audio/gstbaseaudiosink.c | 12 +++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3402fd54b3..3ed65b11d8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2008-04-03 Wim Taymans + + * gst-libs/gst/audio/gstbaseaudiosink.c: + (gst_base_audio_sink_skew_slaving), (gst_base_audio_sink_render): + Guard against over and underflows because of clock slaving. + When we are using our own clock, still compensate for any calibrations + that we might have done to our clock. + 2008-04-03 Wim Taymans * ext/theora/theoradec.c: (theora_handle_type_packet), diff --git a/gst-libs/gst/audio/gstbaseaudiosink.c b/gst-libs/gst/audio/gstbaseaudiosink.c index 4bd5cfda8a..91ab4928c2 100644 --- a/gst-libs/gst/audio/gstbaseaudiosink.c +++ b/gst-libs/gst/audio/gstbaseaudiosink.c @@ -870,8 +870,9 @@ gst_base_audio_sink_skew_slaving (GstBaseAudioSink * sink, etime = gst_clock_get_time (GST_ELEMENT_CLOCK (sink)); itime = gst_clock_get_internal_time (sink->provided_clock); - etime -= cexternal; - itime -= cinternal; + /* make sure we never go below 0 */ + etime = etime > cexternal ? etime - cexternal : 0; + itime = itime > cinternal ? itime - cinternal : 0; skew = GST_CLOCK_DIFF (etime, itime); if (sink->priv->avg_skew == -1) { @@ -896,7 +897,7 @@ gst_base_audio_sink_skew_slaving (GstBaseAudioSink * sink, GST_WARNING_OBJECT (sink, "correct clock skew %" G_GINT64_FORMAT " > %" G_GINT64_FORMAT, sink->priv->avg_skew, segtime2); - cinternal += segtime; + cexternal = cexternal > segtime ? cexternal - segtime : 0; sink->priv->avg_skew -= segtime; segsamples = @@ -1138,6 +1139,11 @@ gst_base_audio_sink_render (GstBaseSink * bsink, GstBuffer * buf) /* handle clock slaving */ gst_base_audio_sink_handle_slaving (sink, render_start, render_stop, &render_start, &render_stop); + } else { + /* no slaving needed but we need to adapt to the clock calibration + * parameters */ + gst_base_audio_sink_none_slaving (sink, render_start, render_stop, + &render_start, &render_stop); } /* and bring the time to the rate corrected offset in the buffer */