Skip to content

linux-v4l2: Keep packed framerate in list values - #202

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/201-v4l2-framerate-truncation
Oct 11, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/201-v4l2-framerate-truncation

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

Description

If you picked a frame rate for a Video Capture Device (V4L2) source, the device ran at a different rate, usually the fastest one it supports. Separately, every change to the source's settings, including moving a camera control slider such as zoom or focus, stopped and restarted the capture. With this change the device runs at the selected rate, and settings changes that don't affect the format no longer restart the capture.

Both problems have the same cause. v4l2_framerate_list() stored each discrete frame interval, a packed 64-bit (numerator, denominator) tuple, in an int, so only the denominator survived. For 30 fps (1/30 s per frame) the saved setting was 30. v4l2_unpack_tuple() reads that as a legacy 16-bit tuple: 0/30 s per frame, an infinite rate, which the driver clamps to its maximum. After v4l2_init(), data->framerate holds the real packed interval reported by the device, so the comparison in v4l2_settings_changed() never matched the stored setting, and every update looked like a frame rate change.

  1. linux-v4l2: Add RED framerate list tests: moves the list entry and the frame rate part of v4l2_settings_changed(), unchanged, into plugins/linux-v4l2/v4l2-framerate.c (no ioctls) and adds test_v4l2_framerate. 2 of its 3 tests fail on this commit:
    • picked_framerate_requests_that_interval (picking 1/30 requests 0/30)
    • control_change_does_not_restart_stream (running at the packed 1/30, setting 30: restart)
    • leave_unchanged_restarts_once passes: the "Leave Unchanged" handling is not changed.
  2. linux-v4l2: Keep packed framerate in list values: stores the list value as int64_t. All 3 tests pass.

Motivation and Context

Fixes #201 (upstream obsproject/obs-studio#13388 by acscd and #13896 by shanefagan; the fix is acscd's obsproject/obs-studio#13808, approved upstream)

Why this one: webcams run at the wrong rate (on some cheap devices the capture stops working altogether), and every settings tweak restarts the capture, so the camera drops frames while you adjust zoom or focus. The fix is one line and has already been approved upstream.

How Has This Been Tested?

Automated: test_v4l2_framerate fails 2 of 3 at the RED commit and passes 3 of 3 at the GREEN commit (built and run on Arch Linux). The build is clean; clang-format and gersemi are clean.

End to end, with the real linux-v4l2 module loaded into a headless libobs, on a v4l2loopback device fed by ffmpeg at 640x480, 30 fps. The harness fills in the source properties the way the properties dialog does, picks "30.00", then changes an unrelated setting three times:

before after
list value for "30.00" 30 4294967326 (1/30)
device frame rate after picking it 1000 fps (driver maximum), then select timed out repeatedly 30 fps
capture restarts for 3 unrelated settings changes 3 0

Not tested:

  • Real UVC camera controls (zoom/focus sliders). They go through the same settings update path as the unrelated change above, but no UVC camera was used.
  • Drivers that adjust the requested interval (e.g. return 1001/30000 for 1/30). These would still read back a different value and restart on every update; that is separate from this bug.
  • The Rust and Docker lanes of the local gate.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

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 tests, commit messages and this text under the submitter's direction, ported acscd's upstream fix, and ran the tests above on the submitter's machines.

🤖 Generated with Claude Code

Picking a discrete framerate for a v4l2 source sets the device to its
fastest rate instead (obsproject/obs-studio#13388, reported by acscd),
and every camera control change such as zoom or focus restarts the
stream (#13896, reported by shanefagan).

Both come from the framerate list storing the packed 64-bit
(numerator, denominator) interval through an int: only the denominator
survives, which unpacks as 0/30 s per frame, and the stored setting
never matches the packed interval the device reports back.

Move the list entry and the framerate restart decision into
v4l2-framerate.c unchanged so cmocka can test them without a device.
The list value tests fail until the truncation is fixed.

Refs obs-rust#201.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@rdoupe
rdoupe requested a review from zackees as a code owner October 11, 2026 05:36
The framerate list stored each discrete frame interval through an int,
truncating the packed 64-bit (numerator, denominator) tuple to its
denominator. Store it as int64_t so the setting holds the interval the
user picked: the device runs at the selected rate, and the setting
matches what the device reports back, so unrelated settings changes no
longer restart the capture.

Turns picked_framerate_requests_that_interval and
control_change_does_not_restart_stream green.

This is obsproject/obs-studio#13808 by acscd.

Fixes obs-rust#201.

Co-Authored-By: acscd <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Local-Gate: v1 tree=9cbfe21ec8400538dc0dfda09175307778fd7f7a secs=84 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791697391,"gate":"rust/all/fmt","host":"linux-x86_64","key":"bdf42dd17bbd8b13266ec682931f98ba52be392534539a6aacb0a77dfa2bef37","lane":"lint","parents":["e58c8d7d9025167b4ad39231563a3668c5e0ebd2"],"secs":11,"stamp":"dbbfa686223fe5d779d544b7fbed1637","tree":"9cbfe21ec8400538dc0dfda09175307778fd7f7a","v":1,"via":"run"}
Ci-Attestation: {"at":1791697391,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"bdf42dd17bbd8b13266ec682931f98ba52be392534539a6aacb0a77dfa2bef37","lane":"lint","parents":["e58c8d7d9025167b4ad39231563a3668c5e0ebd2"],"secs":11,"stamp":"709d1e537fa6e37f7b9d8aec69b0ca31","tree":"9cbfe21ec8400538dc0dfda09175307778fd7f7a","v":1,"via":"run"}
Ci-Attestation: {"at":1791697391,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"a03713842106d45d59cad7bbc78f21de3055cb1eab37a12daa26cfa98dffc177","lane":"rust-test","parents":["e58c8d7d9025167b4ad39231563a3668c5e0ebd2"],"secs":26,"stamp":"73d8080acdbd1c4dd04b7a20f9d539a2","tree":"9cbfe21ec8400538dc0dfda09175307778fd7f7a","v":1,"via":"run"}
Ci-Attestation: {"at":1791697391,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"f73dc3b35b472d69f8709ce6ba79e05e806891d05ed819201c3f891e41df9651","lane":"tier2-linux","parents":["e58c8d7d9025167b4ad39231563a3668c5e0ebd2"],"secs":47,"stamp":"3e1036a16bd58062521bfdb3f8a15f32","tree":"9cbfe21ec8400538dc0dfda09175307778fd7f7a","v":1,"via":"run"}
@zackees

zackees commented Oct 11, 2026

Copy link
Copy Markdown
Member

Verified locally, rebased onto master and stamped. The new head is ebc07f9b3.

  • RED (e58c8d7d9): Tier 2 passed 62 of 63. test_v4l2_framerate failed 2 tests (picked_framerate_requests_that_interval, control_change_does_not_restart_stream).
  • GREEN (6af415962): Tier 2 passed 63 of 63 with ENABLE_RUST_LIBOBS OFF and 63 of 63 with it ON.
  • Local gate: lint, rust-test and tier2-linux all passed.

Non-blocking: profiles that already saved a truncated value (for example 30) keep requesting the legacy 0/30 interval until the user picks the rate again. A follow-up could map a small legacy value to the matching discrete interval. Merging once CI is green.

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: frame rate truncated to int, wrong fps and restarts on every settings change (upstream #13388, #13896)

2 participants