Repository navigation
linux-v4l2: Keep packed framerate in list values - #202
Merged
zackees merged 2 commits intoOct 11, 2026
Merged
Conversation
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]>
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"}
Member
|
Verified locally, rebased onto master and stamped. The new head is
Non-blocking: profiles that already saved a truncated value (for example |
zackees
force-pushed
the
fix/201-v4l2-framerate-truncation
branch
from
October 11, 2026 05:43
6af4159 to
ebc07f9
Compare
9 tasks done
This was referenced Oct 11, 2026
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
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 anint, so only the denominator survived. For 30 fps (1/30 s per frame) the saved setting was30.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. Afterv4l2_init(),data->framerateholds the real packed interval reported by the device, so the comparison inv4l2_settings_changed()never matched the stored setting, and every update looked like a frame rate change.linux-v4l2: Add RED framerate list tests: moves the list entry and the frame rate part ofv4l2_settings_changed(), unchanged, intoplugins/linux-v4l2/v4l2-framerate.c(no ioctls) and addstest_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, setting30: restart)leave_unchanged_restarts_oncepasses: the "Leave Unchanged" handling is not changed.linux-v4l2: Keep packed framerate in list values: stores the list value asint64_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_frameratefails 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-v4l2module 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:304294967326(1/30)select timed outrepeatedlyNot tested:
Types of changes
Checklist:
🤖 Generated with Claude Code