Skip to content

linux-pipewire: Keep the streams of hidden screen captures paused - #1111

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/pipewire-hidden-sources-inactive
Oct 16, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/pipewire-hidden-sources-inactive

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1110

Upstream: obsproject/obs-studio#13836 (SkyKingPX; KalarianAthecila added the case of sources in other scenes). Follow-up of our #109, which already paused a hidden source's stream, but only after a reconnect.

What and why

A Screen Capture (PipeWire) source that is not showing (disabled, or in a scene that is not live) now keeps its screencast paused, so the compositor no longer copies every frame for it. Before, every screen capture streamed from the moment its portal session finished. With several captures this lags the desktop and OBS.

Cause

  • obs_pipewire_connect_stream() (plugins/linux-pipewire/pipewire.c) connected every stream active.
  • Only .hide pauses a stream, and libobs calls .hide only when a showing source stops showing. The portal session finishes after the scene collection has loaded, so a source that was never shown never got a hide.
  • plugins: Reconnect Linux capture after PipeWire restarts #109 added a hide for streams that replace a lost one. The first connect had none.

In the release (0.1.0-beta.20261014 AppImage on a private nested Hyprland 0.56.2 with xdg-desktop-portal-hyprland, its own PipeWire and WirePlumber, and one 1920x1080 headless output at 60 Hz with a clock window. A picker script answers the portal. Scene Live (current) holds a colour source, CapLive and CapDisabled with its item disabled; scene Other (not live) holds CapOther. All three capture the same output. Frames per screencast are counted from the portal's verbose log, CPU from /proc over 10 s, both stacks on the same machine):

0.1.0-beta.20261014 release + this branch's linux-pipewire.so
screencasts running after startup 3 of 3, ~53 fps each 1 of 3 (CapLive), ~52 fps; the other two suspended, 0 fps
Hyprland / OBS CPU after startup 31.7% / 34.9% 15.1% / 13.9%
CapDisabled before its first show has a picture (its stream has been running) empty (no frame yet)
CapDisabled enabled, time to a picture (source screenshot) 1-11 ms each round 35 ms the first time, 1-21 ms after
20 enable/disable rounds of CapDisabled stream running after enable 19/20 (max 105 ms), paused after disable 20/20 20/20 (max 118 ms), 20/20
restart with the saved restore tokens - no picker, 3 streams connected, 1 running

In a first release run (same setup) the three screencasts ran at ~31 fps each with Hyprland at 24.0% and OBS at 24.9%. Switching Live away and back there left only the showing source's screencast running (14.5% / 13.1%): the hide path already worked.

Fix (all in plugins/linux-pipewire)

  • obs_pipewire_connect_stream_info.inactive: connect the stream with PW_STREAM_FLAG_INACTIVE. obs_pipewire_stream_show() starts it, as before.
  • screencast-portal.c: the capture keeps showing, set by its .show and .hide callbacks, and connects a new stream inactive unless it is showing. This covers the first connect and every reconnect, so the reconnect-only hide from plugins: Reconnect Linux capture after PipeWire restarts #109 is gone. A new show_mutex keeps showing and the stream's active state together. .show/.hide run on the video thread, and the main loop connects a stream or swaps it out (destroy_live_stream(), the stream held during a reconnect) under the same lock. Without it, a show between reading the state and storing the new stream would be lost and the source would stay black. show_mutex is taken before the graphics lock and streams_mutex, and .show/.hide hold neither (libobs ticks sources outside the graphics context).

Not changed

  • Restore tokens, the portal session and when the picker appears. A source shown in Properties, Filters or a projector counts as showing, as before.
  • The one visible difference: a source shown for the first time has no old frame to show, so it is empty until its first frame (35 ms above, about two frames at 60 Hz). After that, a show displays the last frame until a new one arrives, as before.
  • The camera source (camera-portal.c) connects the same way. It is left alone: nobody has reported it, and pausing a camera before its first show would let the device stop, so the first show would wait for the camera to start where today it is already running.
  • A stream that fails before it ever streamed is still not reconnected (the streamed check in reconnect-policy.c). A paused stream does not stream until it is shown, but a compositor that ends a screencast removes its node, and that is still handled.

RED → GREEN

  • RED commit: 2d6eb0d test/cmocka: Screen captures that are not showing get frames. test_pipewire_screencast_resume gets three cases. The fake compositor now links every capture stream to its monitor (each once, as before), and the test counts the frames each stream takes (pw_stream_dequeue_buffer wrapped at link time). In both lanes:
    • sources_not_showing_keep_their_streams_inactive fails: "frames in 2 s: showing capture 60, in another scene 60, disabled 60". The two sources that are not showing should get 0.
    • Guards that pass: showing_a_source_starts_its_stream (20 rounds: change the picture while hidden, show, wait for the new picture, hide, no more frames) and sources_not_showing_stay_inactive_after_reconnect (plugins: Reconnect Linux capture after PipeWire restarts #109: after the monitor goes away and comes back, 1 stream gets frames and 2 are paused, then the reconnected hidden source streams when shown).
    • The four existing cases pass. 1 of 7 fails.
  • GREEN: 97dc538. 7/7 in both lanes (ENABLE_RUST_LIBOBS OFF and ON): "showing capture 60, in another scene 0, disabled 0". Without a display all 7 cases skip. In this test the first new frame after a show takes 216-235 ms on average, against 114-122 ms on master. Here every capture shares one producer, and on master the never-shown capture keeps it running. With one other capture kept streaming, the branch takes 95 ms. The product numbers above come from per-source screencasts, as on a desktop.
  • Full ctest at -j8 (private Xvfb, system libobs-opengl masked, TMPDIR unset): 266/266 in each lane. Skipped cases in each lane: open_crashes_without_obs_core (in test_audio_io and test_video_io, as on master), test_alloc_count_stable_after_startup (test_startup_alloc_stable, under load) and test_startup_shutdown_cycles (test_startup_cycle_stress). This branch changes neither. All PipeWire/Pulse tests ran. clang-format 22.1.3, gersemi 0.25.0 and ci/test_registration.py are clean.
  • Real app: the release table above, with this branch's linux-pipewire.so in the 0.1.0-beta.20261014 AppImage.
  • CI: test_pipewire_screencast_resume is already registered for Linux. It skips where pipewire is not installed, as before. The new link option (-Wl,--wrap=pw_stream_dequeue_buffer) applies only to this test.

Checklist

  • Base is master
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): none (a link option for one test)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): not a port

AI note: Claude Code (Claude Opus 5.5) wrote the code, the tests, the commit messages and this text under the submitter's direction, and ran the tests above on the submitter's machines.

🤖 Generated with Claude Code

rdoupe and others added 2 commits October 16, 2026 15:21
test_pipewire_screencast_resume gains three cases. Its fake compositor now
links every capture stream to the monitor (each once, as before), and the
test counts the frames each stream takes (pw_stream_dequeue_buffer,
wrapped at link time).

With a capture showing, a second one in a scene that is not live and a
third disabled in a live scene, all three streams get the monitor's frames.
Their streams connect active, and only a hide after a show pauses them, so
the compositor copies every frame for every screen capture
(obsproject/obs-studio#13836).

RED: sources_not_showing_keep_their_streams_inactive fails, "frames in 2 s:
showing capture 60, in another scene 60, disabled 60" (0 expected for the
two that are not showing). Guards that pass today:
showing_a_source_starts_its_stream (20 rounds of show, a new frame, hide,
no more frames) and sources_not_showing_stay_inactive_after_reconnect
(obs-rust#109: after the monitor comes back, only the showing capture streams).
The four existing cases still pass.

Upstream: obsproject/obs-studio#13836.

Refs obs-rust#1110.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Every Screen Capture (PipeWire) stream connected active. libobs calls
.hide only when a showing source stops showing, so a source that was
disabled or in a scene that is not live when its portal session finished
kept streaming, and the compositor copied every frame for it. With
several captures this lags the desktop and OBS
(obsproject/obs-studio#13836). Our reconnect (obs-rust#109) already paused a
replacement stream for a hidden source; the first connect did not.

The capture now remembers whether libobs last showed or hid it, and
connects its stream with PW_STREAM_FLAG_INACTIVE unless it is showing.
show() starts the stream as before. A show_mutex keeps that flag and the
stream's active state in step: show() and hide() run on the video thread,
a stream is connected or swapped out on the main loop. It is taken before
the graphics lock and streams_mutex; show() and hide() never hold either.

The camera source connects the same way but is left alone: nobody has
reported it, and pausing a never-shown camera would let the device stop,
so its first show would wait for the camera to start where today it is
already running.

GREEN for obs-rust#1110 (RED 2d6eb0d: a source in another scene and a disabled
one each got 60 frames in 2 s). Now 0 and 0, with 60 for the showing
capture. Shown 20 times, such a source got a new frame each time, and
hiding it stopped its frames. After a reconnect only the showing capture
streams.

Upstream: obsproject/obs-studio#13836.

Fixes obs-rust#1110.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rdoupe
rdoupe requested a review from zackees as a code owner October 16, 2026 19:21
@zackees
zackees added this pull request to the merge queue Oct 16, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 16, 2026
@zackees
zackees added this pull request to the merge queue Oct 16, 2026
Merged via the queue into obs-rust:master with commit 306c66a Oct 16, 2026
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

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: linux-pipewire: screen captures that are not showing keep streaming, so several captures lag the compositor (upstream #13836)

2 participants