Skip to content

obs-source: port obs_source_frame_copy to Rust (Fixes #5714) - #5741

Merged
rdoupe merged 4 commits into
masterfrom
port/5714-frame-copy
Nov 26, 2026
Merged

rdoupe merged 4 commits into
masterfrom
port/5714-frame-copy

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #5714.

Ports the exported obs_source_frame_copy() and the private copy_frame_data() / copy_frame_data_plane() / frame_copy_lines() it runs to Rust in obs-source. The copy plan itself (#2215) was already Rust; this moves the code that carries it out.

Commits

  1. 6bd94e1bd libobs: extract, no behavior change. Moves frame_copy_lines, copy_frame_data_plane, copy_frame_data and obs_source_frame_copy (with the plane-count _Static_assert) verbatim into libobs/obs-source-frame-copy-data.c.h in the live core-source group. cache_video() and the two preload paths now call the exported obs_source_frame_copy(), which only calls copy_frame_data(), so the three internal callers stay on one shared copy.
  2. 7e28ab03a test: characterization. test/cmocka/test_source_frame_copy.c through the exported obs_source_frame_copy() against both the C reference and hybrid libobs, frames from obs_source_frame_create(): every format's planes at four sizes with equal line sizes, then destination line sizes longer, shorter and mixed per plane (each row copies the smaller line size, the rest of a longer destination row is untouched; P216 and P416 copy no plane, as upstream does), metadata copied bit for bit, the colour range only when the source is not full range, and format, size, data, line sizes, refs and prev_frame left alone.
  3. 939a0f1bc test: RED. Tier 1 mirrors of the cmocka cases plus edge cases (the order of the writes, plane extents with wrapping row starts, short slices) against a todo!() core.
  4. 57269c821 obs-source: GREEN. Safe core rust/obs-source/src/frame_copy_data.rs writes the metadata, asks the existing frame_copy::copy_plan, writes the colour range when the plan says so and runs each plane copy over slices the shim builds from plane_extent (row starts in u32, as the C computes them). The C ABI shim ffi/source_frame_copy_data.rs mirrors the public struct obs_source_frame. The extracted C moves unchanged to the reference-only group libobs.ported-source-frame-copy-data. Tier 3 (frame_copy_data_parity.rs, oracle source_frame_copy_data.c) runs the original C and the Rust export over every format, seven sizes and six line-size patterns, plus a proptest over same-shape frames, and checks the struct layout against C.

No public header, existing C test, frontend, plugin or obs-websocket change. Exports unchanged (1769 symbols, identical between the C and Rust builds). No intentional differences.

Note: #5721 (draft, #5720) adds a characterization of the same function under the same file name. This PR was claimed first (#5714) and carries its own; whichever lands second rebases onto the other.

Evidence

RED (939a0f1bc):

soldr cargo test -p obs-data --test obs-tests-core -- source::frame_copy_data::
test source::frame_copy_data::edge_copy_plane_rows_and_whole ... FAILED
test source::frame_copy_data::edge_metadata_then_range_then_planes_in_order ... FAILED
test source::frame_copy_data::edge_copy_plane_short_slices_copy_what_fits ... FAILED
test source::frame_copy_data::edge_plane_extent ... FAILED
test source::frame_copy_data::test_source_frame_copy_metadata_and_colour_range ... FAILED
test source::frame_copy_data::test_source_frame_copy_every_format_unequal_line_sizes ... FAILED
test source::frame_copy_data::test_source_frame_copy_every_format_equal_line_sizes ... FAILED
test source::frame_copy_data::test_source_frame_copy_metadata_copy_also_copies_planes ... FAILED
panicked at rust/obs-source/src/frame_copy_data.rs (todo!())

GREEN (head, on dac430e4a):

soldr cargo test -p obs-data --test obs-tests-core -- source::frame_copy_data
test result: ok. 11 passed; 0 failed   (8 Tier 1 + 3 Tier 3 parity)

soldr cargo test -p obs-studio-rust --test obs-tests-app -- canonical_source_frame_copy_data
test result: ok. 1 passed; 0 failed

soldr cargo test -p obs-util --lib -- export_list
test result: ok. 4 passed; 0 failed

./lint
== lane lint: ok

OBS_CMOCKA_LINK=false uv run --no-project ci/windows_link_check.py
exit 0

OBS_CTEST_JOBS=10 uv run rust/tools/linux-validate/run.py --repeat 1 --tests '^(test_source_frame_copy|test_source_frame_copy_steps.*|test_async_.*)$'
== libobs exported symbols, C vs Rust: IDENTICAL (1769 symbols)
== [OFF] ctest: 100% tests passed, 0 tests failed out of 1114
== [OFF] repeat: 100% tests passed, 0 tests failed out of 14
== [ON] ctest: 100% tests passed, 0 tests failed out of 1114
== [ON] repeat: 100% tests passed, 0 tests failed out of 14

🤖 Generated with Claude Code

@rdoupe

rdoupe commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Rebased onto master (frame init moved to its own ported group in #5634, so the core-source group and the module lists conflicted). After the rebase: ./lint ok; soldr cargo test -p obs-data --test obs-tests-core frame_copy 88 passed; the registration test passes; Tier 2 linux-validate --tests 'test_source_frame' 1117/1117 then 4/4 (test_source_frame_copy, its steps and steps_rust, test_source_frame_init). Will mark ready once CI is green.

@rdoupe
rdoupe marked this pull request as ready for review November 26, 2026 00:07
@rdoupe
rdoupe requested a review from zackees as a code owner November 26, 2026 00:07
@rdoupe
rdoupe added this pull request to the merge queue Nov 26, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 26, 2026
rdoupe and others added 4 commits November 25, 2026 19:58
Moves frame_copy_lines, copy_frame_data_plane, copy_frame_data and
obs_source_frame_copy, with the plane-count _Static_assert, into
libobs/obs-source-frame-copy-data.c.h in the live core-source group.
cache_video() and the two preload paths now call the exported
obs_source_frame_copy() (it only calls copy_frame_data()), so they no
longer need the static function. No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A cmocka test through the exported obs_source_frame_copy() on frames of
the same format and size, the source from obs_source_frame_create():
every format's planes at four sizes with equal line sizes, then with the
destination's line sizes longer, shorter and mixed per plane (each row
copies the smaller line size, the rest of a longer destination row stays
untouched; P216 and P416 copy no plane), the metadata copied bit for bit,
the colour range only when the source is not full range, and format,
size, data, line sizes, refs and prev_frame left alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tier 1 mirrors of test_source_frame_copy.c (same cases, formats, sizes,
line sizes and fills) and new edge cases (the order of the writes, the
plane extents with wrapping row starts, short slices) against a todo!()
core in obs_source::frame_copy_data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Safe core frame_copy_data::copy_frame_data writes the metadata, asks the
existing frame_copy::copy_plan, writes the colour range when the plan
says so and runs each plane copy through frame_copy_data::copy_plane over
slices the shim builds from plane_extent (row starts in u32, as the C
computes them). The C ABI shim mirrors the public struct obs_source_frame
and writes each field through the pointer. cache_video() and the two
preload paths reach it through the exported obs_source_frame_copy(). The
extracted C moves to the reference-only group
libobs.ported-source-frame-copy-data. Tier 3 parity against the original
C over every format, seven sizes and six line-size patterns, and a
proptest over same-shape frames.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Ci-Attestation: {"at":1795655480,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["736fd91a366abcdc32abafce77e41fcbfe4e67c0"],"secs":93,"stamp":"6eb78adf660271b68d6d201bef38bf04","tree":"9727ee1e3c9c055f0ae3737a61c4c91dd3f58d44","v":1,"via":"run"}
Ci-Attestation: {"at":1795655480,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["736fd91a366abcdc32abafce77e41fcbfe4e67c0"],"secs":93,"stamp":"ed13aecc41336dbc8b58ae2eb145a132","tree":"9727ee1e3c9c055f0ae3737a61c4c91dd3f58d44","v":1,"via":"run"}
Ci-Attestation: {"at":1795655480,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["736fd91a366abcdc32abafce77e41fcbfe4e67c0"],"secs":93,"stamp":"a5323f8165dceb55bdbe6f07b1ad47ae","tree":"9727ee1e3c9c055f0ae3737a61c4c91dd3f58d44","v":1,"via":"run"}
Ci-Attestation: {"at":1795655480,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["736fd91a366abcdc32abafce77e41fcbfe4e67c0"],"secs":93,"stamp":"f03b85df1b3a02cf2d16a5722a3fd8bd","tree":"9727ee1e3c9c055f0ae3737a61c4c91dd3f58d44","v":1,"via":"run"}
Ci-Attestation: {"at":1795655386,"gate":"general/all/client-lint","host":"linux-x86_64","key":"ba618f321d17f7ec6047b7687078ec63937be1a44724e00e36fb766b846cb0d0","lane":"client-lint","parents":["736fd91a366abcdc32abafce77e41fcbfe4e67c0"],"secs":10,"stamp":"5f66ddf545df2d40d90292ac818dfa62","tree":"9727ee1e3c9c055f0ae3737a61c4c91dd3f58d44","v":1,"via":"run"}
Ci-Attestation: {"at":1795655480,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["736fd91a366abcdc32abafce77e41fcbfe4e67c0"],"secs":93,"stamp":"f589f637c69716edcbc2c55dbb73d317","tree":"9727ee1e3c9c055f0ae3737a61c4c91dd3f58d44","v":1,"via":"run"}
Ci-Attestation: {"at":1795655386,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"ba618f321d17f7ec6047b7687078ec63937be1a44724e00e36fb766b846cb0d0","lane":"client-lint","parents":["736fd91a366abcdc32abafce77e41fcbfe4e67c0"],"secs":10,"stamp":"f60685b3f19de6abefba990c81b14d60","tree":"9727ee1e3c9c055f0ae3737a61c4c91dd3f58d44","v":1,"via":"run"}
Ci-Attestation: {"at":1795655386,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"ba618f321d17f7ec6047b7687078ec63937be1a44724e00e36fb766b846cb0d0","lane":"client-lint","parents":["736fd91a366abcdc32abafce77e41fcbfe4e67c0"],"secs":10,"stamp":"6f0964d4948f8514891947565aebbf36","tree":"9727ee1e3c9c055f0ae3737a61c4c91dd3f58d44","v":1,"via":"run"}
Ci-Attestation: {"at":1795655386,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"ba618f321d17f7ec6047b7687078ec63937be1a44724e00e36fb766b846cb0d0","lane":"client-lint","parents":["736fd91a366abcdc32abafce77e41fcbfe4e67c0"],"secs":10,"stamp":"575b97a9c110507b09bab1d256b0f402","tree":"9727ee1e3c9c055f0ae3737a61c4c91dd3f58d44","v":1,"via":"run"}
Ci-Attestation: {"at":1795655386,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"ba618f321d17f7ec6047b7687078ec63937be1a44724e00e36fb766b846cb0d0","lane":"client-lint","parents":["736fd91a366abcdc32abafce77e41fcbfe4e67c0"],"secs":10,"stamp":"3e3b533c9d90ef9e16c8014d42fa2aeb","tree":"9727ee1e3c9c055f0ae3737a61c4c91dd3f58d44","v":1,"via":"run"}
Ci-Attestation: {"at":1795655386,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"ba618f321d17f7ec6047b7687078ec63937be1a44724e00e36fb766b846cb0d0","lane":"client-lint","parents":["736fd91a366abcdc32abafce77e41fcbfe4e67c0"],"secs":10,"stamp":"96ad65cd71bc5cbae9f26f9a58edec69","tree":"9727ee1e3c9c055f0ae3737a61c4c91dd3f58d44","v":1,"via":"run"}
Ci-Attestation: {"at":1795655386,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"ba618f321d17f7ec6047b7687078ec63937be1a44724e00e36fb766b846cb0d0","lane":"client-lint","parents":["736fd91a366abcdc32abafce77e41fcbfe4e67c0"],"secs":10,"stamp":"e3c586bd31587e8daa68b139c7de9a4f","tree":"9727ee1e3c9c055f0ae3737a61c4c91dd3f58d44","v":1,"via":"run"}
Ci-Attestation: {"at":1795655386,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"ba618f321d17f7ec6047b7687078ec63937be1a44724e00e36fb766b846cb0d0","lane":"client-lint","parents":["736fd91a366abcdc32abafce77e41fcbfe4e67c0"],"secs":10,"stamp":"67a717335f95c4c04518b6e4ff092f4a","tree":"9727ee1e3c9c055f0ae3737a61c4c91dd3f58d44","v":1,"via":"run"}
Ci-Attestation: {"at":1795655386,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"ba618f321d17f7ec6047b7687078ec63937be1a44724e00e36fb766b846cb0d0","lane":"client-lint","parents":["736fd91a366abcdc32abafce77e41fcbfe4e67c0"],"secs":10,"stamp":"3f0b0529180c22c94a9f2650cde61e36","tree":"9727ee1e3c9c055f0ae3737a61c4c91dd3f58d44","v":1,"via":"run"}
Ci-Attestation: {"at":1795655386,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"ba618f321d17f7ec6047b7687078ec63937be1a44724e00e36fb766b846cb0d0","lane":"client-lint","parents":["736fd91a366abcdc32abafce77e41fcbfe4e67c0"],"secs":10,"stamp":"8b8b15aa697252ced257f7f0efaadf8d","tree":"9727ee1e3c9c055f0ae3737a61c4c91dd3f58d44","v":1,"via":"run"}
Ci-Attestation: {"at":1795655386,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"ba618f321d17f7ec6047b7687078ec63937be1a44724e00e36fb766b846cb0d0","lane":"client-lint","parents":["736fd91a366abcdc32abafce77e41fcbfe4e67c0"],"secs":10,"stamp":"21c24c146cb8d10a6e6e5172ac248f95","tree":"9727ee1e3c9c055f0ae3737a61c4c91dd3f58d44","v":1,"via":"run"}
Ci-Attestation: {"at":1795655386,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"ba618f321d17f7ec6047b7687078ec63937be1a44724e00e36fb766b846cb0d0","lane":"client-lint","parents":["736fd91a366abcdc32abafce77e41fcbfe4e67c0"],"secs":10,"stamp":"f37f67fbb787ff7ecf71e8ec4e561bb1","tree":"9727ee1e3c9c055f0ae3737a61c4c91dd3f58d44","v":1,"via":"run"}
Ci-Attestation: {"at":1795655386,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"ba618f321d17f7ec6047b7687078ec63937be1a44724e00e36fb766b846cb0d0","lane":"client-lint","parents":["736fd91a366abcdc32abafce77e41fcbfe4e67c0"],"secs":10,"stamp":"32e893afc3044d736e3bcfd9172140c9","tree":"9727ee1e3c9c055f0ae3737a61c4c91dd3f58d44","v":1,"via":"run"}
Ci-Attestation: {"at":1795655644,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"49587e5440f1978772c3d9d3e97ce51c084e66021005445d96ceb793304b201f","lane":"client-test-x86_64-unknown-linux-gnu","parents":["736fd91a366abcdc32abafce77e41fcbfe4e67c0"],"secs":164,"stamp":"32467eaf3c4731135d949704421f7472","tree":"9727ee1e3c9c055f0ae3737a61c4c91dd3f58d44","v":1,"via":"run"}

Client-Checks: {"checks":{"base":"7f54bf96e78bc88fc3ea6a698513e38131e7932e","coverage":"all-tracked-applicable-files","diff":["libobs/build/libobs.ported-source-frame-copy-data+.h.c","libobs/build/ported-source-sets/source-frame-copy-data.json","libobs/cmake/rust-exports.d/obs-source-source_frame_copy_data.txt","libobs/obs-source-frame-copy-data.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_copy_data_swap_is_registered.rs","rust/obs-c-oracle/oracle.d/source-frame-copy-data.list","rust/obs-c-oracle/oracle/source_frame_copy_data.c","rust/obs-source/Cargo.toml","rust/obs-source/src/ffi/mod.rs","rust/obs-source/src/ffi/source_frame_copy_data.rs","rust/obs-source/src/frame_copy_data.rs","rust/obs-source/src/lib.rs","rust/obs-source/tests/source/frame_copy_data.rs","rust/obs-source/tests/source/frame_copy_data_parity.rs","rust/obs-source/tests/source/main.rs","test/cmocka/build/test-graph.json","test/cmocka/test_source_frame_copy.c","test/cmocka/tests.d/test_source_frame_copy.cmake"],"head":"e543bfee7ee8cc80188acce181553d85642043cb","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":"3fb3223eb3447aea49eca9e9441be52328bdccc7f3f1f03377b40ecf99ebe582","tree":"9727ee1e3c9c055f0ae3737a61c4c91dd3f58d44"}}
@rdoupe
rdoupe force-pushed the port/5714-frame-copy branch from 69287a0 to 59d8dbc Compare November 26, 2026 01:14
@rdoupe
rdoupe added this pull request to the merge queue Nov 26, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this to In merge queue in obs-rust Multiview Nov 26, 2026
Merged via the queue into master with commit dc65e23 Nov 26, 2026
46 checks passed
@rdoupe
rdoupe deleted the port/5714-frame-copy branch November 26, 2026 02:42
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In merge queue to Done in obs-rust Multiview Nov 26, 2026
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 obs_source_frame_copy and copy_frame_data to obs-source

1 participant