Skip to content

linux-pipewire: Listen to the camera registry once the connection is set - #775

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/pw-camera-registry-race
Oct 14, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/pw-camera-registry-race

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

Fixes #774

What and why

OBS no longer crashes at startup when the scene collection has a "Video Capture Device (PipeWire)" source and the camera portal's PipeWire thread wins a race against the main thread.

Reproduced in release v0.1.0-beta.20261014 (AppImage, headless: private Xvfb, a private D-Bus session with a fake camera portal, a private PipeWire daemon with WirePlumber and no device monitors, 8 producers posing as 640x480 NV12 cameras, one busy loop per core and 30 more PipeWire nodes). The saved scene collection has 8 PipeWire camera sources. Each run is a cold start: OBS starts, all 8 cameras negotiate, then OBS gets SIGTERM. The two builds of each pair ran side by side:

Build Starts Crashed at startup
release 200 4
same AppImage with this branch's linux-pipewire.so 200 0 (8 of 8 cameras negotiated and a clean quit in 200 of 200)
release (earlier pair) 200 6
same AppImage with this branch's linux-pipewire.so (earlier pair) 200 0

In total, 10 of 400 against 0 of 400. Every startup crash was a SIGSEGV on the PipeWire thread, with the log ending at [pipewire] Created registry and no [camera-portal] Found device line, which is the upstream report's signature. The swapped plugin ran with the AppImage's own libobs. It loaded the AppImage's libpipewire (1.6.2) in the earlier pair and the system's (1.6.8, the build's RUNPATH) in the first pair, which made no difference: 0 crashes in both pairs.

RED → GREEN

  • RED commit: ef8271f test/cmocka: Add a failing test for the camera portal registry race. test_pipewire_camera_registry_race (Linux; private PipeWire daemon through test_pipewire_cursor_hdr.sh, private D-Bus bus, X display for obs_startup(); skips without them) runs the real camera portal against a fake org.freedesktop.portal.Camera, with a video source node in the test as the camera, like the unplug and unload tests. A source is set to the camera before the camera portal connects, as when a saved scene collection loads. The test links with --wrap: it holds the camera portal right after obs_pipewire_connect_fd() returns, until a roundtrip shows that the registry has delivered its globals, which makes the race deterministic, and it counts the calls made with a NULL connection instead of letting them crash. 2 of 3 cases fail in both lanes: registry_events_wait_for_the_connection ("calls with no connection yet: 3 obs_pipewire_get_registry(), 1 obs_pipewire_connect_stream()") and saved_source_streams_the_camera ("streams connected for the source: 0"). The guard camera_is_listed passes.
  • GREEN: 7082887. 3 of 3 with ENABLE_RUST_LIBOBS OFF and ON; test_pipewire_camera_unplug and test_pipewire_camera_unload pass without the registry hold. Full ctest (private Xvfb, system libobs-opengl masked, TMPDIR unset): 216/216 in both lanes, every PipeWire/PulseAudio test ran; skipped only open_crashes_without_obs_core (two tests) and test_startup_shutdown_cycles, as on master here. CI has no pipewire binary, so the new test builds and skips there, like the other camera tests.

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
  • 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 test, 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
rdoupe requested a review from zackees as a code owner October 14, 2026 22:27
@zackees zackees added the ci-full Run every CI job on this PR, including the release-gating OBS app builds and Flatpak label Oct 14, 2026
rdoupe and others added 2 commits October 14, 2026 15:31
on_pipewire_remote_opened_cb() stores the camera portal's PipeWire
connection only after obs_pipewire_connect_fd() returns, but that
function has already added the registry listener and let the PipeWire
thread run. Registry globals that arrive in between reach
on_registry_global_cb() while connection->obs_pw is still NULL.

The test holds the camera portal right after obs_pipewire_connect_fd()
returns, until a roundtrip shows that the registry has delivered its
globals, and counts the calls made with a NULL connection instead of
letting them crash. A source set to the camera exists before the
connection, as when a saved scene collection is loaded at startup.

Refs obs-rust#774.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
obs_pipewire_connect_fd() added the camera portal's registry listener
and unlocked the PipeWire thread before returning, and the camera portal
stored the connection in connection->obs_pw only after that. A registry
global delivered in between reached on_registry_global_cb() with
connection->obs_pw still NULL, which it dereferences to bind the node and
to connect a source's stream: a crash at startup with a saved PipeWire
camera source.

Add obs_pipewire_add_registry_listener() and call it after the
assignment, so no registry event can arrive before the connection is
set. This is the fix TheMorpheus407 proposed and tested upstream. As
suggested there, obs_pipewire_connect_fd() no longer takes registry
events; the screencast portal never passed any.

The camera unplug and unload tests no longer need to hold the registry
events until the first roundtrip.

Fixes obs-rust#774.

Co-Authored-By: TheMorpheus407 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=a4e114082ce8564d85b3244299637b4c4f05b8c2 secs=532 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run
Ci-Attestation: {"at":1792017594,"gate":"rust/all/fmt","host":"linux-x86_64","key":"72c9438302e8fa2a1a847102d5c2f36db11ec3f6240bd39af9e24c2d8f2b2e34","lane":"lint","parents":["7a2f78465676e6c8951b272e25078fcae6943dff"],"secs":58,"stamp":"c329b59bbe1ce8fdca0a48b72b650dec","tree":"a4e114082ce8564d85b3244299637b4c4f05b8c2","v":1,"via":"run"}
Ci-Attestation: {"at":1792017594,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"72c9438302e8fa2a1a847102d5c2f36db11ec3f6240bd39af9e24c2d8f2b2e34","lane":"lint","parents":["7a2f78465676e6c8951b272e25078fcae6943dff"],"secs":58,"stamp":"d8e8ac506abaaf8b6930ecc53d766142","tree":"a4e114082ce8564d85b3244299637b4c4f05b8c2","v":1,"via":"run"}
Ci-Attestation: {"at":1792017594,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"666e22193c084fa36c0ff10e2e534889ef73a4cfbf3446cb6dab47c1adf7e446","lane":"rust-test","parents":["7a2f78465676e6c8951b272e25078fcae6943dff"],"secs":127,"stamp":"2e515bea032357fc8e23c57c3a344cd2","tree":"a4e114082ce8564d85b3244299637b4c4f05b8c2","v":1,"via":"run"}
Ci-Attestation: {"at":1792017594,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"23901b9b59943eb3eeb69964b7d0350a1210c65038ba7b123087ce7e9db4353a","lane":"cross","parents":["7a2f78465676e6c8951b272e25078fcae6943dff"],"secs":115,"stamp":"25fb5c8e171bf2738f53cac9580aae6c","tree":"a4e114082ce8564d85b3244299637b4c4f05b8c2","v":1,"via":"run"}
Ci-Attestation: {"at":1792017594,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"23901b9b59943eb3eeb69964b7d0350a1210c65038ba7b123087ce7e9db4353a","lane":"cross","parents":["7a2f78465676e6c8951b272e25078fcae6943dff"],"secs":115,"stamp":"abf7c59cb278750a6c31af8859ed165d","tree":"a4e114082ce8564d85b3244299637b4c4f05b8c2","v":1,"via":"run"}
Ci-Attestation: {"at":1792017594,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"23901b9b59943eb3eeb69964b7d0350a1210c65038ba7b123087ce7e9db4353a","lane":"cross","parents":["7a2f78465676e6c8951b272e25078fcae6943dff"],"secs":115,"stamp":"96110cec7fc2ea56d34e3b7e33157b85","tree":"a4e114082ce8564d85b3244299637b4c4f05b8c2","v":1,"via":"run"}
Ci-Attestation: {"at":1792017594,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"23901b9b59943eb3eeb69964b7d0350a1210c65038ba7b123087ce7e9db4353a","lane":"cross","parents":["7a2f78465676e6c8951b272e25078fcae6943dff"],"secs":115,"stamp":"8d91e9d94bad2598688a7ff88a7107f3","tree":"a4e114082ce8564d85b3244299637b4c4f05b8c2","v":1,"via":"run"}
Ci-Attestation: {"at":1792017594,"gate":"rust/x86_64-apple-darwin/clippy","host":"linux-x86_64","key":"23901b9b59943eb3eeb69964b7d0350a1210c65038ba7b123087ce7e9db4353a","lane":"cross","parents":["7a2f78465676e6c8951b272e25078fcae6943dff"],"secs":115,"stamp":"c7af56da0f7a1aea9fa5fb88b41cd7fc","tree":"a4e114082ce8564d85b3244299637b4c4f05b8c2","v":1,"via":"run"}
Ci-Attestation: {"at":1792017594,"gate":"rust/x86_64-apple-darwin/dylint","host":"linux-x86_64","key":"23901b9b59943eb3eeb69964b7d0350a1210c65038ba7b123087ce7e9db4353a","lane":"cross","parents":["7a2f78465676e6c8951b272e25078fcae6943dff"],"secs":115,"stamp":"2d8c6ab24c42d1bef6874d744bc0202d","tree":"a4e114082ce8564d85b3244299637b4c4f05b8c2","v":1,"via":"run"}
Ci-Attestation: {"at":1792017594,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"6e2dffb2591bc1be33d58905d5801cd0e3870dc4ccfa21f52a0b0527d1a110c0","lane":"tier2-linux","parents":["7a2f78465676e6c8951b272e25078fcae6943dff"],"secs":233,"stamp":"1c99af69ef9b3aa93d4204ff83749f78","tree":"a4e114082ce8564d85b3244299637b4c4f05b8c2","v":1,"via":"run"}
@zackees

zackees commented Oct 14, 2026

Copy link
Copy Markdown
Member

Rebased onto master, set ci-full (plugin change), and ran the stamped local gate (Tier 2 runs the PipeWire tests). Your RED/GREEN evidence above stands.

On the edits to existing tests, for reviewers: test_pipewire_camera_nv12.c and test_pipewire_context_fail.c only follow the plugin-internal obs_pipewire_connect_fd() signature change (pipewire.h is the plugin's own header, not a public libobs header). The ~50 lines removed from test_pipewire_camera_unload.c / _unplug.c were a registry-event gate whose own comment said it existed to sidestep this exact race (obsproject/obs-studio#13971); with the race fixed, the workaround goes. Neither weakens what those tests check.

  • Rebased on master, local gate passed; pushed as b20bf92.

@zackees

zackees commented Oct 14, 2026

Copy link
Copy Markdown
Member

Independent red/green run of the three PipeWire camera cmocka tests. Tier 2 skips them because its image has no pipewire or dbus-daemon (#776), so I ran them in the Tier 2 image (ubuntu:26.04, libobs + cmocka, ENABLE_RUST_LIBOBS=OFF) with pipewire dbus dbus-daemon xvfb xauth wireplumber pipewire-pulse added, under xvfb-run ctest -R "test_pipewire_camera_(registry_race|unload|unplug)". The test wrapper starts its own private PipeWire daemon and the test starts a fake portal on a private D-Bus bus, so WirePlumber was not needed. All three ran; none was Skipped.

Test RED 7a2f784 GREEN b20bf92 (PR head)
test_pipewire_camera_registry_race Failed (2 of 3 cases) Passed (3 of 3)
test_pipewire_camera_unload Passed Passed
test_pipewire_camera_unplug Passed Passed

RED output:

calls with no connection yet: 3 obs_pipewire_get_registry(), 1 obs_pipewire_connect_stream()
registry events reached the camera portal before it had its PipeWire connection
[  FAILED  ] registry_events_wait_for_the_connection
streams connected for the source: 0
the source set to "obs-test-camera" never connected a stream
[  FAILED  ] saved_source_streams_the_camera

GREEN output:

calls with no connection yet: 0 obs_pipewire_get_registry(), 0 obs_pipewire_connect_stream()
streams connected for the source: 1

The ENABLE_RUST_LIBOBS=ON lane was not run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-full Run every CI job on this PR, including the release-gating OBS app builds and Flatpak

Projects

Status: Done

2 participants