From bd2a039c8d06f84113f8524ab42b86dbbd307f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 2 Jul 2024 17:15:58 +0300 Subject: [PATCH] livesync: Use the actual output buffer duration of gap filler buffers Otherwise the following can happen: - 25fps stream - buffer with PTS 0ms, duration 20ms arrives, is output - buffer with PTS 40ms, duration 20ms arrives - is considered early because 20ms < 40ms - filler buffer with PTS 20ms and 40ms duration is output - buffer with PTS 40ms is output After this change no filler would be inserted because the gap is smaller than the duration of a filler buffer. Also, previously the 40ms duration would be used if a filler was previously output because in that case the cached output buffer duration would've already been patched from 20ms to 40ms. Part-of: --- utils/livesync/src/livesync/imp.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/utils/livesync/src/livesync/imp.rs b/utils/livesync/src/livesync/imp.rs index be5ab2e9..106a8035 100644 --- a/utils/livesync/src/livesync/imp.rs +++ b/utils/livesync/src/livesync/imp.rs @@ -1295,10 +1295,14 @@ impl LiveSync { }; // When out_timestamp is set, we also have an out_buffer unless it is the first buffer - let Some(ref out_buffer) = state.out_buffer else { + if state.out_buffer.is_none() { return false; - }; - let slack = out_buffer.duration().unwrap(); + } + + // Use the duration we would insert as a gap filler in patch_output_buffer() + let slack = state.out_duration.map_or(DEFAULT_DURATION, |dur| { + dur.clamp(MINIMUM_DURATION, MAXIMUM_DURATION) + }); if timestamp.start < out_timestamp.end + slack { return false;