Repository navigation
Description
Unit
The steps of the audio tick that drop audio from a source's input buffer in libobs/obs-audio.c.h, into rust/obs-core as obs_core::audio_discard. Slice 2 of obs-audio.c, after #1903 (slice 1, obs_core::audio_mix, #1905 / #1909). It moves first to libobs/obs-audio-discard.c.h.
ignore_audio: a source that lags behind the tick start at maximum buffering. Drop the lagging samples (rounded up, cut at what is buffered) and moveaudio_tson; adjust a 1 ns rounding error; or, when that is not enough or there is no timestamp, restart the source's audio (audio_pending,audio_ts = 0,timing_set = false). The result tells the caller to render the source again.discard_if_stopped: the "pending stop" check. When the buffered size does not change for two ticks, clear the buffer and reset the timestamp.discard_audio: after the mix, drop the frames of this tick from the input buffer and setaudio_tsto the tick end. It covers the early returns (render sources, a source ahead of the window, a source behind it, a start point equal toAUDIO_OUTPUT_FRAMES) and the not-enough-data path (audio_ts = ts->end).
These stay C in obs-audio.c.h: audio_callback, the source tree walk, the locks, the blog lines (the core returns the values they print), the DEBUG_AUDIO asserts, the min-timestamp search (find_min_ts, audio_buffer_insufficient, mark_invalid_sources, calc_min_ts: slice 3) and the monitoring checks.
Phase and position
Phase 6 (#444), the second slice of obs-audio.c. Crate obs-core, next to audio_mix. Same shape as slice 1: helpers declared in a header without EXPORT, hidden shims, and the C core compiled into the cmocka test for Tier 3.
Seam
The functions change seven fields of struct obs_source: audio_input_buf[] (deques), audio_ts, last_audio_input_buf_size, audio_pending, pending_stop, timing_set, and read info.audio_render. As in slice 1 (struct obs_audio_buffering), the C passes them by pointer in a small struct declared in obs-audio-discard.h:
struct obs_audio_input {
struct deque *buf; /* audio_input_buf, `channels` entries */
uint64_t *audio_ts;
size_t *last_size;
bool *pending;
bool *pending_stop;
bool *timing_set;
};The deque pops use obs-util::deque on the C-owned struct deque in place (ffi::deque), as slice 1 does for buffered_timestamps. No obs-internal.h layout goes to Rust, and no public header changes. The functions run under the source's audio_buf_mutex, which the C keeps.
Kept as in C: the sample count comes from channel 0's buffer, and every channel pops that size.
Existing tests
- No test covers these three functions.
test_audio_buffering_subsample(Flaky: real-time audio cmocka tests lose audio under machine load (test_vlc_playlist_gap, test_group_hide_transition_audio) #838, extended in libobs: Move the audio tick arithmetic into obs-audio-mix.c (#1903) #1905) compilesobs-audio.c.handobs-audio-mix.c.hinto itself; the new cases go there (no new executable). test_audio_clock_drift,test_audio_sync_offset_change,test_audio_capture_mix_raceandtest_async_delay_audiorun the real mixer throughOBS::libobs. They see the swap and are the Tier 2 for this slice.
New characterization cases:
ignore_audio: data without a timestamp (all popped, restart, no rerender); a lag of 1 ns, of one sample and of a partial sample (the round-up); a lag larger than the buffer (cut, then restart); thestart_ts - 1rounding adjustment; back in sync (rerender); no data while pending (no warning) and while not pending (warning).discard_if_stopped: empty buffer; the size changed (remembered); the same size once (pending_stopset) and twice (cleared).discard_audio: a render source;audio_tsat or after the tick end; behind the tick start, with and without the stopped check; onts->startandts->start - 1; a start point inside the tick and atAUDIO_OUTPUT_FRAMES; not enough data (audio_ts = ts->end); a full discard on 1, 2 and 8 channels.
Plan
One PR, in this order:
- Extraction commit, behaviour-neutral, no Rust: move the three functions into
libobs/obs-audio-discard.c.hwith thestruct obs_audio_inputsignatures, declared inlibobs/obs-audio-discard.hwithoutEXPORT. They return a small step struct with the values thatobs-audio.c.hlogs. The callers fill the struct and log. 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: the dropped sample count never exceeds what is buffered,audio_tsnever moves backwards except to 0, the buffer is either untouched, cut by the tick, or empty), failing. - GREEN: the core, a thin hidden
#[no_mangle]shim, the include moved to alibobs.ported-audio-discardgroup inlibobs/build/source-sets.json, Tier 3 proptest againstrust/obs-c-oracle/legacy/(the extracted C), andport_comparisonnumbers fordiscard_audio. - Tier 2: the real-mixer tests above with Rust off and on. Tier 4: n/a.
discard_audio runs on every audio tick for every audio source. Besides port_comparison, I measure it on a real OBS host (NDI/ALSA audio) before and after, and put the numbers in the PR.
Next slice
Slice 3: the min-timestamp search (find_min_ts, audio_buffer_insufficient, mark_invalid_sources, calc_min_ts). It walks the audio source list under audio_sources_mutex, so it needs its own check for a seam. Filed when this one closes.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
vpacher commentedon Oct 25, 2026
Claiming: #2403
Plan as in the description: one PR (extraction, characterization, RED, GREEN with Tier 3 and
port_comparison, Tier 2), with a short progress note here after each step that lands. First PR expected within two days.vpacher commentedon Oct 25, 2026
Progress: #2404 is open with the whole plan (extraction, characterization, RED, GREEN, Tier 3). Tier 1/3 54/54 on Linux and macOS, Tier 2 5/5 on the hybrid and the C reference, mutation check 19/19. The real-host before/after follows with the next production rebuild after the merge.
Found while characterizing: without a timestamp,
ignore_audioclears only channel 0 (it popsaudio_input_buf[0].sizefrom each channel and reads that size again per channel). The port keeps it and the PR documents it; a fix would be its own issue.obs-core: Port the audio input discard steps (obs-rust#2403) (obs-rus…
obs-core: Port the per-source decisions of the audio render step (obs…