Repository navigation
linux-pipewire: Listen to the camera registry once the connection is set - #775
Conversation
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"}
|
Rebased onto master, set On the edits to existing tests, for reviewers:
|
7082887 to
b20bf92
Compare
|
Independent red/green run of the three PipeWire camera cmocka tests. Tier 2 skips them because its image has no
RED output: GREEN output: The ENABLE_RUST_LIBOBS=ON lane was not run. |
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.
obs_pipewire_connect_fd()(plugins/linux-pipewire/pipewire.c) added the camera portal's registry listener (line 1341) and unlocked the PipeWire thread loop (line 1345) before it returned.on_pipewire_remote_opened_cb()(camera-portal.cline 1081) stored the returned connection inconnection->obs_pwonly after that.on_registry_global_cb()withconnection->obs_pwstill NULL. It reads the registry through it (line 1000,obs_pipewire_get_registry(NULL)), and for a source set to that camera it also connects the stream through it (line 287). The result is a SIGSEGV on the PipeWire thread right after[pipewire] Created registry.obs_pipewire_add_registry_listener(). The camera portal calls it onceconnection->obs_pwis set, so no registry event can arrive earlier. This is the fix the upstream reporter, TheMorpheus407, proposed and tested on Startup crash in camera portal: on_registry_global_cb reads connection->obs_pw before it is assigned obsproject/obs-studio#13971 (credited as co-author). As they suggested,obs_pipewire_connect_fd()no longer takes registry events; the screencast portal never passed any.test_pipewire_camera_unplug,test_pipewire_camera_unload) held the registry events until the first roundtrip to avoid this race. That workaround is removed.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:
linux-pipewire.solinux-pipewire.so(earlier pair)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 registryand no[camera-portal] Found deviceline, 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
test/cmocka: Add a failing test for the camera portal registry race.test_pipewire_camera_registry_race(Linux; private PipeWire daemon throughtest_pipewire_cursor_hdr.sh, private D-Bus bus, X display forobs_startup(); skips without them) runs the real camera portal against a fakeorg.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 afterobs_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()") andsaved_source_streams_the_camera("streams connected for the source: 0"). The guardcamera_is_listedpasses.ENABLE_RUST_LIBOBSOFF and ON;test_pipewire_camera_unplugandtest_pipewire_camera_unloadpass without the registry hold. Full ctest (private Xvfb, systemlibobs-openglmasked, TMPDIR unset): 216/216 in both lanes, every PipeWire/PulseAudio test ran; skipped onlyopen_crashes_without_obs_core(two tests) andtest_startup_shutdown_cycles, as on master here. CI has nopipewirebinary, so the new test builds and skips there, like the other camera tests.Checklist
master-W..., ratchets): noneAI 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