Skip to content

obs-source: port the six async-frame entry wrappers to Rust (Fixes #5760) - #5761

Merged
rdoupe merged 4 commits into
masterfrom
port/5760-frame-wrappers
Nov 26, 2026
Merged

rdoupe merged 4 commits into
masterfrom
port/5760-frame-wrappers

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #5760.

Ports the six exported async-frame entry points obs_source_output_video(), obs_source_output_video2(), obs_source_preload_video(), obs_source_preload_video2(), obs_source_set_video_frame() and obs_source_set_video_frame2() from libobs/obs-source.c.h to obs-source. Each is the same thin wrapper (a destroying() check, a NULL shortcut, then a frame built from the caller's) in front of a C worker.

Commits

  1. libobs: extract ... verbatim moves the six functions unchanged into libobs/obs-source-frame-wrappers.c.h, a member of the live core-source group. The new file sorts before obs-source.c.h in the unity group, so the three workers they call (obs_source_output_video_internal(), _preload_video_internal(), _set_video_frame_internal()) lose their static and obs-internal.h declares them; hidden visibility keeps them out of the exports. No behavior change.
  2. test: characterize ... adds test_source_frame_wrappers (cmocka, a private async source after obs_startup(), 7 cases) against hybrid libobs and the C reference. The workers are hidden in libobs, so each case checks what the worker left: a source being destroyed returns before the NULL check (output with a NULL frame would otherwise clear the clocks); a NULL frame clears the queue, the cache and both clocks through output and changes nothing through preload or set; the obs_source_frame entries queue or preload the whole frame with full_range replaced (BGRA becomes full range, I420 keeps it, max_luminance 1000 kept); the obs_source_frame2 entries take full_range from the range (default resolves per format) and write max_luminance 0 over a frame that had 1000; the set pair also fills the async texture description and clears async_textures_stale; the caller's frame is byte-for-byte unchanged. The set_video_frame(NULL) quirk (it calls the preload worker) leaves no state that tells the two workers apart, so Tier 1 and Tier 3 pin it.
  3. test: RED adds Tier 1 (obs_source::frame_wrappers over a recording model of destroying() and the three workers: which worker each entry calls, the order, and the exact frame each worker gets, field by field as bits) against todo!() cores.
  4. obs-source: port implements the core and the six exports. destroying() and the three workers stay C behind the new adapter file obs-source-frame-wrappers-fields.c.h (declared in obs-internal.h). The extracted C moves to the reference-only group libobs.ported-source-frame-wrappers.

Contract

  • A source being destroyed returns at once, before the NULL check.
  • A NULL frame goes to the worker as NULL; obs_source_set_video_frame()/_set_video_frame2() hand it to the preload worker (upstream quirk, characterized, not endorsed).
  • The obs_source_frame entries copy the caller's whole struct and replace only full_range with obs_source_frame_copy_full_range(format, full_range).
  • The obs_source_frame2 entries build a zeroed frame of all MAX_AV_PLANES data/linesize pairs, width, height, timestamp, format, flip, flags, trc, color_matrix, color_range_min/_max, with full_range = obs_source_frame_copy_full_range2(format, range) and max_luminance = 0.
  • The worker gets a pointer to the local copy; the caller's frame is only read.

Tier 3 (frame_wrappers_parity, oracle/source_frame_wrappers.c) runs the original C and the Rust exports on a real private source over the same production adapters, with destroying() (reading the real field) and the three workers routed through recorders, and compares for every call: which worker runs, its source, whether its frame pointer is NULL, the caller's or a copy, and every field of the copy as bits (NaN, infinities and denormals included). It checks the Rust mirrors of both frame structs against the C layouts (sizes and every offset), pins the characterized answers, rejects four export mutants (set NULL to the set worker, the caller's frame passed through, the NULL check before destroying(), the obs_source_frame range rule on frame2), and runs a proptest over random frames, ranges, formats and destroying values.

No intentional differences. No public-header, existing-C-test, WebSocket or workflow edits. Tier 4 does not apply.

Test cost: new Rust tests are each under 0.1 s in debug, with or without OBS_PARITY_CASES=reduced; the proptest peaks at 12.9 MB over 25 runs; no threads of their own (the three recorder tests run in one isolated child process each, as the shared recorder needs).

Evidence

RED (commit 3, cores todo!()):

soldr cargo test -p obs-data --test obs-tests-core frame_wrappers::
test result: FAILED. 0 passed; 7 failed; 0 ignored; 0 measured; 6825 filtered out
(each: not yet implemented: ... safe core (#5760))

GREEN (commit 4, after rebasing onto the cea708 port #5752):

soldr cargo test -p obs-data --test obs-tests-core frame_wrappers
test result: ok. 11 passed; 0 failed   (7 Tier 1 + 4 Tier 3: layout, characterized, mutants, proptest)
soldr cargo test -p obs-studio-rust --test obs-tests-app -- canonical_source_frame_wrappers canonical_source_output_cea708
test result: ok. 2 passed; 0 failed
./lint   -> lane lint: ok
uv run ci/windows_link_check.py   -> exit 0

Mutation checks on the safe core (each reverted): set_video_frame NULL to the set worker; full_range not replaced; NULL check before destroying(); frame2 max_luminance not zero. Each fails Tier 1 and all three recorder-based Tier 3 tests; an equivalent rewrite (control) passes 11/11.

Tier 2 (OBS_CTEST_JOBS=10 uv run rust/tools/linux-validate/run.py --repeat 3 --tests 'test_source_frame_wrappers|test_async_overflow_clock|test_media_restart_stale_frame|test_source_deinterlace|test_deinterlace_mode_load|test_async_audio_own_clock'):

  • characterization commit: the first run caught a wrong assumption in the test (a new format resets the async cache and queue, so the test now checks the last queued frame); fixed in that commit, then the binary passed 7/7 on both libraries.
  • GREEN: C reference 1119/1119 and hybrid 1119/1119 passed, repeats 8/8 on each; 623 ported C objects excluded from production libobs (622 before); exported symbols identical C vs Rust (1769).
  • The new binary run directly from that build tree, on each library: [ PASSED ] 7 test(s). for both hybrid (libobs/libobs.so.30) and the C reference (libobs-c-reference/libobs.so.30), on the characterization commit and again on GREEN after the rebase.

🤖 Generated with Claude Code

rdoupe and others added 4 commits November 26, 2026 00:13
Moves obs_source_output_video(), obs_source_output_video2(),
obs_source_preload_video(), obs_source_preload_video2(),
obs_source_set_video_frame() and obs_source_set_video_frame2() unchanged
into libobs/obs-source-frame-wrappers.c.h in the live core-source group.
The three workers they call (obs_source_output_video_internal(),
obs_source_preload_video_internal() and
obs_source_set_video_frame_internal()) stay in obs-source.c.h; they lose
their `static` and obs-internal.h declares them, because the new file
comes before obs-source.c.h in the unity group. Hidden visibility keeps
them out of the exported symbols. No behavior change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adds test_source_frame_wrappers (cmocka, a private async source, 7 cases)
against hybrid libobs and the C reference. The workers are hidden in
libobs, so each case checks what the worker left: a source being
destroyed returns before the NULL check (output with a NULL frame would
clear the clocks); a NULL frame clears the queue, the cache and both
clocks through output and changes nothing through preload or set; the
obs_source_frame variants copy the whole frame with full_range replaced
(YUV keeps it, BGRA becomes full range); the obs_source_frame2 variants
take full_range from the range and max_luminance 0; the caller's frame is
never written.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adds obs_source::frame_wrappers with todo!() bodies and its Tier 1 tests
over a recording model of destroying() and the three C workers: a source
being destroyed returns first, NULL frames go to the worker (and the two
set_video_frame entries to the preload worker), the obs_source_frame
entries copy the whole frame with full_range replaced, the
obs_source_frame2 entries build a zeroed frame with full_range from the
range and max_luminance 0, and the worker never gets the caller's frame.

soldr cargo test -p obs-data --test obs-tests-core frame_wrappers::
fails 7 of 7 (not yet implemented).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
)

Implements obs_source::frame_wrappers and the six exports
obs_source_output_video(), obs_source_output_video2(),
obs_source_preload_video(), obs_source_preload_video2(),
obs_source_set_video_frame() and obs_source_set_video_frame2(). A source
being destroyed returns first; a NULL frame goes to the worker as NULL
(the set_video_frame pair to the preload worker, as upstream); an
obs_source_frame is copied whole with full_range replaced, an
obs_source_frame2 builds a zeroed frame with full_range from the range and
max_luminance 0; the worker gets the local copy.

destroying() and the three workers stay C behind the new adapter file
obs-source-frame-wrappers-fields.c.h (declared in obs-internal.h). The
extracted C moves to the reference-only group
libobs.ported-source-frame-wrappers.

Tier 3 (frame_wrappers_parity, oracle/source_frame_wrappers.c) runs the
original C and the Rust exports on a real private source over the same
adapters, with destroying() and the workers recorded, and compares which
worker runs, its source, whether its frame is NULL, the caller's or a
copy, and every field of the copy as bits; it checks both frame layouts,
pins the characterized answers, rejects four export mutants and runs a
proptest over random frames.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Ci-Attestation: {"at":1795670503,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["bd63b0fc7726716aae7d3eecbe7263f2d23a6f1b"],"secs":95,"stamp":"4e34e2a414dbceba8d6e8bd4b87788a7","tree":"cac94551ccd2eb9ffd9085a2296126762b9a08ad","v":1,"via":"run"}
Ci-Attestation: {"at":1795670503,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["bd63b0fc7726716aae7d3eecbe7263f2d23a6f1b"],"secs":95,"stamp":"260e43117b4a68a6d5112c17daec2dbc","tree":"cac94551ccd2eb9ffd9085a2296126762b9a08ad","v":1,"via":"run"}
Ci-Attestation: {"at":1795670503,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["bd63b0fc7726716aae7d3eecbe7263f2d23a6f1b"],"secs":95,"stamp":"be03472440c96f1204c081575153ce0e","tree":"cac94551ccd2eb9ffd9085a2296126762b9a08ad","v":1,"via":"run"}
Ci-Attestation: {"at":1795670503,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["bd63b0fc7726716aae7d3eecbe7263f2d23a6f1b"],"secs":95,"stamp":"3673672118e5936ebedf44f63fe605bc","tree":"cac94551ccd2eb9ffd9085a2296126762b9a08ad","v":1,"via":"run"}
Ci-Attestation: {"at":1795670408,"gate":"general/all/client-lint","host":"linux-x86_64","key":"9b5242b962333cd36a9f0ef30f036840080e88a41339fb7be39021134f1e8137","lane":"client-lint","parents":["bd63b0fc7726716aae7d3eecbe7263f2d23a6f1b"],"secs":102,"stamp":"fa5ed3c4be251ce075a0a03ba673f902","tree":"cac94551ccd2eb9ffd9085a2296126762b9a08ad","v":1,"via":"run"}
Ci-Attestation: {"at":1795670503,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["bd63b0fc7726716aae7d3eecbe7263f2d23a6f1b"],"secs":95,"stamp":"5a8a40452f521dfe9e3dc3a62bee3b56","tree":"cac94551ccd2eb9ffd9085a2296126762b9a08ad","v":1,"via":"run"}
Ci-Attestation: {"at":1795670408,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"9b5242b962333cd36a9f0ef30f036840080e88a41339fb7be39021134f1e8137","lane":"client-lint","parents":["bd63b0fc7726716aae7d3eecbe7263f2d23a6f1b"],"secs":102,"stamp":"6e5248184b6c1d0ac3a651d2a203deee","tree":"cac94551ccd2eb9ffd9085a2296126762b9a08ad","v":1,"via":"run"}
Ci-Attestation: {"at":1795670408,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"9b5242b962333cd36a9f0ef30f036840080e88a41339fb7be39021134f1e8137","lane":"client-lint","parents":["bd63b0fc7726716aae7d3eecbe7263f2d23a6f1b"],"secs":102,"stamp":"178ace8eaa8f8dfb2b1fa12719f8c3b4","tree":"cac94551ccd2eb9ffd9085a2296126762b9a08ad","v":1,"via":"run"}
Ci-Attestation: {"at":1795670408,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"9b5242b962333cd36a9f0ef30f036840080e88a41339fb7be39021134f1e8137","lane":"client-lint","parents":["bd63b0fc7726716aae7d3eecbe7263f2d23a6f1b"],"secs":102,"stamp":"d1d186387aea35399f4ce4c13cb6768b","tree":"cac94551ccd2eb9ffd9085a2296126762b9a08ad","v":1,"via":"run"}
Ci-Attestation: {"at":1795670408,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"9b5242b962333cd36a9f0ef30f036840080e88a41339fb7be39021134f1e8137","lane":"client-lint","parents":["bd63b0fc7726716aae7d3eecbe7263f2d23a6f1b"],"secs":102,"stamp":"0ed2ad987400b27996922f00771d1228","tree":"cac94551ccd2eb9ffd9085a2296126762b9a08ad","v":1,"via":"run"}
Ci-Attestation: {"at":1795670408,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"9b5242b962333cd36a9f0ef30f036840080e88a41339fb7be39021134f1e8137","lane":"client-lint","parents":["bd63b0fc7726716aae7d3eecbe7263f2d23a6f1b"],"secs":102,"stamp":"1b7d06315bfae9842ff43d3669fdd5a2","tree":"cac94551ccd2eb9ffd9085a2296126762b9a08ad","v":1,"via":"run"}
Ci-Attestation: {"at":1795670408,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"9b5242b962333cd36a9f0ef30f036840080e88a41339fb7be39021134f1e8137","lane":"client-lint","parents":["bd63b0fc7726716aae7d3eecbe7263f2d23a6f1b"],"secs":102,"stamp":"67aeca80cb969b30e2fb0a265a5e398e","tree":"cac94551ccd2eb9ffd9085a2296126762b9a08ad","v":1,"via":"run"}
Ci-Attestation: {"at":1795670408,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"9b5242b962333cd36a9f0ef30f036840080e88a41339fb7be39021134f1e8137","lane":"client-lint","parents":["bd63b0fc7726716aae7d3eecbe7263f2d23a6f1b"],"secs":102,"stamp":"e28e4ff9974fae28ae35bc1eb5239688","tree":"cac94551ccd2eb9ffd9085a2296126762b9a08ad","v":1,"via":"run"}
Ci-Attestation: {"at":1795670408,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"9b5242b962333cd36a9f0ef30f036840080e88a41339fb7be39021134f1e8137","lane":"client-lint","parents":["bd63b0fc7726716aae7d3eecbe7263f2d23a6f1b"],"secs":102,"stamp":"6b16fc3de6d1ad5d51578896da88771c","tree":"cac94551ccd2eb9ffd9085a2296126762b9a08ad","v":1,"via":"run"}
Ci-Attestation: {"at":1795670408,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"9b5242b962333cd36a9f0ef30f036840080e88a41339fb7be39021134f1e8137","lane":"client-lint","parents":["bd63b0fc7726716aae7d3eecbe7263f2d23a6f1b"],"secs":102,"stamp":"a39b14e5757427809d267aca9599bfa1","tree":"cac94551ccd2eb9ffd9085a2296126762b9a08ad","v":1,"via":"run"}
Ci-Attestation: {"at":1795670408,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"9b5242b962333cd36a9f0ef30f036840080e88a41339fb7be39021134f1e8137","lane":"client-lint","parents":["bd63b0fc7726716aae7d3eecbe7263f2d23a6f1b"],"secs":102,"stamp":"834ba0ad6ad7acfbbd36cbaa740139e3","tree":"cac94551ccd2eb9ffd9085a2296126762b9a08ad","v":1,"via":"run"}
Ci-Attestation: {"at":1795670408,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"9b5242b962333cd36a9f0ef30f036840080e88a41339fb7be39021134f1e8137","lane":"client-lint","parents":["bd63b0fc7726716aae7d3eecbe7263f2d23a6f1b"],"secs":102,"stamp":"fed15245258a2eb00c7bac1bce847f0d","tree":"cac94551ccd2eb9ffd9085a2296126762b9a08ad","v":1,"via":"run"}
Ci-Attestation: {"at":1795670408,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"9b5242b962333cd36a9f0ef30f036840080e88a41339fb7be39021134f1e8137","lane":"client-lint","parents":["bd63b0fc7726716aae7d3eecbe7263f2d23a6f1b"],"secs":102,"stamp":"85da17a0ed48ed66dc40eb87517a051d","tree":"cac94551ccd2eb9ffd9085a2296126762b9a08ad","v":1,"via":"run"}
Ci-Attestation: {"at":1795670777,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"869494226a1582afa13b3a379b2d1bff497456686507da184c07958ae32306ac","lane":"client-test-x86_64-unknown-linux-gnu","parents":["bd63b0fc7726716aae7d3eecbe7263f2d23a6f1b"],"secs":273,"stamp":"2d8b4d9b4d599ff73394234dd5d655b4","tree":"cac94551ccd2eb9ffd9085a2296126762b9a08ad","v":1,"via":"run"}

Client-Checks: {"checks":{"base":"1a371e8bc576a915376715bf91ad39d30518b860","coverage":"all-tracked-applicable-files","diff":["libobs/build/libobs.core-source+.h.c","libobs/build/libobs.ported-source-frame-wrappers+.h.c","libobs/build/ported-source-sets/source-frame-wrappers.json","libobs/cmake/rust-exports.d/obs-source-source_frame_wrappers.txt","libobs/obs-internal.h","libobs/obs-source-frame-wrappers-fields.c.h","libobs/obs-source-frame-wrappers.c.h","libobs/obs-source.c.h","rust/README.md","rust/obs-build/tests/native.rs","rust/obs-build/tests/native/registration/canonical_source_frame_wrappers_swap_is_registered.rs","rust/obs-c-oracle/oracle.d/source-frame-wrappers.list","rust/obs-c-oracle/oracle/source_frame_wrappers.c","rust/obs-source/Cargo.toml","rust/obs-source/src/ffi/mod.rs","rust/obs-source/src/ffi/source_frame_wrappers.rs","rust/obs-source/src/frame_wrappers.rs","rust/obs-source/src/lib.rs","rust/obs-source/tests/source/frame_wrappers.rs","rust/obs-source/tests/source/frame_wrappers_parity.rs","rust/obs-source/tests/source/main.rs","test/cmocka/build/test-graph.json","test/cmocka/test_source_frame_wrappers.c","test/cmocka/tests.d/test_source_frame_wrappers.cmake"],"head":"cd9654438ddcbf277abb781c4014d5d195273b89","tools":{"orchestrator-python":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]","schema-dependencies":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]\n{'jsonschema': '4.26.0', 'json_source_map': '1.0.5'}","uv":"uv 0.13.5 (x86_64-unknown-linux-gnu)","xmllint":"xmllint: using libxml version 21504-GITv2.15.4\n   compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 DTDValid HTML C14N Catalog XPath XPointer XInclude Iconv ICU ISO8859X Regexps Automata RelaxNG Schemas Schematron Modules Debug Zlib"},"tracked-digest":"185d47a2f39fe6e2176c6ee779b6158d68108c070aa1b62dba872941505436d5","tree":"cac94551ccd2eb9ffd9085a2296126762b9a08ad"}}
@rdoupe
rdoupe requested a review from zackees as a code owner November 26, 2026 05:26
@rdoupe
rdoupe added this pull request to the merge queue Nov 26, 2026
Merged via the queue into master with commit 8a8e7b6 Nov 26, 2026
47 checks passed
@rdoupe
rdoupe deleted the port/5760-frame-wrappers branch November 26, 2026 06:39
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.

rust: port the six async-frame entry wrappers (obs_source_output_video/2, preload_video/2, set_video_frame/2) to obs-source

1 participant