[vlc-devel] [PATCH v2 05/13] video_output: rework the deadline parameter return

Steve Lhomme robux4 at ycbcr.xyz
Mon Aug 17 15:15:24 CEST 2020


It's not a deadline that we get, but a value we return.

We should always return a value, even if the picture wasn't rendered yet.
Setting a dummy value before calling the function seems more hackish.

Do not compare a next_deadline value if it's VLC_TICK_INVALID.
Set it to date_refresh even if it's VLC_TICK_INVALID.

Substract the render delay once we have the date we want the next render,
outside of ThreadDisplayPicture().

Reorder the code to avoid intermediate variables and so we can compare the
display refresh deadline and the render time of the next picture.

date_next was computed even when next_system_pts is INT64_MAX.
---
 src/video_output/video_output.c | 68 +++++++++++++++++----------------
 1 file changed, 35 insertions(+), 33 deletions(-)

diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 51dfe2df9ca..eda98beea31 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -1453,10 +1453,10 @@ static int ThreadDisplayRenderPicture(vout_thread_sys_t *vout, bool is_forced)
 
 static void ThreadProcessMouseState(vout_thread_sys_t *);
 
-static int ThreadDisplayPicture(vout_thread_sys_t *vout, vlc_tick_t *deadline)
+static int ThreadDisplayPicture(vout_thread_sys_t *vout, vlc_tick_t *next_render)
 {
     vout_thread_sys_t *sys = vout;
-    bool frame_by_frame = !deadline;
+    bool frame_by_frame = !next_render;
     bool paused = sys->pause.is_on;
     bool first = !sys->displayed.current;
 
@@ -1464,10 +1464,10 @@ static int ThreadDisplayPicture(vout_thread_sys_t *vout, vlc_tick_t *deadline)
 
     if (atomic_load(&sys->mouse_changed))
     {
-        if (deadline)
+        if (next_render)
         {
              // wait in case the mouse state changes just before display
-            vlc_tick_wait(*deadline);
+            vlc_tick_wait(*next_render);
         }
         ThreadProcessMouseState(vout);
     }
@@ -1478,6 +1478,9 @@ static int ThreadDisplayPicture(vout_thread_sys_t *vout, vlc_tick_t *deadline)
         ThreadChangeFilters(vout, sys->filter.new_filters, &sys->filter.new_interlaced);
     vlc_mutex_unlock(&sys->filter.lock);
 
+    if (next_render)
+        *next_render = VLC_TICK_INVALID;
+
     if (first)
         if (ThreadDisplayPreparePicture(vout, true, frame_by_frame, &paused)) /* FIXME not sure it is ok */
             return VLC_EGENERIC;
@@ -1488,27 +1491,8 @@ static int ThreadDisplayPicture(vout_thread_sys_t *vout, vlc_tick_t *deadline)
             ;
 
     const vlc_tick_t system_now = vlc_tick_now();
-    const vlc_tick_t render_delay = vout_chrono_GetHigh(&sys->render) + VOUT_MWAIT_TOLERANCE;
 
     bool drop_next_frame = frame_by_frame;
-    vlc_tick_t date_next = VLC_TICK_INVALID;
-
-    if (!paused && sys->displayed.next) {
-        const vlc_tick_t next_system_pts =
-            vlc_clock_ConvertToSystem(sys->clock, system_now,
-                                      sys->displayed.next->date, sys->rate);
-        if (unlikely(next_system_pts == INT64_MAX))
-        {
-            /* The clock was just paused, don't display the next frame (keep
-             * the current one). */
-            paused = true;
-        }
-        {
-            date_next = next_system_pts - render_delay;
-            if (date_next <= system_now)
-                drop_next_frame = true;
-        }
-    }
 
     /* FIXME/XXX we must redisplay the last decoded picture (because
      * of potential vout updated, or filters update or SPU update)
@@ -1521,20 +1505,37 @@ static int ThreadDisplayPicture(vout_thread_sys_t *vout, vlc_tick_t *deadline)
      */
     bool refresh = false;
 
-    vlc_tick_t date_refresh = VLC_TICK_INVALID;
     if (sys->displayed.date != VLC_TICK_INVALID) {
-        date_refresh = sys->displayed.date + VOUT_REDISPLAY_DELAY - render_delay;
+        vlc_tick_t date_refresh = sys->displayed.date + VOUT_REDISPLAY_DELAY;
         refresh = date_refresh <= system_now;
+        if (!frame_by_frame)
+            *next_render = date_refresh;
     }
-    bool force_refresh = !drop_next_frame && refresh;
 
-    if (!frame_by_frame) {
-        if (date_refresh != VLC_TICK_INVALID)
-            *deadline = date_refresh;
-        if (date_next != VLC_TICK_INVALID && date_next < *deadline)
-            *deadline = date_next;
+    if (!paused && sys->displayed.next) {
+        const vlc_tick_t next_system_pts =
+            vlc_clock_ConvertToSystem(sys->clock, system_now,
+                                      sys->displayed.next->date, sys->rate);
+        if (unlikely(next_system_pts == INT64_MAX))
+        {
+            /* The clock was just paused, don't display the next frame (keep
+             * the current one). */
+            paused = true;
+        }
+        else
+        {
+            if (!frame_by_frame) {
+                if (*next_render == VLC_TICK_INVALID || *next_render > next_system_pts)
+                    *next_render = next_system_pts;
+            }
+
+            if (next_system_pts <= system_now)
+                drop_next_frame = true;
+        }
     }
 
+    bool force_refresh = !drop_next_frame && refresh;
+
     if (!first && !refresh && !drop_next_frame) {
         return VLC_EGENERIC;
     }
@@ -1634,7 +1635,7 @@ void vout_NextPicture(vout_thread_t *vout, vlc_tick_t *duration)
     if (sys->step.last == VLC_TICK_INVALID)
         sys->step.last = sys->displayed.timestamp;
 
-    if (ThreadDisplayPicture(sys, NULL) == 0) {
+    if (ThreadDisplayPicture(sys, NULL) == VLC_SUCCESS) {
         sys->step.timestamp = sys->displayed.timestamp;
 
         if (sys->step.last != VLC_TICK_INVALID &&
@@ -1901,8 +1902,9 @@ static void *Thread(void *object)
             }
         }
 
-        deadline = VLC_TICK_INVALID;
         wait = ThreadDisplayPicture(vout, &deadline) != VLC_SUCCESS;
+        if (deadline != VLC_TICK_INVALID)
+            deadline -= vout_chrono_GetHigh(&sys->render) + VOUT_MWAIT_TOLERANCE;
 
         const bool picture_interlaced = sys->displayed.is_interlaced;
 
-- 
2.26.2



More information about the vlc-devel mailing list