Skip to content

obs-source: port obs_source_show_preloaded_video to Rust (Fixes #5762) - #5765

Merged
rdoupe merged 4 commits into
masterfrom
port/5762-show-preloaded-video
Nov 26, 2026
Merged

rdoupe merged 4 commits into
masterfrom
port/5762-show-preloaded-video

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #5762

Ports obs_source_show_preloaded_video() from libobs/obs-source.c.h into obs-source. It is the consumer half of the preload pair whose producer is in #5761; the two touch no common file.

Commits:

  1. libobs: extract moves the body unchanged into libobs/obs-source-show-preloaded-video.c.h in the live core-source group. Everything it calls is already declared in obs-internal.h. No behavior change.
  2. test: characterize adds test_source_show_preloaded_video (cmocka, stack source fixtures under a started core without video): NULL source, destroying source and missing preload frame touch nothing; otherwise the preload frame's flip and alpha mode reach the upload state, the textures are marked fresh and the source active, and the audio timing restarts at one clock read (time zero for monitor-only) against last_frame_ts, with the audio buffer emptied and audio_ts placed by the sync and resample offsets; both mutexes are free afterwards.
  3. test: RED adds Tier 1 (obs_source::show_preloaded_video over a recording model: the order of every step, the graphics context's scope and each mutex's) against a todo!() core.
  4. obs-source: port implements the core and the export. Every step stays C behind the adapters in obs-source-show-preloaded-video-fields.c.h (declared in obs-internal.h; destroying() reuses obs_source_caption_callback_destroying()). The extracted C moves to the reference-only group libobs.ported-source-show-preloaded-video.

Tier 3 (show_preloaded_video_parity) compiles the original C and the production adapters into the oracle with the two mutexes, obs_enter/leave_graphics, set_async_texture_size, update_async_textures, os_atomic_set_bool, os_gettime_ns and the two audio resets routed through recorders. It compares the calls with their arguments, the diagnostic and the state left over 320 combinations (NULL source, destroying, preload, five monitoring types including out-of-range values, both flag states, edge timestamps) plus a proptest, pins the characterized sequence, and rejects four export mutants (no destroying check, clock read for monitor-only, unlocked last_frame_ts, active before the upload).

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

Evidence

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

soldr cargo test -p obs-data --test obs-tests-core show_preloaded_video
test result: FAILED. 0 passed; 7 failed; 0 ignored; 0 measured; 6834 filtered out

GREEN (commit 4):

soldr cargo test -p obs-data --test obs-tests-core show_preloaded_video
test result: ok. 11 passed; 0 failed; 0 ignored; 0 measured; 6834 filtered out; finished in 0.02s

Mutation check: swapping mark_textures_fresh/mark_active in the core fails matches_c_over_every_combination, pins_the_characterized_sequence and matches_c_on_random_states.

Tier 2 (OBS_CTEST_JOBS=10 uv run rust/tools/linux-validate/run.py --repeat 1 --tests 'test_source_show_preloaded_video|test_media_restart_stale_frame|test_media_sync_offset_restart'): 1121/1121 passed on the C reference and on hybrid libobs after rebasing onto #5761 (with test_source_frame_wrappers added to the repeat), then the repeated tests on each.

Registration: soldr cargo test -p obs-studio-rust --test obs-tests-app canonical_source_show_preloaded 1 passed. ./lint ok.

Test cost: the 11 Rust tests take 0.02 s in debug, 33 MB peak for the whole filtered run (the four parity tests run in isolated children, which own the log handler); no threads of their own.

🤖 Generated with Claude Code

@rdoupe
rdoupe requested a review from zackees as a code owner November 26, 2026 07:12
rdoupe and others added 4 commits November 26, 2026 02:13
Moves obs_source_show_preloaded_video() unchanged into
libobs/obs-source-show-preloaded-video.c.h in the live core-source group.
Everything it calls (destroying(), set_async_texture_size(),
update_async_textures(), reset_audio_timing() and
reset_audio_data_at_sys_time()) is already declared in obs-internal.h, so
nothing else moves. No behavior change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
test_source_show_preloaded_video runs on stack source fixtures under a
started core without video, against the hybrid libobs and the C reference:
a NULL source, a source being destroyed and a source without a preload
frame return with nothing touched; otherwise the preload frame's flip and
alpha mode are copied into the async upload state, the textures are marked
fresh and the source active, and the audio timing restarts at one clock
read (time zero for a monitor-only source) against last_frame_ts, with the
audio buffer emptied and audio_ts placed by the sync and resample offsets.
Both mutexes are free afterwards (probed from another thread, as they are
recursive).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Adds obs_source::show_preloaded_video (the Host trait over the source,
graphics, clock and audio operations, show_preloaded_video against todo!())
and its Tier 1 cases over a recording model, mirroring every
test_source_show_preloaded_video case plus the order of each step and the
scope of the graphics context and of each mutex: the NULL source
diagnostic, a destroying source and a missing preload frame left alone, the
texture update and the two flags inside graphics, last_frame_ts under
async_mutex, and the monitoring check, one clock read (none for a
monitor-only source) and the two audio resets under audio_buf_mutex.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The export runs the safe core obs_source::show_preloaded_video in the C's
order: a NULL source logs the obs_source_valid() line; a source being
destroyed or without a preload frame is left alone; otherwise, inside one
graphics context, set_async_texture_size() and update_async_textures() run
on the preload frame and the source's textures, async_textures_stale is
cleared and async_active set; then last_frame_ts is read under
async_mutex, and under audio_buf_mutex one clock read (none and time zero
for a monitor-only source) feeds reset_audio_timing() and
reset_audio_data_at_sys_time().

Every step stays C in obs-source-show-preloaded-video-fields.c.h, each
adapter the line it stands for; destroying() is the existing
obs_source_caption_callback_destroying(). The extracted C moves unchanged
to the reference-only group libobs.ported-source-show-preloaded-video.

Tier 3 runs the original C and the Rust export over real sources on the
same adapters, with the mutexes, the graphics context, the texture upload,
the flag stores, the clock and the audio resets recorded with their
arguments, and compares the calls, the diagnostic and the state left over
every combination of NULL source, destroying, preload frame, five
monitoring types, both flag states and edge timestamps, plus a proptest;
four export mutants are rejected.

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

Ci-Attestation: {"at":1795678481,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["3d16423b29bd028db6b20561ad2711192db21c26"],"secs":94,"stamp":"c2f45dcda0565837f3b8d755d43f4b02","tree":"fe769d4342c388802284f122cd816b941ffe4613","v":1,"via":"run"}
Ci-Attestation: {"at":1795678481,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["3d16423b29bd028db6b20561ad2711192db21c26"],"secs":94,"stamp":"35195a855811fccde6348a480f8c4cf8","tree":"fe769d4342c388802284f122cd816b941ffe4613","v":1,"via":"run"}
Ci-Attestation: {"at":1795678481,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["3d16423b29bd028db6b20561ad2711192db21c26"],"secs":94,"stamp":"5f25fb2990771dd1c9e0394481729afb","tree":"fe769d4342c388802284f122cd816b941ffe4613","v":1,"via":"run"}
Ci-Attestation: {"at":1795678481,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["3d16423b29bd028db6b20561ad2711192db21c26"],"secs":94,"stamp":"789e183249e3508042c6086d0439d154","tree":"fe769d4342c388802284f122cd816b941ffe4613","v":1,"via":"run"}
Ci-Attestation: {"at":1795678386,"gate":"general/all/client-lint","host":"linux-x86_64","key":"b1838118a739b9796cf9a0eb4d6d9e346596eada163455110d07c1e3fbd8d3eb","lane":"client-lint","parents":["3d16423b29bd028db6b20561ad2711192db21c26"],"secs":71,"stamp":"02d62de620d70e8686b9e71af755fac3","tree":"fe769d4342c388802284f122cd816b941ffe4613","v":1,"via":"run"}
Ci-Attestation: {"at":1795678481,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["3d16423b29bd028db6b20561ad2711192db21c26"],"secs":94,"stamp":"b5b2851a8591695f4bdd86a08f6b9b4d","tree":"fe769d4342c388802284f122cd816b941ffe4613","v":1,"via":"run"}
Ci-Attestation: {"at":1795678387,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"b1838118a739b9796cf9a0eb4d6d9e346596eada163455110d07c1e3fbd8d3eb","lane":"client-lint","parents":["3d16423b29bd028db6b20561ad2711192db21c26"],"secs":71,"stamp":"d21c2da4fff4a5b9a7c6874971634d51","tree":"fe769d4342c388802284f122cd816b941ffe4613","v":1,"via":"run"}
Ci-Attestation: {"at":1795678387,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"b1838118a739b9796cf9a0eb4d6d9e346596eada163455110d07c1e3fbd8d3eb","lane":"client-lint","parents":["3d16423b29bd028db6b20561ad2711192db21c26"],"secs":71,"stamp":"8520e6c38e3b502c407dea9c098ddb64","tree":"fe769d4342c388802284f122cd816b941ffe4613","v":1,"via":"run"}
Ci-Attestation: {"at":1795678387,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"b1838118a739b9796cf9a0eb4d6d9e346596eada163455110d07c1e3fbd8d3eb","lane":"client-lint","parents":["3d16423b29bd028db6b20561ad2711192db21c26"],"secs":71,"stamp":"b8153a0d3c16f93acd486f25709b692f","tree":"fe769d4342c388802284f122cd816b941ffe4613","v":1,"via":"run"}
Ci-Attestation: {"at":1795678387,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"b1838118a739b9796cf9a0eb4d6d9e346596eada163455110d07c1e3fbd8d3eb","lane":"client-lint","parents":["3d16423b29bd028db6b20561ad2711192db21c26"],"secs":71,"stamp":"58d6c21ad4570ef24b99f2f67f16d90f","tree":"fe769d4342c388802284f122cd816b941ffe4613","v":1,"via":"run"}
Ci-Attestation: {"at":1795678387,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"b1838118a739b9796cf9a0eb4d6d9e346596eada163455110d07c1e3fbd8d3eb","lane":"client-lint","parents":["3d16423b29bd028db6b20561ad2711192db21c26"],"secs":71,"stamp":"5f72f63033cd087d472263230b4b26a5","tree":"fe769d4342c388802284f122cd816b941ffe4613","v":1,"via":"run"}
Ci-Attestation: {"at":1795678387,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"b1838118a739b9796cf9a0eb4d6d9e346596eada163455110d07c1e3fbd8d3eb","lane":"client-lint","parents":["3d16423b29bd028db6b20561ad2711192db21c26"],"secs":71,"stamp":"c2f8eba01394a41f1015bf191c6423d2","tree":"fe769d4342c388802284f122cd816b941ffe4613","v":1,"via":"run"}
Ci-Attestation: {"at":1795678387,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"b1838118a739b9796cf9a0eb4d6d9e346596eada163455110d07c1e3fbd8d3eb","lane":"client-lint","parents":["3d16423b29bd028db6b20561ad2711192db21c26"],"secs":71,"stamp":"541a79ef2a3b55da880d80c0e168774b","tree":"fe769d4342c388802284f122cd816b941ffe4613","v":1,"via":"run"}
Ci-Attestation: {"at":1795678387,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"b1838118a739b9796cf9a0eb4d6d9e346596eada163455110d07c1e3fbd8d3eb","lane":"client-lint","parents":["3d16423b29bd028db6b20561ad2711192db21c26"],"secs":71,"stamp":"007e224c1798d0aaa9e410e133a025bd","tree":"fe769d4342c388802284f122cd816b941ffe4613","v":1,"via":"run"}
Ci-Attestation: {"at":1795678387,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"b1838118a739b9796cf9a0eb4d6d9e346596eada163455110d07c1e3fbd8d3eb","lane":"client-lint","parents":["3d16423b29bd028db6b20561ad2711192db21c26"],"secs":71,"stamp":"858f9047cf7f8933ccfb62b35e7de21f","tree":"fe769d4342c388802284f122cd816b941ffe4613","v":1,"via":"run"}
Ci-Attestation: {"at":1795678387,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"b1838118a739b9796cf9a0eb4d6d9e346596eada163455110d07c1e3fbd8d3eb","lane":"client-lint","parents":["3d16423b29bd028db6b20561ad2711192db21c26"],"secs":71,"stamp":"a160f470d9a2523369130d592e6d9fc6","tree":"fe769d4342c388802284f122cd816b941ffe4613","v":1,"via":"run"}
Ci-Attestation: {"at":1795678386,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"b1838118a739b9796cf9a0eb4d6d9e346596eada163455110d07c1e3fbd8d3eb","lane":"client-lint","parents":["3d16423b29bd028db6b20561ad2711192db21c26"],"secs":71,"stamp":"25e29cd01361e4f73a061fefd637fc36","tree":"fe769d4342c388802284f122cd816b941ffe4613","v":1,"via":"run"}
Ci-Attestation: {"at":1795678387,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"b1838118a739b9796cf9a0eb4d6d9e346596eada163455110d07c1e3fbd8d3eb","lane":"client-lint","parents":["3d16423b29bd028db6b20561ad2711192db21c26"],"secs":71,"stamp":"d52d14b1dc8802483c41eea4b17c959a","tree":"fe769d4342c388802284f122cd816b941ffe4613","v":1,"via":"run"}
Ci-Attestation: {"at":1795678721,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"c20ae8e0c3d243bc49f49dff320a76a2b097f2a2f72d341c94198110fae5ea24","lane":"client-test-x86_64-unknown-linux-gnu","parents":["3d16423b29bd028db6b20561ad2711192db21c26"],"secs":239,"stamp":"010f5a95132f9c527a1e1d40b62e22fb","tree":"fe769d4342c388802284f122cd816b941ffe4613","v":1,"via":"run"}

Client-Checks: {"checks":{"base":"8a8e7b63feb4fce649904a2bd30152463438d087","coverage":"all-tracked-applicable-files","diff":["libobs/build/libobs.core-source+.h.c","libobs/build/libobs.ported-source-show-preloaded-video+.h.c","libobs/build/ported-source-sets/source-show-preloaded-video.json","libobs/cmake/rust-exports.d/obs-source-source_show_preloaded_video.txt","libobs/obs-internal.h","libobs/obs-source-show-preloaded-video-fields.c.h","libobs/obs-source-show-preloaded-video.c.h","libobs/obs-source.c.h","rust/README.md","rust/obs-build/tests/native.rs","rust/obs-build/tests/native/registration/canonical_source_show_preloaded_video_swap_is_registered.rs","rust/obs-c-oracle/oracle.d/source-show-preloaded-video.list","rust/obs-c-oracle/oracle/source_show_preloaded_video.c","rust/obs-source/Cargo.toml","rust/obs-source/src/ffi/mod.rs","rust/obs-source/src/ffi/source_show_preloaded_video.rs","rust/obs-source/src/lib.rs","rust/obs-source/src/show_preloaded_video.rs","rust/obs-source/tests/source/main.rs","rust/obs-source/tests/source/show_preloaded_video.rs","rust/obs-source/tests/source/show_preloaded_video_parity.rs","test/cmocka/build/test-graph.json","test/cmocka/test_source_show_preloaded_video.c","test/cmocka/tests.d/test_source_show_preloaded_video.cmake"],"head":"5667be60d596062ee1a147f7f8def4571ea52dae","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":"dbb28fd457e8e4d76a107f40b822ec208a4b1115fc5b06582572ff6c85798fad","tree":"fe769d4342c388802284f122cd816b941ffe4613"}}
@rdoupe
rdoupe force-pushed the port/5762-show-preloaded-video branch from dd32bf1 to eb67798 Compare November 26, 2026 07:38
@rdoupe
rdoupe enabled auto-merge November 26, 2026 07:39
@rdoupe
rdoupe added this pull request to the merge queue Nov 26, 2026
Merged via the queue into master with commit 152c528 Nov 26, 2026
47 checks passed
@rdoupe
rdoupe deleted the port/5762-show-preloaded-video branch November 26, 2026 08:54
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_show_preloaded_video to obs-source

1 participant