Skip to content

obs-core: Port the per-source decisions of the audio render step (#2452) - #2456

Merged
zackees merged 4 commits into
masterfrom
port/audio-render
Oct 26, 2026
Merged

zackees merged 4 commits into
masterfrom
port/audio-render

Conversation

@vpacher

@vpacher vpacher commented Oct 26, 2026

Copy link
Copy Markdown
Member

Fixes #2452

Slice 4 of obs-audio.c, after #1903, #2403 (#2404) and #2405 (#2406): the per-source decisions of the "build audio render order" and "render audio data" steps of the audio tick move to libobs/obs-audio-render.c.h and are ported to obs_core::audio_render.

What changed

  • libobs/obs-audio-render.{h,c.h}, on plain values:
    • obs_audio_render_tree(): push_audio_tree2's choice for one visited source (skip a removed source, add a new one, tag an individual audio source that is already in the render order so it is mixed as a root node, or nothing);
    • obs_audio_render_silence(): should_silence_monitored_source, on the deduplication source's fields (struct obs_audio_monitor_dedup: set, active, muted, volume, mixers), monitoring_enabled and whether the source is the deduplication source;
    • obs_audio_render_clear_mixes(): the mixes clear_audio_output_buf clears;
    • obs_audio_render_backwards(): the "gone backwards" choice in the render loop (mark pending, drop and render again, or nothing).
  • The source type and the two output flags are copied into obs-audio-render.h (checked by _Static_assert in obs-audio.c.h), so the core and the C oracle compile without obs.h. Own PCH, as audio_min_ts.
  • obs-audio.c.h keeps the walks over the views, the tree and the audio sources, the locks and refs, render_order and root_nodes, the memset of the output buffers, the rendering, the task queue and the logging. After this slice it holds only that orchestration.
  • rust/obs-core/src/audio_render.rs (safe core) and src/ffi/audio_render.rs (shim). Own unity group libobs.ported-audio-render; the shims are hidden; ci/test_ported_sources.py; rust/README.md.

Kept, characterized, not endorsed

  • Only an individual audio source (an input with audio, not composite) is tagged as duplicated. A scene or a transition that is reached twice is mixed through each parent.
  • The silence check uses the capture source's own fader: a volume within 0.0001 of 0 counts as muted (NaN does not).
  • The backwards check is strict on the tick start and skips a source without a timestamp.
  • push_audio_tree (top-level sources and the audio source list) does not check obs_source_removed; its callers do.

Intentional difference (C dereferences null; libobs never gets there)

  • A null dedup silences nothing.

RED → GREEN

  1. Extraction c1a0ead86 (behaviour-neutral, no Rust): the audio tests 32/32 on Linux.
  2. Characterization 498f8ea97: 6 new cases in test_audio_buffering_subsample (41/41), 4 on plain values and 2 through the C wrappers (push_audio_tree2 on a render order; should_silence_monitored_source and clear_audio_output_buf on sources with output buffers).
  3. RED 81929a4c9: Tier 1 obs_core::audio_render, the 4 plain-value cases 1:1 plus edge cases and properties: 0 of 11 pass (todo!()).
  4. GREEN 25e7b2951: 11 of 11, and Tier 3: the C oracle (the file unmodified, functions renamed) against the shims, 10 of 10. The layout of both enums and the struct and the copied constants; the tree choice exhaustively over removed × present × duplicated × 7 types × every subset of 6 flags; the silence check over every combination of 5 flags × 13 edge volumes (±0, ±1e-4, ±5e-5, 1e-3, 1, the smallest subnormal, NaN, ±∞); the mixes and the backwards edges; 50 000 random cases per function.

Mutation check (done once, not committed): all 13 mutants fail Tier 1 or Tier 3 (removed not first; present inverted; duplicated, composite flag, type, active, the deduplication source and the fader ignored; < instead of <= in close_float; the mix mask dropped; > instead of >= and audio_ts == 0 ignored in the backwards check; pending and drop swapped).

port_comparison (M1 Max): audio_render/tree_duplicate 1.64 ns (C 1.65 ns), audio_render/silence_monitored 1.30 ns (C 1.30 ns).

Tier 2 (Linux x86_64, Debian 13)

Lint lane (ci/local_gate.py --lane lint) on the same host passes: clang-format, gersemi, ruff, the 225 ci/test_*.py self-tests, the ratchets, rustfmt, clippy -D warnings for the workspace and every feature set, and the Dylints.

test_audio_buffering_subsample, test_async_delay_audio, test_audio_capture_mix_race, test_audio_clock_drift, test_audio_sync_offset_change, test_group_hide_transition_audio, test_transition_removed_child_audio and test_preview_audio_sources pass on the hybrid libobs and on libobs-c-reference (8/8 each; the loaded libobs checked with LD_DEBUG=libs). Exported symbols: 1766 on both; the four shims are local.

The real-host before/after (CT104, NDI/ALSA audio) goes with the next production rebuild, together with #2403 and #2405.

Checklist

  • Base is master
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits
  • User-visible change: not applicable (no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes: not applicable
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

vpacher and others added 4 commits October 26, 2026 07:49
…-audio-render.c

Behaviour-neutral extraction for the port to obs-core (slice 4 of
obs-audio.c, after #1903, #2403 and #2405). Four decisions of
audio_callback's render-order and render steps move to
libobs/obs-audio-render.c.h, on plain values, declared in
obs-audio-render.h without EXPORT:

- obs_audio_render_tree: push_audio_tree2's choice for one visited
  source (skip a removed source, add a new one, tag an individual audio
  source that is already in the render order, or nothing).
- obs_audio_render_silence: should_silence_monitored_source.
- obs_audio_render_clear_mixes: the mixes clear_audio_output_buf clears.
- obs_audio_render_backwards: the "gone backwards" choice in the render
  loop (mark pending, drop and render again, or nothing).

obs-audio.c keeps the walks, the locks and refs, render_order and
root_nodes, the memset, the rendering and the logging, and passes the
fields in. test_audio_buffering_subsample compiles the new file in.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Cases for obs-audio-render.c before its port to obs-core, in
test_audio_buffering_subsample:

- tree_choice: a removed source is skipped, a new one added, an
  individual audio source that is present and not tagged is tagged; a
  scene, a transition, a composite input, an input without audio and a
  filter are never tagged (they are mixed through each parent).
- tree_wrapper_tags_once: push_audio_tree2 on a render order tags a
  repeated microphone once and makes it a root node, leaves a repeated
  scene alone, and skips a removed source that is in the render order.
- silence_check and silence_wrappers_use_the_source_fields: an active,
  unmuted Audio Output Capture source silences monitored sources but not
  itself; a fader within 0.0001 of 0 counts as muted; only the mixes
  both sources use are cleared, all frames of them.
- clear_mixes_choice: bits at and above MAX_AUDIO_MIXES are not mixes.
- backwards_choice: only at the maximum buffering, with a timestamp and
  strictly before the tick start; a render source is marked pending,
  another source is dropped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The safe core of obs-audio-render.c in obs_core::audio_render: tree,
silence, clear_mixes and backwards, with todo!() bodies. Tier 1 in
obs-tests-core: the four cmocka cases of obs-audio-render.c one to one
(tree_choice, silence_check, clear_mixes_choice, backwards_choice), edge
cases (a type outside the enum, the fader at the precision and NaN, the
backwards check at both ends of u64) and properties for each function.

RED: the 11 audio_render tests fail on todo!().

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GREEN for obs_core::audio_render: the safe core (tree, silence,
clear_mixes, backwards), a thin hidden #[no_mangle] shim for the four
functions of obs-audio-render.h, and the include moved to the
libobs.ported-audio-render group, so the hybrid libobs drops the C. The
deduplication source's fields cross as struct obs_audio_monitor_dedup
(#[repr(C)] mirror, layout checked against the C).

Tier 1: 11/11. Tier 3 (obs_core::audio_render_parity) against the
unmodified C in rust/obs-c-oracle/oracle/audio_render.c: the enum and
struct layout and the copied constants; the tree choice exhaustively
over removed x present x duplicated x 7 types x every subset of 6 flags;
the silence check over every combination of 5 flags x 13 edge volumes
(+-0, +-1e-4, +-5e-5, 1e-3, 1, the smallest subnormal, NaN, +-inf); the
mixes and the backwards edges; 50 000 random cases per function. 10/10.

port_comparison (M1 Max): tree_duplicate 1.64 ns (C 1.65 ns),
silence_monitored 1.30 ns (C 1.30 ns).

Intentional difference: a null dedup silences nothing (C: dereferences
it; libobs always passes one).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@vpacher
vpacher requested a review from zackees as a code owner October 26, 2026 07:32
@zackees

zackees commented Oct 26, 2026

Copy link
Copy Markdown
Member

Coordinator review: a pure-decision extraction like #2448. The new characterization cases are added to test_audio_buffering_subsample.c with no existing assertion changed, which follows the one-binary-per-category rule. The C-vs-Rust parity test, the bench and the export maps are in. Queuing.

@zackees
zackees added this pull request to the merge queue Oct 26, 2026
Merged via the queue into master with commit 94aabdd Oct 26, 2026
36 checks passed
@zackees
zackees deleted the port/audio-render branch October 26, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

rust: Port the per-source decisions of the audio render step in obs-audio.c to obs-core (#1903 slice 4)

2 participants