Repository navigation
linux-v4l2: Restore saved camera controls only on their camera - #460
Merged
zackees merged 2 commits intoOct 13, 2026
Merged
Conversation
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]>
Since obs-rust#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 obs-rust#363 / obs-rust#364. Fixes obs-rust#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"}
Member
|
Verified locally in the Tier 2 image (OFF and ON):
|
zackees
force-pushed
the
fix/v4l2-controls-device-identity
branch
from
October 13, 2026 05:56
9ec0218 to
a08e650
Compare
5 of 6 tasks
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 now restores its saved camera controls only on the camera they were set on. Since #364 they were written to whatever camera the source opened, so switching a source from camera A to camera B, or two cameras swapping
/dev/videoNafter a reboot or a replug, wrote A's exposure, focus, zoom or menu modes to B.controls_deviceholds the card name and bus info fromVIDIOC_QUERYCAP, the same text the Device list shows, so two cameras of the same model on different ports differ.v4l2_init()writes the saved controls only if they belong to the open camera; otherwise it writes nothing and logs it. "Restore camera controls when the camera connects" (linux-v4l2: Add an option to not restore camera controls on connect #386) works as before: unchecked, nothing is written.device_selected()) puts the previous camera's controls aside undercontrols_other_devicesand brings back those saved for the new camera, if any. The sliders no longer show another camera's values, and switching back restores the first camera's. This writes nothing to the camera.device_iddoes not go through the Properties window: the new camera is not written, and the saved controls stay the first camera's until the Properties window is opened on the new one.savecallback) or when its Properties window is opened.VIDIOC_QUERYCAP(every V4L2 driver must) behaves as before.test/cmocka: Add RED V4L2 camera controls device identity tests: the fake libv4l2 oftest_v4l2_controlsgets a second camera of the same model on another USB port, with its owncard/bus_infoand control values, and a second node so the cameras can swap. Nine cases:8 of 23 cases fail; the 14 cases of linux-v4l2: Apply saved camera controls when the device opens #364 and linux-v4l2: Add an option to not restore camera controls on connect #386 pass.
linux-v4l2: Restore saved camera controls only on their camera: 23 of 23 pass.Motivation and Context
Fixes #459, a follow-up of #363 / #364 found in review. #364 (upstream obsproject/obs-studio#11633, reported by vpzomtrrfrt) made OBS write saved controls when the camera opens, which about ten people across four upstream issues asked for. It did not say which camera the values were for, so it also wrote them to the wrong camera in two ordinary cases: a source switched to another camera, and cameras that swap
/dev/videoN(obsproject/obs-studio#3003 is the upstream report of cameras swapping after a reboot). Before #364 OBS never wrote a control on its own, so neither case changed a camera. With this change the restore from #364 and the opt-out from #386 stay as they are, and the values only go back to the camera they came from.How Has This Been Tested?
Automated, in both libobs lanes (
ENABLE_RUST_LIBOBSOFF and ON), on current master:test_v4l2_controls: 8 of 23 cases fail at the RED commit and 23 of 23 pass at GREEN, in each lane.ctest -Vshows all 23 cases run, none skipped; the test also passes without a display and without xvfb.device_selected()(2), not bringing them back (1), nosavecallback (1), not tying old settings to the first camera (1), not using the camera found at startup indevice_selected()(1).test_v4l2_controls23 of 23 in each lane; the full suite passes except master'stest_video_io/test_video_io_hidden, which collide on Xvfb under parallel load and pass on their own (untouched here).ci/test_registration.pyare clean. No CMake change; the test is already registered and runs in the Tier 2 Linux job.Not tested:
cardandbus_infothe way uvcvideo does (usb-<controller>-<port>); two real cameras, a real reboot or replug, and the Qt Properties window were not tried.Types of changes
Checklist:
🤖 Generated with Claude Code