Repository navigation
linux-v4l2: Add an option to not restore camera controls on connect - #386
Merged
zackees merged 2 commits intoOct 12, 2026
Merged
Conversation
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"}
Member
|
Verified locally in the Tier 2 image (OFF and ON):
|
zackees
force-pushed
the
fix/v4l2-restore-controls-toggle
branch
from
October 12, 2026 15:53
464e3c2 to
7975a38
Compare
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]>
This was referenced Oct 15, 2026
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]>
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.
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.
v4l2_init()writes the saved controls (those with a user value that differ from the device) on create, restart and reconnect, andv4l2_update()writes them on every settings update. With an external PTZ controller, the pan, tilt or zoom last set in OBS went back on the camera every time OBS started or the camera reconnected (raised by alerque on bug: linux-v4l2: saved camera controls (zoom, focus, exposure) are not applied at start, after a replug or from scripts (upstream #11633) #363).v4l2_control_changed(), unchanged).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:6 of 14 cases fail; the 8 cases from linux-v4l2: Apply saved camera controls when the device opens #364 pass with the default.
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_LIBOBSOFF 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 -Vshows all 14 cases run, none skipped, without a display and without xvfb.device_selected()rebuilds fails the default case.ci/test_registration.pyare clean. The test was already registered and runs in the Tier 2 Linux job; no CMake change.Not tested:
obs_properties(type, group, long description), not on screen.UX check (feature-done-check.md)
Types of changes
Checklist:
🤖 Generated with Claude Code