You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
win-dshow: virtual camera sleepto spins on Sleep(0) each frame inside the consuming app #1279
plugins/win-dshow/virtualcam-module/sleepto.c.h:43-50: after Sleep(ms-1) it loops on Sleep(0) until the deadline. It runs once per frame in the virtual camera filter (virtualcam-filter.cpp.hpp:195), i.e. inside the process of whatever app is using the OBS Virtual Camera (Zoom, Teams, browsers), about 1 ms of spinning per frame.
Fix: same direction as the os_sleepto_ns sibling: a high-resolution waitable timer, or accept ~1 ms jitter and drop the spin. Virtual camera consumers rarely need sub-ms pacing.
Test / evidence: CPU time of a consumer process reading the virtual camera, before and after.
Claiming: drop the Sleep(0) tail in the virtual camera's sleepto_100ns, the issue's second option (accept ~1 ms jitter, no spin).
Measure first. Compile the real sleepto.c.h in an isolated harness and measure the calling thread's CPU per frame at 60 fps (GetThreadTimes), before and after. That is the number the issue asks for.
Delete the spin. After the Sleep(ms - 1) the function returns instead of looping on Sleep(0). The only caller waits on an absolute cur_time += obs_interval and ignores the return value, so returning up to 1 ms early does not drift the frame schedule: the next iteration just waits longer. Nothing else calls it.
Keep the evidence honest. I will report both numbers. A CPU bound test is safe in one direction (it cannot fail after the fix) but can pass on a loaded machine before it, so I will say what it does and does not prove rather than overselling it.
One PR against master. If the measurement shows the spin is not what the issue says it is, I will post that and release instead.
The real sleepto.c.h, compiled on its own, called on an absolute 60 fps grid (the filter's cur_time += obs_interval), 2000 frames per run, two rounds per arm. Thread CPU from GetThreadTimes; delta is the return time minus the deadline, percentiles over the run.
Host with a 1 ms timer period (libobs sets this for its own process):
CPU/frame
delta p50
p90
p99
before (spin)
0.71 / 1.41 ms
0.000 ms
0.000-0.004 ms
0.08-1.55 ms
after (no spin)
0.023 / 0.031 ms
-0.91 ms
-0.27 to -0.35 ms
0.29-2.15 ms
That is the ~1 ms the issue describes, gone: 30-50x less CPU, at the cost of producing each frame about 0.9 ms before its deadline.
Host at the default 15.6 ms granularity (the consuming app's own setting):
CPU/frame
delta p50
before
0.02-0.09 ms
5.3-6.6 ms late
after
0.02-0.03 ms
2.2-7.1 ms late
Here Sleep already overshoots the 16.67 ms deadline by several ms, the spin rarely runs, and the change is inside the noise. Worth stating plainly: the win only exists where the host has a fine timer.
No drift. Every run in both arms took 33333 ms for 2000 frames (16.667 ms/frame), so the early return is absorbed by the next, longer wait rather than accumulating.
Decisions
No test with this change. No test target compiles plugins/win-dshow/virtualcam-module, and the cmocka suite runs on Linux only, where this file is _WIN32-only, so a test there would be empty. Recorded here per docs/rust-port/testing-policy.md rather than silently skipped. The measurement above is the evidence, and a regression (re-adding the loop) is visible in it.
Contract change documented.sleepto_100ns no longer guarantees the target was reached; the header now says it returns true when the target had not already passed on entry, and the body comment gives the ~2 ms bound instead of the ~1 ms both earlier drafts claimed.
Activity
MCPVOT commentedon Oct 21, 2026
Claiming: drop the
Sleep(0)tail in the virtual camera'ssleepto_100ns, the issue's second option (accept ~1 ms jitter, no spin).sleepto.c.hin an isolated harness and measure the calling thread's CPU per frame at 60 fps (GetThreadTimes), before and after. That is the number the issue asks for.Sleep(ms - 1)the function returns instead of looping onSleep(0). The only caller waits on an absolutecur_time += obs_intervaland ignores the return value, so returning up to 1 ms early does not drift the frame schedule: the next iteration just waits longer. Nothing else calls it.One PR against
master. If the measurement shows the spin is not what the issue says it is, I will post that and release instead.MCPVOT commentedon Oct 21, 2026
Measurement
The real
sleepto.c.h, compiled on its own, called on an absolute 60 fps grid (the filter'scur_time += obs_interval), 2000 frames per run, two rounds per arm. Thread CPU fromGetThreadTimes; delta is the return time minus the deadline, percentiles over the run.Host with a 1 ms timer period (libobs sets this for its own process):
That is the ~1 ms the issue describes, gone: 30-50x less CPU, at the cost of producing each frame about 0.9 ms before its deadline.
Host at the default 15.6 ms granularity (the consuming app's own setting):
Here
Sleepalready overshoots the 16.67 ms deadline by several ms, the spin rarely runs, and the change is inside the noise. Worth stating plainly: the win only exists where the host has a fine timer.No drift. Every run in both arms took 33333 ms for 2000 frames (16.667 ms/frame), so the early return is absorbed by the next, longer wait rather than accumulating.
Decisions
plugins/win-dshow/virtualcam-module, and the cmocka suite runs on Linux only, where this file is_WIN32-only, so a test there would be empty. Recorded here perdocs/rust-port/testing-policy.mdrather than silently skipped. The measurement above is the evidence, and a regression (re-adding the loop) is visible in it.sleepto_100nsno longer guarantees the target was reached; the header now says it returns true when the target had not already passed on entry, and the body comment gives the ~2 ms bound instead of the ~1 ms both earlier drafts claimed.PR next.
docs: features line for the virtual camera spin (obs-rust#1279)
win-dshow: drop the virtual camera sleep spin (obs-rust#1638)