audiobasesink: Fix custom slaving driftsamples calculation
driftsamples currently uses the requested skew directly, even if it exceeds cexternal. Use the approach that skew_slaving uses to fix this. As a side benefit, this makes the custom_slaving and skew_slaving code easier to compare. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8605>
This commit is contained in:
parent
a59810ef97
commit
9ffab2199d
@ -1262,7 +1262,7 @@ gst_audio_base_sink_custom_slaving (GstAudioBaseSink * sink,
|
|||||||
{
|
{
|
||||||
GstClockTime cinternal, cexternal, crate_num, crate_denom;
|
GstClockTime cinternal, cexternal, crate_num, crate_denom;
|
||||||
GstClockTime etime, itime;
|
GstClockTime etime, itime;
|
||||||
GstClockTimeDiff requested_skew;
|
GstClockTimeDiff requested_skew, drift;
|
||||||
gint driftsamples;
|
gint driftsamples;
|
||||||
gint64 last_align;
|
gint64 last_align;
|
||||||
|
|
||||||
@ -1300,10 +1300,18 @@ gst_audio_base_sink_custom_slaving (GstAudioBaseSink * sink,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (requested_skew > 0) {
|
if (requested_skew > 0) {
|
||||||
cexternal = (cexternal > requested_skew) ? (cexternal - requested_skew) : 0;
|
/* Move the external time backward by the requested skew, but don't ever
|
||||||
|
* go negative. Moving the requested skew by the same distance defines
|
||||||
|
* the new clock skew window center point. This allows the clock to
|
||||||
|
* drift equally into either direction after the correction. */
|
||||||
|
if (G_LIKELY (cexternal > requested_skew))
|
||||||
|
drift = requested_skew;
|
||||||
|
else
|
||||||
|
drift = cexternal;
|
||||||
|
|
||||||
driftsamples =
|
cexternal -= drift;
|
||||||
(sink->ringbuffer->spec.info.rate * requested_skew) / GST_SECOND;
|
|
||||||
|
driftsamples = (sink->ringbuffer->spec.info.rate * drift) / GST_SECOND;
|
||||||
last_align = sink->priv->last_align;
|
last_align = sink->priv->last_align;
|
||||||
|
|
||||||
/* if we were aligning in the wrong direction or we aligned more than what we
|
/* if we were aligning in the wrong direction or we aligned more than what we
|
||||||
@ -1318,10 +1326,10 @@ gst_audio_base_sink_custom_slaving (GstAudioBaseSink * sink,
|
|||||||
gst_clock_set_calibration (sink->provided_clock, cinternal, cexternal,
|
gst_clock_set_calibration (sink->provided_clock, cinternal, cexternal,
|
||||||
crate_num, crate_denom);
|
crate_num, crate_denom);
|
||||||
} else if (requested_skew < 0) {
|
} else if (requested_skew < 0) {
|
||||||
cexternal += ABS (requested_skew);
|
drift = -requested_skew;
|
||||||
|
cexternal += drift;
|
||||||
|
|
||||||
driftsamples =
|
driftsamples = (sink->ringbuffer->spec.info.rate * drift) / GST_SECOND;
|
||||||
(sink->ringbuffer->spec.info.rate * ABS (requested_skew)) / GST_SECOND;
|
|
||||||
last_align = sink->priv->last_align;
|
last_align = sink->priv->last_align;
|
||||||
|
|
||||||
/* if we were aligning in the wrong direction or we aligned more than what we
|
/* if we were aligning in the wrong direction or we aligned more than what we
|
||||||
|
Loading…
x
Reference in New Issue
Block a user