Repository navigation
obs-core: Port the minimum audio timestamp decisions (#2405) - #2406
Merged
Merged
Conversation
…-ts.c The per-source decisions of the "get minimum audio timestamp" step of the audio tick move from obs-audio.c to obs-audio-min-ts.c, on plain values: - obs_audio_min_ts_earlier(): find_min_ts's test for one source (not pending, a timestamp, strictly earlier than the minimum); - obs_audio_min_ts_insufficient(): audio_buffer_insufficient_locked, on audio_render, audio_pending by pointer, audio_ts and channel 0's buffered size; - obs_audio_min_ts_buffering(): the choice after the search between fixed, added and no buffering. The walk over the audio sources, the locks, the two passes of calc_min_ts, the names and the logging stay in obs-audio.c. Each source is still locked on its own while it is checked, so the values are read when they were before. Behaviour-neutral: audio_buffering_maxed() is still only read with fixed_buffer set. Refs obs-rust#2405 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cases for obs-audio-min-ts.c before its port, on plain values: the earlier-source test (pending, no timestamp, equal, earlier), the sufficiency check (render, pending and untimed sources; a whole tick and one sample less on min_ts and min_ts - 1; a start point inside the tick; a start point at and past AUDIO_OUTPUT_FRAMES, which is never short, where discard_audio stops only on ==), and the choice between fixed, added and no buffering. Through calc_min_ts in obs-audio.c, on a list of sources: the earlier source and its name, ties kept by the first (newest) source, no source earlier than the tick. Kept, characterized, not endorsed: when the source with the minimum is short for a tick at its own timestamp, mark_invalid_sources marks it pending and calc_min_ts searches again, but from the first pass's minimum. The comparison is strict, so the second pass finds nothing: the minimum stays the timestamp of the source just marked pending, audio_callback adds buffering for it, and the name is NULL. This is in the code since the audio subsystem of 2015 (c1dd156). Refs obs-rust#2405 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…port RED for the port of libobs/obs-audio-min-ts.c.h, the per-source decisions of the minimum audio timestamp step of the audio tick, to a new module, audio_min_ts, of rust/obs-core. The safe core is a stub (todo!()): earlier() (find_min_ts's test for one source), insufficient() (audio_buffer_insufficient, pending by reference) and buffering() with BufferingChoice (none, fixed, added). tests/obs_core/audio_min_ts.rs ports the 4 plain-value obs-audio-min-ts.c cases of test_audio_buffering_subsample 1:1, under the same names, in the same order, with the same inputs and expectations. The fifth cmocka case checks the walk in obs-audio.c and has no counterpart. New edge cases (edge_*): min_ts of 0 (min_ts - 1 wraps, as in C) and a sample rate of 0 (every offset maps to frame 0). Proptests: earlier() only lowers min_ts, to a valid earlier source's timestamp; insufficient() sets pending exactly when it returns true and never clears it, and is never short with a whole tick buffered. cargo test -p obs-data --test obs-tests-core obs_core::audio_min_ts fails 8 of 8 with "not yet implemented". Refs obs-rust#2405 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Ports libobs/obs-audio-min-ts.c.h, the per-source decisions of the minimum audio timestamp step of the audio tick, to the audio_min_ts module of rust/obs-core. The walk over the audio source list, the per-source locks, the two passes of calc_min_ts, the names and the logging stay C in obs-audio.c.h, so each value is read when it was before. The hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/audio_min_ts.rs): earlier() (not pending, a timestamp, strictly earlier: the new minimum), insufficient() (whether channel 0's buffered bytes are short for a tick at min_ts; a short source is marked pending) and buffering() (fixed, added or no buffering). The uint64_t and size_t arithmetic is the C's and wraps where it wraps; util_mul_div64 is audio_mix's, per host. No state, no lock; the module denies clippy's panic, indexing and arithmetic lints. Shim (src/ffi/audio_min_ts.rs): the three functions keep the C signatures; the choice is returned as the int of enum obs_audio_buffering_choice. Kept, characterized, not endorsed: the sufficiency check stops at a start point >= frame 1024 (discard_audio: ==); ties keep the first (newest) source; calc_min_ts's second pass never raises the minimum (C side). Intentional differences, where C dereferences null and libobs never gets there: a null min_ts or pending does nothing and returns false. C side: the file leaves libobs.core-output for its own group, libobs.ported-audio-min-ts (LIBOBS_PORTED_SOURCES), whose PCH is obs-audio-min-ts.h with media-io/audio-io.h and util/util_uint64.h. The three functions are not EXPORT, so the shims are hidden: rust-hidden.txt, the local: list of rust-exports.map and rust-unexports-macos.txt. ci/test_ported_sources.py checks the group on every host. Tier 1 obs_core::audio_min_ts passes 8/8. Refs obs-rust#2405 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Oracle (oracle/audio_min_ts.c): the original obs-audio-min-ts.c.h, unmodified, with its three functions renamed to oracle_*, plus the size and values of enum obs_audio_buffering_choice. util_mul_div64 stays the header inline. Tier 3 (tests/obs_core/audio_min_ts_parity.rs): both sides get the same values through their C signatures, and are compared: the result, the minimum after obs_audio_min_ts_earlier, and pending after obs_audio_min_ts_insufficient: - the enum's size and values; - every start frame at 44.1 and 48 kHz, on the frame's time and 1 ns either side, with the buffer one sample short, exact and one sample over; - 50 000 random cases per function (timestamps near the minimum, near 0 and near u64::MAX, any buffered size, rates from 0 to 384 kHz and any). Excluded, the intentional difference, tested on the shim alone: null pointers. port_comparison (benches/port_comparison/audio_min_ts.rs): the earlier-source test, and the sufficiency check of a source with enough input and a start point inside the tick. obs_core::audio_min_ts and audio_min_ts_parity pass 14/14 on macOS arm64. Refs obs-rust#2405 Co-Authored-By: Claude Opus 5.5 <[email protected]>
zackees
approved these changes
Oct 25, 2026
zackees
left a comment
Member
There was a problem hiding this comment.
Reviewed.
- The three decisions match the removed C:
earlieris the same!pending && ts && ts < mintest.insufficientkeeps theaudio_ts != min_ts && != min_ts - 1start-point trim, the>= AUDIO_OUTPUT_FRAMESearly return and settingaudio_pendingthrough the pointer. Theswitchkeeps the fixed / maxed /min_ts < ts.startbranches. - The
audio_buffering_maxed()call stays behindfixed_bufferthrough the&&, so it is still only called when the C called it. - The walk, the locks and the logging stay in C, for the reason given.
test_audio_buffering_subsample.cis the obs-rust characterization file of the earlier slices (#1905, #2404). The cases are only added, and the one removed line is its header comment.- The export, hidden and macOS lists, the unity group,
source-sets.jsonand the Tier 3 parity tests are all there. LGTM.
zackees
enabled auto-merge
October 25, 2026 18:02
6 of 7 tasks
This was referenced Oct 25, 2026
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 #2405
Slice 3 of
obs-audio.c, after #1903 and #2403 (#2404): the per-source decisions of the "get minimum audio timestamp" step of the audio tick move tolibobs/obs-audio-min-ts.c.hand are ported toobs_core::audio_min_ts.What changed
libobs/obs-audio-min-ts.{h,c.h}, on plain values:obs_audio_min_ts_earlier():find_min_ts's test for one source (not pending, a timestamp, strictly earlier than the minimum);obs_audio_min_ts_insufficient():audio_buffer_insufficient, onaudio_render,audio_pendingby pointer,audio_tsand channel 0's buffered size;obs_audio_min_ts_buffering(): the choice after the search between fixed, added and no buffering.obs-audio.c.hkeeps the walk over the audio source list, each source'saudio_buf_mutex, the two passes ofcalc_min_ts, the names and the logging. The walk stays C on purpose: each source is locked on its own, one after the other, and other threads change the values between the passes, so a walk over a snapshot would change when the values are read.rust/obs-core/src/audio_min_ts.rs(safe core) andsrc/ffi/audio_min_ts.rs(shim). Own unity grouplibobs.ported-audio-min-ts; the shims are hidden;ci/test_ported_sources.py;rust/README.md.Kept, characterized, not endorsed
calc_min_ts's second pass never raises the minimum. When the source with the minimum is short for a tick at its own timestamp,mark_invalid_sourcesmarks it pending andcalc_min_tssearches again, but from the first pass's minimum, not from the tick start. The comparison is strict, so the second pass finds nothing: the minimum stays the timestamp of the source just marked pending,audio_callbackadds buffering for it in that tick, and the "adding N milliseconds of audio buffering" line names(null). This is in the code since the audio subsystem of 2015 (c1dd156db, also upstream).calc_min_ts_through_the_listpins it onlibobsandlibobs-c-reference. A change would be its own issue.>=frame 1024, wherediscard_audiostops only on==.Intentional differences (C dereferences null; libobs never gets there)
min_tsorpendingdoes nothing and returns false.RED → GREEN
66f7e539f(behaviour-neutral, no Rust).audio_buffering_maxed()is still only read withfixed_bufferset.0d756de4d: 5 new cases intest_audio_buffering_subsample(35/35 onlibobs,libobs-c-referenceand the hybrid), 4 on plain values and 1 throughcalc_min_tson a list of sources.62f59a61c: Tier 1obs_core::audio_min_ts, the 4 plain-value cases 1:1 plus edge cases and proptests: 0 of 8 pass (todo!()).0606d6aeb: 8 of 8.4ede2cd2f: the C oracle (the file unmodified, functions renamed) against the shim: the enum, every start frame at 44.1 and 48 kHz with the buffer one sample short, exact and over, and 50 000 random cases per function.obs_core::audio*(audio_mix,audio_discard,audio_min_ts) 68/68 on Linux x86_64; 14/14 for this module on macOS arm64.Mutation check (done once, not committed): 13 of 14 mutants fail Tier 1 or Tier 3 (untimed or pending sources taken;
<=instead of<; the minimum not updated; render or pending sources checked;min_ts - 1not on the tick; an exact tick short; pending not set; the start point ignored;maxedinverted; added buffering on<=; the shim's enum values swapped). The survivor,>=→>on the start point, is equivalent: at a start point of exactly 1024 no frame is needed, so nothing is short.Tier 2 (Linux x86_64, Debian 13, Xvfb)
Lint lane (
ci/local_gate.py --lane lint) on the same host: clang-format, rustfmt, clippy-D warningsfor the workspace and every feature set, the Dylints and the ratchets pass; its self-test step skipstest_hybrid_packagingthere (nozstdon that host, the same on master).test_audio_buffering_subsample,test_audio_clock_drift,test_audio_sync_offset_change,test_audio_capture_mix_raceandtest_async_delay_audiopass on the hybrid libobs and onlibobs-c-reference(5/5 each). Exported symbols: 1766 on both; the three shims are local.port_comparison (Linux x86_64, one pinned core, criterion median, Rust / C)
Both run once per audio tick for every audio source. At this size the runs vary by about 0.4 ns: an earlier run on the same host gave 1.971 / 1.805 ns for
earlier, so the two are the same within noise. The real-host before/after (CT104, NDI/ALSA audio) for #2404 and this slice together follows with the next production rebuild after the merge.Checklist
master-W..., ratchets): noneAI note: Claude Code (Claude Opus 5.5) wrote the code, the tests, the commit messages and this text under the submitter's direction, and ran the tests above on the submitter's machines.