Repository navigation
libobs: Reject recursive transition destinations - #737
Merged
zackees merged 2 commits intoOct 14, 2026
Merged
Conversation
zackees
marked this pull request as ready for review
October 14, 2026 23:10
5 of 7 tasks
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Status: draft. Opened so upstream PR CI can run it. No issue has been opened. Branch
fix/transition-recursive-destinationis on the fork, two commits aboveupstream/masterat7cf6f3932e8706f363e2e6f38a91683354bb2b31:af07e1a04cb69cab18683ffce4f2ec6446b1274a—libobs: reject recursive transition destinations (RED)(tests only)8094e1fdb0297674b957b3eabbed02a7463d9d62—libobs: reject recursive transition destinations (GREEN)A merge against
upstream/masterata48a9a13d80d3ac5ded749093e6ac2a08855e189is clean.Problem
obs_transition_start(T, ..., dest)hangs forever whendestalready contains T. Examples: a nested transition whose source is T, a chain through another transition, or a plugin'stransition_startcallback that puts T intodestjust 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_startcallsset_source(libobs/obs-source-transition.c:371).set_sourcetakes T's non-recursivetransition_mutex(:231), then admits the destination throughactivate_transition→obs_source_add_active_child.obs_source_add_active_childwalks the destination's full tree (libobs/obs-source.c:4781).obs_transition_enum_sources(obs-source.c:4711-4712), which locks that transition's mutex (obs-source-transition.c:606).For
dest == T, admission refuses (parent == child), but the start still returns true and signalstransition_start.Fix
Reject recursion:
obs_transition_startwalks the destination and rejects it if T appears anywhere in it, or ifdest == T(obs-source-transition.c:386-395). This walk runs without T's mutex held, so it cannot deadlock.transition_startcallback 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.set_sourcenow returns the admission result.obs_transition_startreturns false and emits no start signal. The old B slot and its reference are kept (obs-source-transition.c:433-437).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 publicobs_transition_get_time(:541-543). Before, all three read it without the lock. A start publishes its clock under that lock, together with thetransitioning_*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_timefollowed byobs_transition_video_render_direct).obs_transition_audio_renderalready 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_timeandcalc_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_timeand itsobs_transition_video_render_direct, that frame can still draw the destination. Upstream has the same gap.Alternatives considered:
transition_mutexrecursive. That would avoid the hang, but it would also hide real cycles: a cyclic graph would recurse forever when rendering. Rejected.transition_startcallback can still create the cycle after the preflight. Rejected.Evidence
RED → GREEN:
test_transition_recursive_destinationis 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 intest/cmocka/tests.d/.On RED, built with
ENABLE_RUST_LIBOBSOFF 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):child terminated by signal 14 (transition start did not return).callback_clock_survives_same_destination_startreads progress7.723159e-09where it expects1.On GREEN, both modes:
Seven
ctestruns passed in each mode (logs for five were kept).Render races: three cases share one setup.
enum_active_sourcesis called during admission while T's mutex is held. It waits until the render thread has entered T'svideo_renderand is asleep, read from/proc/self/task/<tid>/stat. After enteringvideo_render, the render thread can only block on T's mutex.transition_video_stop.The cases differ in how T's
video_renderdraws, each the way a shipped transition does:video_renderrender_during_admission_keeps_new_transitionobs_transition_video_render(the built-in transitions)timed_direct_render_during_admission_uses_new_clockobs_transition_get_timepicks A or B, thenobs_transition_video_render_direct(the stinger without a track matte)direct_render_during_admission_keeps_new_transitionobs_transition_video_render_directalone (the stinger while its track matte is not ready)In the timed case the render thread waits inside
obs_transition_get_time, soobs_transition_video_render_direct's own clock read happens after the start. The direct-only case is the one that covers that read.first transitioning frame: seen=1 get_time=0.000000 -> target A.obs_transition_get_timewithout the lockget_time=1.000000 -> target Brender_during_admission_keeps_new_transitionfailed, 5 of 5 runs:video_stop_signals=1Mutation 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.
callback_clock_survives_same_destination_startcallback_zero_duration_survives_rejection,callback_long_duration_survives_rejectioncallback_clock_restarts_for_new_destinationnull_destination_start_restarts_clock(progress1.45175463e-08, expected1)obs_transition_video_render2reads the clock before the lockrender_during_admission_keeps_new_transition(2 of 2 runs,video_stop_signals=1)obs_transition_video_render_directreads the clock before the lockdirect_render_during_admission_keeps_new_transition(3 of 3 runs OFF, 1 of 1 ON,video_stop_signals=1)obs_transition_get_timereads the clock without the locktimed_direct_render_during_admission_uses_new_clock(the earlier revision 1 above)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 withENABLE_RUST_LIBOBSOFF 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 == Treturned 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_timenow takestransition_mutexfor that read. A caller that already holds T's mutex would now deadlock. No libobs path does this. In the tree, the callers are:video_render(no transition lock held);GetCurrentSceneTransitionCursor(RequestHandler_Transitions.cpp:262), on a request thread with no transition lock held;obs-slideshow.c:543,:558,obs-slideshow-mk2.c:644,:672). These hold no lock.obs_source_media_nextandobs_source_media_previousonly queue an action, andprocess_media_actions(obs-source.c:1315-1357) runs it after releasing the queue's mutex, fromobs_source_video_tick(:1408) on the graphics thread. The slideshow then callsobs_transition_starton 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:get_widthandget_heightof T's direct children, or of their first filters.recalculate_transition_size(:177-191) andrecalculate_transition_matrix(:119-129) call them under the lock, fromobs_transition_tickon every tick as well as after a start and on load.obs_source_add_active_childandobs_source_remove_active_childwalks inset_sourceandactivate_transition(:267-275,:332-344), inobs_transition_stop(:718-719) and inobs_transition_swap_begin(:1118-1125, which holds two transition locks). That includes theenum_active_sourcesorenum_all_sourcesof a source in T's tree, and a callback passed to an enumeration of T.obs_transition_stop(:720).obs_source_destroythen runs synchronously, emits thesource_filter_removeandfilter_removesignals and calls the plugin'sfilter_removecallback (obs-source.c:3213-3220, reached from:782-783). Thedestroysignal 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 definesget_widthis 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'sget_width, which waits for the script's mutex. Meanwhile one of the same script's callbacks on another thread holds that mutex and callsobs_transition_get_time(T), which blocks on T. The existing locked transition calls, such asobs_transition_startandobs_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_startcallback 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 atobs-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
test_transition_recursive_destinationfails on the RED commit, whose libobs sources are identical tomaster, and passes on GREEN. Built locally on x86-64 Linux (Debian container, GCC, RelWithDebInfo,-Werror) withENABLE_RUST_LIBOBSboth OFF and ON, and run under Xvfb with software GL. No sanitizer flags were used. CI builds the test with its own flags.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.