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

Thomas Guillem thomas at gllm.fr
Thu Sep 5 13:40:03 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 | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 5badb35321..d9d6dce94c 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -1203,9 +1203,24 @@ 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. Tell the clock that the pts was
+             * rendered late. */
+            system_pts = system_now;
+        }
+        else
+        {
+            /* Wait to reach system_pts */
+            vlc_clock_Wait(sys->clock, system_now, pts, sys->rate,
+                           VOUT_REDISPLAY_DELAY);
+
+            /* Don't touch system_pts. Tell the clock that the pts was rendered
+             * at the expected date */
+        }
+        vlc_clock_Update(sys->clock, system_pts, pts, sys->rate);
     }
+    sys->displayed.date = system_pts;
 
     /* Display the direct buffer returned by vout_RenderPicture */
     vout_display_Display(vd, todisplay);
@@ -1214,16 +1229,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 && drift != INT64_MAX)
-            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