Repository navigation
linux-v4l2: Disable inactive camera controls instead of rebuilding - #895
Merged
Merged
Conversation
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]>
zackees
enabled auto-merge
October 15, 2026 21:23
This was referenced Oct 15, 2026
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]>
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.
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
V4L2_CTRL_FLAG_INACTIVE(uvc_query_v4l2_ctrl()indrivers/media/usb/uvc/uvc_ctrl.c) and refuses to set it withEACCES(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.v4l2_control_changed()inplugins/linux-v4l2/v4l2-controls.creturnedtruewheneverVIDIOC_S_CTRLfailed, andtruetells 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
Documentation/userspace-api/media/v4l/vidioc-queryctrl.rst). qv4l2 (v4l-utils,utils/qv4l2/ctrl-tab.cpp) disables these controls: itsCTRL_FLAG_DISABLEDincludesV4L2_CTRL_FLAG_INACTIVE.v4l2_ctrl_auto_cluster()) set the same flag, as uvcvideo does.unable to set <control> to <value>: <error>) instead of rebuilding the window.V4L2_CTRL_FLAG_UPDATEon its automatic controls, so the flags are read back instead of relying on that flag.When another program changes the automatic mode
another_program_turning_auto_exposure_on_disables_the_exposureandanother_program_setting_manual_mode_enables_the_exposurecover this.VIDIOC_SUBSCRIBE_EVENTwithV4L2_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
Background
return trueon failure comes from upstream ("linux-v4l2: Add support for controls", 2019). The control-restore code this fork added (linux-v4l2: Apply saved camera controls when the device opens #364, linux-v4l2: Add an option to not restore camera controls on connect #386, linux-v4l2: Restore saved camera controls only on their camera #460) already skips inactive controls and is not involved.V4L2_CTRL_FLAG_INACTIVEthrough. Checked in PipeWire 1.0.5, 1.4.11 and 1.6.0:spa/plugins/v4l2/v4l2-utils.cnever reads it.Reproduction
Reproduced in release v0.1.0-beta.20261014 (AppImage, headless), using a stand-in rather than a real camera:
/dev/video0. As in uvcvideo, Exposure Time, Absolute is flagged inactive and refused with EACCES unless Auto Exposure is in Manual Mode.dbus-run-session,--multi. The source was created over obs-websocket.Not yet confirmed on the reporter's camera: this needs their test.
RED → GREEN
test/cmocka: Add failing tests for refused V4L2 camera controls.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.inactive_controls_are_disabled_on_load: the exposure and the manual focus are enabled while inactive.switching_auto_exposure_enables_and_disables_the_exposureandturning_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.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.ENABLE_RUST_LIBOBSOFF and ON. Full ctest (private Xvfb, systemlibobs-openglmasked, TMPDIR unset,-j4): C lane 249/249, Rust lane 247/249. The two Rust-lane failures,test_pulse_monitor_reset_terminated_context_reset_recoversandtest_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_stressskipped its case once under the parallel run. All three pass 3 of 3 alone in both lanes, with no skips. Alltest_v4l2_*tests passed in both lanes. clang-format andci/test_registration.pyclean.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