Skip to content

linux-pipewire: Restart a camera stream for a new resolution - #934

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/pw-camera-resolution-restart
Oct 16, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/pw-camera-resolution-restart

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

Refs #933

What and why

This says Refs, not Fixes: #933 stays open after merge until the change is confirmed on real libcamera hardware (the reporter's Surface). Our check used libcamera's virtual camera.

Picking another resolution for a streaming "Video Capture Device (PipeWire)" source now restarts the camera stream at the new size. It no longer renegotiates the running stream.

  • The resolution change is EberhartLeberhart's. They traced it on bug: linux-pipewire: cameras sending NV12 show green or crash (upstream #13823) #390, wrote the patch and tested it on a Surface Pro 5 (Intel IPU3 behind libcamera, PipeWire 1.0.5). Their result there: 640x480 → 1280x720 and a switch between the front and rear camera both came back streaming, with no renegotiation and no -EPIPE. This PR takes their resolution change as is and adds a test and the framerate part below.
  • Before: format_selected() in plugins/linux-pipewire/camera-portal.c restarted the stream (stream_camera(), destroy + create) for a new subtype or pixel format. For a new resolution it called obs_pipewire_stream_set_resolution(), which renegotiates the running stream.
  • Why that breaks: a libcamera camera cannot be reconfigured while it runs. PipeWire's libcamera plugin before 1.4.9 calls Camera::configure() on the running camera anyway. libcamera refuses (Camera in Running state trying configure()), and the stream ends in res:-32 (Broken pipe) and unconnected. With PipeWire 1.0.5 (Ubuntu 24.04 and derivatives) the PipeWire daemon itself crashed in our setup. PipeWire 1.4.9 and later stop the camera first.
  • After: a resolution change takes the same stream_camera() path as a pixel-format change. The set_resolution branch is gone.
  • Framerate: when the camera lists no framerates for the selected format, format_selected() dropped a framerate kept from before with obs_pipewire_stream_set_framerate(NULL) on the running stream. On the old plugin that crashed the daemon the same way (reproduced with the release and a saved framerate, by only opening Properties). The framerate is now dropped as part of the restart. The framerate list is filled before the restart decision, so a format change and a dropped framerate give one restart, not two.
  • framerate_selected() is unchanged. PipeWire's libcamera plugin lists no framerates (1.0.5 and 1.4.11 checked; also what the reporter measured), so that callback is never reached for these cameras. On cameras that list framerates (V4L2 behind PipeWire), a picked framerate still renegotiates in place, as before.
  • pipewire.c is unchanged, so screen and window capture keep their in-place renegotiation.
  • Cost: every PipeWire camera, including V4L2 cameras that renegotiated cleanly before, now gets a short gap on a resolution change while the new stream is created and linked. On PipeWire 1.6.8 with a test camera that renegotiates cleanly, the gap from the old stream pausing to the new one streaming was 16-60 ms here (this includes our stand-in session manager's 50 ms link poll), against 1-3 ms for the old in-place renegotiation. On real hardware the camera's own stop/start time comes on top; libcamera on PipeWire 1.4.9+ pays that already, since it stops the camera to reconfigure.

Release check (AppImage v0.1.0-beta.20261014, headless: private Xvfb, dbus-run-session, fake camera portal on the private bus). Server side: a private PipeWire 1.0.5 daemon with its own libcamera SPA plugin and libcamera 0.5.2's software virtual camera (NV12, 640x480 and 320x240), both built from upstream tags. libcamera's buffer allocator was patched locally to use plain memfds, because this host gives no access to dma-heaps or udmabuf. That changes where frame memory comes from, not the camera state machine or the plugin. Client side: the AppImage's libpipewire 1.6.2. A script links each new capture port once, as a session manager would. The resolution is picked by setting the format to 320x240 (SetInputSettings) and opening Properties (OpenInputPropertiesDialog), which runs format_selected() like a click in the list.

Plugin in the AppImage PipeWire 1.0.5 + libcamera virtual camera, 640x480 → 320x240
v0.1.0-beta.20261014 (as released) Renegotiating stream → res:-32 (Broken pipe) → unconnected. libcamera: Camera in Running state trying configure(). The daemon segfaults in the plugin's requestComplete(). The preview freezes.
master same
this branch old stream unconnected (no error) → new stream → Size: 320x240 → streaming, preview live. Two more switches (→ 640x480 → 320x240) the same. No libcamera error, daemon up.
release, saved 15 FPS, only opening Properties Renegotiating stream → Broken pipe → daemon crash
this branch, same one restart (640x480 30/1, streaming); the next Properties pass: no restart, no renegotiation

On the host's PipeWire 1.6.8 with a fake camera that renegotiates cleanly (V4L2-like), this branch also changes resolution, with the restart gap above. We showed this with a software camera only. It still has to be confirmed on real libcamera hardware.

RED → GREEN

  • RED commit: 0d72766 test/cmocka: Add failing test for a PipeWire camera resolution change.
    • test_pipewire_camera_resolution_restart runs the real camera portal against a fake org.freedesktop.portal.Camera on a private D-Bus bus (GTestDBus) and a private PipeWire daemon (test_pipewire_cursor_hdr.sh), like test_pipewire_camera_renegotiate.
    • A stream node plays the old libcamera plugin: YUY2 64x48 or 32x24, one EnumFormat per size, no framerates. It refuses a second format without a clear in between (pw_stream_set_error), like Camera::configure() on a running camera.
    • 2 of 3 fail in both lanes:
      • resolution_change_restarts_the_stream: "the streaming camera was asked for 32x24 in place 1 time(s)".
      • dropped_framerate_does_not_reconfigure: "opening Properties asked the streaming camera for a new format 1 time(s) in place".
    • camera_streams (guard) passes.
  • GREEN: fc16f3b, 3 of 3 with ENABLE_RUST_LIBOBS OFF and ON.
    • The resolution case also checks one new stream at 32x24 and back at 64x48, no Renegotiating stream, and the camera streaming at the new size.
    • Other camera tests: the other six test_pipewire_camera_* tests (control_refresh, nv12, registry_race, renegotiate, unload, unplug) pass in both lanes. 15 repeats of the new test: all passed. With DISPLAY unset, its cases skip.
    • Full ctest (private Xvfb, system libobs-opengl masked, TMPDIR unset): 250/250 with ENABLE_RUST_LIBOBS OFF and 250/250 ON. Every PipeWire/PulseAudio test ran. Skipped cases: open_crashes_without_obs_core (test_audio_io, test_video_io), and test_startup_alloc_stable / test_startup_cycle_stress, which skip with the system GL module masked.
    • clang-format, gersemi, ci/test_registration.py and ci/test_cmocka_sanitize.py clean.

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 test, the commit messages and this text under the submitter's direction, applied the reporter's fix, and ran the tests above on the submitter's machines.

🤖 Generated with Claude Code

@zackees zackees added the ci-full Run every CI job on this PR, including the release-gating OBS app builds and Flatpak label Oct 16, 2026
@zackees
zackees enabled auto-merge October 16, 2026 00:54
@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
rdoupe and others added 2 commits October 15, 2026 20:24
Picking another resolution in the format list of a streaming "Video
Capture Device (PipeWire)" source renegotiates the running stream in
place: format_selected() calls obs_pipewire_stream_set_resolution(). A
camera behind libcamera cannot be reconfigured while it delivers, and
PipeWire's libcamera plugin before 1.4.9 does not stop it first, so the
stream dies ("Broken pipe", then "unconnected"; with PipeWire 1.0.5 the
whole daemon crashes). Reported on a Surface Pro 5 with an IPU3 camera
in obs-rust#390, upstream obsproject/obs-studio#10399.

The same happens when the format list drops a framerate kept from
before (the camera lists none for the format): format_selected() then
calls obs_pipewire_stream_set_framerate(NULL) on the running stream.

test_pipewire_camera_resolution_restart runs camera-portal.c against a
fake camera portal on a private D-Bus bus and a camera node on a
private PipeWire daemon. The node plays a libcamera camera: YUY2 at
64x48 or 32x24, one EnumFormat per size, no framerates, and it refuses
a second format without a clear in between, like the old plugin. Two of
three cases fail: opening Properties with a kept framerate asks the
running camera for a new format, and picking 32x24 renegotiates the
running stream instead of starting a new one.

Needs an X display for obs_startup(), dbus-daemon and pipewire; skips
without them.

Refs obs-rust#933.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
format_selected() restarted the camera stream (stream_camera()) for a
new subtype or pixel format, but renegotiated a running stream in place
for a new resolution. Cameras behind libcamera cannot be reconfigured
while they deliver; with PipeWire's libcamera plugin before 1.4.9 the
stream then dies ("Broken pipe", then "unconnected"), and with PipeWire
1.0.5 the daemon crashes. A new resolution now restarts the stream like
a new pixel format does.

When the camera lists no framerates for the selected format, a
framerate kept from before was dropped with
obs_pipewire_stream_set_framerate(NULL), which renegotiated the running
stream in the same way. It is now dropped as part of the restart.

The framerate list is filled before the restart decision.
framerate_selected() is unchanged: PipeWire's libcamera plugin lists no
framerates (1.0.5 and 1.4.11 checked), so it is not reached for these
cameras.

The resolution change and its hardware test on an IPU3 camera come from
the reporter of obs-rust#390.

test_pipewire_camera_resolution_restart: 3 of 3 pass.

Refs obs-rust#933.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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