Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fallback to audio sync logic if mpv window isn't visible #15552

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Dudemanguy
Copy link
Member

This solves the problem mentioned here. If we skip rendering while the player is in display-sync mode, then there is no driver-level blocking which means mpv will go through the render loop unthrottled. Not good of course. On X11, I just ignored this problem and made it always render if we were using display sync. Wayland has its own blocking thing so it works there. So fix this by simply repurposing the already existing code path for audio sync when we hit this case. display sync is meaningless if the window is obscured and the audio sync stuff already handles all the appropriate throttling/timings for us.

x11 and wayland VOs + backends all have logic that skips drawing frames
when the mpv isn't visible for efficiency reasons. This is implemented
in each individual VO, but it is useful for the core to be aware of this
as well. Currently, the display-sync modes on x11 do not try to be
efficient and always render anyways because there is no blocking on the
graphics API level if you skip rendering a frame (wayland works here by
accident). This means mpv would otherwise blaze through frames which is
not what anyone wants. We can instead improve this by implementing the
blocking mechanism in the core and using that when appropriate. This
commit does not implement that yet, but simply switches the draw_frame
to a boolean. Receiving false means that the VO is not drawing frames
and it should be treated as if the surface was hidden.
Copy link

github-actions bot commented Dec 20, 2024

Download the artifacts for this pull request:

Windows
macOS

Copy link
Contributor

@llyyr llyyr left a comment

Choose a reason for hiding this comment

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

Works as advertised.

@kasper93 kasper93 self-requested a review December 21, 2024 02:35
The previous commit put all the pieces in place so now this can be
implemented. Scheduling frames is already written with the assumption
that display sync maybe turn on/off at any time. So all that needs to be
done is check if the VO reports that it is not visible. If so, simply
flip mpctx->display_sync_active to false for that frame and skip the
display sync frame handling. It will become true again when the mpv
window comes back into view.
When this was originally implemented, I lazily skipped the optimization
when using display sync because mpv would rip through all the frames
without waiting since there was no blocking. With the previous commits,
we now fall back on the audio sync logic when the window is not visible,
so the extra condition can be removed.
@Dudemanguy Dudemanguy force-pushed the visibility-improvements branch from cf50805 to 7715172 Compare December 21, 2024 23:06
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