Repository navigation
obs-source: Port the transition load checks - #2602
Merged
Merged
Conversation
Behaviour-neutral extraction before the Rust port. The decisions of transition_valid(), valid_scale_type(), obs_transition_load(), copy_source_state(), obs_transition_swap_begin() and obs_transition_swap_end() in obs-source-transition.c.h move to libobs/obs-source-transition-load.c.h, as six functions on plain values declared in the new libobs/obs-source-transition-load.h without EXPORT (hidden, as -fvisibility=hidden keeps them): - _is_transition(): the type check of transition_valid(), after obs_ptr_valid(); - _scale_type(): valid_scale_type(), used by obs_transition_set_scale_type() and obs_transition_load(): 0, 1 and 2 as they are, any other int64_t Max Only; - _looks_up(): obs_transition_load() looks its saved source up only with a name; - _source() -> KEEP | NOT_FOUND | REFUSE: what the load does with the looked-up source after the add (the add only for a found source); - _swaps(): the swap of a transition with itself does nothing, in both swap_begin() and swap_end(); - _copy_stores(): copy_source_state() stores the new child unless it was to be added as an active child and the add failed. obs_transition_load()'s release of the old source A (#2584) asks obs_source_transition_start_child_active(), the rule copy_source_state() and obs_transition_set() already ask. Split per step, as #2153 did, so every call and read stays where it was and under its condition: obs_ptr_valid(), the locks and their order, the pointer comparisons, the obs_data reads at the top, the lookup, the add only for a found source or an active new child (the C's own &&), every obs_source_get_ref() and obs_source_release(), the active child calls, the (uint32_t) truncations of the loaded alignment and size, the mode taken as is, the fields the swap hands over, the texrender swap, recalculate_transition_size() and _matrices(), and the logs. The getters' answers for an invalid transition (Max Only, 0, 0x0 and false) stay C as the literals they are. The source type and the scale type cross as int; the header copies OBS_SOURCE_TYPE_TRANSITION and the three scale types, and obs-source-transition.c.h checks them and that enum obs_source_type is int-sized with _Static_assert (the scale type enum is already checked there). Checked in a scratch harness (not committed). It compiles origin/master's transition_valid(), valid_scale_type(), obs_transition_set_scale_type(), obs_transition_get_scale_type(), obs_transition_get_alignment(), obs_transition_get_size(), obs_transition_fixed(), obs_transition_load(), copy_source_state(), obs_transition_swap_begin() and obs_transition_swap_end() 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), obs_ptr_valid(), the obs_data reads, obs_get_source_by_name() (which may find nothing), obs_source_add_active_child() (which may fail), obs_source_remove_active_child(), obs_source_get_ref() (which may return NULL), obs_source_release(), obs_source_get_name(), blog(), obs_transition_clear() and the size and matrix recalculation. Another thread may write a source, a slot flag, the scale type, the fixed flag, the width or the video flag at any lock, unlock or call. Inputs: two transitions and four children of any source type (including values out of the enum), every slot empty or any child and active or not, no source, the transition swapped with itself or the other, names that are missing, unknown, a child or a transition, and loaded and set values at 0, 1, 2, 3, -1, 7, 255, 2^31, around 2^32, the ends of int64_t and random; one to four operations each. 5,800,000 runs: 2,000,000 each with GCC and Clang at -O2, 500,000 each at -O0, 300,000 each under ASan and UBSan with no recovery (GCC -O0, Clang -O2) and 200,000 with gcov. All 149,390,395 logged events match, as does the final state (every field, reference and active reference). Every branch of origin/master's functions is taken both ways. 24 deliberately broken moves were planted, and all 24 fail it: each function's rule inverted, widened or made constant (the type at >= 2, STRETCH dropped, the default ASPECT, the value's low bit, the lookup always or never, NOT_FOUND and REFUSE swapped or made KEEP, the swap always or for the same transition, the store rule as add_ok, !adds && add_ok, adds || add_ok and !adds), and at the call sites the add for a source not found, the add for an inactive or missing new child, the old source A removed when inactive, the type check on a constant, the scale type taken mod 3 and the lookup without a name. git blame on the moved lines shows the upstream commits 6839ff7 and a1fbf10, and the fork's #2080 (the scale type rule), #2513 (the swap refusal) and #2584 (the release of the old source A); 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 set is unchanged (1766 on the C backend); the six functions are local. Refs #2595.
test_transition_load_steps compiles libobs/obs-source-transition-load.c.h and libobs/obs-source-transition-start.c.h (ASan and UBSan) and calls only their functions through the two headers. 10 cases: - the header's copies of OBS_SOURCE_TYPE_TRANSITION and the three scale types, the enums' sizes and the source outcome values; - the type check: only 2, over -1000..1000 and the ends of int; - the scale type: 0, 1 and 2 as they are, anything else Max Only (3, -1, the ends of int32_t and int64_t, -1000..1000), compared in 64 bits (2^32 + 1 and 2^32 + 2 are Max Only, not Aspect or Stretch); - the load's lookup and source outcome, the swap gate and copy_source_state()'s store rule over every combination. obs_transition_load(), copy_source_state() with the swap, the getters and obs_transition_set_scale_type() are also copied onto a stand-in transition whose children count their references and active references and refuse an add to a transition they contain, to pin end to end: the loaded fields; a missing name (no lookup, no warning), an unknown or empty name (none and a warning), a known source (kept, one reference and one active reference), a source that contains the transition (released, none and a warning, and the old source A still goes out); a load onto a slot A that holds a source (taken back), the same source again and an inactive slot A (released without a removal); the swap with itself (nothing); all 32 slot states of the swap (old child present and active or not, new child present, active and contained or not), each child left with the right references and the refusal storing none, inactive; and the getters and the setter on a source of every type and on none. Characterized, not endorsed: - the loaded alignment, width and height are truncated to their low 32 bits: 2^32 + 5 loads as 5, -1 as UINT32_MAX, INT64_MIN as 0; - the loaded mode is kept as is: 7 stays 7. It is in the native test graph, in name order, with both headers as watch inputs. 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_load_release, test_transition_scale_type, test_transition_swap, test_transition_swap_active and test_transition_swap_cycle cover the callers. Refs #2595.
RED for the port of libobs/obs-source-transition-load.c.h to a new transition_load module of rust/obs-source, next to transition_clock, transition_render and transition_start. The safe core is a stub (todo!()): is_transition(), scale_type(), looks_up(), source() -> Source (Keep, NotFound, Refuse), swaps() and copy_stores(), with TYPE_TRANSITION and the scale types (taken from transition_clock). The plan sketched wider steps: load_fields() for the five loaded values, load_source(has_name, found, add_ok), release_old(), swap() and copy_slot(has_old, old_active, child_active, add_ok). The truncations and the mode stay C casts, so load_fields() comes down to scale_type(). load_source() and copy_slot() would take the add's result before the C knows whether it adds at all; so the lookup, the outcome after the add and the store rule are their own functions, and the C keeps its && before each add. release_old() is transition_start::child_active(), already ported, and the getters' defaults stay C literals. tests/source/transition_load.rs ports test_transition_load_steps 1:1: its 10 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 type check over -100,000..100,000, the ends of i32 and 2 with any other bit set; - the scale type at every power of two with its neighbours and negations, a stride over i64 and the ends, against origin/master's valid_scale_type(); - proptests (4,096 cases each): every decision over full-range values, and sequences of up to eleven loads (any name, any int64_t values), swaps, swap_begin()s and swap_end()s alone, scale type sets and getter reads on three transitions of any source type with children that may contain them, through the stand-in against a copy of the callers with origin/master's expressions inline; both end in the same state, and every child's references match the slots that hold it. soldr cargo test -p obs-data --test obs-tests-core -- source::transition_load passes 1 of 15 (the constants) and fails 14 with "not yet implemented". Refs #2595.
Ports libobs/obs-source-transition-load.c.h, the load, scale type and swap checks of obs-source-transition.c, to the transition_load module of rust/obs-source. obs-source-transition.c.h stays C around it: obs_ptr_valid(), the locks and the texture locks in their order, the pointer comparisons, the obs_data reads, obs_get_source_by_name(), the add only for a found source or an active new child, every obs_source_get_ref() and obs_source_release(), the active child calls, the (uint32_t) truncations and the mode taken as is, the fields the swap hands over, the texrender swap, the size and matrix recalculation, the getters' literals and the logs. The hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/transition_load.rs), six functions: - is_transition(): type == TYPE_TRANSITION (2); - scale_type(): 1 and 2 as Aspect and Stretch, any other i64 Max Only, matched on the whole i64 (2^32 + 1 is not Aspect); - looks_up(): has_name; swaps(): !same; - source() -> Source: NotFound without a source, Refuse when the add failed, else Keep; - copy_stores(): !adds || add_ok. TYPE_TRANSITION is the header's; the scale types are 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_load.rs): the six C signatures by value; the source type and the scale type result as int, the loaded scale type as int64_t, the outcome as the C's enum (u32, as source_transition_start returns its admission). 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-load (LIBOBS_PORTED_SOURCES), whose PCH is only obs-source-transition-load.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 six 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_load_steps still compiles the C file into itself, unchanged. The new test_transition_load_steps_rust builds the same test source against libobs_rust-static instead, as test_transition_start_steps_rust does, and links: the test includes the two headers and obs.h and calls only hidden functions. The 28 transition tests (test_transition_*, test_studio_mode_swap, test_studio_mode_exit, test_saved_transition, test_tbar_position, test_fade_to_color_mix, test_visibility_transition, test_stinger_media_duration, test_item_transition_empty_source, test_group_hide_transition_audio and test_slideshow_manual_end, with the _rust variants) pass on the C backend, the hybrid and libobs-c-reference. soldr cargo test -p obs-data --test obs-tests-core -- source::transition_load:: passes 15 of 15. No user-visible change, so no docs/features.md line. Refs #2595.
Tier 3 for the transition_load port. oracle/source_transition_load.c compiles the unmodified libobs/obs-source-transition-load.c.h with its six functions renamed to oracle_*, and exports the header's values and sizes by index. tests/source/transition_load_parity.rs gives each input to the oracle, the shim (the extern "C" function the hybrid links) and the core, and compares each bool as the C's byte (0 or 1, the same on both sides), the outcome as the C's enum value and each number exactly: - the header's values and the sizes of the outcome enum, bool and int; - every function of flags over every combination of them; - the type check over every int from -1,000,000 to 1,000,000, every 65,521st int, 2 with each other bit set and the ends; - the scale type over every value from -1,000,000 to 1,000,000, every power of two with its neighbours and negations, the 65,536 values either side of 2^32 and -2^32, the 65,536 at each end of int64_t and a stride over int64_t; - proptests (20,000 cases each) over any int type, any int64_t scale type and any flags. Nothing is excluded: the C has no undefined or host-dependent result here, and the port has no intentional difference. Mutation check: 23 mutants, all killed. 16 in the core (the type check at >= and !=, each scale type mapped wrong, the default Aspect, the value's low 32 bits matched, the lookup always or never, each source outcome inverted or swapped, the swap gate inverted or constant, and the store rule as add_ok, !adds && add_ok and adds || add_ok): Tier 1 and Tier 3 each kill all 16. 7 in the shims (a constant type, the scale type's low 32 bits, a constant lookup, the source and store arguments swapped, KEEP returned as REFUSE, the swap gate inverted): Tier 3 kills all 7 (Tier 1 calls only the core). Refs #2595.
rust/README.md gets the row for libobs/obs-source-transition-load.c.h (obs-source::transition_load), in sorted place: what moved, what stays C and why (every read and call at its point and under its condition, the add only under the C's own &&, the truncating casts, the swap's handover and the getters' literals), 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_load.rs runs 1024 loads over every combination of the flags the C reads, source types in and out of the enum and saved scale types at 0, 1, 2, 3, -1 and past 32 bits, each through the type check, the lookup, the source outcome and the scale type, then a swap's gate and the store rule of both slots, on the shims and on the oracle, and checks both checksums match. Release, x86_64 Linux, GCC, a loaded host, median per 1024 loads: Rust 16.99 us, C 16.72 us (1.02x), about 17 ns a load. The port changes nothing a user can see, so docs/features.md has no line. Fixes #2595.
rdoupe
force-pushed
the
fix/2545-test-cmocka-fix-transition-fixtu
branch
from
October 27, 2026 11:51
99af84c to
333209b
Compare
rdoupe
marked this pull request as ready for review
October 27, 2026 12:11
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.
Fixes #2595
What and why
Ports the load, scale type and swap checks left in
libobs/obs-source-transition.c.htorust/obs-source, as a new moduletransition_load, next totransition_clock,transition_renderandtransition_start. Every transition goes through them: each scene collection load, each Studio Mode swap, and every getter and setter that checks the source is a transition.transition_valid(): the type check afterobs_ptr_valid();valid_scale_type()(obs_transition_set_scale_type()andobs_transition_load()): 0, 1 and 2 as they are, any otherint64_tMax Only;obs_transition_load(): the saved source is looked up only with a name, and after the add it is kept, not found (warn) or refused for recursion (warn, release, none);copy_source_state(): the new child is stored unless it was to be added as an active child and the add failed;obs_transition_swap_begin()and_end(): a transition swapped with itself does nothing.The load's release of the old source A (#2584) asks
transition_start::child_active(), already ported.Split per step, as #2153 did. The plan sketched
load_fields(),load_source(has_name, found, add_ok),release_old(),swap()andcopy_slot(has_old, old_active, child_active, add_ok). The truncations and the mode stay C casts, soload_fields()comes down toscale_type();load_source()andcopy_slot()would take the add's result before the C knows whether it adds at all. So the lookup, the outcome after the add and the store rule are their own functions, and the C keeps its own&&before each add. Six functions cross the C ABI:obs_source_transition_load_is_transition(),_scale_type(),_looks_up(),_source()(KEEP,NOT_FOUNDorREFUSE, anenum obs_source_transition_load_outcome),_swaps()and_copy_stores().What stays C, at its point and under its condition:
obs_ptr_valid(); both mutexes and the texture mutexes in their order; the pointer comparisons; theobs_datareads at the top of the load;obs_get_source_by_name(); the add only for a found source or an active new child; everyobs_source_get_ref()andobs_source_release(); the active child calls; the(uint32_t)truncations of the loaded alignment and size and the mode taken as is; the fields the swap hands over; the texrender swap;recalculate_transition_size()and_matrices(); every log; the getters' answers for an invalid transition (Max Only, 0, 0x0, false), which are literals; and all of transition audio mixing, untouched.The header copies
OBS_SOURCE_TYPE_TRANSITIONand the three scale types, andobs-source-transition.c.hchecks them and thatenum obs_source_typeisint-sized with_Static_assert. No pointer crosses and no struct is mirrored.Six commits:
Move (behaviour-neutral): the decisions go to
libobs/obs-source-transition-load.c.h, declared in the newobs-source-transition-load.hwithoutEXPORT, so they are hidden. The file joinslibobs.core-source.git blameon the moved lines shows the upstream commits 6839ff7 and a1fbf10 and the fork's libobs: Treat an out-of-range transition scale type as Max Only #2080, libobs: Leave swapped slot empty on cycle #2513 and libobs: Release slot A in obs_transition_load #2584; they move as they are.The move was checked against the original code. A scratch harness (not committed) compiles origin/master's
transition_valid(),valid_scale_type(),obs_transition_set_scale_type(), the four getters,obs_transition_load(),copy_source_state(),obs_transition_swap_begin()and_end()verbatim next to this branch's and the moved file, as C++:obs_ptr_valid(), theobs_datareads, the lookup (which may find nothing), the add (which may fail), the removal,obs_source_get_ref()(which may return NULL),obs_source_release(), the names,blog(),obs_transition_clear()and the size and matrix recalculation;int64_tand random.5,800,000 runs (GCC and Clang
-O2, 2,000,000 each;-O0, 500,000 each; ASan with UBSan, no recovery, under GCC-O0and Clang-O2, 300,000 each; gcov, 200,000): all 149,390,395 logged events match on both sides, and so does the final state. Every branch of origin/master's functions is taken both ways.24 deliberately broken moves were tried, and all 24 fail the harness: each rule inverted, widened or made constant, and at the call sites the add for a source not found, the add for an inactive or missing new child, the old source A removed when inactive, the type check on a constant, the scale type taken mod 3 and the lookup without a name.
Characterization:
test_transition_load_steps, 10 cases. It compiles the moved file (and the start file, forchild_active()) with ASan and UBSan and calls only their functions: the header's values; the type check over -1000..1000 and the ends; the scale type at 0..3, -1, the ends ofint32_tandint64_t, 2^32 + 1 and 2^32 + 2 (Max Only: compared in 64 bits) and -1000..1000; every combination of the other four. It also copies the callers onto a stand-in transition whose children count their references and active references: the loaded fields, a missing, unknown, empty, known and recursive source, a load onto a filled slot A and an inactive one, the swap with itself, all 32 slot states of the swap, and the getters and setter on every source type.RED: Tier 1 against
todo!(). It ports the 10 C cases 1:1 and adds five edge tests: every flag combination; the type check over -100,000..100,000; the scale type at every power of two and a stride overi64; proptests over full-range values, and over sequences of loads, swaps, scale type sets and getter reads through the stand-in, against origin/master's expressions inline.GREEN: the safe core (six functions,
Source) and six#[no_mangle]shims, in a newlibobs.ported-source-transition-loadgroup whose PCH is only the new header.Tier 3: a C oracle of the unchanged file, the parity tests and a mutation check.
Docs: the README row, the crate's description,
lib.rs, and aport_comparisonbench module. The port changes nothing a user can see, sodocs/features.mdhas 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.scale_type()matches the wholei64, as the C'sswitchonint64_tdoes, so a saved 2^32 + 1 is Max Only, not Aspect.Bench (x86_64 Linux, GCC, release, not pinned to a core, a loaded host; median per 1024 loads, each through the type check, the lookup, the source outcome and the scale type, then a swap's gate and the store rule of both slots): Rust 16.99 µs, C 16.72 µs (1.02x), about 17 ns a load.
obs_transition_get_size()names itselfobs_transition_set_sizein its validity log.RED → GREEN
3a5e705ce(obs-source: Test the transition_load port).soldr cargo test -p obs-data --test obs-tests-core -- source::transition_load::: 1 passed (the constants, which are not stubs), 14 failed, each on atodo!()("not yet implemented").local_gate --lane lintwas clean on RED, and--test-diff origin/masterran 4644 tests: 4630 passed, 6 skipped, and only those 14 failed (runs were on99af84c15, the same RED but for one edge test that also checked 2 | 2 as a non-transition, fixed since).obs-source: Port the transition load checks): Tier 1 15/15.test_transition_load_stepspasses 10/10 on the C backend, on hybridlibobsand onlibobs-c-reference, andtest_transition_load_steps_rustpasses 10/10 against the Rust archive.test_transition_*,test_studio_mode_swap,test_studio_mode_exit,test_saved_transition,test_tbar_position,test_fade_to_color_mix,test_visibility_transition,test_stinger_media_duration,test_item_transition_empty_source,test_group_hide_transition_audioandtest_slideshow_manual_end, with the four_rustvariants) pass on all three, run through ctest under a private Xvfb with a fresh HOME, none skipped.libobs-c-reference.obs-source: Check transition_load against the C): 5/5, oracle, shims and core compared exactly (eachboolas the C's byte):boolandint;intfrom -1,000,000 to 1,000,000, a stride ofint, 2 with each other bit set and the ends;int64_t, and a stride ofint64_t;333209b55, on81f7d266e:./lint,local_gate --lane lintand--lane crosspass;./unittest's Rust lanes pass (4665 and 845 tests, 6 skipped);SOLDR_RUSTC_WRAPPER=none soldr cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets --locked -- -D warningsis clean; the CI unit checks (ci/test_build_groups.py,test_ported_sources.py,test_sorted_shared_lists.py,test_test_graph_sorted.py,test_naming.pyand the cmocka checks) pass; exported symbols are again 1766 and identical on all three builds, and the 28 transition tests pass on all three;77cdc73af, on8494808d6:--test-diff origin/masterpasses (4649 passed, 6 skipped), andsoldr cargo test -p obs-c-oracle --locked --bench port_comparisonpasses, thesource_transition_loadmodule included;81f7d266ethe bench test crashes in thegifmodule, master's own (bug: obs-c-oracle: port_comparison gif bench dereferences a NULL frame #2614), before it reaches this port's module.libobs(runs were on77cdc73af, on8494808d6), under a private Xvfb with a fresh HOME: 590/591. The one failure,test_source_monitor_only_load, timed out because that run pointed PulseAudio at no server; it passes alone on hybridlibobsandlibobs-c-referencewith the normal environment, and does not touch transitions. Skipped: the three hardware tests (test_pulse_default_follow,test_v4l2_vivid_replug,test_v4l2_vivid_stall).Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)