Skip to content

obs-source: Port the transition child slots - #3563

Merged
rdoupe merged 4 commits into
masterfrom
fix/rust-port-port-the-transition-ch-568
Nov 3, 2026
Merged

rdoupe merged 4 commits into
masterfrom
fix/rust-port-port-the-transition-ch-568

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #3562

What and why

This ports the child slots of a transition (libobs/obs-source-transition-slots.c.h, moved out of obs-source-transition.c in #3530) to rust/obs-source: obs_transition_clear(), obs_transition_enum_sources(), and the swap of obs_transition_swap_begin() (with its file-local copy_source_state()) and obs_transition_swap_end(). The clear and the swap stay EXPORT through obs.h. obs_transition_enum_sources() is declared in obs-internal.h without EXPORT (obs-source.c's tree walks call it), so it stays hidden (rust-hidden.d).

The safe core (obs_source::transition_slots) is generic over a Transition: one method per field read or write, per lock call, and per call into the rest of libobs (obs_source_get_ref(), obs_source_release(), the active-child add and remove, the recursion warning). Each function makes the C's calls in the C's order and under the C's locks. The swap uses the rules ported with the transition start and load (child_active, copy_stores, swaps).

The C shims go in obs-source-seam, next to the settings shims, for the reason that crate's README gives. They reach the fields, both mutexes and the render targets only through the transition seam, so struct obs_source is not mirrored. The libobs calls go through a small Calls trait: Libobs calls the C symbols, and the parity test passes in the oracle's recording stand-ins. The locks are taken where the C takes them. The swap's begin takes both texture locks (the old transition's, then the new one's) and then both transition locks. It releases only the transition locks, and its end releases the texture locks after the render targets move. The enum's callback runs with transition_mutex held.

The unity group moves from libobs.core-source into its own libobs.ported-source-transition-slots. Its precompiled header is obs-internal.h plus the seam, start and load headers.

There are no intentional differences. Kept as the C has it, characterized but not endorsed:

  • The enum and the swap don't check their sources.
  • When a child is going away (obs_source_get_ref() returns NULL), its slot ends up empty but keeps the old transition's active flag.
  • When an add is refused (the new transition itself, or a source that contains it), a warning is logged and the slot is stored empty and inactive.

(no upstream issue)

RED → GREEN

  • RED commit: 21f8db4 (obs-source: Add Tier 1 tests for the slots): 17 of the 18 Tier 1 tests in source::transition_slots fail on the todo!() core (the 18th checks constants). --test-diff on it: 6144 run, exactly those 17 failed, 6 skipped.
  • GREEN: e01495c.
    • Tier 1: 18/18. The cases of test_source_transition_slots.c plus the hand-over plan, on a fake source graph that counts references and links, records every call and lock in order, and panics on a field touched without the C's lock.
    • Tier 2: the transition C tests (transition|swap|stinger|fade_to_color) pass 25/26 on the C build and 30/31 on hybrid libobs and on libobs-c-reference, with 0 skipped (Xvfb). The one failure on all three builds, C included, is test_stinger_media_duration: the stinger's effect file isn't in that build tree's run directory.
    • Tier 3 (1883f4d): 4/4. Mutants of the core (no remove of the old child, no manual target, no audio stop, a refused slot left active, the old children not released) each fail it.
    • Export sets are identical on all three builds (1767). In the hybrid the four functions are Rust, with obs_transition_enum_sources local.
    • The shims name obs_source_add_active_child() and obs_source_remove_active_child(), and obs-tests-core links no libobs. The MSVC, MinGW and macOS linkers want every named symbol resolved, so oracle/source_active_child_links.c defines both for that binary; no test reaches them. Without it, the MinGW build of the test binaries failed to link.
    • ./unittest: rust-test passes (6432 tests and the 912 obs-util ones, all passed, 6 skipped, and the MinGW build), and Tier 2 passes 711/711 on hybrid libobs and on libobs-c-reference.
    • --lane lint and --lane cross pass every step except Dylint, which has no driver for its nightly on this machine. The Windows clippy on --all-targets is clean.
    • Runs were on 64f4f38.
  • Real app (UI, protocol output or logging changes): not applicable (a port with no change in behaviour).

Test cost: new tests: longest module 0.03 s (the parity tests, all four; 0.016 s with OBS_PARITY_CASES=reduced), Tier 1 0.01 s, peak RSS 25 MB over 20 runs. No threads of their own; the warning test runs once in a child process.

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 (not stamped: the gate stops at the Dylint step, which has no driver for its nightly on this machine)
  • 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
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

RED for #3562. obs_source::transition_slots has its API and docs, with
todo!() bodies: clear(), enum_sources(), copy_source_state(),
swap_begin() and swap_end(), generic over a Transition with one method
per field read or write, per lock call and per call into the rest of
libobs (obs_source_get_ref(), obs_source_release(), the active-child
add and remove, the recursion warning).

tests/source/transition_slots.rs runs them on a fake source graph that
counts references and active-child links, records every call in order,
and panics on a field touched without the lock the C holds there or a
lock taken twice. The c_* cases follow test_source_transition_slots.c;
the others pin which children are released, added or kept, what the
destination stores when the add fails or the child is going away,
which clock fields move, and every lock's order, with a proptest over
any two transitions. 17 of the 18 fail on the stubs (obs-tests-core,
source::transition_slots); the constants pass.

Refs #3562.
The child slots of obs-source-transition-slots.c are Rust:
obs_transition_clear(), obs_transition_enum_sources(), and the swap of
obs_transition_swap_begin() (with copy_source_state()) and
obs_transition_swap_end(). The clear and the swap stay EXPORT
(rust-exports.d); obs_transition_enum_sources() is declared in
obs-internal.h without EXPORT and stays hidden (rust-hidden.d). The
export sets of the C, hybrid and C reference builds are unchanged
(1767).

The safe core makes the C's calls in its order and under its locks,
generic over a Transition: one method per seam call (the check, each
field, both mutexes, the render targets) and per libobs call. The
shims in obs-source-seam implement it over the transition seam and,
through Calls, over obs_source_get_ref(), obs_source_release(), the
active-child add and remove and obs_source_get_name(), with the
recursion warning through blog(). Libobs makes those calls through
the C symbols; the parity test hands in the oracle's stand-ins.

oracle/source_active_child_links.c gives obs-tests-core
obs_source_add_active_child() and obs_source_remove_active_child()
under their own names: the MSVC, MinGW and macOS linkers resolve every
symbol the shims name, used or not, and that binary links no libobs.
No test reaches them.

The file moves from libobs.core-source into its own ported group,
libobs.ported-source-transition-slots, whose precompiled header is
obs-internal.h with the seam, start and load headers.

Tier 1: 18/18. Tier 2: the transition tests pass 25/26 on the C build
and 30/31 on the hybrid and C reference builds, 0 skipped; the one
failure on all three is test_stinger_media_duration, whose stinger
effect file is not in this tree's run directory.

Refs #3562.
oracle/source_transition_slots.c builds the original
obs-source-transition-slots.c renamed oracle_*, over the transition
seam the settings oracle already compiles under its own names. Its
calls into the rest of libobs (obs_source_get_ref(),
obs_source_release(), the active-child add and remove,
obs_source_get_name()) go to recording stand-ins: one graph of test
sources (zeroed struct obs_source with a type, a name and both
transition mutexes), each with a reference count, a link count per
parent and child, and a trace of every call but the name reads, whose
order the C leaves unspecified.

tests/source_seam/transition_slots_parity.rs runs the C and the Rust
shims (with the same stand-ins as their Calls) on the same graph, built
afresh for each, and compares after every call and between each swap's
begin and end: every slot, active flag, running flag, clock field and
render target, which mutexes are held, every reference and link count,
the calls in order and what the enum's callback got with the lock held.
Every call on ten fixed graphs (the C test's running transition, a new
one that held children, inactive slots, the new transition and a scene
that contains it in the old one's slots, a transition holding itself,
one child in both slots, an input with children, children going away,
a manual and an audio-only transition) and a proptest over random
graphs and sequences of up to seven calls. In a child process, the
recursion warning is the C's line and level from both sides.

Mutants in the core (no remove of the old child, no manual target, no
stop of the audio, a refused slot left active, the old children not
released) each fail it. The order of the lock calls is not visible
here; the Tier 1 tests pin it.

Refs #3562.
rust/README.md gets the row for obs-source-transition-slots.c (the
core over the seam and the libobs calls, the locking, which functions
are exported, what is kept and how each tier checks it) and the file
in the obs-source and obs-source-seam rows; both crates' descriptions,
lib.rs module docs and the obs-source-seam README name it, and so does
naming.md's obs-source*.c.h row. No intentional differences, and no
change a user can see, so docs/features.md gets no line.

Fixes #3562.
@rdoupe
rdoupe force-pushed the fix/rust-port-port-the-transition-ch-568 branch from 22c756b to 64f4f38 Compare November 3, 2026 16:06
@rdoupe
rdoupe marked this pull request as ready for review November 3, 2026 18:18
@rdoupe
rdoupe requested a review from zackees as a code owner November 3, 2026 18:18
@rdoupe
rdoupe added this pull request to the merge queue Nov 3, 2026
Merged via the queue into master with commit 1061a6d Nov 3, 2026
195 of 208 checks passed
@rdoupe
rdoupe deleted the fix/rust-port-port-the-transition-ch-568 branch November 3, 2026 18:35
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 child slots

1 participant