Skip to content

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

Closed

Description

@vpacher

Unit

The per-source decisions of the "build audio render order" and "render audio data" steps of the audio tick in libobs/obs-audio.c.h, into rust/obs-core as obs_core::audio_render. Slice 4 of obs-audio.c, after #1903 (audio_mix), #2403 (audio_discard) and #2405 (audio_min_ts). It moves first to libobs/obs-audio-render.c.h.

  • push_audio_tree2, the choice for one visited source: skip it (removed), add it to the render order (not there yet), tag it as duplicated and add it to root_nodes (already there, an individual audio source, not tagged yet), or nothing. With is_individual_audio_source: an input with OBS_SOURCE_AUDIO and without OBS_SOURCE_COMPOSITE.
  • should_silence_monitored_source: whether a monitored source is silenced because an unmuted Audio Output Capture source records the monitoring device (the deduplication source is set, active, not muted, its volume not 0 within 0.0001, and the source is monitored and not the capture source itself).
  • clear_audio_output_buf, the choice of mixes: the mixes that both the capture source and the source use, within MAX_AUDIO_MIXES.
  • The "gone backwards" choice in the render loop: when buffering is at the maximum and a source's timestamp is set and before the tick start, a source with audio_render is marked pending, another source has its audio dropped (ignore_audio) and is rendered again after the lock is released. Otherwise nothing.

These stay C in obs-audio.c.h: audio_callback and its order of steps, the walk over the views and their channels (including the check for a view used by two mixes), obs_source_enum_active_tree, the walk over first_audio_source, all locks, obs_source_get_ref/obs_source_release, da_find/da_push_back on render_order and root_nodes, the memset of the output buffers, obs_source_audio_render, the task queue, and the logging. The C finds a source in the render order and passes the result; Rust does not hold source pointers.

Phase and position

Phase 6 (#444), the fourth slice of obs-audio.c. Crate obs-core, next to audio_mix, audio_discard and audio_min_ts. Size: S. After it, obs-audio.c.h keeps only the orchestration: the walks, the locks and refs, the task queue and audio_callback.

Seam

Plain values: the source type and output flags, whether the source is removed, whether it is in the render order already, its audio_is_duplicated flag, the monitoring fields of the deduplication source and of the source (set, active, muted, volume, monitoring_enabled, same source), the two mixer masks, and for the backwards check audio_render (as a bool), audio_ts, the tick start and whether buffering is at the maximum. Rust returns the choice; the C acts on it. No struct of obs-internal.h goes to Rust, and no public header changes.

#2450 (open, @rdoupe) changes the monitoring setter in obs-source.c.h and obs-internal.h. It does not touch obs-audio.c.h; if it changes a field that this slice reads, I rebase on it.

Characterized behaviour to keep (to confirm in the characterization commit)

  • Only individual audio sources are tagged as duplicated. A scene or a transition that is in the tree twice is not tagged and is mixed through each parent.
  • push_audio_tree (top-level sources and the audio source list) does not check obs_source_removed; its callers do for the view channels, the audio source list does it before the call.
  • The silence check uses the capture source's own volume (fader), not the mixer's, and treats a volume within 0.0001 of 0 as muted.
  • The backwards check uses < on the tick start and skips a source with audio_ts == 0.

Existing tests

  • No test covers these decisions. The new cases go into test_audio_buffering_subsample, which compiles obs-audio.c.h and the extracted cores into itself.
  • test_audio_clock_drift, test_audio_sync_offset_change, test_audio_capture_mix_race, test_async_delay_audio, test_group_hide_transition_audio and test_transition_removed_child_audio run the real mixer through OBS::libobs and are the Tier 2 for this slice.

New characterization cases:

  • The tree choice: removed (skip), new (add), present and individual and not tagged (tag + root), present and tagged (nothing), present and not individual: a scene, a filter-like composite, an input without audio (nothing).
  • The silence check: no capture source, inactive, muted, volume 0 and 0.00005 (not silenced), volume 0.001 (silenced), the source not monitored, the source is the capture source.
  • The mix mask: no common mix, one, all six, bits above MAX_AUDIO_MIXES ignored.
  • The backwards choice: not at the maximum, audio_ts 0, equal to the tick start, before it with and without audio_render.

Plan

One PR, in this order:

  1. Extraction commit, behaviour-neutral, no Rust: the four decisions into libobs/obs-audio-render.c.h, declared in libobs/obs-audio-render.h without EXPORT. obs-audio.c.h calls them. The unchanged C tests pass.
  2. Characterization commit: the cases above, against the C reference and the hybrid libobs.
  3. RED: the safe core in obs-core with todo!(), Tier 1 tests in obs-tests-core (the cmocka cases 1:1, plus properties), failing.
  4. GREEN: the core, a thin hidden #[no_mangle] shim, the include moved to a libobs.ported-audio-render group in libobs/build/source-sets.json, Tier 3 proptest against the C oracle, and port_comparison numbers for the per-source choices.
  5. Tier 2: the real-mixer tests above with Rust off and on. Tier 4: n/a.

The choices run on every audio tick for every source in the tree. The real-host before/after (CT104, NDI/ALSA audio) goes with the next production rebuild, together with #2403 and #2405.

Activity

  1. vpacher commented on Oct 26, 2026

    @vpacher
    MemberAuthor

    Claiming: #2452

    Plan as in the description: one PR (extraction, characterization, RED, GREEN with Tier 3 and port_comparison, Tier 2). Extraction, characterization and RED are done locally (CT104: the audio tests 32/32 after the extraction, test_audio_buffering_subsample 41/41 with the new cases on the C); GREEN is in progress.

  2. added
    ready
    on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ready

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions