Improve delay buffer startup

The delay buffer clock estimates the clock offset between the PTS and
the frame decoded date using an "Exponentially Weighted Moving Average"
(EWMA).

But for the first frames, the clock have less than SC_CLOCK_RANGE
points to average. Since the timing for the first frames are typically
the worst ones, give more weight to the last point for the estimation.

Once SC_CLOCK_RANGE points are available (i.e. when SC_CLOCK_RANGE ==
clock->range), the new estimation is equivalent to the previous version.
This commit is contained in:
Romain Vimont 2024-09-12 10:53:44 +02:00
parent f089ea67e1
commit a7cae59578

View File

@ -21,8 +21,10 @@ sc_clock_update(struct sc_clock *clock, sc_tick system, sc_tick stream) {
}
sc_tick offset = system - stream;
clock->offset = ((clock->range - 1) * clock->offset + offset)
/ clock->range;
unsigned clock_weight = clock->range - 1;
unsigned value_weight = SC_CLOCK_RANGE - clock->range + 1;
clock->offset = (clock->offset * clock_weight + offset * value_weight)
/ SC_CLOCK_RANGE;
#ifdef SC_CLOCK_DEBUG
LOGD("Clock estimation: pts + %" PRItick, clock->offset);