Skip to content

libobs: Move transition sizing, load and getters - #3588

Merged
rdoupe merged 7 commits into
masterfrom
fix/rust-port-extract-transition-siz-574
Nov 3, 2026
Merged

rdoupe merged 7 commits into
masterfrom
fix/rust-port-extract-transition-siz-574

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Refs #3580
Refs #3581
Refs #3582
Fixes #3580
Fixes #3581
Fixes #3582

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: same file, same unity group, and the load calls the sizing helpers. There is no Rust and no change in behaviour; the ports to rust/obs-source / obs-source-seam come next.

  1. The transition sizing and tick (rust: Port the transition sizing and tick (move them out of obs-source-transition.c) #3580):
    • get_cx(), get_cy(), recalculate_transition_matrices() and recalculate_transition_size() lose static (and inline) and become transition_get_cx(), transition_get_cy(), transition_recalculate_matrices() and transition_recalculate_size(), so the rest of the transition code can still call them once they move. The bare names would risk a clash in the unity group; nothing else in libobs defines the new ones. Renaming the callers is the only change to them.
    • The private header libobs/obs-source-transition-size.h declares them. It is marked "private adapter, not a new public API", nothing in it is EXPORT, and libobs.pch.h includes it after the seam header.
    • The add_alignment() declaration, the four helpers, recalculate_transition_matrix() and obs_transition_tick() then move verbatim into libobs/obs-source-transition-size.c.h.
  2. The transition load (rust: Port obs_transition_load (move it out of obs-source-transition.c) #3581): obs_transition_load() moves verbatim into libobs/obs-source-transition-restore.c.h. The ported rules already have obs-source-transition-load.c.h, so this file is -restore.
  3. The transition getters and manual controls (rust: Port the transition source getters and manual controls (move them out of obs-source-transition.c) #3582): obs_transition_get_source(), obs_transition_get_active_source(), obs_transition_set_manual_torque() and obs_transition_set_manual_time() move verbatim into libobs/obs-source-transition-access.c.h. obs_transition_set_manual_time() still calls obs_transition_set(), which stays behind.

All three files are live C in libobs.core-source, ahead of obs-source-transition.c.h, in the group's sorted order. Each has its own copy of the lock macros it uses, #undef'd at its end (BUILD.md rule 5). obs-source-transition.c.h loses 229 lines.

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). Each case that depends on the graphics thread's tick waits for the frame that shows what it checks, with a 5 s bound that only turns a hang into a failure. The same goes for a source's last reference: the graphics thread holds one on every source while it ticks them, so a check that a source is gone waits for its weak reference to expire. Odd behaviour is pinned as it is.

  • test_source_transition_size (4 cases):

    • the actual size (obs_source_get_width() / _height()): the larger width and the larger height of the two children, 0x0 with none. A start sets it at once, obs_transition_set() leaves it to the next tick, and each tick follows a child's resize and an emptied slot;
    • a size set with obs_transition_set_size() is the size the render2 callback gets, one dimension at a time, while obs_source_get_width() still reports the children's size (characterized, not endorsed);
    • each slot's matrix, rebuilt by the tick from the child's size, the scale type and the alignment;
    • the manual value at each tick: snapped with a torque of 0, stepped with a torque, and at the target in one tick when the clamp is larger than the step.
  • test_source_transition_restore (7 cases), through obs_load_sources(), since the load is not exported:

    • each field written from the saved data;
    • a missing key writes 0, so the alignment becomes OBS_ALIGN_CENTER and not a new transition's left and top, and the missing name "" is looked up and logged as not found (characterized, not endorsed);
    • out-of-range scale types load as MAX_ONLY, and the alignment, mode and size are cast as they are;
    • a found source becomes slot A's active child (a shown transition shows it, and its clear takes it back);
    • a missing source is logged and leaves slot A empty;
    • the transition named as its own slot A is refused with both warnings, and its reference is given back;
    • the source slot A held before the load is released either way.
  • test_source_transition_access (6 cases):

    • each getter's slot, and the reference it returns, seen through a weak reference;
    • the active source while idle, while running in auto or manual mode, and after obs_transition_set();
    • NULL logs at debug level, and get_active_source logs under "obs_transition_get_source" (characterized, not endorsed). A non-transition gives NULL with no log line;
    • the torque and clamp the tick uses, each call replacing both;
    • the reset to slot A at a manual time of 0 or -0, and not at 0.5, 1, NaN, or 0 in auto mode.

    The two setters are only called on transitions, since neither checks its argument (characterized, not endorsed). Their port fixes that and the log name.

Checked against origin/master's functions. A scratch harness (not committed) extracts master's eleven moved 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: the clock, fit, offset, load and start rules, the child size reads, the matrix calls, add_alignment(), calc_torquef(), the texrender resets, the obs_data reads, the lookup, scripted obs_source_add_active_child() results, refs and releases, transition_valid(), obs_transition_set(), the logs, and each lock and trylock (scripted results). 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) are byte-identical under gcc and clang at -O0, at -O2, and at -O1 with ASan and UBSan. The random inputs cover special floats, sizes up to UINT32_MAX, int64_t edges for every loaded key, a NULL or missing name, and empty and self-held slots. Under clang's UBSan both builds report the same float-to-int cast of the matrix offset for a transition wider than INT_MAX, at the same moved line. That is master's behaviour, and it moves unchanged.

All 25 planted mutants are caught by the harness, in:

  • get_cx and the fold;
  • the slot each matrix reads, and slot B's matrix;
  • the offsets, and the lock on the matrix and empty-slot paths;
  • the snap value and the texture trylock;
  • each loaded field, slot A's active flag and the lock;
  • the old and refused sources' releases;
  • the getters' slot, reference and active test;
  • torque and clamp;
  • the reset slot and the manual target;
  • the log name.

Nine of them, planted in the real libobs, also fail the new C tests.

The move commits are byte-identical to the text they replace (checked with diff on each).

RED → GREEN

  • RED commit: none, by design. Each issue is a behaviour-neutral move: testing-policy.md's "Extracting a function before porting it" step, a separate commit with no Rust and no behaviour change, whose proof is that the unchanged C tests pass. The characterization tests pin current C behaviour, so they pass before the move as well ("Characterization tests for units without C tests"). There is no failing state to commit. Each issue's pair is its characterization test, then its move. RED and GREEN come in the ports that follow, as with the settings and slots moves (libobs: Move the transition settings and slots #3537).
  • GREEN: runs were on 3761cdb.
    • The transition tests, with the three new ones, pass on all three builds: C (25/25), hybrid (30/30) and libobs-c-reference (30/30), under Xvfb with none skipped.
    • The export sets of the C, hybrid and C reference builds are unchanged (1767). obs_transition_load() and the four sizing helpers are local (t).
    • Local gate, --test-diff origin/master: the workspace's 6432 nextest tests passed (6 skipped) and the doctests passed.
    • Local gate, --lane lint and --lane cross: clang-format, gersemi, ruff, the 343 ci/test_*.py checks, rustfmt, every clippy run, and the MSVC cross clippy all pass. The Dylint step didn't run locally because this machine has no Dylint driver for the pinned nightly, so PR CI runs it. No Rust changed.
    • ./unittest passed, Tier 2 in Docker included (714/714). The Windows --all-targets clippy passed. The head is unstamped because the stamp's lint lane stops at the same Dylint step, so PR CI runs the full suite.
  • Real app (UI, protocol output or logging changes): N/A, 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). Here: the characterization test, then the move, for each issue; no RED, see above.
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

Characterization before the transition sizing and tick of
obs-source-transition.c (get_cx(), get_cy(), the matrix and size
recalculations and obs_transition_tick()) move to their own file and
are ported. test_transition_scale_type pins the matrix of each scale
type as a start builds it; nothing pinned the actual size, the render
size, what the tick rebuilds or how it moves the manual value.

test_source_transition_size creates transitions through the real
libobs. 4 cases pin:
- the actual size (obs_source_get_width() and _height()): the larger
  width and the larger height of the children, 0x0 with none, at once
  after a start, at the next tick after obs_transition_set(), and
  following a child's resize and an emptied slot at each tick;
- a size set with obs_transition_set_size() is the size the render2
  callback gets, one dimension at a time, while obs_source_get_width()
  still reports the children's size (characterized, not endorsed);
- each slot's matrix, rebuilt by the tick from the child's size, the
  scale type and the alignment;
- the manual value at each tick: snapped to the target with a torque
  of 0, stepped towards it with a torque, and at the target in one
  tick when the clamp is larger than the step.

Each case waits for the tick it needs, not a fixed time. 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 #3580.
get_cx(), get_cy(), recalculate_transition_matrices() and
recalculate_transition_size() of obs-source-transition.c lose static
(and inline) and become transition_get_cx(), transition_get_cy(),
transition_recalculate_matrices() and transition_recalculate_size(),
so the sizing file that moves out next can define them and the rest of
the transition code can call them. The bare names would risk a clash
in the unity group; no other file of libobs defines the new ones.

obs-source-transition-size.h declares them, hidden in libobs (not
EXPORT), and libobs.pch.h includes it after the seam header. Renaming
the callers is the only change to them; the bodies are unchanged.

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

Refs #3580.
The add_alignment() declaration, transition_get_cx(),
transition_get_cy(), recalculate_transition_matrix(),
transition_recalculate_matrices(), transition_recalculate_size() and
obs_transition_tick() move verbatim from obs-source-transition.c into
obs-source-transition-size.c, ahead of their port to rust/obs-source.
The file has its own copy of lock_transition(), unlock_transition(),
trylock_textures() and unlock_textures(), #undef'd at its end
(BUILD.md), and is live C in libobs.core-source, after the seam.

No behaviour change: every moved line is byte-identical to the
previous commit's, the export sets of the C, hybrid and C reference
builds are unchanged (1767), with the four helpers local, and the
transition tests, with test_source_transition_size, pass on all
three.

Refs #3580.
Characterization before obs_transition_load() of
obs-source-transition.c moves to its own file and is ported.
test_transition_scale_type pins the loaded scale type and
test_transition_load_release the release of slot A's old source while
the transition is shown; nothing pinned the other fields it writes,
the keys it reads as 0, or the three outcomes of its lookup.

test_source_transition_restore loads transitions with
obs_load_sources(), as a scene collection does (the load is not
exported), through the real libobs. 7 cases pin:
- each field written from saved data, read back through the getters
  and obs_save_source(), slot A, and the actual size from its child at
  once;
- a key the data does not hold writes 0: the alignment becomes
  OBS_ALIGN_CENTER rather than a new transition's left and top, and
  the missing name "" is looked up and logged as not found
  (characterized, not endorsed);
- a scale type outside the enum (3, -1, the int64 limits) loads as
  MAX_ONLY, and the alignment, mode and size are cast as they are
  (characterized, not endorsed);
- a found source goes into slot A as an active child: a shown
  transition shows it, and its clear takes it back;
- a missing source is logged and slot A stays empty;
- the transition named as its own slot A is refused with a log, and
  the reference its lookup took is given back;
- the source slot A held before the load is released, whether the
  load puts a source there or not.

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 #3581.
obs_transition_load() moves verbatim from obs-source-transition.c into
obs-source-transition-restore.c, ahead of its port to rust/obs-source
(obs-source-transition-load.c is taken by its ported rules). It calls
the seam's valid_scale_type() and the sizing file's
transition_recalculate_size() and transition_recalculate_matrices().
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, ahead of the seam.

No behaviour change: every moved line is byte-identical to the
previous commit's, the export sets of the C, hybrid and C reference
builds are unchanged (1767), with obs_transition_load() local, and the
transition tests, with test_source_transition_restore, pass on all
three.

Refs #3581.
Characterization before obs_transition_get_source(),
obs_transition_get_active_source(), obs_transition_set_manual_torque()
and obs_transition_set_manual_time() of obs-source-transition.c move
to their own file and are ported. Other transition tests call the
getters along the way and see the manual value move; nothing pinned
the references the getters return, their refusals, or when a manual
time ends the transition.

test_source_transition_access creates transitions through the real
libobs, and sees a child's last reference go through a weak reference.
6 cases pin:
- obs_transition_get_source() for slot A and B, NULL for an empty
  slot, each a new reference of its own;
- obs_transition_get_active_source(): A while idle, B while the
  transition runs in auto or manual mode, the given source once
  obs_transition_set() ends it, again a reference of its own;
- NULL gives NULL and a debug line, which get_active_source logs under
  "obs_transition_get_source" (characterized, not endorsed); a source
  that is not a transition gives NULL with no line;
- the torque and clamp the tick moves the manual value with, each
  call replacing both;
- a manual time of 0 or -0 in manual mode ends the transition on slot
  A; 0.5, 1, NaN, or 0 in auto mode do not.

The setters are called on transitions only, as neither checks its
argument (characterized, not endorsed). 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 #3582.
obs_transition_get_source(), obs_transition_get_active_source(),
obs_transition_set_manual_torque() and
obs_transition_set_manual_time() move verbatim from
obs-source-transition.c into obs-source-transition-access.c, ahead of
their port to rust/obs-source. The getters call the seam's
transition_valid(); obs_transition_set_manual_time() still calls
obs_transition_set(), which stays in obs-source-transition.c. 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,
ahead of the seam.

No behaviour change: every moved line is byte-identical to the
previous commit's, the export sets of the C, hybrid and C reference
builds are unchanged (1767), and the transition tests, with
test_source_transition_size, test_source_transition_restore and
test_source_transition_access, pass on all three.

Fixes #3580.
Fixes #3581.
Fixes #3582.
@rdoupe
rdoupe requested a review from zackees as a code owner November 3, 2026 21:03
@rdoupe
rdoupe added this pull request to the merge queue Nov 3, 2026
Merged via the queue into master with commit 83d524e Nov 3, 2026
43 checks passed
@rdoupe
rdoupe deleted the fix/rust-port-extract-transition-siz-574 branch November 3, 2026 21:46
@rdoupe rdoupe mentioned this pull request Nov 7, 2026
5 of 7 tasks
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