Skip to content

perf(audio-mix): add only into the active mixes (#3189) - #3227

Merged
vpacher merged 3 commits into
masterfrom
perf/3189-audio-mix-active-mixes
Oct 31, 2026
Merged

vpacher merged 3 commits into
masterfrom
perf/3189-audio-mix-active-mixes

Conversation

@vpacher

@vpacher vpacher commented Oct 31, 2026

Copy link
Copy Markdown
Member

Fixes #3189

What

obs_audio_mix_add() added every root source into all 6 mixes, though audio_callback() gets the mask of the mixes some output reads (audio-io sets a bit for each mix with inputs). Nothing reads a mix outside the mask: clamp_audio_output() skips a mix without inputs, and do_audio_output() has no input to hand it to.

  • New hidden obs_audio_mix_add_mixers(…, uint32_t mixers) (C in obs-audio-mix.c.h, Rust shim on the safe core's new mix_active()): adds into the mixes whose bit is set and leaves the others as they are.
  • obs_audio_mix_add() keeps its signature (test_audio_buffering_subsample calls it) and is now the all-mixes case (ALL_MIXERS).
  • audio_callback() in obs-audio.c.h mixes through a new static mix_audio_mixers() that passes its mask on. mix_audio() stays the all-mixes form: test_audio_buffering_subsample includes obs-audio.c.h and calls it.

Output. A mix outside the mask keeps the zeros audio-io cleared it to.

  • For a normal source this is the same bytes as before: process_audio_source_tick() already zeroes the source's buffer of every mix outside the mask, so the old add was + 0.0f.
  • A source with its own audio_render (a scene, a transition) does not clear those buffers, so they hold what the last tick that mixed them wrote. Before, that stale audio went into a mix nobody reads. The one visible difference: an output that connects to a mix between audio-io taking the mask and handing out the mixes gets one tick of silence instead of one tick of stale audio.

Commits

  1. RED 61d5c94: the C function (the spec, and the oracle through one more rename), the declaration, the export lists, ALL_MIXERS and mix_active() as a todo!() stub, the shim, and the tests:

    • Tier 1: mix_active() over every mask of the 6 mixes against every mix, ALL_MIXERS is the six mixes, a mix past 32 bits is never active;
    • Tier 3: mix_mixers_every_mask compares the shim with the C for all 64 masks, alone and with every bit above them set, on a whole tick and from frame 300, stereo and 8 channels, and checks that a mix outside the mask keeps its values.

    The 3 Tier 1 tests fail on the stub; the Tier 3 test reaches it through the extern "C" shim and aborts the run.

  2. GREEN 509723b: mix_active(), obs_audio_mix_add() as the all-mixes case, mix_audio_mixers() in audio_callback(); the rust/README.md row. 50/50 audio_mix tests.

  3. Bench 1c0d4e3: audio_mix/add_sources/<4|16|32>/<6_mixes|1_mix>, one tick of that many sources (each its own stereo buffer) through obs_audio_mix_add_mixers() on both sides, checked bit for bit once, then timed.

Numbers

rust/tools/benchmarks/record.py --cpu 31 --repeats 5 --category audio_mix, Ryzen 9 5950X (Linux x86_64), two runs. 6_mixes is what every tick did before this PR; 1_mix is one recording or stream track.

Sources 6 mixes, Rust 1 mix, Rust Rust gain 6 mixes, C 1 mix, C
4 4.46 µs 0.68 / 0.66 µs 6.6–6.7x 13.5 µs 2.2 / 2.3 µs
16 19.5 / 19.2 µs 2.71 / 2.72 µs 7.0–7.2x 54.5 µs 8.3 / 8.4 µs
32 39.4 µs 5.62 / 5.64 µs 7.0x 109.9 / 109.3 µs 16.9 µs

Rust/C stays at 0.29–0.36 in every case. The other audio_mix rows do not move.

Tests

  • OBS_PARITY_CASES=reduced soldr cargo test -p obs-data --test obs-tests-core -- audio_mix: 50/50.
  • Local gate, stamped head 1c0d4e3: lint, rust-test, cross and tier2-linux passed (7 min 11 s).
  • Test cost (macOS, debug, 25 runs, /usr/bin/time -l): mix_mixers_every_mask longest 0.81 s, peak RSS 13 MB; the whole audio_mix_parity module 0.78 s reduced, 1.49 s full cases, peak RSS 21 MB; the three new Tier 1 tests only test bits. No test starts its own threads.
  • Real app: not run. The mixes an output reads get the same bytes (Tier 3 above); test_audio_buffering_subsample and the real-mixer Tier 2 tests (test_audio_clock_drift, test_audio_capture_mix_race, …) run the changed audio_callback() through libobs.

Checklist

  • Base is master
  • I claimed the issue
  • RED, then GREEN commits
  • User-visible change: none in the output an output reads (see What)
  • (Optional) Local gate passed and the pushed head is stamped
  • Warning or flag changes: not applicable
  • Intentional differences from C: none; the C changes the same way

🤖 Generated with Claude Code

vpacher and others added 3 commits October 31, 2026 18:53
obs_audio_mix_add() adds every root source into all 6 mixes, though
audio_callback() gets the mask of the mixes some output reads (audio-io
sets a bit for each mix with inputs). The mixes outside the mask are
never read: clamp_audio_output() skips a mix without inputs, and
do_audio_output() has no input to hand it to.

obs_audio_mix_add_mixers() takes that mask. obs_audio_mix_add() keeps
its signature, which test_audio_buffering_subsample calls, and becomes
the all-mixes case. The C in obs-audio-mix.c.h is the spec and the
oracle (one more rename in oracle/audio_mix.c); the hidden symbol is
in rust-exports.map, rust-hidden.txt and rust-unexports-macos.txt.

The safe core gets ALL_MIXERS and mix_active() (todo!() here), the
shim obs_audio_mix_add_mixers() on top of it.

Tests:
- Tier 1 (tests/obs_core/audio_mix.rs): mix_active() over every mask
  of the 6 mixes against every mix, ALL_MIXERS is the six mixes, and a
  mix past 32 bits is never active.
- Tier 3 (audio_mix_parity.rs): compare_mix() takes an optional mask;
  mix_mixers_every_mask compares the shim with the C for all 64 masks,
  alone and with every bit above them set, on a whole tick and from
  frame 300, stereo and 8 channels, and checks that a mix outside the
  mask keeps its values.

OBS_PARITY_CASES=reduced soldr cargo test -p obs-data --test
obs-tests-core -- audio_mix: the 3 Tier 1 tests fail on todo!();
mix_mixers_every_mask reaches it through the extern "C" shim and
aborts the run (a panic that cannot unwind).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
mix_active() is the bit test, 0 for a mix past the mask's 32 bits.
obs_audio_mix_add() in the shim is obs_audio_mix_add_mixers() with
ALL_MIXERS, so test_audio_buffering_subsample and every other caller
see what they saw before.

audio_callback() in obs-audio.c.h mixes through the new static
mix_audio_mixers(), which passes the mask it gets to
obs_audio_mix_add_mixers(). mix_audio() stays the all-mixes form:
test_audio_buffering_subsample includes obs-audio.c.h and calls it.

A mix outside the mask now keeps the zeros audio-io cleared it to.
For a normal source that is the same bytes as before:
process_audio_source_tick() zeroes the source's buffer of every mix
outside the mask, so the old add was + 0.0f. A source with its own
audio_render (a scene, a transition) leaves those buffers as the last
tick that mixed them wrote them, and the old add put that stale audio
into a mix nobody reads; an output that connects to that mix during
the tick now gets one tick of silence instead.

rust/README.md: the audio mix row names the new function.

OBS_PARITY_CASES=reduced soldr cargo test -p obs-data --test
obs-tests-core -- audio_mix: 50 passed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…3189)

audio_mix/add_sources/<sources>/<6_mixes|1_mix>: one tick of that many
root sources, each its own stereo whole-tick buffer, through
obs_audio_mix_add_mixers() on both sides, checked bit for bit once
and then timed. 6_mixes is what obs_audio_mix_add() did for every
source before; 1_mix is one recording or stream track.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=79807bb4dd1795687641df5f7e800a9fafc50c09 secs=431 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run,macos-native:n/a,windows-native:n/a
Ci-Attestation: {"at":1793469720,"gate":"rust/all/fmt","host":"linux-x86_64","key":"51fb5ff39635282aaab440f392fb6f6e24f8ffb32e4a50fdc23618602fa1fff3","lane":"lint","parents":["509723b7e268153ceb103b83612098c2894e3e97"],"secs":91,"stamp":"2ae25cd9e24655373a3a9d36e8686af7","tree":"79807bb4dd1795687641df5f7e800a9fafc50c09","v":1,"via":"run"}
Ci-Attestation: {"at":1793469720,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"51fb5ff39635282aaab440f392fb6f6e24f8ffb32e4a50fdc23618602fa1fff3","lane":"lint","parents":["509723b7e268153ceb103b83612098c2894e3e97"],"secs":91,"stamp":"6c628bd464008446e4ad9cdaa33bc0bd","tree":"79807bb4dd1795687641df5f7e800a9fafc50c09","v":1,"via":"run"}
Ci-Attestation: {"at":1793469720,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"a55aaf5b49b6a59a672129082b2295b478c46063fbedac2ec8b07395a4405ab7","lane":"rust-test","parents":["509723b7e268153ceb103b83612098c2894e3e97"],"secs":174,"stamp":"7f02de83198e543b66d3530423700973","tree":"79807bb4dd1795687641df5f7e800a9fafc50c09","v":1,"via":"run"}
Ci-Attestation: {"at":1793469720,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"acef0931c5427c10f2ac96452965f58309b140b2cf37d8dc079dd297212271b6","lane":"cross","parents":["509723b7e268153ceb103b83612098c2894e3e97"],"secs":165,"stamp":"3ad0eac374e2bd8043e947170156ec93","tree":"79807bb4dd1795687641df5f7e800a9fafc50c09","v":1,"via":"run"}
Ci-Attestation: {"at":1793469720,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"acef0931c5427c10f2ac96452965f58309b140b2cf37d8dc079dd297212271b6","lane":"cross","parents":["509723b7e268153ceb103b83612098c2894e3e97"],"secs":165,"stamp":"8fbb875e6f9b904928675175273edfc9","tree":"79807bb4dd1795687641df5f7e800a9fafc50c09","v":1,"via":"run"}
Ci-Attestation: {"at":1793469720,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"acef0931c5427c10f2ac96452965f58309b140b2cf37d8dc079dd297212271b6","lane":"cross","parents":["509723b7e268153ceb103b83612098c2894e3e97"],"secs":165,"stamp":"7320ac573a93c1dbf1ad3bad269e2032","tree":"79807bb4dd1795687641df5f7e800a9fafc50c09","v":1,"via":"run"}
Ci-Attestation: {"at":1793469720,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"acef0931c5427c10f2ac96452965f58309b140b2cf37d8dc079dd297212271b6","lane":"cross","parents":["509723b7e268153ceb103b83612098c2894e3e97"],"secs":165,"stamp":"f13f2d26b89e718e2deeb9d31b8546b8","tree":"79807bb4dd1795687641df5f7e800a9fafc50c09","v":1,"via":"run"}
Ci-Attestation: {"at":1793469720,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"44f2b20d1240545e0249c4dca1b99a6d85c14f53fbbafa88d43306de1204c667","lane":"tier2-linux","parents":["509723b7e268153ceb103b83612098c2894e3e97"],"secs":246,"stamp":"0efa4979f00b09f31569177b15c34444","tree":"79807bb4dd1795687641df5f7e800a9fafc50c09","v":1,"via":"run"}

@zackees zackees left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coordinator review: No blocking findings.

  • libobs/obs-audio-mix.h is an internal header (not in public_headers in libobs/CMakeLists.txt, declarations carry no EXPORT), so adding obs_audio_mix_add_mixers is not a public-header edit. The symbol is added to all three hidden lists (rust-exports.map, rust-hidden.txt, rust-unexports-macos.txt).
  • C (obs-audio-mix.c.h:54) and Rust (ffi/audio_mix.rs, mix_active) skip the same mixes. obs_audio_mix_add stays the ALL_MIXERS case, so test_audio_buffering_subsample is unchanged. Tier 3 parity covers every mask, and the Test cost line is present.
  • The one behaviour change is that stale audio from scenes or transitions is no longer added into unread mixes. It is documented in the body and reaches no output.

@vpacher
vpacher added this pull request to the merge queue Oct 31, 2026
Merged via the queue into master with commit c4e25cb Oct 31, 2026
37 checks passed
@vpacher
vpacher deleted the perf/3189-audio-mix-active-mixes branch October 31, 2026 18:43
zackees added a commit that referenced this pull request Oct 31, 2026
…enerate the linker lists (#3233) [GREEN]

rust-hidden.txt becomes libobs/cmake/rust-hidden.d/<crate>-<ffi module>.txt
(132 fragments) plus rust-hidden-base.txt for Rust runtime patterns, C glue
and the macOS-only compiler-rt helpers. libobs/cmake/rust-hidden.cmake
generates rust-exports.map and rust-unexports-macos.txt into the build tree
at configure time (also runnable with cmake -P); rust/obs-build writes the
same lists. The committed .map and macOS list are gone.
Rebased onto master after #3165 and #3227: their eight new hidden shims
moved into the per-module fragments (obs-graphics-effect_param_types.txt,
obs-core-audio_mix.txt), so the generated sets still equal master's old
lists exactly.

ci_scope: a rust-hidden.d fragment edit is Linux only; the mirrored-lists
rule (#2288) and its test are removed. export_list.rs reads the fragments
and checks each names only its own module's shims.

Refs #3233, #3232
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 31, 2026
…ists (obs-rust#3233) (obs-rust#3248)

* test(ci): pin per-module hidden-symbol fragments and Linux-only scope (obs-rust#3233) [RED]

Fails: the three shared lists still exist, rust-hidden.d/ and the
generator are missing, and a fragment edit selects macOS and Windows.

Refs obs-rust#3233, obs-rust#3232

* build(libobs): split hidden-symbol lists into per-module fragments, generate the linker lists (obs-rust#3233) [GREEN]

rust-hidden.txt becomes libobs/cmake/rust-hidden.d/<crate>-<ffi module>.txt
(132 fragments) plus rust-hidden-base.txt for Rust runtime patterns, C glue
and the macOS-only compiler-rt helpers. libobs/cmake/rust-hidden.cmake
generates rust-exports.map and rust-unexports-macos.txt into the build tree
at configure time (also runnable with cmake -P); rust/obs-build writes the
same lists. The committed .map and macOS list are gone.
Rebased onto master after obs-rust#3165 and obs-rust#3227: their eight new hidden shims
moved into the per-module fragments (obs-graphics-effect_param_types.txt,
obs-core-audio_mix.txt), so the generated sets still equal master's old
lists exactly.

ci_scope: a rust-hidden.d fragment edit is Linux only; the mirrored-lists
rule (obs-rust#2288) and its test are removed. export_list.rs reads the fragments
and checks each names only its own module's shims.

Refs obs-rust#3233, obs-rust#3232

* style: gersemi format rust-hidden.cmake (obs-rust#3233)
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.

perf: obs-audio-mix: add only into the active mixes

2 participants