From 5e5a32534ad9aa340f7cf76b2d54461e8f7d1098 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Fri, 10 Nov 2023 22:37:52 +0100 Subject: [PATCH] vo: add frame vsync and vsync duration Relative to frame PTS timeline as oposed to display vblank. Those values are relative to unadjusted video timeline. They will be used by gpu-next where it expect virtual frame vsync, not display vblank time. --- player/video.c | 6 ++++-- video/out/vo.c | 1 + video/out/vo.h | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/player/video.c b/player/video.c index 6d16f675ef..879cd52497 100644 --- a/player/video.c +++ b/player/video.c @@ -834,8 +834,8 @@ static void handle_display_sync_frame(struct MPContext *mpctx, if (vsync <= 0) return; - double adjusted_duration = MPMAX(0, mpctx->past_frames[0].approx_duration); - adjusted_duration /= opts->playback_speed; + double approx_duration = MPMAX(0, mpctx->past_frames[0].approx_duration); + double adjusted_duration = approx_duration / opts->playback_speed; if (adjusted_duration > 0.5) return; @@ -919,6 +919,8 @@ static void handle_display_sync_frame(struct MPContext *mpctx, frame->vsync_interval = vsync; frame->vsync_offset = -prev_error; frame->ideal_frame_duration = frame_duration; + frame->ideal_frame_vsync = (-prev_error / frame_duration) * approx_duration; + frame->ideal_frame_vsync_duration = approx_duration / num_vsyncs; frame->num_vsyncs = num_vsyncs; frame->display_synced = true; diff --git a/video/out/vo.c b/video/out/vo.c index 2296d25448..3e75cc57b8 100644 --- a/video/out/vo.c +++ b/video/out/vo.c @@ -898,6 +898,7 @@ static bool render_frame(struct vo *vo) in->current_frame->repeat = true; if (frame->display_synced) { in->current_frame->vsync_offset += in->current_frame->vsync_interval; + in->current_frame->ideal_frame_vsync += in->current_frame->ideal_frame_vsync_duration; in->dropped_frame |= in->current_frame->num_vsyncs < 1; } if (in->current_frame->num_vsyncs > 0) diff --git a/video/out/vo.h b/video/out/vo.h index 1fb83ddd65..5ebfc39674 100644 --- a/video/out/vo.h +++ b/video/out/vo.h @@ -218,6 +218,10 @@ struct vo_frame { // "ideal" frame duration (can be different from num_vsyncs*vsync_interval // up to a vsync) - valid for the entire frame, i.e. not changed for repeats double ideal_frame_duration; + // "ideal" frame vsync point relative to the pts + double ideal_frame_vsync; + // "ideal" frame duration relative to the pts + double ideal_frame_vsync_duration; // how often the frame will be repeated (does not include OSD redraws) int num_vsyncs; // Set if the current frame is repeated from the previous. It's guaranteed