Repository navigation
Description
Follow-up of #363 / PR #364, found in review. Since #364, a Video Capture Device (V4L2) source writes its saved camera controls to the camera whenever the device opens (OBS starts, the source restarts, the camera is replugged or comes back from suspend). The saved controls are stored under the driver's control names only ("Exposure Time, Absolute", "Auto Exposure", "Focus (absolute)", "Zoom, Absolute"...), with nothing that says which camera they were set on. Most webcams share those names, so the values follow the source, not the camera:
- Switching a source to another camera. A source set up on camera A is switched to camera B, in the Properties window or from a script or obs-websocket (
SetInputSettingswith a newdevice_id). The source restarts on B and writes A's saved controls to B right away. In the Properties window this happens as soon as B is picked in the list; Cancel puts the source back on A, but B has already been changed. - Two cameras swapping
/dev/videoN. The source remembers its camera by node (/dev/video0), and the numbers follow the order the cameras are found in. After a reboot, or when both are replugged in another order, camera B can come up at A's node. OBS then writes A's controls to B at startup, or on the reconnect, with no user action. Upstream OBS already captured from the wrong camera in that case (Webcam ordering is not persistent in Linux obsproject/obs-studio#3003); since linux-v4l2: Apply saved camera controls when the device opens #364 it also changes that camera's settings.
Menu controls cross over too: "Auto Exposure" set to Manual together with A's exposure time can leave B dark, and a manual focus can leave it blurred. The values stay in the camera, so other programs using B see them as well. Only controls the user set in OBS are written, and "Restore camera controls when the camera connects" (#386) turned off avoids it, but it is on by default.
Before #364 OBS never wrote a control on its own, so neither path changed the camera (the sliders only showed A's values while capturing from B).
Location
plugins/linux-v4l2/v4l2-controls.cv4l2_saved_control_value()(line 156) looks a saved control up by name only (line 160);v4l2_apply_controls()(line 226) writes every saved control that differs from what the open device reports.plugins/linux-v4l2/v4l2-input.cv4l2_update()(line 1085) copies the whole settings object as the saved controls (line 1117); a newdevice_idrestarts the source (line 1050), andv4l2_init()(line 934) writes them to whatever device it opened (line 1009). The reconnect handlerdevice_added()(line 782) callsv4l2_init()for whatever camera now sits at the source's node.
Class
Regression from #364: OBS writes one camera's saved settings to another camera's hardware.
How it is reached
- Set exposure, focus or zoom on camera A in a source's Properties. Pick camera B in the same source's Device list: B gets A's values.
- With two cameras and a source on each, reboot (or replug both in the other order) so that they swap
/dev/videoN: at startup each source writes its saved controls to the other camera.
Reproduced headlessly with the test_v4l2_controls harness from #364 (the real v4l2-input.c and v4l2-controls.c against a fake UVC webcam and the plugin's own udev handlers), extended with a second fake camera of the same model on another USB port: switching the source to it, and making it take the source's node on replug or at startup, each write the first camera's zoom, brightness and power line frequency to it.
Proposed fix and failing test
Fix: record which camera the saved controls were set on, as the card name and bus info from VIDIOC_QUERYCAP (what the Device list already shows, so two cameras of the same model on different ports differ), in a controls_device setting.
- When the device opens, the saved controls are written only if they belong to it.
- Picking another camera in the Properties window puts the previous camera's controls aside for it 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 the change have no camera recorded: the controls belong to the first camera the source opens, as today, and that camera is recorded, so existing setups keep their restore.
- "Restore camera controls when the camera connects" (linux-v4l2: Add an option to not restore camera controls on connect #386) works as before.
RED test (cmocka, extends test_v4l2_controls; no camera, kernel module or display). The fake gets a second camera of the same model on another port, with its own control values, and a second node so the cameras can swap. 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 the change are applied to the first camera opened and tied to it, also when camera B is picked in the Properties window before the scene collection is saved.
8 of 23 cases fail on master; the 14 cases of #364 and #386 pass.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
rdoupe commentedon Oct 13, 2026
Claiming: this issue.
test_v4l2_controls(fake UVC harness with a second camera of the same model on another port; no display): switching to camera B writes nothing to B, A->B->A restores A, B appearing at A's node on replug or at startup writes nothing, the same camera replugged is still restored, legacy settings attach to the first camera opened. 8 of 23 fail today.PR today.
test/cmocka: Add RED V4L2 camera controls device identity tests
linux-v4l2: Restore saved camera controls only on their camera
linux-v4l2: Restore saved camera controls only on their camera (obs-r…