Skip to content

linux-v4l2: camera-busy warning: Close it / Ignore / Always allow, every holder, later opens (#3724) - #3725

Merged
zackees merged 4 commits into
masterfrom
fix/3724-camera-busy
Nov 6, 2026
Merged

zackees merged 4 commits into
masterfrom
fix/3724-camera-busy

Conversation

@zackees

@zackees zackees commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Refs #3724 (follow-up of #799 / #800).

A general camera-busy warning for the V4L2 camera source, for any camera and any app holding it.

What it does

  • Detection. EBUSY on open / REQBUFS / STREAMON (the existing source_device_busy signal from linux-v4l2: recover a camera another process holds (EBUSY): name it, Force Camera, auto-retry #800), and another program opening the device while OBS holds it: the plugin now announces source_device_opened / source_device_closed, and the frontend puts an inotify IN_OPEN watch on the node, on its own thread. It looks who holds the device 500 ms after an open, so OBS's own reopen and programs that only probe /dev/video* are not reported.
  • Holders. Every process other than OBS with an fd on the device, from /proc/<pid>/fd (the root is a parameter, so tests use fixture trees). The name is the exe's file name, or comm when they disagree (multicall binaries such as NixOS's coreutils sleep, or apps that renamed themselves); Nix's .foo-wrapped shows as foo.
  • Dialog "Camera is in use", naming the device and each app with its PID. It waits for a click: no countdown, no default button (Enter answers nothing).
  • No stacking. One dialog per device + app at a time, then 60 s of quiet after an answer.
  • Window. A child of the OBS main window (its transient parent), window type exactly Qt::Dialog, non-modal, no WindowStaysOnTopHint, not Tool. While OBS is in the background it shows with WA_ShowWithoutActivating and QApplication::alert, so it never takes the focus from the user's current app. While the main window is hidden or minimized the warning waits and shows when the window comes back. No desktop notifications.
  • Log. A [camera-busy] blog line for every warning (including the suppressed ones, with the reason), every answer, and every Close it result.
  • The C rollback build (no frontend Rust) keeps linux-v4l2: recover a camera another process holds (EBUSY): name it, Force Camera, auto-retry #800's popup unchanged.

Layout

  • rust/obs-camera-busy: the pure core (holder scan, names, allowlist, dedupe / rate limit, what an answer does, the SIGTERM→SIGKILL sequence over a Signals trait, texts, log lines). src/platform/ holds kill(2), getuid(2) and the inotify/poll watcher thread. src/ffi is the C ABI (frontend/utility/obs-camera-busy.h), linked through rust/obs-frontend.
  • Frontend: OBSCameraBusy (the window, its own unity group so the Qt test builds it alone) and CameraBusy (the glue). OBSBasic routes source_device_busy to it and saves the allowlist.
  • Plugin: v4l2-input.c.h announces opened / closed.

Commits

  • RED 982e245: Tier 1 tests against todo!() stubs. 39 of 40 fail; the ffi module aborts the binary (a todo!() cannot unwind out of extern "C").
  • GREEN 22d5d9b: the core. All 46 camera_busy:: tests in obs-tests-gpu pass.
  • Then the frontend, the plugin, the Qt test and the ledger line.
  • The Qt test test_camera_busy_dialog was run locally (built by hand against Qt 6.11.1, offscreen platform) before the fixes, and it caught two real bugs:
    • ~Qt::Tool also cleared the Dialog/Window type bits, which made the dialog a plain child widget inside the main window (isWindow() false).
    • QDialogButtonBox made the AcceptRole "Always allow" button the default, so Enter answered it.
      After the fixes, 10 of 10 pass. They check the parent and transientParent, the window type and flags, non-modality, WA_ShowWithoutActivating, that nothing answers without a click, and exactly one answer per way out.

Tiers and policy

New code with no C original: Tier 2 (unchanged C tests against a Rust port) and Tier 3 (differential) do not apply, as recorded under Decisions: on #3724. The existing test_v4l2_busy* C tests are unchanged. There is no rust-exports.d / rust-hidden.d fragment because the crate links into the frontend, not libobs, like obs-fallback-warning. The crate is excluded from Tier 2 proof inputs (local-gate.toml), and its platform/mod.rs is listed in ci/shared-build-files.txt as a new crate's boundary. The tests are modules of the existing obs-tests-gpu binary, so there is no new test executable.

Test cost: 46 new Rust tests; the whole module runs in 0.47 s (longest is the real-process SIGKILL test, about 0.4 s). Peak RSS is 5.5 MB over 5 runs. There are no proptests. Own threads: the watcher tests start one watcher thread each. The close and watch tests spawn one short sh/sleep child each, which is killed and reaped.

Not verified

  • Not exercised against a real busy camera, and the full OBS app was not run with this change on a real Wayland/KDE session. So the real-session behaviour is unverified: minimize/restore with OBS, and not stealing focus from another app under KWin. What is verified is on Qt's offscreen platform (flags, transient parent, no activation attribute). This PR therefore uses Refs #3724, not Fixes.

…#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").
…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
#3724 (#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.
…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.
@zackees
zackees force-pushed the fix/3724-camera-busy branch from aa87deb to ad674f0 Compare November 6, 2026 02:24
…_busy fixture tests on Linux only (#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.
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.

1 participant