[vlc-devel] [PATCH 2/2] vout: update the clock between prepare() and display()

Thomas Guillem thomas at gllm.fr
Mon Sep 2 15:45:46 CEST 2019


The clock was updated just after the display returned. This could lead to a
(very) small imprecision (delay between the display implementation exit path
and vlc_tick_now() duration).

Instead, we can update the clock just after prepare(), using system_pts.
---
 src/video_output/video_output.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 8360a83019..37c940254b 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -1166,9 +1166,22 @@ static int ThreadDisplayRenderPicture(vout_thread_t *vout, bool is_forced)
     if (!is_forced)
     {
         system_now = vlc_tick_now();
-        vlc_clock_Wait(sys->clock, system_now, pts, sys->rate,
-                       VOUT_REDISPLAY_DELAY);
+        if (unlikely(system_now > system_pts))
+        {
+            /* vd->prepare took too much time */
+            system_pts = system_now;
+
+            vlc_clock_Update(sys->clock, system_pts, pts, sys->rate);
+        }
+        else
+        {
+            vlc_clock_Update(sys->clock, system_pts, pts, sys->rate);
+
+            vlc_clock_Wait(sys->clock, system_now, pts, sys->rate,
+                           VOUT_REDISPLAY_DELAY);
+        }
     }
+    sys->displayed.date = system_pts;
 
     /* Display the direct buffer returned by vout_RenderPicture */
     vout_display_Display(vd, todisplay);
@@ -1177,16 +1190,6 @@ static int ThreadDisplayRenderPicture(vout_thread_t *vout, bool is_forced)
     if (subpic)
         subpicture_Delete(subpic);
 
-    if (!is_forced)
-    {
-        system_now = vlc_tick_now();
-        const vlc_tick_t drift = vlc_clock_Update(sys->clock, system_now,
-                                                  pts, sys->rate);
-        if (drift != VLC_TICK_INVALID)
-            system_now += drift;
-    }
-    sys->displayed.date = system_now;
-
     vout_statistic_AddDisplayed(&sys->statistic, 1);
 
     return VLC_SUCCESS;
-- 
2.20.1



More information about the vlc-devel mailing list