[vlc-devel] [PATCH] video_output: drop frames that take too much time to process

Steve Lhomme robux4 at ycbcr.xyz
Mon Aug 10 13:32:31 CEST 2020


If a frame arrives at the rendering step later than it's display time (plus the
late threshold we allow), there's no way it will be displayed in time or even
late with some tolerance.

We can drop it and save some rendering/swap time for the next picture. We just
didn't detect the lateness at an upper level.
---
 src/video_output/video_output.c | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index 6cf7a426673..e7209d4d690 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -1032,6 +1032,12 @@ static void ThreadChangeFilters(vout_thread_sys_t *vout,
         vlc_mutex_unlock(&sys->filter.lock);
 }
 
+static vlc_tick_t GetPictureLateThreshold(picture_t *decoded)
+{
+    if (decoded->format.i_frame_rate && decoded->format.i_frame_rate_base)
+        return VLC_TICK_FROM_MS(500) * decoded->format.i_frame_rate_base / decoded->format.i_frame_rate;
+    return VOUT_DISPLAY_LATE_THRESHOLD;
+}
 
 /* */
 static int ThreadDisplayPreparePicture(vout_thread_sys_t *vout, bool reuse,
@@ -1071,12 +1077,7 @@ static int ThreadDisplayPreparePicture(vout_thread_sys_t *vout, bool reuse,
                     else
                         late = date - system_pts;
 
-                    vlc_tick_t late_threshold;
-                    if (decoded->format.i_frame_rate && decoded->format.i_frame_rate_base)
-                        late_threshold = VLC_TICK_FROM_MS(500) * decoded->format.i_frame_rate_base / decoded->format.i_frame_rate;
-                    else
-                        late_threshold = VOUT_DISPLAY_LATE_THRESHOLD;
-                    if (late > late_threshold) {
+                    if (late > GetPictureLateThreshold(decoded)) {
                         msg_Warn(&vout->obj, "picture is too late to be displayed (missing %"PRId64" ms)", MS_FROM_VLC_TICK(late));
                         picture_Release(decoded);
                         vout_statistic_AddLost(&sys->statistic, 1);
@@ -1377,6 +1378,18 @@ static int ThreadDisplayRenderPicture(vout_thread_sys_t *vout, bool is_forced)
         is_forced = true;
     }
 
+    if (system_now > (system_pts + GetPictureLateThreshold(todisplay)))
+    {
+        /* We received/processed this picture too late. Let's not
+         * waste time trying to render it and leave more time for the
+         * next one. */
+        vlc_mutex_unlock(&sys->display_lock);
+        vout_statistic_AddLost(&sys->statistic, 1);
+        // release as we won't reach vout_display_Display()
+        picture_Release(todisplay);
+        return VLC_EGENERIC;
+    }
+
     const unsigned frame_rate = todisplay->format.i_frame_rate;
     const unsigned frame_rate_base = todisplay->format.i_frame_rate_base;
 
-- 
2.26.2



More information about the vlc-devel mailing list