Skip to content

obs-source: Port the transition start checks and child handover - #2478

Merged
zackees merged 6 commits into
obs-rust:masterfrom
rdoupe:port/transition-start
Oct 26, 2026
Merged

zackees merged 6 commits into
obs-rust:masterfrom
rdoupe:port/transition-start

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Fixes #2473

What and why

Ports the start checks and child handover of libobs/obs-source-transition.c.h to rust/obs-source, as a new module transition_start, next to transition_clock and transition_render. Every obs_transition_start() goes through them: each Studio Mode switch, T-bar grab and scene change.

  • obs_transition_start(): the first refusal (the destination is already source A and nothing is running), whether the recursion walk runs, the second admission (refused, already there in manual mode, or go), the duration in ns, and the start to no destination that sets both flags itself;
  • set_source(): the clock restart rule, the handover of an active slot (the new child added first, the old one removed only if the add worked), the admission callback gate, and the size recalculation for a size of 0;
  • activate_transition(): the child is added only to a slot that is not active yet;
  • obs_transition_get_active_source() and obs_transition_save(): B while transitioning, else A;
  • obs_transition_set_manual_time(): manual mode and t == 0.0f sets source A;
  • obs_transition_set() and copy_source_state(): whether a child goes out or comes in as an active child.

The earlier transition ports (#2055 clock and fit, #2184 render and audio) left all of this in C.

This unit is concurrency-sensitive, so the plan's API was split per step. obs_transition_start() reads the sources in three separate lock sections on purpose: the plugin's transition_start callback can re-enter (start the same transition again, or set it), and obs_transition_set() runs between the first two. The plan sketched first_gate(), second_gate(), clock(), handover(same_child, already_active, has_new, has_old), after_add(add_ok, has_callback) and needs_resize(cx, cy). handover() would decide the removal before the add's result is known, and needs_resize() would read cy when cx is 0, where the C reads it only when cx is not 0. So each step is its own function, asked at its own point, as #2153 did. Each one gets only values the C already read, in the lock section where it reads them today. No lock section is merged, and no read moves across a lock, a callback or a signal. Fourteen functions cross the C ABI:

  • obs_source_transition_start_refused(), _walks(), _admit() (GO, REFUSE or DONE), _duration_ns() and _null_dest();
  • _restart(), _adds(), _removes(), _calls_back() and _unsized();
  • _activates(), _active_index(), _manual_reset() and _child_active().

What stays C, at its point and under its condition:

  • the locks and lock_textures(), and every pointer comparison (dest == sources[0], dest == sources[1], new_child == old_child, dest == transition, tr_dest == tr_source);
  • transition_active() with its ||: the video flag is read only when the audio flag is clear. So the "finish the running transition first" step and the stop signal of obs_transition_set() are still exactly that read;
  • the fixed duration read (only when it is enabled), the size reads (cy only when cx is not 0), and copy_source_state()'s read of the old slot's flag (only with an old child);
  • the swap gate; every obs_source_get_ref() and obs_source_release(); the active child calls in their order; obs_source_enum_full_tree() with check_transition_recursion(); the plugin callback; obs_source_dosignal(); recalculate_transition_size() and _matrices(); os_gettime_ns(); the logs.

The header copies OBS_TRANSITION_MODE_MANUAL, and obs-source-transition.c.h checks it with _Static_assert (enum obs_transition_mode is already checked as int-sized there). No pointer crosses and no struct is mirrored. The core reuses transition_clock::MODE_MANUAL.

Six commits:

  1. Move (behaviour-neutral, 78dd0b9be): the decisions go to libobs/obs-source-transition-start.c.h, declared in the new obs-source-transition-start.h without EXPORT, so they are hidden. The file joins libobs.core-source. git blame on the moved lines shows upstream commits (6839ff7, a97039d, e6b52f2, a1fbf10) and the fork's recursion fix from libobs: Reject recursive transition destinations #737 (8094e1f); they move as they are.

    The move was checked against the original code. A scratch harness (not committed) compiles origin/master's transition_active(), write_start_clock(), set_source(), obs_transition_get_active_source(), activate_transition(), check_transition_recursion(), obs_transition_start(), obs_transition_set_manual_time(), obs_transition_set(), obs_transition_save(), copy_source_state(), obs_transition_swap_begin(), obs_transition_swap_end() and obs_transition_clear() verbatim, next to this branch's and the moved file, as C++:

    • the stand-in sources' fields are wrappers that log every read and write, with the value;
    • every call is logged in order with its arguments: both mutexes of both transitions (lock and unlock), transition_valid(), obs_source_get_ref() (which may return NULL, as for a source being destroyed), obs_source_release(), the active child calls (the add may fail), the tree walk with each visit, the names, blog(), the signals, os_gettime_ns(), the size and matrix recalculation and the obs_data writes;
    • a concurrent writer, which takes the transition's mutex as libobs does, may move any source, slot flag, transitioning flag, the mode, the manual target and value, the size, the fixed duration and the start time at any unlock or call;
    • the plugin's transition_start may do nothing, start the same transition again (two levels deep), set it, set a manual time or write a field;
    • the inputs cover two transitions and four children, every slot and flag, modes 0, 1 and outside the enum, durations from 0 to UINT32_MAX, sizes 0, 1 and full HD, the fixed duration on and off, manual times 0, -0, NaN, 1, 0.5, the smallest denormal, -1 and infinity, and destinations that are empty, the transition itself, the other transition or a child.

    11,000,000 runs (GCC and Clang -O2, 4,000,000 each; -O0, 1,000,000 each; ASan with UBSan, no recovery, under GCC -O0 and Clang -O2, 300,000 each; gcov, 400,000): all 1,236,343,886 logged events match on both sides, and so does the final state. Every branch of origin/master's functions is taken both ways, except set_source()'s callback == NULL edge: every caller passes activate_transition().

    29 deliberately broken moves were tried, and all 29 fail the harness:

    • the second section read without its lock, and its reads merged into the first section;
    • the video flag read always (in the restart rule and in the active source), cy read always, the fixed duration read always;
    • the old child removed before the add, obs_transition_save() reading the flags before its lock, the old slot's flag read without an old child;
    • 21 changed decisions: each operand of each rule dropped or inverted, the duration in µs and in 32 bits, the size test at 1, the reset at t <= 0 and not for -0.0, the active index swapped.
  2. Characterization (55784bb8e): test_transition_start_steps, 17 cases. It compiles the moved file with ASan and UBSan and calls only its functions:

    • each gate over every combination of its inputs: the first refusal and the walk; the second admission over all 16 flag combinations at six modes; the clock rule, the handover, the callback gate and the null destination; the active index and the active child rule;
    • the duration at 0, 1, 300, around 2^32 ns and UINT32_MAX ms;
    • the manual reset at 0, -0 (resets), NaN (does not), 1, the smallest denormal either side, -1 and infinity, and never outside manual mode.

    It also copies the callers onto a stand-in transition that counts each child's references and active references:

    • a start from idle, to source A, to the transition itself and to a tree holding it, while running, and to no destination with and without a source A;
    • a re-entering transition_start callback that starts the same transition again;
    • a failed add (a cycle the walk did not see) that keeps the nested start's clock and child;
    • the fixed duration on and off at 0 and UINT32_MAX;
    • the swap with the same transition, a running one and inactive slots, and the set while running, idle and to none.

    It is in the test graph, sorted, with the header as a watch input.

  3. RED (d3930f32b): Tier 1 against todo!(). It ports the 17 C cases 1:1 and adds six edge tests:

    • every decision over every flag combination;
    • the admission and reset for every mode from -70,000 to 70,000 and the ends of i32;
    • the duration at every power of two and its neighbours and a stride of u32, against the exact 128-bit product;
    • the reset over 18 special floats and every 4,099th f32 bit pattern;
    • proptests over full-range values, and over sequences of starts, sets, manual times, active source reads and swaps (with a re-entering plugin, failing adds, a fixed duration and unsized transitions) through the stand-in, against origin/master's expressions inline.
  4. GREEN (c57410162): the safe core (fourteen functions, Admission) and fourteen #[no_mangle] shims, in a new libobs.ported-source-transition-start group whose PCH is only the new header.

    • The commit updates source-sets.json, the unity lists, the three export lists and ci/test_ported_sources.py, each in sorted place.
    • test_transition_start_steps_rust builds the unchanged test source against libobs_rust-static, as test_source_audio_place_steps_rust does.
  5. Tier 3 (2cdfba826): a C oracle of the unchanged file, the parity tests and a mutation check.

  6. Docs (602fab079): the README row, the crate's description, lib.rs, and a port_comparison bench module in the sorted lists. The port changes nothing a user can see, so docs/features.md has no line.

The core denies clippy's arithmetic, indexing, as, unwrap, expect, panic, todo, unimplemented and unreachable lints. It keeps no state and takes no lock. The duration widens to 64 bits before the product, which cannot wrap (UINT32_MAX * 1e6 is below 2^52), and has no division. manual_reset() uses Rust's IEEE f32 ==, which matches the C's t == 0.0f (true for -0.0, false for NaN).

  • Kept, characterized, not endorsed (unchanged behaviour):
    • the mode a re-entering start writes stays when the outer start completes (the comment in obs_transition_start() already says so);
    • since upstream's finish step (0df94d5) runs before the second read, a running manual transition started again to the same destination first finishes on it. The start is then refused as a start to source A, so the transition jumps to the destination. The manual "already there" success (DONE) now needs another thread's start between the finish and the second read;
    • a start to no destination with a source B in a slot that is not active adds NULL, which fails, and is refused with the recursion warning. libobs never leaves a source B in an inactive slot;
    • obs_transition_set() marks slot A active even when adding its source fails (see below).
  • Intentional differences: none.

Bench (x86_64 Linux, GCC, release, not pinned to a core, a loaded host; median per 1024 starts, each through every decision in the C's order, then a manual time and the set's two active child rules): Rust 19.65 µs, C 20.63 µs (0.95x), about 19 ns a start.

RED → GREEN

  • RED commit: d3930f32b (obs-source: Test the transition_start port).
    • soldr cargo test -p obs-data --test obs-tests-core -- source::transition_start: 1 passed (the constants, which are not stubs), 22 failed, each on a todo!() ("not yet implemented").
    • On that commit, before the final rebase (6229a7c6e, the same tree on 2fbf34251), local_gate --lane lint was clean, and --test-diff origin/master ran 4300 tests: 4278 passed, 6 skipped, and only those 22 failed.
  • GREEN (c57410162): Tier 1 23/23.
    • test_transition_start_steps passes 17/17 on the C backend, on hybrid libobs and on libobs-c-reference, and test_transition_start_steps_rust passes 17/17 against the Rust archive.
    • These real-libobs tests see the swap and pass on all three, run through ctest under a private Xvfb with a fresh HOME, with every case run and none skipped: test_transition_recursive_destination, test_transition_swap, test_studio_mode_swap, test_studio_mode_exit, test_saved_transition, test_transition_scale_type, test_item_transition_empty_source, test_visibility_transition, test_stinger_media_duration, test_transition_removed_child_audio, test_group_hide_transition_audio, test_tbar_position, test_fade_to_color_mix, test_transition_audio_rescale, test_slideshow_manual_end, test_transition_clock_steps and test_transition_render_steps. That is 130 cmocka cases on the C backend, and 183 with the three _rust variants on the other two.
    • Exported symbols are identical on all three (1766). The fourteen functions are local. In the hybrid they come from the Rust archive, and the group's object is built only for libobs-c-reference.
  • Tier 3 (2cdfba826): 6/6, oracle, shims and core compared exactly (each bool as the C's byte):
    • the header's values and the sizes of the admission enum, bool and size_t;
    • every function of flags over every combination of them;
    • the admission over all 16 flag combinations for every mode from -100,000 to 100,000, every 65,521st int and the ends;
    • the duration and the size rule over every value to 100,000, every 65,521st uint32_t, every power of two and its neighbours, and the ends;
    • the manual reset over 36 special floats at every mode from -1,000 to 1,000 and the ends. In manual mode it also runs over every 257th f32 bit pattern, and the 65,536 patterns either side of both zeros, both infinities and the start of both quiet NaN ranges;
    • proptests of 20,000 cases each over full-range values and any f32 bit pattern;
    • nothing is excluded.
  • Mutation check: 43 mutants (27 in the core, 16 in the shims).
    • 36 are killed. Tier 1 kills every core mutant that changes a result, and Tier 3 kills every mutant that changes a result, core or shim.
    • The seven survivors are equivalent: the core asking DONE before REFUSE (the two need active and !active, so they never meet); the shims swapping the arguments of adds(), removes(), child_active(), restart() and null_dest() (each symmetric in the swapped pair); and a reset of -t.
  • Checks on 602fab079 (the head, on 4cd953c4e):
    • local_gate --lane lint and --test-diff origin/master pass (test-diff: 4401 passed, 6 skipped);
    • --lane cross (clippy for x86_64-pc-windows-msvc and aarch64-apple-darwin, with SOLDR_RUSTC_WRAPPER=none) passes. It ran on 200da06a6, the same branch on ced504882; the one commit between them changes only CI scripts and docs/features.md;
    • SOLDR_RUSTC_WRAPPER=none soldr cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets --locked -- -D warnings is clean (the cross lane lints only --lib --bins without the oracle);
    • soldr cargo test -p obs-c-oracle --locked --bench port_comparison passes.
  • Full ctest (C backend, hybrid libobs, libobs-c-reference) on 200da06a6, under a private Xvfb with a fresh HOME:
    • 528/528 on the C backend and 560/560 on hybrid libobs;
    • 559/560 on libobs-c-reference. The one failure, test_pulse_monitor_device, comes from the shared session's default sink, which other PulseAudio tests change while they run in parallel. It passes 3/3 alone and does not touch transitions;
    • every lane skips the same three hardware tests (test_pulse_default_follow, test_v4l2_vivid_replug, test_v4l2_vivid_stall). The exported symbol sets of those builds are still identical (1766).
  • Pinned suite counts: none cover this suite.
  • Real app: not applicable (no UI, protocol or logging change).

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)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): none

Behaviour-neutral extraction before the Rust port. The decisions of
obs_transition_start(), set_source(), activate_transition(),
obs_transition_get_active_source(), obs_transition_save(),
obs_transition_set_manual_time(), obs_transition_set() and
copy_source_state() in obs-source-transition.c.h move to
libobs/obs-source-transition-start.c.h, as fourteen functions on plain
values declared in the new libobs/obs-source-transition-start.h without
EXPORT (hidden, as -fvisibility=hidden keeps them):

- _refused(): the first refusal of obs_transition_start() (the
  destination is source A and nothing is running);
- _walks(): whether the recursion walk runs (a destination that is not
  the transition itself);
- _admit() -> GO | REFUSE | DONE: the second read's refusal and the
  manual same-target success;
- _duration_ns(): (uint64_t)ms * 1000000;
- _restart(): set_source()'s clock rule;
- _adds(), _removes() and _calls_back(): the handover of an active slot
  (the new child added first, the old one removed only if the add
  worked) and the admission callback;
- _unsized(): a transition size of 0;
- _null_dest(): a start to no destination sets both flags itself;
- _activates(): activate_transition() adds only to a slot not active
  yet;
- _active_index(): B while transitioning, else A;
- _manual_reset(): manual mode and t == 0.0f;
- _child_active(): a child goes out (obs_transition_set()) or comes in
  (copy_source_state()) as an active child.

Split per read, as obs-rust#2153 did. obs_transition_start() reads the sources
in three lock sections on purpose (the plugin's transition_start
callback can re-enter, and obs_transition_set() runs in between), so
each function gets only what one section read and is asked where the C
decided before. The rest stays C at its point: the locks,
lock_textures(), the pointer comparisons, transition_active() and its
||, which reads the video flag only when the audio flag is clear (so
the "finish the running transition first" step and the stop signal are
still that read), the fixed duration read (only when it is enabled),
the size reads (cy only when cx is not 0), copy_source_state()'s read
of the old slot's flag (only with an old child), the swap gate
(tr_dest == tr_source), every obs_source_get_ref() and
obs_source_release(), the active child calls, the recursion walk and
check_transition_recursion(), the plugin callback, the signals,
recalculate_transition_size() and _matrices(), os_gettime_ns() and the
logs. The mode crosses as int; the header copies
OBS_TRANSITION_MODE_MANUAL and obs-source-transition.c.h checks it with
_Static_assert (enum obs_transition_mode is already checked int-sized
there).

Checked in a scratch harness (not committed). It compiles
origin/master's transition_active(), write_start_clock(),
set_source(), obs_transition_get_active_source(),
activate_transition(), check_transition_recursion(),
obs_transition_start(), obs_transition_set_manual_time(),
obs_transition_set(), obs_transition_save(), copy_source_state(),
obs_transition_swap_begin(), obs_transition_swap_end() and
obs_transition_clear() verbatim next to this branch's and the moved
file, as C++, over stand-in sources whose fields log every read and
write with its value. Every call is logged in order with its
arguments: both mutexes of both transitions (lock and unlock),
transition_valid(), obs_source_get_ref() (which may return NULL, as for
a source being destroyed), obs_source_release(), the active child
calls (the add may fail), obs_source_enum_full_tree() with each visit,
obs_source_get_name(), blog(), the signals, os_gettime_ns(), the size
and matrix recalculation and the obs_data writes. A concurrent writer,
which takes the transition's mutex as libobs does, may move any source,
slot flag, transitioning flag, the mode, the manual target and value,
the size, the fixed duration and the start time at any unlock or call.
The plugin's transition_start may do nothing, start the transition
again (two levels deep), set it, set a manual time or write a field.
Inputs: two transitions and four children; every slot empty or any
source; every flag; modes 0, 1 and out of the enum; durations 0, 1,
300, 1000, UINT32_MAX - 1, UINT32_MAX and random; sizes 0, 1 and full
HD; fixed duration on and off; manual times 0, -0, NaN, 1, 0.5, the
smallest denormal, -1 and infinity; destinations empty, the transition
itself, the other transition or a child; one to six operations each.

11,000,000 runs: 4,000,000 each with GCC and Clang at -O2, 1,000,000
each at -O0, 300,000 each under ASan and UBSan with no recovery (GCC
-O0, Clang -O2) and 400,000 with gcov. All 1,236,343,886 events match,
as does the final state. Every branch of origin/master's functions is
taken both ways, but set_source()'s callback == NULL edge: every caller
passes activate_transition().

29 deliberately broken moves were planted, and all 29 fail it: the
second section read without its lock, the second section's reads
merged into the first, the video flag read always (restart rule and
active source), cy read always, the fixed duration read always, the old
child removed before the add, obs_transition_save() reading the flags
before its lock, the old slot's flag read without an old child, and
twenty-one changed decisions (each operand of each rule dropped or
inverted, the duration in us and in 32 bits, the size at 1, the reset
at t <= 0 and not for -0.0, and the active index swapped).

git blame on the moved lines shows upstream commits (6839ff7,
a97039d, e6b52f2, a1fbf10) and the fork's recursion fix from
obs-rust#737 (8094e1f: the clock flags, the walk's start value and the null
destination); they move as they are.

The new file joins libobs.core-source with libobs.pch.h, which includes
the new header; source-sets.json lists it. docs/rust-port/naming.md
already maps libobs/obs-source*.c.h to rust/obs-source. The exported
symbol sets are unchanged; the fourteen functions are local.

Refs obs-rust#2473
test_transition_start_steps compiles
libobs/obs-source-transition-start.c.h (ASan and UBSan) and calls only
its functions through obs-source-transition-start.h. 17 cases:

- the header's copy of OBS_TRANSITION_MODE_MANUAL, the enum's size and
  the admission values;
- the first refusal and the recursion walk over all four inputs each;
- the second admission over all 16 flag combinations at six modes (0,
  manual, 2, -1 and the ends of int);
- the duration in ns at 0, 1, 300, around 2^32 ns and UINT32_MAX ms;
- set_source()'s clock rule, the handover, the callback gate and the
  null destination over every combination, the size of 0, the slot
  activation, the active index and the active child rule;
- the manual reset at 0, -0 (resets), NaN (does not), 1, the smallest
  denormal either side, -1 and infinity, and never outside manual mode.

obs_transition_start(), set_source(), activate_transition(),
obs_transition_set(), obs_transition_set_manual_time(), the active
source and the swap are also copied onto a stand-in transition that
counts each child's references and active references, to pin end to
end: a start from idle (sized and unsized), to source A, to the
transition itself and to a tree that holds it (refused before anything
changes), while running (finished on B first, then to the new one),
and to no destination with and without a source A; a re-entering
transition_start callback that starts the same transition, to another
destination and to the same one; a failed add (a cycle the walk did
not see) that keeps the nested start's clock and child; the fixed
duration on and off at 0, 1, 300 and UINT32_MAX against the same
requested durations; the manual times at 0, -0, NaN and 1 in manual
and auto mode; the swap with the same transition, a running one and
inactive slots; and the set while running, idle and to none.

Characterized, not endorsed:
- the mode a re-entering start writes stays, even when the outer
  start then completes (the comment in obs_transition_start() says
  so);
- since upstream's finish step (0df94d5) runs before the second
  read, a running manual transition started again to the same
  destination finishes on it, and the start is then refused as a
  start to source A: the transition jumps to the destination. The
  manual "already there" success needs another thread's start
  between the finish and the second read;
- a start to no destination with a source B in a slot that is not
  active adds NULL, which fails, and is refused with the recursion
  warning (libobs never leaves a source B in an inactive slot);
- obs_transition_set() marks slot A active even when the add of the
  new source fails, so the next set removes an active reference it
  never got.

It is in the native test graph, in name order, with the header as a
watch input. No assert_in_range or fail_msg, so it builds with cmocka
1.x and 2.x, and no two enum types are compared. The real-libobs tests
test_transition_recursive_destination, test_transition_swap,
test_studio_mode_swap, test_studio_mode_exit, test_saved_transition,
test_tbar_position, test_fade_to_color_mix, test_visibility_transition
and test_stinger_media_duration cover the callers.

Refs obs-rust#2473
RED for the port of libobs/obs-source-transition-start.c.h to a new
transition_start module of rust/obs-source, next to transition_clock
and transition_render. The safe core is a stub (todo!()): refused(),
walks(), admit() -> Admission (Go, Refuse, Done), duration_ns(),
restart(), adds(), removes(), calls_back(), is_unsized() (unsized is a
reserved word), null_dest(), activates(), active_index(),
manual_reset() and child_active(), with MODE_MANUAL taken from
transition_clock.

The plan sketched first_gate(), second_gate(), clock(), handover(),
after_add() and needs_resize() as wider steps. handover() and
after_add() would decide the remove before the add's result is known,
and needs_resize(cx, cy) would read cy when cx is 0, where the C reads
it only when cx is not 0. So each step is its own function, asked at
its own point, as obs-rust#2153 did; the fixed duration choice, the finish
step and the swap gate stay C as the reads they are.

tests/source/transition_start.rs ports test_transition_start_steps
1:1: its 17 cases under the same names (steps_*), in the same order,
with the same values and expectations, the characterized-not-endorsed
cases and the stand-in transition's copies of the callers included.

Edge cases (edge_*) check the core against models of the original C:
- every decision over every combination of its flags;
- the second admission over all 16 flag combinations and the manual
  reset at both zeros and NaN for every mode from -70,000 to 70,000
  and the ends of i32;
- the duration at every power of two and its neighbours, every
  65,521st u32 and the ends, against the exact 128-bit product;
- the manual reset over 18 special floats (both zeros, NaNs with
  either sign and payload, infinities, denormals, the extremes) at six
  modes, and every 4,099th f32 bit pattern;
- proptests (4,096 cases each): every decision over full-range values
  and any f32 bit pattern, and sequences of up to eleven starts, sets,
  manual times, active source reads and swaps, with a re-entering
  plugin, failing adds, a fixed duration and unsized transitions,
  through the stand-in against a copy of the callers with
  origin/master's expressions inline.

soldr cargo test -p obs-data --test obs-tests-core --
source::transition_start passes 1 of 23 (the constants) and fails 22
with "not yet implemented".

Refs obs-rust#2473
Ports libobs/obs-source-transition-start.c.h, the start checks and
child handover of obs-source-transition.c, to the transition_start
module of rust/obs-source. obs-source-transition.c.h stays C around
it: the three lock sections of obs_transition_start() with their
reads, the pointer comparisons, transition_active(), the finish step,
the fixed duration read, the size reads, lock_textures(), every
obs_source_get_ref() and obs_source_release(), the active child calls
in their order, the recursion walk, the plugin's transition_start
callback (which can re-enter), the signals, the size and matrix
recalculation, os_gettime_ns() and the logs. The hybrid libobs drops
the C file and links the Rust shims in its place.

Safe core (src/transition_start.rs), fourteen functions:
- refused(): same_as_source && !active; walks(): has_dest &&
  !recursive;
- admit() -> Admission: Refuse as refused(), Done when active, manual,
  the same mode and the same destination, else Go;
- duration_ns(): the u32 widened to u64 times 1e6 (cannot wrap);
- restart(): !active || (!same_as_dest && !same_as_source);
- adds(), removes(), calls_back() and child_active(): the C's &&;
- is_unsized(): size == 0; null_dest(): !has_dest && same_as_dest &&
  !same_as_source; activates(): !slot_active;
- active_index(): 1 while active, else 0;
- manual_reset(): MODE_MANUAL and t == 0.0, an IEEE compare (true for
  -0.0, false for NaN) as the C's t == 0.0f.
MODE_MANUAL is transition_clock's. The module denies clippy's
arithmetic, indexing, as, unwrap, expect, panic, todo, unimplemented
and unreachable lints, keeps no state and takes no lock.

Shims (src/ffi/source_transition_start.rs): the fourteen C signatures
by value; the mode as int, the admission as the C's enum (u32, as
source_transition_clock returns its step). No pointer crosses and no
struct is mirrored. No intentional difference from the C.

C side: the file leaves libobs.core-source for its own group,
libobs.ported-source-transition-start (LIBOBS_PORTED_SOURCES), whose
PCH is only obs-source-transition-start.h; libobs.pch.h keeps the
header for obs-source-transition.c. The functions are not EXPORT, so
the shims are hidden: rust-hidden.txt, the local: list of
rust-exports.map and rust-unexports-macos.txt. libobs-rust already
links the crate's ffi. The exported symbol sets are unchanged and
equal: 1766 on the C backend, the hybrid and libobs-c-reference; the
fourteen functions are local in all three, and the hybrid's come from
the Rust archive (the group's object is built only for
libobs-c-reference). ci/test_ported_sources.py checks the group on
every host.

test_transition_start_steps still compiles the C file into itself,
unchanged. The new test_transition_start_steps_rust builds the same
test source against libobs_rust-static instead, as
test_source_audio_place_steps_rust does, and links: the test includes
the header and obs.h and calls only the fourteen hidden functions.
test_transition_recursive_destination, test_transition_swap,
test_studio_mode_swap, test_studio_mode_exit, test_saved_transition,
test_transition_scale_type, test_item_transition_empty_source,
test_visibility_transition, test_stinger_media_duration,
test_transition_removed_child_audio, test_group_hide_transition_audio,
test_tbar_position, test_fade_to_color_mix,
test_transition_audio_rescale, test_slideshow_manual_end,
test_transition_clock_steps and test_transition_render_steps see the
swap through the real libobs, and pass on the C backend, the hybrid
and libobs-c-reference.

soldr cargo test -p obs-data --test obs-tests-core --
source::transition_start passes 23 of 23.

No user-visible change, so no docs/features.md line.

Refs obs-rust#2473
Tier 3 for the transition_start port. oracle/source_transition_start.c
compiles the unchanged libobs/obs-source-transition-start.c.h with its
fourteen functions renamed to oracle_*, plus the header's values and
the sizes of the admission enum, bool and size_t.

tests/source/transition_start_parity.rs gives each input to the
oracle, to the shim the hybrid links and to the core, and compares
each bool as the byte the C returns (it must be 0 or 1), the admission
as the C's enum value and each number exactly:
- the header's values and the three sizes;
- every function of flags over every combination of them;
- the second admission over all 16 flag combinations for every mode
  from -100,000 to 100,000, every 65,521st int and the ends;
- the duration and the size rule over every value to 100,000, every
  65,521st uint32_t, every power of two and its neighbours, and the
  ends;
- the manual reset at every mode from -1,000 to 1,000 and the ends
  over 36 special floats, and in manual mode over every 257th f32 bit
  pattern, the 65,536 patterns either side of both zeros, of both
  infinities and of the start of both quiet NaN ranges;
- proptests (20,000 cases each) of every function over any flags, any
  int mode, any uint32_t and any f32 bit pattern.

Nothing is excluded: the C has no undefined or host-dependent result
here, and the port has no intentional difference. The callers are not
copied again: every function's whole flag domain is compared, and
Tier 1's sequence proptest runs the copied callers on the core against
origin/master's expressions inline.

Mutation check (once, not committed): 43 mutants, 27 in the core and
16 in the shims (failing tests per tier, Tier 1 of 23 and Tier 3 of 6):

  mutant                                      Tier 1  Tier 3
  core: refused ignores active                       7      3
  core: refused ignores the source                  17      3
  core: walks ignores recursive                      4      2
  core: done without active                          4      2
  core: done in any mode                             3      2
  core: done without the same mode                   3      2
  core: done without the same dest                   3      2
  core: done asked before refuse                     0      0
  core: duration in us                              11      2
  core: duration in 32 bits                          5      2
  core: restart ignores active                       4      2
  core: restart ignores source A                     2      2
  core: restart || as &&                             5      2
  core: adds ignores the slot                       11      2
  core: removes ignores the add                      4      2
  core: removes ignores the old child                2      2
  core: calls back after a failed add                4      2
  core: unsized at 1                                 1      1
  core: null dest ignores source A                   2      2
  core: null dest ignores the dest                   2      2
  core: activates inverted                           9      2
  core: active index inverted                        6      2
  core: reset at t <= 0                              4      2
  core: reset not for -0.0                           5      1
  core: reset in any mode                            5      1
  core: child_active ignores the slot                3      2
  core: MODE_MANUAL 2                                5      4
  shim: refuse and done swapped                      0      2
  shim: refused arguments swapped                    0      2
  shim: walks recursive inverted                     0      2
  shim: admit mode + 1                               0      2
  shim: duration + 1                                 0      2
  shim: restart dest and source swapped              0      0
  shim: removes old and add swapped                  0      0
  shim: adds arguments swapped                       0      0
  shim: unsized of size / 2                          0      1
  shim: null dest dest and source swapped            0      0
  shim: active index inverted                        0      2
  shim: reset of -t                                  0      0
  shim: reset mode + 1                               0      1
  shim: child_active arguments swapped               0      0
  shim: calls_back add inverted                      0      2
  shim: activates inverted                           0      2

36 are killed: Tier 1 kills every core mutant that changes a result,
and Tier 3 kills every one that does, in the core and the shims. The
seven survivors are equivalent: the core asking Done before Refuse
(the two need active and !active, so they never meet); the shims
swapping the arguments of adds(), removes(), child_active() (each an
&& of its arguments), restart() (symmetric in the destination and
source A) and null_dest() (!has_dest && same_as_dest &&
!same_as_source is the same with has_dest and same_as_source
swapped); and the reset of -t (negation keeps both zeros zero and NaN
NaN).

soldr cargo test -p obs-data --test obs-tests-core --
source::transition_start passes 29 of 29 (Tier 1 23, Tier 3 6).

Refs obs-rust#2473
rust/README.md gets the row for libobs/obs-source-transition-start.c.h
(obs-source::transition_start), in sorted place: what moved, what
stays C and why (every read in its lock section, since
obs_transition_start() reads the sources in three sections on purpose
and the plugin's transition_start callback can re-enter; the ||
around transition_active(), the fixed duration and size reads, the
active child calls in their order, the walk, the callbacks and the
signals), the characterized-not-endorsed behaviours, the tests that
see the swap and what Tier 3 covers. The obs-source crate row, its
Cargo description and the lib.rs crate docs name the new module.
docs/rust-port/naming.md already maps libobs/obs-source*.c.h to
rust/obs-source.

rust/obs-c-oracle/benches/port_comparison/source_transition_start.rs,
in the sorted mod and modules![...] lists, runs 1024 starts over every
combination of the flags the C reads, manual and auto modes,
durations from 0 to UINT32_MAX ms and sizes of 0 and full HD, through
every decision in the C's order, then a manual time and the set's two
active child rules, on the shims and on the oracle, and checks both
checksums match. Release, x86_64 Linux, GCC, a loaded host, median per
1024 starts: Rust 19.65 us, C 20.63 us (0.95x), about 19 ns a start.

The port changes nothing a user can see, so docs/features.md has no
line.

Fixes obs-rust#2473
@rdoupe
rdoupe requested a review from zackees as a code owner October 26, 2026 13:05
@zackees

zackees commented Oct 26, 2026

Copy link
Copy Markdown
Member

Coordinator review: a decision port in the standard shape, like #2469. The transition start checks and the child handover move into a steps unit and then to Rust, with a C reference copy, a parity test, a bench and the export maps. The only existing test file touched is the test-graph.json entry. Queuing; it merges when CI is green.

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 start checks in obs-source-transition.c to obs-source

2 participants