Skip to content

obs-core: port obs-view to Rust (#1933) - #1935

Merged
zackees merged 4 commits into
masterfrom
port/1933-view
Oct 23, 2026
Merged

zackees merged 4 commits into
masterfrom
port/1933-view

Conversation

@zackees

@zackees zackees commented Oct 23, 2026

Copy link
Copy Markdown
Member

Refs #1933. Tier 2 is #1934 (test/cmocka/test_view.c).

RED

c39ea9829: todo!() stubs in rust/obs-core/src/view.rs and 12 Tier 1 cases in rust/obs-core/tests/obs_core/view.rs (a recording host); all 12 fail with not yet implemented: #1933.

GREEN

  • dda5c76ba safe core over a Host trait, in the C's order: set_source takes the new reference and swaps it under the lock, then activates the new source and deactivates and releases the old one; render drops removed sources and renders the others under the lock; free deactivates and releases each channel, clears them, destroys the mutex. 12/12 Tier 1 pass.
  • e955cf794 swap: the view functions move from libobs/obs-view.c.h to libobs/obs-view-api.c.h in a new unity group libobs.ported-view (+ pch, source-sets.json), which the hybrid libobs replaces with obs-core's ffi::view. The 9 public functions are exported (rust-exports.d/obs-core-view.txt); obs_view_init / obs_view_free (internal, called by obs-canvas.c) are hidden (rust-hidden.txt, rust-exports.map, rust-unexports-macos.txt).
  • 93bac7240 bench.

What stayed C and why

struct obs_view is embedded in struct obs_canvas, so its layout stays C in obs-view.c.h, behind 19 hidden one-step accessors declared in obs-internal.h: the mutex (init/destroy/lock/unlock), type, channels, a source's removed flag, the main canvas mix info, and the obs->video.mixes list (obs_view_mix_add keeps obs_create_video_mix + the locked push together). The obs_source_* calls are the real ones.

Tiers

  • Tier 1: 12 cases (order of every lock/ref/activation step, NULL and out-of-range channels, failed mutex, mixes).
  • Tier 2: test: characterize obs-view before the Rust port (#1933) #1934.
  • Tier 3: view_parity runs fixed and random (512 cases) operation sequences through the unmodified C (oracle/view.c, built with NDEBUG as release libobs) and the shims over shared traced stand-ins, comparing the trace, results, every channel and the mixes after each step; plus init/free on a raw struct. Swapping activate-new / deactivate-old in set_source fails it.
  • ./lint passes; obs-util export-list tests pass (6); ci/test_ported_sources.py passes. Both changed C groups compile (gcc -fsyntax-only).

Bench (Rust / C, oracle stand-ins)

Rust C
set_source swap 30.4 ns 27.3 ns
get_source 7.80 ns 7.70 ns
render (16 of 64) 174.1 ns 169.0 ns
create + destroy 188.8 ns 200.2 ns

Kept / intentional differences

Kept, characterized, not endorsed: obs_view_render releases a removed source without deactivating it; obs_view_enum_video_info does not check the view (NULL enumerates mixes whose view was removed). Intentional: no assert on the channel (out of range returns, as release libobs); a NULL enum_proc with a matching mix panics (the C calls through it).

Not user-visible; no features.md line.

12 Tier 1 cases on a recording host fail with 'not yet implemented: #1933'.
The view functions move from obs-view.c.h to obs-view-api.c.h in their own
unity group, libobs.ported-view, which the hybrid libobs replaces with the
Rust shims in obs-core's ffi::view (rust-exports.d/obs-core-view.txt; the
internal obs_view_init/obs_view_free are hidden). struct obs_view stays C in
obs-view.c.h, embedded in struct obs_canvas: hidden one-step accessors there
give the C file and the shims its mutex, channels and type, a source's
removed flag and the video mixes list.

Tier 3 (view_parity): fixed and random operation sequences through the C
oracle (NDEBUG, as release libobs) and the shims over shared traced
stand-ins, comparing the trace, results, channels and mixes after each step;
plus obs_view_init/obs_view_free on a raw struct. Swapping the activation of
the new source and the deactivation of the old one in set_source fails it.

Refs #1933
Rust/C on the oracle's stand-ins: set_source swap 30.4/27.3 ns, get_source
7.80/7.70 ns, render (16 of 64 channels) 174.1/169.0 ns, create + destroy
188.8/200.2 ns.
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
Merged via the queue into master with commit b4a5894 Oct 23, 2026
33 checks passed
@zackees
zackees deleted the port/1933-view branch October 26, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant