Skip to content

vout: reduce blocking on resize

Romain Vimont requested to merge rom1v/vlc:rereresize into master

This is an alternative implementation of !1176 (closed):

  1. replace the proposed priority mechanism on display_lock by a separate lock;
  2. keep the principle of interrupting the clock-wait between prepare() and display() (and display early) on resize.

The resulting graphs are similar (the principle is the same).


Why replacing the display_lock by a separate lock for handling resizes?

On resize (i.e. in vout_ChangeDisplaySize()), the display_lock was acquired from the UI thread to ensure that no more rendering will be performed at the previous size before calling the "ack callback" (used by the xdg-shell vout window to synchronize with the wl-shm vout display) and returning.

This MR provides the same guarantee with a separate lock, but in addition, it guarantees that the UI thread will never have to wait for another vout loop (without introducing a priority mechanism like in !1176 (closed)).

Digression: Also note (as already mentioned in previous months) that to achieve "frame perfect" rendering, the UI would have to wait not only until all rendering at the old size are complete (what the display_lock achieve on master or what this MR provides), but also until a new rendering is performed at the new size. We can't reasonably do that now, since we are not able to re-render the current frame "quickly" (without re-preparing and waiting), but the mechanism introduced in this MR will allow to wait for the end of rendering easily (it would be even more simple than this MR, since there will be no need for tracking the rendering state).


quick & dirty additional patch to print measurements
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index ed19f4a111..db080e7c8c 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -479,6 +479,8 @@ void vout_ChangeDisplaySize(vout_thread_t *vout,
 
     assert(!sys->dummy);
 
+    vlc_tick_t t = vlc_tick_now();
+
     vlc_mutex_lock(&sys->resize.lock);
     sys->resize.pending = true;
     sys->resize.width = width;
@@ -503,6 +505,9 @@ void vout_ChangeDisplaySize(vout_thread_t *vout,
     while (sys->resize.waiting_eor)
         vlc_cond_wait(&sys->resize.cond, &sys->resize.lock);
 
+    vlc_tick_t t2 = vlc_tick_now();
+    fprintf(stderr, "[%ld] resize requested from UI thread after %ld\n", t2, t2 - t);
+
     if (cb != NULL)
         cb(opaque);
     vlc_mutex_unlock(&sys->resize.lock);
@@ -1333,6 +1338,9 @@ static int RenderPicture(vout_thread_sys_t *sys, bool render_now)
                     /* A caller (the UI thread) awaits for the rendering to
                      * complete urgently, do not wait. */
                     sys->wait_interrupted = true;
+                    vlc_tick_t t = vlc_tick_now();
+                    fprintf(stderr, "[%ld] interrupted %ld before deadline\n",
+                            t, deadline - t);
                     break;
                 }
 
Edited by Romain Vimont

Merge request reports