Skip to content

linux-v4l2: Add an option to not restore camera controls on connect - #386

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/v4l2-restore-controls-toggle
Oct 12, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/v4l2-restore-controls-toggle

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

Description

A Video Capture Device (V4L2) source gets a per-source option, "Restore camera controls when the camera connects". It is the first item of the Camera Controls group in the source's Properties. Unticking it stops OBS from writing the saved camera controls when the camera opens, so an external PTZ controller keeps control of pan, tilt and zoom.

  1. test/cmocka: Add RED V4L2 restore camera controls option tests: test_v4l2_controls (the fake UVC webcam and fake udev harness from linux-v4l2: Apply saved camera controls when the device opens #364) now creates its sources with the source's defaults, as OBS does, and gains six cases:

    • the option exists, is on by default, has a tooltip, and stays in the Camera Controls group after the group is rebuilt for the device;
    • unchecked: no saved control is written when the source is created, when the camera is replugged, or when another setting is updated after an external controller moved the zoom;
    • unchecked: a control changed in the Properties window is still written, and only that one;
    • ticking or unticking the checkbox writes no control.

    6 of 14 cases fail; the 8 cases from linux-v4l2: Apply saved camera controls when the device opens #364 pass with the default.

  2. linux-v4l2: Add an option to not restore camera controls on connect: 14 of 14 pass.

Motivation and Context

Fixes #385, a follow-up of #363 / #364 raised by alerque on #363. #364 fixed saved controls not being applied (upstream obsproject/obs-studio#11633 and about ten people across four upstream issues), but gave people who drive the camera from elsewhere no way out. The option keeps the fix for them by default and gives PTZ users the old behaviour back with one checkbox per source.

How Has This Been Tested?

Automated, in both libobs lanes (ENABLE_RUST_LIBOBS OFF and ON), on current master:

  • test_v4l2_controls: 6 of 14 cases fail at the RED commit and 14 of 14 pass at GREEN. ctest -V shows all 14 cases run, none skipped, without a display and without xvfb.
  • The guards are checked by mutation. Writing the saved controls on the update that ticks the checkbox fails the toggle case. Leaving the checkbox out of the group that device_selected() rebuilds fails the default case.
  • Full ctest at GREEN: 126 of 126 in each lane (rebased on current master).
  • clang-format, gersemi and ci/test_registration.py are clean. The test was already registered and runs in the Tier 2 Linux job; no CMake change.

Not tested:

  • A real camera or PTZ controller (none here).
  • The Qt Properties window was not opened. The checkbox and its tooltip are checked through obs_properties (type, group, long description), not on screen.

UX check (feature-done-check.md)

# Result Evidence / gap
1 Discover PASS The checkbox is the first item under Camera Controls, where the controls it affects are; the tooltip names external PTZ controllers.
2 Configure PASS One checkbox per source, saved with the source; no restart needed.
3 Status PASS The checkbox is the state. Nothing is shown when a restore happens, as in #364.
4 Failure PARTIAL A control the camera refuses is logged only (unchanged from #364).
5 Limits PARTIAL Relative controls (Pan, Relative...) are never restored, whatever the option; the tooltip says "controls changed here" but does not mention them. While the camera is unplugged, the Properties window disables the whole group, so the option can only be changed with the camera connected.
6 Existing settings PASS Moving a control in Properties still writes it, with the option on or off.
7 Coherence PARTIAL Unchecked, the sliders show the values saved in OBS, not what the PTZ controller set (as before #364).
8 Docs/announcement PASS The label is the one promised on #363, and the behaviour described there (unchecked: written only when changed in Properties, never on start or reconnect) is what the tests check.
9 Hands-on OPEN Headless harness only. Needs someone with a PTZ setup (alerque offered the use case on #363) to confirm on a real camera.

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.
  • I have used AI tooling in the creation of this PR
  • I am an AI agent being used to assist with this pull request: Claude Code (Claude Opus 5.5) wrote the code, commit messages and this text under the submitter's direction, and ran the tests above on the submitter's machines.

🤖 Generated with Claude Code

Since obs-rust#364 the Video Capture Device (V4L2) source writes its saved camera
controls whenever the device opens (OBS starts, the source restarts, the
camera is replugged) and on every settings update. With an external PTZ
controller this puts the pan, tilt or zoom last set in OBS back over the
controller's on every start and reconnect (raised by alerque on obs-rust#363).

The source needs a per-source option, "Restore camera controls when the
camera connects", next to the camera controls in its properties. On (the
default) keeps obs-rust#364's behaviour. Off is the behaviour before obs-rust#364: a
control is written only when the user changes it in the Properties
window.

test_v4l2_controls now creates its sources with the source's defaults,
as OBS does, and gains six cases:
- the option exists, is on by default, has a tooltip, and is in the
  Camera Controls group, also once the group is rebuilt for the device;
- off: no saved control is written when the source is created, when the
  camera is replugged, or when a script updates another setting after
  an external controller moved the zoom;
- off: a control changed in the Properties window is still written, and
  only that one;
- ticking or unticking the checkbox writes no control.

6 of 14 cases fail; the 8 cases of obs-rust#364 still pass with the default.

Refs obs-rust#385.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Since obs-rust#364 the Video Capture Device (V4L2) source writes its saved
camera controls whenever the device opens (OBS starts, the source
restarts, the camera is replugged) and on every settings update. With an
external PTZ controller, this puts the pan, tilt or zoom last set in OBS
back over the controller's on every start and reconnect (raised by
alerque on obs-rust#363).

Add "Restore camera controls when the camera connects" as the first item
of the Camera Controls group in the source's properties, with a tooltip
that names external PTZ controllers. It is on by default, which keeps
obs-rust#364's behaviour. Off, v4l2_init() and v4l2_update() write no saved
control, as before obs-rust#364: a control is written only when the user changes
it in the Properties window (v4l2_control_changed(), unchanged).

Ticking the option writes nothing by itself: the saved controls are
written the next time the device opens or the settings change.

Fixes obs-rust#385.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Local-Gate: v1 tree=74ceb9ced3a280927c0daea8659b31275a72e616 secs=100 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791820410,"gate":"rust/all/fmt","host":"linux-x86_64","key":"41b971c85d446edeea0a3a45563d800e91be829cbc9ecc5e55e7ead0a8abf542","lane":"lint","parents":["8c7d229d74baa49d32e0668f6911233c8b829117"],"secs":14,"stamp":"4ac26e8605dbfd86713f6160fe230408","tree":"74ceb9ced3a280927c0daea8659b31275a72e616","v":1,"via":"run"}
Ci-Attestation: {"at":1791820410,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"41b971c85d446edeea0a3a45563d800e91be829cbc9ecc5e55e7ead0a8abf542","lane":"lint","parents":["8c7d229d74baa49d32e0668f6911233c8b829117"],"secs":14,"stamp":"a53fa52032ba18e279a853ade09bc785","tree":"74ceb9ced3a280927c0daea8659b31275a72e616","v":1,"via":"run"}
Ci-Attestation: {"at":1791820410,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"f8361c033af5335d4c5c74e844ca019c836f5e124c766c4695b13e5826f8e24c","lane":"rust-test","parents":["8c7d229d74baa49d32e0668f6911233c8b829117"],"secs":40,"stamp":"476727479aab24b6ca7fb72448d020be","tree":"74ceb9ced3a280927c0daea8659b31275a72e616","v":1,"via":"run"}
Ci-Attestation: {"at":1791820410,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"4707aa46545efc1d54aebe2d6a51dc77248d6fff24135f5c30b3fd1ddb3ad82d","lane":"tier2-linux","parents":["8c7d229d74baa49d32e0668f6911233c8b829117"],"secs":47,"stamp":"6244a7ac3506901f5aa80701413f3ee7","tree":"74ceb9ced3a280927c0daea8659b31275a72e616","v":1,"via":"run"}
@zackees

zackees commented Oct 12, 2026

Copy link
Copy Markdown
Member

Verified locally in the Tier 2 image (OFF and ON):

  • RED 8c7d229: test_v4l2_controls fails the 6 new cases (restoring_controls_is_on_by_default, unchecked_saved_controls_are_not_written_on_create/update/replug, unchecked_a_control_changed_in_properties_is_written, toggling_the_checkbox_writes_nothing)
  • GREEN 464e3c2: 128/128
  • The test change only adds lines; existing cases are untouched. Rebased on master, local gate passed; pushed as 7975a38.

@zackees
zackees force-pushed the fix/v4l2-restore-controls-toggle branch from 464e3c2 to 7975a38 Compare October 12, 2026 15:53
@zackees
zackees merged commit e2b8572 into obs-rust:master Oct 12, 2026
23 checks passed
zackees pushed a commit to rdoupe/obs-studio that referenced this pull request Oct 13, 2026
Since obs-rust#364 the Video Capture Device (V4L2) source writes its saved
camera controls whenever the device opens. The controls are saved under
the driver's control names only, with nothing that says which camera
they were set on, so:
- switching a source from camera A to camera B (in the Properties
  window, or from a script or obs-websocket) writes A's exposure, focus,
  zoom or menu modes to B;
- when two cameras swap /dev/videoN nodes (reboot, replug, a USB hub
  that resets), OBS writes A's values to B at startup or on reconnect,
  with no user action.

The fake libv4l2 of test_v4l2_controls gains a second camera of the same
model on another USB port (own card/bus_info from VIDIOC_QUERYCAP and own
control values) and a second node, so the cameras can swap nodes. Nine
cases:
- a source switched to camera B writes nothing to it;
- A -> B -> A: A gets its values back, B is never written;
- the same switch in the Properties window: B is not written, the
  sliders stop showing A's values, and A's come back with A;
- a control changed on B after the switch is the only one restored on B;
- camera B taking the source's node on replug, or at startup, is not
  written;
- control: the same camera replugged is still restored;
- settings saved before this change are applied to the first camera
  opened and tied to it, so they do not follow the node to camera B,
  nor go to camera B when it is picked in the Properties window before
  the scene collection is saved.

8 of 23 cases fail; the 14 cases of obs-rust#364 and obs-rust#386 pass.

Refs obs-rust#459.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
zackees pushed a commit that referenced this pull request Oct 13, 2026
* test/cmocka: Add RED V4L2 camera controls device identity tests

Since #364 the Video Capture Device (V4L2) source writes its saved
camera controls whenever the device opens. The controls are saved under
the driver's control names only, with nothing that says which camera
they were set on, so:
- switching a source from camera A to camera B (in the Properties
  window, or from a script or obs-websocket) writes A's exposure, focus,
  zoom or menu modes to B;
- when two cameras swap /dev/videoN nodes (reboot, replug, a USB hub
  that resets), OBS writes A's values to B at startup or on reconnect,
  with no user action.

The fake libv4l2 of test_v4l2_controls gains a second camera of the same
model on another USB port (own card/bus_info from VIDIOC_QUERYCAP and own
control values) and a second node, so the cameras can swap nodes. Nine
cases:
- a source switched to camera B writes nothing to it;
- A -> B -> A: A gets its values back, B is never written;
- the same switch in the Properties window: B is not written, the
  sliders stop showing A's values, and A's come back with A;
- a control changed on B after the switch is the only one restored on B;
- camera B taking the source's node on replug, or at startup, is not
  written;
- control: the same camera replugged is still restored;
- settings saved before this change are applied to the first camera
  opened and tied to it, so they do not follow the node to camera B,
  nor go to camera B when it is picked in the Properties window before
  the scene collection is saved.

8 of 23 cases fail; the 14 cases of #364 and #386 pass.

Refs #459.

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

* linux-v4l2: Restore saved camera controls only on their camera

Since #364 the Video Capture Device (V4L2) source writes its saved
camera controls whenever the device opens. They are saved under the
driver's control names only, so a source switched from camera A to
camera B, or two cameras that swap /dev/videoN nodes after a reboot or a
replug, got A's exposure, focus, zoom or menu modes written to B.

The source now records which camera the saved controls belong to:
"controls_device" holds the card name and bus info from VIDIOC_QUERYCAP,
as in the device list, so two cameras of the same model on different
ports differ.
- The device opens (start, restart, replug): the saved controls are
  written only if they were set on that camera. Restore off is
  unchanged: nothing is written.
- Picking another camera in the Properties window puts the controls of
  the previous camera aside, under "controls_other_devices", and brings
  back those saved for the new one, so the sliders do not show another
  camera's values and switching back restores them. Nothing is written
  to the camera by this.
- Settings saved before this change have no camera: the controls belong
  to the first camera the source opens, as before, which is recorded
  when the source is saved (or when its properties are opened).

A camera that cannot be identified behaves as before.

Follow-up of #363 / #364.

Fixes #459.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=87f2f59f1247ef4fbd7439302e624a32c4fe6d9f secs=256 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791870982,"gate":"rust/all/fmt","host":"linux-x86_64","key":"9535bc7082c3374893e25968a8f8f4b95e057f437a12ac6d12a699181f1b3d58","lane":"lint","parents":["2c216e7f448e92a9cd625e0aebc94519f3fb6153"],"secs":77,"stamp":"2f9cd4b02096f22f162ca4f463249809","tree":"87f2f59f1247ef4fbd7439302e624a32c4fe6d9f","v":1,"via":"run"}
Ci-Attestation: {"at":1791870982,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"9535bc7082c3374893e25968a8f8f4b95e057f437a12ac6d12a699181f1b3d58","lane":"lint","parents":["2c216e7f448e92a9cd625e0aebc94519f3fb6153"],"secs":77,"stamp":"7caaba97b5fde22529bdb9d1d6246c69","tree":"87f2f59f1247ef4fbd7439302e624a32c4fe6d9f","v":1,"via":"run"}
Ci-Attestation: {"at":1791870982,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"934a9e9013d6280946151b5007b005f3efd11f420d8fa285852b19bdc099f54d","lane":"rust-test","parents":["2c216e7f448e92a9cd625e0aebc94519f3fb6153"],"secs":115,"stamp":"8574802dd67be6f0be3835115d228972","tree":"87f2f59f1247ef4fbd7439302e624a32c4fe6d9f","v":1,"via":"run"}
Ci-Attestation: {"at":1791870982,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"653fe6b68ade50c85d12e620cd12b57e0ae6f1e95a37b6d5a2c94713cdeed602","lane":"tier2-linux","parents":["2c216e7f448e92a9cd625e0aebc94519f3fb6153"],"secs":64,"stamp":"a20fee5b21d1965f9cbc264e7302c9e0","tree":"87f2f59f1247ef4fbd7439302e624a32c4fe6d9f","v":1,"via":"run"}

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 16, 2026
…obs-rust#977)

The tooltip of "Restore camera controls when the camera connects" said
the saved controls are set again "when the source's settings change".
Ticking the checkbox is such a change, but by design (obs-rust#386) it writes
nothing: the controls are set at the next open, replug or other settings
change, so a PTZ camera does not move the moment the box is ticked.

Reword the en-US tooltip to match. No behaviour change; the existing
toggling_the_checkbox_writes_nothing case in test_v4l2_controls already
covers the behaviour the new wording describes.

Fixes obs-rust#976.

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

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: linux-v4l2: saved camera controls override an external PTZ controller on every start and reconnect (follow-up of #363)

2 participants