Skip to content

obs-output: Port the raw output audio admission and capture hookup - #2457

Merged
zackees merged 6 commits into
obs-rust:masterfrom
rdoupe:port/raw-audio
Oct 26, 2026
Merged

zackees merged 6 commits into
obs-rust:masterfrom
rdoupe:port/raw-audio

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Fixes #2449

What and why

Ports the raw output audio admission and capture hookup of libobs/obs-output.c.h to rust/obs-output, as a new module raw_audio, next to delay and interleave. Every raw output (one with raw_audio or raw_audio2: the FFmpeg custom output, DeckLink and AJA) runs these for each audio packet, and every output runs the hookup once when it starts capturing:

  • prepare_audio(): an output without video takes the packet whole; no video start yet, the packet waits; a packet that ends at or before the video start is dropped; otherwise the front is cut to the video start;
  • default_raw_audio_callback(): the audio start, the block and push sizes, the block loop, each block's timestamp (with the pause offset) and the frame count;
  • start_raw_audio(): which mixes are connected with raw_audio2;
  • hook_data_capture(): which encoded callback (interleave when the output has both video and audio), and whether the delay wraps it, with its length.

The plan's API was split per step. The plan sketched admit(in) -> Pass | Wait | Drop | Cut { frames, ns }, mixers(mask, raw2) and hook(flags, delay_sec). admit() would read last_video_ts before the video start check and compute the packet's duration (a division by the sample rate) before the before-video check; mixers() would read mixer_mask once instead of once per mix. So each step is its own function, asked at its own point (as #2153 did), and nineteen functions cross the C ABI:

  • prepare_audio(): obs_output_raw_audio_passthrough(), _video_unset() (asked before the video start is taken from the pause data, and again after), _before_video(), _ends_before(), and the cut: _cut_ns(), _cut_ts(), _cut_bytes() (asked for each plane) and _cut_frames();
  • default_raw_audio_callback(): _start_unset(), _block_bytes(), _push_bytes() (asked for each plane), _can_pop(), _block_ts(), _paused_ts() (under the pause mutex) and _next_frames();
  • start_raw_audio(): _mix_on(), asked for each mix;
  • hook_data_capture(): _interleave(), _delay_on() and _delay_ns().

What stays C, at its point and under its condition:

  • data_active(), audio_pause_check(), the deques and each plane's pointer advance;
  • the pause mutex and its reads: last_video_ts only while video_start_ts is 0, as today, and ts_offset;
  • every conversion that divides by the sample rate: the packet's duration (util_mul_div64(frames, 1e9, sample_rate)), the cut in frames (util_mul_div64(cutoff, sample_rate, 1e9)) and audio_frames_to_ns(). On MSVC x64 util_mul_div64() is _udiv128(), which faults on a zero divisor. C passes the results in;
  • the raw_audio and raw_audio2 callbacks and the NULL test of raw_audio2, get_first_mixer() (already the Rust video_checks::first_mixer), get_audio_conversion(), audio_output_connect(), start_raw_video();
  • reset_packet_data() under interleaved_mutex, obs_encoder_start(), the delay's fields, os_atomic_set_bool() and its log line;
  • stop_raw_audio(), unchanged.

The header copies OBS_OUTPUT_VIDEO and AUDIO_OUTPUT_FRAMES, and obs-output.c.h checks them with _Static_assert. No pointer crosses and no struct is mirrored.

Six commits:

  1. Move (behaviour-neutral, 934bfc228): the decisions go to libobs/obs-output-raw-audio.c.h, declared in the new obs-output-raw-audio.h without EXPORT, so they are hidden. The file joins libobs.core-output. git blame on the moved lines shows only upstream commits.

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

    • the stand-in output's fields log every read and write, with the value;
    • every call is logged in order with its arguments: each lock and unlock, data_active(), audio_pause_check(), each deque push and pop, util_mul_div64(), each raw_audio / raw_audio2 call with its block, audio_output_connect(), start_raw_video(), reset_packet_data(), obs_encoder_start() with its callback, os_atomic_set_bool() and the log line;
    • the stubs answer from one seeded stream in call order. Another thread moves last_video_ts and ts_offset around each lock and callback, and audio_pause_check() may move the packet. Reads with nothing between them are compared as a sorted run (the C leaves operand order unsequenced);
    • the inputs cover any flag word with and without raw_audio2, video starts at, around and up to three packets from each packet, rates of 1 Hz to about 1 GHz, 0 to 8 planes, buffered sizes around one block in every mix, packets ending exactly at the video start, full-range mixer masks, frame totals and delays.

    2,600,000 runs (GCC and Clang -O2, 1,000,000 each; GCC -O0, 300,000; GCC -O0 with coverage, 100,000; ASan with UBSan, no recovery, under GCC -O0 and Clang -O2, 100,000 each): all 1,064,380,967 logged events match, and so does the output after each run. Every branch of origin/master's functions is reached both ways (gcov).

    21 deliberately broken moves were tried, and 20 fail the harness:

    • last_video_ts read with a video start set; the second video start check dropped;
    • the duration computed before the before-video check;
    • the push size hoisted out of the plane loop (one audio_size read); mixer_mask read once for the loop;
    • audio_start_ts read under the pause mutex;
    • thirteen changed decisions: the passthrough inverted, each comparison moved by one, the cut reversed, a frame count off by one, the pause offset dropped, the interleave rule as ||, the delay rule inverted and its product in uint32_t.

    The 21st, the cut in bytes without the (uint32_t) truncation, is equivalent: the cut in frames never exceeds the packet's uint32_t frames.

  2. Characterization (88a433050): test_output_raw_audio_steps, 19 cases. It compiles the moved file and obs-output-video-checks.c.h (for obs_output_first_mixer()), with ASan and UBSan, and calls only their functions. It pins every decision over edge values, and copies prepare_audio(), the block loop, start_raw_audio() and hook_data_capture() onto a stand-in output, end to end at 48 kHz:

    • audio before the video by one sample (one frame dropped) and by less than one;
    • a packet ending exactly at the video start (dropped) and one a nanosecond later (one frame kept);
    • at and after the video; no video start yet (waits, then taken from the pause data, and kept); an audio-only output;
    • the block loop over one, two and three packets and single packets of 1.5, 2.5 and 3 blocks, with the block timestamps and the pause offset;
    • every 8-bit mixer mask with and without raw_audio2, and every flag combination of the hookup with and without a delay.

    It is in the test graph, sorted, with both headers as watch inputs.

  3. RED (7e48aa77b): Tier 1 against todo!(). It ports the 19 C cases 1:1 and adds 5 edge tests: every decision against a model of the C over 30 special timestamps (pairs, and triples for the drop), edge sizes and frame counts, every low 16-bit flag word and mask at every index, the delay over a stride through u32, and proptests over full-range values and over packet sequences through the stand-in against origin/master's expressions inline.

  4. GREEN (7053e9925): the safe core (nineteen functions) and nineteen #[no_mangle] shims, in a new libobs.ported-output-raw-audio group whose PCH is only the new header.

    • The commit updates source-sets.json, the unity lists, the three export lists and ci/test_ported_sources.py, each in sorted place.
    • test_output_raw_audio_steps has no _rust variant, as for test_output_stop_stats_steps: the shims' archive member also holds the rest of obs-output, which does not link on its own. Its tests.d file says so.
  5. Tier 3 (ed643bfba): a C oracle of the unchanged file, the parity tests and a mutation check.

  6. Docs (22cb23067): the README rows, the crate's description, lib.rs and a port_comparison bench file in the sorted lists. docs/rust-port/naming.md maps the file in the move commit. The port changes nothing a user can see, so docs/features.md has no line.

The core denies clippy's arithmetic, indexing, as, unwrap, expect, panic, todo, unimplemented and unreachable lints. It keeps no state, takes no lock and does not divide. Every sum, difference and product wraps as the C's unsigned arithmetic does.

  • Kept, characterized, not endorsed (upstream behaviour, unchanged):
    • the block loop pops only while more than one block is buffered (>), so a raw output always holds its last full block back, and nothing sends it when the output stops: the last 1024 frames of every mix are lost;
    • a cut of less than one sample moves the timestamp to the video start but drops no frame, and a packet ending a nanosecond into the video keeps one frame: the conversion to frames rounds down;
    • a packet whose end wraps past UINT64_MAX is dropped;
    • the cut in frames is truncated to uint32_t;
    • with no mix in the mask, raw_audio2 connects none and raw_audio connects mix 0; bits past MAX_AUDIO_MIXES are ignored.
  • Intentional differences: mix_on() with an index at or past the width of size_t, where the C's shift is undefined, says not set. The C asks only 0 to 5.

Bench (x86_64 Linux, GCC, release, not pinned to a core, a loaded host; median per 1024 packets through every admission and block decision): Rust 12.57 µs, C 12.54 µs (1.00x).

RED → GREEN

  • RED commit: 7e48aa77b (obs-output: Add Tier 1 tests for raw audio; it was d51082e08 before the rebase onto 96a2393b1).
    • soldr cargo test -p obs-data --test obs-tests-core -- output::raw_audio: 1 passed (the constants), 23 failed, each on a todo!().
    • On that commit, local_gate --lane lint was clean, and --test-diff origin/master ran 4217 tests: 4194 passed, 6 skipped, and only those 23 failed.
  • GREEN (7053e9925): Tier 1 24/24.
    • test_output_raw_audio_steps passes 19/19 on the C backend, on hybrid libobs and on libobs-c-reference.
    • test_output_input_checks, test_output_before_video, test_raw_output_video_reset, test_output_delay_e2e, test_output_delay_restart, test_output_interleave_e2e, test_output_interleave_restart, test_replay_buffer_pause_stop, test_ffmpeg_output_drain, test_encoder_error_stop, test_output_end_capture_thread_join and test_output_video_checks_steps pass on all three (run through ctest, every case run, none skipped).
    • Exported symbols are identical on all three (1766). The nineteen 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 (ed643bfba): 7/7, oracle, shims and core compared exactly.
    • The two constants.
    • Every two-value decision over every pair of 30 special timestamps, and the drop over every triple (27,000 calls).
    • The sizes over 13 special usize values, 12 frame counts and the 30 cut lengths.
    • Every low 20-bit flag word and a stride through u32; every low 16-bit mask under four high words at every index below the width; the delay over 0 to 100,000 and a stride through u32.
    • The callers copied onto a stand-in output, over the oracle and over the shims: 186,624 two-packet sequences around the video start (flags, video starts, pause data, rates of 1 Hz to 384 kHz, sizes 1 to 8, 1, 2 and 8 planes), every 12-bit mixer mask with and without raw_audio2, every 6-bit flag word with five delays.
    • Proptests of 20,000 cases each, over full-range values and over packet sequences from any state.
    • The stand-in's conversion is a shared copy of util_mul_div64()'s portable formula with a rate of at least 1; on MSVC x64 the oracle side asserts the rate first (cfg!(all(target_env = "msvc", target_arch = "x86_64"))).
  • Mutation check: 27 mutants (21 in the core, 6 in the shims).
    • Tier 1 kills all 21 in the core (2 to 9 tests each). Tier 3 kills 26 (1 to 4 tests each), the shim mutants included.
    • The survivor is equivalent: the shim's ends_before() with the timestamp and the duration swapped adds them the same way.
  • Checks on 98d7d15bb (this head before the rebase onto 96a2393b1, which changes only test_source_video_tick_steps.c):
    • local_gate --lane lint, --test-diff origin/master (4224 passed, 6 skipped) and --lane cross all pass;
    • soldr cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets --locked -- -D warnings is clean;
    • soldr cargo test -p obs-c-oracle --locked --bench port_comparison passes.
  • Full ctest (C backend, hybrid libobs, libobs-c-reference) on 98d7d15bb: 100% passed on each: 520/520 (C backend), 548/548 (hybrid), 548/548 (libobs-c-reference), with no reruns needed. On every lane, test_v4l2_vivid_replug and test_v4l2_vivid_stall skip themselves (they need root and the vivid module), and so does test_pulse_default_follow (it needs a PulseAudio null-sink module this headless host's private session lacks). None touches raw output audio.
  • After the rebase, on 22cb23067: local_gate --lane lint and --test-diff origin/master (4224 passed, 6 skipped) pass again; test_output_raw_audio_steps, test_output_input_checks, test_output_before_video, test_raw_output_video_reset, test_output_interleave_e2e and test_output_delay_e2e pass on all three lanes, and the exported symbol sets are still identical.
  • Pinned suite counts: none cover this suite. The only pinned count, the graphics suite's 12, is unchanged.
  • 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)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): one, mix_on() past the width of size_t

Behaviour-neutral extraction before the Rust port. The decisions of
prepare_audio(), default_raw_audio_callback(), start_raw_audio() and
hook_data_capture() move to libobs/obs-output-raw-audio.c.h, as
nineteen functions on plain values declared in the new
libobs/obs-output-raw-audio.h without EXPORT (hidden, as
-fvisibility=hidden keeps them):

- prepare_audio(): _passthrough() (no OBS_OUTPUT_VIDEO flag),
  _video_unset() (asked before the video start is taken from the pause
  data, and again after), _before_video(), _ends_before() (the packet
  ends at or before the video start: dropped) and the front cut:
  _cut_ns(), _cut_ts(), _cut_bytes() (asked for each plane) and
  _cut_frames();
- default_raw_audio_callback(): _start_unset(), _block_bytes(),
  _push_bytes() (asked for each plane), _can_pop() (the block loop),
  _block_ts(), _paused_ts() (under the pause mutex) and _next_frames();
- start_raw_audio(): _mix_on(), asked for each mix with raw_audio2;
- hook_data_capture(): _interleave() (the encoded callback),
  _delay_on() and _delay_ns().

The plan sketched one admit() returning pass, wait, drop or cut. That
would read last_video_ts before the video start check and compute the
packet's duration before the before-video check, so each step is its
own function, asked at its own point, as obs-rust#2153 did. last_video_ts is
still read under the pause mutex only while video_start_ts is 0, and
video_start_ts is read again after; the duration and the cut in frames
are computed only on the cut path; audio_size is read once per plane;
mixer_mask once per mix; audio_start_ts before the pause mutex is taken
and ts_offset under it.

C keeps data_active(), audio_pause_check(), the deques and each
plane's pointer advance, the raw_audio and raw_audio2 callbacks and the
NULL test of raw_audio2, get_first_mixer(), audio_output_connect(),
get_audio_conversion(), start_raw_video(), reset_packet_data() under
interleaved_mutex, obs_encoder_start(), the delay's fields,
os_atomic_set_bool() and log, and every conversion that divides by the
sample rate: util_mul_div64(frames, 1e9, sample_rate),
util_mul_div64(cutoff, sample_rate, 1e9) and audio_frames_to_ns(),
passed in by value. On MSVC x64 util_mul_div64() is _udiv128(), which
faults on a zero divisor. stop_raw_audio() is unchanged.

The expressions move as they were: the uint64_t sums and differences,
the size_t products, the (uint32_t) truncation of the cut, the uint32_t
frame difference and the uint64_t delay product.

Checked in a scratch harness (not committed). It compiles
origin/master's prepare_audio(), default_raw_audio_callback(),
start_audio_encoders(), start_video_encoders(), start_raw_audio(),
preserve_active(), hook_data_capture(), get_first_mixer() and the flag
helpers verbatim, and this branch's with the moved file, as C++, over
a stand-in output whose fields log every read and write with the
value. It logs every lock and unlock, data_active(),
audio_pause_check(), deque push and pop (with their sizes),
util_mul_div64(), raw_audio and raw_audio2 call (with the block),
audio_output_connect(), get_audio_conversion(), start_raw_video(),
obs_output_get_video_conversion(), reset_packet_data(),
obs_encoder_start() (with the callback), os_atomic_set_bool() and log
line, in order. The stubs answer from one seeded stream in call order;
another thread moves last_video_ts and ts_offset around each lock and
callback, and audio_pause_check() may move the packet. Reads with no
write or call between them are compared as a sorted run, since the C
leaves their operand order unsequenced.
- Inputs: any flag word (the four flags and random high bits), with and
  without raw_audio2; video starts of 0, at, one either side of, half a
  packet, a packet and up to three packets either side of the packet,
  and random; last_video_ts likewise; rates of 1 Hz to about 1 GHz;
  audio sizes 0 to 8 and 0 to 8 planes; buffered sizes below, at and
  above one block in every mix and plane; 0 to 5 packets of 0, 1, 480,
  1023 to 1025, 2048, 4096 or random frames, including ones ending
  exactly at the video start; random audio starts and frame totals;
  mixer masks of the six mixes and full-range ones; every encoder slot
  set or not; delays of 0, small and full-range.
- 2,600,000 runs (GCC and Clang -O2, 1,000,000 each; GCC -O0, 300,000;
  GCC -O0 with coverage, 100,000; ASan with UBSan under GCC -O0 and
  Clang -O2, 100,000 each) give equal events and equal outputs after
  each run: 1,064,380,967 events.
- Every branch of origin/master's functions is reached both ways
  (gcov).
- 21 deliberately broken moves were planted. 20 fail it: the
  passthrough inverted, last_video_ts read with a video start set, the
  second video start check dropped, the duration computed before the
  before-video check, push sizes hoisted out of the plane loop (one
  audio_size read), mixer_mask read once for the loop, audio_start_ts
  read under the pause mutex, and thirteen changed decisions (each
  comparison moved by one, the cut reversed, a frame count off by one,
  the pause offset dropped, the interleave rule as ||, the delay rule
  inverted and its product in uint32_t). The 21st, the cut in bytes
  without the (uint32_t) truncation, is equivalent: the cut in frames
  never exceeds the packet's uint32_t frames.

git blame on the moved lines shows only upstream commits (85ca1b6,
153fa63, a1fbf10, b8a3ae1, 6ec0b2d, 0f9376f and earlier).
The fork has not changed them.

The constants OBS_OUTPUT_VIDEO and AUDIO_OUTPUT_FRAMES are copied into
the header, so it needs no core header; obs-output.c.h checks them with
_Static_assert. The new file joins libobs.core-output, just before
obs-output.c.h, with libobs.pch.h, which includes the new header;
source-sets.json lists it. docs/rust-port/naming.md maps it to
rust/obs-output. The exported symbol sets are unchanged (1766); the
nineteen functions are local.

Refs obs-rust#2449
test_output_raw_audio_steps compiles libobs/obs-output-raw-audio.c.h
and libobs/obs-output-video-checks.c.h (for obs_output_first_mixer())
with ASan and UBSan, and calls only their functions through
obs-output-raw-audio.h and obs-output-video-checks.h. 19 cases:

- the copied constants;
- prepare_audio(): the passthrough over every low 16-bit flag word; no
  video or audio start over the edge timestamps; before the video over
  every pair of edge timestamps; the drop for a packet ending before or
  exactly at the video start, one ending a nanosecond after it, a
  0-frame packet and an end wrapping past UINT64_MAX, and over every
  triple of edge timestamps; the cut in nanoseconds, its timestamp, the
  cut in bytes and the frames left;
- default_raw_audio_callback(): the block and push sizes, the block
  loop's strict >, the block timestamp, the pause offset and the frame
  count, with their wraps;
- start_raw_audio()'s mix rule over every 8-bit mask and index;
- hook_data_capture()'s interleave, delay and delay product rules.

prepare_audio(), the block loop of default_raw_audio_callback(),
start_raw_audio() and hook_data_capture() are also copied onto a
stand-in output that counts the bytes buffered, with the real
util_mul_div64(), to pin end to end at 48 kHz: audio before the video
by one sample (one frame dropped) and by less than one (the timestamp
moves, no frame is dropped), a packet ending exactly at the video start
(dropped) and one a nanosecond later (one frame kept), at and after the
video, no video start yet (waits; then taken from the pause data, and
kept), an audio-only output (always whole), the block loop over one,
two and three packets and single packets of 1.5, 2.5 and 3 blocks, with
the block timestamps and the pause offset; every 8-bit mixer mask with
and without raw_audio2; and every flag combination of the hookup with
delays of 0, 1, 20 and UINT32_MAX seconds.

Characterized, not endorsed:
- the block loop pops only while more than one block is buffered, so
  the last full block is held back, and nothing sends it when the
  output stops;
- a cut of less than one sample moves the timestamp to the video start
  but drops no frame, and a packet ending a nanosecond into the video
  keeps one frame: the conversion rounds down;
- a packet whose end wraps past UINT64_MAX is dropped;
- the cut in frames is truncated to uint32_t;
- with no mix in the mask, raw_audio2 connects none and raw_audio mix
  0; bits past MAX_AUDIO_MIXES are ignored.

It is in the native test graph, in name order, with both headers as
watch inputs, and links libm off MSVC. No assert_in_range or fail_msg,
so it builds with cmocka 1.x and 2.x. The real-libobs tests
test_raw_output_video_reset, test_output_before_video,
test_output_delay_e2e, test_output_delay_restart,
test_output_interleave_e2e, test_output_input_checks,
test_replay_buffer_pause_stop and test_ffmpeg_output_drain cover the
callers.

Refs obs-rust#2449
RED for the port of libobs/obs-output-raw-audio.c.h to a new raw_audio
module of rust/obs-output, next to delay and interleave. The safe core
is a stub (todo!()): passthrough(), video_unset(), before_video(),
ends_before(), cut_ns(), cut_ts(), cut_bytes(), cut_frames(),
start_unset(), block_bytes(), push_bytes(), can_pop(), block_ts(),
paused_ts(), next_frames(), mix_on(), interleave(), delay_on() and
delay_ns(), with OBS_OUTPUT_VIDEO taken from video_checks and
AUDIO_OUTPUT_FRAMES.

tests/output/raw_audio.rs ports test_output_raw_audio_steps 1:1: its
19 cases under the same names (steps_*), in the same order, with the
same values and expectations, the characterized-not-endorsed cases
included, the stand-in output written in Rust over the core, with
video_checks::first_mixer() for the first mixer.

Edge cases (edge_*) check the core against models of the original C:
every pair (and for the drop every triple) of 30 special timestamps
around the integer and 48 kHz packet edges; the sizes over edge
usize values and frame counts; every low 16-bit flag word under four
high words; every mix index of every low 16-bit mask under three high
words, and indices past the width; the delay over a stride through
all u32; a proptest of every decision over full-range values (4,096
cases); and a proptest of the stand-in over packet sequences against
the origin/master code with its expressions inline.

soldr cargo test -p obs-data --test obs-tests-core -- output::raw_audio
passes 1 of 24 (the constants) and fails 23 with "not yet
implemented".

Refs obs-rust#2449
Ports libobs/obs-output-raw-audio.c.h, the raw output audio admission
and the capture hookup of obs-output.c, to the raw_audio module of
rust/obs-output. obs-output.c.h stays C around it: data_active(), every
read of the output, the pause mutex and its reads, audio_pause_check(),
the deques and each plane's pointer advance, the raw_audio and
raw_audio2 callbacks, the mixer connections, the encoder starts, the
delay's fields and log, and every conversion that divides by the
sample rate. The hybrid libobs drops the C file and links the Rust
shims in its place.

Safe core (src/raw_audio.rs):
- passthrough(): no OBS_OUTPUT_VIDEO flag; video_unset() and
  start_unset(): a timestamp of 0;
- before_video(), can_pop(): the C's < and >; ends_before(): the
  wrapping sum at or before the video start;
- cut_ns(), cut_ts(), block_ts(), paused_ts(): wrapping differences
  and sums; next_frames(): a wrapping usize sum;
- cut_bytes(), cut_frames(): the low 32 bits of the cut, as the C's
  (uint32_t) cast, times audio_size (wrapping usize) or from the frames
  (wrapping u32); block_bytes(), push_bytes(): wrapping usize products;
- mix_on(): bit idx of the mask; interleave(): video and audio;
  delay_on(): not 0; delay_ns(): a u64 product, which cannot wrap.
The module denies clippy's arithmetic, as, indexing, unwrap, expect,
panic, todo, unimplemented and unreachable lints, keeps no state, takes
no lock and does not divide.

Shims (src/ffi/output_raw_audio.rs): the nineteen functions keep the C
signatures. No pointer crosses and no struct is mirrored.

Intentional difference: mix_on() with an index at or past the width of
size_t, where the C's shift is undefined, says not set. The C asks only
0 to 5.

C side: the file leaves libobs.core-output for its own group,
libobs.ported-output-raw-audio (LIBOBS_PORTED_SOURCES), whose PCH is
only obs-output-raw-audio.h; libobs.pch.h keeps the header for
obs-output.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_output_raw_audio_steps still compiles the C file into itself,
unchanged. It has no _rust variant, as for test_output_stop_stats_steps:
the shims' archive member also holds the rest of obs-output, which
needs libobs's hidden seams and obs-util, so it does not link on its
own. Its tests.d file says so.

soldr cargo test -p obs-data --test obs-tests-core -- output::raw_audio
passes 24 of 24.

Refs obs-rust#2449
Tier 3 for the raw_audio port. The oracle
(rust/obs-c-oracle/oracle/output_raw_audio.c) compiles the unchanged
libobs/obs-output-raw-audio.c.h with its nineteen functions renamed to
oracle_*, plus its two constants, bound in src/output_raw_audio.rs.
Nothing in it divides.

tests/output/raw_audio_parity.rs compares the oracle, the shims and the
core exactly, all three sides:
- the two constants;
- every two-value decision over every pair of 30 special u64 values
  (around 0, 2^32, 2^63, u64::MAX, a video start, one 48 kHz packet and
  one sample), and the drop over every triple (27,000 calls);
- the sizes over every pair of 13 special usize values, 12 special
  frame counts and the 30 special cut lengths;
- the passthrough over every low 20-bit flag word and a stride through
  all u32; the mix rule over every low 16-bit mask under four high
  words at every index below the width of usize; the delay over 0 to
  100,000 and a stride through all u32; the interleave rule;
- the callers (prepare_audio(), the block loop, start_raw_audio() and
  hook_data_capture(), as the C test's stand-in output) on the oracle
  and on the shims: 186,624 two-packet sequences over flags, video
  starts, pause data, rates of 1 Hz to 384 kHz, sizes 1 to 8 and 1, 2
  and 8 planes around the video start, comparing every admission, cut,
  push, block and timestamp; every 12-bit mixer mask with and without
  raw_audio2; every 6-bit flag word with five delays;
- proptests (20,000 cases each) of every decision over full-range
  values and of the callers over packet sequences from any state.

The stand-in's conversions are the file's own copy of util_mul_div64()'s
portable formula, shared by both sides, with a rate of at least 1; on
MSVC x64 the oracle side asserts the rate before it divides
(cfg!(all(target_env = "msvc", target_arch = "x86_64"))). The oracle is
called for mix_on() only below the width of usize, where the C's shift
is defined; that excludes exactly the intentional difference. Otherwise
no input is excluded.

Mutation check (once, not committed): 27 mutants, 21 in the core and 6
in the shims.

  mutant                                  Tier 1  Tier 3
  passthrough: flag test inverted              9       4
  video_unset: <= 1                            2       1
  start_unset: inverted                        8       4
  before_video: <=                             2       2
  ends_before: <                               3       2
  ends_before: saturating sum                  3       2
  cut_ns: reversed                             7       4
  cut_ts: saturating                           3       2
  cut_bytes: no u32 truncation                 3       2
  cut_frames: saturating                       3       2
  the u32 truncation at 16 bits                3       2
  block_bytes: 1023 frames                     5       4
  push_bytes: saturating                       2       2
  can_pop: >=                                  4       3
  block_ts: saturating                         4       3
  paused_ts: offset dropped                    5       4
  next_frames: saturating                      2       1
  mix_on: next bit                             4       3
  interleave: ||                               4       3
  delay_on: inverted                           4       3
  delay_ns: u32 product                        4       3
  shim passthrough inverted                    0       4
  shim ends_before: timestamp and duration     0       0
  shim cut_ns: arguments swapped               0       4
  shim mix_on: arguments swapped               0       3
  shim push_bytes: block size                  0       4
  shim delay_ns: one second short              0       3

(failing tests per tier.) Tier 1 kills all 21 core mutants, Tier 3 26
of 27. The survivor is equivalent: the shim's ends_before() with the
timestamp and the duration swapped adds them the same way.

soldr cargo test -p obs-data --test obs-tests-core -- output::raw_audio
passes 31 of 31 (24 Tier 1, 7 Tier 3).

Refs obs-rust#2449
rust/README.md gets the row for libobs/obs-output-raw-audio.c.h
(obs-output::raw_audio): what moved, what stays C and why, the
characterized-not-endorsed behaviours (the held-back last block among
them), the one intentional difference and the tests that cover it; the
obs-output crate row, its Cargo description and lib.rs name the new
module. docs/rust-port/naming.md already maps the file to
rust/obs-output (the move commit).

rust/obs-c-oracle/benches/port_comparison/output_raw_audio.rs, in the
sorted module list, runs 1024 packets around a video start through
every decision prepare_audio() and default_raw_audio_callback() ask, on
the shims and on the oracle, and checks both checksums match. Release,
x86_64 Linux, GCC, a loaded host, median: Rust 12.57 us, C 12.54 us
(1.00x).

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

Fixes obs-rust#2449
@rdoupe
rdoupe requested a review from zackees as a code owner October 26, 2026 07:33
@zackees

zackees commented Oct 26, 2026

Copy link
Copy Markdown
Member

Coordinator review: same extraction pattern. A new raw-audio admission unit with a C reference, a bench and the export maps. No existing C test assertion changes; only test-graph.json gains an entry. Queuing; it merges when CI is green.

@zackees
zackees enabled auto-merge October 26, 2026 07:42
@zackees
zackees added this pull request to the merge queue Oct 26, 2026
Merged via the queue into obs-rust:master with commit 206eefc Oct 26, 2026
36 checks passed
@rdoupe rdoupe mentioned this pull request Oct 26, 2026
6 of 7 tasks
zackees pushed a commit to rdoupe/obs-studio that referenced this pull request Oct 26, 2026
* libobs: Move the output start decisions

Behaviour-neutral extraction before the Rust port. The decisions of
obs_output_start(), obs_output_actual_start(),
obs_output_initialize_encoders() and
obs_output_begin_data_capture_internal() move to
libobs/obs-output-start.c.h, as six functions on plain values declared
in the new libobs/obs-output-start.h without EXPORT (hidden, as
-fvisibility=hidden keeps them):

- obs_output_start() and obs_output_begin_data_capture_internal():
  _service() (OBS_OUTPUT_SERVICE: the service gate before the start,
  the activation after the hookup);
- obs_output_actual_start(): _drop_restart_ref() (a delayed restart's
  reference is dropped when delay_restart_refs is not 0);
- obs_output_initialize_encoders(): _init_video() and _init_audio();
- obs_output_begin_data_capture_internal(): _reset_raw() (a raw output
  resets its audio and timestamps) and _pair() (video and audio both:
  the encoders are paired).

Two rules were already ported, so their callers ask them:
obs_output_start()'s delayed start is obs_output_raw_audio_delay_on()
(delay_sec is not 0), the test hook_data_capture() asks (obs-rust#2457), and
reset_raw_output()'s conversion fill (a rate that is not 0, a format
and speakers that are not unknown replace the mix's) is
obs_encoder_size_audio_defaults(), get_audio_info()'s fill. The two
headers note the new callers.

One function per decision, asked where the C made it, so every read
stays where it was. The plan's routes (start_route over starting and
delay_active, actual_steps over success and the restart refs,
init_route over active and delay_active, begin_route and begin_signal
over delay_active, active and reconnecting) would load an atomic where
the C's && and early returns do not, or load one once for a whole
function that another thread writes between the tests, so the
single-field tests stay C in their order: context.data, starting and
delay_active (the "already starting" refusal), success, active and
delay_active, delay_capturing, audio, audio_conversion_set,
reconnecting. Each atomic is loaded where it always was. Nothing is
left to decide in begin_delayed_capture() (two single-field tests) or
obs_output_begin_data_capture() (it always clears starting after
active is set), so they are unchanged.

C keeps the stopping event wait, every atomic load and store,
info.start, obs_video_stats_frame_counts(), the caption track reset
under its mutex, obs_service_can_try_to_connect() and
obs_service_initialize() in their && order, obs_service_activate(),
obs_output_delay_start(), the encoder initialization with the last-error
copy, can_begin_data_capture(), pair_encoders() (its locks and weak
references), hook_data_capture(), calculate_batch_size(),
clear_raw_audio_buffers(), audio_output_get_info(), get_audio_planes(),
get_audio_size(), pause_reset(), every signal and every log.

One read changes: obs_output_begin_data_capture_internal()'s pair test
reads info.flags once where flag_video() && flag_audio() read it twice.
info.flags is set when the output is created and never written again.

Checked in a scratch harness (not committed). It compiles
origin/master's seven functions (obs_output_start(), _actual_start(),
_initialize_encoders(), begin_delayed_capture(), reset_raw_output(),
obs_output_begin_data_capture_internal() and
obs_output_begin_data_capture()) and their flag and atomic helpers
verbatim, and this branch's with the moved file,
obs-output-raw-audio.c.h and obs-encoder-size.c.h, with every read and
write of an output field rewritten the same way into a logged access
(with the value), over a stand-in output. It logs every atomic load,
store and decrement (with the field and value), the stopping event
wait, bfree(), the frame counts, every lock and unlock, the caption
deque calls, obs_output_valid(), each service call, the delayed start,
info.start, the encoder initialization, can_begin_data_capture(),
pair_encoders(), hook_data_capture(), calculate_batch_size(), the raw
audio calls (audio_output_get_info(), get_audio_planes() and
get_audio_size() with their arguments, the buffer clear and the pause
reset), every signal and every log, in order. Another thread flips one
of starting, active, reconnecting, delay_active, delay_capturing,
data_active and delay_restart_refs at any of those calls. A repeated
info.flags read with nothing between is logged once (the read above).
- Inputs: every low flag word with and without high bits, with and
  without context.data, a service and an audio, each atomic set and
  clear, restart refs of 0, 1, 2, -1, LONG_MIN and LONG_MAX, delays of
  0, 1, 30 and UINT32_MAX, every result of the valid check, the
  service, info.start, the encoder initialization, the capture check
  and the delayed start, conversions with each field set, 0 or unknown
  (set or not), edge mix rates, formats and speakers, 0 to 10 caption
  tracks; one to six calls in a row.
- 2,900,000 runs (GCC and Clang -O2, 1,000,000 each; GCC -O0, 500,000;
  ASan with UBSan under GCC -O0 and Clang -O2, 200,000 each) give
  equal events, equal returns and an equal end state (every output
  field and the caption tracks): 169,887,172 events.
- Every branch of origin/master's functions that these callers can
  reach is taken both ways (gcov, 92 of 98; the other six are
  log_flag_encoded()'s inverse_log side, which they never ask, and the
  harness's dispatch).
- 25 deliberately broken moves were planted and all 25 fail it: the
  restart refs loaded before info.start, delay_active loaded before
  starting or hoisted out of the &&, the service initialized before
  can_try, the delayed start on the wrong field, the conversion fill
  without its set test, with its arguments swapped or dropping the
  rate, active loaded before delay_active in the begin, the pair after
  data_active, the raw reset after the capture check, the activation
  after the signal, the begin signal tests swapped, audio encoders
  before video, delay_active loaded with active, the decrement
  unconditional, the wrong flag rule at the activation, and nine
  changed decisions (the service test inverted, the restart ref test
  > 0, the video and audio flags swapped in either init, the raw
  reset inverted, || for && and video only in the pair, the delay
  always on).

git blame on the moved lines shows upstream commits only (ceb675f,
645e31f, 6ec0b2d, d314d47, 09e10a4, 8830c41).

The four flags are copied into the header, so it needs no core header;
obs-output.c.h checks them with _Static_assert. The new file joins
libobs.core-output, just before obs-output.c.h, with libobs.pch.h,
which includes the new header; source-sets.json lists it.
docs/rust-port/naming.md maps the file to rust/obs-output. The exported
symbol sets are unchanged (1766) on the C, hybrid and C reference
libobs; the six functions are local.

Refs obs-rust#2522

* test: Characterize the output start decisions

test_output_start_steps compiles libobs/obs-output-start.c.h,
libobs/obs-output-raw-audio.c.h (whose delay test obs_output_start()
asks) and libobs/obs-encoder-size.c.h (whose audio fill
reset_raw_output() asks) with ASan and UBSan, and calls only their
functions through their headers. Five cases on the functions:

- the copied flags (OBS_OUTPUT_VIDEO, _AUDIO, _ENCODED, _SERVICE);
- the service, init, raw reset and pair rules over every low 16-bit
  flag word with four high words (each looks at its own bits only);
- the restart reference: dropped for any count that is not 0 (a
  negative count too: characterized, not endorsed, never reached);
- the delayed start, for any delay that is not 0;
- the conversion fill: each field set alone replaces only the mix's,
  0 and unknown keep the mix's, any other format or speakers value is
  taken as it is.

The bodies of obs_output_start(), obs_output_actual_start(),
obs_output_initialize_encoders(), begin_delayed_capture(),
reset_raw_output(), obs_output_begin_data_capture_internal() and
obs_output_begin_data_capture() are also copied onto a stand-in output
(no thread, lock, service or encoder; their results are given, and
every call, store, signal and warning is recorded), to pin end to end
in 14 cases:

- the start of a stream, a recording and a raw output; invalid and no
  data; already starting (refused with the warning) and starting with
  a delay active (goes on); active, reconnecting and delay_capturing,
  which do not refuse it;
- the service gate when it cannot try (initialize not called), when
  initialize fails and without the service flag;
- the delayed start (its result, no "starting"; the gate first; a raw
  output with a delay is delayed too: characterized, not endorsed);
- the actual start on success and failure, with and without data,
  with 0, 1, 2, 3 and -1 restart refs (one dropped per start, on
  success and failure), the last error freed and the caption tracks
  reset whatever the result;
- the encoder initialization of raw, video, audio, AV and flagless
  encoded outputs, a video failure stopping before the audio, active
  (true only with a delay active), delay_active alone, and the raw
  refusal before the active test;
- the raw reset with no conversion, an unset one, each field set
  alone, 0 and unknown, and no audio;
- the begin of a stream, a recording, raw video, raw AV (paired too:
  characterized, not endorsed) and encoded audio-only outputs; active,
  a failed capture check (total_frames already reset, no data_active)
  and invalid; each end signal (reconnect_success clearing the flag,
  "starting" for a delay the hookup turned on, reconnecting over the
  delay, "start"); the delayed capture (start, reconnect_success,
  already capturing, before active and the capture check); starting
  cleared after every begin;
- a start then a begin, a second start while starting, and a start
  after a failed one.

It is in the native test graph, in name order, with the three headers
as watch inputs, and links libm off MSVC. No assert_in_range or
fail_msg, so it builds with cmocka 1.x and 2.x, and no comparison
between two enum types (MSVC C5287). The real-libobs tests
test_output_start_twice, test_output_failed_start_encoders,
test_output_delay, test_output_delay_restart, test_output_before_video,
test_raw_output_video_reset, test_output_interleave_restart and
test_rtmp_send_thread_leak cover the callers.

Refs obs-rust#2522

* obs-output: Add Tier 1 tests for output start

RED for the port of libobs/obs-output-start.c.h to a new output_start
module of rust/obs-output, next to output_slots and raw_audio. The
safe core is a stub (todo!()): service(), drop_restart_ref(),
init_video(), init_audio(), reset_raw() and pair(), with the four flags
(video_checks'). It re-exports raw_audio's delay_on() and
encoder_size's audio_defaults() with AudioFill, the delayed start and
the conversion fill the callers share, already ported.

tests/output/output_start.rs ports test_output_start_steps 1:1: its 19
cases under the same names (steps_*), in the same order, with the same
values and expectations, the characterized-not-endorsed cases
included, the stand-in output and its copies of obs_output_start(),
obs_output_actual_start(), obs_output_initialize_encoders(),
begin_delayed_capture(), reset_raw_output(),
obs_output_begin_data_capture_internal() and
obs_output_begin_data_capture() written in Rust over the core.

Edge cases (edge_*) check the core against the origin/master
expressions inline: every low 16-bit flag word under 16 high words;
every restart count from -1,000 to 1,000 and the extremes; every delay
to 100,000 and the top 1,000; the conversion fill over every
combination of edge formats, rates and speakers for the conversion and
the mix (86,016); the stand-in through every caller for every low flag
word, each of six atomics set and clear, three restart counts, a delay
or none and each of eleven call results failing alone (73,728
outputs); and proptests (4,096 cases each) of every decision over
full-range values and of the stand-in over sequences of up to eleven
calls, with another thread flipping the atomics, the restart refs, the
delay and the call results between them.

soldr cargo test -p obs-data --test obs-tests-core --
output::output_start passes 6 of 25 (the constants and the cases that
ask only the already-ported delay test and conversion fill) and fails
19 with "not yet implemented".

Refs obs-rust#2522

* obs-output: Port the output start decisions

Ports libobs/obs-output-start.c.h, the output start and begin-capture
decisions, to the output_start module of rust/obs-output.
obs-output.c.h stays C around it: obs_output_valid(),
log_flag_encoded(), every warning, every atomic load and store
(starting, delay_active, active, reconnecting, data_active,
delay_capturing and delay_restart_refs) where it always was, the
context.data, success, audio and audio_conversion_set tests and the
single-field tests in their && order, the stopping event wait,
info.start, the frame counts, the caption track reset under its mutex,
the service calls in their order, obs_output_delay_start(), the encoder
initialization, can_begin_data_capture(), pair_encoders() with its
locks and weak references, hook_data_capture(), calculate_batch_size(),
the raw audio calls, every signal and every log. The hybrid libobs
drops the C file and links the Rust shims in its place.

Safe core (src/output_start.rs):
- service(): OBS_OUTPUT_SERVICE is in the flags (the gate before the
  start, the activation after the hookup);
- drop_restart_ref(): the loaded restart count is not 0;
- init_video() and init_audio(): OBS_OUTPUT_VIDEO, OBS_OUTPUT_AUDIO;
- reset_raw(): OBS_OUTPUT_ENCODED is not in the flags;
- pair(): both OBS_OUTPUT_VIDEO and OBS_OUTPUT_AUDIO;
- delay_on() re-exported from raw_audio and audio_defaults() (with
  AudioFill) from encoder_size: obs_output_start() and
  reset_raw_output() call those shims, so they share one
  implementation.
The flags are video_checks'. The module denies clippy's arithmetic,
as, indexing, unwrap, expect, panic, todo, unimplemented and
unreachable lints, keeps no state, takes no lock and does not divide.

Shims (src/ffi/output_start.rs): the six functions keep the C
signatures; the restart count comes in as c_long (32 bits on Windows)
and is widened to i64. No pointer crosses.

No intentional differences.

C side: the file leaves libobs.core-output for its own group,
libobs.ported-output-start (LIBOBS_PORTED_SOURCES), whose PCH is only
obs-output-start.h; libobs.pch.h keeps the header for obs-output.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. The exported symbol sets are unchanged
(1766) on the C, hybrid and C reference libobs, and the six functions
are local in each; the hybrid libobs has no C object for the group.

test_output_start_steps still compiles the C file into itself,
unchanged. It has no _rust variant, as for test_output_slots_steps:
the shims' archive member also holds the rest of obs-output, which
needs libobs's hidden seams and obs-util, so it does not link on its
own. Its tests.d file says so.

soldr cargo test -p obs-data --test obs-tests-core --
output::output_start passes 25 of 25. Through ctest (private Xvfb and
D-Bus, own HOME and runtime directory, no sound), the full suite passes
against the C libobs (538 of 538) and the hybrid libobs (570 of 570),
the same 3 skipped on each (a PulseAudio default sink and the v4l2 vivid
module, absent here). Against the C reference libobs 569 of 570 passed
in that run: test_encoder_error_stop's raw replay buffer case saw no
packets before its injected failure at a load average of about 20, and
passed in each of three runs on its own (the C reference runs the same C
as the C libobs, where it passed). Among them test_output_start_steps,
test_output_start_twice, test_output_failed_start_encoders,
test_ffmpeg_output_connecting, test_output_start_log, test_output_delay,
test_output_delay_e2e, test_output_delay_restart,
test_output_before_video, test_raw_output_video_reset,
test_output_interleave_restart, test_rtmp_send_thread_leak,
test_output_raw_audio_steps and test_encoder_size_steps.

Refs obs-rust#2522

* obs-output: Check the output start against C

Tier 3 for the output_start port. The oracle
(rust/obs-c-oracle/oracle/output_start.c) compiles the unchanged
libobs/obs-output-start.c.h with its six functions renamed to
oracle_*, plus its four flags and the width of long, bound in
src/output_start.rs. Nothing in it divides. The delayed start's oracle
is output_raw_audio's and the conversion fill's encoder_size's.

tests/output/output_start_parity.rs compares the oracle, the shims and
the core exactly, all three sides:
- the four flags and sizeof(long) (32 bits on Windows: the shim takes
  c_long and widens it);
- the five flag rules over every low 16-bit flag word under 16 high
  words and a stride through all of u32;
- the restart count over -100,000 to 100,000, the 100,000 values at
  each extreme of long and a stride through all of it;
- the delayed start over 0 to 1,000,000, the top 100,000 and a stride
  through all of u32;
- the conversion fill over every combination of 12 formats, 12 rates
  and 12 speakers against four mixes (6,912);
- the callers on test_output_start_steps' stand-in output (shared with
  Tier 1), on the oracle's gates and on the shims: every caller for
  every low flag word under two high words, each of six atomics set
  and clear, three restart counts, two delays and each of twelve call
  results failing alone (147,456 outputs), comparing every return, the
  record and the end state;
- proptests (20,000 cases each) of every decision over full-range
  values and of the stand-in over sequences of up to fifteen calls,
  with another thread flipping the atomics, the restart refs, the delay
  and the call results between them.

No input is excluded: nothing in the C divides or overflows. A restart
count past a 32-bit long is passed to the C and the shim at the
nearest end, which keeps "not 0". The proptests keep no regression
files (failure_persistence None), as the delay and interleave parity
runners do.

Mutation check (once, not committed): 20 mutants, 13 in the core and
7 in the shims.

  mutant                                  Tier 1  Tier 3
  service: ==                                  12       4
  service: the video flag                      11       4
  OBS_OUTPUT_SERVICE = 1 << 4                   9       5
  drop_restart_ref: > 0                         6       3
  drop_restart_ref: never                       6       4
  init_video: the audio flag                    6       4
  init_video: always                            6       4
  init_audio: the video flag                    6       4
  reset_raw: encoded                            9       4
  reset_raw: the video flag                     8       4
  OBS_OUTPUT_ENCODED = 1 << 3                   3       5
  pair: ||                                      7       4
  pair: video only                              7       4
  shim service inverted                         0       4
  shim drop_restart_ref: positive only          0       3
  shim init_video asks init_audio               0       4
  shim init_audio asks init_video               0       4
  shim reset_raw inverted                       0       4
  shim pair asks service                        0       4
  shim service: flags >> 1                      0       4

(failing tests per tier.) Tier 1 kills all 13 core mutants and Tier 3
all 20.

soldr cargo test -p obs-data --test obs-tests-core --
output::output_start passes 33 of 33 (25 Tier 1, 8 Tier 3).

Refs obs-rust#2522

* docs: Record the output start port

rust/README.md gets the row for libobs/obs-output-start.c.h
(obs-output::output_start), after encoder_lifecycle's: what moved, the
delayed start and the conversion fill shared with raw_audio and
encoder_size, what stays C and why (every atomic loaded where it
always was, the single-field tests in their && order, the order of the
stores), the one read that changed (info.flags once in the pair test),
the characterized-not-endorsed behaviours (a negative restart count
dropped, a raw output delayed or paired, a flagless encoded output
initializing nothing, only starting refusing a start) and the tests
that cover it; the obs-output crate row names the file. The crate's
Cargo description and lib.rs named the module in the port commit, and
docs/rust-port/naming.md maps the file (the move commit).

rust/obs-c-oracle/benches/port_comparison/output_start.rs, in the
sorted module list, runs 1024 rounds over the flag words of a stream,
a recording, a raw video and a raw AV output with restart counts,
delays and four conversions, asking every decision obs_output_start(),
obs_output_actual_start(), obs_output_initialize_encoders(),
reset_raw_output() and obs_output_begin_data_capture_internal() ask,
in their order, on the shims and on the oracle, and checks both
checksums match. Release, x86_64 Linux, GCC, median (load average 9
to 26): Rust 19.06 us, C 19.94 us (0.96x), about 19 ns a round, next
to the service calls, the encoder initialization or a single signal.

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

Fixes obs-rust#2522
@rdoupe rdoupe mentioned this pull request Oct 26, 2026
6 of 7 tasks
rdoupe added a commit that referenced this pull request Oct 27, 2026
Behaviour-neutral extraction before the Rust port. The decisions of
obs_output_stop(), end_data_capture_thread() and
obs_output_end_data_capture_internal() move to
libobs/obs-output-stop.c.h, as seven functions on plain values declared
in the new libobs/obs-output-stop.h without EXPORT (hidden, as
-fvisibility=hidden keeps them):

- _encoded() (OBS_OUTPUT_ENCODED: obs_output_stop()'s delayed stop,
  the encoders or the raw video and audio in the end-capture thread,
  the unstarted encoders' shutdown);
- _delay_on() (active_delay_ns is not 0: the delayed stop, the
  process_delay() callback and the delay cleanup);
- _has_video() and _has_audio() (which encoders or raw connections
  stop; the frame log);
- _service() (the service is deactivated);
- _end_delay() (delay_restart_refs is 0: the delay ends; otherwise a
  restart keeps it);
- _thread_failed() (pthread_create() did not return 0: the unstarted
  shutdown is dropped, or the end-capture thread runs inline).

Two rules were already ported, so their callers ask them:
end_data_capture_thread()'s interleave test is
obs_output_raw_audio_interleave(), the test hook_data_capture() asks
for the same callback, and stop_raw_audio()'s mix test is
obs_output_raw_audio_mix_on(), start_raw_audio()'s (#2457). The first
mixer was already obs_output_first_mixer(). obs-output-raw-audio.h
notes the new callers.

One function per decision, asked where the C made it, so every read
stays where it was. The plan's routes (stop_route, actual_stop,
end_route and signal_stop_clears over the atomics, thread_stops over
the flags and active_delay_ns) would load an atomic where the C's &&
and early returns do not, or load one once for a whole function that
another thread writes between the tests: reconnecting is loaded twice
in obs_output_actual_stop() and obs_output_stop(), and active_delay_ns
twice in end_data_capture_thread() while the encoders' callbacks still
write it. So the single-field tests stay C in their order:
context.data, active, reconnecting, the stopping event, force,
delay_active, delay_capturing, data_active, the end-capture thread's
flag, raw_audio2 and signal. Nothing is left to decide in
obs_output_force_stop(), obs_output_actual_stop() or
obs_output_signal_stop()'s stop branch (single-field tests only), so
they are unchanged.

C keeps every atomic load and store, the stopping event, the unpause,
the reconnect thread's join, info.stop, obs_output_end_data_capture(),
obs_output_delay_stop(), obs_encoder_stop(),
obs_encoder_shutdown_unstarted(), stop_raw_video(),
audio_output_disconnect(), obs_service_deactivate(),
obs_output_cleanup_delay(), log_frame_info(), the caption frees under
their mutex, the keyframe tracking clear, the joins, pthread_create(),
the stop parameters copied before a thread starts (#2086, #2098), the
reconnect policy, every signal and every log.

No read changes: each new call reads the field the old test read, in
the same place and order.

Checked in a scratch harness (not committed). It compiles
origin/master's obs_output_actual_stop(), obs_output_stop(),
obs_output_force_stop(), stop_audio_encoders(), stop_video_encoders(),
stop_raw_audio(), end_data_capture_thread(),
shutdown_unstarted_encoders() and its thread,
obs_output_end_data_capture_internal(), obs_output_end_data_capture()
and obs_output_signal_stop(), with their flag, atomic and join helpers
and get_first_mixer(), verbatim, and this branch's with the moved file,
obs-output-raw-audio.c.h and obs-output-video-checks.c.h, with every
read of info.flags, active_delay_ns, mixer_mask, context.data,
raw_audio2 and reconnect_thread_active and every write of stop_code
rewritten the same way into a logged access, over a stand-in output.
It logs every atomic load, store, exchange, increment and decrement
(with the field and value), every stopping and reconnect event test,
reset and signal, the unpause, every join and pthread_create() (with
its result), info.stop, every lock and unlock, bfree(), the keyframe
clear, obs_output_valid(), the delayed stop, each encoder stop (with
its callback), each unstarted shutdown, the raw video stop, each
audio disconnect (with its mix), the deactivation, the delay cleanup,
the frame log, the stop parameters, every signal and every log, in
order. Another thread flips one of the atomics, the stopping event,
active_delay_ns, the restart refs or reconnect_thread_active, or runs a
created thread, at random between events.

- Inputs: all 16 combinations of the four flags, with and without
  high bits, context.data and raw_audio2, each atomic set and clear,
  restart refs of 0, 1, 2, -1, LONG_MIN and LONG_MAX, delays of 0, 1,
  10^9 and UINT64_MAX, mixer masks with and without high bits,
  encoders and caption tracks present or not, every result of the
  valid check, can_reconnect() and pthread_create(), forced or not,
  signalled or not, six stop codes; one to six calls in a row, the
  created threads run at the end of a call or in the middle of the
  next.
- 2,900,000 runs (GCC and Clang -O2, 1,000,000 each; GCC -O0, 500,000;
  ASan with UBSan under GCC -O0 and Clang -O2, 200,000 each) give
  equal events and an equal end state (every atomic, both events, the
  stop code, the thread, the keyframe tracking and the caption tracks):
  204,669,941 events.
- Every branch of origin/master's functions is taken both ways (gcov,
  130 of 130).
- 21 deliberately broken moves were planted and 20 fail it: the
  encoded, video, audio and service rules on the wrong flag or
  inverted, the delay rule > 1, the end-delay rule inverted or for
  positive counts only, the thread rule for negative results only,
  OBS_OUTPUT_STOP_ENCODED on the wrong bit, active_delay_ns read
  before the flags in the delayed stop, the interleave asked with
  video twice, the callback ignoring the delay, the delay cleanup on
  the encoded flag, the next mix disconnected, the encoded flag read
  before active in the unstarted shutdown, the end delay inverted at
  its call, the frame log on the audio flag, the inline fallback
  inverted, the unstarted thread's result ignored, and the
  deactivation after the delay cleanup. The one that passes reads
  has_audio before has_video: two reads of info.flags, which is set
  when the output is created and never written again, so it is
  equivalent.

git blame on the moved lines shows upstream commits (0538865,
29e849e, 3869cb8, 645e31f, a1fbf10, b8a3ae1, d314d47,
d7db0b8) and this fork's unstarted encoder shutdown (7041590).

The four flags are copied into the header, so it needs no core header;
obs-output.c.h checks them with _Static_assert. The new file joins
libobs.core-output, just before obs-output.c.h, with libobs.pch.h,
which includes the new header; source-sets.json lists it.
docs/rust-port/naming.md maps the file to rust/obs-output. The exported
symbol sets are unchanged (1766) on the hybrid and C reference libobs,
and identical; the seven functions are local.

Refs #2535.
MCPVOT pushed a commit to MCPVOT/obs-studio that referenced this pull request Oct 30, 2026
* libobs: Move the output stop decisions

Behaviour-neutral extraction before the Rust port. The decisions of
obs_output_stop(), end_data_capture_thread() and
obs_output_end_data_capture_internal() move to
libobs/obs-output-stop.c.h, as seven functions on plain values declared
in the new libobs/obs-output-stop.h without EXPORT (hidden, as
-fvisibility=hidden keeps them):

- _encoded() (OBS_OUTPUT_ENCODED: obs_output_stop()'s delayed stop,
  the encoders or the raw video and audio in the end-capture thread,
  the unstarted encoders' shutdown);
- _delay_on() (active_delay_ns is not 0: the delayed stop, the
  process_delay() callback and the delay cleanup);
- _has_video() and _has_audio() (which encoders or raw connections
  stop; the frame log);
- _service() (the service is deactivated);
- _end_delay() (delay_restart_refs is 0: the delay ends; otherwise a
  restart keeps it);
- _thread_failed() (pthread_create() did not return 0: the unstarted
  shutdown is dropped, or the end-capture thread runs inline).

Two rules were already ported, so their callers ask them:
end_data_capture_thread()'s interleave test is
obs_output_raw_audio_interleave(), the test hook_data_capture() asks
for the same callback, and stop_raw_audio()'s mix test is
obs_output_raw_audio_mix_on(), start_raw_audio()'s (obs-rust#2457). The first
mixer was already obs_output_first_mixer(). obs-output-raw-audio.h
notes the new callers.

One function per decision, asked where the C made it, so every read
stays where it was. The plan's routes (stop_route, actual_stop,
end_route and signal_stop_clears over the atomics, thread_stops over
the flags and active_delay_ns) would load an atomic where the C's &&
and early returns do not, or load one once for a whole function that
another thread writes between the tests: reconnecting is loaded twice
in obs_output_actual_stop() and obs_output_stop(), and active_delay_ns
twice in end_data_capture_thread() while the encoders' callbacks still
write it. So the single-field tests stay C in their order:
context.data, active, reconnecting, the stopping event, force,
delay_active, delay_capturing, data_active, the end-capture thread's
flag, raw_audio2 and signal. Nothing is left to decide in
obs_output_force_stop(), obs_output_actual_stop() or
obs_output_signal_stop()'s stop branch (single-field tests only), so
they are unchanged.

C keeps every atomic load and store, the stopping event, the unpause,
the reconnect thread's join, info.stop, obs_output_end_data_capture(),
obs_output_delay_stop(), obs_encoder_stop(),
obs_encoder_shutdown_unstarted(), stop_raw_video(),
audio_output_disconnect(), obs_service_deactivate(),
obs_output_cleanup_delay(), log_frame_info(), the caption frees under
their mutex, the keyframe tracking clear, the joins, pthread_create(),
the stop parameters copied before a thread starts (obs-rust#2086, obs-rust#2098), the
reconnect policy, every signal and every log.

No read changes: each new call reads the field the old test read, in
the same place and order.

Checked in a scratch harness (not committed). It compiles
origin/master's obs_output_actual_stop(), obs_output_stop(),
obs_output_force_stop(), stop_audio_encoders(), stop_video_encoders(),
stop_raw_audio(), end_data_capture_thread(),
shutdown_unstarted_encoders() and its thread,
obs_output_end_data_capture_internal(), obs_output_end_data_capture()
and obs_output_signal_stop(), with their flag, atomic and join helpers
and get_first_mixer(), verbatim, and this branch's with the moved file,
obs-output-raw-audio.c.h and obs-output-video-checks.c.h, with every
read of info.flags, active_delay_ns, mixer_mask, context.data,
raw_audio2 and reconnect_thread_active and every write of stop_code
rewritten the same way into a logged access, over a stand-in output.
It logs every atomic load, store, exchange, increment and decrement
(with the field and value), every stopping and reconnect event test,
reset and signal, the unpause, every join and pthread_create() (with
its result), info.stop, every lock and unlock, bfree(), the keyframe
clear, obs_output_valid(), the delayed stop, each encoder stop (with
its callback), each unstarted shutdown, the raw video stop, each
audio disconnect (with its mix), the deactivation, the delay cleanup,
the frame log, the stop parameters, every signal and every log, in
order. Another thread flips one of the atomics, the stopping event,
active_delay_ns, the restart refs or reconnect_thread_active, or runs a
created thread, at random between events.

- Inputs: all 16 combinations of the four flags, with and without
  high bits, context.data and raw_audio2, each atomic set and clear,
  restart refs of 0, 1, 2, -1, LONG_MIN and LONG_MAX, delays of 0, 1,
  10^9 and UINT64_MAX, mixer masks with and without high bits,
  encoders and caption tracks present or not, every result of the
  valid check, can_reconnect() and pthread_create(), forced or not,
  signalled or not, six stop codes; one to six calls in a row, the
  created threads run at the end of a call or in the middle of the
  next.
- 2,900,000 runs (GCC and Clang -O2, 1,000,000 each; GCC -O0, 500,000;
  ASan with UBSan under GCC -O0 and Clang -O2, 200,000 each) give
  equal events and an equal end state (every atomic, both events, the
  stop code, the thread, the keyframe tracking and the caption tracks):
  204,669,941 events.
- Every branch of origin/master's functions is taken both ways (gcov,
  130 of 130).
- 21 deliberately broken moves were planted and 20 fail it: the
  encoded, video, audio and service rules on the wrong flag or
  inverted, the delay rule > 1, the end-delay rule inverted or for
  positive counts only, the thread rule for negative results only,
  OBS_OUTPUT_STOP_ENCODED on the wrong bit, active_delay_ns read
  before the flags in the delayed stop, the interleave asked with
  video twice, the callback ignoring the delay, the delay cleanup on
  the encoded flag, the next mix disconnected, the encoded flag read
  before active in the unstarted shutdown, the end delay inverted at
  its call, the frame log on the audio flag, the inline fallback
  inverted, the unstarted thread's result ignored, and the
  deactivation after the delay cleanup. The one that passes reads
  has_audio before has_video: two reads of info.flags, which is set
  when the output is created and never written again, so it is
  equivalent.

git blame on the moved lines shows upstream commits (0538865,
29e849e, 3869cb8, 645e31f, a1fbf10, b8a3ae1, d314d47,
d7db0b8) and this fork's unstarted encoder shutdown (7041590).

The four flags are copied into the header, so it needs no core header;
obs-output.c.h checks them with _Static_assert. The new file joins
libobs.core-output, just before obs-output.c.h, with libobs.pch.h,
which includes the new header; source-sets.json lists it.
docs/rust-port/naming.md maps the file to rust/obs-output. The exported
symbol sets are unchanged (1766) on the hybrid and C reference libobs,
and identical; the seven functions are local.

Refs obs-rust#2535.

* test: Characterize the output stop decisions

test_output_stop_steps compiles libobs/obs-output-stop.c.h,
libobs/obs-output-raw-audio.c.h (whose interleave and mix tests the
end-capture thread and stop_raw_audio() ask) and
libobs/obs-output-video-checks.c.h (the first mixer) with ASan and
UBSan, and calls only their functions through their headers. Six cases
on the functions:

- the copied flags (OBS_OUTPUT_VIDEO, _AUDIO, _ENCODED, _SERVICE);
- the encoded, video, audio and service rules over every low 16-bit
  flag word with four high words (each looks at its own bit only);
- the running delay, for any active_delay_ns that is not 0;
- the end of the delay, only for no restart reference (a negative
  count keeps it too: characterized, not endorsed, never reached);
- the thread creation failure, for any result that is not 0;
- the shared rules at these callers' values: the interleave over both
  flags, each mix's bit below six mixes, the first mixer (0 for none).

The bodies of obs_output_stop(), obs_output_force_stop(),
obs_output_actual_stop(), stop_raw_audio(), end_data_capture_thread(),
shutdown_unstarted_encoders_thread(),
obs_output_end_data_capture_internal(), obs_output_end_data_capture()
and obs_output_signal_stop() are also copied onto a stand-in output (no
thread, lock, service or encoder; their results are given, a created
thread runs when the case says, and every call, event, signal and
warning is recorded), to pin end to end in 13 cases:

- the stop of a stream and a raw output (the stop code left for the
  plugin, still active); invalid, no data, neither active nor
  reconnecting, already stopping; data_active, delay_active and
  delay_capturing not changing the route;
- the delayed stop of an encoded output, even while stopping; a raw
  output with active_delay_ns stopping at once (characterized, not
  endorsed); reconnecting coming first;
- a reconnecting output stopped with data (with and without its
  thread to join), without data (refused, and forced: the stop
  signalled here), and with a delay active (not "was reconnecting":
  the forced stop clears the delay, then ends the capture);
- the forced stop when stopping and not, of an inactive output, and
  invalid;
- the not-forced refusal while stopping; the caption tracks freed;
- the forced stop of a delayed output that is capturing (the plugin's
  stop after the end) and is not, not forced, and with data not active;
- the end before the capture began: the code copied first, the last
  thread joined, the unstarted encoders shut down on a thread for an
  encoded output only, none while one is still ending or the output is
  active, the creation failing; without the end signal; invalid;
- the end of a delay with 0, 1 and -1 restart references;
- the full end of a stream (the frame log, the join, the code copied
  before the thread, the signal after; the thread's work), without the
  signal, of an audio-only output, and the inline fallback;
- each callback (delay, interleave, default), empty slots, an encoded
  output with neither flag (characterized, not endorsed); the raw video
  and audio, each mix with raw_audio2, the first mixer without it, and
  a raw output's service and delay cleanup (characterized, not
  endorsed);
- the stop signal without a reconnect (a delay, delay_capturing and
  reconnecting cleared first) and with one (a restart reference taken,
  no stop signal), a stream that never connected, invalid;
- a stop then the end and its thread, a second stop while stopping and
  a forced one after it, an end before the last thread ran, and a
  delayed stop then the delay's end.

It is in the native test graph, in name order, with the three headers
as watch inputs, and links libm off MSVC. No assert_in_range or
fail_msg, so it builds with cmocka 1.x and 2.x, and no comparison
between two enum types (MSVC C5287). The real-libobs tests
test_output_end_capture_thread_join, test_output_deactivate_state,
test_null_output_stop_thread, test_ffmpeg_output_stop,
test_ffmpeg_output_drain, test_encoder_error_stop,
test_replay_buffer_pause_stop, test_output_delay_e2e,
test_output_failed_start_encoders, test_recording_shutdown and
test_pthread_init_failures cover the callers.

Refs obs-rust#2535.

* obs-output: Add Tier 1 tests for output stop

RED for the port of libobs/obs-output-stop.c.h to a new output_stop
module of rust/obs-output, next to output_start and stop_stats. The
safe core is a stub (todo!()): encoded(), delay_on(), has_video(),
has_audio(), service(), end_delay() and thread_failed(), with the four
flags (video_checks'). It re-exports raw_audio's interleave() and
mix_on() and video_checks' first_mixer(), the callback, mix and first
mixer rules the callers share, already ported.

tests/output/output_stop.rs ports test_output_stop_steps 1:1: its 19
cases under the same names (steps_*), in the same order, with the same
values and expectations, the characterized-not-endorsed cases
included, the stand-in output and its copies of obs_output_stop(),
obs_output_force_stop(), obs_output_actual_stop(), stop_raw_audio(),
end_data_capture_thread(), shutdown_unstarted_encoders_thread(),
obs_output_end_data_capture_internal(), obs_output_end_data_capture()
and obs_output_signal_stop() written in Rust over the core.

Edge cases (edge_*) check the core against the origin/master
expressions inline: every low 16-bit flag word under 16 high words;
every restart count and thread result from -1,000 to 1,000 and the
extremes; every delay to 100,000 and the top 1,000; every mixer mask
to 4,096 and three wide ones; the stand-in through eleven callers
(each followed by its created thread) for every low flag word, each
of eight atomics and the stopping event set and clear, a restart
reference or none, a delay or none and each of eight inputs changed
alone (294,912 outputs); and proptests (4,096 cases each) of every
decision over full-range values and of the stand-in over sequences of
up to eleven calls, with another thread flipping the atomics, the
stopping event, the delay, the restart refs and the call results, or
running the created thread, between them.

soldr cargo test -p obs-data --test obs-tests-core --
output::output_stop passes 5 of 25 (the constants, the shared rules
and the two cases whose paths ask no new rule) and fails 20 with "not
yet implemented".

Refs obs-rust#2535.

* obs-output: Port the output stop decisions

Ports libobs/obs-output-stop.c.h, the output stop and end-capture
decisions, to the output_stop module of rust/obs-output. obs-output.c.h
stays C around it: obs_output_valid(), the context.data, raw_audio2,
signal and force tests, every atomic load and store (active,
data_active, reconnecting, starting, delay_active, delay_capturing,
delay_restart_refs and the end-capture thread's flags) and the stopping
event test where they always were, in their && order, the unpause, the
event resets and signals, the reconnect thread's join, info.stop,
obs_output_end_data_capture(), obs_output_delay_stop(), the encoder
stops and shutdowns, stop_raw_video(), audio_output_disconnect(),
obs_service_deactivate(), obs_output_cleanup_delay(), log_frame_info(),
the caption frees under their mutex, the keyframe tracking clear, the
joins, pthread_create(), the stop parameters copied before a thread
starts, the reconnect policy, every signal and every log. The hybrid
libobs drops the C file and links the Rust shims in its place.

Safe core (src/output_stop.rs):
- encoded(): OBS_OUTPUT_ENCODED is in the flags (the delayed stop, the
  encoders or the raw connections, the unstarted encoders' shutdown);
- delay_on(): active_delay_ns is not 0 (the delayed stop, the
  process_delay() callback, the delay cleanup);
- has_video() and has_audio(): OBS_OUTPUT_VIDEO, OBS_OUTPUT_AUDIO;
- service(): OBS_OUTPUT_SERVICE (the deactivation);
- end_delay(): the loaded restart count is 0;
- thread_failed(): pthread_create() did not return 0;
- interleave() and mix_on() re-exported from raw_audio and
  first_mixer() from video_checks: end_data_capture_thread(),
  stop_raw_audio() and get_first_mixer() call those shims, so they
  share one implementation.
The flags are video_checks'. The module denies clippy's arithmetic,
as, indexing, unwrap, expect, panic, todo, unimplemented and
unreachable lints, keeps no state, takes no lock and does not divide.

Shims (src/ffi/output_stop.rs): the seven functions keep the C
signatures; the restart count comes in as c_long (32 bits on Windows)
and is widened to i64, the thread result as c_int. No pointer crosses.

No intentional differences.

C side: the file leaves libobs.core-output for its own group,
libobs.ported-output-stop (LIBOBS_PORTED_SOURCES), whose PCH is only
obs-output-stop.h; libobs.pch.h keeps the header for obs-output.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. The exported symbol sets are unchanged
(1766) on the hybrid and C reference libobs, and identical, and the
seven functions are local in each; the hybrid libobs has no C object
for the group.

test_output_stop_steps still compiles the C file into itself,
unchanged. It has no _rust variant, as for test_output_start_steps:
the shims' archive member also holds the rest of obs-output, which
needs libobs's hidden seams and obs-util, so it does not link on its
own. Its tests.d file says so.

soldr cargo test -p obs-data --test obs-tests-core --
output::output_stop passes 25 of 25. Through ctest (private Xvfb and
D-Bus, own HOME and runtime directory, no sound), the full suite passes
against the hybrid libobs and the C reference libobs, 582 of 582 each,
the same 3 skipped on each (a PulseAudio default sink and the v4l2
vivid module, absent here). Among them test_output_stop_steps,
test_output_end_capture_thread_join, test_output_deactivate_state,
test_null_output_stop_thread, test_ffmpeg_output_stop,
test_ffmpeg_output_drain, test_encoder_error_stop,
test_replay_buffer_pause_stop, test_output_delay_e2e,
test_output_failed_start_encoders, test_recording_shutdown,
test_pthread_init_failures, test_output_start_steps and
test_output_raw_audio_steps.

Refs obs-rust#2535.

* obs-output: Check the output stop against C

Tier 3 for the output_stop port. The oracle
(rust/obs-c-oracle/oracle/output_stop.c) compiles the unchanged
libobs/obs-output-stop.c.h with its seven functions renamed to
oracle_*, plus its four flags and the widths of long and int, bound in
src/output_stop.rs. Nothing in it divides. The interleave and mix
oracles are output_raw_audio's and the first mixer's
output_video_checks'.

tests/output/output_stop_parity.rs compares the oracle, the shims and
the core exactly, all three sides:
- the four flags, sizeof(long) (32 bits on Windows: the shim takes
  c_long and widens it) and sizeof(int);
- the four flag rules over every low 16-bit flag word under 16 high
  words and a stride through all of u32;
- the delay over 0 to 1,000,000, the top 100,000, a stride through all
  of u64, every power of two and a stride of multiples of 2^32 (not 0,
  with the low 32 bits clear);
- the restart count over -100,000 to 100,000, the 100,000 values at
  each extreme of long and a stride through all of it;
- the thread result over -100,000 to 100,000, both ends of int and a
  stride through all of it;
- the callers on test_output_stop_steps' stand-in output (shared with
  Tier 1), on the oracle's gates and on the shims: eleven callers, each
  followed by its created thread, for every low flag word under two
  high words, each of eight atomics and the stopping event set and
  clear, a restart reference or none, a delay or none and each of eight
  inputs changed alone (589,824 outputs), comparing the record and the
  end state;
- proptests (20,000 cases each) of every decision over full-range
  values and of the stand-in over sequences of up to fifteen calls,
  with another thread flipping the atomics, the stopping event, the
  delay, the restart refs and the call results, or running the created
  thread, between them.

No input is excluded: nothing in the C divides or overflows, and the
mix test is asked only below six, as stop_raw_audio() asks it. A
restart count past a 32-bit long is passed to the C and the shim at
the nearest end, which keeps "not 0". The proptests keep no regression
files (failure_persistence None), as the start parity runners do.

Mutation check (once, not committed): 20 mutants, 13 in the core and
7 in the shims.

  mutant                                  Tier 1  Tier 3
  encoded: ==                                  12       4
  encoded: the video flag                       9       4
  OBS_OUTPUT_ENCODED from the service flag      6       5
  delay_on: > 1                                 5       2
  delay_on: always                              9       3
  has_video: the audio flag                     8       4
  has_audio: the video flag                     7       4
  service: ==                                   9       4
  service: the encoded flag                     8       4
  end_delay: <= 0                               5       3
  end_delay: !=                                 8       4
  thread_failed: < 0                            7       4
  thread_failed: never                          7       4
  shim encoded inverted                         0       4
  shim delay_on: the low 32 bits only           0       1
  shim has_video asks has_audio                 0       4
  shim has_audio asks has_video                 0       4
  shim service: flags >> 1                      0       4
  shim end_delay: positive only                 0       3
  shim thread_failed inverted                   0       4

(failing tests per tier.) Tier 1 kills all 13 core mutants and Tier 3
all 20. The low-32-bit shim first survived Tier 3; the powers of two
and the multiples of 2^32 in the delay inputs were added for it.

soldr cargo test -p obs-data --test obs-tests-core --
output::output_stop passes 33 of 33 (25 Tier 1, 8 Tier 3).

Refs obs-rust#2535.

* docs: Record the output stop port

rust/README.md gets the row for libobs/obs-output-stop.c.h
(obs-output::output_stop), after output_start's: what moved, the
interleave, mix and first mixer rules shared with raw_audio and
video_checks, what stays C and why (every atomic and the stopping
event loaded where they always were, the single-field tests in their
&& order, the three functions left unchanged), the
characterized-not-endorsed behaviours (a negative restart count
keeping the delay, a raw output with active_delay_ns stopping at once
and cleaning the delay up, an encoded output with neither flag
stopping no encoder, a forced stop of an inactive output calling
info.stop) and the tests that cover it; the obs-output crate row
names the file. The crate's Cargo description and lib.rs named the
module in the port commit, and docs/rust-port/naming.md maps the file
(the move commit).

rust/obs-c-oracle/benches/port_comparison/output_stop.rs, in the
sorted module list, runs 1024 rounds over the flag words of a stream,
a recording, a raw video and a raw AV output with delays, restart
counts, thread results and mixer masks, asking every decision
obs_output_stop(), obs_output_end_data_capture_internal(),
end_data_capture_thread() and stop_raw_audio() ask, in their order, on
the shims and on the oracle, and checks both checksums match; it
allocates nothing. Release, x86_64 Linux, GCC, median (load average
about 2): Rust 11.97 us, C 11.67 us (1.03x), about 12 ns a round, next
to an encoder stop, a thread creation or a single signal.

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

Fixes obs-rust#2535.

Local-Gate: v1 tree=77f3d243bf420ee69d5e95cb6146969b8cbbd5b0 secs=2935 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run
Ci-Attestation: {"at":1793060878,"gate":"rust/all/fmt","host":"linux-x86_64","key":"f354ddaafb1c15220eefabf7ae947cdbbb8c4645965c892be853a458f5ef16bd","lane":"lint","parents":["3880579f1553f8040b0015430552db5476aa4ed4"],"secs":55,"stamp":"e4bbf2bdbc8d4c1b7547c5965b53d0c2","tree":"77f3d243bf420ee69d5e95cb6146969b8cbbd5b0","v":1,"via":"run"}
Ci-Attestation: {"at":1793060878,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"f354ddaafb1c15220eefabf7ae947cdbbb8c4645965c892be853a458f5ef16bd","lane":"lint","parents":["3880579f1553f8040b0015430552db5476aa4ed4"],"secs":55,"stamp":"0d6b01e784ea3654ab7866f721bf3504","tree":"77f3d243bf420ee69d5e95cb6146969b8cbbd5b0","v":1,"via":"run"}
Ci-Attestation: {"at":1793060878,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"41d224f892012bab2557b4b451abce1d3d00fe9f9fdaa5a007c848b652cb0219","lane":"rust-test","parents":["3880579f1553f8040b0015430552db5476aa4ed4"],"secs":225,"stamp":"1bb6727794422645927ea85f1b4b6b11","tree":"77f3d243bf420ee69d5e95cb6146969b8cbbd5b0","v":1,"via":"run"}
Ci-Attestation: {"at":1793060878,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"edcd63b2913f488f130ce87c3c659d94c1a170c5462167e54c67a17748671f88","lane":"cross","parents":["3880579f1553f8040b0015430552db5476aa4ed4"],"secs":87,"stamp":"68304326bb180d3143006b4aeb0097fb","tree":"77f3d243bf420ee69d5e95cb6146969b8cbbd5b0","v":1,"via":"run"}
Ci-Attestation: {"at":1793060878,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"edcd63b2913f488f130ce87c3c659d94c1a170c5462167e54c67a17748671f88","lane":"cross","parents":["3880579f1553f8040b0015430552db5476aa4ed4"],"secs":87,"stamp":"f81377b13bc7c6a0c2e134dea1cf15b5","tree":"77f3d243bf420ee69d5e95cb6146969b8cbbd5b0","v":1,"via":"run"}
Ci-Attestation: {"at":1793060878,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"edcd63b2913f488f130ce87c3c659d94c1a170c5462167e54c67a17748671f88","lane":"cross","parents":["3880579f1553f8040b0015430552db5476aa4ed4"],"secs":87,"stamp":"9e47d3d83c06a4668a89cbc83890f62a","tree":"77f3d243bf420ee69d5e95cb6146969b8cbbd5b0","v":1,"via":"run"}
Ci-Attestation: {"at":1793060878,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"edcd63b2913f488f130ce87c3c659d94c1a170c5462167e54c67a17748671f88","lane":"cross","parents":["3880579f1553f8040b0015430552db5476aa4ed4"],"secs":87,"stamp":"0a230a5fd6b21acbd36130c4de2dfd47","tree":"77f3d243bf420ee69d5e95cb6146969b8cbbd5b0","v":1,"via":"run"}
Ci-Attestation: {"at":1793060878,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"a8bb094345e54633d203f45ae83b9a8068a28660e8cdcf9b6cd0b12162628f15","lane":"tier2-linux","parents":["3880579f1553f8040b0015430552db5476aa4ed4"],"secs":2568,"stamp":"e00d9c45cd138cbd539e6fa2dc570b83","tree":"77f3d243bf420ee69d5e95cb6146969b8cbbd5b0","v":1,"via":"run"}
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 raw output audio admission in obs-output.c to obs-output

2 participants