Skip to content

obs-source: port process_media_actions to Rust (Fixes #5902) - #5907

Merged
zackees merged 4 commits into
masterfrom
port/5902-media-actions
Nov 29, 2026
Merged

zackees merged 4 commits into
masterfrom
port/5902-media-actions

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 28, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #5902.

Ports process_media_actions(), the drain of a source's media action queue that obs_source_video_tick() runs once per tick for a source with OBS_SOURCE_CONTROLLABLE_MEDIA, to obs-source. It is the last C step of the media control path: the obs_source_media_* calls that fill the queue are Rust since #5617, and the dispatch and signal decisions it asks are Rust since #2257. Same shape as #5900.

Commits, in order:

  1. Extract verbatim (libobs: extract ...): the function moves unchanged into libobs/obs-source-media-actions.c.h, still in the live core-source group; obs-source.c.h keeps its prototype for obs_source_video_tick(). No behavior change.
  2. Characterize (Tier 2): new test_source_media_actions. The drain and obs_source_video_tick() are both hidden, so the test goes through the core's video thread, like test_source_video_tick_callbacks: a tick callback queues a batch for a public controllable source, and the same frame's tick drains it. It pins: every action in one tick, oldest first; each callback with the source's data (pause / ms) and then its signal (media_pause/media_play, media_restart, media_stopped, media_next, media_previous; none for set-time) on the source's own handler, with only source in a fixed 128-byte calldata; callbacks and signals on the video thread with media_actions_mutex released, so actions queued from a callback or a signal handler run in the same tick; an out-of-enum type dropped with no call or signal; a MEDIA_ACTION_NONE mid-queue ends the tick and the rest run on the next one. Linux with OpenGL, under xvfb-run.
  3. RED: safe core media_actions::process over a Source trait (pop, six callbacks, signal), stubbed todo!(), with Tier 1 tests in obs-source's existing source test binary (no new test binary).
  4. GREEN: the core and a hidden shim (rust-hidden.d; no EXPORT). The locked pop (the original lock / copy / pop / unlock, reading only the union member the type uses), the six info.media_* calls with context.data and obs_source_dosignal(source, NULL, ...) stay C in the new obs-source-media-actions-fields.c.h (live group, no EXPORT). The extracted C moves to the reference-only group libobs.ported-source-media-actions.

Tier 3, new media_actions_parity: the original C (compiled from the extracted file with the original C dispatch and signal steps) and the Rust shim run on a noise-filled real-header source with a real queue and a real signal handler. Every lock and unlock of the queue mutex (with the queue length), every callback (data pointer and argument) and every signal (name and calldata shape) is recorded in order and must match, as must the queue left behind and every other byte of the source. Cases: empty queue, each action type alone (including i64::MIN/MAX times and out-of-enum types) under three noise fills, NONE mid-queue, actions queued from the restart callback or the media_restart signal, and a proptest over queues of up to 16 entries. The oracle uses a stand-in for obs_source_dosignal() with the same body minus the obs->signals branch (the core global can't be linked there; both sides pass NULL for it, and a non-NULL name would be recorded). Registration test canonical_source_media_actions_swap_is_registered.

No intentional differences; Tier 4 does not apply. Not user-visible, so no features.md line.

Evidence

RED, at the RED commit 2d8ad84:

soldr cargo test -p obs-data --test obs-tests-core media_actions::
test result: FAILED. 0 passed; 6 failed   (each panics in the todo!())

GREEN, at the head 70a026f (on 13854a4):

soldr cargo test -p obs-data --test obs-tests-core media_actions
test result: ok. 11 passed; 0 failed      (6 Tier 1 + 5 Tier 3)
soldr cargo test -p obs-studio-rust --test obs-tests-app canonical_source_media_actions
test result: ok. 1 passed; 0 failed
soldr cargo test -p obs-util --lib export_list
test result: ok. 4 passed; 0 failed

Mutation check on the Tier 3 parity (each run alone, then restored): Skip returning instead of continuing, stop not called, pause inverted for the signal, the signal emitted twice, and the shim's next calling the previous adapter all fail it (3-4 of 5 tests each); an identity edit passes 5/5.

Tier 2 (cmocka against hybrid libobs and the C reference). The characterization at d79577f, run in the kept build volume under xvfb-run -a: [ PASSED ] 4 test(s) on both libraries, none skipped. On the GREEN commit:

OBS_CTEST_JOBS=10 uv run rust/tools/linux-validate/run.py --repeat 5 --tests 'test_source_media_actions|test_source_media_controls|test_media_play_after_stop'
ported C objects excluded from production libobs: 653 (one more than before)
libobs exported symbols, C vs Rust: IDENTICAL (1769 symbols)
[OFF] 100% tests passed, 0 tests failed out of 1147; the three media tests 5/5
[ON]  100% tests passed, 0 tests failed out of 1147; the three media tests 5/5

./lint: == lane lint: ok.

Test cost: new tests (6 Tier 1 incl. one proptest, 5 Tier 3 incl. one proptest, 1 registration): the media_actions filter finishes in 0.06 s in the debug build (0.01 s with OBS_PARITY_CASES=reduced); peak RSS 15.4 MB over 20 runs of the filtered binary (systemd-run MemoryAccounting); no threads of their own. The new cmocka test runs 0.70 s in ctest (a few 60 fps frames per case).

🤖 Generated with Claude Code

@rdoupe
rdoupe requested a review from zackees as a code owner November 28, 2026 21:01
@zackees
zackees force-pushed the port/5902-media-actions branch from 70a026f to 2b2075d Compare November 28, 2026 21:22
@zackees

zackees commented Nov 28, 2026

Copy link
Copy Markdown
Member

Coordinator rebase 2b2075d. The usual rust/obs-source/Cargo.toml description conflict, this time against #5900's push-to-enable-signal entry. I kept both and added media-actions after media-admission. No code changed. Review: it has Tier 2 cmocka, Tier 3 parity against the oracle, and a Test cost line, so it's set to auto-merge.

@zackees
zackees enabled auto-merge November 28, 2026 21:22
@rdoupe

rdoupe commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator Author

Checked the rebase locally on the same tree (identical apart from the word order in the description line): soldr cargo test -p obs-data --test obs-tests-core media_actions 11 passed, soldr cargo test -p obs-studio-rust --test obs-tests-app canonical_source_media_actions 1 passed, soldr cargo test -p obs-util --lib export_list 4 passed, and soldr cargo clippy --workspace --all-targets --locked -- -D warnings clean.

@zackees zackees left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coordinator review: LGTM. It follows the #5889 shape: a verbatim extraction of process_media_actions, the cmocka characterization, Tier 1 RED before GREEN, and Tier 3 parity (media_actions_parity.rs) against the oracle. No C test or public header is edited, and it has a Test cost line. It's already on auto-merge.

@zackees
zackees added this pull request to the merge queue Nov 28, 2026
@zackees
zackees removed this pull request from the merge queue due to a manual request Nov 28, 2026
@rdoupe
rdoupe added this pull request to the merge queue Nov 28, 2026
@rdoupe
rdoupe removed this pull request from the merge queue due to a manual request Nov 29, 2026
@rdoupe
rdoupe force-pushed the port/5902-media-actions branch from 2b2075d to 3ac2df6 Compare November 29, 2026 00:22
@rdoupe
rdoupe enabled auto-merge November 29, 2026 00:22
@zackees

zackees commented Nov 29, 2026

Copy link
Copy Markdown
Member

Coordinator: I took this out of the queue, since it collided with #5898 on the rust/obs-source/Cargo.toml description line. #5912 replaces that line with a fixed summary and adds ci/test_crate_descriptions.py, so ports no longer append to it. Once #5912 lands I'll rebase this PR by taking master's short line and dropping the media-actions entry; rust/README.md keeps the per-file record. That's the last conflict of this kind.

@rdoupe
rdoupe added this pull request to the merge queue Nov 29, 2026
@zackees
zackees removed this pull request from the merge queue due to a manual request Nov 29, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this to Ready to merge in obs-rust Multiview Nov 29, 2026
@obs-rust-ai-rebase

obs-rust-ai-rebase Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

ai-rebase: skipped skipped: worker active

rdoupe and others added 4 commits November 28, 2026 18:22
Move process_media_actions() out of obs-source.c.h into
obs-source-media-actions.c.h, unchanged, in the live core-source group.
obs_source_video_tick() keeps calling it through the prototype left in
obs-source.c.h. No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
process_media_actions() and obs_source_video_tick() are hidden, so the
test reaches them through the core's video thread: a tick callback queues
a batch for a public CONTROLLABLE_MEDIA source, which the same frame's tick
drains. One tick runs every action oldest first, each callback with the
source's data and then its signal (none for set-time) on the source's own
handler, with only "source" in a fixed 128-byte calldata; callbacks and
signals run on the video thread with media_actions_mutex released, so what
they queue runs in the same tick; a type outside the enum is dropped and a
MEDIA_ACTION_NONE ends the tick with the rest left for the next. Linux
with OpenGL, under xvfb-run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A model of the queue, the six callbacks and the signal pins the cases of
test_source_media_actions: every queued action in one tick, oldest first,
callback then signal (none for set-time); actions queued from a callback
or a signal run in the same tick; out-of-enum types are dropped and a
MEDIA_ACTION_NONE ends the tick with the rest left; pause is read only for
play/pause; plus a proptest over any queue. The core is a stub, so all six
fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Swap process_media_actions() in hybrid libobs for a safe Rust core over a
Source trait: until the queue is empty, take the front action off under
media_actions_mutex (released before anything else runs), ask
media_admission for the step, call the matching info.media_* callback with
context.data, then emit its signal on the source's own handler; a
MEDIA_ACTION_NONE ends the tick and an out-of-enum type is dropped. The
locked pop (reading only the union member the type uses), the six
callback calls and obs_source_dosignal() stay behind
obs-source-media-actions-fields.c.h (live group, no EXPORT); the shim is
hidden through rust-hidden.d, and the original moves to the ported group
for the C reference.

Tier 3 runs the original C (with the original dispatch and signal steps)
and the Rust shim on a noise-filled real-header source with a real queue
and signal handler, comparing every lock and unlock, callback and signal
in order, the queue left and every other byte, over each action alone, a
NONE mid-queue, actions queued from a callback or a signal and a
proptest, and rejects five mutants. No intentional differences.

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

Ci-Attestation: {"at":1795911536,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["5a1a93468b6b451d53b1cbd844584f0df23e8d9f"],"secs":76,"stamp":"b38f9bb9f63f49258df1156e40dbe406","tree":"83c04bd6e8cfaa2ec0d4e9c5853efbe4424febff","v":1,"via":"run"}
Ci-Attestation: {"at":1795911536,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["5a1a93468b6b451d53b1cbd844584f0df23e8d9f"],"secs":76,"stamp":"aeb777051e14a629b8c233d8c10e2fc9","tree":"83c04bd6e8cfaa2ec0d4e9c5853efbe4424febff","v":1,"via":"run"}
Ci-Attestation: {"at":1795911536,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["5a1a93468b6b451d53b1cbd844584f0df23e8d9f"],"secs":76,"stamp":"7c06d231c7dbd81f9581a38d22207031","tree":"83c04bd6e8cfaa2ec0d4e9c5853efbe4424febff","v":1,"via":"run"}
Ci-Attestation: {"at":1795911536,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["5a1a93468b6b451d53b1cbd844584f0df23e8d9f"],"secs":76,"stamp":"f170e6a9ad94f96ffeb567720605cd43","tree":"83c04bd6e8cfaa2ec0d4e9c5853efbe4424febff","v":1,"via":"run"}
Ci-Attestation: {"at":1795911459,"gate":"general/all/client-lint","host":"linux-x86_64","key":"871c8527c0f29193c96c7ac9f958dc362e92fce32a2b52b66435be1910677feb","lane":"client-lint","parents":["5a1a93468b6b451d53b1cbd844584f0df23e8d9f"],"secs":9,"stamp":"fe3d009e92731a7445efbe65123e4b1c","tree":"83c04bd6e8cfaa2ec0d4e9c5853efbe4424febff","v":1,"via":"run"}
Ci-Attestation: {"at":1795911536,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["5a1a93468b6b451d53b1cbd844584f0df23e8d9f"],"secs":76,"stamp":"fad11009648ebe71595478764dc4e1e7","tree":"83c04bd6e8cfaa2ec0d4e9c5853efbe4424febff","v":1,"via":"run"}
Ci-Attestation: {"at":1795911459,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"871c8527c0f29193c96c7ac9f958dc362e92fce32a2b52b66435be1910677feb","lane":"client-lint","parents":["5a1a93468b6b451d53b1cbd844584f0df23e8d9f"],"secs":9,"stamp":"6820bd2eabbdb24910de6a83a26879b4","tree":"83c04bd6e8cfaa2ec0d4e9c5853efbe4424febff","v":1,"via":"run"}
Ci-Attestation: {"at":1795911460,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"871c8527c0f29193c96c7ac9f958dc362e92fce32a2b52b66435be1910677feb","lane":"client-lint","parents":["5a1a93468b6b451d53b1cbd844584f0df23e8d9f"],"secs":9,"stamp":"22ac5e4843694087b2fe861876583764","tree":"83c04bd6e8cfaa2ec0d4e9c5853efbe4424febff","v":1,"via":"run"}
Ci-Attestation: {"at":1795911459,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"871c8527c0f29193c96c7ac9f958dc362e92fce32a2b52b66435be1910677feb","lane":"client-lint","parents":["5a1a93468b6b451d53b1cbd844584f0df23e8d9f"],"secs":9,"stamp":"da73f7fd896b4a601668b6a9003b4753","tree":"83c04bd6e8cfaa2ec0d4e9c5853efbe4424febff","v":1,"via":"run"}
Ci-Attestation: {"at":1795911459,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"871c8527c0f29193c96c7ac9f958dc362e92fce32a2b52b66435be1910677feb","lane":"client-lint","parents":["5a1a93468b6b451d53b1cbd844584f0df23e8d9f"],"secs":9,"stamp":"5ccb57a81b5fa2cf959f942c8c54734d","tree":"83c04bd6e8cfaa2ec0d4e9c5853efbe4424febff","v":1,"via":"run"}
Ci-Attestation: {"at":1795911459,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"871c8527c0f29193c96c7ac9f958dc362e92fce32a2b52b66435be1910677feb","lane":"client-lint","parents":["5a1a93468b6b451d53b1cbd844584f0df23e8d9f"],"secs":9,"stamp":"ce3db09b17b65fd8688dff51e337ce9c","tree":"83c04bd6e8cfaa2ec0d4e9c5853efbe4424febff","v":1,"via":"run"}
Ci-Attestation: {"at":1795911459,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"871c8527c0f29193c96c7ac9f958dc362e92fce32a2b52b66435be1910677feb","lane":"client-lint","parents":["5a1a93468b6b451d53b1cbd844584f0df23e8d9f"],"secs":9,"stamp":"0b6d0b624a72b44dd28904de0c8dd255","tree":"83c04bd6e8cfaa2ec0d4e9c5853efbe4424febff","v":1,"via":"run"}
Ci-Attestation: {"at":1795911459,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"871c8527c0f29193c96c7ac9f958dc362e92fce32a2b52b66435be1910677feb","lane":"client-lint","parents":["5a1a93468b6b451d53b1cbd844584f0df23e8d9f"],"secs":9,"stamp":"bce3fd3843becb66c4ff9e872751d8b4","tree":"83c04bd6e8cfaa2ec0d4e9c5853efbe4424febff","v":1,"via":"run"}
Ci-Attestation: {"at":1795911459,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"871c8527c0f29193c96c7ac9f958dc362e92fce32a2b52b66435be1910677feb","lane":"client-lint","parents":["5a1a93468b6b451d53b1cbd844584f0df23e8d9f"],"secs":9,"stamp":"863ebc0219f344b2f2b2a2e0d2a5c3e0","tree":"83c04bd6e8cfaa2ec0d4e9c5853efbe4424febff","v":1,"via":"run"}
Ci-Attestation: {"at":1795911459,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"871c8527c0f29193c96c7ac9f958dc362e92fce32a2b52b66435be1910677feb","lane":"client-lint","parents":["5a1a93468b6b451d53b1cbd844584f0df23e8d9f"],"secs":9,"stamp":"1e40cda8107afddf487a8aa0a708091e","tree":"83c04bd6e8cfaa2ec0d4e9c5853efbe4424febff","v":1,"via":"run"}
Ci-Attestation: {"at":1795911459,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"871c8527c0f29193c96c7ac9f958dc362e92fce32a2b52b66435be1910677feb","lane":"client-lint","parents":["5a1a93468b6b451d53b1cbd844584f0df23e8d9f"],"secs":9,"stamp":"12269ec370f6380c2ecd8b64f3fc84a6","tree":"83c04bd6e8cfaa2ec0d4e9c5853efbe4424febff","v":1,"via":"run"}
Ci-Attestation: {"at":1795911459,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"871c8527c0f29193c96c7ac9f958dc362e92fce32a2b52b66435be1910677feb","lane":"client-lint","parents":["5a1a93468b6b451d53b1cbd844584f0df23e8d9f"],"secs":9,"stamp":"9b3bff5775f13a6c66b3e7b8c1cdf9b7","tree":"83c04bd6e8cfaa2ec0d4e9c5853efbe4424febff","v":1,"via":"run"}
Ci-Attestation: {"at":1795911459,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"871c8527c0f29193c96c7ac9f958dc362e92fce32a2b52b66435be1910677feb","lane":"client-lint","parents":["5a1a93468b6b451d53b1cbd844584f0df23e8d9f"],"secs":9,"stamp":"143796daffb81219a3d8b1fe81bf34d3","tree":"83c04bd6e8cfaa2ec0d4e9c5853efbe4424febff","v":1,"via":"run"}
Ci-Attestation: {"at":1795911748,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"166d7a4df29656d7ac9c2bf63e4f2d5e23e7702c16e09997767b2fd1f35753a2","lane":"client-test-x86_64-unknown-linux-gnu","parents":["5a1a93468b6b451d53b1cbd844584f0df23e8d9f"],"secs":212,"stamp":"9b58132e4be4ad8485689bdbba8987de","tree":"83c04bd6e8cfaa2ec0d4e9c5853efbe4424febff","v":1,"via":"run"}

Client-Checks: {"checks":{"base":"e5ca61531cc08ea6d160d8a3e10cf1f98cf55526","coverage":"all-tracked-applicable-files","diff":["libobs/build/libobs.core-source+.h.c","libobs/build/libobs.ported-source-media-actions+.h.c","libobs/build/ported-source-sets/source-media-actions.json","libobs/cmake/rust-hidden.d/obs-source-source_media_actions.txt","libobs/obs-source-media-actions-fields.c.h","libobs/obs-source-media-actions.c.h","libobs/obs-source.c.h","rust/README.md","rust/obs-build/tests/native.rs","rust/obs-build/tests/native/registration/canonical_source_media_actions_swap_is_registered.rs","rust/obs-c-oracle/oracle.d/source-media-actions.list","rust/obs-c-oracle/oracle/source_media_actions.c","rust/obs-source/Cargo.toml","rust/obs-source/src/ffi/mod.rs","rust/obs-source/src/ffi/source_media_actions.rs","rust/obs-source/src/lib.rs","rust/obs-source/src/media_actions.rs","rust/obs-source/src/media_controls.rs","rust/obs-source/tests/source/main.rs","rust/obs-source/tests/source/media_actions.rs","rust/obs-source/tests/source/media_actions_parity.rs","test/cmocka/build/test-graph.json","test/cmocka/test_source_media_actions.c","test/cmocka/tests.d/test_source_media_actions.cmake"],"head":"413d21381daece99d153fbc9cb046a92029dd8e5","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":"d9dbe229a19c1924c357951f3346e2e40a9e38a50b037ebc140c6d2882a47642","tree":"83c04bd6e8cfaa2ec0d4e9c5853efbe4424febff"}}
@zackees
zackees force-pushed the port/5902-media-actions branch from 3ac2df6 to 0096645 Compare November 29, 2026 02:23
@zackees

zackees commented Nov 29, 2026

Copy link
Copy Markdown
Member

Coordinator rebase onto master after #5912: rust/obs-source/Cargo.toml's description is now a fixed summary (guarded by ci/test_crate_descriptions.py), so I took master's line and dropped this PR's entry. rust/README.md keeps the per-file record. Nothing else in Cargo.toml changed, and the rest of the rebase was clean. Future ports don't touch that line.

@zackees
zackees enabled auto-merge November 29, 2026 02:23
@zackees
zackees added this pull request to the merge queue Nov 29, 2026
Merged via the queue into master with commit bcaa2f7 Nov 29, 2026
98 of 101 checks passed
@zackees
zackees deleted the port/5902-media-actions branch November 29, 2026 04:11
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Ready to merge to Done in obs-rust Multiview Nov 29, 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 process_media_actions (the media action queue drain) to obs-source

2 participants