Repository navigation
obs-source: Port the async video frame pacing - #2046
Merged
Merged
Conversation
Behaviour-neutral extraction before the Rust port. The pacing decisions of get_closest_frame() and ready_async_frame() in obs-source.c.h, which pick the frame async_tick() shows for every async source without 2x deinterlacing (media, cameras, capture cards), move to libobs/obs-source-async-pacing.c.h as one function on the queue's timestamps, obs_source_async_pacing(), declared in the new libobs/obs-source-async-pacing.h without EXPORT (hidden, as -fvisibility=hidden keeps it). Every rule moves unchanged: - the first-frame rule: with last_frame_ts 0 the oldest frame is shown, buffered or not, and seeds last_frame_ts; - unbuffered: the newest frame, the older ones dropped, and last_frame_ts set even then (upstream d60d222); - the timing jump: the oldest frame more than MAX_TS_VAR from last_frame_ts, either way (frame_out_of_bounds(), upstream 1c40ce6), is shown at once and becomes the clock; - the catch-up walk: the source clock advances by sys_time - last_sys_timestamp and drops the frames it passed, keeps a passed frame while the next is due within 2 ms (upstream 76870d1; only once a frame is passed, upstream 62500b5), never drops the last queued frame, and re-anchors when the next frame jumps more than MAX_TS_VAR; - the seed of last_frame_ts from the shown frame when it is 0. obs-source.c.h keeps everything that touches the queue or the frames: the async_frames queue, da_erase(), remove_async_frame(), the async cache, async_mutex (async_tick() holds it) and the frame pointers. It copies the timestamps, oldest first, into a stack array of MAX_ASYNC_FRAMES, calls the function, erases drop_front frames from the front (remove_async_frame() on each, after its erase, as before), stores last_frame_ts and takes the front frame when take_first is set. Why that order is the same: every da_erase() in ready_async_frame() was at index 0 and erased the front frame, and remove_async_frame() of that frame followed it. In the walk the passed frame is always array[0] and the next array[1], so the erases are a prefix of the queue, in order. Neither da_erase() nor remove_async_frame() reads a timestamp or last_frame_ts, so computing first and applying after gives the same queue, cache, prev_frame flags and last_frame_ts. remove_async_frame(source, NULL), which the walk called before it had passed a frame, did nothing: no cached frame is NULL (obs_source_frame_create() uses bzalloc()). Checked in a scratch harness (not committed) that compiles origin/master's two functions verbatim on a stand-in source: 20,000,000 random queues of 0 to 40 frames give the same drops, frame and last_frame_ts, the erases are always a prefix released in order, and the characterization test of the next commit passes against it. cache_video() checks MAX_ASYNC_FRAMES before it unlocks async_mutex to copy the frame, and obs_source_output_video_internal() queues it under a second lock, so a source that outputs from several threads can queue a few frames more than 30. get_closest_frame() then copies into a heap buffer instead, so no queue length overflows the stack array. The DEBUG_ASYNC_FRAMES logging (compiled out, 0) goes. All arithmetic is the same uint64_t arithmetic, wrapping where it wrapped. frame_out_of_bounds() stays in obs-internal.h for obs-source-deinterlace.c; the new file has its own copy on values. The 2 ms guard and MAX_TS_VAR are named in the header, and obs-source.c.h checks MAX_TS_VAR against it at compile time. The new file joins libobs.core-source with libobs.pch.h, which includes the new header. The exported symbol sets are unchanged (1766). Refs obs-rust#2024
test_async_frame_pacing_steps compiles libobs/obs-source-async-pacing.c.h (ASan and UBSan, no libobs core) and calls only obs_source_async_pacing(), so it runs on every platform. A model queue stands in for async_frames: it applies each result as get_closest_frame() does (drop_front frames off the front, then the front frame taken) and stores last_sys_timestamp as async_tick() does. Every call also checks the contract obs-source.c.h relies on: drop_front below the queue length, and nothing dropped without a frame taken. 12 cases: - an empty queue (NULL timestamps): nothing dropped or taken; - the first-frame rule: last_frame_ts 0 shows the oldest frame, buffered or unbuffered, whatever the clocks, and seeds last_frame_ts; - unbuffered with 1, 2 and 30 frames: the newest, the others dropped, no jump rule and no walk; and 31 and 40 frames, which cache_video()'s unlocked check lets producers on several threads queue; - the timing jump at MAX_TS_VAR - 1, MAX_TS_VAR and MAX_TS_VAR + 1, ahead and behind (strict: MAX_TS_VAR is not a jump), only on the oldest frame, and between 0 and UINT64_MAX; - the 2 ms guard: the next frame due 1999999 ns ago keeps the passed one, 2000000 and 2000001 drop it; not applied before a frame is passed (upstream 62500b5), so a frame 1 ns due is shown; a frame exactly at the clock is not due; - the re-anchor inside the walk at MAX_TS_VAR + 1 (and not at MAX_TS_VAR), backwards, twice in one walk; - timestamps going backwards, by 1 ns and down a queue; - sys_time before last_sys_timestamp, the clock wrapping below 0 and the jump that recovers on the next tick; - 30 frames all in the past: the walk stops at one frame left, or keeps the one before when the last is within the guard; - sequences on exact integer clocks: 30 fps into 60 (each frame two ticks), 60 into 30 (every other frame dropped), 30 into 30, and 60 into 30 unbuffered. Characterized, not endorsed: - a frame at timestamp 0 seeds last_frame_ts 0, so the next tick takes the first-frame rule again; a timing jump to timestamp 0 does the same; - the first-frame rule shows the oldest frame even when the source is unbuffered; - a timestamp before the passed frame's, by any amount, wraps past MAX_TS_VAR and re-anchors the clock; - sys_time before last_sys_timestamp wraps sys_offset and moves the source clock back, so a frame that was due is held; below 0 it wraps to near UINT64_MAX and the walk drops to the last frame; - the re-anchor uses the passed frame's offset from the clock before this tick's advance, so a re-anchoring tick loses its sys_offset; - a re-anchor that lands on 0 shows the passed frame and re-seeds last_frame_ts from it; - at the same source and canvas rate on exact clocks, every frame after the first is shown a tick late (the clock must be strictly past a frame). The expectations were checked against origin/master's get_closest_frame() and ready_async_frame() compiled verbatim on a stand-in source (scratch, not committed): all 12 cases pass there too. It is in the native test graph, in the core suite. It needs no libm and includes only obs-source-async-pacing.h. Refs obs-rust#2024
RED for the port of libobs/obs-source-async-pacing.c.h to the async_pacing module of rust/obs-source, next to deinterlace_pacing (obs-rust#1950). The safe core is a stub (todo!()): pace(timestamps, sys_time, state) -> Pacing { drop_front, take_first, last_frame_ts }, the hidden C function on a slice of the queue's timestamps and the source's last_frame_ts, last_sys_timestamp and async_unbuffered; frame_out_of_bounds(), its own copy of the obs-internal.h inline on values; and MAX_TS_VAR and FRAME_TOLERANCE. tests/source/async_pacing.rs ports test_async_frame_pacing_steps 1:1: its 12 cases under the same names (steps_*), in the same order, with the same inputs and expectations, the characterized-not-endorsed cases and the model queue of the sequences included. Edge cases (edge_*) check pace() against a model of the original get_closest_frame() and ready_async_frame(), written as the C was, on a Vec queue that erases at index 0 and records each frame remove_async_frame() releases, so each case also checks that the erases are a prefix of the queue, released in order, and that the frame taken is the one after them. They also check the contract obs-source.c.h relies on (drop_front below the length, nothing dropped without a frame taken, the first-frame and newest- only rules) over: every queue of up to two of 18 special values (0, 1, the thresholds +-1 around a clock, 2^63, the end of the range), from each of them as last_frame_ts, over 9 canvas steps (the guard and jump edges, backwards, wrapping) and both bufferings; queues of three of them, buffered; frame_out_of_bounds() against i128 arithmetic; and two proptests, full-range queues of 1 to 30 frames and frame-rate-like queues with jitter and a jump (4000 cases each). soldr cargo test -p obs-data --test obs-tests-core -- source::async_pacing fails 17 of 17 with "not yet implemented". Refs obs-rust#2024
Ports libobs/obs-source-async-pacing.c.h, the frame pacing of every async source without 2x deinterlacing (media, cameras, capture cards), to the async_pacing module of rust/obs-source. get_closest_frame() stays C in obs-source.c.h: the copy of the queue's timestamps, the erases at index 0 with remove_async_frame() on each, the store of last_frame_ts and the frame taken, the async_frames queue, the async cache, async_mutex and the frame pointers. The hybrid libobs drops the C file and links the Rust shim in its place. Safe core (src/async_pacing.rs): pace() is the C function on a slice. With last_frame_ts 0 it takes the oldest frame (the first-frame rule); unbuffered it drops all but the newest; buffered it takes the oldest after a timing jump (frame_out_of_bounds(), its own copy of the obs-internal.h inline: more than MAX_TS_VAR either way), else walks: the clock advances by the wrapped sys_time - last_sys_timestamp, the frames passed are dropped, the passed frame is kept while the next is due within FRAME_TOLERANCE (only once a frame is passed), the last frame is never dropped, and the clock re-anchors to the next frame less the passed frame's offset when the next frame is more than MAX_TS_VAR (wrapped) after it. A frame taken with last_frame_ts 0 seeds it. The walk keeps the C's index arithmetic as front, the index of async_frames.array[0]: each da_erase() at index 0 is front + 1, and "one frame left" is no timestamp at front + 1. Every sum and difference is wrapping_* where the C's uint64_t wraps. The module denies clippy's arithmetic, indexing, as, unwrap, expect, panic, unimplemented and unreachable lints, keeps no state and takes no lock. Shim (src/ffi/source_async_pacing.rs): obs_source_async_pacing() keeps the C signature and returns struct obs_source_async_pacing_result by value (#[repr(C)]: size_t, uint64_t, bool). It reads count timestamps and nothing else, and writes through no pointer. Intentional difference: a null timestamps with a count above 0 reads as an empty queue (nothing dropped or taken, last_frame_ts kept), where the C reads through the null pointer; libobs never passes an empty queue and always passes its own array. Kept, characterized, not endorsed (test_async_frame_pacing_steps): a frame at timestamp 0 seeds last_frame_ts 0; the first-frame rule shows the oldest frame of an unbuffered source; a timestamp before the passed frame's re-anchors; a canvas clock going backwards moves the source clock back, below 0 to near UINT64_MAX; a re-anchoring tick loses its sys_offset; a re-anchor onto 0 re-seeds; at equal rates on exact clocks frames come a tick late. C side: the file leaves libobs.core-source for its own group, libobs.ported-source-async-pacing (LIBOBS_PORTED_SOURCES), whose PCH is only obs-source-async-pacing.h; libobs.pch.h keeps the header for obs-source.c. The function is not EXPORT, so the shim is hidden: rust-hidden.txt, the local: list of rust-exports.map and rust-unexports-macos.txt. libobs-rust already links the crate's ffi. The exported symbol sets are unchanged and equal: 1766 on the C backend, the hybrid and libobs-c-reference; obs_source_async_pacing is local in all three, and the hybrid's comes from the Rust archive. ci/test_ported_sources.py checks the group on every host. test_async_frame_pacing_steps still compiles the C file into itself, unchanged. The new test_async_frame_pacing_steps_rust builds the same test source against libobs_rust-static instead, as test_deinterlace_pacing_steps_rust does, and links: the test includes only the header and calls only the hidden function. The real-libobs tests (test_media_restart_stale_frame, test_media_restart_first_frame, test_async_delay_audio, the v4l2 tests) see the swap through the hybrid. Tier 1 source::async_pacing passes 17/17. Refs obs-rust#2024
Oracle (oracle/source_async_pacing.c): the original obs-source-async-pacing.c.h, unmodified, with its function renamed to oracle_obs_source_async_pacing, plus the two thresholds and the layout of struct obs_source_async_pacing_result (its size and the offsets of its three fields). take_first is declared as u8 on the Rust side, the byte the C stores. Tier 3 (tests/source/async_pacing_parity.rs, 8 tests). Each call compares the bytes of the two results: drop_front and last_frame_ts as their bytes, take_first as its byte. Runs: - the thresholds and the result's size and offsets against the C header; - every queue of up to two of 20 special values (0, 1, the guard and MAX_TS_VAR +-1 around a clock, 2^63 +-1, the end of the range) from each of them as last_frame_ts, over 10 canvas steps (none, a tick, the guard and jump edges, backwards, wrapping), both bufferings: 168,400 calls; and every queue of three from five last_frame_ts values, buffered: 400,000 calls; - proptests over full-range u64 queues of 1 to 30 frames, and over queues near the clock whose steps sit at the guard, at MAX_TS_VAR, at a frame interval, at 0 or anywhere (20000 cases each); - 3000 random sequences of 2 to 300 canvas ticks through a model of async_tick(), get_closest_frame() and cache_video(): the queue and its 30-frame limit (a full queue resets it and last_frame_ts), the erases from the front, the stores of last_frame_ts and last_sys_timestamp, and the frame taken, driven once by the C and once by the shim. Sources of 23.976, 25, 29.97, 30, 50 and 60 frames a second into 30 and 60 fps canvases, buffered and unbuffered, with timestamp and arrival jitter, latency, bursts, lost frames, late ticks, ticks that stop (the queue fills), a canvas clock going back, timestamps that jump ahead or back by MAX_TS_VAR, MAX_TS_VAR + 1 or any amount or land anywhere, resets (obs_source_output_video(NULL)) and the buffering toggled. The bytes of every call's result and the model's state after every tick must be equal; - every rate pair, buffered and unbuffered, clean and jittered, 600 ticks each from fixed seeds with a jump each way; the clean buffered runs show their frames in order and never twice; - a check that 2000 sequences reach every rule more than 100 times: the first-frame rule (2817), unbuffered (102863), the timing jump (116), nothing due (29383), the front frame (84569), frames dropped (17316), dropped to the last (2226), the guard keeping a frame (12614), a re-anchor or seed (370) and a full queue (253). The parity module passed 20 runs in a row with fresh random seeds; no regression file came up. Mutation check (done once, not committed), with Tier 1 (17 tests) and Tier 3 (8) in one run: 51 mutants, 44 in the core and 7 in the shim. Every non-equivalent core mutant fails both tiers: | Mutant | Tier 1 | Tier 3 | |---|---|---| | frame_out_of_bounds > as >=, either side | 4 | 3 | | frame_out_of_bounds one-sided (wrapping) | 10 | 6 | | no timing jump at all | 7 | 7 | | no first-frame rule | 4 | 6 | | no seed of last_frame_ts / seed from the oldest frame | 8 / 2 | 6 / 2 | | an empty queue takes a frame | 2 | 1 | | unbuffered keeps two / drops none / walks | 6 | 6 | | unbuffered keeps last_frame_ts / stores the oldest | 6 | 6 | | jump without its store / returns false / off | 6 | 7 | | sys_offset reversed / saturating | 9 / 2 | 6 / 4 | | clock advance saturating / missing | 3 / 8 | 5 / 6 | | frame_offset taken after the advance | 4 | 6 | | walk while >= | 4 | 5 | | guard <= | 3 | 2 | | guard before a frame is passed (pre-62500b512) | 4 | 6 | | no guard / 1 ms guard (pre-76870d176) | 5 | 6 / 7 | | erase before a frame is passed | 9 | 6 | | no erase (the walk never ends: killed by the hang) | 11 hung | 6 hung | | last-frame check one early | 10 | 6 | | walk returns true without a frame | 7 | 6 | | drop_front one more / the last frame not dropped | 8 / 9 | 6 | | re-anchor >= / off / without or adding the offset | 3 / 5 | 3 / 6 | | re-anchor saturating (no backwards re-anchor) / two-sided | 5 | 6 / 4 | | frame_offset or frame_time not updated | 2 / 4 | 5 | | MAX_TS_VAR +-1 | 2 | 5 / 4 | Two survive and are equivalent: frame_out_of_bounds with ts <= last_frame_ts (at equality both branches compute 0), and the guard's difference saturating (the guard runs only inside "while last_frame_ts > next", so it cannot wrap). The 7 shim mutants (take_first negated, drop_front one less, the old last_frame_ts returned, last_frame_ts and last_sys_timestamp swapped, async_unbuffered negated, a count of 1 read as empty, one timestamp short) fail Tier 3 (6 or 7 of 8); Tier 1 does not reach the shim. Intentional difference, not compared: a null timestamps with a count above 0 is an empty queue for the shim; the C reads through it. Refs obs-rust#2024
The rust/README.md crate table now lists libobs/obs-source-async-pacing.c.h among the units rust/obs-source holds, and its port table has a row for it: the one function, its rules, what stays C in get_closest_frame() (the copy of the timestamps, with its heap fallback past MAX_ASYNC_FRAMES, the erases at index 0 with remove_async_frame() after each, the stores and the frame taken), the wrapping arithmetic, what the characterization pins and the port keeps, the one intentional difference (a null timestamps with a count above 0 is an empty queue), the _rust variant of the steps test, the real-libobs tests that see the swap, and what Tier 3 compares. The crate's description and lib.rs say what it holds. docs/rust-port/naming.md already maps libobs/obs-source*.c.h to rust/obs-source. port_comparison gets its own bench file, benches/port_comparison/source_async_pacing.rs: 1024 ticks' queues recorded from a 29.97 frames a second source into a 60 fps canvas, with jitter, late deliveries and clock jumps, run buffered (the jump check, the walk, the guard and the re-anchor) and unbuffered, plus 1024 walks over 30 frames all in the past, the results folded into a checksum both sides must match. On x86_64 Linux (GCC, not pinned, a loaded host; median per 1024 ticks): buffered_tick 4.34 us Rust and 3.43 us C (1.26x), unbuffered_tick 3.83 us Rust and 3.05 us C (1.25x), walk_30 25.30 us Rust and 22.98 us C (1.10x): under 1 ns more per tick, about 2 ns for a 30-frame walk. Fixes obs-rust#2024
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 24, 2026
6 of 7 tasks
6 of 7 tasks
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 #2024
What and why
Ports the async video frame pacing of
get_closest_frame()andready_async_frame()inlibobs/obs-source.c.htorust/obs-source, as a new moduleasync_pacingnext todeinterlace_pacing(#1950). Once a tick,async_tick()uses these rules to choose which queued frame to show. That applies to every async source without 2x deinterlacing: media, cameras and capture cards. A wrong rule would drop or repeat frames for all of them, or put audio and video out of sync. So every rule from the functions' history is pinned in the characterization and checked by a mutant:last_frame_tsis set for unbuffered sources too (upstream d60d222);MAX_TS_VARis used both for the jump and for the re-anchor (upstream 1c40ce6);Six commits:
Move (behaviour-neutral): the decisions go to
libobs/obs-source-async-pacing.c.has one function,obs_source_async_pacing(), declared in the newobs-source-async-pacing.hwithoutEXPORT(hidden). It takes the queue's timestamps, oldest first, withsys_time,last_frame_ts,last_sys_timestampandasync_unbuffered. It returnsstruct obs_source_async_pacing_result { size_t drop_front; uint64_t last_frame_ts; bool take_first; }.frame_out_of_bounds()stays inobs-internal.hforobs-source-deinterlace.c.h; the new file has its own copy on values.obs-source.c.hkeeps everything that touches the queue or the frames:async_frames,da_erase(),remove_async_frame(), the async cache,async_mutex(held byasync_tick()) and the frame pointers.get_closest_frame()copies the timestamps into a stack array ofMAX_ASYNC_FRAMESand calls the function. It then erasesdrop_frontframes at index 0, each followed byremove_async_frame()as before, storeslast_frame_ts, and takes the front frame whentake_firstis set.Why this order is the same as before. Every
da_erase()inready_async_frame()was at index 0 and erased the front frame, andremove_async_frame()of that frame followed it. In the walk, the passed frame is alwaysarray[0]and the next isarray[1], so the erases are a prefix of the queue, in order. Neitherda_erase()norremove_async_frame()reads a timestamp orlast_frame_ts, so deciding first and applying afterwards gives the same queue, cache,prev_frameflags andlast_frame_ts. The walk also calledremove_async_frame(source, NULL)before it had passed a frame. That did nothing, because no cached frame is NULL (obs_source_frame_create()usesbzalloc()).This was checked against the original code. A scratch harness (not committed) compiles origin/master's two functions verbatim on a stand-in source. On 20,000,000 random queues of 0 to 40 frames it gives the same drops, the same frame taken and the same
last_frame_ts. Its erases are always a prefix of the queue, released in order, and the characterization of commit 2 passes against it too.The
DEBUG_ASYNC_FRAMESlogging (compiled out) goes.MAX_TS_VARis checked against the header with_Static_assert. The file stays inlibobs.core-sourcefor this commit.Characterization:
test_async_frame_pacing_steps, 12 cases. It compiles the moved file and calls the function through a model queue, which applies each result asget_closest_frame()does and storeslast_sys_timestampasasync_tick()does. Every call also checks the contract the caller relies on:drop_frontis below the queue length, and nothing is dropped without a frame taken. It pins:last_frame_ts == 0(the first-frame rule);MAX_TS_VAR- 1,MAX_TS_VARandMAX_TS_VAR+ 1, ahead and behind;MAX_TS_VAR+ 1 but not atMAX_TS_VAR, backwards, and twice in one walk);sys_time < last_sys_timestamp;It is in the core suite of the test graph, so no pinned count changes. It needs no libm and includes only the new header.
RED: Tier 1 in the crate against
todo!(). 17 of 17 fail.GREEN: the safe core and the
#[no_mangle]shim, in a newlibobs.ported-source-async-pacinggroup whose PCH is only the new header. This commit updates the three export lists,source-sets.json, the unity lists andci/test_ported_sources.py, each in sorted place, and addstest_async_frame_pacing_steps_rust.Tier 3: a C oracle and byte-level parity, plus the mutation check.
Docs: the README rows, the crate's description and
lib.rs, and aport_comparisonbench file.docs/rust-port/naming.mdalready mapslibobs/obs-source*.c.htorust/obs-source.Every sum and difference is
wrapping_*where the C'suint64_twraps:sys_time - last_sys_timestamp, the clock advance,frame_offset, the guard's difference and the re-anchor'snext - frame_timeandnext - frame_offset. The walk keeps the C's index arithmetic asfront, the index ofasync_frames.array[0]: eachda_erase()at index 0 becomesfront + 1, and "one frame left" means there is no timestamp atfront + 1. The core denies clippy's arithmetic, indexing,as, unwrap, expect, panic, unimplemented and unreachable lints. The crate still depends on no other crate.What changed in the C.
get_closest_frame()now copies the timestamps, calls the function and applies the result. For a queue longer thanMAX_ASYNC_FRAMESit copies into abmalloc()buffer instead of the stack array (see the first finding). Nothing else changed.Kept, characterized, not endorsed:
last_frame_ts0, so the next tick takes the first-frame rule again. A timing jump to timestamp 0 does the same.MAX_TS_VARand re-anchors the clock.sys_timebeforelast_sys_timestampwrapssys_offsetand moves the source clock back, so a frame that was due is held. Below 0 the clock wraps to nearUINT64_MAX, the walk drops to the last frame, and the next tick recovers through the jump rule. libobs'svideo_timedoes not go backwards, so this is reachable only through a source clock that wraps.sys_offset(up to one canvas interval).last_frame_tsfrom it.Intentional difference: if
timestampsis NULL with a count above 0, the shim treats it as an empty queue: nothing is dropped or taken andlast_frame_tsis kept. The C reads through the null pointer. libobs never passes an empty queue and always passes its own array. This is listed in the shim and parity test headers and in rust/README.md.The
_rustvariant links. The test calls the hidden function directly, sotest_async_frame_pacing_steps_rustbuilds the unchanged test source againstlibobs_rust-static, astest_deinterlace_pacing_steps_rustdoes. The test includes only the new header, which needs no SIMDe or graphics headers, so the target needs nolibobsinterface include directories. It passes 12/12 on the hybrid tree.Exported symbols: 1766 on the C backend, the hybrid and
libobs-c-reference, with identical sets, and the same as at commit 1 (checked on2183ae742, at GREEN and at commit 1).obs_source_async_pacingis local (t) in all three. In the hybrid it comes from the Rust archive, whoseasync_pacing::paceis linked in, and no async-pacing object is on the hybrid's link line. The ported group is compiled only intolibobs-c-reference.Performance (
port_comparison, x86_64, GCC, not pinned, a loaded host; median per 1024 ticks):buffered_tick(the jump check and the walk over recorded queues of a 29.97 fps source into 60 fps): 4.34 µs Rust, 3.43 µs C (1.26x);unbuffered_tick: 3.83 µs Rust, 3.05 µs C (1.25x);walk_30(30 frames in the past): 25.30 µs Rust, 22.98 µs C (1.10x).That is under 1 ns more per tick for the queues a source sees, and about 2 ns for a 30-frame walk, once per async source per canvas frame.
No user-visible change, so no
docs/features.mdline.Observed, not changed (upstream behaviour; nothing here is fixed):
MAX_ASYNC_FRAMESis not a hard limit.cache_video()checksasync_frames.num >= MAX_ASYNC_FRAMESunderasync_mutexand then unlocks it to copy the frame.obs_source_output_video_internal()queues the frame later, under a second lock. So a source that outputs from more than one thread can queue one extra frame per concurrent caller past 30. Upstream handled any length, so nothing breaks today. A fixed stack array of 30 in the new copy, however, would have been a stack overflow. That is whyget_closest_frame()falls back tobmalloc()for longer queues, and why the characterization pins 31 and 40 frames.cache_video()clears it at 30.RED → GREEN
254d779ca.soldr cargo test -p obs-data --test obs-tests-core -- source::async_pacingfails 17 of 17, every failure "not yet implemented": the 12 portedsteps_*cases and 5edge_*cases, two of them proptests. (The run was on the same commit before a rustfmt-only fixup of the test file and the rebases.)32c9c9e33. Tier 1 passes 17/17. Tier 2 ran under a privateXvfb -noresetwithdbus-run-session, a fresh HOME,ulimit -c 0and no TMPDIR, through ctest (so each test got its working directory and environment). It ran on2183ae742(this branch onec2a5a90b), whose C and Rust library code is the GREEN commit's. The final head2ff3e5387(onb3912c298) differs from it only by master's next three commits (frontend: main window controls through the platform facade (#873) #2037 frontend, fix(canvas): release a source's weak canvas ref after the canvas is gone #2041obs-canvas.c.hand its new test, infra(sanitize): run each unit test from its ctest working directory #2044 a sanitize script), none of which touches these files:test_media_restart_stale_frametest_media_restart_first_frametest_async_delay_audiotest_v4l2_frameratetest_v4l2_corrupt_framebusy,busy_signal,controls,fd_cloexec,input_caps,udev_poll_error,vcam_write)test_deinterlace_2x_field_ordertest_deinterlace_pacing_stepstest_deinterlace_pacing_steps_rusttest_async_frame_pacing_stepstest_async_frame_pacing_steps_rustNo ctest test was skipped. Inside the tests, three cases skip on each lane, as on master:
open_crashes_without_obs_coreintest_audio_ioandtest_video_io, andtest_hex_float_values_ignore_comma_locale, which needs a comma-decimal locale this host does not have. No rerun was needed: none of the real-time tests (#838) failed in any run. The same set also passed on all three builds on80cafa039(before #2021), with the full ctest at 411/411 and 419/419, and on the C backend and the hybrid at GREEN on46a482f83. Before the c-ref run,ninja libobs-c-referencewas run explicitly (no work to do: itslibobs.so.30was from the head build), and the loader was checked to uselibobs-c-reference/libobs.so.30(the tests have a RUNPATH, so LD_LIBRARY_PATH wins).Tier 3,
988dfd633(source::async_pacing_parity, 8 tests). Each call compares the bytes of the two results:drop_frontandlast_frame_tsas their bytes, andtake_firstas the byte the C stores. Runs:the two thresholds, and the result struct's size and field offsets, against the C header;
every queue of up to two of 20 special values (0, 1, the guard and
MAX_TS_VAR±1 around a clock, 2^63 ±1, the end of the range), with each of them aslast_frame_ts, over 10 canvas steps (none, a tick, the guard and jump edges, backwards, wrapping) and both bufferings: 168,400 calls. Also every queue of three, buffered, from fivelast_frame_tsvalues: 400,000 calls;proptests over full-range
u64queues of 1 to 30 frames, and over queues near the clock whose steps sit at the guard, atMAX_TS_VAR, at a frame interval, at 0 or anywhere (20,000 cases each);3000 random sequences of 2 to 300 ticks through a model of
async_tick(),get_closest_frame()andcache_video(), driven once by the C and once by the shim. The model covers the queue, its 30-frame limit and reset, the erases, the stores and the frame taken. The bytes of every call's result and the model's state after every tick must be equal. The sequences use:MAX_TS_VAR,MAX_TS_VAR+ 1 or any amount, or land anywhere;obs_source_output_video(NULL)) and the buffering toggled;every rate pair, buffered and unbuffered, clean and jittered, from fixed seeds. The clean buffered runs show their frames in order and never twice;
a check that 2000 sequences reach every rule more than 100 times:
The parity module passed 20 runs in a row with fresh seeds, and no regression file came up.
Mutation check (once, not committed; Tier 1 and Tier 3 in one run): 49 of 51 mutants fail, and the 2 that survive are equivalent.
frame_out_of_bounds:>as>=, behind / aheadframe_out_of_bounds: one-sided (the wrapped difference only)frame_out_of_boundsfalse)last_frame_ts/ seed from the oldest framelast_frame_ts/ stores the oldestsys_offsetreversed / saturatingframe_offsettaken after the advance>=<=>=/ off / without the offset / adding itframe_offset/frame_timenot updatedMAX_TS_VAR+ 1 / - 1take_firstnegated,drop_front- 1, the oldlast_frame_ts,last_frame_tsandlast_sys_timestampswapped,async_unbufferednegated, a count of 1 read as empty, one timestamp short (7 mutants)ts <= last_frame_tsinframe_out_of_bounds(at equality both branches give 0)while last_frame_ts > next)Other runs:
uv run ci/local_gate.py --test-diff origin/masteron the final head2ff3e5387(and before that on2183ae742, the same result): 3073/3073 passed, 2 skipped (the existing#[ignore]tests: the NVENC loader test, which needs an NVIDIA driver, and obs-source: Port the source audio input steps #2021's exhaustive balance test), and the doc-tests pass; all 25source::async_pacing*tests are among them.uv run ci/local_gate.py --lane lintand--lane cross: ok on2183ae742, and before that onf26b44e1b.cargo clippy -p obs-data --tests -p obs-c-oracle --all-targets -D warningsis clean.ci/test_build_groups.py,ci/test_ported_sources.py,ci/test_oracle_standins.py,ci/test_sorted_shared_lists.py,ci/test_test_graph_sorted.py,ci/test_cmocka_includes.py,ci/test_cmocka_rust_static_guard.pyandci/test_naming.py: OK on the final head2ff3e5387..cmakefiles formatted with gersemi 0.25.0; C with clang-format 22.1.3.80cafa039with no conflicts; ontoec2a5a90b, after obs-source: Port the source audio input steps #2021 (the source audio input steps) merged. obs-source: Port the source audio input steps #2021's entries sit next to this PR's inlibobs.pch.h,source-sets.json,ci/test_ported_sources.py, the three export lists,ffi/mod.rs,lib.rs, the testmain.rs, the oracle'slib.rs,port_comparison.rs, the crate description and the README. Every conflict was resolved by keeping both entries, in sorted order. Then ontob3912c298, with no conflicts. After each rebase,source-sets.json,test-graph.json, the unity lists and the three export lists were compared by hand against master: only this PR's lines differ.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)--test-diffpassed locally; nothing is stamped)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)