Skip to content

rust: Port media-io video-io.h and frame-rate.h inlines to obs-media-io - #114

Merged
zackees merged 3 commits into
obs-rust:masterfrom
swilk19:port/video-io-inlines
Oct 10, 2026
Merged

zackees merged 3 commits into
obs-rust:masterfrom
swilk19:port/video-io-inlines

Conversation

@swilk19

@swilk19 swilk19 commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Description

Ports the static inline helpers in libobs/media-io/video-io.h (format_is_yuv, get_video_format_name, get_video_colorspace_name, resolve_video_range, get_video_range_name) and libobs/media-io/frame-rate.h (media_frames_per_second_to_frame_interval, _to_fps, _is_valid) to obs-media-io, as item 1 of the media-io part 2 order on #45. No intentional differences.

Header-inline exemption. The helpers are compiled into every C caller, so nothing is swapped or exported, there is no ENABLE_RUST_LIBOBS guard and no rust-exports.txt entry, and both headers are unmodified. Tier 2 is the unchanged cmocka test passing OFF and ON plus a layout test of every struct the headers define. Tier 1 and Tier 3 run against non-inline oracle_* wrappers.

Structs and enums. ffi::video_io mirrors struct video_data, struct video_output_info and struct video_scale_info with the enums as c_ints, and ffi::frame_rate mirrors struct media_frames_per_second. The layout test checks size, alignment and every field offset against the oracle (including video_output_info's pointer and size_t), and MAX_AV_PLANES against the length of video_data.data. video_io.rs also gains enum video_trc and enum video_scale_type (VideoTrc, VideoScaleType) with *_to_c / *_from_c, and the layout test checks their size, alignment and enumerator values, as #106 did for colorspace and range.

Values outside the enums. The safe core takes the Rust enums, with exhaustive matches in place of the C switches. ffi::video_io also has plain (not exported, not no_mangle) helpers that take the C enum values as c_ints, for later shims such as video-frame.c that receive them from C. They convert with *_from_c and give a value outside its enum the C's default result: an unknown format is not YUV and is named "None", an unknown colorspace is "Unknown", and an unknown range is returned unchanged by resolve_video_range and named "Partial". If you would rather not carry these until a shim needs them, they can move into the parity test.

Oracle. oracle/video_io_inlines.c and oracle/frame_rate.c wrap the header functions, each with its own binding module (src/video_io_inlines.rs, src/frame_rate.rs). frame-rate.h has no includes of its own, so its wrapper includes util/c99defs.h first.

Motivation and Context

Item 1 of the order approved on #45 (#45 (comment)). Later media-io ports use these types and helpers when they handle the enums and structs.

Refs #45

How Has This Been Tested?

Linux x86_64 (WSL2), Rust via soldr.

  • Commits follow the policy: test/cmocka/test_video_io_inlines.c (C characterization, passes OFF and ON before any Rust), then RED (todo!() core: Tier 1 and parity fail, layout passes), then GREEN.
  • The cmocka test pins format_is_yuv and get_video_format_name for every enum video_format value (including the lower-case "v210" and "R10l"), the colorspace names (DEFAULT is named as Rec. 709), resolve_video_range and get_video_range_name for every format with each range, and values just outside each enum. For frame-rate.h it pins 30/1, 30000/1001, the u32 extremes, zero parts (inf, 0 and NaN) and _is_valid. The conversions are single double divisions and are compared exactly.
  • soldr cargo test -p obs-media-io: Tier 1 (1:1 port of the cmocka cases plus edge cases), Tier 2 layout for the four structs and two enums, and Tier 3 parity. Parity sweeps every enumerator plus two values on each side of each enum and INT_MIN/INT_MAX, checks the safe core against the oracle for every enumerator, compares the frame-rate conversions bit for bit (NaN included) over an edge grid with zeros and u32::MAX, and adds proptest over arbitrary c_ints and u32 pairs.
  • Mutation check: reporting VIDEO_FORMAT_V210 as not YUV fails the enumerator sweep and the safe-core parity test; dropping the denominator test from is_valid fails the frame-rate edge test. Both reverted.
  • ./lint and ./unittest: ok. tier2-linux ran test_video_io_inlines with ENABLE_RUST_LIBOBS OFF and ON (41/41 each). The libobs exported symbols are identical OFF vs ON (1752). HEAD carries the local-gate stamp.
  • macOS and Windows were not run locally; the Rust Tests and rust-tier2 CI jobs cover them.

Types of changes

  • Code cleanup (non-breaking change which makes code smaller or more readable)

Checklist:

  • My code has been run through clang-format.
  • I have read the contributing document.
  • My code is not on the master branch.
  • The code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.

🤖 Generated with Claude Code

swilk19 and others added 2 commits October 10, 2026 14:40
…test

Pins the header-inline helpers before the Rust port: format_is_yuv and
get_video_format_name for every enum video_format value (including the
lower-case "v210" and "R10l"), get_video_colorspace_name (DEFAULT is
named as Rec. 709), resolve_video_range and get_video_range_name for
every format with each range, and the frame-rate.h conversions and
validity check.

Values outside the enums are characterized: an unknown format is not
YUV and is named "None", an unknown colorspace is "Unknown", an
unknown range is returned unchanged by resolve_video_range and named
"Partial". Zero frame-rate parts are divided as is (inf, 0 or NaN).
The conversions are single double divisions and are compared exactly.

Nothing is swapped, so the test passes with ENABLE_RUST_LIBOBS OFF and
ON alike.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Tier 1, Tier 2 layout and Tier 3 parity tests for the static inline
helpers in media-io/video-io.h (format_is_yuv, get_video_format_name,
get_video_colorspace_name, resolve_video_range, get_video_range_name)
and media-io/frame-rate.h (media_frames_per_second_to_frame_interval,
_to_fps, _is_valid), against todo!() cores.

The helpers are header-inline, so nothing is swapped or exported and
the header-inline exemption applies: Tier 2 is a layout test of every
struct the headers define plus the unchanged cmocka test passing OFF
and ON. ffi::video_io mirrors struct video_data, struct
video_output_info and struct video_scale_info with the enums as
c_ints, and ffi::frame_rate mirrors struct media_frames_per_second;
the layout test checks size, alignment and every field offset against
the oracle, and MAX_AV_PLANES against the length of video_data.data.

video_io.rs also gains enum video_trc and enum video_scale_type
(VideoTrc, VideoScaleType) with *_to_c / *_from_c like the other
media-io enums; the layout test checks their size, alignment and every
enumerator's value against the oracle, as for colorspace and range.

ffi::video_io also has the helpers for C enum values, for later shims
that receive them as c_ints. They convert and call the safe core, and
give values outside the enums the C's result: an unknown format is
VIDEO_FORMAT_NONE, an unknown colorspace is named "Unknown", and an
unknown range is returned unchanged and named "Partial".

The oracles are non-inline oracle_* wrappers around the real header
functions (oracle/video_io_inlines.c, oracle/frame_rate.c), each with
its own binding module. Parity sweeps every enumerator plus values
just outside each enum, compares the frame-rate conversions bit for
bit at edge values, and adds proptest over arbitrary c_ints and u32s.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…io (GREEN)

format_is_yuv, get_video_format_name, get_video_colorspace_name,
resolve_video_range and get_video_range_name, and the frame-rate.h
conversions and validity check, as safe Rust that later media-io ports
use when they handle these enums and structs. The C helpers are static
inline and stay compiled into every C caller; nothing is swapped or
exported, so there is no ENABLE_RUST_LIBOBS guard. No intentional
differences.

The switches become exhaustive matches, so a new enum value fails to
compile instead of falling through to the C's default. The frame-rate
conversions are the C's single f64 divisions, zero parts included, and
parity is bit-exact.

Mutation check: reporting VIDEO_FORMAT_V210 as not YUV, and dropping
the denominator test from is_valid, each fail the enumerator sweep and
edge-value parity tests.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Local-Gate: v1 tree=9bb9dbcd18d0bb7724447dbf1e397c16a754200e secs=372 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791668831,"gate":"rust/all/fmt","host":"linux-x86_64","key":"f50d22fe6722c6f2be9a65981c1f9aabe7430351bf55abc4aea61bcd7353cf7c","lane":"lint","parents":["300f2d6e21a73d9ad02e401676fed852d528f393"],"secs":127,"stamp":"2752bc6b9899bd8ab204c1ebcd4f546a","tree":"9bb9dbcd18d0bb7724447dbf1e397c16a754200e","v":1,"via":"run"}
Ci-Attestation: {"at":1791668831,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"f50d22fe6722c6f2be9a65981c1f9aabe7430351bf55abc4aea61bcd7353cf7c","lane":"lint","parents":["300f2d6e21a73d9ad02e401676fed852d528f393"],"secs":127,"stamp":"7a54138ef6489b61881e9c5c25db4796","tree":"9bb9dbcd18d0bb7724447dbf1e397c16a754200e","v":1,"via":"run"}
Ci-Attestation: {"at":1791668831,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"901cc0e7d55ba21870d182ddb7658947c37563beb2c1db405a22ed969ebec4e8","lane":"rust-test","parents":["300f2d6e21a73d9ad02e401676fed852d528f393"],"secs":92,"stamp":"2634bd89e5201622b56ebf48a94ddf1e","tree":"9bb9dbcd18d0bb7724447dbf1e397c16a754200e","v":1,"via":"run"}
Ci-Attestation: {"at":1791668831,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"77ed72aed16fa50f007e3693bccfcebe557650b4d910a08d172dcfe975191442","lane":"tier2-linux","parents":["300f2d6e21a73d9ad02e401676fed852d528f393"],"secs":152,"stamp":"d0447d0489e766fbf3965cfc0d1c2db0","tree":"9bb9dbcd18d0bb7724447dbf1e397c16a754200e","v":1,"via":"run"}
@zackees

zackees commented Oct 10, 2026

Copy link
Copy Markdown
Member

Rebased onto master (after #109 work, #112 and #113; no conflicts). RED→GREEN, checked with soldr's cache disabled: video_io_inlines fails 16/18 at the RED commit and the full suite passes at head. The local gate (lint, rust-test, Tier 2 OFF/ON) passes and is stamped.

@zackees
zackees force-pushed the port/video-io-inlines branch from 6126e8b to 533539d Compare October 10, 2026 21:47
@zackees
zackees merged commit 625cda8 into obs-rust:master Oct 10, 2026
20 checks passed
@swilk19
swilk19 deleted the port/video-io-inlines branch October 11, 2026 01:49
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