From 7384b054335b334d040f11ee22129afc99b77f63 Mon Sep 17 00:00:00 2001 From: James Ross-Gowan Date: Sat, 19 Oct 2019 00:12:06 +1100 Subject: vo_gpu: d3d11: prevent wraparound in queued frames calc If expected_sync_pc is greater than submit_count, the unsigned subtraction will wraparound, which breaks playback. This bug was found while experimenting with bit-blt model present, but it might be possible to trigger it with the flip model as well, if there was a dropped frame. --- video/out/d3d11/context.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/video/out/d3d11/context.c b/video/out/d3d11/context.c index 62c0f5772f..f03f93df92 100644 --- a/video/out/d3d11/context.c +++ b/video/out/d3d11/context.c @@ -296,8 +296,9 @@ static void d3d11_get_vsync(struct ra_swapchain *sw, struct vo_vsync_info *info) // Now guess the timestamp of the last submitted frame based on the // timestamp of the frame at SyncRefreshCount and the frame rate + int queued_frames = submit_count - expected_sync_pc; int64_t last_queue_display_time_qpc = stats.SyncQPCTime.QuadPart + - (submit_count - expected_sync_pc) * p->vsync_duration_qpc; + queued_frames * p->vsync_duration_qpc; // Only set the estimated display time if it's after the last submission // time. It could be before if mpv skips a lot of frames. -- cgit v1.2.3