From 827e06ccc3c66f70fb8b5c28a727721eb933f1cf Mon Sep 17 00:00:00 2001 From: Ismail Degani Date: Sun, 5 Jul 2026 01:38:01 +0000 Subject: [PATCH] es_out: scale preroll clock-origin compensation by the playback rate After a seek, EsOutDecodersStopBuffering() rebases the clock system origin by subtracting i_buffering_duration, a stream-time duration, from a system-time date without accounting for the playback rate. Timestamp conversion then stretches the preroll portion by 1/rate, so at rates below 1.0 every precise seek stalls playback for i_preroll_duration * (1/rate - 1) while the preroll is replayed in stretched wall time. With a 1.67s preroll this measures as a ~5s freeze at 0.25x and a ~16s freeze at 0.1x; with typical 5-10s GOPs the freeze reaches 15-60s, making seeking effectively unusable in slow motion (issue #21890, also reported against vlc-android). Scale only the preroll part of the compensation by the rate. The pts_delay part must stay unscaled because the input clock already compensates it on every conversion via ClockGetTsOffset(); scaling it here too would make the first frames late by pts_delay * (1/rate - 1). Verified on master (8115e53) with a headless libvlc driver polling media_player_get_time() every 250ms around a set_time() to 60s on a local mp4 (1.67s preroll, file-caching 1000). Wall time until the reported time advanced 200ms past the seek target: rate before after 1.0x 1.75s 1.75s (unchanged) 2.0x 1.50s 1.50s (unchanged) 0.25x 6.25s 2.25s 0.1x 18.0s 2.5s (the residual at slow rates is the measurement itself: advancing 200ms of stream time takes 0.8s / 2s of wall time at 0.25x / 0.1x.) The same fix was previously verified against the 3.0.x branch with a patched libvlccore 3.0.20: stall at 0.25x dropped from ~5-6s to under 1s, at 0.1x from ~15-17s to under 2s. Co-authored-by: Claude --- src/input/es_out.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/input/es_out.c b/src/input/es_out.c index db2ff90..908078d 100644 --- a/src/input/es_out.c +++ b/src/input/es_out.c @@ -1218,7 +1218,15 @@ static void EsOutDecodersStopBuffering(es_out_sys_t *p_sys, bool b_forced) /* */ const vlc_tick_t i_current_date = p_sys->b_paused ? p_sys->i_pause_date : vlc_tick_now(); - const vlc_tick_t update = i_current_date - i_buffering_duration; + /* The buffered data will be consumed at the current playback rate: scale + * the origin compensation for the preroll part accordingly, otherwise a + * precise seek at rate != 1.0 replays the preroll (keyframe -> seek + * target) stretched by 1/rate in wall time, stalling playback for + * i_preroll_duration * (1/rate - 1) (see issue #21890). The pts_delay + * part must NOT be scaled here: the input clock already compensates it + * on timestamp conversion (ClockGetTsOffset). */ + const vlc_tick_t update = i_current_date - i_buffering_duration + - (vlc_tick_t)(i_preroll_duration * (1.0 / p_sys->rate - 1.0)); /* The call order of these 3 input_clock_t/vlc_clock_main_t functions is * important: -- 2.43.0