Skip to content

linux-capture: XComposite backs off the window search while the window is unmapped (#1357) - #1366

Merged
zackees merged 3 commits into
masterfrom
fix/1357-xcomposite-search-backoff
Oct 17, 2026
Merged

zackees merged 3 commits into
masterfrom
fix/1357-xcomposite-search-backoff

Conversation

@zackees

@zackees zackees commented Oct 17, 2026

Copy link
Copy Markdown
Member

Refs #1357 (parent #1273). No closing keyword: the real app was not run.

Cause

xcompcap_video_tick treats a non-viewable window (minimized, other workspace) as lost. Every 2 s (FIND_WINDOW_INTERVAL), under obs_enter_graphics(), it ran xcomp_find_window (client list + per-window name/class round trips) and tore down/recreated the watcher and pixmap, even when the search returned the same XID. Forever.

Design

Decision factored into pure static inline helpers in plugins/linux-capture/xcomposite-search.h (included via the group PCH):

  • xcomp_search_due: search at once when window_changed (watcher saw Map/Configure/Expose/Visibility/Destroy on the target), else when lost and the interval has passed.
  • xcomp_search_needs_rebuild: no watcher/pixmap rebuild when the search found the same XID and it is still not viewable (and not forced).
  • xcomp_search_done: interval doubles 2 -> 4 -> 8 -> 16 -> 30 s cap on a miss; resets to 2 s on capture or a forced search. xcompcap_update (settings) resets it too.

Recovery: MapNotify reaches the watcher (already subscribed with StructureNotifyMask on the unmapped window), sets window_changed, and the next tick searches and rebuilds immediately, as today. A new XID (relaunched app) still rebuilds; DestroyNotify resets the backoff.

Tests

New test/cmocka/test_xcomposite_search_backoff.c (tests.d fragment, cmocka only, no X): 60 s of simulated 1/60 s ticks with the window unmapped -> 3..6 searches (old: 29), 0 rebuilds; map event resets; window_changed forces an immediate search; rebuild rules.

  • RED (e2ef500, stubs keeping today's behavior): 4 FAILED TEST(S), 1 of 293 failed.
  • GREEN: rust/tools/linux-validate/run.sh --repeat 1 --tests 'xcomposite|linux.capture|x11': 100% of 293 passed in OFF and ON builds.
    No Xvfb end-to-end case: the harness has no existing xcomposite/linux-capture test, so it would need a full plugin load + window manager; not cheap. There were no prior linux-capture tests to regress. Plugin compile is covered by PR CI (no X headers on the host).

Tiers: Tier 2/3/4 do not apply (C plugin, no Rust port).

…apped (#1357)

Pure decision helpers in xcomposite-search.h are stubs that keep today's
behavior (search every tick it is due, rebuild every time); the new cmocka
test fails 4/4.

Refs #1357
…pped (#1357)

While the captured window was not viewable (minimized, other workspace) the
tick searched the client list and rebuilt the pixmap and watcher every 2 s
forever. Now a search that finds the same, still unmapped window rebuilds
nothing, and the interval doubles 2 -> 30 s. MapNotify/ConfigureNotify (via
the watcher's window_changed), new settings and a successful capture reset
it, so recovery is as fast as before.

Refs #1357
@zackees
zackees enabled auto-merge October 17, 2026 23:27
@zackees
zackees added this pull request to the merge queue Oct 17, 2026
Merged via the queue into master with commit a994939 Oct 17, 2026
23 checks passed
zackees added a commit that referenced this pull request Oct 18, 2026
…f a round trip per frame (#1356)

xcompcap_video_tick called xcomp_window_exists (xcb_get_window_attributes
request + reply) once or twice per frame under obs_enter_graphics and the
source lock. The watcher now feeds Map/Unmap/DestroyNotify into a cached
presence state; the tick reads the cache, reads events with the
non-blocking xcb_poll_for_event (and frees them), and asks the server only
after window_changed/new settings and at most once a second as a safety
net, before obs_enter_graphics. #1366's search backoff is unchanged.

Refs #1356
zackees added a commit that referenced this pull request Oct 18, 2026
…f a round trip per frame (#1356)

xcompcap_video_tick called xcomp_window_exists (xcb_get_window_attributes
request + reply) once or twice per frame under obs_enter_graphics and the
source lock. The watcher now feeds Map/Unmap/DestroyNotify into a cached
presence state; the tick reads the cache, reads events with the
non-blocking xcb_poll_for_event (and frees them), and asks the server only
after window_changed/new settings and at most once a second as a safety
net, before obs_enter_graphics. #1366's search backoff is unchanged.

Refs #1356
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 18, 2026
…f a round trip per frame (obs-rust#1356) (obs-rust#1377)

* test(linux-capture): RED, XComposite asks the X server whether its window exists every frame (obs-rust#1356)

Pure presence helpers stubbed to today's behaviour (a round trip per
tick, events ignored); the new cmocka test counts round trips.

Refs obs-rust#1356

* linux-capture: XComposite tracks window state from X events instead of a round trip per frame (obs-rust#1356)

xcompcap_video_tick called xcomp_window_exists (xcb_get_window_attributes
request + reply) once or twice per frame under obs_enter_graphics and the
source lock. The watcher now feeds Map/Unmap/DestroyNotify into a cached
presence state; the tick reads the cache, reads events with the
non-blocking xcb_poll_for_event (and frees them), and asks the server only
after window_changed/new settings and at most once a second as a safety
net, before obs_enter_graphics. obs-rust#1366's search backoff is unchanged.

Refs obs-rust#1356

* docs(features): XComposite window state from X events (obs-rust#1377)

Refs obs-rust#1356

* test(linux-capture): XComposite capture follows map/unmap/destroy end to end under Xvfb (obs-rust#1356)

Compiles the linux-capture unity file into a cmocka test, publishes a
minimal EWMH setup in place of a window manager, and drives a plain xcb
window through map, three unmap/map rounds and destroy while libobs ticks
the real xcomposite source. Unmap must unhook within 400 ms (well under
the 1 s safety net, so it comes from the UnmapNotify read by
xcb_poll_for_event), map must re-hook within 2 s, destroy must unhook.
Xvfb's llvmpipe cannot import the window pixmap as an EGLImage, so the
capture's texture is not checked; the hooked state is.

Refs obs-rust#1356
@zackees
zackees deleted the fix/1357-xcomposite-search-backoff branch October 26, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant