Repository navigation
obs-core: Port the graphics loop's frame timing (tick time and frame statistics) - #2763
Merged
Merged
Conversation
…ming.c Behaviour-neutral extraction before the Rust port (#2754). Two decisions of the graphics thread loop in obs-video.c.h move to libobs/obs-video-frame-timing.c.h, as two functions on plain values declared in the new libobs/obs-video-frame-timing.h without EXPORT (hidden, as -fvisibility=hidden keeps them): - obs_video_frame_timing_tick(cur_time, last_time, interval_ns): tick_sources()'s time since the last tick (last_time one interval back on the first frame, when it is 0) and its seconds as (float)((double)delta / 1e9), which every tick callback and every source's video_tick gets; - obs_video_frame_timing_stats(sums, frame_time_ns, video_time, last_time): the end of obs_graphics_thread_loop(): the render time, frame time and frame sums of struct obs_graphics_context, and once the frame time sum reaches one second, the fps (double), the average render time and the reset sums. obs-video.c keeps os_gettime_ns(), the tick callbacks under draw_callbacks_mutex, the source list under sources_mutex, the profiler, obs_video_stats_set_timing() (called only when the stats say report) and the context fields (it passes them in and stores what comes back). Refs #2754 Co-Authored-By: Claude Opus 5.5 <[email protected]>
test_video_frame_timing_steps compiles libobs/obs-video-frame-timing.c into itself (the functions are hidden in libobs) and pins the current C behaviour: - obs_video_frame_timing_tick(): one interval on the first frame (also at time 0 and earlier than one interval, where last_time wraps), the time since the last tick otherwise (25, 29.97, 30, 60 fps, a late frame, the same time), the float seconds (0.04f at 25 fps, 1.0f for one second), and a clock that goes backwards (the uint64_t delta wraps to nearly 2^64, characterized, not endorsed). - obs_video_frame_timing_stats(): below one second the sums grow and nothing is reported; at exactly one second (25 x 40 ms, and 30 x 29.97 fps frames) it reports the fps and the average render time and resets; a late frame that crosses the second; and, characterized, not endorsed: a frame time before the tick time (the step wraps and reports at once with an fps near 0), and the uint64_t and uint32_t sums at their limits. A report with the frame count wrapped to 0 (the C divides by zero) is unreachable and not covered. No display and no libobs core, so it runs on every platform, with ASan and UBSan. macOS: 7/7, clean with -Wconversion -Wsign-conversion. Refs #2754 Co-Authored-By: Claude Opus 5.5 <[email protected]>
RED for #2754. obs_core::video_frame_timing has its API and docs, with todo!() bodies: tick() (tick_sources()'s time since the last tick and its f32 seconds) and stats() (the frame statistics at the end of obs_graphics_thread_loop(): the sums, the one-second window, fps, average render time, reset). tests/obs_core/video_frame_timing.rs: - steps_*: test_video_frame_timing_steps.c 1:1 (7 cases, same names, values and expectations; floats compared bit for bit); - edge_*: proptests over full-range times, intervals and sums against models of the C's expressions, a realistic run (reports about once a second, fps near 1e9 / interval), and the intentional difference for a report with the frame count wrapped to 0 (the C divides by zero; unreachable). All 11 fail on the stubs (obs-tests-core, video_frame_timing). Refs #2754 Co-Authored-By: Claude Opus 5.5 <[email protected]>
GREEN for #2754: obs_core::video_frame_timing replaces libobs/obs-video-frame-timing.c in the hybrid libobs. - tick(): the last tick time one interval back when it is 0, the wrapping u64 delta, and the seconds as (f64 / 1e9) as f32 (the C's double, then float: the same IEEE roundings). - stats(): the three sums with wrapping arithmetic, and at one second of frame time the fps (f64 frames over the f64 seconds), the average render time and the reset sums. Intentional difference, unreachable: a report with the frame count wrapped to 0 gives an average of 0 (the C divides by zero). C ABI: ffi::video_frame_timing, #[repr(C)] mirrors of the three structs and the two shims, hidden like the C (rust-hidden.txt, rust-exports.map, rust-unexports-macos.txt). libobs: obs-video-frame-timing.c moves from libobs.core-output to its own group libobs.ported-video-frame-timing with a header that needs only obs-video-frame-timing.h, so the C oracle and the C test compile it on their own; ci/test_ported_sources.py lists it. Tier 1 (obs-tests-core, video_frame_timing): 11/11. obs-util export lists: 3/3. clippy -D warnings clean. Refs #2754 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Tier 2 layout and Tier 3 parity for #2754. - obs-c-oracle: oracle/video_frame_timing.c builds the original libobs/obs-video-frame-timing.c.h, unmodified, with its two functions renamed oracle_*, plus the layouts of its three structs as the C sees them; src/video_frame_timing.rs binds them. - tests/obs_core/video_frame_timing_parity.rs runs every call on the shim, the C and the safe core and compares exactly (integers, the bool, and the float seconds and double fps bit for bit): the layout; the tick over 0, 1, common times and intervals and the u64 edges; the statistics around the one-second window with sums at the u64 and u32 edges; a frame-by-frame run of 10 s at 25, 29.97, 30 and 60 fps with late frames; proptests over the full ranges. A report with the frame count wrapped to 0 is not given to the C (it divides by zero); there the shim is compared with the core (average 0), the one intentional difference. - Deliberate-break check (by hand, not committed): f32 seconds without the double step fail 3 of the 7 parity tests; the window as > instead of >= fails 2. - port_comparison/video_frame_timing.rs: 1024 frames at 60 fps with late frames, tick plus stats per frame, one checksum. macOS arm64 (M1 Max): Rust 5.46 us, C 7.02 us per 1024 frames. obs-tests-core video_frame_timing: 18/18 (11 Tier 1, 7 parity). clippy -D warnings clean on obs-c-oracle, obs-core and obs-data. Refs #2754 Co-Authored-By: Claude Opus 5.5 <[email protected]>
rust/README.md: obs-core's description and the swap-table row for libobs/obs-video-frame-timing.c.h (obs-core::video_frame_timing, group libobs.ported-video-frame-timing, the two hidden functions, and the intentional difference for a report with the frame count wrapped to 0). docs/rust-port/naming.md: obs-video-frame-timing.c.h among the units extracted from libobs/obs-video.c.h that live in rust/obs-core. Refs #2754 Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=cad46486daba52e37320337c986007d1292afdb5 secs=596 lanes=lint:run,rust-test:reused@dea530f7a23b,cross:reused@057585848c22,tier2-linux:run Ci-Attestation: {"at":1793180855,"gate":"rust/all/fmt","host":"linux-x86_64","key":"75baa89de4ec9cbf2c4e5d4b296f028ef58968dfd99b0ae79171b75d10455879","lane":"lint","parents":["09bdac5d9263620fc84eec72438ba0cbfe744949"],"secs":30,"stamp":"a542a672a3ea4b2c0588c5e3b66026f8","tree":"cad46486daba52e37320337c986007d1292afdb5","v":1,"via":"run"} Ci-Attestation: {"at":1793180855,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"75baa89de4ec9cbf2c4e5d4b296f028ef58968dfd99b0ae79171b75d10455879","lane":"lint","parents":["09bdac5d9263620fc84eec72438ba0cbfe744949"],"secs":30,"stamp":"18552c5bb11833bca60a6603079af84a","tree":"cad46486daba52e37320337c986007d1292afdb5","v":1,"via":"run"} Ci-Attestation: {"at":1793179976,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"dea530f7a23b0d1864b10a18f5006cb592c9fe03193144174111149a706501fb","lane":"rust-test","parents":["09bdac5d9263620fc84eec72438ba0cbfe744949"],"secs":null,"stamp":"42f74fb6f01362471df828c3d510d1ca","tree":"cad46486daba52e37320337c986007d1292afdb5","v":1,"via":"reused"} Ci-Attestation: {"at":1793179976,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"057585848c229cf3d8f64d85b58a1f4bf478dbf389f68a5e23d76f1adeb3a293","lane":"cross","parents":["09bdac5d9263620fc84eec72438ba0cbfe744949"],"secs":null,"stamp":"ac3a8de2e540c232c38757a76d64904d","tree":"cad46486daba52e37320337c986007d1292afdb5","v":1,"via":"reused"} Ci-Attestation: {"at":1793179976,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"057585848c229cf3d8f64d85b58a1f4bf478dbf389f68a5e23d76f1adeb3a293","lane":"cross","parents":["09bdac5d9263620fc84eec72438ba0cbfe744949"],"secs":null,"stamp":"67e9cb98b464e19bed71a0f684c23a14","tree":"cad46486daba52e37320337c986007d1292afdb5","v":1,"via":"reused"} Ci-Attestation: {"at":1793179976,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"057585848c229cf3d8f64d85b58a1f4bf478dbf389f68a5e23d76f1adeb3a293","lane":"cross","parents":["09bdac5d9263620fc84eec72438ba0cbfe744949"],"secs":null,"stamp":"bf53f8f442c639ba8969d98542424594","tree":"cad46486daba52e37320337c986007d1292afdb5","v":1,"via":"reused"} Ci-Attestation: {"at":1793179976,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"057585848c229cf3d8f64d85b58a1f4bf478dbf389f68a5e23d76f1adeb3a293","lane":"cross","parents":["09bdac5d9263620fc84eec72438ba0cbfe744949"],"secs":null,"stamp":"246d6c751830e6a21870503543dfcb31","tree":"cad46486daba52e37320337c986007d1292afdb5","v":1,"via":"reused"} Ci-Attestation: {"at":1793180855,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"b2b43c0e94a2ac1950b52a423a30e2c4d09ea7bba50b807e4277e4c346f512c8","lane":"tier2-linux","parents":["09bdac5d9263620fc84eec72438ba0cbfe744949"],"secs":566,"stamp":"ac1f629ed68f0dc17310c8958c004526","tree":"cad46486daba52e37320337c986007d1292afdb5","v":1,"via":"run"}
zackees
reviewed
Oct 28, 2026
zackees
left a comment
Member
There was a problem hiding this comment.
Reviewed. This is the shape a port PR should have, and I found nothing to change.
What I verified rather than took on trust:
- The unit is two plain-value functions, split out behaviour-neutrally first (
obs_video_frame_timing_tick,obs_video_frame_timing_stats), with the loop's I/O —os_gettime_ns(), the tick callbacks underdraw_callbacks_mutex, the source list undersources_mutex, the profiler,obs_video_stats_set_timing()— left inobs-video.c. That is the split that makes Tier 3 parity meaningful: the shim cannot accidentally test itself. - RED then GREEN is in the commit order, stubs failing 11 tests before the port lands, and the characterization test (
test_video_frame_timing_steps, 7 cases under ASan and UBSan) exists before the Rust port so the C's behaviour — including the wrap on a backwards clock and theuint64_t/uint32_tlimits — is pinned first. The limits are characterized as observed, not endorsed, which is the right call. - The stated intentional difference is the safe direction. A report whose frame count wrapped to 0 gives 0 average render time in Rust where the C divides by zero; it is unreachable in practice and it removes a UB path rather than adding one. Calling it out in the body is what makes that reviewable.
- Tier 3 coverage is exact, not approximate: shim, C and core on every call with the float seconds and the double fps compared bit for bit, plus the deliberate-break check (
f32without thedoublestep fails 3 of 7;>instead of>=fails 2) — a differential suite that fails when the port drifts, which is the only kind worth having. - The head carries
Local-GateandCi-Attestationtrailers for its exact tree (cad46486…), so the skipped lanes are skipped for a stamped reason; the Windows MSVC/WX, macOS arm64 ASan+UBSan and the 9 neighbouring libobs tests are reported separately. Rebase onto545007864was a no-conflict range-identical replay, docs conflicts resolved by keeping both. - No
docs/features.mdline, correctly: a port is behaviour-neutral (the precedent set by #2721).
No changes requested. It is queued.
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.
Port of the frame timing decisions of the graphics thread loop in
libobs/obs-video.c.htorust/obs-core(video_frame_timing), next tovideo_pacing(#2738, the frame time step ofvideo_sleep()in the same loop).Fixes #2754
Commits
libobs: Move the graphics loop's frame timing into obs-video-frame-timing.c(behaviour-neutral).test: Characterize the graphics loop's frame timing(test_video_frame_timing_steps).obs-core: Add Tier 1 tests for the frame timing port(RED: 11 tests ontodo!()stubs).obs-core: Port the graphics loop's frame timing(GREEN:obs-core::video_frame_timing, the shims, grouplibobs.ported-video-frame-timing).obs-core: Check the frame timing port against the C(oracle, Tier 3 parity,port_comparison).docs: Record the frame timing port.Unit
Two functions on plain values, declared in
libobs/obs-video-frame-timing.hwithout EXPORT (hidden):obs_video_frame_timing_tick(cur_time, last_time, interval_ns):tick_sources()'s time since the last tick (one interval back on the first frame, when the last tick time is 0) and its seconds as(float)((double)delta / 1e9), which every tick callback and every source'svideo_tickgets.obs_video_frame_timing_stats(sums, frame_time_ns, video_time, last_time): the end ofobs_graphics_thread_loop(): the render time, frame time and frame sums ofstruct obs_graphics_context, and once the frame time sum reaches one second, thedoublefps, the average render time and the reset sums.obs-video.ckeepsos_gettime_ns(), the tick callbacks underdraw_callbacks_mutex, the source list undersources_mutex, the profiler,obs_video_stats_set_timing()(called only when the stats say report) and the context fields.The Rust core keeps the C's wrapping unsigned arithmetic and the same IEEE conversions (
u64tof64,f64tof32). One intentional difference, unreachable: a report with the frame count wrapped to 0 (2^32 frames without one second of frame time) gives an average render time of 0; the C divides by zero.Tests
test_video_frame_timing_steps, 7 cases, ASan and UBSan): the first frame, normal and late frames at 25, 29.97, 30 and 60 fps, the float seconds, a clock that goes backwards (the delta wraps), the statistics below, at and across the one-second window, and the sums at theuint64_tanduint32_tlimits (characterized, not endorsed).f32seconds without thedoublestep fail 3 of the 7 parity tests, the window as>instead of>=fails 2.port_comparison(video_frame_timing/frame/1024, 60 fps with late frames, tick and stats per frame): macOS arm64 Rust 5.46 us, C 7.02 us.Verification
ci-lint local-gate run): lint 70 s, rust-test 278 s, cross 116 s, tier2-linux 568 s; after the rebase onto545007864lint (30 s) and tier2-linux (566 s) ran again, rust-test and cross were reused for unchanged inputs (OBS_CTEST_JOBS=16, both ctest modes against libobs and libobs-c-reference, plus the exported-symbol diff). The head carries theLocal-GateandCi-Attestationtrailers for its exact tree, so PR CI can skip Rust Tests (Linux), Rust Tier 2 Linux and Rust Cross Lint.windows-ci-x64, MSVC/WX): libobs and the tests build with no warning;test_video_frame_timing_steps7/7 and the other video and encoder step tests pass;obs-tests-corevideo_frame_timingwith MSVC (the oracle compiled by MSVC): 18/18.test_video_frame_timing_steps7/7 with ASan + UBSan and-Wpedantic -Wmissing-prototypes -Wstrict-prototypes -Wconversion -Wsign-conversion;obs-tests-corevideo_frame_timing18/18; obs-util export lists 3/3;clippy -D warningsclean.parity_stats_full_rangewith 14.6 MB and 0.18 s (the empty test exe is about 7.7 MB); all 18 together over 30 runs, 17.4 MB and 0.27 s. No generated value drives an allocation.bd6f3ceea(obs-core: Port the Linux system info parsing #2721), then onto545007864(no conflicts, range-diff identical);git range-diffshows only the doc conflicts with obs-core: Port the Linux system info parsing #2721 inrust/obs-core/src/lib.rs,rust/obs-core/Cargo.toml,rust/README.mdanddocs/rust-port/naming.md, resolved by keeping both.These real-libobs tests stay green:
test_source_video_tick_steps,test_source_profiler,test_media_restart_stale_frame,test_transition_recursive_destination,test_slideshow_empty,test_slideshow_manual_end,test_video_pacing_steps,test_video_output_step_steps,test_video_copy_plan_steps.🤖 Generated with Claude Code