Skip to content

obs-source: Port the transition audio render - #4095

Merged
rdoupe merged 6 commits into
masterfrom
fix/rust-port-port-the-rest-of-the-t-701
Nov 9, 2026
Merged

rdoupe merged 6 commits into
masterfrom
fix/rust-port-port-the-rest-of-the-t-701

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #4092

What and why

Ports the rest of libobs/obs-source-transition.c.h to Rust: obs_transition_audio_render() (obs.h, EXPORT) with the helpers it calls (transition_live_sources(), transition_calc_min_ts(), transition_process_audio(), mix_child()), and obs_transition_init() / obs_transition_free(), which a source's create and destroy call (declared in obs-internal.h, hidden). Every transition plugin's audio goes through the render: scene transitions, stingers, fades and the Studio Mode T-bar. After this the file has no C left.

  • test_source_transition_audio (new characterization test, its own commit, before RED) calls obs_transition_audio_render() directly, with no audio subsystem, on a test transition whose children's audio timestamp, flags and buffers it sets: the copy of slot A while idle, the mix of each valid child by mixer mask and channel, the place of a child's audio, each sample's time, the audio stop for each step and the removed child a stop can leave in slot A (libobs: Transition audio can take its timestamp from a removed child after the audio stop #2185), and obs_transition_init()'s state.
  • obs_source::transition_audio is the safe core, generic over a Transition trait that extends transition_stop's with one method per further field read or write, mutex call, child read, buffer access and libobs call, so each function makes the C's reads and calls in the C's order and under the C's lock. The rules it asks are the Rust ones the C asked (transition_render's audio plans, transition_sample_time, transition_clock::min_ts), and the stop helpers (transition_stop::calc_time, stop, handle_stop) are called in Rust.
  • The C shims are in obs-source-seam (ffi::source_transition), on the stop shims' Seam: every field, flag, mutex, child audio flag and the context data go through the transition seam; struct obs_source is never mirrored. obs_source_removed(), the audio timestamp and mix reads, obs_source_get_ref(), the graphics context and the texrender calls go through a Calls trait that extends the stop shims', so the parity test can hand in the oracle's recording stand-ins. struct obs_source_audio_mix is mirrored, with a layout test against the header.
  • Kept from the C: the mix reads only the clock copied under transition_mutex (bug: libobs: transition audio block mixed with two clocks #3499); the children's audio_pending and audio_is_duplicated are read under transition_mutex alone; slot A's copy is one TOTAL_AUDIO_SIZE copy from its audio_output_buf[0][0]; init returns on a failed mutex before it makes the texrenders; free destroys the mutexes before it enters the graphics context.
  • The file moves from libobs.core-source into its own ported group, libobs.ported-source-transition (ported-source-sets/source-transition.json), whose precompiled header is obs-internal.h with the transition headers it uses. Its _Static_asserts on the Rust rules' constants move verbatim into obs-source-transition-seam.c.h, which every build still compiles. ci/test_ported_sources.py no longer lists the file as unported C. The shims' fragments are rust-exports.d/ and rust-hidden.d/obs-source-seam-source_transition.txt; oracle/source_transition_links.c gives obs-tests-core the libobs calls the shims name, for the Windows link.

No intentional differences from C. The functions are Lain Bailey's upstream code; the port commit credits them. No port_comparison bench entry, as for the other seam ports. No upstream issue.

RED → GREEN

  • RED commit: 44271c7. obs-tests-core source::transition_audio: all 19 fail on the todo!() core. On it, --lane lint passed and --test-diff ran 7416 tests with exactly those 19 failing (6 skipped).
  • GREEN: b64ca8c.
    • Characterization (320d918): test_source_transition_audio 13/13 on the C build, hybrid libobs and libobs-c-reference, and 30 runs in a row on the C build.
    • Tier 1: 19/19 (source::transition_audio): init's calls and early returns, free's order, the argument check, the idle copy, the mix by mixer mask and channel, the pending and duplicated skips, each place, each sample's time in manual and auto mode, the audio stop for each step with the stop's slot shift under the lock and its signal after, the second read after a stop, a child being destroyed, and that a callback rewriting the clock mid-mix changes no sample's time.
    • Tier 2: the transition, slideshow, stinger, Studio Mode, group-hide, fade and scene canvas tests pass on the C build (45 tests) and, with the _rust variants, on hybrid libobs and libobs-c-reference (50 tests, 365 cases each, 0 skipped), under a private Xvfb. Export sets identical on the C, hybrid and C reference builds (1767), obs_transition_init / obs_transition_free local (t); the hybrid compiles no C for the unit. Two audio tests outside the unit (test_source_audio_settings, test_v4l2_vcam_audio) fail the same way on the plain C build in the sandbox (no sound server, no v4l2 loopback device).
    • Tier 3 (1a0be33): the oracle builds the original file renamed, its stop helpers the stop oracle's C, on the slots oracle's graph with recording stand-ins for its libobs calls, which the Rust shims are handed too. After every call both sides agree on the result and ts_out, the caller's whole mix bit for bit, the slots, flags, clock, alignment and texrenders, the held mutexes, reference and link counts, the mix callbacks' records (calls, a hash of every time and context data they got, calls with the lock held) and every call in order: the characterization test's cases, every audio stop step and place, a child in both slots or being destroyed, the argument check, init and free with each texrender missing, a callback that rewrites the clock, audio flag and context data on every call (as another thread may after the lock), and a proptest over random graphs and requests. Left out, as libobs never passes them: a sample rate of 0, more than MAX_AUDIO_CHANNELS channels and NULL mix callbacks. Mutation: 18 mutants planted in the core; the parity test catches all 18.
    • Gates, runs were on 595463b (rebased onto 7d64449): the ci/ quick checks, ./lint, --lane lint, --lane dylint and --lane cross ok; soldr cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets --locked -- -D warnings clean; soldr cargo test -p obs-c-oracle --locked --bench port_comparison ok; export sets again identical (1767); the local gate's full Tier 2 suite 816/816 against both libobs-c-reference and hybrid libobs, and its Linux Rust tests 7456/7456 (6 skipped) and 914/914. The head is not stamped: the gate's rust-test lane stops in the MinGW build of oracle/output_pause_queries.c, which this PR does not touch (the open issue on the pthread probe macro redefinition, bug: obs-c-oracle: pthread probe macro redefinition blocks Fast Gate #4069), so PR CI runs the full suite. Before the rebase (runs were on 7b80a5321): --test-diff 7424/7424 (6 skipped), and ci/windows_link_check.py linked every test binary. The seam parity tests passed 40 runs in a row in one process, and every transition test 30.
    • After the first PR CI run: the audio callback port (obs-core: Port the audio callback #4071) landed with its own obs_source_removed() link stand-in, so the merge result defined it twice (duplicate symbol in the Windows link check, Fast Gate and the Windows Rust tests). Rebased onto 43f2136 and dropped this PR's copy (2f823a4). Runs were on 2f823a4: ci/windows_link_check.py linked every test binary, --test-diff origin/master 7517/7517 (6 skipped), --lane lint ok, export sets identical (1767), and the transition Tier 2 set 50/50 on hybrid libobs and libobs-c-reference.
  • Test cost: 27 new tests (19 Tier 1, 8 Tier 3): 0.03 s and 0.20 s at reduced (0.55 s at full) in the debug build, peak RSS 23 MB and 13 MB over 20 runs, no own threads.
  • Real app (UI, protocol output or logging changes): not applicable, a port with no change in behaviour.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • 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 (N/A for docs-only; a focused CI fix may push RED and GREEN together)
  • User-visible change: its line in docs/features.md is added or updated (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 (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports) (none)

@rdoupe
rdoupe force-pushed the fix/rust-port-port-the-rest-of-the-t-701 branch from 5bd0c1a to 595463b Compare November 9, 2026 03:14
rdoupe and others added 6 commits November 8, 2026 23:09
test_source_transition_audio pins the rest of
obs-source-transition.c through the real libobs before it is ported:
obs_transition_audio_render() called directly, with no audio
subsystem, on a test transition whose children's audio timestamp,
pending and duplicated flags and buffers the test sets, with mix
callbacks that count their calls and record each sample's time.

It pins the copy of slot A's whole block while idle; no timestamp (no
child, a pending, removed or zero-timestamp child) writing nothing;
the mix of each valid child with its callback by mixer mask and
channel on top of the mix; a pending or duplicated child skipped; the
place of a child's audio (a partial block, past the block, timestamp
0); each sample's time in manual and auto mode; the audio stop for
each step, with the slot shift and the stop signal; a removed child
the stop leaves in slot A giving no timestamp (#2185); and the state
obs_transition_init() leaves.

It passes 13/13 on the C build, the hybrid build and the C reference,
and 30 runs in a row on the C build. Transitions need core video, so
it is Linux only and skips without a display, like the other
transition characterization tests.

Refs #4092.
RED for #4092. obs_source::transition_audio has its API and docs, with
todo!() bodies: init(), free() and audio_render()
(obs_transition_init(), obs_transition_free() and
obs_transition_audio_render() with the helpers it calls), generic over
a Transition trait that extends transition_stop's with one method per
further field read or write, mutex call, child read, buffer access and
libobs call.

tests/source/transition_audio.rs runs them on a fake transition that
records every read and write (with the lock state), mutex, lock,
graphics and libobs call and child read in order, and the time each
mix callback call gets. It pins init's calls and early returns, free's
order, the argument check, the copy of slot A while idle, the mix of
each child by mixer mask and channel, the skip of a pending or
duplicated child, the place of a child's audio, each sample's time in
manual and auto mode, the audio stop for each step with the stop's
slot shift under the lock and its signal after, the second read of the
children after a stop (#2185), and that the mix reads only the clock
copied under the lock (#3499). All 19 fail on the stubs
(obs-tests-core, source::transition_audio).

Refs #4092.
obs_transition_audio_render() of obs-source-transition.c is Rust,
EXPORT through obs.h (rust-exports.d), and so are obs_transition_init()
and obs_transition_free(), which a source's create and destroy call,
hidden (rust-hidden.d). With them go the helpers the render calls:
transition_live_sources(), transition_calc_min_ts(),
transition_process_audio() and mix_child(). The file has no C left. The
export sets of the C, hybrid and C reference builds are unchanged
(1767), with init and free local.

obs_source::transition_audio makes the C's reads and calls in the C's
order: under transition_mutex the live children and their earliest
timestamp, the clock at it, the audio stop (transition_stop's calc_time,
stop and handle_stop, called in Rust), the second read of the children
after a stop (#2185) and the state copy; after the lock the mix of each
child with its callback, by mixer mask and channel, from the copied
clock only (#3499), or the copy of slot A's whole block, then the
releases and the stop's callback and signals. Init returns on a failed
mutex before it makes the texrenders; free destroys the mutexes before
it enters the graphics context.

The shims never mirror struct obs_source: every field, flag, mutex,
child audio flag and the context data go through the transition seam,
on the stop shims' Seam. The libobs calls go through Calls, which
extends the stop shims': obs_source_removed(),
obs_source_get_audio_timestamp(), obs_source_get_audio_mix(),
obs_source_get_ref(), the graphics context and the texrender calls.
struct obs_source_audio_mix is mirrored as obs-source.h lays it out.

The file moves from libobs.core-source into its own ported group,
libobs.ported-source-transition, whose precompiled header is
obs-internal.h with the transition headers it uses. Its _Static_asserts
on the Rust rules' constants move verbatim into
obs-source-transition-seam.c, which every build still compiles.

oracle/source_transition_links.c gives obs-tests-core the libobs calls
the shims name that no oracle defines (obs_source_removed(), the
audio timestamp and mix reads, gs_enter_context() and
gs_leave_context()), for the Windows link.

Tier 1: 19/19. Tier 2: the transition, slideshow, stinger, Studio Mode,
group-hide, fade and scene canvas tests pass on the C build (45 tests)
and, with the _rust variants, on the hybrid and C reference builds (50
tests, 365 cases each, 0 skipped).

Refs #4092.

Co-Authored-By: Lain Bailey <[email protected]>
oracle/source_transition.c builds the rest of the original
obs-source-transition.c renamed oracle_*, on the slots oracle's graph
of test sources. Its stop helpers are the stop oracle's C, renamed
after the group's headers, so the C side is the original C throughout.
Its libobs calls go to recording stand-ins: the slots oracle's
get_ref() and release(), and here obs_source_removed(), the audio
timestamp and mix reads, the texrender create and destroy and the
graphics context; a child gets a timestamp, flags and an audio block of
its own. The type's mix callbacks record their calls, a hash of the
times and context data they got and whether the lock was held, and can
rewrite the clock, audio flag and context data on every call, as
another thread may once the render lets the lock go.

transition_audio_parity.rs runs the C and the Rust shims (handed the
same stand-ins) on the same graph. After every call they agree on the
result and ts_out, the caller's whole mix bit for bit, the slots,
flags, clock, alignment and texrenders, the held mutexes, the
reference and link counts, the callbacks' records and every call in
order: the characterization test's cases, every audio stop step and
place, a child in both slots or being destroyed, the argument check,
init and free with each texrender missing, the writes after the lock,
and a proptest over random graphs and requests. A layout test pins
struct obs_source_audio_mix and the constants the shims pass.

No intentional differences. Left out, as libobs never passes them: a
sample rate of 0, more than MAX_AUDIO_CHANNELS channels and NULL mix
callbacks, where the C divides by zero, reads past data[] or calls
NULL.

Mutation: 18 mutants planted in the core (the second read after a
stop, the copied clock, the callbacks' slots, the frame offset, the
mixer mask, the copy of A, the releases, the stop's place and step,
the duplicated check, the order of the mix read, the empty-slot
get_ref, the context data read, the pending check of the timestamps,
the copied flag, and init's and free's steps); the parity test catches
all 18.

Refs #4092.
rust/README.md gets the row of obs-source-transition.c (its core,
shims, locking, what moved to the seam file and its tiers) and names it
in the obs-source and obs-source-seam rows; naming.md lists it among
the seam crate's C files. The two crates' descriptions, lib.rs docs
and the seam crate's README table name it too. No features line: the
port changes no behaviour.

Fixes #4092.
The audio callback port (#4071) added oracle/audio_callback_links.c,
which defines obs_source_removed() for the same test binaries. With
both, obs-tests-core fails to link on MSVC and the Linux gates with a
duplicate symbol. The transition audio links keep the four calls no
other oracle defines, and name where the fifth comes from.

Refs #4092.
@rdoupe
rdoupe force-pushed the fix/rust-port-port-the-rest-of-the-t-701 branch from 595463b to 2f823a4 Compare November 9, 2026 04:28
@rdoupe
rdoupe marked this pull request as ready for review November 9, 2026 05:39
@rdoupe
rdoupe requested a review from zackees as a code owner November 9, 2026 05:39
@rdoupe
rdoupe added this pull request to the merge queue Nov 9, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 9, 2026
@rdoupe
rdoupe added this pull request to the merge queue Nov 9, 2026
Merged via the queue into master with commit f50c8a4 Nov 9, 2026
81 of 83 checks passed
@rdoupe
rdoupe deleted the fix/rust-port-port-the-rest-of-the-t-701 branch November 9, 2026 07:12
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Needs fix to Done in obs-rust Multiview Nov 9, 2026
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 transition audio render, init and free

1 participant