Skip to content

obs-source: Port the source monitoring rules - #2629

Merged
rdoupe merged 6 commits into
masterfrom
fix/rust-port-source-monitoring-moni-204
Oct 27, 2026
Merged

rdoupe merged 6 commits into
masterfrom
fix/rust-port-source-monitoring-moni-204

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2621

What and why

Ports the monitoring, monitor-only mute, balance, mixer, flag, push-to and audio active decisions left in libobs/obs-source.c.h to rust/obs-source, as a new module monitoring, next to ptm_gate and volume_apply. Every source goes through them: each monitoring change in the Advanced Audio Properties, each balance and track change, each push-to enable and every scene collection load that restores them.

Split per step, as #2153 did. The plan sketched monitoring_enable(cur, enabled, muted), monitoring_type_first(type, muted), monitoring_type_after_disable(muted_for_monitor_only, muted_now) and type_of(valid, enabled, muted). Each would take a read the C makes only under a condition (user_muted only when monitoring turns on, monitoring_enabled again after the signals, obs_source_muted() only where its && reaches it) before the C knows it makes it. So the C keeps those conditions and asks one rule per read. Thirteen functions cross the C ABI: obs_source_monitoring_changes(), _has_audio(), _mixers_store(), _push_to_logs(), _on_type(), _stored_type(), _monitor() (KEEP, CREATE or DESTROY), _route() (OFF, MONITOR_ONLY, MONITOR_AND_OUTPUT or ON), _off_reads_mute(), _off_unmutes(), _only_mutes(), _balance() and _audio_active() (NONE, ACTIVATE or DEACTIVATE).

What stays C, at its point and under its condition: obs_source_valid(); audio_mutex around the push-to values; os_atomic_load_bool() of monitor_only_muted once before the steps and every os_atomic_set_bool(); the read of owns_info_id, and of the output flags only when it is false; obs_source_get_output_flags() before the changed test; user_muted read only when monitoring turns on; monitoring_enabled read again after the signals; obs_source_muted() and obs_source_set_muted() in their order (the mute before monitoring turns on); every calldata_*(), signal and log, the deprecation warnings included; the (float) of the handler's balance; audio_monitor_create() and _destroy(); and the getters' answers for an invalid source (0, false and 0.5), which are literals.

The header copies OBS_SOURCE_AUDIO and the three monitoring types, and obs-source.c.h checks them and that enum obs_monitoring_type is int-sized with _Static_assert. No pointer crosses and no struct is mirrored.

Six commits:

  1. Move (behaviour-neutral): the decisions go to libobs/obs-source-monitoring.c.h, declared in the new obs-source-monitoring.h without EXPORT, so they are hidden. The file joins libobs.core-source. git blame on the moved lines shows the upstream commits d2934ec and 646836a and the fork's libobs: Saturate push-to-talk stop times and clamp the audio balance #2058 and libobs: Keep Monitor Only out of the outputs when set by type #2450; they move as they are.

    The move was checked against the original code. A scratch harness (not committed) compiles origin/master's fifteen functions verbatim next to this branch's and the moved file, as C++:

    • the stand-in source's fields are wrappers that log every read and write, with the value;
    • every call is logged in order with its arguments: obs_source_valid(), the lock and unlock, the calldata sets and gets, each signal, blog(), obs_source_get_output_flags(), the atomics, obs_source_muted(), obs_source_set_muted(), obs_source_dosignal(), the push-to signal and the monitor's create and destroy;
    • a signal handler may leave any mixers (above UINT32_MAX, negative, the ends of int64_t) or any balance, and another thread may write any field at any event;
    • the inputs cover an invalid source and every start state, flags and mixers at the edges and random, types 0 to 4, -1, the ends of int and random, and balances at both NaNs, the signed zeros, the subnormals, 1.0 and its neighbours, the ends, the infinities and random bit patterns.

    5,800,000 runs (GCC and Clang -O2, 2,000,000 each; -O0, 500,000 each; ASan with UBSan, no recovery, under GCC -O0 and Clang -O2, 300,000 each; gcov, 200,000): all 82,503,972 logged events match on both sides, and so does the final state. Every branch of origin/master's functions is taken both ways. Clang's UBSan leg leaves out C++'s enum range check, which C does not have (master's switch (type) on a value outside the enum trips it as C++).

    30 deliberately broken moves were tried, and all 30 fail the harness: each rule inverted, widened or made constant, and at the call sites the mute read before the mark, user_muted read without its log, the output flags read only after a change, the mixers' gate reading the output flags first, and the type taken mod 4.

  2. Characterization: test_source_monitoring_steps, 16 cases. It compiles the moved file with ASan and UBSan and calls only its functions: the header's values; every rule over every combination of its flags and the edges of its numbers; and copies of the callers on a stand-in source that records its signals, logs, mute calls and monitor: every type from every start state, the compatibility signal's type, the balance and mixers a handler leaves, the push-to enables and the audio active signal.

  3. RED: Tier 1 against todo!(). It ports the 16 C cases 1:1 and adds six edge tests: every flag combination; the route over -100,000..100,000; the mixers at every power of two; the balance at every special value, in steps over -2.0..2.0 and a stride over every bit pattern; proptests over full-range values, and over sequences of up to eleven operations through the stand-in, against origin/master's expressions inline.

  4. GREEN: the safe core and thirteen #[no_mangle] shims, in a new libobs.ported-source-monitoring group whose PCH is only the new header.

  5. Tier 3: a C oracle of the unchanged file, the parity tests and a mutation check.

  6. Docs: the README row, the crate's description, lib.rs, and a port_comparison bench module. The port changes nothing a user can see, so docs/features.md has no line.

  • Kept, characterized, not endorsed (unchanged behaviour): the mixers a handler leaves are truncated to their low 32 bits; a balance of -0.0 stays -0.0; Monitor and Output unmutes a mute the user set, while none keeps it.
  • Intentional differences: none.

RED → GREEN

  • RED commit: f2b0f8d11 (obs-source: Test the monitoring port).
    • soldr cargo test -p obs-data --test obs-tests-core -- source::monitoring: 1 passed (the constants, which are not stubs), 21 failed, each on a todo!() ("not yet implemented").
    • local_gate --lane lint was clean on RED, and --test-diff origin/master ran 4687 tests: 4660 passed, 6 skipped, and only those 21 failed (runs were on ead7c97e4, on 2d5ade17d: the same RED before the rebase).
  • GREEN (obs-source: Port the source monitoring rules): Tier 1 22/22.
    • test_source_monitoring_steps passes 16/16 on the C backend, on hybrid libobs and on libobs-c-reference, and test_source_monitoring_steps_rust passes 16/16 against the Rust archive.
    • The 83 tests matching source, audio, monitor, mute, balance, push-to, mixer and volume (test_source_monitoring_type, test_source_monitor_only_load and test_source_audio_balance_mono among them) pass on hybrid libobs and libobs-c-reference, none skipped. In the parallel runs test_source_volume_mix (hybrid) and test_ws_monitor_only and test_xshm_monitor_hotplug (c-ref) failed once each; each passes alone on both.
    • Exported symbols are identical on all three (1766). The thirteen functions are local. In the hybrid they come from the Rust archive, and the group's object is built only for libobs-c-reference.
  • Tier 3 (obs-source: Check monitoring against the C): 7/7, oracle, shims and core compared exactly (each bool as the C's byte, the balance by its bits):
    • the header's values and the sizes of the three enums, bool, int and float;
    • every function of flags over every combination, and the push-to log rule with each flag bit;
    • the same-value rule and the audio gate over every pair of 32-bit edges and every bit;
    • the mixers at every power of two of int64_t with its neighbours and negations, 65,536 values either side of 2^32 and -2^32 and at each end, and a stride of int64_t;
    • the route over every int from -1,000,000 to 1,000,000, a stride of int and the ends;
    • the balance over all 100,663,296 bit patterns of the zeros, subnormals, 0.5 to 2.0, infinities and NaNs of both signs, and every 251st pattern of the rest (all 2^32 patterns were also checked once; too slow to keep in a debug build);
    • proptests of 20,000 cases over full-range values;
    • nothing is excluded.
  • Mutation check: 34 mutants, all killed. Tier 1 and Tier 3 each kill all 22 core mutants; Tier 3 kills all 12 shim mutants (Tier 1 calls only the core).
  • Checks before the rebase (runs were on 6ba7ac699, on 2d5ade17d): ./lint, local_gate --lane lint and --lane cross pass; --test-diff origin/master passes (4694 passed, 6 skipped); SOLDR_RUSTC_WRAPPER=none soldr cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets --locked -- -D warnings is clean; ci/test_build_groups.py, test_ported_sources.py, test_sorted_shared_lists.py, test_test_graph_sorted.py and test_naming.py pass.
  • Bench: soldr cargo test -p obs-c-oracle --locked --bench port_comparison passes (master's gif bench fix, obs-c-oracle: Fix the gif bench's pixel read #2616, is in the base now). Release, x86_64 Linux, GCC, a loaded host, median per 1024 updates: Rust 17.74 µs, C 18.05 µs (0.98x).
  • Review fix, folded into GREEN: the thirteen entries in rust-exports.map, rust-hidden.txt and rust-unexports-macos.txt are in name order inside their block.
  • After the rebase onto b7a503d10 (runs were on 22d958323): the shared lists only add this port's entries against master; exported symbols are 1766 and identical on the C backend, the hybrid and libobs-c-reference, the thirteen functions local; the 83 related C tests pass on the hybrid and libobs-c-reference (test_source_registration failed once in the parallel c-ref run and passes alone), and the characterization and its _rust variant pass on the C backend; ./lint, local_gate --lane lint and --lane cross, the MSVC --all-targets clippy, the CI unit checks and the port_comparison bench test pass; ./unittest's Linux Rust tests pass (4694 and 845, 6 skipped).
  • Not stamped: on current master the local gate's rust-test lane fails in its windows-gnu --no-run build, in libobs/media-io/audio-math.h, which this PR does not touch, since -Wconversion joined the oracle's flags (bug: obs-c-oracle: windows-gnu oracle build fails under -Wconversion in audio-math.h #2648, filed). PR CI runs the full suite.
  • Pinned suite counts: none cover this test.
  • Real app: not applicable (no UI, protocol or logging change).

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (N/A for docs-only; a focused CI fix may push RED and GREEN together)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): none

Behaviour-neutral extraction before the Rust port. The decisions of
obs_source_set_flags(), obs_source_set_audio_mixers(),
obs_source_get_audio_mixers(), obs_source_enable_push_to_mute(),
obs_source_enable_push_to_talk(), obs_source_set_monitoring_enabled(),
obs_source_set_monitoring_type(), obs_source_get_monitoring_type(),
clamp_balance() and obs_source_set_audio_active() in obs-source.c.h move
to libobs/obs-source-monitoring.c.h, as thirteen functions on plain
values declared in the new libobs/obs-source-monitoring.h without
EXPORT (hidden, as -fvisibility=hidden keeps them):

- _changes(): a set does something only when the value changes (the
  flags, the mixers, monitoring on or off, and the push-to enables'
  signal);
- _has_audio(): the mixers' gate for a source that does not own its
  info id (OBS_SOURCE_AUDIO in the output flags);
- _mixers_store(): the low 32 bits of what an audio_mixers handler
  leaves;
- _push_to_logs(): the push-to enables log a change on an audio source;
- _on_type(): monitoring on and muted is Monitor Only, else Monitor and
  Output (#2447), for the compatibility signal and the getter;
- _stored_type() and _monitor() -> KEEP | CREATE | DESTROY: the type
  obs_source_set_monitoring_enabled() stores and the monitor route;
- _route() -> OFF | MONITOR_ONLY | MONITOR_AND_OUTPUT | ON: the steps of
  obs_source_set_monitoring_type() for a type (#2444, #2447);
- _off_reads_mute() and _off_unmutes(): none looks at the mute only when
  Monitor Only set it, and undoes it if it is still on;
- _only_mutes(): Monitor Only mutes first if not muted;
- _balance(): clamp_balance(), NaN centred, else clamped to [0, 1]
  (#2051);
- _audio_active() -> NONE | ACTIVATE | DEACTIVATE: the signal of a
  change.

Split per step, as #2153 did, so every call and read stays where it was
and under its condition: obs_source_valid(), audio_mutex,
os_atomic_load_bool() of monitor_only_muted once before the steps and
os_atomic_set_bool() of it and of audio_active, the reads of
owns_info_id (and of the output flags only when it is false),
obs_source_get_output_flags() before the changed test, user_muted read
only when monitoring turns on, monitoring_enabled read again after the
signals, obs_source_muted() only where the C's && reached it (after
monitoring is off, for none), obs_source_set_muted() and
obs_source_set_monitoring_enabled() in their order (the mute before
monitoring turns on), every calldata_*(), signal and log, the (float)
of the handler's balance, audio_monitor_create() and _destroy(), and
the getters' answers for an invalid source (0, false and 0.5).
clamp_balance() stays as an inline wrapper for its two calls. The
monitoring type crosses as int; the header copies OBS_SOURCE_AUDIO and
the three monitoring types, and obs-source.c.h checks them and that
enum obs_monitoring_type is int-sized with _Static_assert.

Checked in a scratch harness (not committed). It compiles
origin/master's fifteen functions (the ten above with
obs_source_get_flags(), obs_source_get_monitoring_enabled(),
obs_source_get_balance_value(), obs_source_set_balance_value() and
obs_source_audio_active()) verbatim next to this branch's and the moved
file, as C++, over a stand-in source whose fields log every read and
write with its value. Every call is logged in order with its arguments:
obs_source_valid(), the lock and unlock, the calldata sets and gets,
each signal, blog(), obs_source_get_output_flags(), the atomics,
obs_source_muted(), obs_source_set_muted(), obs_source_dosignal(), the
push-to signal and audio_monitor_create() and _destroy(). A signal
handler may leave any mixers (above UINT32_MAX, negative, the ends of
int64_t) or any balance, and another thread may write any field at any
event. Inputs: an invalid source or any start state, flags and mixers
at the edges and random, types 0 to 4, -1, the ends of int and random,
balances at NaN (both signs), the signed zeros, the smallest
subnormals, 1.0 and its neighbours, the ends of float, the infinities
and random bit patterns; one to four operations each.

5,800,000 runs: 2,000,000 each with GCC and Clang at -O2, 500,000 each
at -O0, 300,000 each under ASan and UBSan with no recovery (GCC -O0,
Clang -O2, without C++'s enum range check, which C does not have) and
200,000 with gcov. All 82,503,972 logged events match, as does the
final state. Every branch of origin/master's functions is taken both
ways.

30 deliberately broken moves were planted, and all 30 fail it: each
function's rule inverted, widened or made constant (changes as == and
>, the audio bit as bit 0 or any flag, the mixers shifted or saturated,
the log rule without the flag or without the change, the on type
constant or inverted, the stored type Monitor Only, the monitor never
kept or created on the wrong edge, each route moved, the default OFF,
the three mute steps constant, NaN as 0.0, the clamp at <= 0 and below
1.0, the active signal never NONE or on prev), and at the call sites
the mute read before the mark, user_muted read without its log, the
output flags read only after a change, the mixers' gate reading the
output flags first, and the type taken mod 4.

git blame on the moved lines shows the upstream commits d2934ec and
646836a, and the fork's #2058 (the balance clamp) and #2450 (the
Monitor Only steps); they move as they are.

The new file joins libobs.core-source with libobs.pch.h, which includes
the new header; source-sets.json lists it. docs/rust-port/naming.md
already maps libobs/obs-source*.c.h to rust/obs-source. The exported
symbol set is unchanged (1766 on the C backend); the thirteen functions
are local.

Refs #2621.
test_source_monitoring_steps compiles libobs/obs-source-monitoring.c.h
(ASan and UBSan) and calls only its functions through the header. 16
cases:

- the header's copies of OBS_SOURCE_AUDIO and the three monitoring
  types, the enum's size and the monitor, route and active values;
- the same-value rule over pairs of 32-bit edges and the four bools;
- the audio gate over every bit and the mixers' stored value;
- the push-to log rule over flags and changes;
- the on and stored types and the monitor route, every combination;
- the route over -1000..1000 and the ends of int, and the three mute
  steps;
- the balance at NaN (quiet, negative and signalling), the signed
  zeros, the smallest subnormals, 1.0 and its neighbours, the ends of
  float and the infinities;
- the audio active signal, every combination.

obs_source_set_monitoring_type(), _set_monitoring_enabled(),
_get_monitoring_type(), _set_balance_value(), _set_audio_mixers(),
_get_audio_mixers(), _set_flags(), the push-to enables and
_set_audio_active() are also copied onto a stand-in source that records
its signals, logs, mute calls and monitor, to pin end to end: every
type (none, Monitor Only, Monitor and Output, 3 and -1) from every
start state (on or off, muted or not, Monitor Only's mark set or not),
with the steps in order (the mute before monitoring turns on), the
compatibility signal's type and the getter after each; Monitor Only
then none (the mute goes) and with a mute set in between (it stays);
the same value of monitoring on or off doing nothing; the balance sent
and the one a handler leaves (NaN, 2.0, -1.0, 0.75, -0.0); the mixers
of an audio source, a video-only source with and without its own info
id and an invalid source, and a handler's value; the flags; the
push-to enables with the same value (no signal, no log), a change
(log, then signal) and on a video-only source (signal, no log); and
audio active set twice (one signal).

Characterized, not endorsed:
- the mixers a handler leaves are truncated to their low 32 bits:
  2^32 + 3 is 3, -1 is UINT32_MAX;
- a balance of -0.0 stays -0.0;
- Monitor and Output unmutes a mute the user set, while none keeps it.

It is in the native test graph, in name order, with the header as a
watch input and libm off MSVC. No assert_in_range or fail_msg, so it
builds with cmocka 1.x and 2.x, and no two enum types are compared.
The real-libobs tests test_source_monitoring_type,
test_source_monitor_only_load and test_source_audio_balance_mono cover
the callers.

Refs #2621.
RED for the port of libobs/obs-source-monitoring.c.h to a new
monitoring module of rust/obs-source, next to ptm_gate and
volume_apply. The safe core is a stub (todo!()): changes(),
has_audio(), mixers_store(), push_to_logs(), on_type(), stored_type(),
monitor() -> Monitor (Keep, Create, Destroy), route() -> Route (Off,
MonitorOnly, MonitorAndOutput, On), off_reads_mute(), off_unmutes(),
only_mutes(), balance() and audio_active() -> Active (None, Activate,
Deactivate), with AUDIO and the three monitoring types.

The plan sketched wider steps: monitoring_enable(cur, enabled, muted)
returning the compatibility type, the stored type and the monitor at
once, monitoring_type_first(type, muted) and
monitoring_type_after_disable(muted_for_monitor_only, muted_now), and
type_of(valid, enabled, muted). Each would take a read the C makes only
under a condition (user_muted only when monitoring turns on,
monitoring_enabled again after the signals, obs_source_muted() only
where its && reaches it) before the C knows it makes it; so the C keeps
those conditions and asks one rule per read. The validity checks and
the getters' literals stay C.

tests/source/monitoring.rs ports test_source_monitoring_steps 1:1: its
16 cases under the same names (steps_*), in the same order, with the
same values and expectations, the characterized-not-endorsed cases and
the stand-in source's copies of the callers included.

Edge cases (edge_*) check the core against models of origin/master's
expressions:
- every decision over every combination of its flags;
- the route over -100,000..100,000, the ends of i32 and every power of
  two with its neighbours;
- the mixers at every power of two of i64 with its neighbours and
  negations, and the audio gate at every bit;
- the balance at every special value (both NaNs, signalling NaNs, the
  signed zeros, the subnormals, 1.0 and its neighbours, the ends and
  the infinities), every 1/4096 from -2.0 to 2.0 and a stride over
  every bit pattern;
- proptests (4,096 cases each): every decision over full-range values,
  and sequences of up to eleven operations (flags, mixers, push-to,
  monitoring on or off, any type, the getters, any balance, audio
  active, a user mute, a handler that leaves any mixers or balance,
  the output flags and the info id) through the stand-in against a
  copy of the callers with origin/master's expressions inline; both
  end in the same state after every step.

soldr cargo test -p obs-data --test obs-tests-core --
source::monitoring passes 1 of 22 (the constants) and fails 21 with
"not yet implemented".

Refs #2621.
Ports libobs/obs-source-monitoring.c.h, the monitoring, monitor-only
mute, balance, mixer, flag, push-to and audio active rules of
obs-source.c, to the monitoring module of rust/obs-source.
obs-source.c.h stays C around it: obs_source_valid(), audio_mutex, the
atomics on monitor_only_muted and audio_active, every read of the
source's fields at its point (the output flags only when the source does
not own its info id, user_muted only when monitoring turns on,
monitoring_enabled again after the signals),
obs_source_get_output_flags(), obs_source_muted() and
obs_source_set_muted() under the C's own &&, every calldata_*(), signal
and log, the (float) of the handler's balance, audio_monitor_create()
and _destroy(), and the getters' literals. The hybrid libobs drops the C
file and links the Rust shims in its place.

Safe core (src/monitoring.rs), thirteen functions:
- changes(): cur != value;
- has_audio(): AUDIO (1 << 1) in the output flags;
- mixers_store(): the low 32 bits of the i64, by its bytes;
- push_to_logs(): has_audio() && changed;
- on_type(), stored_type(): Monitor Only when muted, else Monitor and
  Output; Monitor and Output when on, else none;
- monitor() -> Monitor: Create on false -> true, Destroy on true ->
  false, else Keep;
- route() -> Route: 0, 1 and 2 to Off, MonitorOnly and
  MonitorAndOutput, any other i32 On;
- off_reads_mute(), off_unmutes(), only_mutes(): the mark, the mute,
  and not muted;
- balance(): NaN is 0.5, then the C's two compares in its order (not
  f32::clamp()), so -0.0 stays -0.0;
- audio_active() -> Active: Activate on false -> true, Deactivate on
  true -> false, else None.
The module denies clippy's arithmetic, indexing, as, float_cmp,
unwrap, expect, panic, todo, unimplemented and unreachable lints,
keeps no state and takes no lock.

Shims (src/ffi/source_monitoring.rs): the thirteen C signatures by
value; the monitoring types as int, the handler's mixers as int64_t,
the balance as float, the monitor, route and active outcomes as the
C's enums (u32). No pointer crosses and no struct is mirrored. No
intentional difference from the C.

C side: the file leaves libobs.core-source for its own group,
libobs.ported-source-monitoring (LIBOBS_PORTED_SOURCES), whose PCH is
only math.h and obs-source-monitoring.h; libobs.pch.h keeps the header
for obs-source.c. The functions are not EXPORT, so the shims are
hidden: rust-hidden.txt, the local: list of rust-exports.map and
rust-unexports-macos.txt. libobs-rust already links the crate's ffi.
ci/test_ported_sources.py checks the group on every host.

test_source_monitoring_steps still compiles the C file into itself,
unchanged. The new test_source_monitoring_steps_rust builds the same
test source against libobs_rust-static instead, with libm off MSVC
for nextafterf(), as test_transition_load_steps_rust does, and links:
the test includes the header and obs.h and calls only hidden
functions. It passes 16/16 on the C backend, the hybrid and
libobs-c-reference, as does test_source_monitoring_steps; so do
test_source_monitoring_type, test_source_monitor_only_load,
test_source_audio_balance_mono and the other 80 source, audio,
monitor, mute, push-to and volume tests (three failed once each under
a parallel run and pass alone on both). The exported symbol sets are
unchanged and equal: 1766 on the C backend, the hybrid and
libobs-c-reference; the thirteen functions are local in all three, and
the group's object is built only for libobs-c-reference.

soldr cargo test -p obs-data --test obs-tests-core --
source::monitoring:: passes 22 of 22.

No user-visible change, so no docs/features.md line.

Refs #2621.
Tier 3 for the monitoring port. oracle/source_monitoring.c compiles the
unmodified libobs/obs-source-monitoring.c.h with its thirteen functions
renamed to oracle_*, and exports the header's values and sizes by
index (the renames also rename the monitor and route enum tags, which
share their functions' names, so the enums are sized by what the
functions return). tests/source/monitoring_parity.rs gives each input
to the oracle, the shim (the extern "C" function the hybrid links) and
the core, and compares each bool as the C's byte (0 or 1, the same on
both sides), each outcome as the C's enum value, each integer exactly
and the balance by its bits:

- the header's values and the sizes of the three enums, bool, int and
  float;
- every function of flags over every combination of them, and the
  push-to log rule with each flag bit;
- the same-value rule and the audio gate over every pair of 32-bit
  edges and every bit;
- the mixers at every power of two of int64_t with its neighbours and
  negations, the 65,536 values either side of 2^32 and -2^32 and at
  each end, and a stride over int64_t;
- the route over every int from -1,000,000 to 1,000,000, every 65,521st
  int and the ends;
- the balance over every bit pattern whose top byte is 0x00, 0x3f,
  0x7f, 0x80, 0xbf or 0xff (the zeros, the subnormals, 0.5 to 2.0, the
  infinities and every NaN, of both signs: 100,663,296 patterns) and
  every 251st pattern of the rest;
- proptests (20,000 cases) over full-range values.

Nothing is excluded: the C has no undefined or host-dependent result
here (isnan() and the compares are IEEE on every host, and the
(uint32_t) of an int64_t is modular), and the port has no intentional
difference. Every one of the 2^32 balance patterns was also checked
once (131 s in a debug build, too slow to keep).

Mutation check: 34 mutants, all killed. 22 in the core (changes as ==,
the audio bit as bit 0, the mixers saturated or byte-swapped, the log
rule without the flag or without the change, the on type inverted, the
stored type Monitor Only, the monitor never created or created on the
wrong edge, each route moved and the default Off, the three mute steps
constant or inverted, NaN as 0.0, the clamp at <= 0.0 and above 0.999,
the active signal on the wrong edge or never None): Tier 1 and Tier 3
each kill all 22. 12 in the shims (changes inverted, the mixers
shifted, the log rule always changed, the on type inverted, the
monitor's and the active signal's arguments swapped, the type taken
mod 4, the balance's absolute value, Create as Destroy, On as Off,
Activate as None, and off_unmutes() answered by the wrong rule): Tier 3
kills all 12 (Tier 1 calls only the core).

Refs #2621.
rust/README.md gets the row for libobs/obs-source-monitoring.c.h
(obs-source::monitoring), in sorted place: what moved, what stays C
and why (every read and call at its point and under its condition, the
C's own && before each mute read, the atomics, the signals, the
monitor and the getters' literals), the characterized-not-endorsed
behaviours, the tests that see the swap and what Tier 3 covers. The
obs-source crate row, its Cargo description and the lib.rs crate docs
name the new module. docs/rust-port/naming.md already maps
libobs/obs-source*.c.h to rust/obs-source.

rust/obs-c-oracle/benches/port_comparison/source_monitoring.rs runs
1024 updates over every combination of the flags the C reads, with
monitoring types 0, 1, 2, 3 and -1, handler mixers of 0x3f, -1 and
past 32 bits, and balances at NaN, -0.0, 0.25, 0.5, 1.0, 2.0 and -1.0,
each through the same-value rule, the audio gate, the stored mixers,
the push-to log rule, the monitoring types and monitor route, the
type's route and its three mute steps, the balance twice and the
active signal, on the shims and on the oracle, and checks both
checksums match. Release, x86_64 Linux, GCC, a loaded host, median per
1024 updates: Rust 17.74 us, C 18.05 us (0.98x), about 17 ns an update.

The port changes nothing a user can see, so docs/features.md has no
line.

Fixes #2621.
@rdoupe
rdoupe force-pushed the fix/rust-port-source-monitoring-moni-204 branch from ead7c97 to 22d9583 Compare October 27, 2026 14:54
@rdoupe
rdoupe marked this pull request as ready for review October 27, 2026 15:15
@rdoupe
rdoupe requested a review from zackees as a code owner October 27, 2026 15:15
@rdoupe
rdoupe added this pull request to the merge queue Oct 27, 2026
Merged via the queue into master with commit 7ba13d0 Oct 27, 2026
36 checks passed
@rdoupe
rdoupe deleted the fix/rust-port-source-monitoring-moni-204 branch October 27, 2026 15:48
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Needs fix to Done in obs-rust Multiview Oct 27, 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 the source monitoring, monitor-only mute and balance rules in obs-source.c to obs-source

1 participant