Repository navigation
Description
Unit
The per-source decisions of the "get minimum audio timestamp" step of the audio tick in libobs/obs-audio.c.h, into rust/obs-core as obs_core::audio_min_ts. Slice 3 of obs-audio.c, after #1903 (audio_mix) and #2403 (audio_discard, #2404). It moves first to libobs/obs-audio-min-ts.c.h.
find_min_ts, the comparison for one source: a source counts when it is not pending, has a timestamp, and is strictly earlier than the current minimum.audio_buffer_insufficient_locked: whether a source's input holds enough audio for a tick that starts atmin_ts; if not, the source is marked pending.- The choice after the search in
audio_callback: fixed buffering (whenfixed_bufferand not at the maximum), added buffering (whenmin_tsis before the tick start), or none.
These stay C in obs-audio.c.h: the walk over first_audio_source / next_audio_source under audio_sources_mutex, each source's audio_buf_mutex, the two passes of calc_min_ts, obs_source_get_name, and the logging. The walk stays C on purpose: each source is locked on its own, one after the other, and other threads change audio_ts and the input buffers between the passes. A Rust walk over a snapshot would change when the values are read.
Phase and position
Phase 6 (#444), the third slice of obs-audio.c. Crate obs-core, next to audio_mix and audio_discard. Size: S. After it, obs-audio.c.h keeps the audio tree walk, the monitoring checks, the task queue and audio_callback itself.
Seam
Plain values and one field by pointer: audio_render (as a bool), audio_pending (by pointer, set when the input is short), audio_ts, channel 0's input size in bytes, the sample rate and min_ts. No struct of obs-internal.h goes to Rust, and no public header changes. The functions run under the source's audio_buf_mutex, which the C keeps.
Characterized behaviour to keep
- The second pass of
calc_min_tscannot raise the minimum. Whenmark_invalid_sourcesmarks a source pending (its input is short for a tick atmin_ts),calc_min_tsrunsfind_min_tsagain, but from the minimum of the first pass, not from the tick start. The comparison is strict, so the second pass finds no source and only sets the name to NULL. The minimum stays the timestamp of the source that was just marked pending,audio_callbackadds buffering for it, and the "adding N milliseconds of audio buffering" line names(null). This is in OBS since the new audio subsystem (2015,c1dd156db). Only a concurrent change between the passes can lower the minimum. Confirmed on the C (libobsandlibobs-c-reference) with a characterization case on a list of sources. The port keeps it; a change would be its own issue. audio_buffer_insufficientreturns false for a start point at or pastAUDIO_OUTPUT_FRAMES(>=), whilediscard_audiostops only on==.- Ties keep the first source in the list (the most recently created audio source, since sources are added at the head).
Existing tests
- No test covers these decisions. The new cases go into
test_audio_buffering_subsample, which compilesobs-audio.c.hand the extracted cores into itself. test_audio_clock_drift,test_audio_sync_offset_change,test_audio_capture_mix_raceandtest_async_delay_audiorun the real mixer throughOBS::libobsand are the Tier 2 for this slice.
New characterization cases:
- The comparison: pending, without a timestamp, equal to the minimum (not taken), earlier (taken).
- Insufficient: a render source, a pending source, no timestamp (all false, not marked); a start on
min_tsand onmin_ts - 1with exactly a tick and one sample less; a start point inside the tick; a start point at and past frame 1024 (false); the pending flag set only when short. - The choice: fixed and not at the maximum, fixed at the maximum, not fixed with
min_tsbefore, at and after the tick start. - Through the C wrappers, on a
struct obs_core_datawith two and three sources in the list: the minimum, the name, and the case above where the source with the minimum is short (it is marked pending, the minimum does not change, the name becomes NULL).
Plan
One PR, in this order:
- Extraction commit, behaviour-neutral, no Rust: the three decisions into
libobs/obs-audio-min-ts.c.h, declared inlibobs/obs-audio-min-ts.hwithoutEXPORT. The walk and the passes inobs-audio.c.hcall them. The unchanged C tests pass. - Characterization commit: the cases above, against the C reference and the hybrid libobs.
- RED: the safe core in
obs-corewithtodo!(), Tier 1 tests inobs-tests-core(the cmocka cases 1:1, plus properties), failing. - GREEN: the core, a thin hidden
#[no_mangle]shim, the include moved to alibobs.ported-audio-min-tsgroup inlibobs/build/source-sets.json, Tier 3 proptest against the C oracle, andport_comparisonnumbers for the per-source check. - Tier 2: the real-mixer tests above with Rust off and on. Tier 4: n/a.
The per-source check runs on every audio tick for every audio source. The real-host before/after (CT104, NDI/ALSA audio) is measured once for #2403 and this slice together, at the production rebuild after both merge.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
vpacher commentedon Oct 25, 2026
Claiming: #2405
Plan as in the description: one PR (extraction, characterization, RED, GREEN with Tier 3 and
port_comparison, Tier 2). The work is done locally on top of #2404; the PR follows after the checks on the rebased head.vpacher commentedon Oct 25, 2026
Progress: #2406 is open with the whole plan (extraction, characterization, RED, GREEN, Tier 3). Tier 1/3 68/68 for
obs_core::audio*on Linux, Tier 2 5/5 on the hybrid and the C reference, mutation check 13/14 (the survivor is equivalent). Thecalc_min_tssecond-pass behaviour is confirmed on the C and pinned bycalc_min_ts_through_the_list.obs-core: Port the minimum audio timestamp decisions (obs-rust#2405) (o…
test: Keep the audio_min_ts parity rate where util_mul_div64 fits on …
obs-core: Port the per-source decisions of the audio render step (obs…