Skip to content

rust: Port media-io/video-io.c to obs-media-io - #420

Merged
zackees merged 6 commits into
obs-rust:masterfrom
nathan-v:test/video-io
Oct 13, 2026
Merged

zackees merged 6 commits into
obs-rust:masterfrom
nathan-v:test/video-io

Conversation

@nathan-v

@nathan-v nathan-v commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Refs #45

What and why

libobs/media-io/video-io.c is the video output thread: the frame cache, the input list, and the scaler hookup. The safe core is obs-media-io::video_output. The C shims keep the libobs API. video_scaler_* stays the FFmpeg C file. ENABLE_RUST_LIBOBS drops media-io/video-io.c.

Six functions are not EXPORT: video_output_inc_texture_encoders, video_output_dec_texture_encoders, video_output_inc_texture_frames, video_output_inc_texture_skipped_frames, video_output_create_with_frame_rate_divisor, and video_output_free_frame_rate_divisor. They stay hidden, in rust-hidden.txt, in the local: section of rust-exports.map, and in rust-unexports-macos.txt.

Scaler creation, the scale call, and their error logs run after the input &mut ends. The input guard stays held across those calls, same as C's input mutex. video_scaler_scale logs when sws_scale fails, so the scaler and its convert buffer leave the input list for that call. A log handler on this thread can connect again without aliasing the input list.

Tier 1 calls the C shims, the same way audio_io does.

Intentional differences, also listed in the parity test header and rust/README.md: cache frames are zeroed (C's bmalloc leaves them uninitialized); close on a divisor child stops the root and frees only the child; the stop flag is atomic; connect(NULL) returns false; a null get_skipped_frames or get_total_frames returns 0; a null info or out-pointer to open returns VIDEO_OUTPUT_INVALIDPARAM; a null frame pointer to lock_frame returns true and writes nothing.

RED → GREEN

  • RED commit: da139e8da. soldr cargo test -p obs-media-io --test video_io aborts in video_output_open (not yet implemented). The stub is extern "C", so the panic cannot unwind.
  • GREEN: Tier 1 video_io 17/17 and Tier 3 video_io_parity 7/7. Tier 2 cmocka is 139 tests, 0 failed, with ENABLE_RUST_LIBOBS OFF and ON. test_video_io and test_video_io_hidden passed in both. Exported symbols OFF vs ON are identical (1766). A wrapping_add(1) on frame_time fails getters_match (1000000001 vs 1000000000); that edit was reverted. A lib test, scale_reenter_connects, connects again from inside scale. Linux cargo test -p obs-media-io passed in the arm64 obs-rust-linux-validate image (rustc 1.98.1, rust-lld). The GitHub runner is x86_64.

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
  • Local gate passed and the pushed head is stamped
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

@nathan-v
nathan-v requested a review from zackees as a code owner October 13, 2026 01:01
@nathan-v
nathan-v marked this pull request as draft October 13, 2026 01:03
@zackees

zackees commented Oct 13, 2026

Copy link
Copy Markdown
Member

Verified locally: this is a characterization commit, so it should pass on the C implementation with no RED step. Tier 2 passes 139/139 with ENABLE_RUST_LIBOBS OFF and ON (test_video_io and test_video_io_hidden both pass in each build). Rebased on master, local gate passed; pushed as 734ed27.

@nathan-v nathan-v changed the title test: characterize video-io.c before port rust: Port media-io/video-io.c to obs-media-io Oct 13, 2026
@nathan-v
nathan-v marked this pull request as ready for review October 13, 2026 03:13
cmocka tests pinning the current C behavior of
libobs/media-io/video-io.c ahead of the obs-media-io port.

test_video_io links libobs and covers the exported API: open
parameter checks, getters, the cache clamp, connect and delivery,
rejected conversions, a zero conversion size, SRGB collapsing to
709, a real scale (linesize only), a repeated frame, the
frame-rate divisor on connect2, a full cache counting a skip, and
the first raw input clearing the frame counters.

test_video_io_hidden compiles video-io.c into the binary. The six
non-EXPORT functions are hidden, so they cannot be linked out of
libobs. That copy takes precedence and does not exercise a later
Rust swap. It pins the texture-encoder refcount and the shallow
frame-rate-divisor copy.

connect(NULL) crashes in get_root before the NULL check. A NULL
get_skipped_frames or get_total_frames dereferences the handle.
close on a divisor child frees the parent's cache. Those are not
called. The crash without obs_startup is forked and skipped when
obs_startup succeeds.

Refs obs-rust#45

Local-Gate: v1 tree=e6446569e55c15e7a8b67c4dde7bf9dccfc0ab28 secs=167 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791854349,"gate":"rust/all/fmt","host":"linux-x86_64","key":"59141c2c75455186035b9aaed5de830a13593a503e8c93acb3c1883750cae784","lane":"lint","parents":["487c90c44ffb91e59baa6dd5304688309f8ac2d4"],"secs":61,"stamp":"bb2e1273be913c21939eddf51d36a6f2","tree":"e6446569e55c15e7a8b67c4dde7bf9dccfc0ab28","v":1,"via":"run"}
Ci-Attestation: {"at":1791854349,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"59141c2c75455186035b9aaed5de830a13593a503e8c93acb3c1883750cae784","lane":"lint","parents":["487c90c44ffb91e59baa6dd5304688309f8ac2d4"],"secs":61,"stamp":"6aa834bd91abaf7d1000a104c0d80aea","tree":"e6446569e55c15e7a8b67c4dde7bf9dccfc0ab28","v":1,"via":"run"}
Ci-Attestation: {"at":1791854349,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"bb9356392a2b12790dd03a77e50b858a0d57397c7f05704a3786eaf6db534596","lane":"rust-test","parents":["487c90c44ffb91e59baa6dd5304688309f8ac2d4"],"secs":47,"stamp":"0ed58bf3dc3c76585304dde92651f97b","tree":"e6446569e55c15e7a8b67c4dde7bf9dccfc0ab28","v":1,"via":"run"}
Ci-Attestation: {"at":1791854349,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"d3cdc5c7d09ab91056fbe4b43eedc2b16ddf3172a63403c22204f41e498c1887","lane":"tier2-linux","parents":["487c90c44ffb91e59baa6dd5304688309f8ac2d4"],"secs":59,"stamp":"1f7bf0c8bbcafc528f672dacf31f95a4","tree":"e6446569e55c15e7a8b67c4dde7bf9dccfc0ab28","v":1,"via":"run"}
Seventeen Tier 1 tests call the shims. soldr cargo test -p
obs-media-io --test video_io aborts in video_output_open:
not yet implemented. The stub is extern "C", so the panic
cannot unwind.

Refs obs-rust#45
The video thread, cache, and input list live in
obs-media-io::video_output. The shims replace video-io.c
when ENABLE_RUST_LIBOBS is on. video_scaler stays the
FFmpeg C file.

soldr cargo test -p obs-media-io --test video_io --test
video_io_parity passes, 17 and 7. A wrapping_add(1) on
frame_time fails getters_match: 1000000001 vs 1000000000.

Linux cargo test of obs-media-io (arm64 image, rust-lld)
passes the same tests. The GitHub runner is x86_64.

Refs obs-rust#45

Local-Gate: v1 tree=5a22fb3b58ca2a531a448ac61bd10af3058eaaa7 secs=102 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791857820,"gate":"rust/all/fmt","host":"darwin-arm64","key":"032c6d1e755bc8583714ea3b90a2766e53e83bd789250bfc6bb69e5b7ce175c9","lane":"lint","parents":["3976d46de9fdd5f81fb556afdce290178a86fd96"],"secs":38,"stamp":"c5c9030a73fff1a1fa2595895a9d5e13","tree":"5a22fb3b58ca2a531a448ac61bd10af3058eaaa7","v":1,"via":"run"}
Ci-Attestation: {"at":1791857820,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"darwin-arm64","key":"032c6d1e755bc8583714ea3b90a2766e53e83bd789250bfc6bb69e5b7ce175c9","lane":"lint","parents":["3976d46de9fdd5f81fb556afdce290178a86fd96"],"secs":38,"stamp":"88221ee8a1712be93a21f922968f2e9c","tree":"5a22fb3b58ca2a531a448ac61bd10af3058eaaa7","v":1,"via":"run"}
Ci-Attestation: {"at":1791857820,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"darwin-arm64","key":"679dce4c17bc83e5e7ba1ab24be1bde4f8cbfd8203e85bead5b3dca754892dfd","lane":"rust-test","parents":["3976d46de9fdd5f81fb556afdce290178a86fd96"],"secs":22,"stamp":"c22083f8462cd727ea3eaf9baa2fa77e","tree":"5a22fb3b58ca2a531a448ac61bd10af3058eaaa7","v":1,"via":"run"}
Ci-Attestation: {"at":1791857820,"gate":"cpp/linux-x64/tier2","host":"darwin-arm64","key":"ac48b099857602c01de0905dee540067c95f3653db63b8bc6fafb3b000fdf217","lane":"tier2-linux","parents":["3976d46de9fdd5f81fb556afdce290178a86fd96"],"secs":42,"stamp":"a67b32085e5f7efb76ece8701c42ef61","tree":"5a22fb3b58ca2a531a448ac61bd10af3058eaaa7","v":1,"via":"run"}
connect built the scaler inside with_mut. blog runs a log
handler on this thread, and that handler can connect again.
A second with_mut would alias the input list. The guard
stays held across the host call, same as C's input mutex.

Refs obs-rust#45

Local-Gate: v1 tree=95558b81aa13b77cc6d6ef6fae4e8280c1a40ec9 secs=125 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791858285,"gate":"rust/all/fmt","host":"darwin-arm64","key":"2530b044ec935c0d26bc2f4d8f29011aaf3b4446471c95def9c212428eb210a3","lane":"lint","parents":["14737489d2486c5503baf0a5196e0f9d61d5847b"],"secs":44,"stamp":"11fb0a30ff54c0111723fd156da78301","tree":"95558b81aa13b77cc6d6ef6fae4e8280c1a40ec9","v":1,"via":"run"}
Ci-Attestation: {"at":1791858285,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"darwin-arm64","key":"2530b044ec935c0d26bc2f4d8f29011aaf3b4446471c95def9c212428eb210a3","lane":"lint","parents":["14737489d2486c5503baf0a5196e0f9d61d5847b"],"secs":44,"stamp":"f2c32cba5ab38e61dc4e531b6841f07f","tree":"95558b81aa13b77cc6d6ef6fae4e8280c1a40ec9","v":1,"via":"run"}
Ci-Attestation: {"at":1791858285,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"darwin-arm64","key":"0e09ebaf625bd2c1cf43790079bbeb99dbefdb6781ea2684ecbeaac10316e84f","lane":"rust-test","parents":["14737489d2486c5503baf0a5196e0f9d61d5847b"],"secs":34,"stamp":"e33009c1da47fe9d5dd8d41e5d82db0c","tree":"95558b81aa13b77cc6d6ef6fae4e8280c1a40ec9","v":1,"via":"run"}
Ci-Attestation: {"at":1791858285,"gate":"cpp/linux-x64/tier2","host":"darwin-arm64","key":"12a383372b1efa4600d00fed68e2e9c07cf11e2581afd6cac49fdd27f66078f0","lane":"tier2-linux","parents":["14737489d2486c5503baf0a5196e0f9d61d5847b"],"secs":47,"stamp":"6b1a53b602bd5f04c61792c9747d1ea3","tree":"95558b81aa13b77cc6d6ef6fae4e8280c1a40ec9","v":1,"via":"run"}
clang-format 22.1.3 wants the scaler create signature on
two lines. CI checks changed .c files under rust/. The
local lint lane does not.

Refs obs-rust#45

Local-Gate: v1 tree=d2db1045a4997d3471298a0eec062117297b56e1 secs=139 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791858979,"gate":"rust/all/fmt","host":"darwin-arm64","key":"5f29de47eb69cabedcd93d87a100d07b1cd812d788942fd0cf97110d51b311d8","lane":"lint","parents":["4a6424b2e2c634b7a9e94d75c84266c083050020"],"secs":46,"stamp":"4b631af1c192120e8661c8fce03b2421","tree":"d2db1045a4997d3471298a0eec062117297b56e1","v":1,"via":"run"}
Ci-Attestation: {"at":1791858979,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"darwin-arm64","key":"5f29de47eb69cabedcd93d87a100d07b1cd812d788942fd0cf97110d51b311d8","lane":"lint","parents":["4a6424b2e2c634b7a9e94d75c84266c083050020"],"secs":46,"stamp":"1cd63f2dbdbd1c10bbc0c2fa72557383","tree":"d2db1045a4997d3471298a0eec062117297b56e1","v":1,"via":"run"}
Ci-Attestation: {"at":1791858979,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"darwin-arm64","key":"ced1802dfb74b4c72d906102e61e78a3bdda7df3439800f5056a95eac6dae7cb","lane":"rust-test","parents":["4a6424b2e2c634b7a9e94d75c84266c083050020"],"secs":47,"stamp":"4f076aafd034bf74512ab3309a5414a9","tree":"d2db1045a4997d3471298a0eec062117297b56e1","v":1,"via":"run"}
Ci-Attestation: {"at":1791858979,"gate":"cpp/linux-x64/tier2","host":"darwin-arm64","key":"50d168f00e0129c61dfa158ebbf0da610074439f1975b96975549d1d46dfdf4a","lane":"tier2-linux","parents":["4a6424b2e2c634b7a9e94d75c84266c083050020"],"secs":46,"stamp":"76d6ad9d6230b445673dc99be8a9fdff","tree":"d2db1045a4997d3471298a0eec062117297b56e1","v":1,"via":"run"}
video_scaler_scale logs when sws_scale fails. A log handler
on this thread can connect again. Take the scaler and the
convert buffer out of the input list before that call.

Refs obs-rust#45

Local-Gate: v1 tree=05d034a9c91e1dbc750f8fa9174df467e607ceeb secs=152 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791861540,"gate":"rust/all/fmt","host":"linux-x86_64","key":"f4557351dd895a801c12ad1cdb9ee67974a6346b21c7bba6f4cbbf424caf8d45","lane":"lint","parents":["caf34863b5c53412e9296a201afa27ed0b7e11be"],"secs":32,"stamp":"34cf9bb63c88427be7fa758824270b56","tree":"05d034a9c91e1dbc750f8fa9174df467e607ceeb","v":1,"via":"run"}
Ci-Attestation: {"at":1791861540,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"f4557351dd895a801c12ad1cdb9ee67974a6346b21c7bba6f4cbbf424caf8d45","lane":"lint","parents":["caf34863b5c53412e9296a201afa27ed0b7e11be"],"secs":32,"stamp":"75fa25fc23a1b7f919190f3fc26be44e","tree":"05d034a9c91e1dbc750f8fa9174df467e607ceeb","v":1,"via":"run"}
Ci-Attestation: {"at":1791861540,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"96815df1a30cde638bbbdd822cc09f9825faf1efc59226270b6ff1d48fbea547","lane":"rust-test","parents":["caf34863b5c53412e9296a201afa27ed0b7e11be"],"secs":58,"stamp":"6e0e129c643a4a426176bf4452e1df8f","tree":"05d034a9c91e1dbc750f8fa9174df467e607ceeb","v":1,"via":"run"}
Ci-Attestation: {"at":1791861540,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"ca94ff3ee54ae75306969315358f7a4dbf6e34d7ddc90b9d77f271251b350f8c","lane":"tier2-linux","parents":["caf34863b5c53412e9296a201afa27ed0b7e11be"],"secs":61,"stamp":"cb939d33f857a7e0f495a764c16c4e3b","tree":"05d034a9c91e1dbc750f8fa9174df467e607ceeb","v":1,"via":"run"}
@zackees

zackees commented Oct 13, 2026

Copy link
Copy Markdown
Member

Verified the full port now that it's ready (zccache bypassed):

  • Characterization 734ed27: Tier 2 139/139 OFF and ON (checked earlier)
  • RED da139e8: obs-media-io video_io aborts on its first stub (cache_size_zero_lock_fails panics in src/ffi/video_io.rs)
  • GREEN 8cf7da4: obs-media-io 235/235
  • Rebased on master, local gate passed (lint, rust-test, tier2-linux with ENABLE_RUST_LIBOBS OFF and ON, which is the port against the unchanged C tests); pushed as c296924.

@zackees
zackees merged commit 71f5e4d into obs-rust:master Oct 13, 2026
23 checks passed
zackees added a commit to rdoupe/obs-studio that referenced this pull request Oct 13, 2026
obs-rust#420 (video-io port) and obs-rust#431 (windows-gnu --no-run link in the
rust-test lane) merged within minutes, and together the lane failed on
master: obs-media-io's video_io test didn't link.

- The video-io oracle's obs_get_profiler_name_store/profile_store_name
  stand-ins were weak on every non-MSVC Windows target, where the audio
  oracle's strong copies don't exist; MinGW drops weak-only definitions
  from static archives. Strong on every _WIN32 now.
- GNU ld scans archives once, in order, and rustc put the oracle's rlib
  before obs_util and obs_media_io, which call into it. The lane links
  through the toolchain's lld (rustlib/<host>/bin/gcc-ld) instead.

Refs obs-rust#291
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