From f36d9d6b08801efabcbfd4cdcdaf0453175893de Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 20 May 2008 16:26:53 +0000 Subject: [PATCH] gst-libs/gst/audio/gstbaseaudiosink.c: We can only use our optimal calibration if we prerolled before the latency exp... Original commit message from CVS: * gst-libs/gst/audio/gstbaseaudiosink.c: (gst_base_audio_sink_sync_latency): We can only use our optimal calibration if we prerolled before the latency expired. --- ChangeLog | 7 ++++++ gst-libs/gst/audio/gstbaseaudiosink.c | 33 ++++++++++++--------------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index f806070b93..c57143c0d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-05-20 Wim Taymans + + * gst-libs/gst/audio/gstbaseaudiosink.c: + (gst_base_audio_sink_sync_latency): + We can only use our optimal calibration if we prerolled before the + latency expired. + 2008-05-20 Tim-Philipp Müller * configure.ac: diff --git a/gst-libs/gst/audio/gstbaseaudiosink.c b/gst-libs/gst/audio/gstbaseaudiosink.c index 1954695c4b..38b6a0cf31 100644 --- a/gst-libs/gst/audio/gstbaseaudiosink.c +++ b/gst-libs/gst/audio/gstbaseaudiosink.c @@ -1025,6 +1025,7 @@ gst_base_audio_sink_sync_latency (GstBaseSink * bsink) GstBaseAudioSink *sink; GstClockTime itime, etime; GstClockTime rate_num, rate_denom; + GstClockTimeDiff jitter; sink = GST_BASE_AUDIO_SINK (bsink); @@ -1039,8 +1040,6 @@ gst_base_audio_sink_sync_latency (GstBaseSink * bsink) GST_OBJECT_UNLOCK (sink); do { - GstClockTimeDiff jitter; - GST_DEBUG_OBJECT (sink, "checking preroll"); /* first wait for the playing state before we can continue */ @@ -1077,23 +1076,24 @@ gst_base_audio_sink_sync_latency (GstBaseSink * bsink) * yet. if some other error occures, we continue. */ } while (status == GST_CLOCK_UNSCHEDULED); - GST_OBJECT_LOCK (sink); GST_DEBUG_OBJECT (sink, "latency synced"); - /* if we are slaved to a clock, we need to set the initial - * calibration */ - switch (sink->priv->slave_method) { - case GST_BASE_AUDIO_SINK_SLAVE_SKEW: - case GST_BASE_AUDIO_SINK_SLAVE_RESAMPLE: - case GST_BASE_AUDIO_SINK_SLAVE_NONE: - default: - /* When we are prerolled, our internal clock should exactly have been the - * latency (== the running time of the external clock) */ - etime = GST_ELEMENT_CAST (sink)->base_time + time; - itime = gst_base_audio_sink_get_time (sink->provided_clock, sink); - break; + /* when we prerolled in time, we can accurately set the calibration, + * our internal clock should exactly have been the latency (== the running + * time of the external clock) */ + etime = GST_ELEMENT_CAST (sink)->base_time + time; + itime = gst_base_audio_sink_get_time (sink->provided_clock, sink); + + if (status == GST_CLOCK_EARLY) { + /* when we prerolled late, we have to take into account the lateness */ + GST_DEBUG_OBJECT (sink, "late preroll, adding jitter"); + etime += jitter; } + + /* start ringbuffer so we can start slaving right away when we need to */ + gst_ring_buffer_start (sink->ringbuffer); + GST_DEBUG_OBJECT (sink, "internal time: %" GST_TIME_FORMAT " external time: %" GST_TIME_FORMAT, GST_TIME_ARGS (itime), GST_TIME_ARGS (etime)); @@ -1120,9 +1120,6 @@ gst_base_audio_sink_sync_latency (GstBaseSink * bsink) sink->priv->avg_skew = -1; sink->next_sample = -1; - /* start ringbuffer so we can start slaving right away when we need to */ - gst_ring_buffer_start (sink->ringbuffer); - return GST_FLOW_OK; /* ERRORS */