Skip to content

obs-source: swap source audio-capture callback registration to safe Rust (Refs #5243) - #5254

Merged
rdoupe merged 2 commits into
masterfrom
port/source-audio-capture-callbacks
Nov 19, 2026
Merged

rdoupe merged 2 commits into
masterfrom
port/source-audio-capture-callbacks

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #5243

Moves obs_source_add_audio_capture_callback and obs_source_remove_audio_capture_callback from libobs/obs-source-audio-capture-callbacks.c.h into obs-source. The C extraction (#5242) is the prerequisite.

What changed

  • obs-source::callback_registry: the ordered (callback, param) update that caption registration already used, now shared. caption_callbacks and the new audio_capture_callbacks call it with their own diagnostic names. Behaviour is the same: append keeps order and duplicates, remove erases the first exact pair, NULL callbacks and params are stored, a NULL source logs <name>: Null 'source' parameter at LOG_DEBUG before any lock.
  • ffi::callback_list: the locked C darray behind the registry (shared with the caption shim, which shrinks). The new ffi::source_audio_capture_callbacks exports the two public functions, which forward to private _rust entries (hidden from shared libobs, rust-hidden.d), the same shape as obs-encoder: swap texture-input activity to safe Rust (Refs #5216) #5226.
  • C: libobs/obs-source-audio-capture-callback-fields.c.h is the real private adapter (list address, audio_cb_mutex lock/unlock). The source mutex, the darray and its bmem storage stay in C. The original C moves to its own ported group, libobs.ported-source-audio-capture-callbacks.
  • The audio-controls oracle used to define no-op stand-ins under the real names. They are now renamed inside that oracle, so the Rust export is the only definition in the test binary.

Tests

  • Tier 1: rust/obs-source/tests/source/audio_capture_callbacks.rs mirrors the three cmocka cases.
  • Tier 2: test_source_audio_capture_callbacks.c is unchanged. A new test_audio_capture_callbacks_rust builds it with SOURCE_AUDIO_CAPTURE_EXTERNAL against libobs_rust-static, through the _rust entries and the real adapter compiled over the fixture's recording mutex (test/cmocka/source-audio-capture-callback-record-support.c). That way its lock-count and mutation-under-lock assertions apply to the Rust code. The target name stays outside the test_source_ prefix on purpose: the source-step link fragments give every test_source_* Rust-static target an aborting blog stub, and this test checks the real diagnostics. Instead it links the real variadic blog (base-variadic.c.h) over the Rust log handler. Every other Rust-static consumer gets the real adapter from the existing video_info_query_link_support archive.
  • Tier 3: audio_capture_callbacks_parity.rs runs the original C (rust/obs-c-oracle/oracle/source_audio_capture_callbacks.c) side by side with the Rust. It covers the characterized edges, 60-operation growth over every null/non-null pair, a proptest of up to 128 operations, the public and _rust entries alike, the unlocked mutex after each call, NULL-source diagnostics, and the real-header layouts of struct audio_cb_info and struct darray. Mutation check: making removal erase the last match instead of the first fails characterized_edges and sequences.
  • Tier 4 does not apply (no protocol surface).

Evidence

RED (commit e642d99, core stubbed):

soldr cargo test -p obs-data --test obs-tests-core -- source::audio_capture_callbacks source::caption_callbacks
test source::audio_capture_callbacks::test_source_audio_capture_callbacks_pair_identity_order_and_removal ... FAILED
test source::audio_capture_callbacks::test_source_audio_capture_callbacks_null_pairs_are_stored ... FAILED
test source::audio_capture_callbacks::test_source_audio_capture_callbacks_invalid_source ... FAILED
test result: FAILED. 6 passed; 3 failed

(The caption cases still pass after the shared-registry refactor.)

GREEN:

soldr cargo test -p obs-data --test obs-tests-core
test result: ok. 6134 passed; 0 failed; 5 ignored

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

OBS_CTEST_JOBS=10 uv run rust/tools/linux-validate/run.py --repeat 1 --tests 'audio_capture_callbacks|test_source_caption'
100% tests passed, 0 tests failed out of 1034
  test_audio_capture_callbacks_rust ... Passed
  test_source_audio_capture_callbacks ... Passed
# the Rust-static binary run directly in the build volume:
[  PASSED  ] 3 test(s).   (invalid_source, pair_identity_order_and_removal, null_pairs_are_stored_without_invocation)

uv run --no-project ci/windows_link_check.py
Tier 2 win-x64: linked   Tier 2 mac-arm64: linked   (including test_audio_capture_callbacks_rust)

./lint   -> lane lint: ok

Along the way: before the variadic blog was linked in, the fixture ran but its handler saw 0 of the 2 diagnostics, because they went through shared libobs's own log state. Before the rename it aborted on the source-step blog stub.

🤖 Generated with Claude Code

@rdoupe
rdoupe requested a review from zackees as a code owner November 19, 2026 15:57
@rdoupe rdoupe changed the title obs-source: swap source audio-capture callback registration to safe Rust (GREEN, Refs #5243) obs-source: swap source audio-capture callback registration to safe Rust (Refs #5243) Nov 19, 2026
@rdoupe
rdoupe enabled auto-merge November 19, 2026 16:43
@rdoupe
rdoupe added this pull request to the merge queue Nov 19, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this to In merge queue in obs-rust Multiview Nov 19, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 19, 2026
@rdoupe
rdoupe added this pull request to the merge queue Nov 19, 2026
@rdoupe
rdoupe removed this pull request from the merge queue due to a manual request Nov 19, 2026
@rdoupe
rdoupe added this pull request to the merge queue Nov 19, 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 19, 2026
rdoupe and others added 2 commits November 19, 2026 13:48
…t stub (RED, Refs #5243)

Moves the caption registry's ordered-pair update into callback_registry so
both source callback lists share it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ust (GREEN, Refs #5243)

obs_source_add/remove_audio_capture_callback now run in obs-source over
the shared ordered-pair registry. The real private adapter keeps
audio_cb_mutex, the C darray and its bmem storage. The unchanged C
characterization links the Rust through private _rust entries, the real
adapter compiled over its recording mutex and the real variadic blog
(test_audio_capture_callbacks_rust, outside the test_source_ prefix that
gives source-step fixtures an aborting blog stub); Tier 3 compares the
Rust with the original C. The audio-controls oracle keeps its no-op
stand-ins private.

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

Ci-Attestation: {"at":1795114575,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["d18d25fff73a4991be7d42d3b70748a278e874ed"],"secs":94,"stamp":"1cf32ef3d25d7ad68f11c761ca5b0c2a","tree":"eab26f59bb8fdccbbb768130e0f311bc2d39bcd5","v":1,"via":"run"}
Ci-Attestation: {"at":1795114575,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["d18d25fff73a4991be7d42d3b70748a278e874ed"],"secs":94,"stamp":"62ef1be030ea8f161f8a9ae7e613319d","tree":"eab26f59bb8fdccbbb768130e0f311bc2d39bcd5","v":1,"via":"run"}
Ci-Attestation: {"at":1795114575,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["d18d25fff73a4991be7d42d3b70748a278e874ed"],"secs":94,"stamp":"c4ba0ebed76aabac8d320df8c0397140","tree":"eab26f59bb8fdccbbb768130e0f311bc2d39bcd5","v":1,"via":"run"}
Ci-Attestation: {"at":1795114575,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["d18d25fff73a4991be7d42d3b70748a278e874ed"],"secs":94,"stamp":"21d9bdd81c24166994a34c0ddb080b4b","tree":"eab26f59bb8fdccbbb768130e0f311bc2d39bcd5","v":1,"via":"run"}
Ci-Attestation: {"at":1795114480,"gate":"general/all/client-lint","host":"linux-x86_64","key":"b7d03511ca333ed8ee4e48a83faaef561e36d8e4f42ef5f377fef4faeec4237d","lane":"client-lint","parents":["d18d25fff73a4991be7d42d3b70748a278e874ed"],"secs":75,"stamp":"18f81e9c602268dfa767dd40d9a6f35d","tree":"eab26f59bb8fdccbbb768130e0f311bc2d39bcd5","v":1,"via":"run"}
Ci-Attestation: {"at":1795114575,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["d18d25fff73a4991be7d42d3b70748a278e874ed"],"secs":94,"stamp":"bf56ddd441a588f10d278d288a84ef5d","tree":"eab26f59bb8fdccbbb768130e0f311bc2d39bcd5","v":1,"via":"run"}
Ci-Attestation: {"at":1795114480,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"b7d03511ca333ed8ee4e48a83faaef561e36d8e4f42ef5f377fef4faeec4237d","lane":"client-lint","parents":["d18d25fff73a4991be7d42d3b70748a278e874ed"],"secs":75,"stamp":"b22fcc56d6f6a5cda5858de671433cbe","tree":"eab26f59bb8fdccbbb768130e0f311bc2d39bcd5","v":1,"via":"run"}
Ci-Attestation: {"at":1795114480,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"b7d03511ca333ed8ee4e48a83faaef561e36d8e4f42ef5f377fef4faeec4237d","lane":"client-lint","parents":["d18d25fff73a4991be7d42d3b70748a278e874ed"],"secs":75,"stamp":"11829d15e37422a15d2427fe10d889e9","tree":"eab26f59bb8fdccbbb768130e0f311bc2d39bcd5","v":1,"via":"run"}
Ci-Attestation: {"at":1795114480,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"b7d03511ca333ed8ee4e48a83faaef561e36d8e4f42ef5f377fef4faeec4237d","lane":"client-lint","parents":["d18d25fff73a4991be7d42d3b70748a278e874ed"],"secs":75,"stamp":"4c72da0388614c58b987a607e468e606","tree":"eab26f59bb8fdccbbb768130e0f311bc2d39bcd5","v":1,"via":"run"}
Ci-Attestation: {"at":1795114480,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"b7d03511ca333ed8ee4e48a83faaef561e36d8e4f42ef5f377fef4faeec4237d","lane":"client-lint","parents":["d18d25fff73a4991be7d42d3b70748a278e874ed"],"secs":75,"stamp":"9b383d5d7a32aef4f1bbce0e285656b4","tree":"eab26f59bb8fdccbbb768130e0f311bc2d39bcd5","v":1,"via":"run"}
Ci-Attestation: {"at":1795114480,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"b7d03511ca333ed8ee4e48a83faaef561e36d8e4f42ef5f377fef4faeec4237d","lane":"client-lint","parents":["d18d25fff73a4991be7d42d3b70748a278e874ed"],"secs":75,"stamp":"bc525eb29423f62b73a048e4c23e0a54","tree":"eab26f59bb8fdccbbb768130e0f311bc2d39bcd5","v":1,"via":"run"}
Ci-Attestation: {"at":1795114480,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"b7d03511ca333ed8ee4e48a83faaef561e36d8e4f42ef5f377fef4faeec4237d","lane":"client-lint","parents":["d18d25fff73a4991be7d42d3b70748a278e874ed"],"secs":75,"stamp":"db8b8d44ef63656cd710667f242b5e14","tree":"eab26f59bb8fdccbbb768130e0f311bc2d39bcd5","v":1,"via":"run"}
Ci-Attestation: {"at":1795114480,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"b7d03511ca333ed8ee4e48a83faaef561e36d8e4f42ef5f377fef4faeec4237d","lane":"client-lint","parents":["d18d25fff73a4991be7d42d3b70748a278e874ed"],"secs":75,"stamp":"68d34003beaab2e4d21ed4f25ab8e975","tree":"eab26f59bb8fdccbbb768130e0f311bc2d39bcd5","v":1,"via":"run"}
Ci-Attestation: {"at":1795114480,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"b7d03511ca333ed8ee4e48a83faaef561e36d8e4f42ef5f377fef4faeec4237d","lane":"client-lint","parents":["d18d25fff73a4991be7d42d3b70748a278e874ed"],"secs":75,"stamp":"eda790340083d7feb43d4f14f3518c51","tree":"eab26f59bb8fdccbbb768130e0f311bc2d39bcd5","v":1,"via":"run"}
Ci-Attestation: {"at":1795114480,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"b7d03511ca333ed8ee4e48a83faaef561e36d8e4f42ef5f377fef4faeec4237d","lane":"client-lint","parents":["d18d25fff73a4991be7d42d3b70748a278e874ed"],"secs":75,"stamp":"7d01fa4bad64dc5e26a57181c1510dcb","tree":"eab26f59bb8fdccbbb768130e0f311bc2d39bcd5","v":1,"via":"run"}
Ci-Attestation: {"at":1795114480,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"b7d03511ca333ed8ee4e48a83faaef561e36d8e4f42ef5f377fef4faeec4237d","lane":"client-lint","parents":["d18d25fff73a4991be7d42d3b70748a278e874ed"],"secs":75,"stamp":"0eb5cf1ab8650f89b9b3cde52159ced5","tree":"eab26f59bb8fdccbbb768130e0f311bc2d39bcd5","v":1,"via":"run"}
Ci-Attestation: {"at":1795114480,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"b7d03511ca333ed8ee4e48a83faaef561e36d8e4f42ef5f377fef4faeec4237d","lane":"client-lint","parents":["d18d25fff73a4991be7d42d3b70748a278e874ed"],"secs":75,"stamp":"e23772d7a95438198513827fcab8bfdf","tree":"eab26f59bb8fdccbbb768130e0f311bc2d39bcd5","v":1,"via":"run"}
Ci-Attestation: {"at":1795114480,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"b7d03511ca333ed8ee4e48a83faaef561e36d8e4f42ef5f377fef4faeec4237d","lane":"client-lint","parents":["d18d25fff73a4991be7d42d3b70748a278e874ed"],"secs":75,"stamp":"09b2b26ecc7c101a7210721d77dfb682","tree":"eab26f59bb8fdccbbb768130e0f311bc2d39bcd5","v":1,"via":"run"}
Ci-Attestation: {"at":1795114803,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"1986f1abdc20e80e7195d630b7e7cc3f532989b914690c5c50efbe470ce9c860","lane":"client-test-x86_64-unknown-linux-gnu","parents":["d18d25fff73a4991be7d42d3b70748a278e874ed"],"secs":227,"stamp":"f751ac40697d3c983668c2349c415cbe","tree":"eab26f59bb8fdccbbb768130e0f311bc2d39bcd5","v":1,"via":"run"}

Client-Checks: {"checks":{"base":"6c3417a871453a8b68bb78bc5dd70d07b0bfefc9","coverage":"all-tracked-applicable-files","diff":["libobs/build/libobs.core-source+.h.c","libobs/build/libobs.ported-source-audio-capture-callbacks+.h.c","libobs/build/ported-source-sets/source-audio-capture-callbacks.json","libobs/cmake/rust-exports.d/obs-source-source_audio_capture_callbacks.txt","libobs/cmake/rust-hidden.d/obs-source-source_audio_capture_callbacks.txt","libobs/obs-internal.h","libobs/obs-source-audio-capture-callback-fields.c.h","rust/README.md","rust/obs-build/tests/native/registration/canonical_video_info_query_is_registered.rs","rust/obs-build/tests/native/registration/rust-static/cases/header/test_audio_capture_callbacks.json","rust/obs-c-oracle/oracle/audio_controls.c","rust/obs-c-oracle/oracle/source_audio_capture_callbacks.c","rust/obs-source/src/audio_capture_callbacks.rs","rust/obs-source/src/callback_registry.rs","rust/obs-source/src/caption_callbacks.rs","rust/obs-source/src/ffi/callback_list.rs","rust/obs-source/src/ffi/mod.rs","rust/obs-source/src/ffi/source_audio_capture_callbacks.rs","rust/obs-source/src/ffi/source_caption_callbacks.rs","rust/obs-source/src/lib.rs","rust/obs-source/tests/source/audio_capture_callbacks.rs","rust/obs-source/tests/source/audio_capture_callbacks_parity.rs","rust/obs-source/tests/source/main.rs","test/cmocka/build/test-graph.json","test/cmocka/source-audio-capture-callback-link-support.c","test/cmocka/source-audio-capture-callback-record-support.c","test/cmocka/tests.d/test_audio_capture_callbacks.cmake","test/cmocka/tests.d/video_info_query_link_support.cmake"],"head":"d26fc5bcd8650254811d38ada567bffd5801a146","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":"e3f2b115e013875f432fbe50bab6ee5e0fbbf49fd3cd2a5a12ce72ff6c8ee23b","tree":"eab26f59bb8fdccbbb768130e0f311bc2d39bcd5"}}
@rdoupe
rdoupe force-pushed the port/source-audio-capture-callbacks branch from 3f9a6a1 to 1f21b35 Compare November 19, 2026 19:00
@rdoupe
rdoupe enabled auto-merge November 19, 2026 19:00
@rdoupe
rdoupe added this pull request to the merge queue Nov 19, 2026
Merged via the queue into master with commit 9649a94 Nov 19, 2026
44 checks passed
@rdoupe
rdoupe deleted the port/source-audio-capture-callbacks branch November 19, 2026 20:00
@alerque

alerque commented Nov 19, 2026

Copy link
Copy Markdown

Ya'll know the machines are gaslighting you right? I've seen dozens of PRs "porting to safe rust" and every one of them I've spot checked is just transpiling from C to unsafe Rust. Sure they may be functionally equivalent and in some cases to provide the same functionality across an FFI bridge it is necessary to use unsafe, but these PRs are just straight up gaslighting with the titles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In merge queue

Development

Successfully merging this pull request may close these issues.

2 participants