Skip to content

libobs: Read the output interleaver fields through hidden accessors - #1599

Merged
zackees merged 1 commit into
obs-rust:masterfrom
rdoupe:refactor/output-interleave-accessors
Oct 21, 2026
Merged

zackees merged 1 commit into
obs-rust:masterfrom
rdoupe:refactor/output-interleave-accessors

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator

Refs #1594 (step 2 of the plan: the accessors; the darray operations and the port follow)

What and why

obs-output-interleave.c.h reads and writes about 25 fields of struct obs_output, the caption tracks, and four fields of each encoder. These structs are private and platform-sized, and the Rust port should not mirror them. So the testing policy calls for a behaviour-neutral internal accessor in its own PR first. This is that PR. It has no Rust, and no public header or signature changes.

  • obs_output_interleave_fields() is declared in obs-internal.h next to the delay accessor and defined in obs-output.c.h. It returns one plain struct obs_output_interleave_fields of pointers into the output: interleaved_mutex, interleaved_packets, received_video[], received_audio, video_offsets[], audio_offsets[], highest_audio_ts, highest_video_ts[], video_encoders[], audio_encoders[], encoder_packet_times[], keyframe_group_tracking, pkt_callbacks_mutex, pkt_callbacks, total_frames, interleaver_max_batch_size, active_delay_ns, plus encoded_packet (info.encoded_packet), data (context.data) and name (context.name). An array field points at its first element.
  • obs_output_caption_track_fields(output, track) does the same for one caption track: caption_mutex, caption_head, caption_timestamp, last_caption_timestamp and caption_data.size.
  • In obs-encoder.c.h, obs_encoder_interleave_info() returns an encoder's timebase_num, timebase_den, framesize and encoder_group as values. obs_encoder_group_num_started() reads the group's num_encoders_started under the group's mutex.
  • interleave_packets(), get_encoder_index() and free_packets() get hidden external linkage and are declared in obs-internal.h. obs-output.c.h still passes interleave_packets to obs_encoder_start()/obs_encoder_stop(), and the Rust port will replace that symbol, as process_delay was replaced (libobs: Port the output stream delay to obs-output #1567).
  • The four obs-output.c helpers the interleaver calls are reached through hidden wrappers: obs_output_interleave_active(), obs_output_interleave_first_audio_encoder_index(), obs_output_interleave_first_video_encoder_index() and obs_output_interleave_add_caption().
  • None of these functions is EXPORT, so -fvisibility=hidden keeps them out of libobs.so, as with obs_output_delay_fields in libobs: Read the output delay fields through a hidden accessor #1550. They are C, not Rust shims, so rust-hidden.txt, rust-exports.map and rust-unexports-macos.txt need no entries.
  • obs-output-interleave.c.h now reaches the output and its encoders only through these. It has no output-> and no encoder-> left. The pointers alias the fields themselves, so every field is still read and written at the same point, under the same lock.

Design notes, against the plan in #1594:

  • Named darray types. The four DARRAY(...) members the interleaver uses get typedefs in obs-internal.h: obs_encoder_packet_array_t, obs_encoder_packet_time_array_t, obs_keyframe_group_array_t and obs_packet_callback_array_t. Without a name, C gives a pointer to an anonymous DARRAY union a type of its own, which the member's type does not match. The layout is unchanged. obs_source_info_array_t already uses this pattern in that header.
  • Wrappers, not relinked helpers. active() is static inline, and about 40 call sites in obs-output.c.h use it. The other three are plain static functions. Wrappers keep those definitions static and inlinable, and keep generic names such as active and add_caption out of libobs's global namespace. libobs: Read the output delay fields through a hidden accessor #1550 did the same for do_output_signal() with obs_output_delay_signal(). The three entry points keep their names, because test_output_interleave's cases call them by name.
  • Two encoder accessors. The plan had one encoder accessor that included the group's started count. Reading the count in that same call would take the group's mutex where the C code does not: on every keyframe check, and in get_encoder_duration(). So the count has its own call, at the point where the old code took the lock.
  • The group pointer is read once. check_encoder_group_keyframe_alignment() reads the encoder's group once, after the keyframe and video checks, not three times. Nothing synchronizes between those reads, and the group changes only while the encoder is stopped. The order of the return conditions is unchanged.
  • Caption track pointer. send_interleaved() reads the track's caption_tracks[] pointer once, before it takes the caption mutex. The old code read it twice. The pointer is set when the output is created and does not change while the output exists.
  • The accessor is fetched in each function. The test's cases call the static helpers directly with the output, so each helper keeps its struct obs_output * parameter and fetches the field struct itself. This costs about 20 pointer stores per call. Nothing is loaded from the output, and nothing locks.
  • const. The output accessor takes a const obs_output_t * for get_encoder_index(), and casts the const away in one place (through uintptr_t, as -Wcast-qual requires), as libobs: Read the output delay fields through a hidden accessor #1550 does.
  • Unity group. The file stays in its unity group, just before obs-output.c.h. It no longer needs that position, and the port PR moves it to its own group.

Tests: test_output_interleave compiles obs-output-interleave.c.h without obs-output.c.h or obs-encoder.c.h. Its harness therefore gets test/cmocka/output_interleave_fields_stub.c, which defines the same four accessors over the test's structs. That adds one source and a comment line to tests.d/test_output_interleave.cmake. In test_output_interleave.c, the four helper stubs take the wrapper names and external linkage, and the header comment says so. No test case or assertion changes.

RED → GREEN

  • No RED commit: this is a behaviour-neutral seam, and the existing tests pass on it unchanged.
  • Local, two build trees (ENABLE_RUST_LIBOBS=OFF and ON), headless (private Xvfb, private D-Bus, fresh HOME). Each runs the full cmocka suite against libobs and against libobs-with-rust:
Lane libobs libobs-with-rust Exported symbols
C (ENABLE_RUST_LIBOBS=OFF) 347/347 347/347 IDENTICAL (1766)
Rust (ENABLE_RUST_LIBOBS=ON) 347/347 347/347 IDENTICAL (1766)

In the Rust lane's libobs-with-rust run, test_core_module_load was run on its own: the system cmocka library became unavailable during the run, and that test clears LD_LIBRARY_PATH before re-running itself, so it was run with cmocka preloaded (it passed, as it did in the other three runs).

No test was skipped or not run. After the rebase onto current master, the 35 output, interleave, darray, encoder, caption and delay tests (including the new test_darray_ops) passed again in both lanes against both libraries. The export lists are also identical across the two lanes. The 11 new hidden functions are in the static symbol table of all four libobs.so builds, as local (t) symbols, and in none of the dynamic export tables.

  • test_output_interleave: 30/30, three runs in each lane, against libobs and libobs-with-rust. It was also 30/30 under ASan and UBSan, with leak checking, and no reports.
  • uv run ci/local_gate.py --lane lint: ok. --lane cross: ok. --lane cross-release: ok. These are Rust lanes. PR CI covers the Windows and macOS C link of the new hidden functions.
  • Real app: not applicable (no behaviour change).

Checklist

  • Base is master
  • 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: the characterization test_output_interleave merged in libobs: Move the output packet interleaver into obs-output-interleave.c #1595; no RED here (behaviour-neutral seam)
  • 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): not applicable
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): not applicable (no port here)

Behavior-neutral seam before the Rust port of obs-output-interleave.c: the
port should not mirror the private, platform-sized struct obs_output or
struct obs_encoder.

obs_output_interleave_fields(), defined in obs-output.c and declared in
obs-internal.h, returns one plain struct of pointers to the fields the
interleaver reads and writes: interleaved_mutex, interleaved_packets, the
received flags, the offsets and highest timestamps, the encoder arrays,
encoder_packet_times, keyframe_group_tracking, the packet callbacks and
their mutex, total_frames, interleaver_max_batch_size, active_delay_ns,
and info.encoded_packet, context.data and context.name. The darray members
it points at get named typedefs (same layout), so the pointers have a
type. obs_output_caption_track_fields() does the same for one caption
track. obs_encoder_interleave_info() returns an encoder's time base, frame
size and group, and obs_encoder_group_num_started() reads the group's
started count under its mutex, where the interleaver read it before.

interleave_packets(), get_encoder_index() and free_packets() get hidden
external linkage, and active(), the two first-encoder-index helpers and
add_caption() get hidden obs_output_interleave_ wrappers, so they keep
their static, inlinable definitions and generic names stay out of
libobs's global namespace. None of these is EXPORT, so
-fvisibility=hidden keeps them out of libobs, and the exported symbol set
stays the same.

obs-output-interleave.c now reaches the output and its encoders only
through these. Each field is still read and written at the same point,
under the same lock, as the pointers alias the fields themselves.

test_output_interleave compiles obs-output-interleave.c without
obs-output.c and obs-encoder.c, so its harness gains
output_interleave_fields_stub.c, the same four accessors over the test's
structs, and its four helper stubs take the wrapper names. No test case
changes.

Refs obs-rust#1594
@rdoupe
rdoupe requested a review from zackees as a code owner October 21, 2026 03:08
@zackees
zackees enabled auto-merge October 21, 2026 03:11
@zackees
zackees added this pull request to the merge queue Oct 21, 2026
Merged via the queue into obs-rust:master with commit 6feeef3 Oct 21, 2026
25 checks passed
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 21, 2026
* libobs: Add Tier 1 tests for the output interleaver port

RED for the port of libobs/obs-output-interleave.c.h, the encoded packet
interleaver, to obs-output's new interleave module. The pure parts work
on a slice of packets (a PacketView trait): the first and last packet of
a track, the start index, the premature prune, the insertion position,
the offset arithmetic, the streamable count and the catch-up rule, the
discard count, the caption timing and the packet-time lookup. The
functions named after the C ones are generic over the output
(InterleaveOutput): its fields, the queue and the other darrays, the
locks, the encoders and the libobs calls the C file makes, so the C ABI
shim can run them on the real struct obs_output through the hidden
accessors of obs-rust#1599, and the tests on a model. Every function is a
todo!() stub.

The first thirty cases mirror test_output_interleave 1:1 (same names,
same assertions, in order) on a model output that records what the C
test's stubs record: each sent packet with whether interleaved_mutex was
held, each packet callback call with its packet time and whether
pkt_callbacks_mutex was held, each add_caption call with whether the
track's caption mutex was held, and every held copy until it is
released. The other 23 pin the edges: the dts_usec and encoder duration
truncation, the first and last packet of a track, the start index and
the premature prune without audio, the duration lookups stopping at the
missing track, the insertion position at equal times, the opposing-type
test without video encoders, the catch-up boundaries, the discard
count, the caption timing at equal times, the first matching packet
time, single-encoder and foreign group entries, one lock per packet and
none when inactive, a delayed waiting packet released after the unlock,
a packet time offset after the start, an audio packet's time going to
the same-numbered array, one pir per callback, and a start without video
encoders.

They are a module of obs-tests-core, so no new test binary
(ci/test_binary_cap.py: 8 of 8).

soldr cargo test -p obs-data --test obs-tests-core output::interleave::
fails 53 of 53 with "not yet implemented".

Refs obs-rust#1594

* libobs: Port the output interleaver to obs-output

libobs/obs-output-interleave.c.h moves to obs_output::interleave. It is
the encoded packet callback of an output with video and audio:
interleave_packets queues the encoders' packets, starts every track
together at timestamp 0 and sends the packets in dts order, with their
encoder timing, captions and the encoder group keyframe check.
interleave_packets, get_encoder_index and free_packets are declared in
obs-internal.h without EXPORT; obs-output.c calls them, and passes
interleave_packets to the encoders by name, so the Rust symbol replaces
the C one the encoder later compares against.

The pure parts work on a slice of packets (PacketView): the first and
last packet of a track, the start index, the premature prune, the
insertion position, the offset arithmetic, the streamable count and the
catch-up rule, the discard count, the caption timing and the packet-time
lookup. The functions named after the C ones are generic over the output
(InterleaveOutput), as the delay core is over DelayOutput, and take
interleaved_mutex, pkt_callbacks_mutex and the caption mutex exactly
where the C does. The nine behaviours test_output_interleave marks
"characterized, not endorsed" are kept, among them the late-audio
keyframe drop, the last-track prune difference, the truncating encoder
duration, the track-0-only start index, the non-keyframe start, the
waiting non-keyframe discard, priming audio at offset 0 and the early
return that does not release a delayed packet.

The shim never reads struct obs_output or struct obs_encoder: it goes
through the hidden accessors and wrappers of obs-rust#1599, and reads and writes
each field where the C does. interleaved_packets, encoder_packet_times[]
and keyframe_group_tracking stay the C darrays obs-output.c resets and
frees; they are changed in place with obs_util::ffi::darray (obs-rust#1596,
obs-rust#1600). Queued packets are libobs's reference-counted copies or the
delay's. The clock is read once per packet callback, as in C; the
*_with_clock entry point and the statics module (the C file's static
functions on a live output) are Rust-mangled and are what the parity
test drives.

The file leaves libobs.core-output for its own group,
libobs.ported-output-interleave, whose PCH is obs-internal.h alone, so
the oracle and test_output_interleave compile it without the core. The
three symbols go in rust-hidden.txt, rust-exports.map and
rust-unexports-macos.txt. The exported symbol sets are unchanged.

Tier 3 (oracle/output_interleave.c) compares the layouts of the
keyframe group entry, the packet callback, the caption text, the darray
and the three accessor structs, the values the file uses, thirteen
characterization scenarios, and 1024 random runs of up to 80 steps over
one to two video and audio encoders: packets with random tracks,
keyframes, running timestamps and packet times, changes of active, the
delay, the batch limit, the captions, add_caption, the callbacks and the
encoder group, restarts, get_encoder_index, and the static functions
where their C preconditions hold. After every step it compares the
return value, every recorded call and whether each lock was held, the
log line, the held copies, the caller's packet, every queued packet,
packet time and group entry, the darray capacities and every
interleaver field. Both sides go through the same accessor and libobs
stand-ins. The oracle builds the file with NDEBUG, as libobs is built:
darray_pop_front asserts when a video packet without a packet time is
discarded, then does nothing, as the Rust darray does. No intentional
differences. test_output_interleave compiles the C into itself and is
unchanged.

Fixes obs-rust#1594
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 24, 2026
…obs-rust#2117)

* libobs: Move the output video checks into obs-output-video-checks.c

Behaviour-neutral extraction before the Rust port. The decisions of
get_first_mixer(), obs_output_get_width2() / _height2(), video_valid(),
audio_valid(), can_begin_data_capture(), has_scaling(),
obs_output_get_video_conversion(), the gates of
obs_output_can_begin_data_capture() and the clamp of
obs_output_get_congestion() move to libobs/obs-output-video-checks.c.h, as
six functions on plain values declared in the new
libobs/obs-output-video-checks.h without EXPORT (hidden, as
-fvisibility=hidden keeps them):

- obs_output_first_mixer(mixer_mask): the lowest set bit below
  MAX_AUDIO_MIXES, else 0, the loop moved as it was;
- obs_output_size_route(encoded, has_encoder, scaled): where one axis of
  obs_output_get_width2() / _height2() comes from, the encoder, 0, the
  scaled size or the video's;
- obs_output_capture_ready(presence): the flag and presence checks, over
  struct obs_output_capture_presence (info.flags, a bit per set video and
  audio encoder, and whether video, audio and service are set), with the
  encoder loops over the same MAX_OUTPUT_*_ENCODERS;
- obs_output_begin_gate(delay_active, active): ready, refuse or check;
- obs_output_conversion_plan(sizes): the set conversion with a 0 width or
  height filled from the raw output's size (the scaled size when set, else
  the video's, which is what obs_output_get_width() / _height() returned
  there), the scaled size when has_scaling(), or none;
- obs_output_congestion_clamp(value): the 0-1 clamp, a NaN still passing
  through.

obs-output.c.h keeps obs_output_valid(), the log_flag_* warnings, the
idx check, the pthread_join() of end_data_capture_thread, the calls to
obs_encoder_get_width() / _height() (only on the encoder route, so they run
exactly when they ran before), video_output_get_*(), video_output_get_info()
for the format, info.get_congestion and every write to video_conversion.
obs_output_set_mixer() is unchanged.

What changes in what the C reads, not in what it does:
- obs_output_can_begin_data_capture() loads active even when delay_active is
  set (two atomic loads, no side effect);
- obs_output_get_width2() / _height2() read video_encoders[idx] (already
  bounds-checked) on a raw output too;
- obs_output_get_video_conversion() reads the video's size up front
  (video_output_get_*() are NULL-safe reads) instead of through
  obs_output_get_width() on the set path, and stores the set conversion's
  width and height back unchanged when they were not 0.

Checked in a scratch harness (not committed) that compiles origin/master's
functions verbatim against the moved ones on a stand-in output: 20,000,000
random outputs (flags, encoders, video, audio, service, scaled and
conversion sizes, mixer masks, the two atomics and f32 congestion bit
patterns) give the same results, the same obs_encoder_get_width() /
_height() calls and the same video_conversion afterwards.

The flags and limits are copied into the header, so it needs no core
header; obs-output.c.h checks them against obs-output.h and audio-io.h 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).

git log -L on each moved function shows only upstream history; the fork's
fixes in this file (obs-rust#470, obs-rust#539, obs-rust#1109, obs-rust#1572, obs-rust#1599) are in the code that
stays in obs-output.c.h. obs-rust#470's NULL video after a view's mix is gone stays
covered: video_valid() and the conversion read a NULL video as no video, 0 x
0, as before.

Refs obs-rust#2067

* test: Characterize the output video size, conversion and capture checks

test_output_video_checks_steps compiles libobs/obs-output-video-checks.c.h
(ASan and UBSan) and calls only its six functions through
obs-output-video-checks.h, so it runs on every platform without a display.
27 cases:

- obs_output_first_mixer(): 0; each single bit of size_t (the mixer for
  bits 0 to 5, 0 above); several bits (the lowest below MAX_AUDIO_MIXES
  wins, a bit past the mixers does not hide one below); bits only at or
  above MAX_AUDIO_MIXES;
- obs_output_size_route(): encoded with and without an encoder at the
  index, whatever the scaled size; raw with a scaled size (1, 2, 720, 1280,
  2^31, UINT32_MAX) and without, with and without an encoder;
- obs_output_capture_ready(): each flag alone and together (video, audio,
  encoded, service, raw and encoded AV, a stream), against each presence
  bit: each of the 10 video and 6 audio encoder bits and the bits past
  them, the video, the audio and the service; the other flags
  (MULTI_TRACK, CAN_PAUSE, MULTI_TRACK_VIDEO, unknown) ignored; and every
  combination of the four flags against every single presence bit
  (14,976 calls) against a model;
- obs_output_begin_gate(): the four combinations of delay_active and
  active;
- obs_output_conversion_plan(): not set against scaled 0, equal and
  different (one axis is enough; one axis 0 is no scaling; no video reads
  as 0 x 0); set, kept whatever the scaled and video sizes; set with a 0
  width, height or both, filled from the scaled size or else the video's,
  each axis on its own;
- obs_output_congestion_clamp(): -1, 0, 0.5, 1, 2, +-inf and NaN, the
  floats next to 0 and 1, -0 (kept as -0), FLT_MAX and -FLT_MAX, compared
  bit for bit.

Characterized, not endorsed:
- a mixer mask with bits only at or above MAX_AUDIO_MIXES reports mixer 0
  (obs_output_set_mixer() with an index of 6 or more; a separate fix);
- a set conversion with a 0 axis, no scaled size and no video keeps 0 on
  that axis and is still returned;
- a NaN congestion from the plugin is returned as it is, payload and sign
  kept.
Characterized: an encoder bit at or above MAX_OUTPUT_*_ENCODERS is not an
encoder (obs-output.c builds the masks from the arrays, so it never sets
one).

It is in the native test graph, in the core suite, and links libm off
MSVC. The real-libobs tests test_raw_output_video_reset (obs-rust#470),
test_scaled_mix_alpha, test_texture_encoder_raw_format,
test_output_start_twice (obs-rust#539), test_output_failed_start_encoders,
test_output_null_id and test_encoding_lag_rescale cover the callers.

Refs obs-rust#2067

* obs-output: Add Tier 1 tests for the output video checks port

RED for the port of libobs/obs-output-video-checks.c.h to the
video_checks module of rust/obs-output, next to encoder_roi (obs-rust#1974). The
safe core is a stub (todo!()): first_mixer(mask) -> usize,
size_route(encoded, has_encoder, scaled) -> SizeRoute { Zero, Encoder,
Scaled, Video }, capture_ready(&Presence) -> bool, begin_gate(delay_active,
active) -> BeginGate { Ready, Refuse, Check }, video_conversion(
&ConversionSizes) -> Conversion { None, UseSet, Scaled } and
congestion(f32) -> f32, with the flags and limits as constants.

tests/output/video_checks.rs ports test_output_video_checks_steps 1:1: its
27 cases under the same names (steps_*), in the same order, with the same
values and expectations, the characterized-not-endorsed cases included.

Edge cases (edge_*) check the core against models of the original C:
every mixer mask of up to two bits with each low 6-bit pattern; every flag
word over the low 8 bits, with and without the high bits, against every
presence; every 10-bit video and 6-bit audio encoder pattern, with and
without the bits past the limits; the size routes over the u32 edges;
every conversion over the sizes 0, 1, 2 and u32::MAX, set and not set; the
congestion bit patterns within 256 of 0, -0, 1, -1, the infinities and the
NaNs, bit for bit; and the constants.

soldr cargo test -p obs-data --test obs-tests-core -- output::video_checks::
fails 33 of 34 with "not yet implemented"; edge_constants, which reads only
the constants, passes.

Refs obs-rust#2067

* obs-output: Port the output video checks

Ports libobs/obs-output-video-checks.c.h, the video size, conversion and
capture checks of obs-output.c, to the video_checks module of
rust/obs-output. obs-output.c.h stays C around it: obs_output_valid(), the
log_flag_* warnings, the index check, the pthread_join() of
end_data_capture_thread, obs_encoder_get_width() / _height() on the encoder
route, video_output_get_*() and video_output_get_info(), info.get_congestion,
the atomic loads, the presence masks built from the encoder arrays and every
write to video_conversion. obs_output_set_mixer() is unchanged. The hybrid
libobs drops the C file and links the Rust shims in its place.

Safe core (src/video_checks.rs):
- first_mixer(): the first i in 0..MAX_AUDIO_MIXES whose bit is set, else 0;
- size_route(): Encoder or Zero for an encoded output, Scaled when the
  scaled size is not 0, else Video;
- capture_ready(): each wanted part (OBS_OUTPUT_VIDEO, _AUDIO, _SERVICE)
  must be there, video and audio from the encoder bits below
  MAX_OUTPUT_VIDEO_ENCODERS / _AUDIO_ENCODERS when encoded, from the video
  and audio otherwise; the checks in the C's order;
- begin_gate(): Ready when the delay is active, else Refuse when active,
  else Check;
- video_conversion(): UseSet with each 0 axis filled from the raw output's
  size (scaled, else the video's); else Scaled when both scaled axes are set
  and either differs from the video's; else None;
- congestion(): below 0 is 0, above 1 is 1, the rest unchanged, so -0 stays
  -0 and a NaN passes through with its payload. It is f32::clamp(0.0, 1.0),
  which makes the C's two comparisons in the C's order (clippy's
  manual_clamp asks for it); the bounds are constants, so it cannot panic.
The module denies clippy's arithmetic, indexing, unwrap, expect, panic,
todo, unimplemented and unreachable lints, keeps no state and takes no
lock.

Shims (src/ffi/output_video_checks.rs): the six functions keep the C
signatures. struct obs_output_capture_presence, struct
obs_output_conversion_sizes and struct obs_output_conversion_choice are
mirrored #[repr(C)]; the shims read the input structs by value and return
the enum values as u32 (the C's enums) and the choice by value, 0 x 0 with
NONE as the C's initializer. No intentional differences.

Kept, characterized, not endorsed (test_output_video_checks_steps): a mixer
mask with bits only at or above MAX_AUDIO_MIXES reports mixer 0; a set
conversion with a 0 axis and no scaled size or video keeps 0; a NaN
congestion is returned as it is.

C side: the file leaves libobs.core-output for its own group,
libobs.ported-output-video-checks (LIBOBS_PORTED_SOURCES), whose PCH is only
obs-output-video-checks.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. The exported symbol sets are unchanged and
equal: 1766 on the C backend, the hybrid and libobs-c-reference; the six
functions are local in all three, and the hybrid's come from the Rust
archive (no C object of the group in the hybrid libobs).
ci/test_ported_sources.py checks the group on every host.

test_output_video_checks_steps still compiles the C file into itself,
unchanged. It has no _rust variant: linking it against libobs_rust-static
was tried and fails with 506 undefined references, because the shims'
archive member (obs_output cgu.1) also holds the service lifecycle, the
delay and the interleaver, which need libobs's hidden seams and obs-util
(GIO, libuuid); test_output_protocol_list_steps is in the same place. The
real-libobs tests (test_raw_output_video_reset, test_scaled_mix_alpha,
test_texture_encoder_raw_format, test_output_start_twice,
test_output_failed_start_encoders, test_output_null_id,
test_encoding_lag_rescale) see the swap through the hybrid.

Tier 1 output::video_checks passes 34/34.

Refs obs-rust#2067

* obs-output: Check the output video checks port against the C

Oracle (oracle/output_video_checks.c): the original
obs-output-video-checks.c.h, unmodified, with its six functions renamed to
oracle_obs_output_*, plus the 17 constants of the header (the flags, the
limits and the enum values) and the layout of struct
obs_output_capture_presence, struct obs_output_conversion_sizes and struct
obs_output_conversion_choice (sizes, alignments and every offset) and the
size of the enums.

Tier 3 (tests/output/video_checks_parity.rs, 15 tests). Every call runs the
shim, the C and the safe core and compares the results exactly: the mixer
index, the route and the gate as values, the capture check as a bool, the
conversion choice field by field, and the congestion as f32 bits. Runs:
- the constants and the layouts against the C;
- every mixer mask of up to two bits, each with every low 6-bit pattern
  or'ed in and replacing its low bits;
- every size route over 8 special scaled sizes (0, 1, 2, 720, 1080, 2^31 -
  1, 2^31, UINT32_MAX);
- the capture check exhaustively: the four checked flags, every 10-bit
  video and 6-bit audio encoder mask and the video, audio and service bits,
  8,388,608 calls; and every low 8-bit flag word, alone, with all high bits
  and with bit 31, against encoder masks with bits past the limits;
- the four begin gates;
- every conversion over the sizes 0, 1, 2 and UINT32_MAX on all six, set and
  not set (8192, each kind reached), plus the steps test's values;
- the congestion over the bit patterns within 256 of 0, -0, 1, -1, 0.5, the
  largest finite floats, the infinities and the NaNs (quiet, signalling,
  either sign), and every 65521st of all 2^32;
- proptests (8192 cases each) over full-range usize mixer masks, u32 flags
  and encoder masks, u32 sizes biased to 0 and to scaled equal to video on
  one axis or both, and f32 congestions drawn as bit patterns, plus bit
  patterns near the edges. No wide Range<f32> is used.

The parity module passed 10 runs in a row with fresh seeds. The regression
file holds the seeds proptest saved while the mutants below failed; all
pass on the port.

Each congestion mutant replaces the whole body of congestion(), so the
rows hold for the f32::clamp form the port uses (the run was on the C's
if / else chain, which clippy then asked to write as clamp).

Mutation check (done once, not committed), with Tier 1 (34 tests) and
Tier 3 (15) in one run: 45 mutants, 37 in the core and 8 in the shims. 42
fail; the 3 that survive are equivalent.

| Mutant | Tier 1 | Tier 3 |
|---|---|---|
| first_mixer: 7 mixers / 5 mixers | 3 / 3 | 2 / 2 |
| first_mixer: none found is MAX_AUDIO_MIXES | 4 | 2 |
| first_mixer: highest bit / no mixer limit | 2 / 3 | 2 / 2 |
| size_route: Encoder and Zero swapped | 2 | 2 |
| size_route: raw always Video / scaled > 1 | 2 / 2 | 2 / 2 |
| size_route: a raw output with an encoder asks it | 2 | 2 |
| capture: encoded video from the video pointer | 7 | 3 |
| capture: 11 video encoders / 5 audio encoders | 5 / 5 | 2 / 3 |
| capture: encoder masks without the limit | 6 | 2 |
| capture: no service check / service always needed | 3 / 11 | 3 / 3 |
| capture: video checked on the audio flag | 8 | 3 |
| capture: encoded read from OBS_OUTPUT_SERVICE | 7 | 3 |
| capture: raw audio from the video pointer | 4 | 3 |
| begin_gate: active first / delay gives Check | 1 / 1 | 1 / 1 |
| conversion: fill from the video only / always fill | 2 / 4 | 2 / 2 |
| conversion: width filled from the height axis / no fill | 2 / 2 | 2 / 2 |
| has_scaling: either axis / both must differ | 2 / 2 | 2 / 2 |
| has_scaling: no scaled_height check / ignores the video | 2 / 2 | 2 / 2 |
| conversion: the set conversion ignored when scaled | 3 | 2 |
| congestion: if value <= 0 (-0 becomes +0) | 2 | 2 |
| congestion: NaN as 0 / max().min() | 2 / 3 | 3 / 3 |
| congestion: upper bound 0.999 | 3 | 3 |
| MAX_AUDIO_MIXES 5 / MAX_OUTPUT_VIDEO_ENCODERS 9 | 3 / 6 | 3 / 4 |
| shim: SCALED and VIDEO swapped / READY and REFUSE swapped | 0 | 2 / 1 |
| shim: video and audio swapped / set width and height swapped | 0 | 3 / 2 |
| shim: NONE carries the scaled size / SET reported as SCALED | 0 | 2 / 2 |
| shim: first_mixer of mask & 0x1f | 0 | 2 |
| equivalent: the C's if / else if chain with > as >= (1 gives 1 either way) | 0 | 0 |
| equivalent: the C's if / else if chain itself, in the core or in the shim (the same comparisons as f32::clamp: NaN and -0 pass) | 0 | 0 |

Tier 1 does not reach the shims; Tier 3 kills every shim mutant.

Refs obs-rust#2067

* docs: Record the output video checks port

The rust/README.md crate table now lists
libobs/obs-output-video-checks.c.h among the units rust/obs-output holds,
and its port table has a row for it: the six functions and their rules,
what stays C in obs-output.c.h (the validity checks, the warnings, the
join, the encoder and video size calls, the plugin's congestion, the atomic
loads, the presence masks and the writes to video_conversion), the three
mirrored structs, the "characterized, not endorsed" behaviours kept, why
test_output_video_checks_steps has no _rust variant, the real-libobs tests
that see the swap, and what Tier 3 compares. No intentional differences.
The crate's description and lib.rs say what it holds.
docs/rust-port/naming.md got its entry in the move commit.

port_comparison gets its own bench file,
benches/port_comparison/output_video_checks.rs: 1024 capture checks over
streams, recordings, raw and broken outputs; 1024 conversion plans over
1080p, 720p, 1440p and no video, scaled or not, with set conversions with
and without 0 axes; and 1024 rounds of the first mixer, a size route, a
begin gate and a congestion clamp (NaN every 97th), each folded into a
checksum both sides must match. On x86_64 Linux (GCC, not pinned, a loaded
host; median per 1024 calls): capture_ready 2.40 us Rust and 2.76 us C
(0.87x), conversion_plan 2.61 us Rust and 5.92 us C (0.44x),
mixer_route_gate_congestion 5.78 us Rust and 6.07 us C (0.95x). Each runs
at most once per output start or per getter call, so neither side is on a
hot path.

Fixes obs-rust#2067
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.

2 participants