Skip to content

obs-output: Port the output encoder slot rules and setter gates - #2475

Merged
zackees merged 6 commits into
obs-rust:masterfrom
rdoupe:port/output-encoder-slots
Oct 26, 2026
Merged

zackees merged 6 commits into
obs-rust:masterfrom
rdoupe:port/output-encoder-slots

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Fixes #2467

What and why

Ports the encoder slot rules and setter gates of libobs/obs-output.c.h to rust/obs-output, as a new module output_slots, next to video_checks. Every encoded output goes through them when the frontend, obs-websocket or a plugin sets its encoders, mixers or preferred size, and get_first_video_encoder_index() / get_first_audio_encoder_index() also run for every interleaved packet and every pause:

  • get_first_video_encoder_index() and get_first_audio_encoder_index() (which obs_output_audio() now calls instead of its own copy of the loop): the lowest occupied slot;
  • obs_output_set_mixer(): the range check and the mask;
  • obs_output_set_video_encoder2() and obs_output_set_audio_encoder(): the type gate, the index rule (with OBS_OUTPUT_MULTI_TRACK_VIDEO / OBS_OUTPUT_MULTI_TRACK below the slot count, else index 0 only), and for video the preferred-size step at index 0;
  • obs_output_remove_encoder_internal(): which slots an encoder of that type can be in;
  • obs_output_get_video_encoder2(), obs_output_get_audio_encoder() and obs_output_set_preferred_size2(): the index bounds, and the raw size write at index 0.

The plan's API was split per step. The plan sketched one slot_gate(kind, flags, has_encoder, encoder_type, active, idx) -> Refuse | Same | Replace { caption, preferred_size }, plus mixer_gate(), service_gate(), preferred_size() and remove_slots(). A combined gate would load active() before the type gate logs and returns, and read the slot before the index rule; service_gate() would load active() and read service->active ahead of the short circuit (and dereference a NULL service). So each step is its own function, asked at its own point (as #2153 did), and twelve functions cross the C ABI:

  • obs_output_slots_first_video() and _first_audio(): the lowest set bit of an occupancy mask the caller builds (bit i: slot i is set), as can_begin_data_capture() already does since obs-output: Port the output video size, conversion and capture checks #2117; the index is written only when a slot is set;
  • _mixer_in_range() and _mixer_mask();
  • _video_type_ok() and _audio_type_ok(): the type gates, also asked in turn by remove_encoder_internal(), so info.type is still read twice there as the if / else if did;
  • _video_index_ok() and _audio_index_ok();
  • _default_index() and _scaled_axis_set(): asked for scaled_width, then for scaled_height only when the width is set;
  • _video_slot() and _audio_slot().

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

  • obs_output_valid(), the log_flag_* checks in their order with their short circuit (they log as they test), flag_encoded();
  • active(), an atomic, loaded where it was: after the type gate and before the index rule in the setters, after the range check in obs_output_set_mixer();
  • every read of the output and the encoder, and every pointer comparison (the slot already holding the encoder, the slots that hold it);
  • every obs_encoder_get_ref() and obs_encoder_release() in their order (release the old, then reference the new), obs_encoder_add_output() and _remove_output();
  • destroy_caption_track() and create_caption_track() (a NULL test of the encoder), obs_encoder_set_scaled_size(), obs_encoder_audio() and every log;
  • obs_output_set_mixers(), obs_output_remove_encoder() and obs_output_set_service(), unchanged: they decide nothing beyond those flag, active and NULL checks.

The header copies the two multitrack flags, the two slot counts, MAX_AUDIO_MIXES and the two encoder types, and obs-output.c.h checks them with _Static_assert. The one pointer is the index the two first functions write; no struct is mirrored.

The one read that changed: building the occupancy mask reads every slot, where the loop stopped at the first set one. The reads are of plain pointers, with no call, lock or write between them, as in can_begin_data_capture().

Six commits:

  1. Move (behaviour-neutral, 2304de38e): the decisions go to libobs/obs-output-slots.c.h, declared in the new obs-output-slots.h without EXPORT, so they are hidden. The file joins libobs.core-output. git blame on the moved lines shows upstream commits and one fork change, the mixer range check of libobs: Ignore an out-of-range output mixer index and a conversion without video #2142.

    The move was checked against the original code. A scratch harness (not committed) compiles origin/master's flag helpers, active(), the two index helpers, obs_output_video(), obs_output_audio(), the mixer setters and getter, both remove functions, the four encoder setters and three getters, obs_output_set_service() and both preferred-size setters verbatim, next to this branch's and the moved file, as C++:

    • the stand-in output's fields (the flags, the slots, the caption tracks, the scaled size, the mixer mask, the service, the encoders' types, the services' active and output) log every read and write, with the value;
    • every call is logged in order with its arguments and result: obs_output_valid(), each active load, reference, release, output hookup, caption track, scaled size, obs_encoder_audio() / _video() and log line;
    • the stubs answer from one seeded stream in call order; another thread may flip active after any load of it, and a reference may fail. Reads with nothing between them are compared as a sorted run;
    • the inputs are one to four calls of eighteen entry points with any flag word, slots empty or holding one of six encoders (two video, two audio, types 2 and 9), indexes 0, 1, max - 1, max, max + 1, 2^32, SIZE_MAX and random, NULL encoders and outputs, and three services (one active, one owned by another output);
    • the one expected difference, the mask reading every slot, is normalized on both sides: a scan of slots 0, 1, 2, ... in order is cut after its first set slot, and every other read must match.

    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 34,198,187 logged events match, and so does the state after each run. Every line and branch of origin/master's functions, this branch's and the moved file's is reached both ways (gcov).

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

    • active() loaded before the type gate; scaled_height read with scaled_width 0; info.type read once in remove_encoder_internal();
    • the audio index rule dropped (it crashes); the raw size written at any index; obs_output_audio() taking slot 0;
    • fifteen changed decisions: the bit test inverted, slot 0 skipped, the last audio slot missed, the mask shifted by one, and the range, mask, type, index, default-index, scaled-size and bound rules each off by one, inverted or on the wrong kind.

    The 22nd, _first_audio() scanning ten slots, is equivalent here: the caller's mask has no bit from 6 up. The characterization test pins the function itself.

  2. Characterization (69b317ee4): test_output_slots_steps, 16 cases. It compiles the moved file with ASan and UBSan and calls only its functions: every decision over every 10-bit (video) and 6-bit (audio) mask under four high words, every low 8-bit flag word at 15 edge indexes, the type gates over eight types, and the mixer shift at every width. It also copies the callers onto a stand-in output that records every warning, active load, reference, hookup, caption track and scaled size, end to end for raw, encoded, video-only, audio-only and multitrack outputs:

    • the flag warnings first, the type warning before the active load, the active refusal (even for NULL);
    • the index rules at 0, 1, max - 1, max and SIZE_MAX; OBS_OUTPUT_MULTI_TRACK is the audio flag and says nothing about video, and the other way round;
    • the same encoder twice (nothing after the active load), the old encoder released before the new one is referenced, NULL clearing a slot and destroying its caption track;
    • the preferred size at index 0 only, and only with both axes set; the getters' bounds whatever the flags; obs_output_audio() and obs_output_get_video_encoder() taking the first occupied slot;
    • set_mixer() at MAX_AUDIO_MIXES - 1 and at it (the range warning before the active refusal); remove_encoder_internal() clearing every slot of the encoder's kind; set_preferred_size2()'s raw write at index 0 and the encoder size at any slot.

    It is in the test graph, sorted, with the header as a watch input. It compares no values of two different enum types and uses no assert_in_range or fail_msg.

  3. RED (6eca4df8c): Tier 1 against todo!(). It ports the 16 C cases 1:1 and adds 7 edge tests: the slot counts, every 16-bit mask under four high words, every low 16-bit flag word under four high words at indexes 0 to 11 and the edges, the mixer mask past the width, the type gates over -1000 to 1000, a proptest of every decision over full-range values, and a proptest of the stand-in over call sequences against origin/master's expressions inline.

  4. GREEN (4dcfad91c): the safe core and twelve #[no_mangle] shims, in a new libobs.ported-output-slots 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_slots_steps has no _rust variant, as for test_output_raw_audio_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 (13eff59f7): a C oracle of the unchanged file, the parity tests and a mutation check.

  6. Docs (1c78504d8): 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 no arithmetic; its slot counts are asserted at compile time against the ones video_checks mirrors.

  • Kept, characterized, not endorsed (upstream behaviour, unchanged):
    • an encoder whose reference fails (it is being destroyed) leaves its video slot empty but still gets a caption track: the C tests the encoder it was passed, not the reference it got;
    • clearing video slot 0 of an output with a scaled size still asks obs_encoder_set_scaled_size() of the now-NULL slot, which logs a NULL parameter warning;
    • remove_encoder_internal() looks for a video encoder only in the video slots (the setters never put it anywhere else).
  • Intentional differences: mixer_mask() with an index at or past the width of size_t, where the C's shift is undefined, gives 0. The C asks only 0 to 5.

Bench (x86_64 Linux, GCC, release, not pinned to a core, a loaded host; median per 1024 rounds of every setter, getter and mixer decision): Rust 14.81 µs, C 15.29 µs (0.97x).

RED → GREEN

  • RED commit: 6eca4df8c (obs-output: Add Tier 1 tests for output slots; the same patch was 4629c7e4d on origin/master 2fbf34251, where these runs were made).
    • soldr cargo test -p obs-data --test obs-tests-core -- output::output_slots: 1 passed (the constants), 22 failed, each on a todo!().
    • On that commit, local_gate --lane lint was clean, and --test-diff origin/master ran 4300 tests: 4278 passed, 6 skipped, and only those 22 failed.
  • GREEN (4dcfad91c): Tier 1 23/23.
    • test_output_slots_steps passes 16/16 on the C backend, on hybrid libobs and on libobs-c-reference.
    • test_multitrack_encoder_override, test_output_input_checks, test_service_encoder_settings, test_output_interleave_e2e, test_output_caption_codec, test_raw_output_video_reset, test_output_null_id, test_multitrack_ladder, test_output_video_checks_steps, test_output_raw_audio_steps, test_output_start_twice, test_output_failed_start_encoders, test_encoder_video_reset and test_output_delay_restart pass on all three (run through ctest).
    • Exported symbols are identical on all three (1766, as on origin/master). The twelve 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 (13eff59f7): 9/9, oracle, shims and core compared exactly.
    • The seven constants.
    • The first slot of each kind over every 16-bit mask under 16 high words and a stride through u32, with whether the index was written.
    • The mixer range over 0 to 1023 and the edges, the mask at every shift below the width; the type gates over -100,000 to 100,000 and the i32 edges; the index rules over every low 16-bit flag word under four high words at indexes 0 to 11 and the edges; the default index, the scaled-size axis and the bounds.
    • The callers copied onto a stand-in output, over the oracle and over the shims: every one- and two-call sequence of 14 calls from 64 starts (13,440 sequences), and each call from those starts made active.
    • Proptests of 20,000 cases each, over full-range values and over call sequences from any start.
  • Mutation check: 23 mutants (16 in the core, 7 in the shims).
    • Tier 1 kills all 16 in the core (1 to 10 tests each). Tier 3 kills 22 (1 to 6 tests each), every shim mutant included.
    • The Tier 3 survivor is the intentional difference (the mask past the width of usize, where the oracle is not called); Tier 1 pins it.
  • Checks (the branch was rebased three times while they ran; git range-diff shows the six patches unchanged each time):
    • on 1c78504d8 (this head, on origin/master 917094b1c): local_gate --lane lint passes;
    • on 352f4a3fa (the same patches on fb85e74ac): local_gate --lane lint and --test-diff origin/master (4372 passed, 6 skipped) pass; the selected real-libobs tests above pass on all three lanes and the exported symbol sets are identical (1766);
    • on 612fc0e2c (on 1dc59c1a9): local_gate --lane cross passes, SOLDR_RUSTC_WRAPPER=none soldr cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets --locked -- -D warnings is clean, and soldr cargo test -p obs-c-oracle --locked --bench port_comparison passes.
  • Full ctest (C backend, hybrid libobs, libobs-c-reference) on 72d55e251 (the same patches on 2fbf34251): 100% passed on each, 527/527 (C backend), 556/556 (hybrid), 556/556 (libobs-c-reference), with no reruns. 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 the private session lacks). None touches the output slots.
  • 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, mixer_mask() past the width of size_t

Behaviour-neutral extraction before the Rust port. The decisions of the
encoder slot setters and getters of obs-output.c move to
libobs/obs-output-slots.c.h, as twelve functions on plain values
declared in the new libobs/obs-output-slots.h without EXPORT (hidden, as
-fvisibility=hidden keeps them):

- get_first_video_encoder_index() and get_first_audio_encoder_index():
  _first_video() and _first_audio(), the lowest occupied slot of an
  occupancy mask the caller builds (bit i: slot i is set), as
  can_begin_data_capture() already does; obs_output_audio() now calls
  get_first_audio_encoder_index() instead of its own copy of the loop;
- obs_output_set_mixer(): _mixer_in_range() and _mixer_mask();
- obs_output_set_video_encoder2() and obs_output_set_audio_encoder():
  _video_type_ok() and _audio_type_ok() (the type gate, also the slot
  choice of obs_output_remove_encoder_internal()), _video_index_ok() and
  _audio_index_ok() (multitrack: below the slot count, else 0 only);
  for video, _default_index() and _scaled_axis_set() (the encoder at
  index 0 takes the scaled size when both axes are set);
- obs_output_get_video_encoder2(), obs_output_get_audio_encoder() and
  obs_output_set_preferred_size2(): _video_slot() and _audio_slot(),
  the bounds, and _default_index() for the raw size write.

The plan sketched one slot_gate() returning refuse, same or replace.
That would load active() before the type gate logs and returns, and
read the slot before the index rule, so each step is its own function,
asked at its own point, as obs-rust#2153 did. The log_flag_* calls stay in their
order with their short circuit, active() is loaded where it was (after
the type gate, before the index rule; after the range check in
set_mixer()), info.type is read twice in
obs_output_remove_encoder_internal() as the if/else-if did, and
scaled_height only when scaled_width is set.

C keeps obs_output_valid(), the log_flag_* checks, flag_encoded(),
active(), every read of the output and the encoder, every pointer
comparison (the slot already holding the encoder, the slots that hold
it), every obs_encoder_get_ref() and obs_encoder_release() in their
order, obs_encoder_add_output() and _remove_output(),
destroy_caption_track() and create_caption_track() (a NULL test of the
encoder), obs_encoder_set_scaled_size(), obs_encoder_audio() and every
log. obs_output_set_mixers(), obs_output_remove_encoder() and
obs_output_set_service() are unchanged: they decide nothing beyond the
flag, active and NULL checks that stay, and their short-circuit order
(log_flag_service(), then active(), then service->active) cannot move
into one call without loading or reading ahead.

Checked in a scratch harness (not committed). It compiles
origin/master's flag helpers, active(), the two index helpers,
obs_output_video(), obs_output_audio(), the mixer setters and getter,
both remove functions, the four encoder setters and three getters,
obs_output_set_service() and both preferred-size setters verbatim, and
this branch's with the moved file, as C++, over a stand-in output whose
fields (the flags, the slots, the caption tracks, the scaled size, the
mixer mask, the service, the encoders' types, the services' active and
output) log every read and write with the value. It logs every
obs_output_valid(), active load, reference, release, output hookup,
caption track, scaled size, obs_encoder_audio() and _video() and log
line, in order, and each call's result. The stubs answer from one
seeded stream in call order; another thread may flip active after any
load of it, and a reference may fail. Reads with no write or call
between them are compared as a sorted run.
- Inputs: one to four calls of the eighteen entry points on one output,
  with any flag word (the seven flags and random high bits), every slot
  empty or holding one of six encoders (two video, two audio, types 2
  and 9), indexes 0, 1, max - 1, max, max + 1, 2^32, SIZE_MAX and
  random, NULL encoders and NULL outputs, sizes 0, 1, 1280 and random,
  three services (one active, one owned by another output).
- One expected difference, normalized on both sides: building the mask
  reads every slot, where the loop stopped at the first set one (plain
  pointers, no call, lock or write between). A scan of slots 0, 1, 2,
  ... in order is cut after its first set slot; every other read must
  match.
- 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 state after each
  run: 34,198,187 events.
- Every line and branch of origin/master's functions, this branch's and
  the moved file's is reached both ways (gcov).
- 22 deliberately broken moves were planted. 21 fail it: each decision
  changed (the bit test inverted, slot 0 skipped, the last audio slot
  missed, the mask shifted by one, the range check, mask, type, index,
  default-index, scaled-size and bound rules each off by one, inverted
  or on the wrong kind), active() loaded before the type gate,
  scaled_height read with scaled_width 0, info.type read once in
  remove_encoder_internal(), the audio index rule dropped (it crashes),
  the raw size written at any index, and obs_output_audio() taking slot
  0. The 22nd, _first_audio() scanning ten slots, is equivalent here:
  the caller's mask has no bit from 6 up. The characterization test
  pins the function itself.

git blame on the moved lines shows upstream commits (6ec0b2d,
84e1f47, 6da26a3, b8a3ae1, 2036de8 and earlier) and one fork
change, the mixer range check of obs-rust#2142.

The constants (OBS_OUTPUT_MULTI_TRACK_AUDIO and _VIDEO, the two slot
counts, MAX_AUDIO_MIXES and the two encoder types) 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) on the C
build, hybrid and c-ref; the twelve functions are local.

Refs obs-rust#2467
test_output_slots_steps compiles libobs/obs-output-slots.c.h with ASan
and UBSan, and calls only its functions through obs-output-slots.h. 16
cases:

- the copied constants;
- the first occupied video slot over every 10-bit mask under four high
  words, the first audio slot over every 6-bit mask likewise, the last
  slot of each, and no write of the index when none is set; bits past
  the slot count are ignored (slots 6 to 9 are video only);
- set_mixer()'s range check at 5, 6 and the edge indexes, and the mask
  over every shift below the width of size_t;
- the two type gates over eight types (the two real ones, 2, 3, 9, the
  negative and INT_MAX);
- the two index rules over every low 8-bit flag word, with and without
  high bits, at 15 edge indexes (0, 1, 2, 5, 6, 7, 9, 10, 11, 31, 32,
  63, 64, SIZE_MAX - 1, SIZE_MAX): OBS_OUTPUT_MULTI_TRACK is the audio
  flag, OBS_OUTPUT_MULTI_TRACK_VIDEO the video one, and each says
  nothing about the other kind;
- the default index, the scaled-size axis test and the two bounds.

The callers are also copied onto a stand-in output that records every
warning, active load, reference, release, hookup, caption track and
scaled size in order: obs_output_set_video_encoder2(),
obs_output_set_audio_encoder(), the getters,
obs_output_get_video_encoder(), obs_output_audio(),
obs_output_set_mixer(), obs_output_remove_encoder_internal() and
obs_output_set_preferred_size2().
They pin, end to end, for raw, encoded, video-only, audio-only and
multitrack outputs: the flag warnings before anything else, the type
warning before the active load, the active refusal (even for NULL), the
index rules at 0, 1, max - 1, max and SIZE_MAX, the same encoder twice
(nothing after the active load), the release of the old encoder before
the reference to the new one, NULL clearing a slot and destroying its
caption track, the preferred size at index 0 only and only with both
axes set, the getters' bounds whatever the flags, the first encoder of
obs_output_get_video_encoder() and obs_output_audio(), set_mixer() at
MAX_AUDIO_MIXES - 1 and at it (the range warning before the active
refusal), remove_encoder_internal() clearing every slot of the
encoder's kind, and set_preferred_size2()'s raw write at index 0 and
encoder size at any slot.

Characterized, not endorsed:
- an encoder whose reference fails (it is being destroyed) leaves the
  slot empty but still gets a caption track: the C tests the encoder it
  was passed, not the reference it got;
- clearing video slot 0 of an output with a scaled size still sets the
  size, on the NULL slot, so obs_encoder_set_scaled_size() logs a NULL
  parameter;
- remove_encoder_internal() looks for a video encoder only in the video
  slots (the setters refuse to put it anywhere else).

obs_output_set_service(), obs_output_set_mixers() and
obs_output_remove_encoder() moved nothing, so they are not copied here.

It is in the native test graph, in name order, with the header as a
watch input, and links libm off MSVC. No assert_in_range or fail_msg,
so it builds with cmocka 1.x and 2.x, and it compares no values of two
different enum types. The real-libobs tests
test_multitrack_encoder_override, test_output_input_checks,
test_service_encoder_settings, test_output_interleave_e2e,
test_output_caption_codec, test_raw_output_video_reset and
test_output_null_id cover the callers; test_multitrack_ladder the
frontend's track layout.

Refs obs-rust#2467
RED for the port of libobs/obs-output-slots.c.h to a new output_slots
module of rust/obs-output, next to video_checks. The safe core is a stub
(todo!()): SlotKind (Video, Audio) and its count(), first_slot(),
mixer_in_range(), mixer_mask(), type_ok(), index_ok(), default_index(),
scaled_axis_set() and slot_exists(), with the multitrack flags, the slot
counts, the two encoder types and MAX_AUDIO_MIXES (from video_checks).
The two C functions per kind (_first_video and _first_audio, ...) take
the kind here.

tests/output/output_slots.rs ports test_output_slots_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 included,
the stand-in output written in Rust over the core.

Edge cases (edge_*) check the core against models of the original C:
the slot counts; the first slot over every 16-bit mask under four high
words; the index rules over every low 16-bit flag word under four high
words at indexes 0 to 11 and 15 edge values; the mixer mask past the
width of usize (0, where the C's shift is undefined); the type gates
over -1000 to 1000 and the i32 edges; a proptest of every decision over
full-range values (4,096 cases); and a proptest of the stand-in over
sequences of 1 to 11 calls (the setters, getters, obs_output_audio(),
set_mixer(), remove_encoder_internal(), set_preferred_size2() and
active flips) from any start, against the same stand-in with
origin/master's expressions inline (4,096 cases).

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

Refs obs-rust#2467
Ports libobs/obs-output-slots.c.h, the encoder slot rules and setter
gates of obs-output.c, to the output_slots module of rust/obs-output.
obs-output.c.h stays C around it: obs_output_valid(), the log_flag_*
checks in their order, flag_encoded(), the active loads, every read of
the output and the encoder, the occupancy masks, the pointer
comparisons, every reference and release, the encoder hookups, the
caption tracks, the scaled size and the logs. The hybrid libobs drops
the C file and links the Rust shims in its place.

Safe core (src/output_slots.rs):
- SlotKind (Video, Audio): its count (10, 6), multitrack flag
  (OBS_OUTPUT_MULTI_TRACK_VIDEO, OBS_OUTPUT_MULTI_TRACK) and encoder
  type;
- first_slot(): the lowest set bit of the mask below the count;
- mixer_in_range(): below MAX_AUDIO_MIXES; mixer_mask(): bit idx;
- type_ok(): the kind's encoder type; index_ok(): with the kind's
  multitrack flag below its count, else 0 only; slot_exists(): below
  the count, whatever the flags;
- default_index(): 0; scaled_axis_set(): not 0.
The module denies clippy's arithmetic, as, indexing, unwrap, expect,
panic, todo, unimplemented and unreachable lints, keeps no state, takes
no lock and does no arithmetic; its slot counts are asserted at compile
time against the ones video_checks mirrors.

Shims (src/ffi/output_slots.rs): the twelve functions keep the C
signatures. The one pointer is the index the two first_* shims write,
only when a slot is set, as the C did; no struct is mirrored.

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

C side: the file leaves libobs.core-output for its own group,
libobs.ported-output-slots (LIBOBS_PORTED_SOURCES), whose PCH is only
obs-output-slots.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_slots_steps still compiles the C file into itself,
unchanged. It has no _rust variant, as for test_output_raw_audio_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_slots
passes 23 of 23.

Refs obs-rust#2467
Tier 3 for the output_slots port. The oracle
(rust/obs-c-oracle/oracle/output_slots.c) compiles the unchanged
libobs/obs-output-slots.c.h with its twelve functions renamed to
oracle_*, plus its seven constants, bound in src/output_slots.rs.
Nothing in it divides or calls out.

tests/output/output_slots_parity.rs compares the oracle, the shims and
the core exactly, all three sides:
- the seven constants;
- the first slot of each kind over every 16-bit mask under 16 high
  words and a stride through all u32, with whether the index was
  written (it starts as a sentinel);
- the mixer range over 0 to 1023 and the edge indexes, the mask at every
  shift below the width of usize;
- the type gates over -100,000 to 100,000 and the i32 edges;
- the index rules over every low 16-bit flag word under four high words
  at indexes 0 to 11 and 15 edge values;
- the default index and the bounds over 0 to 1023 and the edges, the
  scaled-size axis over 0 to 1023 and a stride through all u32;
- the callers (both encoder setters, the getters,
  obs_output_get_video_encoder(), obs_output_audio(), set_mixer(),
  remove_encoder_internal() and set_preferred_size2(), as the C test's
  stand-in output) on the oracle and on the shims: every one- and
  two-call sequence of 14 calls from 64 starts (every combination of the
  video, audio, encoded and both multitrack flags, empty or with
  encoders, captions and a scaled size; 13,440 sequences), and each
  call from those starts made active, comparing every warning, active
  load, reference, hookup, caption track, scaled size and result;
- proptests (20,000 cases each) of every decision over full-range values
  and of the callers over sequences of up to 16 calls from any start.

The oracle is called for mixer_mask() 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): 23 mutants, 16 in the core and 7
in the shims.

  mutant                                  Tier 1  Tier 3
  first_slot: bit test inverted                6       4
  first_slot: slot 0 skipped                   5       4
  count: ten audio slots                      10       6
  bit_set: the next bit                        6       4
  mixer_in_range: <=                           4       4
  mixer_mask: the next bit                     4       4
  mixer_mask: all bits past the width          2       0
  type_ok: inverted                           10       4
  encoder_type: kinds swapped                  9       3
  multi_track_flag: kinds swapped              8       4
  index_ok: multitrack <=                      6       4
  index_ok: single track takes 1               6       3
  index_ok: flag test inverted                 8       4
  default_index: <= 1                          5       3
  scaled_axis_set: > 1                         1       1
  slot_exists: <=                              5       4
  shim first_video: audio slots                0       4
  shim first: index written when none          0       2
  shim video_type_ok: audio                    0       3
  shim audio_index_ok: video                   0       4
  shim video_slot: audio                       0       4
  shim mixer_mask: the next index              0       4
  shim scaled_axis_set: inverted               0       4

(failing tests per tier.) Tier 1 kills all 16 core mutants, Tier 3 22
of 23. Its survivor is the intentional difference: the mask past the
width of usize, where the oracle is not called; Tier 1 pins it.

soldr cargo test -p obs-data --test obs-tests-core -- output::output_slots
passes 32 of 32 (23 Tier 1, 9 Tier 3).

Refs obs-rust#2467
rust/README.md gets the row for libobs/obs-output-slots.c.h
(obs-output::output_slots): what moved, what stays C and why, the one
read that changed (the occupancy mask reads every slot, as
can_begin_data_capture() already does), the characterized-not-endorsed
behaviours (a caption track for a slot whose reference failed, the
scaled size asked of a cleared slot), 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_slots.rs, in the
sorted module list, runs 1024 rounds of every decision the setters,
getters and obs_output_set_mixer() ask (both first-slot scans, the type,
index, default-index, scaled-size, bound and mixer rules), on the shims
and on the oracle, and checks both checksums match. Release, x86_64
Linux, GCC, a loaded host, median: Rust 14.81 us, C 15.29 us (0.97x).

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

Fixes obs-rust#2467
@zackees

zackees commented Oct 26, 2026

Copy link
Copy Markdown
Member

Coordinator review: a decision port in the standard shape, like #2457. The output encoder slot rules and setter gates move into a steps unit and then to Rust, with a C reference copy, a parity test, a bench and the export maps. The only existing test file touched is the test-graph.json entry. Queuing; it merges when CI is green.

@zackees
zackees enabled auto-merge October 26, 2026 11:42
@zackees
zackees added this pull request to the merge queue Oct 26, 2026
Merged via the queue into obs-rust:master with commit ced5048 Oct 26, 2026
70 of 72 checks passed
vpacher pushed a commit to vpacher/obs-studio that referenced this pull request Oct 26, 2026
test_visibility_transition reuses the names a to e in every case. The
video thread holds a reference on each source while it ticks, so the
teardown's release is not always the scene's last one: the video
thread then destroys the scene after the destruction queue was
flushed, the previous case's boxes are still alive, and libobs renames
the new ones ("c 2 Show Transition", seen in the PR CI of obs-rust#2475).

The teardown now waits for the "destroy" signal of the scene, the
group and every box before the next case runs. The cases and their
assertions are unchanged.

Fixes obs-rust#2479
@zackees zackees mentioned this pull request Oct 26, 2026
6 of 7 tasks
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 output encoder slot gates in obs-output.c to obs-output

2 participants