Repository navigation
linux-v4l2: recover a camera another process holds (EBUSY): name it, Force Camera, auto-retry - #800
Merged
Merged
Conversation
zackees
marked this pull request as ready for review
October 15, 2026 04:56
… retry (#799) test_v4l2_busy pins the new plain-C unit v4l2-busy.c against stubs: find the process holding the device in a fake /proc tree and in the real /proc (a forked helper holding a device node), SIGTERM it only when it belongs to the same user, never escalate to SIGKILL, and back off retries 2 s -> 30 s. Refs #799
When opening or setting up the device fails with EBUSY, the source finds the
process holding it (/proc/<pid>/fd), logs and shows it in the properties
("/dev/video0 is in use by obs (PID 1234)", calling out another OBS
instance), and offers a Force Camera button for a holder of the same user.
Force Camera sends SIGTERM, waits up to 5 s for the device to be released and
opens it; it never escalates to SIGKILL. A busy source rechecks once a second
on the UI thread and opens the device as soon as the holder lets go, or on a
2 s -> 30 s backoff when the holder cannot be seen (another user).
Fixes #799
test_v4l2_busy_signal runs the real v4l2-input.c on a real libobs source against a fake libv4l2 that is busy while a forked helper holds the device. It expects one global source_device_busy signal naming the holder (for the frontend's popup), a force_camera proc that closes the holder with SIGTERM and opens the camera, no SIGKILL for a holder that refuses, and a retry from video_tick once the holder exits. Refs #799
The v4l2 source emits the global signal source_device_busy (source, device, holder name and PID, whether it is another OBS, whether it may be closed) once per busy episode, and registers the proc force_camera(out bool released). The frontend declares the signal before plugins load and shows a modal "Camera is in use" dialog naming the holder, with a Force Camera button (only for a process of the same user) that calls the proc and reports when the holder did not close. One popup per device at a time. Fixes #799
zackees
force-pushed
the
fix/799-v4l2-busy-camera
branch
from
October 15, 2026 05:35
1c279e2 to
1a7a805
Compare
This was referenced Oct 15, 2026
zackees
added a commit
that referenced
this pull request
Nov 6, 2026
…ements (#3724) OBSCameraBusy names the device and every holder and waits for a click: Close it, Ignore, Always allow. It is a child of the main window (its transient parent), window type exactly Qt::Dialog, non-modal, never on top. Two traps the Qt test caught: masking out Qt::Tool clears the Dialog type bits too (Tool is a type, not a flag), which made the window a child widget inside the main window; and QDialogButtonBox makes its first AcceptRole button the default on show, so Enter answered Always allow. Always allow is an ActionRole button for that reason, and no button is auto-default. CameraBusy scans /proc off the UI thread, asks rust/obs-camera-busy whether to show, logs every warning and answer, and runs Close it on a worker thread. In the background the window shows without activating and the taskbar entry is alerted; while the main window is hidden or minimized the warning waits for it. The C rollback build keeps #800's popup. linux-v4l2 announces source_device_opened/closed so the frontend can watch the node for other programs opening it while OBS holds it. The existing v4l2 C tests are unchanged; an undeclared signal is a no-op there.
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Nov 6, 2026
…ery holder, later opens (obs-rust#3724) (obs-rust#3725) * obs-camera-busy: RED: the camera-busy warning's core as todo!() stubs (obs-rust#3724) Tier 1 tests for the decision core of the camera-busy warning: holder scan over a fixture /proc tree, display names, the allowlist, dedupe and rate limit, what an answer does, Close it's SIGTERM -> SIGKILL sequence, the log lines, the inotify watcher and the C ABI. They run as a module of obs-tests-gpu, the frontend's Rust test category, like obs-fallback-warning's. RED: 39 of 40 fail on todo!(); the ffi module aborts the binary (a todo!() cannot unwind out of extern "C"). * obs-camera-busy: GREEN: holders, decisions, Close it and the watcher (obs-rust#3724) The core of the camera-busy warning. Holders come from the fd links of a /proc tree under a caller-supplied root. A holder's name is its exe's file name unless comm disagrees: comm is the exe name cut to 15 bytes, so when it is not a prefix the binary is multicall (NixOS's sleep is coreutils) or it renamed itself, and comm is what ps shows. Nix's .foo-wrapped is foo. One dialog per device and app at a time, then 60 s of quiet after an answer. An open that nobody holds 500 ms later (OBS reopening its own camera, a browser probing every /dev/video*) is not reported. Close it sends SIGTERM, then SIGKILL after 2 s, by the maintainer's decision on obs-rust#3724 (obs-rust#799 had said SIGTERM only; the properties-panel Force Camera button keeps that). A zombie counts as gone: an exited child holds no fd. The crate links into the frontend through obs-frontend, not libobs, so it needs no rust-exports.d/rust-hidden.d fragment and Tier 2 never builds it (local-gate.toml exclude). Its platform/mod.rs is a new crate's shared platform boundary (ci/shared-build-files.txt). 46 camera_busy tests pass in obs-tests-gpu. * frontend, linux-v4l2: the camera-busy window, glue and device announcements (obs-rust#3724) OBSCameraBusy names the device and every holder and waits for a click: Close it, Ignore, Always allow. It is a child of the main window (its transient parent), window type exactly Qt::Dialog, non-modal, never on top. Two traps the Qt test caught: masking out Qt::Tool clears the Dialog type bits too (Tool is a type, not a flag), which made the window a child widget inside the main window; and QDialogButtonBox makes its first AcceptRole button the default on show, so Enter answered Always allow. Always allow is an ActionRole button for that reason, and no button is auto-default. CameraBusy scans /proc off the UI thread, asks rust/obs-camera-busy whether to show, logs every warning and answer, and runs Close it on a worker thread. In the background the window shows without activating and the taskbar entry is alerted; while the main window is hidden or minimized the warning waits for it. The C rollback build keeps obs-rust#800's popup. linux-v4l2 announces source_device_opened/closed so the frontend can watch the node for other programs opening it while OBS holds it. The existing v4l2 C tests are unchanged; an undeclared signal is a no-op there. * linux-v4l2: announce the device only for a source libobs runs; camera_busy fixture tests on Linux only (obs-rust#3724) The v4l2 C tests create the source with no obs_source_t and libobs not started, and obs_get_signal_handler() dereferences the unstarted core: every test_v4l2_* that opens the fake camera segfaulted (and asan then reported the leaks of the dead process). Check the source first, as there is nobody to tell without one. The /proc fixture tests expect can_close, which needs the owner uid that only the Linux platform reads; macOS has no V4L2 and reported false.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #799
A camera another process holds open (EBUSY) used to leave the
v4l2_inputsource dead, with only a log line. Seen with a stock OBS left running that held/dev/video0, so OBS-Studio-Rust showed no camera.What changes
New plain-C unit
plugins/linux-v4l2/v4l2-busy.c, wired intov4l2-input.c:/proc/<pid>/fd, resolving symlinks such as/dev/v4l/by-id. The log and a warning at the top of the source properties say "/dev/video0 is in use by obs (PID 1234)". Another OBS instance is called out as the common case.video_tick) and opens the device as soon as the holder lets go. When the holder can't be seen (it belongs to another user), it retries with a backoff from 2 s up to 30 s.Tests
7f93686b5:test_v4l2_busyfails, 9/11 cases.tier2-linuxlane: 234/234 pass, both OFF and ON.test_v4l2_busycovers:/proctree, including excluding OBS's own pid and a by-id symlink;/proc, SIGTERM releases it, a holder owned by another uid is refused, and a helper that ignores SIGTERM times out and is not killed;The C sources of the existing v4l2 tests were not edited. Their
tests.dCMake files that compilev4l2-input.cnow also compilev4l2-busy.c.Popup ("Camera is in use" + Force Camera)
source_device_busy(source, device, holder name and PID,is_obs,can_force) once per busy episode. It also registers the procforce_camera(out bool released).OBSBasic_DeviceBusy.cpp) declares the signal before plugins load and shows a modal Camera is in use dialog that names the holder. The dialog has a Force Camera button, shown only for a process of the same user, which calls the proc and reports when the holder did not close. Only one popup per device is shown at a time.test_v4l2_busy_signal: 3/4 cases failed. GREEN: localtier2-linuxlane passes 235/235, OFF and ON. The test runs the realv4l2-input.con a real libobs source with forked holders, and checks that the signal fires once, thatforce_cameracloses the holder with SIGTERM and reopens the device, that a holder that refuses is not killed, and the auto-retry throughvideo_tick.