Repository navigation
win-dshow: drop the virtual camera sleep spin - #1638
Merged
zackees merged 2 commits intoOct 21, 2026
Merged
Conversation
`sleepto_100ns` slept `ms - 1` and then spun on `Sleep(0)` until the deadline. It runs once per frame inside the process of whatever app uses the OBS Virtual Camera, so that spin is CPU burned in Zoom, Teams or a browser (obs-rust#1279). The sleep stops within a timer tick of the target, and the only caller waits on an absolute deadline (`cur_time += obs_interval`), so returning there does not drift the frame schedule: the next wait is longer. Measured with the real file on an absolute 60 fps grid, 2000 frames, two rounds per arm, thread CPU: host timer 1 ms (what libobs sets for itself): before cpu 0.71-1.41 ms/frame, delta p50 0.00 ms, p99 0.08-1.55 ms after cpu 0.02-0.03 ms/frame, delta p50 -0.91 ms, p99 0.29-2.15 ms host timer default (15.6 ms granularity): before cpu 0.02-0.09 ms/frame, delta p50 5.3-6.6 ms late after cpu 0.02-0.03 ms/frame, delta p50 2.2-7.1 ms late Both arms keep 16.667 ms per frame over 2000 frames (33333 ms), so the early return does not drift. Where the host has a fine timer the spin is the ~1 ms the issue measured; where it does not, `Sleep` already overshoots the deadline, the spin rarely runs, and the change is not measurable. No test: no test target compiles the virtual camera module, and the C test suite runs on Linux only, where this file is Windows-only. The measurements are the evidence, recorded on obs-rust#1279.
5 tasks done
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.
Fixes #1279
What and why
sleepto_100nssleptms - 1and then spun onSleep(0)until the deadline. It runs once per frame inside the process of whatever app uses the OBS Virtual Camera, so the spin is CPU burned in Zoom, Teams or a browser.This drops the spin: the sleep already stops within a timer tick of the target, and the only caller waits on an absolute deadline (
cur_time += obs_interval), so returning early does not drift the frame schedule, the next wait is simply longer. It is the trade the issue offered ("accept ~1 ms jitter and drop the spin").RED -> GREEN
No test commit: no test target compiles
plugins/win-dshow/virtualcam-module, and the cmocka suite runs on Linux only, where this file is_WIN32-only. Recorded under## Decisionson #1279 rather than silently skipped.The evidence is a measurement of the real file, called on an absolute 60 fps grid, 2000 frames per run, two rounds per arm, thread CPU from
GetThreadTimes:Every run took 33333 ms for 2000 frames in both arms, so there is no drift. Where the host has a fine timer this is the ~1 ms the issue measured; where it does not,
Sleepalready overshoots and the change is inside the noise.Not run: a live consumer app (DirectShow camera consumer). The frame loop and the shared-memory handoff are unchanged; only the wait is.
Checklist
masterdocs/features.mdis added-W..., ratchets): not applicableAlso updates the
sleepto_100nscontract insleepto.h: it returns true when the target had not already passed on entry, and does not promise the target was reached. Before, the spin guaranteed it; nothing documented that.