Skip to content

wlwindow: Add mutex for surface commit to avoid interference between multi-threads

When APP sets video rotation mode or video size during playback, there are multiple threads changing the configuration of the video surface and performing wl_surface_commit.

For example, when setting the rotation mode of a video, there will be two threads (input thread and display thread) operating on the video surface.

  1. input thread: resize video viewport, set buffer transform, etc.
wp_viewport_set_source              // set viewport src size (x, y, width, height)
wp_viewport_set_destination         // set viewport dest size
wl_surface_set_buffer_transform     // set buffer transform (rotation mode)
wl_surface_commit                   // commit video surface
  1. display thread: display video frames received by waylandsink.
gst_wl_buffer_attach               // attach video buffer to surface
wl_surface_damage_buffer           // set damage region
wl_surface_commit                  // commit video surface

When setting the video rotation mode, the operations of these two threads will affect each other as follows.

wp_viewport_set_source           (input thread)
wp_viewport_set_destination      (input thread)
wl_surface_commit                (display thread)
wl_surface_set_buffer_transform  (input thread)
wl_surface_commit                (input thread)

Before the input thread set the rotation mode, the display thread submits the video surface first.

In order to make the operation of two threads atomic, add a mutex commit_lock in these threads. When a thread operates on video surface, other threads cannot operates on this surface.

Merge request reports