Skip to content

Commit

Permalink
player/video: only use MIN_PAST_FRAMES check if speed was changed
Browse files Browse the repository at this point in the history
Otherwise seeking at very high speeds could have some desync since it
naturally desyncs much faster at higher speeds. More clearly restrict
this behavior to the speed change case.

Fixes e3af545
  • Loading branch information
Dudemanguy committed Mar 2, 2024
1 parent 3c37e18 commit a075860
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions player/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ typedef struct MPContext {
/* Heuristic for potentially redrawing subs. */
bool redraw_subs;

bool speed_changed;

bool paused; // internal pause state
bool playback_active; // not paused, restarting, loading, unloading
bool in_playloop;
Expand Down
7 changes: 5 additions & 2 deletions player/video.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ void reset_av_state(struct MPContext *mpctx)
mpctx->logged_async_diff = -1;
mpctx->num_past_frames = 0;
mpctx->total_avsync_change = 0;
mpctx->speed_changed = true;
}

void reset_video_state(struct MPContext *mpctx)
Expand Down Expand Up @@ -606,13 +607,14 @@ static void update_avsync_before_frame(struct MPContext *mpctx)
if (mpctx->video_status < STATUS_READY) {
mpctx->time_frame = 0;
} else if (mpctx->display_sync_active || vo->opts->video_sync == VS_NONE ||
mpctx->num_past_frames <= MIN_PAST_FRAMES)
(mpctx->num_past_frames <= MIN_PAST_FRAMES && mpctx->speed_changed))
{
// don't touch the timing
} else if (mpctx->audio_status == STATUS_PLAYING &&
mpctx->video_status == STATUS_PLAYING &&
!ao_untimed(mpctx->ao))
{
mpctx->speed_changed = false;
double buffered_audio = ao_get_delay(mpctx->ao);

double predicted = mpctx->delay / mpctx->video_speed +
Expand Down Expand Up @@ -846,8 +848,9 @@ static void handle_display_sync_frame(struct MPContext *mpctx,
if (resample && using_spdif_passthrough(mpctx))
return;

if (mpctx->num_past_frames <= MIN_PAST_FRAMES)
if (mpctx->num_past_frames <= MIN_PAST_FRAMES && mpctx->speed_changed)
return;
mpctx->speed_changed = false;

double vsync = vo_get_vsync_interval(vo) / 1e9;
if (vsync <= 0)
Expand Down

0 comments on commit a075860

Please sign in to comment.