Repository navigation
rust: Port media-io/video-frame.c to obs-media-io - #182
Merged
Merged
Conversation
Member
|
Reviewed head 9b2bf84. Base is master. Policy is met, with no blocking findings. Checked:
Must change before merge: none. Non-blocking:
Optional: none. The PR is ready to merge once CI is green. I'm not merging it here. |
Member
|
Verified (soldr cache disabled) and rebased onto current master with no conflicts (old head 9b2bf84, replaced with --force-with-lease). Claimed on #151 before the PR, too.
The local gate passes and is stamped. I'll merge once CI is green. |
zackees
force-pushed
the
port/video-frame
branch
from
October 11, 2026 01:26
9b2bf84 to
81fa72c
Compare
Tier 1, Tier 2 layout and Tier 3 parity tests for video_frame_init, video_frame_copy and the video-frame.h inlines, against a todo!() core. test/cmocka/test_video_frame.c (obs-rust#117) is the existing C test, so there is no characterization commit. Tier 1 ports it 1:1, including its expected_linesizes / expected_heights model, and adds edge cases: the V210 ALIGN-by-48 quirk (1 -> 16, 47 and 48 -> 80, 1280 stays 1280), u32 wraps (width * 4, HALF(UINT32_MAX) = 0, the u32 linesize * rows copy length), and a plane after a skipped one landing on plane 0. Only video_frame_init and video_frame_copy get C symbols, listed in rust-exports.d/obs-media-io-video_frame.txt. video_frame_get_linesizes and video_frame_get_plane_heights have no header declaration and no caller outside video-frame.c, so they are safe-core functions only. ffi::video_frame mirrors struct video_frame. It also has plain-Rust video_frame_free / _create / _destroy for later ports that handle a struct video_frame. The C inlines stay compiled into their callers (header-inline rule). A format outside enum video_format takes the C switches' default, VIDEO_FORMAT_NONE. video_frame_init still reaches bmalloc(0), which crashes, for VIDEO_FORMAT_NONE, an unknown format and a zero width or height, as test_video_frame.c's frame_init_none expects. The safe VideoFrame::new panics there. The oracle (oracle/video_frame.c) renames the four non-static functions and wraps the inlines in oracle_* functions. Its bmalloc and bfree are libobs's, which under cargo test is the Rust bmem port. Parity sweeps every enumerator and out-of-range values over widths and heights at each rounding step and u32 wrap for the linesizes and heights. It compares frame shapes (linesizes, and plane offsets from data[0]) from init and create, and checks free and destroy. Copies run into separate canary-filled destinations, with equal, wider, narrower and zero linesizes, and every byte is compared. Proptest adds arbitrary formats and sizes. The exclusions are the C crashes and UB: bmalloc(0), layouts too large to allocate, and copies past a plane or between overlapping planes. RED: 19 of the 20 Tier 1 tests fail on todo!(). The parity binary aborts at its first todo!() inside an extern "C" shim. The layout test passes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
video_frame_init and video_frame_copy, plus the safe core (obs_media_io::video_frame) that later media-io ports use: the linesize and plane-height tables, FrameLayout (where init puts each plane in its one bmalloc block), copy_extent / copy_plane, and an owned VideoFrame. video-frame.c joins the ENABLE_RUST_LIBOBS guard. No intentional differences. The C switches become exhaustive matches, and the shims map a format outside the enum to VIDEO_FORMAT_NONE, which is what the C's default does. The u32 linesize math wraps as in C (width * 4, HALF(UINT32_MAX), and V210's ALIGN by 48 with a power-of-two mask), and so does the u32 linesize * rows length of an equal-linesize copy. Plane sizes and offsets are usize, as the C's size_t. FrameLayout records the C's offsets[i - 1] rule, so a plane after a skipped one starts at offset 0. video_frame_init calls the real bmalloc with the layout's size, so a zero-size frame still crashes in bmalloc(0), as test_video_frame.c's frame_init_none requires. Mutation check: dropping HALF's rounding, moving each plane one byte past the previous one, copying one byte more per row into a wider dst, and rounding V210 to a true multiple of 48 each fail Tier 1 and parity. Making the equal-linesize copy length usize fails Tier 1. Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=9f2175734fa63710b346cbb1fb7c9f8dea29343d secs=248 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791683468,"gate":"rust/all/fmt","host":"linux-x86_64","key":"e8a0f7af274ad886cbd562c503aab0d219ce962aac5a29651d46b98d19f32ee1","lane":"lint","parents":["07c2c68433edecd5f8b64d9db5c9ccf866304df0"],"secs":115,"stamp":"d52ce43fa01631865319bb175950a38a","tree":"9f2175734fa63710b346cbb1fb7c9f8dea29343d","v":1,"via":"run"} Ci-Attestation: {"at":1791683468,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"e8a0f7af274ad886cbd562c503aab0d219ce962aac5a29651d46b98d19f32ee1","lane":"lint","parents":["07c2c68433edecd5f8b64d9db5c9ccf866304df0"],"secs":115,"stamp":"822a86d6e9d209a47d1f48905a2b76ac","tree":"9f2175734fa63710b346cbb1fb7c9f8dea29343d","v":1,"via":"run"} Ci-Attestation: {"at":1791683468,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"fdfc27a308eb2752ec54bce9502273a44ef009ea151ec5a71f9209412b1f99f3","lane":"rust-test","parents":["07c2c68433edecd5f8b64d9db5c9ccf866304df0"],"secs":55,"stamp":"991aaa2f7b5ff40bfc59fdd7c8c03d27","tree":"9f2175734fa63710b346cbb1fb7c9f8dea29343d","v":1,"via":"run"} Ci-Attestation: {"at":1791683468,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"4f0a44c71280f272d6a5d52a74c6417ffb7febaf08408be7379c3942e5d4fb06","lane":"tier2-linux","parents":["07c2c68433edecd5f8b64d9db5c9ccf866304df0"],"secs":77,"stamp":"9ab70169229d9c18172ece7f0a604322","tree":"9f2175734fa63710b346cbb1fb7c9f8dea29343d","v":1,"via":"run"}
zackees
force-pushed
the
port/video-frame
branch
from
October 11, 2026 01:51
81fa72c to
8f19816
Compare
10 of 22 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Ports
libobs/media-io/video-frame.ctoobs-media-io(obs_media_io::video_frame), as item 5 of the media-io part 2 order on #45. It also covers thevideo-frame.hinlines under the header-inline rule. No intentional differences.Exports. Only
video_frame_initandvideo_frame_copyget C symbols, listed inrust-exports.d/obs-media-io-video_frame.txt.video_frame_get_linesizesandvideo_frame_get_plane_heightsare not static, but they have no header declaration and no caller outsidevideo-frame.c. They are safe-core functions (linesizes,plane_heights) with no C symbol, as agreed on #45.video-frame.cjoins theENABLE_RUST_LIBOBSguard.Header inlines.
video_frame_free,video_frame_createandvideo_frame_destroystay compiled into their C callers, and the header is unchanged.ffi::video_framemirrorsstruct video_frame, with a layout test against the oracle covering size, alignment, both field offsets and both array lengths. It also has plain-Rust (not exported) versions of the three inlines for later ports that handle astruct video_frame, such asvideo-io.c. These are checked againstoracle_*wrappers of the real inlines.Safe core. The core has these pieces:
linesizes/plane_heights, with exhaustive matches.FrameLayout: the allocation size, plus each plane's linesize and offset fromdata[0].copy_extent/copy_plane.VideoFramewithcopy_from.The shims map a format outside the enum to
VIDEO_FORMAT_NONE, which is where the C switches'default:goes.Characterized, not endorsed. These behaviours are ported as they are:
ALIGNby 48.ALIGNmasks with~47, which clears bits 0-3 and bit 5, so width 1 becomes 16, width 47 and 48 become 80, and width 1280 stays 1280 (linesize 3424, not 3456). Unlesswidth + 47wraps, the result is never below the width.u32wraps.width * 4,HALF(UINT32_MAX) = 0, V210's* 16, and theu32linesize * rowslength of an equal-linesize copy all wrap as in C. Plane sizes and offsets areusize, matching the C'ssize_t.istarts atoffsets[i - 1], so a plane after a skipped one lands on plane 0. A skip only happens when a linesize wraps to 0, for example I40A at widthUINT32_MAX.bmalloc(0).VIDEO_FORMAT_NONE, an unknown format, or a zero width or height still reachesbmalloc(0), which crashes. test: characterize video-frame.c before media-io port #117'sframe_init_nonepins this in a forked child, so the shim calls the realbmallocwith the layout's size and does not return early. The safeVideoFrame::newpanics instead.Oracle.
oracle/video_frame.crenames the four non-static functions and wraps the inlines. Itsbmalloc/bfree/base_get_alignmentare libobs's, which undercargo testis the Rust bmem port, so both sides share one allocator.Motivation and Context
Item 5 of the order approved on #45 (#45 (comment)). It was claimed on #151.
Fixes #151
Refs #45
How Has This Been Tested?
Linux x86_64 (WSL2), Rust via soldr.
Commits follow the policy.
test/cmocka/test_video_frame.calready landed in test: characterize video-frame.c before media-io port #117, so the PR starts at RED (todo!()core), then GREEN.Tier 1 ports
test_video_frame.c1:1, including itsexpected_linesizes/expected_heightsmodel.frame_init_nonebecomes ashould_panic. The null-pointer cases have no safe-API counterpart and are in parity instead. Edge cases on top of the port: the V210 quirk, theu32wraps, the skipped-plane offset, the copy extents, and copies between frames of different widths and formats.Tier 3 sweeps:
INT_MIN,INT_MAX), with widths and heights at each rounding step andu32wrap, for the linesizes and heightsinitandcreate(linesizes, and plane offsets fromdata[0]or null), starting from a 0xAB-filled framefree(zeroes the frame), andfree/destroy/initon NULLProptest adds arbitrary formats and sizes, and random per-plane linesizes for copies. The exclusions are the C crashes and UB, and they are listed in the test file:
bmalloc(0), decided from the oracle's tablesRED→GREEN, checked with soldr's cache disabled and a fresh target dir. At the RED commit,
video_framefails 19/20; the one that passes checks the test's own V210 model. The parity binary aborts at its firsttodo!()inside anextern "C"shim. The layout test passes there. At head, everything passes.Mutation check. Each of these fails Tier 1 and parity, and all were reverted:
HALF's roundingMaking the equal-linesize copy length
usizefails Tier 1.Windows MSVC (local, cargo-xwin):
soldr cargo test -p obs-media-iopasses onx86_64-pc-windows-msvc. The oracle is built with clang-cl, and cmocka does not run.Local checks:
./lintand./unittestpass. tier2-linux rantest_video_frame(the unchanged test: characterize video-frame.c before media-io port #117 test,frame_init_nonecrash included) with ENABLE_RUST_LIBOBS OFF and ON (50/50 each). The libobs exported symbols are identical OFF vs ON (1752). HEAD carries the local-gate stamp.Not run locally: macOS. The Rust Tests and
rust-tier2CI jobs cover it.Types of changes
Checklist:
🤖 Generated with Claude Code