Skip to content

obs-core: swap obs_set_audio_monitoring_device and obs_reset_audio_monitoring to Rust (Refs #5491) - #5492

Merged
rdoupe merged 2 commits into
masterfrom
port/audio-monitoring-device
Nov 23, 2026
Merged

rdoupe merged 2 commits into
masterfrom
port/audio-monitoring-device

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Swaps obs_set_audio_monitoring_device and obs_reset_audio_monitoring to safe Rust in obs-core, the follow-up to their characterization and extraction (#5489, #5490). Fixes #5491.

Setting the device (obs_set_audio_monitoring_device(name, id)), in order:

  1. It returns false for a NULL name, a NULL id, an empty name or an empty id. These are checked in that order through core_setup_rules::monitor_missing, before anything else.
  2. It returns false when monitoring is unavailable.
  3. Under monitoring_mutex, an id equal to the stored one (monitor_same of the strcmp) unlocks and returns true with nothing changed.
  4. Otherwise it frees the stored name and id and stores bstrdup copies of the new ones, unlocks, and resets every live monitor (obs_reset_audio_monitoring).
  5. It then tells each source from obs_enum_sources whose output flags pass aoc_check (OBS_SOURCE_DO_NOT_SELF_MONITOR) about the change, with that source's own device_id setting, and returns true.

Resetting (obs_reset_audio_monitoring()) does nothing when monitoring is unavailable. Otherwise it resets each live monitor once under monitoring_mutex, reading the monitor count again before each step, as the C loop does.

The Rust safe core (rust/obs-core/src/audio_monitoring_device.rs) decides which steps run and in what order. The steps on private state stay in C behind private adapters in one hidden file, libobs/obs-audio-monitoring-device-fields.c.h, in the core group: the availability check, the mutex, the compare, the free-and-copy, the monitor count and reset, the enumeration, the flags read and the notice (settings, device_id, obs_source_audio_output_capture_device_changed, release). The original C moves to libobs.ported-audio-monitoring-device for the C reference. Existing C tests and public headers are unchanged. The existing getter adapters (obs-core-monitoring-device-fields.c.h) were not reused: they only read the slots, and the setter has to compare under the lock and free and copy with bmem in C.

Tests

  • Tier 1 (rust/obs-core/tests/obs_core/audio_monitoring_device.rs, in the existing obs-tests-core binary). It mirrors every case of the unchanged test_set_audio_monitoring_device.c over a model core whose source notices drive a model of the deduplication signal. It also covers the refusals that test_monitoring_device checks, plus what the C test cannot see:

    • the refusals happen before any other step, and the availability check comes next;
    • the full step order: lock, compare, copies, unlock, then the resets under their own lock and availability check, then one notice per capture source in enumeration order;
    • when monitoring is lost between the store and the reset, the new device stays stored, no monitor is reset, and the sources are still told;
    • the enumeration callback always continues.
  • Tier 2: the unchanged test_set_audio_monitoring_device, test_core_setup_rules_steps (test_monitoring_device) and test_pulse_monitor_reset run against hybrid libobs and the C reference.

  • Tier 3 (audio_monitoring_device_parity.rs, oracle audio_monitoring_device.c). The original and the shims run on one recording real-header core, through the oracle's copy of the real adapters. Inputs are fixed and proptest names and ids (NULL, empty, short), stored ids, availability, up to 8 monitors and up to 8 sources with mixed flags. The probe compares:

    • the result;
    • the trace of every core read, availability check, lock, compare, free, copy, monitor reset, enumeration, and each source's settings read, notice and release. Steps on the fields are checked to run under the lock, and the enumeration after the unlock;
    • the stored name and id.

    The mutex is only recorded, never taken. Ten mutants are caught: availability checked first, no same-id shortcut, same id answers false, resets before the unlock, no resets, every source told, enumeration stopped early, one monitor fewer, a reset without the availability check, and a reset that skips a monitor.

  • Tier 4 does not apply.

  • Outside the contract, as in the C: an uninitialized core (dereferenced once the name and id pass) and a NULL stored id (passed to strcmp). No intentional differences.

Evidence

  • RED (obs-core: RED Tier 1 mirrors, safe core todo!()):
    soldr cargo test -p obs-data --test obs-tests-core -- audio_monitoring_device:: → test result: FAILED. 0 passed; 10 failed
  • GREEN: soldr cargo test -p obs-data --test obs-tests-core -- audio_monitoring_device → test result: ok. 16 passed; 0 failed (10 Tier 1, 6 Tier 3).
  • Mutation of the real safe core (each reverted afterwards):
    • notify every source → 11 passed, 5 failed;
    • store after the unlock → 7 passed, 9 failed.
  • Tier 2: OBS_CTEST_JOBS=10 uv run rust/tools/linux-validate/run.py --repeat 2 --tests test_set_audio_monitoring_device,test_core_setup_rules_steps,test_pulse_monitor_reset → 100% tests passed, 0 tests failed out of 1086 on both the C reference and hybrid libobs. All three tests Passed on both.
  • uv run ci/windows_link_check.py → exit 0: the category binaries and the Windows/Darwin cmocka *_rust executables link.
  • ./lint --fix passes.
  • Test cost: the longest module run with OBS_PARITY_CASES=reduced takes 0.04 s. Peak RSS is 15.5 MB over 20 runs. The tests start no threads of their own, and the proptest sizes are capped (strings ≤ 6, ≤ 8 monitors, ≤ 8 sources).

🤖 Generated with Claude Code

rdoupe and others added 2 commits November 23, 2026 00:11
…5491)

Safe mirrors of every case of the unchanged
test_set_audio_monitoring_device.c over a model core (stored name and id,
live monitors that remember the device each reset put them on, public and
private sources with output flags and a device_id, and a model of the
deduplication signal their notices drive): a reset with no monitors
touches nothing; each live monitor is reset once per reset; a new device
is stored by copy and resets every monitor onto it; the same id keeps the
old name, resets nothing and tells nobody; every public Audio Output
Capture source is told with its own device_id, which starts and stops the
deduplication as in the C test. Plus the refusals of test_monitoring_device
and what the C test cannot see: NULL or empty name or id refused before
any other step, availability next, then lock, compare, copies, unlock,
the resets under their own lock and availability check, and one notice
per capture source in enumeration order. Against a todo!() core:

    soldr cargo test -p obs-data --test obs-tests-core -- audio_monitoring_device::
    test result: FAILED. 0 passed; 10 failed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nitoring to Rust (Refs #5491)

Both now come from obs-core in hybrid libobs. The safe core decides the
order: a NULL name, NULL id, empty name and empty id are refused, in that
order through core_setup_rules::monitor_missing, before anything else;
then unavailable monitoring is refused; under monitoring_mutex the same
id (monitor_same of the strcmp) unlocks and answers true; otherwise the
stored name and id are replaced by copies, the mutex is released, every
live monitor is reset (obs_reset_audio_monitoring, which asks for
availability again and reads the count before each step under the
mutex), and each enumerated source whose flags pass aoc_check is told
with its own device_id. The fields, mutex, bmem copies, monitor list,
audio_monitor_reset, obs_enum_sources and the notice stay C behind
private adapters (obs-audio-monitoring-device-fields.c.h, in the core
group). The original moves to libobs.ported-audio-monitoring-device for
the C reference.

Tier 3 runs the original and the shims on one recording real-header
core (oracle/audio_monitoring_device.c) over fixed and proptest names,
ids, stored ids, availability, up to eight monitors and up to eight
sources: the result, the trace of every core read, availability check,
lock, compare, free, copy, reset, enumeration and per-source settings
read, notice and release, and the stored strings. Ten mutants are
caught.

    soldr cargo test -p obs-data --test obs-tests-core -- audio_monitoring_device
    test result: ok. 16 passed; 0 failed

Mutation of the safe core (notify every source; store after the unlock):
11 passed; 5 failed and 7 passed; 9 failed.

    OBS_CTEST_JOBS=10 uv run rust/tools/linux-validate/run.py --repeat 2 \
      --tests test_set_audio_monitoring_device,test_core_setup_rules_steps,test_pulse_monitor_reset
    100% tests passed, 0 tests failed out of 1086 (C reference and hybrid)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ci-Attestation: {"at":1795412414,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["c4a3e11875b7d4812bfd87ab4e33d2562e9926bd"],"secs":98,"stamp":"2b0a9dd9ef9bd6ee2eb8304f4c1da972","tree":"ffd204a13a50b00a1a113843083076aed8405d82","v":1,"via":"run"}
Ci-Attestation: {"at":1795412414,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["c4a3e11875b7d4812bfd87ab4e33d2562e9926bd"],"secs":98,"stamp":"000cd0b5d55454863f2e09822db9acdd","tree":"ffd204a13a50b00a1a113843083076aed8405d82","v":1,"via":"run"}
Ci-Attestation: {"at":1795412414,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["c4a3e11875b7d4812bfd87ab4e33d2562e9926bd"],"secs":98,"stamp":"b3506ee49e4b6a17968e6dc3e917e788","tree":"ffd204a13a50b00a1a113843083076aed8405d82","v":1,"via":"run"}
Ci-Attestation: {"at":1795412414,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["c4a3e11875b7d4812bfd87ab4e33d2562e9926bd"],"secs":98,"stamp":"60991024640a501a7917a6dbfc41b5ee","tree":"ffd204a13a50b00a1a113843083076aed8405d82","v":1,"via":"run"}
Ci-Attestation: {"at":1795412315,"gate":"general/all/client-lint","host":"linux-x86_64","key":"8e255b387583e1072a8e3b3c2f730d421d80f5061881f7b402dfe24fa9e56ed7","lane":"client-lint","parents":["c4a3e11875b7d4812bfd87ab4e33d2562e9926bd"],"secs":8,"stamp":"4ff658d4ee8a4746225228d36dff7292","tree":"ffd204a13a50b00a1a113843083076aed8405d82","v":1,"via":"run"}
Ci-Attestation: {"at":1795412414,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["c4a3e11875b7d4812bfd87ab4e33d2562e9926bd"],"secs":98,"stamp":"f34ed47a7b90ccea282f301a7e523734","tree":"ffd204a13a50b00a1a113843083076aed8405d82","v":1,"via":"run"}
Ci-Attestation: {"at":1795412316,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"8e255b387583e1072a8e3b3c2f730d421d80f5061881f7b402dfe24fa9e56ed7","lane":"client-lint","parents":["c4a3e11875b7d4812bfd87ab4e33d2562e9926bd"],"secs":8,"stamp":"a642f540d732b56f8946f14d5db65b2c","tree":"ffd204a13a50b00a1a113843083076aed8405d82","v":1,"via":"run"}
Ci-Attestation: {"at":1795412316,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"8e255b387583e1072a8e3b3c2f730d421d80f5061881f7b402dfe24fa9e56ed7","lane":"client-lint","parents":["c4a3e11875b7d4812bfd87ab4e33d2562e9926bd"],"secs":8,"stamp":"310429cfa115be903f0a6cc5f75b8167","tree":"ffd204a13a50b00a1a113843083076aed8405d82","v":1,"via":"run"}
Ci-Attestation: {"at":1795412316,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"8e255b387583e1072a8e3b3c2f730d421d80f5061881f7b402dfe24fa9e56ed7","lane":"client-lint","parents":["c4a3e11875b7d4812bfd87ab4e33d2562e9926bd"],"secs":8,"stamp":"6811fa130ce827029ba4192770f165b3","tree":"ffd204a13a50b00a1a113843083076aed8405d82","v":1,"via":"run"}
Ci-Attestation: {"at":1795412316,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"8e255b387583e1072a8e3b3c2f730d421d80f5061881f7b402dfe24fa9e56ed7","lane":"client-lint","parents":["c4a3e11875b7d4812bfd87ab4e33d2562e9926bd"],"secs":8,"stamp":"9b08980821f6a01818e9bac868b7f7cd","tree":"ffd204a13a50b00a1a113843083076aed8405d82","v":1,"via":"run"}
Ci-Attestation: {"at":1795412315,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"8e255b387583e1072a8e3b3c2f730d421d80f5061881f7b402dfe24fa9e56ed7","lane":"client-lint","parents":["c4a3e11875b7d4812bfd87ab4e33d2562e9926bd"],"secs":8,"stamp":"1af9f1b511c1cd63eb9d39ddcdc3fc07","tree":"ffd204a13a50b00a1a113843083076aed8405d82","v":1,"via":"run"}
Ci-Attestation: {"at":1795412315,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"8e255b387583e1072a8e3b3c2f730d421d80f5061881f7b402dfe24fa9e56ed7","lane":"client-lint","parents":["c4a3e11875b7d4812bfd87ab4e33d2562e9926bd"],"secs":8,"stamp":"91a476ad000387c378b7d5b7d66938a3","tree":"ffd204a13a50b00a1a113843083076aed8405d82","v":1,"via":"run"}
Ci-Attestation: {"at":1795412316,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"8e255b387583e1072a8e3b3c2f730d421d80f5061881f7b402dfe24fa9e56ed7","lane":"client-lint","parents":["c4a3e11875b7d4812bfd87ab4e33d2562e9926bd"],"secs":8,"stamp":"21532ac34d9199bdb61d152ab8819773","tree":"ffd204a13a50b00a1a113843083076aed8405d82","v":1,"via":"run"}
Ci-Attestation: {"at":1795412316,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"8e255b387583e1072a8e3b3c2f730d421d80f5061881f7b402dfe24fa9e56ed7","lane":"client-lint","parents":["c4a3e11875b7d4812bfd87ab4e33d2562e9926bd"],"secs":8,"stamp":"ab8e1f3477e830e1001cb749490d1c7f","tree":"ffd204a13a50b00a1a113843083076aed8405d82","v":1,"via":"run"}
Ci-Attestation: {"at":1795412315,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"8e255b387583e1072a8e3b3c2f730d421d80f5061881f7b402dfe24fa9e56ed7","lane":"client-lint","parents":["c4a3e11875b7d4812bfd87ab4e33d2562e9926bd"],"secs":8,"stamp":"6f02e31093eb207c6ddb18186ceff741","tree":"ffd204a13a50b00a1a113843083076aed8405d82","v":1,"via":"run"}
Ci-Attestation: {"at":1795412316,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"8e255b387583e1072a8e3b3c2f730d421d80f5061881f7b402dfe24fa9e56ed7","lane":"client-lint","parents":["c4a3e11875b7d4812bfd87ab4e33d2562e9926bd"],"secs":8,"stamp":"0ee6b6aad162b35bbb0f7c630a5fcbfb","tree":"ffd204a13a50b00a1a113843083076aed8405d82","v":1,"via":"run"}
Ci-Attestation: {"at":1795412315,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"8e255b387583e1072a8e3b3c2f730d421d80f5061881f7b402dfe24fa9e56ed7","lane":"client-lint","parents":["c4a3e11875b7d4812bfd87ab4e33d2562e9926bd"],"secs":8,"stamp":"957f8fefdc6c971ef4f691cfdfc08ec7","tree":"ffd204a13a50b00a1a113843083076aed8405d82","v":1,"via":"run"}
Ci-Attestation: {"at":1795412315,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"8e255b387583e1072a8e3b3c2f730d421d80f5061881f7b402dfe24fa9e56ed7","lane":"client-lint","parents":["c4a3e11875b7d4812bfd87ab4e33d2562e9926bd"],"secs":8,"stamp":"0228308aaaf1383923ffde624834cb56","tree":"ffd204a13a50b00a1a113843083076aed8405d82","v":1,"via":"run"}
Ci-Attestation: {"at":1795412629,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"7ebec0a08939587d99dca18e5aa31acd2914b84e4fbc27e0ef7f7eb005b76d68","lane":"client-test-x86_64-unknown-linux-gnu","parents":["c4a3e11875b7d4812bfd87ab4e33d2562e9926bd"],"secs":214,"stamp":"9b418a0239f4fe9158da1652d365d567","tree":"ffd204a13a50b00a1a113843083076aed8405d82","v":1,"via":"run"}

Client-Checks: {"checks":{"base":"b0806bb796050bb254015051233dbebbd53440e2","coverage":"all-tracked-applicable-files","diff":["libobs/build/libobs.core+.h.c","libobs/build/libobs.ported-audio-monitoring-device+.h.c","libobs/build/ported-source-sets/audio-monitoring-device.json","libobs/cmake/rust-exports.d/obs-core-audio_monitoring_device.txt","libobs/obs-audio-monitoring-device-fields.c.h","rust/README.md","rust/obs-c-oracle/oracle/audio_monitoring_device.c","rust/obs-core/src/audio_monitoring_device.rs","rust/obs-core/src/ffi/audio_monitoring_device.rs","rust/obs-core/src/ffi/mod.rs","rust/obs-core/src/lib.rs","rust/obs-core/tests/obs_core/audio_monitoring_device.rs","rust/obs-core/tests/obs_core/audio_monitoring_device_parity.rs","rust/obs-core/tests/obs_core/main.rs"],"head":"969848e17167fe765c6d14a64143d8c334b49892","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":"339b5b3dd75ff82d7eeb4a1db970a1f3358d18f19da9b3263271460bc65a33f2","tree":"ffd204a13a50b00a1a113843083076aed8405d82"}}
@rdoupe
rdoupe requested a review from zackees as a code owner November 23, 2026 05:44
@rdoupe
rdoupe enabled auto-merge November 23, 2026 05:45
@rdoupe
rdoupe added this pull request to the merge queue Nov 23, 2026
@obs-rust-project-manager obs-rust-project-manager Bot moved this to In merge queue in obs-rust Multiview Nov 23, 2026
Merged via the queue into master with commit e192367 Nov 23, 2026
46 checks passed
@rdoupe
rdoupe deleted the port/audio-monitoring-device branch November 23, 2026 06:30
@obs-rust-project-manager obs-rust-project-manager Bot moved this from In merge queue to Done in obs-rust Multiview Nov 23, 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.

obs-core: swap obs_set_audio_monitoring_device and obs_reset_audio_monitoring to Rust

1 participant