From 1798183ce4964fa26bec9eb8a5bc27d4c8a22c17 Mon Sep 17 00:00:00 2001 From: Alexandre Janniaux Date: Tue, 26 Oct 2021 05:56:20 +0200 Subject: [PATCH] VLCVideoUIView: follow guidelines from WWDC21 When using timestamp vs targetTimestamp, one must take care to compare the VSYNC against the previous VSYNC (so targetTimestamp vs previous targetTimestamp) and not use timestamp + targetTimestamp. Also get the current time through CoreAnimation time functions to build the difference with now, allowing a bit of latency to be introduced in timestamp. --- modules/video_output/apple/VLCVideoUIView.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/modules/video_output/apple/VLCVideoUIView.m b/modules/video_output/apple/VLCVideoUIView.m index 7be1af3c5b..547bf3f8ab 100644 --- a/modules/video_output/apple/VLCVideoUIView.m +++ b/modules/video_output/apple/VLCVideoUIView.m @@ -93,6 +93,7 @@ CADisplayLink *_displayLink; dispatch_queue_t _eventq; + vlc_tick_t _last_ca_target_ts; } - (id)initWithWindow:(vout_window_t *)wnd; @@ -115,6 +116,7 @@ { _wnd = wnd; _enabled = NO; + _last_ca_target_ts = VLC_TICK_INVALID; atomic_init(&_avstatEnabled, false); UIView *superview = [self fetchViewContainer]; @@ -230,8 +232,11 @@ /* this compute the length of the VSYNC and the next date for the * VSYNC. */ + vlc_tick_t last_ca_target_ts =_last_ca_target_ts == VLC_TICK_INVALID ? + ca_current_ts : _last_ca_target_ts; vlc_tick_t clock_offset = ca_current_ts - ca_now_ts; - vlc_tick_t vsync_length = ca_target_ts - ca_current_ts; + vlc_tick_t vsync_length = ca_target_ts - last_ca_target_ts; + _last_ca_target_ts = ca_target_ts; if (atomic_load(&_avstatEnabled)) msg_Info(_wnd, "avstats: [RENDER][CADISPLAYLINK] ts=%" PRId64 " "