Skip to content

libobs: Reject recursive transition destinations - #737

Merged
zackees merged 2 commits into
obs-rust:masterfrom
chriscoveries:fix/transition-recursive-destination
Oct 14, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
chriscoveries:fix/transition-recursive-destination

Conversation

@chriscoveries

Copy link
Copy Markdown
Contributor

Draft. Opened so upstream PR CI can run it. Our own CI is down, so this hasn't been through our usual CI runs: see our note on #699.

Status: draft. Opened so upstream PR CI can run it. No issue has been opened. Branch fix/transition-recursive-destination is on the fork, two commits above upstream/master at 7cf6f3932e8706f363e2e6f38a91683354bb2b31:

  • RED af07e1a04cb69cab18683ffce4f2ec6446b1274a — libobs: reject recursive transition destinations (RED) (tests only)
  • GREEN 8094e1fdb0297674b957b3eabbed02a7463d9d62 — libobs: reject recursive transition destinations (GREEN)

A merge against upstream/master at a48a9a13d80d3ac5ded749093e6ac2a08855e189 is clean.

Problem

obs_transition_start(T, ..., dest) hangs forever when dest already contains T. Examples: a nested transition whose source is T, a chain through another transition, or a plugin's transition_start callback that puts T into dest just before admission. The calling thread deadlocks on T's own mutex. Starting T towards itself returns true even though the destination was refused.

Fixes: TBD

Root cause

At the base commit:

  • obs_transition_start calls set_source (libobs/obs-source-transition.c:371).
  • set_source takes T's non-recursive transition_mutex (:231), then admits the destination through activate_transition → obs_source_add_active_child.
  • The cycle check in obs_source_add_active_child walks the destination's full tree (libobs/obs-source.c:4781).
  • When that walk reaches a transition, it enumerates the transition's children with obs_transition_enum_sources (obs-source.c:4711-4712), which locks that transition's mutex (obs-source-transition.c:606).
  • When the walk reaches T, it locks the mutex the same thread already holds, so the thread deadlocks.

For dest == T, admission refuses (parent == child), but the start still returns true and signals transition_start.

Fix

Reject recursion:

  • Preflight. Before any state change or plugin callback, obs_transition_start walks the destination and rejects it if T appears anywhere in it, or if dest == T (obs-source-transition.c:386-395). This walk runs without T's mutex held, so it cannot deadlock.
  • Admission. A plugin's transition_start callback can change the graph after the preflight. Admission therefore checks again: a private traversal with a stop source (obs-source.c:4707-4715, :4794) reports the edge into T without descending into it. A cycle created during the callback is then rejected instead of re-locking the held mutex.
  • Propagation. set_source now returns the admission result. obs_transition_start returns false and emits no start signal. The old B slot and its reference are kept (obs-source-transition.c:433-437).
  • Diagnostic. Each rejection logs obs_transition_start: transition '<T>' has recursive destination '<dest>'.

Keep the clock consistent with re-entry:

  • Write the clock only after admission succeeds. Previously the start clock was written from state read before the plugin callback, before admission. A rejected outer start could therefore overwrite the clock of a start the callback had made. The clock is now decided and written in set_source, under the lock that admits the destination, from state read after the callback (:220-235, :253-259, :277-279). A rejected start writes nothing.

  • Read the clock under the lock. The two video render functions now read the clock under transition_mutex (:760-762, :889-891), and so does the public obs_transition_get_time (:541-543). Before, all three read it without the lock. A start publishes its clock under that lock, together with the transitioning_* flags for every destination except NULL. For an unchanged NULL destination the clock is written under the lock and the flags are set just after the unlock (:438-441, as on base). That is harmless: the clock is written first, so a reader can only see the new clock with the old (false) flags, which renders A as it did before the start. An old clock with new flags cannot occur. So none of these reads can now pair a new start with the previous clock. That pairing would end the new transition on its first frame (render functions), or, for the stinger, choose the destination for one frame before its transition point (obs_transition_get_time followed by obs_transition_video_render_direct). obs_transition_audio_render already read its clock under the lock for the stop decision (:1036-1039). Its per-sample mixing reads the clock after the unlock (process_audio, mix_child, get_sample_time and calc_time, :931-946, called at :1053-1060), unchanged from base.

    Each call is consistent on its own; two separate calls are not one snapshot. If a start lands between the stinger's obs_transition_get_time and its obs_transition_video_render_direct, that frame can still draw the destination. Upstream has the same gap.

Alternatives considered:

  • Make transition_mutex recursive. That would avoid the hang, but it would also hide real cycles: a cyclic graph would recurse forever when rendering. Rejected.
  • Preflight only. A transition_start callback can still create the cycle after the preflight. Rejected.
  • Write the clock before admission and restore it on rejection. This keeps base's write order, so readers that take no lock would see what they saw on base. But it briefly exposes the clock of a start that is about to be rejected. Rejected in favour of a single write under the admitting lock, with every libobs reader taking that lock.

Evidence

  • RED → GREEN: test_transition_recursive_destination is a new cmocka test with 18 public-API cases. Each case runs in a forked child with a 10 s alarm, so a deadlock fails the case instead of hanging the run. The three render-race cases cannot pass without proving that the render thread was blocked inside admission. A render thread stalled for more than 3 s fails the case instead. The test is Linux-only (OpenGL under Xvfb, and the race cases read /proc), registered in test/cmocka/tests.d/.

    On RED, built with ENABLE_RUST_LIBOBS OFF and ON, 12 cases fail and 6 pass (these runs used base libobs with the committed test, which is equivalent because RED changes only tests):

    [  PASSED  ] 6 test(s).
    [  FAILED  ] tests: 12 test(s), listed below:
    
    • Nine cases end with child terminated by signal 14 (transition start did not return).
    • Both self-destination cases return true.
    • callback_clock_survives_same_destination_start reads progress 7.723159e-09 where it expects 1.

    On GREEN, both modes:

    [  PASSED  ] 18 test(s).
    100% tests passed, 0 tests failed out of 1
    

    Seven ctest runs passed in each mode (logs for five were kept).

  • Render races: three cases share one setup.

    • T is on output channel 0.
    • The destination's enum_active_sources is called during admission while T's mutex is held. It waits until the render thread has entered T's video_render and is asleep, read from /proc/self/task/<tid>/stat. After entering video_render, the render thread can only block on T's mutex.
    • Then it lets admission finish. A 10 s AUTO transition must not emit transition_video_stop.

    The cases differ in how T's video_render draws, each the way a shipped transition does:

    Case T's video_render Extra check
    render_during_admission_keeps_new_transition obs_transition_video_render (the built-in transitions)
    timed_direct_render_during_admission_uses_new_clock obs_transition_get_time picks A or B, then obs_transition_video_render_direct (the stinger without a track matte) the first transitioning frame's time is below 1
    direct_render_during_admission_keeps_new_transition obs_transition_video_render_direct alone (the stinger while its track matte is not ready)

    In the timed case the render thread waits inside obs_transition_get_time, so obs_transition_video_render_direct's own clock read happens after the start. The direct-only case is the one that covers that read.

    libobs build Result
    This head All three pass, 7 of 7 runs in each mode (logs for five were kept). The timed case logs first transitioning frame: seen=1 get_time=0.000000 -> target A.
    Earlier revision 1: obs_transition_get_time without the lock Only the timed case fails, 3 of 3 runs OFF and 1 of 1 ON: get_time=1.000000 -> target B
    Earlier revision 2: the render functions also without the lock (run with the earlier 16-case version of this test) Only render_during_admission_keeps_new_transition failed, 5 of 5 runs: video_stop_signals=1
    Master All three pass, because master writes the clock before admission.
  • Mutation check (compiled; OFF, and ON where stated): each mutant fails the cases listed. The rows with run counts were run against this head's test. The other rows are from earlier rounds of this branch. The code they mutate has not changed since.

    Mutant Fails
    Restart decision made before the plugin callback callback_clock_survives_same_destination_start
    Clock written before the admission result is checked callback_zero_duration_survives_rejection, callback_long_duration_survives_rejection
    Never restart the clock when already active callback_clock_restarts_for_new_destination
    No clock write on the unchanged-slot path null_destination_start_restarts_clock (progress 1.45175463e-08, expected 1)
    obs_transition_video_render2 reads the clock before the lock render_during_admission_keeps_new_transition (2 of 2 runs, video_stop_signals=1)
    obs_transition_video_render_direct reads the clock before the lock direct_render_during_admission_keeps_new_transition (3 of 3 runs OFF, 1 of 1 ON, video_stop_signals=1)
    obs_transition_get_time reads the clock without the lock timed_direct_render_during_admission_uses_new_clock (the earlier revision 1 above)
    Earlier preflight mutants (no self guard, immediate children only, preflight after the active reset) the empty-self, indirect and active-reuse cases
  • Fork CI: not run. Our self-hosted CI is down (see our note on #699), so this relies on upstream PR CI.

  • Real runs: not run. The test drives the public transition API with real rendering under Xvfb. No full OBS application session was run.

Compatibility & risk

No public API or ABI changes. The new helpers are static. Exported symbols are 1,766 with ENABLE_RUST_LIBOBS OFF and 1,766 with ON, and the two lists are identical. The transition code is C in both modes. There is no Rust implementation of these functions.

Behaviour changes:

  • A start whose destination contains the transition, including the transition itself, now returns false, logs a warning, and leaves the transition's state unchanged. Before, it deadlocked, or for dest == T returned true.

  • The two video render functions already took transition_mutex. The existing critical section now also covers the clock read, which is a few arithmetic operations and no calls.

  • obs_transition_get_time now takes transition_mutex for that read. A caller that already holds T's mutex would now deadlock. No libobs path does this. In the tree, the callers are:

    • the stinger's video_render (no transition lock held);
    • the frontend, on the UI thread;
    • obs-websocket's GetCurrentSceneTransitionCursor (RequestHandler_Transitions.cpp:262), on a request thread with no transition lock held;
    • the slideshows' next and previous media actions (obs-slideshow.c:543, :558, obs-slideshow-mk2.c:644, :672). These hold no lock. obs_source_media_next and obs_source_media_previous only queue an action, and process_media_actions (obs-source.c:1315-1357) runs it after releasing the queue's mutex, from obs_source_video_tick (:1408) on the graphics thread. The slideshow then calls obs_transition_start on the same transition, which takes the same lock, so the getter adds no new lock-order edge.

    The function is also exported to Lua and Python scripts (obslua.i:102, obspython.i:125), which can call it from frontend-event, hotkey, timer and source callbacks.

    Third-party code that runs while T's mutex is held would now hang if it called obs_transition_get_time(T). Code runs under T's mutex in these places:

    • The get_width and get_height of T's direct children, or of their first filters. recalculate_transition_size (:177-191) and recalculate_transition_matrix (:119-129) call them under the lock, from obs_transition_tick on every tick as well as after a start and on load.
    • Callbacks reached by the obs_source_add_active_child and obs_source_remove_active_child walks in set_source and activate_transition (:267-275, :332-344), in obs_transition_stop (:718-719) and in obs_transition_swap_begin (:1118-1125, which holds two transition locks). That includes the enum_active_sources or enum_all_sources of a source in T's tree, and a callback passed to an enumeration of T.
    • The last release of the old child in obs_transition_stop (:720). obs_source_destroy then runs synchronously, emits the source_filter_remove and filter_remove signals and calls the plugin's filter_remove callback (obs-source.c:3213-3220, reached from :782-783). The destroy signal itself is deferred (:801-809).

    Across threads, the hazard is wider than a single callback. Before this change, a thread holding a plugin or script lock L could call obs_transition_get_time(T) safely. Now it waits on T, and if T's holder is inside one of the callbacks above and needs L, the two threads deadlock. An in-tree route goes through Lua scripting: a script filter that defines get_width is the first filter on a scene that is the program transition's A or B. The graphics thread ticks, takes T, then calls the script's get_width, which waits for the script's mutex. Meanwhile one of the same script's callbacks on another thread holds that mutex and calls obs_transition_get_time(T), which blocks on T. The existing locked transition calls, such as obs_transition_start and obs_transition_get_active_source, have the same hazard on base, so this is a wider version of an existing class. The trigger is narrow, and no in-tree C code calls the getter while holding T's mutex.

  • The start time is sampled after destination admission instead of before it. For a large destination tree, the transition starts timing a little later. The difference is the length of the admission walk.

Known limit (unchanged from upstream): when a plugin's transition_start callback starts the same transition, and the outer start then completes, the transition keeps the nested start's mode, because the mode is written before the callback. This is documented in a code comment at obs-source-transition.c:413-415. Changing it would be a separate change.

Not tested: macOS and Windows (the test is Linux-only), ASan/LeakSanitizer, concurrent graph changes from other threads, and graphs that were already cyclic before the start.

Status

Status: draft. Opened so upstream PR CI can run it.

How this was tested

  • RED → GREEN: test_transition_recursive_destination fails on the RED commit, whose libobs sources are identical to master, and passes on GREEN. Built locally on x86-64 Linux (Debian container, GCC, RelWithDebInfo, -Werror) with ENABLE_RUST_LIBOBS both OFF and ON, and run under Xvfb with software GL. No sanitizer flags were used. CI builds the test with its own flags.
  • Our own CI: not run. Our self-hosted CI is down (see our note on #699), so this relies on upstream PR CI.
  • Real runs: not applicable yet. The test exercises the public transition API with real rendering, but OBS itself was not run.

Thank you to the obs-rust maintainers and contributors for building this project in the open. In the American spirit of free expression and individual independence, and with the principle of judging contributions on their merit alone, this PR is a small piece of what independent people can build when they come together.

@zackees
zackees marked this pull request as ready for review October 14, 2026 23:10
@zackees
zackees self-requested a review as a code owner October 14, 2026 23:10
@zackees
zackees merged commit 1048d20 into obs-rust:master Oct 14, 2026
22 checks passed
vpacher pushed a commit to vpacher/obs-studio that referenced this pull request Oct 26, 2026
…rust#2478)

* libobs: Move the transition start decisions

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: Characterize the transition start checks

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

* obs-source: Test the transition_start port

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

* obs-source: Port the transition start checks

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

* obs-source: Check transition_start against the C

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

* docs: Record the transition start port

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
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.

2 participants