Skip to content

linux-v4l2: Disable inactive camera controls instead of rebuilding - #895

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/v4l2-control-refused
Oct 15, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/v4l2-control-refused

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

Refs #827

What and why

The cause is the first case in zackees' first comment on #827: a camera control that the camera refuses makes the Properties window rebuild, which drops the slider being dragged. This PR fixes that case for the "Video Capture Device (V4L2)" source. It still needs the reporter's confirmation on their camera, so it says Refs, not Fixes: #827 stays open after merge until they have tested a build with it.

The report and the cause

  • Report: "Exposure Time, Absolute" of a UVC webcam (Logitech 046d:081b) with Auto Exposure in Aperture Priority Mode dropped the slider after one step. The reporter confirmed that in Manual Mode it drags normally.
  • Driver: while the automatic mode is on, uvcvideo flags the manual control V4L2_CTRL_FLAG_INACTIVE (uvc_query_v4l2_ctrl() in drivers/media/usb/uvc/uvc_ctrl.c) and refuses to set it with EACCES (uvc_ctrl_is_accessible()). The driver applies the same rule to other manual/automatic pairs, such as White Balance Temperature with White Balance, Automatic, but only Exposure was reported.
  • OBS: v4l2_control_changed() in plugins/linux-v4l2/v4l2-controls.c returned true whenever VIDIOC_S_CTRL failed, and true tells the Properties window to rebuild every widget. Each refused step of a drag destroyed the slider being dragged and reset the scroll position. The spin box and its arrows also accepted values that the camera then refused.

What changes

  • The V4L2 spec says an inactive control "is not applicable to the current configuration and should be displayed accordingly in a user interface" (Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst). qv4l2 (v4l-utils, utils/qv4l2/ctrl-tab.cpp) disables these controls: its CTRL_FLAG_DISABLED includes V4L2_CTRL_FLAG_INACTIVE.
  • The flag doesn't depend on the driver: the kernel's generic auto clusters (v4l2_ctrl_auto_cluster()) set the same flag, as uvcvideo does.
  • Controls flagged inactive are now added disabled. The slider, spin box and label are disabled together, so they stay consistent.
  • The callback no longer writes an inactive control. A refused write is logged as a warning (unable to set <control> to <value>: <error>) instead of rebuilding the window.
  • After a change, the callback reads the flags back from the driver. It asks for a rebuild only when a control was turned on or off, for example when Auto Exposure is switched to Manual Mode. uvcvideo does not set V4L2_CTRL_FLAG_UPDATE on its automatic controls, so the flags are read back instead of relying on that flag.
  • In regular use, dragging a slider never rebuilds the window and never greys anything out.

When another program changes the automatic mode

  • If another program (v4l2-ctl, guvcview, a second OBS window) changes the automatic mode while the Properties window is open, OBS gets no callback. The window keeps showing the old state until the user changes a control.
  • That change re-reads the flags:
    • A slider that became inactive is not written, is disabled, and the window rebuilds once. In this case, and only in this case, a slider can grey out under the mouse.
    • A control that became active is enabled.
  • The tests another_program_turning_auto_exposure_on_disables_the_exposure and another_program_setting_manual_mode_enables_the_exposure cover this.
  • V4L2 control events (VIDIOC_SUBSCRIBE_EVENT with V4L2_EVENT_CTRL, V4L2_EVENT_CTRL_CH_FLAGS) could update the window as soon as the other program changes the mode. That is left out to keep this change small.

Behaviour change

  • While a control's automatic mode is on, its slider and spin box are greyed out, so a value can no longer be typed there. The camera refused those values anyway.
  • The saved value is kept. With "Restore camera controls when the camera connects" on, it is written once the automatic mode is turned off, as before.

Background

Reproduction

Reproduced in release v0.1.0-beta.20261014 (AppImage, headless), using a stand-in rather than a real camera:

  • Stand-in: an LD_PRELOAD shim over libv4l2 presents a UVC-like /dev/video0. As in uvcvideo, Exposure Time, Absolute is flagged inactive and refused with EACCES unless Auto Exposure is in Manual Mode.
  • Setup: private Xvfb, private HOME, dbus-run-session, --multi. The source was created over obs-websocket.
  • Input: XTest drags each slider handle 120 px (20 moves, 50 ms apart).
Build Exposure Time, Absolute (Aperture Priority) Brightness Exposure Time, Absolute (after picking Manual Mode in the window)
v0.1.0-beta.20261014 1 write attempt (refused); the window rebuilds and the drag drops 20 writes, follows the mouse
This branch's plugin in that AppImage disabled: no write, no rebuild 20 writes, follows the mouse enabled after one rebuild; drag: 20 writes (250 → 980), no rebuild

Not yet confirmed on the reporter's camera: this needs their test.

RED → GREEN

  • RED commit: de4a211 test/cmocka: Add failing tests for refused V4L2 camera controls.
    • The cases are added to test_v4l2_controls. Its fake libv4l2 now has uvcvideo's Auto Exposure menu (Manual Mode, Aperture Priority Mode) and Exposure Time, Absolute, which is inactive and refused with EACCES unless Auto Exposure is in Manual Mode. The fake's manual focus is now also refused with EACCES, like uvcvideo, instead of EBUSY.
    • 7 of 32 fail in both lanes:
      • inactive_controls_are_disabled_on_load: the exposure and the manual focus are enabled while inactive.
      • switching_auto_exposure_enables_and_disables_the_exposure and turning_autofocus_off_enables_the_manual_focus: switching the menu or the checkbox asks for no rebuild.
      • moving_an_inactive_control_keeps_the_properties: "8 of 8 changes of the inactive 'Exposure Time, Absolute' asked to rebuild the Properties window".
      • a_refused_control_keeps_the_properties: the same for a driver that refuses a control without flagging it inactive.
      • another_program_turning_auto_exposure_on_disables_the_exposure: the exposure is written 9 times.
      • another_program_setting_manual_mode_enables_the_exposure: the exposure is never disabled to begin with.
    • Guards that pass on RED:
      • moving_an_active_control_keeps_the_properties: 8-step drags of Brightness, and of the exposure in Manual Mode, write each value, ask for no rebuild and disable nothing.
      • active_manual_controls_are_enabled_on_load: with autofocus off and Manual Mode, both manual controls are enabled.
      • the 23 existing cases.
  • GREEN: 92c6b5e, 32 of 32 with ENABLE_RUST_LIBOBS OFF and ON. Full ctest (private Xvfb, system libobs-opengl masked, TMPDIR unset, -j4): C lane 249/249, Rust lane 247/249. The two Rust-lane failures, test_pulse_monitor_reset_terminated_context_reset_recovers and test_video_io, are not touched here: all their cases passed, and they failed in xvfb-run's teardown ("kill: No such process"). In the C lane, test_startup_cycle_stress skipped its case once under the parallel run. All three pass 3 of 3 alone in both lanes, with no skips. All test_v4l2_* tests passed in both lanes. clang-format and ci/test_registration.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 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 and others added 2 commits October 15, 2026 17:03
Dragging "Exposure Time, Absolute" of a UVC webcam in Aperture Priority
Mode drops the slider after one step in the Properties window of the
Video Capture Device (V4L2) source. uvcvideo flags a manual control
inactive (V4L2_CTRL_FLAG_INACTIVE) while its automatic mode is on, and
refuses to set it with EACCES (uvc_ctrl_is_accessible()).
v4l2_control_changed() returns true whenever VIDIOC_S_CTRL fails, which
tells the Properties window to rebuild every widget, so each refused
step destroys the slider being dragged.

The fake libv4l2 of test_v4l2_controls gets uvcvideo's Auto Exposure
menu (Manual Mode, Aperture Priority Mode; starts in Aperture Priority)
and Exposure Time, Absolute, inactive and refused with EACCES unless
Auto Exposure is Manual. Its manual focus is now refused with EACCES
too, like uvcvideo, instead of EBUSY.

New cases. Regular use:
- moving_an_active_control_keeps_the_properties (guard): 8-step drags
  of Brightness and, in Manual Mode, of the exposure write each value,
  ask for no rebuild and disable nothing. Passes.
- inactive_controls_are_disabled_on_load: the exposure (Aperture
  Priority) and the manual focus (autofocus on) are enabled. Fails.
- active_manual_controls_are_enabled_on_load (guard): with autofocus
  off and Manual Mode, both are enabled. Passes.
- switching_auto_exposure_enables_and_disables_the_exposure and
  turning_autofocus_off_enables_the_manual_focus: switching the menu or
  the checkbox asks for no rebuild. Fail.
- moving_an_inactive_control_keeps_the_properties: 8 of 8 moves of the
  inactive exposure ask for a rebuild. Fails.
- a_refused_control_keeps_the_properties: the same for a driver that
  refuses the manual focus without flagging it inactive. Fails.

Another program changes the automatic mode while the window is open (no
callback reaches OBS):
- another_program_turning_auto_exposure_on_disables_the_exposure: after
  it sets Aperture Priority, moving the still-enabled exposure must not
  write it, must disable it and ask for one rebuild only. It is written
  9 times. Fails.
- another_program_setting_manual_mode_enables_the_exposure: after it
  sets Manual Mode, moving any control must enable the exposure once.
  Fails (the exposure is never disabled to begin with).

The 23 existing cases pass. 7 of 32 fail.

Refs obs-rust#827.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
v4l2_control_changed() returned true whenever VIDIOC_S_CTRL failed,
which tells the Properties window to rebuild every widget. A manual
control whose automatic mode is on is inactive: uvcvideo flags it
V4L2_CTRL_FLAG_INACTIVE and refuses to set it with EACCES. Each step of
a drag on such a slider (Exposure Time, Absolute with Auto Exposure in
Aperture Priority Mode, White Balance Temperature with White Balance,
Automatic on) was refused, so the window was rebuilt under the mouse and
the drag dropped after one step.

Controls the driver flags inactive are now shown disabled, as the V4L2
spec asks and qv4l2 does. The callback does not write an inactive
control. A refused write is logged as a warning instead of rebuilding
the window. After a change the callback asks the driver which controls
are active, and asks for a rebuild only when one of them was turned on
or off, e.g. when Auto Exposure goes to Manual Mode. uvcvideo does not
set V4L2_CTRL_FLAG_UPDATE on the automatic controls, so the flags are
read back instead of relying on it.

When another program changes an automatic mode while the window is
open, OBS gets no callback: the window keeps the old state until the
user changes a control, which then re-reads the flags. A slider that
became inactive is then not written, is disabled and the window is
rebuilt once; one that became active is enabled.

A disabled control keeps its saved value; with "Restore camera controls"
on, it is written once its automatic mode is turned off, as before.

test_v4l2_controls: 32 of 32 pass.

Refs obs-rust#827.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rdoupe
rdoupe requested a review from zackees as a code owner October 15, 2026 21:21
@zackees zackees added the ci-full Run every CI job on this PR, including the release-gating OBS app builds and Flatpak label Oct 15, 2026
@zackees
zackees enabled auto-merge October 15, 2026 21:23
@zackees
zackees added this pull request to the merge queue Oct 15, 2026
Merged via the queue into obs-rust:master with commit fd5f935 Oct 15, 2026
21 checks passed
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 16, 2026
…mode is on (obs-rust#1054)

* test/cmocka: Add failing tests for PipeWire camera automatic controls

In the Properties window of the "Video Capture Device (PipeWire)" source,
ticking "Focus, Automatic Continuous" leaves "Focus, Absolute" enabled:
the slider drags, and the camera ignores it. The same for Exposure Time,
Absolute in Auto Mode, White Balance Temperature with White Balance,
Automatic on, and Hue with Hue, Automatic on. The V4L2 driver flags these
controls inactive (V4L2_CTRL_FLAG_INACTIVE), and the V4L2 source greys
them out since obs-rust#895, but PipeWire's V4L2 node does not pass the flag on:
its PropInfo params only carry each control's id, name and range.
Menu controls (Auto Exposure, Power Line Frequency) are missing from the
window altogether: the node publishes a menu as a plain Int with labels,
and the source only reads a choice, so Auto Exposure cannot be switched
to Manual Mode from OBS.

test_pipewire_camera_control_refresh now plays two cameras the way
PipeWire's V4L2 node publishes them (the same prop ids, menus, and the
"device.api" and "object.path" node properties):
- the "UHD Camera" of obs-rust#827, with the control list its driver reports
  (uvcvideo, kernel 7.2.9): Focus, Absolute comes before Focus,
  Automatic Continuous, Auto Exposure starts in Auto Mode, and Iris,
  Absolute has a step of 0;
- a webcam with White Balance, Automatic (listed before its controls)
  and Hue, Automatic (listed after Hue), in Aperture Priority Mode.
Brightness of the existing cases now uses the UHD Camera's range (0-14).

Cases. Guards that pass:
- control_change_reaches_the_camera, control_change_does_not_rebuild_
  properties (obs-rust#829): unchanged apart from the range.
- saved_manual_modes_enable_the_controls_on_load: saved settings with
  the automatic modes off leave the manual controls enabled.
Failing:
- manual_controls_are_disabled_on_load: Focus, Absolute and Exposure
  Time, Absolute of the UHD Camera, and the webcam's white balance, hue,
  exposure and focus controls are enabled while their automatic modes
  are on. Iris, Absolute and the controls after it must stay enabled.
- toggling_autofocus_disables_and_enables_the_focus: unticking and
  ticking the checkbox, three times, asks for no rebuild and changes
  nothing.
- switching_auto_exposure_disables_and_enables_the_exposure: no Auto
  Exposure list to switch.
- toggling_white_balance_and_hue_automatic: the same for White Balance,
  Automatic and Hue, Automatic.
- menu_controls_are_shown: Auto Exposure and Power Line Frequency are
  missing. The node's device path, name and fd must not show up.
- moving_a_manual_control_keeps_the_properties: drags of Focus,
  Absolute with autofocus off and of Iris, Absolute pass; moving the
  overridden Focus, Absolute (from a script) sends it to the camera 8 of
  8 times.

6 of 9 fail, in both lanes.

Refs obs-rust#827.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* linux-pipewire: Disable manual camera controls while their automatic mode is on

With "Focus, Automatic Continuous" ticked in the Properties window of
the "Video Capture Device (PipeWire)" source, "Focus, Absolute" stayed
enabled: the slider dragged, and the camera ignored it (uvcvideo flags
the control inactive and refuses it with EACCES). The same for Exposure
Time, Absolute outside Manual Mode, White Balance Temperature, Red and
Blue Balance with White Balance, Automatic on, and Hue with Hue,
Automatic on. obs-rust#895 greys these out in the V4L2 source from the driver's
V4L2_CTRL_FLAG_INACTIVE, but PipeWire's V4L2 node does not pass that
flag on.

For a V4L2 camera node ("device.api" v4l2, or an "object.path" starting
with "v4l2:"), the source now knows the automatic/manual pairs the V4L2
spec defines, as uvcvideo implements them, by V4L2 control id: the node
gives a control the prop id SPA_PROP_START_CUSTOM + its V4L2 id, or
SPA_PROP_hue / SPA_PROP_exposure. A manual control is shown disabled
while its automatic control, as the window shows it, is not in its
manual mode (0, or Manual Mode for Auto Exposure), whatever the order
the camera lists them in. When the window opens, and after each change,
the states are worked out again; the window is rebuilt only when one of
them changed, so dragging a slider still never rebuilds it (obs-rust#829). An
overridden manual control is not sent to the camera; it keeps its value.

Menu controls are shown again: the node publishes a menu (Auto
Exposure, Power Line Frequency) as a plain Int with labels, not as a
choice, so the source skipped it, and Auto Exposure could not be set to
Manual Mode from OBS. A plain Int with labels is now a list. The node's
other plain values (the device's path, name and fd) are still not
shown.

test_pipewire_camera_control_refresh: 9 of 9 pass, in both lanes.

Refs obs-rust#827.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

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

Development

Successfully merging this pull request may close these issues.

bug: gui: source property sliders practically unusable

2 participants