gst-libs/gst/audio/gstbaseaudiosink.c: When the audio clock is slaved to another clock, never try to align samples bu...

Original commit message from CVS:
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_provide_clock), (gst_base_audio_sink_render):
When the audio clock is slaved to another clock, never try to align
samples but trust the rate interpolation algorithm.
This commit is contained in:
Wim Taymans 2006-07-24 15:14:17 +00:00
parent 19cd03c607
commit f3ae89426a
2 changed files with 42 additions and 26 deletions

View file

@ -1,3 +1,10 @@
2006-07-24 Wim Taymans <wim@fluendo.com>
* gst-libs/gst/audio/gstbaseaudiosink.c:
(gst_base_audio_sink_provide_clock), (gst_base_audio_sink_render):
When the audio clock is slaved to another clock, never try to align
samples but trust the rate interpolation algorithm.
2006-07-24 Wim Taymans <wim@fluendo.com> 2006-07-24 Wim Taymans <wim@fluendo.com>
* ext/alsa/gstalsasink.c: (set_hwparams), (gst_alsasink_prepare): * ext/alsa/gstalsasink.c: (set_hwparams), (gst_alsasink_prepare):

View file

@ -200,6 +200,7 @@ gst_base_audio_sink_provide_clock (GstElement * elem)
return clock; return clock;
/* ERRORS */
wrong_state: wrong_state:
{ {
GST_DEBUG_OBJECT (sink, "ringbuffer not acquired"); GST_DEBUG_OBJECT (sink, "ringbuffer not acquired");
@ -490,11 +491,6 @@ gst_base_audio_sink_render (GstBaseSink * bsink, GstBuffer * buf)
sink = GST_BASE_AUDIO_SINK (bsink); sink = GST_BASE_AUDIO_SINK (bsink);
if (G_UNLIKELY (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT))) {
/* always resync after a discont */
sink->next_sample = -1;
}
ringbuf = sink->ringbuffer; ringbuf = sink->ringbuffer;
/* can't do anything when we don't have the device */ /* can't do anything when we don't have the device */
@ -581,8 +577,23 @@ gst_base_audio_sink_render (GstBaseSink * bsink, GstBuffer * buf)
", render offset %llu, samples %lu", ", render offset %llu, samples %lu",
GST_TIME_ARGS (render_time), render_offset, samples); GST_TIME_ARGS (render_time), render_offset, samples);
/* roundoff errors in timestamp conversion */
if (G_LIKELY (sink->next_sample != -1)) { /* never try to align samples when we are slaved to another clock, just
* trust the rate control algorithm to align the two clocks. We don't take
* the LOCK to read the clock because it does not really matter here and the
* clock is not changed while playing normally. */
if (GST_ELEMENT_CLOCK (sink) != sink->provided_clock) {
GST_DEBUG_OBJECT (sink, "no align needed: we are slaved");
goto no_align;
}
/* always resync after a discont */
if (G_UNLIKELY (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT))) {
GST_DEBUG_OBJECT (sink, "resync after discont");
goto no_align;
}
/* now try to align the sample to the previous one */
diff = ABS ((gint64) render_offset - (gint64) sink->next_sample); diff = ABS ((gint64) render_offset - (gint64) sink->next_sample);
/* we tollerate half a second diff before we start resyncing. This /* we tollerate half a second diff before we start resyncing. This
@ -597,14 +608,12 @@ gst_base_audio_sink_render (GstBaseSink * bsink, GstBuffer * buf)
render_offset = sink->next_sample; render_offset = sink->next_sample;
} else { } else {
/* timestamps drifted apart from previous samples too much, we need to /* timestamps drifted apart from previous samples too much, we need to
* resync. */ * resync. We log this as an element warning. */
GST_WARNING_OBJECT (sink, GST_ELEMENT_WARNING (sink, CORE, CLOCK, (NULL),
"resync after discont with previous sample of diff: %lu", diff); ("Unexpected discontinuity in audio timestamps of more than half a second"));
}
} else {
GST_DEBUG_OBJECT (sink, "resync after discont");
} }
no_align:
crate = crate =
gst_guint64_to_gdouble (crate_num) / gst_guint64_to_gdouble (crate_denom); gst_guint64_to_gdouble (crate_num) / gst_guint64_to_gdouble (crate_denom);
GST_DEBUG_OBJECT (sink, GST_DEBUG_OBJECT (sink,