Skip to content

Conversation

@llyyr
Copy link
Contributor

@llyyr llyyr commented Sep 26, 2025

See individual commit descriptions.

First commit fixes us calling set_color_management on every frame.

Second commit removes unneeded unset_image_description calls.

Third commit adds a roundtrip to block the thread until the compositor responds with a ready to get image_description. This is fine because we aren't calling the function on every frame now as a result of the first commit, which is why I ordered them like this.

@github-actions
Copy link

github-actions bot commented Sep 26, 2025

Calling `pl_color_space_infer` on `wl->target_param` can cause the
`pl_color_space_equal` check to fail on every frame if any values were
changed by `pl_color_space_infer`. This will cause us to believe
target_params get changed on every frame, and we'll end up in a state
where wayland events happen in the following order indefinitely:

  -> wp_color_management_surface_v1#45.set_image_description(...)
  -> wp_color_management_surface_v1#45.unset_image_description()
  -> wl_surface#9.commit()
  -> wp_color_management_surface_v1#45.set_image_description(...)
  -> wp_color_management_surface_v1#45.unset_image_description()
  -> wl_surface#9.commit()

Since image_description is double buffered, we always queue an unset to
the pending state before each commit. As a result, no commit ever
carries a valid image_description.

Taking the sample file in the issue as an example, we end up in this
state because the file has `min_luma == 0` but `pl_color_space_infer`
normalizes this value to `min_luma == 0.000001`. This makes it so that
we store a different `target_param` to `vo_wayland_state` on every frame
than the one received from `vo_get_target_params`. So we end up setting
image description on every frame in this case.

The key problem here is that `set_color_management` isn't blocking the
thread until `set_image_description is called`, so vo->driver->flip_page
is called before this finishes.

This commit fixes the problem by doing any operations that could change
`wl->target_param` first before doing any equality checks to skip
changing to image description pointlessly.

This fixes the problem in the issue that image_description is never set
on such files. The synchronization problem is fixed in a later commit,
because otherwise setting image_description on every frame could have
adverse frame time effects

Fixes: mpv-player#16825
set_image_description replaces the old image description, so we don't
need to call unset_image_description unconditionally. Only call it if we
couldn't set an image description.

This helps with the lack of synchronization between VO pageflips and
wayland protocol events mentioned in the previous commit.
@llyyr llyyr force-pushed the wayland-color-hint2 branch from cc00f96 to 780f30e Compare September 27, 2025 04:09

/* Do a round trip to ensure the image description gets set before
* vo->driver->flip_page calls wl_surface_commit on us */
wl_display_roundtrip(wl->display);
Copy link
Member

@kasper93 kasper93 Sep 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it good thing to do? Does this synchronization can have potentially advert effects?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it was every frame I would say no, but since this should only happen on the first frame or when target_params change, it should be fine.

@Dudemanguy thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gstreamer and GDK do similar blocks, though they create a different queue just for this to block on. I could do that here if preferred

@llyyr
Copy link
Contributor Author

llyyr commented Sep 28, 2025

Dropped the third commit based on irc conversation, discuss it at #16844 instead

Copy link
Member

@kasper93 kasper93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fine. We can improve remaining issues later.

@kasper93 kasper93 merged commit 7037ff4 into mpv-player:master Sep 28, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants