Skip to content

libobs: Move the transition settings and slots - #3537

Merged
rdoupe merged 7 commits into
masterfrom
fix/rust-port-transition-field-seam-550
Nov 3, 2026
Merged

rdoupe merged 7 commits into
masterfrom
fix/rust-port-transition-field-seam-550

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Refs #3528
Refs #3529
Refs #3530
Fixes #3528
Fixes #3529
Fixes #3530

What and why

Three steps of "Extracting a function before porting it" for the rest of libobs/obs-source-transition.c.h, batched in one PR because the last two use the first. There is no Rust and no change in behaviour; the ports of the settings and the child slots to rust/obs-source come next, each in its own PR.

  1. The transition field seam (rust: Port the transition field seam (obs-source-transition.c) #3528), the "internal accessors or adapter seams" step that "Public and internal boundaries" asks for before stateful code is ported (Phase 6 tracker meta: Phase 6 libobs core migration through opaque C seams #444):
    • transition_valid(), transition_active() and valid_scale_type() move into the new libobs/obs-source-transition-seam.c.h with their bodies unchanged. They lose only static inline, so the other transition files of the group can call them.
    • The seam then gets one get and one set per transition field of struct obs_source, and lock, unlock and trylock of transition_mutex and transition_tex_mutex. Each is one field read or write, a matrix4_copy() for the matrices, or one pthread_mutex_*() call returning its result. Nothing calls them yet: the ports will reach the fields through them without the struct layout.
    • The private header libobs/obs-source-transition-seam.h is in libobs.pch.h with the other transition headers. It is marked "private adapter, not a new public API", and nothing in it is EXPORT.
  2. The transition settings (rust: Move the transition settings out of obs-source-transition.c #3529): obs_transition_is_active(), the scale type, alignment and size setters and getters, obs_transition_save(), obs_transition_enable_fixed() and obs_transition_fixed() (ten functions) move verbatim into libobs/obs-source-transition-settings.c.h.
  3. The child slots (rust: Move the transition child slots out of obs-source-transition.c #3530): obs_transition_clear(), obs_transition_enum_sources(), copy_source_state(), obs_transition_swap_begin() and obs_transition_swap_end() move verbatim into libobs/obs-source-transition-slots.c.h. The swap still takes the texture locks in begin and drops them in end, source before destination.

All three files are live C in libobs.core-source, ahead of obs-source-transition.c.h, as effect-parser-lifecycle-adapter.c.h is in libobs.graphics. The settings and slots files each have their own copy of the lock macros they use, #undef'd at their end (BUILD.md rule 5). No other file of the group defines the moved names.

Characterization. Each move gets a test first. The tests create transitions through the real libobs (core video, so Linux under Xvfb, like the other transition tests). Odd behaviour is pinned as it is.

  • test_source_transition_settings (10 cases):

    • each getter after each setter, and a new transition's values;
    • the defaults for NULL and for an input;
    • out-of-range scale types;
    • obs_transition_is_active() up to obs_transition_set() or obs_transition_clear(). obs_transition_force_stop() only signals and leaves it transitioning (characterized, not endorsed);
    • the six transition_ keys obs_transition_save() writes (through obs_save_source(), since it isn't exported): "" with no child, slot B while transitioning, slot A again once it ends.
  • test_source_transition_slots (9 cases), watching each child's last reference through a weak reference:

    • clear empties both slots and drops both references;
    • enum_sources reports slot A, then slot B, and skips an empty slot;
    • between begin and end both transitions hold both children. After end only the new one holds them, running as the old one was, and what it held before is dropped;
    • a swap with itself does nothing;
    • the new transition, held in a slot of the old one, isn't stored in itself;
    • the render targets: after the swap the new transition draws its children into the same two textures the old one drew into;
    • the auto clock: the new transition reads the old one's time at the same video time;
    • the manual state: mode, value and target are handed over (the value stays at 0.25 over the following ticks, where a target left at 0 would snap it to 0). The clock cases wait for the tick they need, not a fixed time.

    Each of the last three fails in the real libobs when its field is dropped from the swap (the texrender exchange, start_time, manual_val, manual_target, the mode).

Checked against origin/master's functions. A scratch harness (not committed) extracts master's 18 functions, with the lock macros, and the three new files whole. It builds each as its own program over one logging stand-in for struct obs_source and every call they make. That covers the validity checks, the scripted obs_source_add_active_child() results, refs and releases, active children, obs_data writes, the logs, each lock and trylock (scripted results) and the enum callback. Each call logs its arguments, and the program dumps every field of six sources after each call. The logs of 20,000 rounds of 12 random calls (240,000 calls; random fields, sizes, scale types from the edges of int64_t, special floats, self-held slots and same-pair swaps) are byte-identical under gcc and clang at -O0, at -O2, and at -O1 with ASan and UBSan.

Across compilers, the two obs_source_get_name() arguments of copy_source_state()'s blog() evaluate in either order (unspecified in C), so the logs are compared per compiler. The new build also checks each accessor: its get returns what its set stored, it changes only its own field, and each lock wrapper holds only its own mutex.

All 21 planted mutants are caught:

  • || to && in transition_active();
  • the type check dropped;
  • the scale type unchecked;
  • is_active reading only the video flag;
  • get_alignment and get_size defaults changed;
  • save writing cx as cy, or outside the lock;
  • the fixed duration changed;
  • clear keeping the audio flag or releasing one slot;
  • enum order reversed;
  • the refused copy keeping its active flag;
  • the swap dropping manual_target, inverting the texture locks, keeping the source's textures or skipping the clear;
  • four accessor mutants, caught by the accessor check.

Two of these planted in the real libobs (enum order, save cx/cy) also fail the new C tests.

Field inventory (accesses at this PR's head; the plan asks for it here and on #444). Outside the transition files, libobs only reads transitioning_audio and transitioning_video (obs-scene.c.h 176) and transition_actual_cx and transition_actual_cy (obs-source.c.h 2264 and 2286). The seam's two accesses per field are its get and set.

Field Users (accesses per file)
transition_sources obs-source-transition.c.h 26, obs-source-transition-seam.c.h 2, obs-source-transition-settings.c.h 1, obs-source-transition-slots.c.h 7
transition_source_active obs-source-transition.c.h 13, obs-source-transition-seam.c.h 2, obs-source-transition-slots.c.h 5
transitioning_video obs-scene.c.h 1, obs-source-transition.c.h 15, obs-source-transition-seam.c.h 3, obs-source-transition-slots.c.h 2
transitioning_audio obs-scene.c.h 1, obs-source-transition.c.h 15, obs-source-transition-seam.c.h 3, obs-source-transition-slots.c.h 2
transition_mode obs-source-transition.c.h 7, obs-source-transition-seam.c.h 2, obs-source-transition-settings.c.h 1, obs-source-transition-slots.c.h 1
transition_manual_val obs-source-transition.c.h 7, obs-source-transition-seam.c.h 2, obs-source-transition-slots.c.h 1
transition_manual_target obs-source-transition.c.h 5, obs-source-transition-seam.c.h 2, obs-source-transition-slots.c.h 1
transition_manual_torque obs-source-transition.c.h 3, obs-source-transition-seam.c.h 2
transition_manual_clamp obs-source-transition.c.h 2, obs-source-transition-seam.c.h 2
transition_start_time obs-source-transition.c.h 3, obs-source-transition-seam.c.h 2, obs-source-transition-slots.c.h 1
transition_duration obs-source-transition.c.h 3, obs-source-transition-seam.c.h 2, obs-source-transition-slots.c.h 1
transition_cx obs-source-transition.c.h 3, obs-source-transition-seam.c.h 2, obs-source-transition-settings.c.h 3
transition_cy obs-source-transition.c.h 3, obs-source-transition-seam.c.h 2, obs-source-transition-settings.c.h 3
transition_actual_cx obs-source.c.h 1, obs-source-transition.c.h 2, obs-source-transition-seam.c.h 2
transition_actual_cy obs-source.c.h 1, obs-source-transition.c.h 2, obs-source-transition-seam.c.h 2
transition_alignment obs-source-transition.c.h 3, obs-source-transition-seam.c.h 2, obs-source-transition-settings.c.h 3
transition_scale_type obs-source-transition.c.h 2, obs-source-transition-seam.c.h 2, obs-source-transition-settings.c.h 3
transition_use_fixed_duration obs-source-transition.c.h 1, obs-source-transition-seam.c.h 2, obs-source-transition-settings.c.h 2
transition_fixed_duration obs-source-transition.c.h 1, obs-source-transition-seam.c.h 2, obs-source-transition-settings.c.h 1
transition_matrices obs-source-transition.c.h 6, obs-source-transition-seam.c.h 2
transition_texrender obs-source-transition.c.h 13, obs-source-transition-seam.c.h 2, obs-source-transition-slots.c.h 4
transition_mutex obs-source-transition.c.h 5, obs-source-transition-seam.c.h 3, obs-source-transition-settings.c.h 2, obs-source-transition-slots.c.h 2
transition_tex_mutex obs-source-transition.c.h 6, obs-source-transition-seam.c.h 3, obs-source-transition-slots.c.h 2

No upstream issue.

RED → GREEN

  • RED commit: N/A. These are the policy's "Extracting a function before porting it" steps: a behaviour-neutral change with no Rust, under unchanged C tests. No test can fail before a verbatim move or before accessors that nothing calls, so each issue has a characterization commit (pinning the current C) and then its move, instead of a RED and GREEN pair. The RED and GREEN pairs come with the ports. The characterization tests (f48febdc0, 37aaffdf8, a40f94631) pass on origin/master's C.
  • GREEN: runs were on a40f94631.
    • The 24 transition tests (test_transition_* with their _rust twins, test_group_hide_transition_audio, and the two new tests) pass on the C build (19 tests), the hybrid libobs (24) and libobs-c-reference (24), with no case skipped, under a private Xvfb. The new tests run 10 and 9 cases on each. Once, under -j4, test_transition_removed_child_audio skipped its stop_tick_ignores_removed_child case on the C build (its own guard for when the video thread stops the transition first); alone it passed 3 of 3.
    • The exported symbol sets are identical on the C, hybrid and C reference builds after every commit, and identical to master's (1767). The three helpers and the 48 accessors are local (t).
    • Local gates: --test-diff origin/master passed (workspace: 6344 passed, 6 skipped).
    • --lane lint passed every check but the Dylints, and --lane cross passed its MSVC clippy but not its Dylints. This machine has no Dylint driver for the nightly master pinned on 2026-11-02, and building one fails. This PR changes no Rust.
  • Real app (UI, protocol output or logging changes): not applicable, no behaviour change.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (N/A for docs-only; a focused CI fix may push RED and GREEN together) (characterization, then each move; no RED, as nothing changes behaviour)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite (not stamped: the Dylint step can't run on this machine)
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports) (not applicable: no port, no difference)

transition_valid(), transition_active() and valid_scale_type() move
from obs-source-transition.c into obs-source-transition-seam.c, the
private seam between the transition code and the transition fields of
struct obs_source. Their bodies are unchanged; they lose only `static
inline`, so the transition settings and child slot files that move out
next can call them. obs-source-transition-seam.h declares them, hidden
in libobs (not EXPORT), and libobs.pch.h includes it with the other
transition headers.

The seam is live C in libobs.core-source, ahead of the transition
file, as effect-parser-lifecycle-adapter.c is in libobs.graphics. No
other file of the group defines these names.

No behaviour change: the export sets of the C, hybrid and C reference
builds are unchanged (1767), with the three functions local.

Refs #3528.
The seam gets one get and one set per transition field of struct
obs_source that the transition code reads or writes (the two slots and
their active flags, the video and audio flags, the clock and manual
fields, the sizes, alignment, scale type, fixed duration, matrices and
texrenders), and lock, unlock and trylock of transition_mutex and
transition_tex_mutex. Each is a single field read or write, a
matrix4_copy() for the matrices, or a single pthread_mutex_*() call
returning its result; none checks its arguments or takes a lock of its
own.

They let the later ports of the transition settings and child slots to
rust/obs-source reach the fields without the struct layout. Nothing
calls them yet. Outside the transition file, libobs reads only
transitioning_audio and transitioning_video (obs-scene.c) and
transition_actual_cx and transition_actual_cy (obs-source.c); those
reads stay as they are.

The export sets of the C, hybrid and C reference builds are unchanged
(1767), with the 48 accessors local.

Refs #3528.
Characterization before the transition settings functions of
obs-source-transition.c (obs_transition_is_active(), the scale type,
alignment and size setters and getters, obs_transition_save() and the
fixed duration switch) move to their own file and are ported.
test_transition_scale_type pins the scale type through the drawn
matrix; nothing pinned the other getters after their setters, their
defaults, or what obs_transition_save() writes.

test_source_transition_settings creates transitions through the real
libobs. 10 cases pin:
- a new transition's values: aligned left and top, 0x0, MAX_ONLY, no
  fixed duration, not transitioning;
- each getter after each setter, any alignment and size stored as
  given, and out-of-range scale types stored as MAX_ONLY;
- the fixed duration switch on and off, with and without a duration;
- obs_transition_is_active() from the start until obs_transition_set()
  or obs_transition_clear() ends it; obs_transition_force_stop() only
  signals and leaves it transitioning (characterized, not endorsed);
- NULL and a source that is not a transition: the setters do nothing
  and the getters return their defaults (get_size zeroes both);
- the six transition_ keys obs_transition_save() writes (through
  obs_save_source(), as it is not exported): "" with no child, slot B
  while transitioning, A again once it ends, and each field read again
  on each save; the fixed duration is not saved.

Transitions need core video, so it builds on Linux only and runs
under xvfb-run, as the other transition tests; without a display the
cases skip. It passes on the C, hybrid and C reference builds.

Refs #3529.
obs_transition_is_active(), the scale type, alignment and size setters
and getters, obs_transition_save(), obs_transition_enable_fixed() and
obs_transition_fixed() move verbatim from obs-source-transition.c into
obs-source-transition-settings.c, ahead of their port to
rust/obs-source. They call the seam's transition_valid(),
transition_active() and valid_scale_type(). The file has its own copy
of lock_transition() and unlock_transition(), #undef'd at its end
(BUILD.md), and is live C in libobs.core-source, after the seam.

No behaviour change: every moved function's text is byte-identical to
origin/master's, the export sets of the C, hybrid and C reference
builds are unchanged (1767), and the transition tests, with
test_source_transition_settings, pass on all three.

Refs #3529.
Characterization before the child slots of obs-source-transition.c
(obs_transition_clear(), obs_transition_enum_sources() and the swap of
obs_transition_swap_begin(), copy_source_state() and
obs_transition_swap_end()) move to their own file and are ported.
test_transition_swap, test_transition_swap_active and
test_transition_swap_cycle pin the swap's running state and its
refusal of a cycle; nothing pinned what clear and enum_sources do with
the slots, or which transition holds a reference after a swap.

test_source_transition_slots creates transitions through the real
libobs and sees a child's last reference go through a weak reference.
6 cases pin:
- clear empties both slots, ends the transition and drops both
  references; clearing an empty transition, NULL or an input does
  nothing;
- enum_sources reports slot A, then slot B, with the transition as the
  parent, and skips an empty slot;
- the swap: between begin and end both transitions hold both children;
  the end clears the old one, so the new one holds the only
  references, running as the old one was;
- what the new transition held before the swap is dropped, and an
  empty slot of the old one empties the new one's;
- a swap of a transition with itself does nothing and returns;
- the new transition, held in a slot of the old one, is not stored in
  itself.

The swap is called as the frontend calls it, begin then end on the
same pair. Transitions need core video, so it builds on Linux only and
runs under xvfb-run; without a display the cases skip. It passes on
the C, hybrid and C reference builds.

Refs #3530.
obs_transition_clear(), obs_transition_enum_sources(),
copy_source_state(), obs_transition_swap_begin() and
obs_transition_swap_end() move verbatim from obs-source-transition.c
into obs-source-transition-slots.c, ahead of their port to
rust/obs-source. obs_transition_clear() calls the seam's
transition_valid(). The file has its own copy of lock_transition(),
unlock_transition(), lock_textures() and unlock_textures(), #undef'd
at its end (BUILD.md), and is live C in libobs.core-source, after the
settings file. The swap still takes the texture locks in begin and
drops them in end, source before destination.

No behaviour change: every moved function's text is byte-identical to
origin/master's, the export sets of the C, hybrid and C reference
builds are unchanged (1767), and the transition tests, with
test_source_transition_settings and test_source_transition_slots, pass
on all three.

Fixes #3528.
Fixes #3529.
Fixes #3530.
test_source_transition_slots checked the slots, references and the
running flags the swap hands over, but not the clock it copies in
obs_transition_swap_begin() or the render targets it exchanges in
obs_transition_swap_end(). Three more cases pin them through the real
libobs:
- the textures: render2 draws the old transition's children into two
  textures; after the swap the new transition draws into those same
  two;
- the auto clock: once a frame has come after the start, the new
  transition reads the same time as the old one at the same video
  time (read old, new, old, retried until no frame came in between);
- the manual state: a manual transition at 0.25 with a torque of 0 is
  handed over with its mode (saved), its value (read at once) and its
  target (the value stays 0.25 over the ticks that follow, where a
  target of 0 would snap it to 0).

The clock cases wait for the tick they need, not a fixed time. Each
case fails when its field is left out of the swap in libobs (the
texrender exchange, start_time, manual_val, manual_target, the mode),
and all 9 cases pass on the C, hybrid and C reference builds.

Fixes #3528.
Fixes #3529.
Fixes #3530.
@rdoupe
rdoupe marked this pull request as ready for review November 3, 2026 07:58
@rdoupe
rdoupe requested a review from zackees as a code owner November 3, 2026 07:58
@rdoupe
rdoupe added this pull request to the merge queue Nov 3, 2026
Merged via the queue into master with commit 6476ead Nov 3, 2026
44 checks passed
@rdoupe
rdoupe deleted the fix/rust-port-transition-field-seam-550 branch November 3, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

1 participant