Skip to content

obs-output: swap encoder group started count to safe Rust (Refs #5319) - #5375

Merged
rdoupe merged 2 commits into
masterfrom
port/5319-encoder-group-num-started
Nov 21, 2026
Merged

rdoupe merged 2 commits into
masterfrom
port/5319-encoder-group-num-started

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #5319

Swaps the hidden accessor obs_encoder_group_num_started (obs-internal.h, no EXPORT) into obs-output. Rust owns the decision: the group's mutex is taken once, num_encoders_started is read once while it is held, and the mutex is released once, so the value seen under the lock comes back over the full uint32_t range. The group is never NULL (the C precondition, kept). The mutex and the count stay in C behind three private adapters (libobs/obs-encoder-group-num-started-fields.c.h), so Rust never sees the group layout or its pthread mutex. The original moves to libobs.ported-encoder-group-num-started for the C reference. No intentional behavior differences. Not user-visible, so no features-ledger line.

Inventory (callers and same-name fakes)

  • Production callers obs-encoder-set-group.c.h and obs-output-interleave.c.h are C inside libobs and now resolve to the hidden Rust export. The Rust interleaver's import (rust/obs-output/src/ffi/output_interleave.rs) is unchanged.
  • test/cmocka/output_interleave_fields_stub.c defines the name for test_output_interleave, which never links libobs_rust-static. It stays as it is, and a registration test pins that no target compiles the stub together with the Rust archive.
  • rust/obs-output/tests/output/interleave_parity.rs had its own #[no_mangle] copy of the name, which would collide with the export in obs-tests-core. It now reaches its groups through the real shim: the oracle has one definition of each adapter, and it forwards any group it does not own to per-thread handlers that the interleave fixture installs (oracle_encoder_group_num_started_foreign, the scene_enum_items.c shape). The recorded NumStarted event is unchanged, and the handlers also check that the read happens under the group lock.
  • rust/obs-c-oracle/benches/port_comparison.rs: the abort stand-in is dropped, along with its entry in ci/test_bench_libobs_stand_ins.py, because a workspace crate now exports the name. The oracle defines the adapters there.
  • Rust-static support: only the unchanged characterization compiled the original, and no Rust-static consumer defines the name or needs the adapters. So no shared support member is added (no placeholders).

Darwin fixture binding (#5226)

The shim is hidden in both libraries and the adapters are never exported, so libobs.dylib can bind neither of them for the twin. From the cross-linked Mach-O artifacts of ci/windows_link_check.py:

  • hybrid obs.dylib: llvm-nm -gU lists 1,904 exports and 0 *group_num_started* names; _obs_encoder_group_num_started and the three adapters are non-external (was a private external).
  • test_encoder_group_num_started_rust (arm64): _obs_encoder_group_num_started is defined locally (from the Rust archive). Its disassembly calls the local _obs_encoder_group_num_started_{lock,read,unlock}; lock and unlock branch to the test's _encoder_group_count_record_{lock,unlock}, and read is ldr w0, [x0, #0x60].

A registration test pins the source side: the name is in rust-hidden.d, it is in no rust-exports.d fragment, the adapters have no EXPORT, and the twin keeps the C target's recorder definitions.

RED (857bf31)

Tier 1 mirrors every assertion of test_encoder_group_num_started.c: one lock and one unlock of the selected group's mutex, never nested; the exact count for 0, 1, 2, 32, UINT32_MAX - 1 and UINT32_MAX with the complement in the other group; unrelated lifecycle state set and nothing changed; the snapshot under the lock returned and the unlock's value left. It adds the lock, read, unlock order and a proptest, all run against a todo!() core. Tier 3 runs the original and a not-exported stub on two recording fixture groups (oracle encoder_group_num_started.c). It compares the result, each lock and unlock, and both groups byte for byte, with the count rewritten in the lock and/or the unlock. It also includes real-header layout and adapter checks, and these mutants: read before the lock, read after the unlock, no lock, no unlock, count clamped to i32::MAX and to 16 bits.

soldr cargo test -p obs-data --test obs-tests-core -- output::encoder_group_num_started
test result: FAILED. 3 passed; 6 failed

(The 3 passes are the layout/adapter check, the original's characterization and the mutant check, which exercise only the C side.)

GREEN (b8329ce)

soldr cargo test -p obs-data --test obs-tests-core -- output::encoder_group_num_started output::interleave
test result: ok. 74 passed; 0 failed

soldr cargo test -p obs-studio-rust --test obs-tests-app -- native_build::canonical_encoder_group_num_started native_build::rust_static native_build::canonical_encoder_outputs
test result: ok. 8 passed; 0 failed

uv run --no-project -m unittest ci/test_bench_libobs_stand_ins.py
OK (3 tests)
  • Tier 2 (OBS_CTEST_JOBS=10 uv run rust/tools/linux-validate/run.py --repeat 1 --tests 'encoder_group|output_interleave'): exported symbols C vs Rust IDENTICAL (1769). OFF/C reference: 1064/1064 passed, repeat 11/11. ON/hybrid: 1064/1064 passed, repeat 11/11. I ran the binaries from the kept volume directly to prove the cases ran rather than skipped. On both libobs and libobs-c-reference: test_encoder_group_num_started 2 passed, test_encoder_group_num_started_rust 2 passed, test_output_interleave 30 passed, test_encoder_group_move 4 passed.
  • uv run --no-project ci/windows_link_check.py: all category binaries linked, and the Windows MSVC and Darwin hybrid libobs plus every configured *_rust fixture, including test_encoder_group_num_started_rust, linked as well (link only, nothing executed).
  • ./lint: ok.

Test cost: the 9 new tests together take under 0.01 s at OBS_PARITY_CASES=reduced in the debug build. Peak RSS for the module is 37 MB over 21 runs. They start no threads of their own.

./push: client-lint (six-target clippy and Dylint) ok, client-test ok; the optional Swift lane is not available here, and the head is unsigned, so the regular PR checks run.

Not verified locally: running natively on macOS or Windows (CI runs those).

🤖 Generated with Claude Code

rdoupe and others added 2 commits November 20, 2026 20:29
… (Refs #5319)

Safe Rust mirrors of every assertion of the unchanged
test_encoder_group_num_started.c on two recording groups (one lock and one
unlock of the selected group's mutex, never nested; the exact count over
the full u32 range, UINT32_MAX included, for the queried group and its
complement for the other, with unrelated lifecycle state set and nothing
changed; the value seen under the lock returned and the unlock's value
left), plus the lock/read/unlock order and a proptest over any count and
any rewrite in the lock or the unlock, against a todo!() core.

Tier 3: the original obs-encoder-group-num-started.c.h and the new private
adapters (obs-encoder-group-num-started-fields.c.h, beside the original in
the core-output group) on two recording fixture groups in the oracle,
comparing the result, every lock and unlock, and both groups byte for byte,
with the count rewritten by the lock and/or the unlock, against a
not-exported shim stub. The real-header layout and the adapters are
checked; mutants (read before the lock, read after the unlock, no lock, no
unlock, count clamped to i32::MAX or 16 bits) are caught.

    soldr cargo test -p obs-data --test obs-tests-core -- output::encoder_group_num_started
    test result: FAILED. 3 passed; 6 failed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
obs_encoder_group_num_started (hidden, obs-internal.h) now comes from
obs-output. Rust owns the decision: the group's mutex is taken once,
num_encoders_started read once while it is held, and the mutex released
once, so the value seen under the lock is returned over the full uint32_t
range. The group is never NULL (the C precondition, kept). The mutex and
the count stay in C behind private adapters
(obs-encoder-group-num-started-fields.c.h); Rust never sees the group
layout or its pthread mutex. The original moves to
libobs.ported-encoder-group-num-started for the C reference.

Tier 2: the unchanged test_encoder_group_num_started keeps testing the C
source; its twin test_encoder_group_num_started_rust compiles the same
fixture with the same recorder definitions, without the original, and runs
its assertions on the Rust shim through the real adapters. No other target
compiled the original, and the only other C definition of the name
(output_interleave_fields_stub.c, test_output_interleave) never links the
Rust archive, so no shared Rust-static support member is needed. The shim
is hidden in both libraries and the adapters are never exported, so on
Darwin the twin cannot bind either name to libobs.dylib (#5226); the
registration test pins that.

Same-name fakes: the interleave parity fixture's own definition of the name
would collide with the export in obs-tests-core, so it now reaches its
groups through the real shim; the oracle's single definition of each
adapter forwards groups that are not its own to per-thread handlers the
fixture installs. The bench's abort stand-in is dropped (and from
ci/test_bench_libobs_stand_ins.py); the oracle defines the adapters there.

    soldr cargo test -p obs-data --test obs-tests-core -- output::encoder_group_num_started output::interleave
    test result: ok. 74 passed; 0 failed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ci-Attestation: {"at":1795224770,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["857bf31451adab51b0e4e9a2bf3a3dfccc75121c"],"secs":95,"stamp":"fc03d1ed07056a4bad07c36a4ef62653","tree":"d384a14b382f130096df19d4bb7b109e6b779b95","v":1,"via":"run"}
Ci-Attestation: {"at":1795224770,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["857bf31451adab51b0e4e9a2bf3a3dfccc75121c"],"secs":95,"stamp":"cc5d0456b85468f08c5b26bf70ddac65","tree":"d384a14b382f130096df19d4bb7b109e6b779b95","v":1,"via":"run"}
Ci-Attestation: {"at":1795224770,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["857bf31451adab51b0e4e9a2bf3a3dfccc75121c"],"secs":95,"stamp":"109c469bba06e99c5deccc9d767df8a4","tree":"d384a14b382f130096df19d4bb7b109e6b779b95","v":1,"via":"run"}
Ci-Attestation: {"at":1795224770,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["857bf31451adab51b0e4e9a2bf3a3dfccc75121c"],"secs":95,"stamp":"d6ad03e5cc7ba98a1e27e14426c3549f","tree":"d384a14b382f130096df19d4bb7b109e6b779b95","v":1,"via":"run"}
Ci-Attestation: {"at":1795224675,"gate":"general/all/client-lint","host":"linux-x86_64","key":"2db147e7a0cfa82a5ad543a99845b7a73ed6e1b8452607d4b943b88a0eefd017","lane":"client-lint","parents":["857bf31451adab51b0e4e9a2bf3a3dfccc75121c"],"secs":103,"stamp":"09f0a34ae0a43afb576f2144300a604e","tree":"d384a14b382f130096df19d4bb7b109e6b779b95","v":1,"via":"run"}
Ci-Attestation: {"at":1795224770,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["857bf31451adab51b0e4e9a2bf3a3dfccc75121c"],"secs":95,"stamp":"8f7161e8547866cd88bb8f965b4f3672","tree":"d384a14b382f130096df19d4bb7b109e6b779b95","v":1,"via":"run"}
Ci-Attestation: {"at":1795224675,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"2db147e7a0cfa82a5ad543a99845b7a73ed6e1b8452607d4b943b88a0eefd017","lane":"client-lint","parents":["857bf31451adab51b0e4e9a2bf3a3dfccc75121c"],"secs":103,"stamp":"28de048c7adf743e50abda3a52481dd0","tree":"d384a14b382f130096df19d4bb7b109e6b779b95","v":1,"via":"run"}
Ci-Attestation: {"at":1795224675,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"2db147e7a0cfa82a5ad543a99845b7a73ed6e1b8452607d4b943b88a0eefd017","lane":"client-lint","parents":["857bf31451adab51b0e4e9a2bf3a3dfccc75121c"],"secs":103,"stamp":"a623681cb5e0c33d4fd1603df36bfb3d","tree":"d384a14b382f130096df19d4bb7b109e6b779b95","v":1,"via":"run"}
Ci-Attestation: {"at":1795224675,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"2db147e7a0cfa82a5ad543a99845b7a73ed6e1b8452607d4b943b88a0eefd017","lane":"client-lint","parents":["857bf31451adab51b0e4e9a2bf3a3dfccc75121c"],"secs":103,"stamp":"f5833fe28e03991f89918fbad86fc7ca","tree":"d384a14b382f130096df19d4bb7b109e6b779b95","v":1,"via":"run"}
Ci-Attestation: {"at":1795224675,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"2db147e7a0cfa82a5ad543a99845b7a73ed6e1b8452607d4b943b88a0eefd017","lane":"client-lint","parents":["857bf31451adab51b0e4e9a2bf3a3dfccc75121c"],"secs":103,"stamp":"8aed974fea0c9502e9c1fd8bee9cd28c","tree":"d384a14b382f130096df19d4bb7b109e6b779b95","v":1,"via":"run"}
Ci-Attestation: {"at":1795224675,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"2db147e7a0cfa82a5ad543a99845b7a73ed6e1b8452607d4b943b88a0eefd017","lane":"client-lint","parents":["857bf31451adab51b0e4e9a2bf3a3dfccc75121c"],"secs":103,"stamp":"0dbf2156909c1f313b43aa5877f2fc4f","tree":"d384a14b382f130096df19d4bb7b109e6b779b95","v":1,"via":"run"}
Ci-Attestation: {"at":1795224675,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"2db147e7a0cfa82a5ad543a99845b7a73ed6e1b8452607d4b943b88a0eefd017","lane":"client-lint","parents":["857bf31451adab51b0e4e9a2bf3a3dfccc75121c"],"secs":103,"stamp":"94c41614869ad18cde4a5326fc6a08fa","tree":"d384a14b382f130096df19d4bb7b109e6b779b95","v":1,"via":"run"}
Ci-Attestation: {"at":1795224675,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"2db147e7a0cfa82a5ad543a99845b7a73ed6e1b8452607d4b943b88a0eefd017","lane":"client-lint","parents":["857bf31451adab51b0e4e9a2bf3a3dfccc75121c"],"secs":103,"stamp":"67a79b9d5808b8d411a85de3e5d8ab32","tree":"d384a14b382f130096df19d4bb7b109e6b779b95","v":1,"via":"run"}
Ci-Attestation: {"at":1795224675,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"2db147e7a0cfa82a5ad543a99845b7a73ed6e1b8452607d4b943b88a0eefd017","lane":"client-lint","parents":["857bf31451adab51b0e4e9a2bf3a3dfccc75121c"],"secs":103,"stamp":"7b60feec5d840c7c5eb8f0bc4221396c","tree":"d384a14b382f130096df19d4bb7b109e6b779b95","v":1,"via":"run"}
Ci-Attestation: {"at":1795224675,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"2db147e7a0cfa82a5ad543a99845b7a73ed6e1b8452607d4b943b88a0eefd017","lane":"client-lint","parents":["857bf31451adab51b0e4e9a2bf3a3dfccc75121c"],"secs":103,"stamp":"cce92a44eb3bbbca4d0242a0025bb9d0","tree":"d384a14b382f130096df19d4bb7b109e6b779b95","v":1,"via":"run"}
Ci-Attestation: {"at":1795224675,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"2db147e7a0cfa82a5ad543a99845b7a73ed6e1b8452607d4b943b88a0eefd017","lane":"client-lint","parents":["857bf31451adab51b0e4e9a2bf3a3dfccc75121c"],"secs":103,"stamp":"36ec0640de17d561bf8da314be47fb02","tree":"d384a14b382f130096df19d4bb7b109e6b779b95","v":1,"via":"run"}
Ci-Attestation: {"at":1795224675,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"2db147e7a0cfa82a5ad543a99845b7a73ed6e1b8452607d4b943b88a0eefd017","lane":"client-lint","parents":["857bf31451adab51b0e4e9a2bf3a3dfccc75121c"],"secs":103,"stamp":"6db26000ede60f5e5c98a5fec8c5cbb6","tree":"d384a14b382f130096df19d4bb7b109e6b779b95","v":1,"via":"run"}
Ci-Attestation: {"at":1795224675,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"2db147e7a0cfa82a5ad543a99845b7a73ed6e1b8452607d4b943b88a0eefd017","lane":"client-lint","parents":["857bf31451adab51b0e4e9a2bf3a3dfccc75121c"],"secs":103,"stamp":"f602562697dfa10e842db638505ece3b","tree":"d384a14b382f130096df19d4bb7b109e6b779b95","v":1,"via":"run"}
Ci-Attestation: {"at":1795224983,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"57ecf0d0dc8fcaf878678b516b5ce48223ab7dc8d448d4a5a8b0da0e960f096e","lane":"client-test-x86_64-unknown-linux-gnu","parents":["857bf31451adab51b0e4e9a2bf3a3dfccc75121c"],"secs":211,"stamp":"d111256363b3efd5ed92fcf532925611","tree":"d384a14b382f130096df19d4bb7b109e6b779b95","v":1,"via":"run"}

Client-Checks: {"checks":{"base":"cbf2fd14f434a285f8cd985cb1572bef630272f3","coverage":"all-tracked-applicable-files","diff":["ci/test_bench_libobs_stand_ins.py","libobs/build/libobs.core-output+.h.c","libobs/build/libobs.ported-encoder-group-num-started+.h.c","libobs/build/ported-source-sets/encoder-group-num-started.json","libobs/cmake/rust-hidden.d/obs-output-encoder_group_num_started.txt","libobs/obs-encoder-group-num-started-fields.c.h","rust/README.md","rust/obs-build/tests/native.rs","rust/obs-build/tests/native/registration/canonical_encoder_group_num_started_swap_is_registered.rs","rust/obs-build/tests/native/registration/rust-static/cases/core-relinked/test_encoder_group_num_started_rust.json","rust/obs-c-oracle/benches/port_comparison.rs","rust/obs-c-oracle/oracle/encoder_group_num_started.c","rust/obs-output/src/encoder_group_num_started.rs","rust/obs-output/src/ffi/encoder_group_num_started.rs","rust/obs-output/src/ffi/mod.rs","rust/obs-output/src/lib.rs","rust/obs-output/tests/output/encoder_group_num_started.rs","rust/obs-output/tests/output/encoder_group_num_started_parity.rs","rust/obs-output/tests/output/interleave_parity.rs","rust/obs-output/tests/output/main.rs","test/cmocka/build/test-graph.json","test/cmocka/encoder-group-num-started-record-support.c"],"head":"9ed7db1611e7a57179a6da509b29aa522c52808c","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":"96301fee900b7d230d2bcc5f90308b3f31a111458f3eefb4f787c1aa4eee1f52","tree":"d384a14b382f130096df19d4bb7b109e6b779b95"}}
@rdoupe
rdoupe requested a review from zackees as a code owner November 21, 2026 01:36
@rdoupe
rdoupe added this pull request to the merge queue Nov 21, 2026
Merged via the queue into master with commit 937eecf Nov 21, 2026
46 checks passed
@rdoupe
rdoupe deleted the port/5319-encoder-group-num-started branch November 21, 2026 02:38
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.

1 participant