Skip to content

libobs: Port the video output plan to obs-core - #1773

Merged
zackees merged 4 commits into
obs-rust:masterfrom
rdoupe:port/video-plan-obs-core
Oct 22, 2026
Merged

zackees merged 4 commits into
obs-rust:masterfrom
rdoupe:port/video-plan-obs-core

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

Refs #1713

What and why

Step 3 of #1713: ports libobs/obs-video-plan.c.h, the video output plan that #1714 moved out of obs.c.h and #1734 fixed, to Rust. As the claim on #1713 said, it goes in a new crate, rust/obs-core, module video_plan. That crate is for the units extracted from libobs/obs.c.h, and later obs.c.h units join it as modules.

The plan is what obs_reset_video() accepts and how it aligns the output size, plus, for each output format, the GPU conversion (the format_conversion.effect techniques and their texel sizes), each conversion plane's size and texture format, and the render texture format and color space. obs.c.h (still C) creates the textures and surfaces from it. The hybrid libobs drops the C file and links the Rust shims instead.

  • Safe core (src/video_plan.rs): size_valid, align_output_size, output_size_valid (checked as given and again after the alignment, libobs: Refuse an output size that the alignment makes invalid #1734), scale_type_name and output_plan, which follows the C's three steps. Technique names are 'static c"..." strings, because obs-video.c keeps them and looks them up by name. Texel sizes are the C's 1.f / (float)size, bit for bit, and infinite for a zero size as in C. The sizes come from profiles, obs-websocket SetVideoSettings and scripts, so the module denies clippy's panic, indexing and arithmetic lints, and no input can make it panic.
  • Shim (src/ffi/video_plan.rs): the five functions with their C signatures, and #[repr(C)] struct obs_video_plane / struct obs_video_output_plan, returned by value. The enums cross as c_ints. A value outside its enum takes the C's default: branch.
  • C side: the file moves out of libobs.core into its own group, libobs.ported-video-plan (in LIBOBS_PORTED_SOURCES, PCH obs-internal.h), so the C reference and the C backend still compile it. The five functions are declared in obs-internal.h without EXPORT, so the shims are hidden (rust-hidden.txt, rust-exports.map, rust-unexports-macos.txt). libobs-rust depends on obs-core and re-exports its ffi.
  • Tests: Tier 1 and Tier 3 are modules of the existing core category binary obs-tests-core, so the test-binary count stays at 8 of 8.

Intentional difference from C (listed in the parity test header and rust/README.md): a null pointer to obs_video_align_output_size is skipped, where C dereferences it. The other pointer is still aligned.

The fps = 0 rejection (steps 4 and 5 in the planning notes) is separate, so this PR uses Refs.

RED → GREEN

  • RED commit: c85322c21. Tier 1 ports test_video_output_plan 1:1 (its 10 cases, same names, same order), plus 8 edge cases. Against the todo!() core, soldr cargo test -p obs-data --test obs-tests-core obs_core:: fails 17 of 18 with "not yet implemented". Only enum_tables_in_header_order passes.
  • GREEN: 1879a13b1 (port), 98b2d62cf (oracle and Tier 3), 31a8bf0b7 (docs).
    • Tier 1: obs_core::video_plan 18 of 18.
    • Tier 2, local, Linux:
      • test_video_output_plan passes 10 of 10 against the C-backend libobs, hybrid libobs and libobs-c-reference.
      • test_video_output_formats passes 4 of 4 against all three, under a private Xvfb.
      • Full ctest: libobs-c-reference 365 of 365. Hybrid libobs 364 of 365: test_pulse_monitor_device failed once under -j4 (the default-sink check in default_device_follows_default_output; the test does not touch the video plan) and passed 5 of 5 run alone. 0 skips in either run.
      • Exported symbols are identical, 1766 in each of the three. The hybrid's five symbols are the Rust ones (obs_core::video_plan::*), and the C reference has no Rust symbols.
    • Tier 3: obs_core::video_plan_parity 11 of 11.
      • Layout and enum values against the C header.
      • Exhaustive: every video_format and video_colorspace value, plus -1, one and two past the end, INT_MIN and INT_MAX, at 24 widths × 24 heights. That is 31 × 11 × 576 plans, compared field by field, with technique names byte for byte and floats bit for bit.
      • Every obs_scale_type value and values outside it.
      • Size checks and alignment at the edges.
      • Proptests, 4096 cases each, over any enum value and any u32 size.
    • Deliberate breaks (not committed), each caught by the parity test:
      • P216 chroma plane at half height: 3 tests fail.
      • Output size not checked again after the alignment: the edge sweep fails.
      • PQ and HLG technique sets of P416 swapped: 3 fail.
      • Texel size computed with a different rounding: 3 fail.
    • uv run ci/local_gate.py --lane lint and --lane cross both pass. ci/test_ported_sources.py, ci/test_build_groups.py, ci/test_binary_cap.py, ci/test_naming.py and ci/test_rust_scope.py pass.
  • Real app (UI, protocol output or logging changes): N/A. No change in behavior, and test_video_output_formats runs obs_reset_video() and real frames through the hybrid for every converted format.

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)
  • 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)

RED for the port of libobs/obs-video-plan.c.h to a new crate,
rust/obs-core, module video_plan: the crate for the units extracted from
libobs/obs.c.h, as the claim on obs-rust#1713 proposed. The safe core is a stub
(todo!()): size_valid(), align_output_size(), output_size_valid(),
scale_type_name() and output_plan(). The C enums it takes or returns,
gs_color_format, gs_color_space and obs_scale_type, are plain data in
header order (GsColorFormat, GsColorSpace, ObsScaleType); video_format
and video_colorspace are obs-media-io's. A value outside its enum is
None, the C's default: branch.

tests/obs_core/video_plan.rs ports test_video_output_plan 1:1: its 10
cases under the same names, in the same order, with the same inputs and
the same expected values, including the written-out plan per format and
the bit-for-bit float comparison over every format x colorspace x size.
techniques_exist_in_the_effect reads libobs/data/format_conversion.effect
from the source tree, with CR removed as the C test does.

Edge cases: the enum tables in header order, the size bounds, a zero
size (infinite texel size, as 1.f / (float)0), u32::MAX sizes, technique
names as C identifiers, techniques and planes in pairs, and two
proptests over any u32 sizes: the plan against the written-out rules,
and the alignment and the output size check.

The tests are a module of the existing core category binary,
obs-tests-core; no new test binary (8 of 8).

soldr cargo test -p obs-data --test obs-tests-core obs_core::
fails 17 of 18 with "not yet implemented"; only
enum_tables_in_header_order passes.

Refs obs-rust#1713
Ports libobs/obs-video-plan.c.h to the video_plan module of a new crate,
rust/obs-core, for the units extracted from libobs/obs.c.h. The plan
tells obs_reset_video() which sizes it takes and how it aligns the
output, and tells the mix setup, per output format, the GPU conversion
(the techniques of format_conversion.effect and their texel sizes), the
size and format of each conversion plane, and the render texture format
and color space. obs.c.h (still C) creates the textures and surfaces
from it; the hybrid libobs drops the C file and links the Rust shims.

Safe core (src/video_plan.rs): size_valid() with OBS_SIZE_MIN and
OBS_SIZE_MAX, align_output_size(), output_size_valid() (valid as given
and after the alignment, obs-rust#1734), scale_type_name(), and output_plan()
with the C's three steps: the techniques and texel sizes, the planes,
and the render textures. Technique names are 'static c"..." strings.
The texel sizes are 1.0 / size as f32, the C's 1.f / (float)size bit for
bit (infinite for a zero size, as in C). The sizes come from profiles,
obs-websocket SetVideoSettings and scripts, so the module denies
clippy's indexing_slicing, arithmetic_side_effects, unwrap_used,
expect_used, panic, todo, unimplemented and unreachable; nothing panics
for any input.

Shim (src/ffi/video_plan.rs): the five functions with the C
signatures, and #[repr(C)] struct obs_video_plane and struct
obs_video_output_plan, returned by value. The enums cross as c_ints;
a value outside its enum takes the C's default: branch. Intentional
difference: a null pointer to obs_video_align_output_size is skipped (C
dereferences it); the other pointer is still aligned.

C side: the file leaves libobs.core for its own group,
libobs.ported-video-plan (LIBOBS_PORTED_SOURCES), whose PCH is
obs-internal.h, so the C reference and the C backend keep compiling it.
The functions are declared in obs-internal.h without EXPORT, so the
shims are hidden: rust-hidden.txt, rust-exports.map and
rust-unexports-macos.txt. libobs-rust depends on obs-core and
re-exports its ffi.

Results: test_video_output_plan (10 of 10) and test_video_output_formats
(4 of 4, under a private Xvfb) pass against the C-backend libobs, the
hybrid libobs and libobs-c-reference. The exported symbol sets are
identical, 1766 in each. Tier 1: obs_core:: 18 of 18.

Refs obs-rust#1713
The oracle, oracle/video_plan.c, is libobs/obs-video-plan.c.h,
unmodified, with its five functions renamed to oracle_*. The rename also
renames the struct tag obs_video_output_plan, in obs-internal.h and the
file alike, which leaves the layout as it is. It also reports the layout
of struct obs_video_plane and struct obs_video_output_plan, the width of
the enums, and the gs_color_format, gs_color_space, obs_scale_type,
video_format and video_colorspace values.

Tier 3 (tests/obs_core/video_plan_parity.rs), in obs-tests-core:

- the layout and the enum values against the C header;
- exhaustively, every video_format and video_colorspace value, with -1,
  one and two past the end, INT_MIN and INT_MAX, at 24 sizes (the
  characterization's, 0, 32769, 65536, 2^31 - 1, 2^31, 2^32 - 2 and
  2^32 - 1) for each of width and height: 31 x 11 x 24 x 24 plans, every
  field, technique names byte for byte, floats bit for bit;
- every obs_scale_type value and values outside it;
- the size checks and the alignment at those sizes;
- proptests (4096 cases each) over any format and color space value and
  any u32 sizes, sizes up to 65536, and the size checks over any u32 and
  near the bounds.

Excluded, the one intentional difference: a null pointer to
obs_video_align_output_size, which the shim skips and C dereferences; a
shim-only test pins it. 11 of 11 pass.

Deliberate breaks, not committed, each caught: the P216 chroma plane at
half height (3 tests fail), the output size not checked again after the
alignment (the edge sweep fails), the PQ and HLG technique sets of P416
swapped (3), and the texel size from a different rounding (3).

Refs obs-rust#1713
naming.md: libobs/obs.c.h and the units extracted from it
(obs-video-plan.c.h so far) go in rust/obs-core. rust/README.md: the
obs-core layout row and the obs-video-plan.c.h row of the ported table,
with its one intentional difference. testing-policy.md: obs-core's
tests are a module of the core category binary, obs-tests-core.

Refs obs-rust#1713
@zackees
zackees force-pushed the port/video-plan-obs-core branch from 31a8bf0 to 6e10e34 Compare October 22, 2026 11:12
@zackees
zackees added this pull request to the merge queue Oct 22, 2026
Merged via the queue into obs-rust:master with commit cc69539 Oct 22, 2026
30 checks passed
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.

2 participants