-
-
Notifications
You must be signed in to change notification settings - Fork 9k
linux-capture: Make X11 display captures handle resolution changes #12937
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
base: master
Are you sure you want to change the base?
linux-capture: Make X11 display captures handle resolution changes #12937
Conversation
5806da1 to
c8f04f0
Compare
|
|
||
| data->xshm = xshm_xcb_attach(data->xcb, data->adj_width, data->adj_height); | ||
| if (!data->xshm) { | ||
| blog(LOG_ERROR, "failed to attach shm after resize!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving the wrong sized texture hanging here might cause rendering to be weird
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, xshm_video_tick should early-return if this branch is taken but not necessarily xshm_video_render. I've pushed a commit that destroys the texture if this fails, so we don't risk rendering a texture with inconsistent dimensions in any case.
The XSHM display source has been unable to handle screen resolution changes on the fly for over 11 years (see commit 76d2bf2): when screen resolution changes while such a source is active, the source fails to resize accordingly, resulting in incorrect output. While this rarely affects the most typical workflows, as users seldom change physical display resolutions while recording, it becomes a more significant issue with virtual displays and multi-monitor setups. For example, virtual screens created by remote desktop clients like xrdp may be frequently resized during window drag and resize operations. I have identified and tried several workarounds, but none are ideal: - The third-party [`obs-gstreamer` plugin](https://github.com/fzwoch/obs-gstreamer) can delegate screen capturing to [GStreamer's `ximagesrc` element](https://gstreamer.freedesktop.org/documentation/ximagesrc/index.html). However, this incurs higher CPU usage than the native XSHM source. - Manually changing any source configuration parameter triggers `xshm_update`, restarting the capture with the new screen geometry. But manual solutions are inconvenient, and may cause visible artifacts while being applied. - A custom OBS plugin or WebSocket client could listen for resolution changes and automate the above workaround, but this solution is inelegant and beyond most users' reach. Thus, this commit fixes the problem at its root by following an approach inspired by other sources and GStreamer's `ximagesrc`: checking for screen geometry changes on each video tick. When a change is detected, the OBS and XSHM textures are resized to match, avoiding unnecessary reinitialization steps for better performance. I didn't observe any material performance impact in the happy path of a constant screen resolution.
c8f04f0 to
4b0db51
Compare
Motivation and Context
The XSHM display source has been unable to handle screen resolution changes on the fly for over 11 years (see commit
76d2bf2): when screen resolution changes while such a source is active, the source fails to resize accordingly, resulting in incorrect output.While this rarely affects the most typical workflows, as users seldom change physical display resolutions while recording, it becomes a more significant issue with virtual displays and multi-monitor setups. For example, virtual screens created by remote desktop servers like xrdp may be frequently resized during client window drag and resize operations.
I have identified and tried several workarounds, but none are ideal:
obs-gstreamerplugin can delegate screen capturing to GStreamer'sximagesrcelement. However, this incurs higher CPU usage than the native XSHM source.xshm_update, restarting the capture with the new screen geometry. But manual solutions are inconvenient, and may cause visible artifacts while being applied.Description
These changes fix the problem described above at its root by following an approach inspired by other sources and GStreamer's
ximagesrc: checking for screen geometry changes on each video tick. When a change is detected, the OBS and XSHM textures are resized to match, avoiding unnecessary reinitialization steps for better performance. I didn't observe any material performance impact in the happy path of a constant screen resolution.How Has This Been Tested?
I've built OBS 32.0.4 from source on a Debian Unstable X11 environment, both with and without this patch. Then I manually tested the two builds side by side, and confirmed that this patch fixes the intended issue without introducing any regressions. I conducted my tests under the xorgxrdp X server.
Types of changes
Checklist: