Skip to content

obs-output: Port the output pause plan - #3024

Merged
zackees merged 8 commits into
masterfrom
fix/rust-port-output-pause-plan-294
Oct 30, 2026
Merged

zackees merged 8 commits into
masterfrom
fix/rust-port-output-pause-plan-294

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #3020

What and why

Ports the pause plan of obs-output.c (what pausing and unpausing a recording, or any output that can pause, does to its encoders: which encoders' pause records are locked and updated, the pause time on the video frame grid, and each record's start, end and offset) to rust/obs-output as the module output_pause, in six commits and two review follow-ups:

  1. Move (libobs: Move output pause plan to own file): the decisions of obs_output_pause(), obs_encoded_output_pause(), obs_raw_output_pause() and their helpers move, behaviour-neutral, to libobs/obs-output-pause.c.h as hidden functions on plain values: the OBS_OUTPUT_CAN_PAUSE gate, the "already in that state" success, the lock set (the slots whose encoder's record is locked, checked and updated), the pause time, the record's field tests, and its offset. obs-output.c keeps obs_output_valid(), every atomic on active, paused and the encoders' paused (each loaded where it was), every pause.mutex lock and unlock in its order, the frame interval read and os_gettime_ns(), get_first_video_encoder_index(), the record stores, the signals and the log.
  2. Characterize: test_output_pause_steps (9 cases, the moved C on its own, ASan/UBSan).
  3. RED: Tier 1 for obs_output::output_pause on todo!() stubs.
  4. GREEN: the core and its C shims in a new group libobs.ported-output-pause, hidden in all three export lists.
  5. Tier 3: the original C as oracle_obs_output_pause_*, parity tests and a port_comparison bench.
  6. Docs: rust/README.md, naming.md, the crate description.
  7. Field tests (libobs: Test pause record fields one at a time): pause_can_start() and pause_can_stop() read ts_end only once their ts_start test passed, which a two-field function lost. The record rules are now one test per field, obs_output_pause_started() and obs_output_pause_ended(), joined with ! and && in obs-output.c in the original order (seven functions in all). The pause symbols in the three export lists are sorted.
  8. obs-output: Scale pause Tier 1 cases by CI level: the Tier 1 proptests go through obs_c_oracle::parity::cases().

Intentional differences (fixed in the port; reachable only from plugins, scripts and libobs hosts):

  • one encoder in two audio slots (or two video slots) hangs a pause: the setters check only the slot they set, and obs_encoded_output_pause() locks the same encoder's plain pause.mutex twice. The port locks, checks and updates each distinct encoder once;
  • the pause time divides by the frame interval, which stays 0 until video is first set up, so a raw output that can pause, in a host that never reset video, divides by zero. The port uses the clock as the pause time when the interval is 0.

docs/features.md has the line under Fixed upstream bugs. No upstream issue.

RED → GREEN

  • RED commit: bd2a258 (obs-output: Add Tier 1 tests for pause port): all 19 Tier 1 tests fail on the stubs with "not yet implemented" (obs-tests-core, output::output_pause).
  • GREEN:
    • Tier 1: 19/19 (output::output_pause).
    • Tier 2: the 77 output, encoder, pause and recording tests (ctest -R 'pause|output|encoder|replay|record', among them test_output_pause_steps, test_replay_buffer_pause_stop, which pauses and unpauses a real recording, test_encoder_output_getters_characterization, test_recording_shutdown*, test_output_delay* and the output and encoder steps tests): 77/77 against the hybrid libobs and 77/77 against libobs-c-reference, 0 skipped, under a private Xvfb.
    • Tier 3: 30/30 with Tier 1 (output::output_pause_parity, 11 cases): the flag gate over every low 16-bit flag word under 16 high words and a stride through u32, 65,536 slot layouts with repeats, the record rules over 14 edge timestamps cubed, the pause time for 12 intervals, whole pauses side by side over every layout of four slots with every record state, raw pauses, and proptests. 12 planted mutants of the core (after the field-test split): all caught by Tier 3 and by Tier 1.
    • Gates: --test-diff origin/master 5278 passed, 6 skipped; --lane lint and --lane cross ok; cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targets clean.
    • Exported symbols unchanged and identical on the C, hybrid and C reference libobs (1767); the seven functions are local in each, and the hybrid ones are the Rust shims.
    • port_comparison (output_pause/pause_unpause/256): Rust 8.6 µs, C 9.7 µs.
    • Test cost: new tests longest 0.6 s for the whole module (debug, both levels); peak RSS 25 MB over 25 runs at each level (the binary filtered to output::output_pause); no own threads.
  • Real app (UI, protocol output or logging changes): N/A (no UI, protocol or log change).

Runs were on cd010f0, based on ddbece4. The local gate could not run its Tier 2 lane here (no Docker access on this host), so the head is not stamped and PR CI runs the full suite; Tier 2 ran natively instead (77/77 on each libobs, after the rebase).

Move proof: master's obs_output_pause(), obs_encoded_output_pause(), obs_raw_output_pause() and their four helpers against the moved code over logging stand-ins (every lock, atomic, clock read, signal and log), 300,000 random outputs with 1 to 4 calls each: gcc and clang, -O0 and -O2, with and without ASan/UBSan, 0 differences; after the field-test split, 11 planted mutants all caught by the harness (the two && joins in obs-output.c included) and the 9 in the moved file by the characterization.

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
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

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

- obs_output_pause(): obs_output_pause_allowed(flags), the
  OBS_OUTPUT_CAN_PAUSE gate, and obs_output_pause_already(paused,
  pause), the "already in that state" success;
- obs_encoded_output_pause(): obs_output_pause_lock_set(video, audio,
  &video_lock, &audio_lock), the slots whose encoder's pause record is
  locked, checked and updated (every slot with an encoder, as before);
  the lock, gate, update and unlock loops walk its marks;
- get_closest_v_ts(): obs_output_pause_closest_ts(last_video_ts,
  interval, now), the clock snapped to the frame grid two frames on;
- pause_can_start() and pause_can_stop():
  obs_output_pause_can_start() and obs_output_pause_can_stop();
- end_pause(): obs_output_pause_ends(ts_end) and
  obs_output_pause_offset(ts_offset, ts_start, ts_end).

The arithmetic is C's, unchanged. The new header copies
OBS_OUTPUT_CAN_PAUSE, MAX_OUTPUT_VIDEO_ENCODERS and
MAX_OUTPUT_AUDIO_ENCODERS; obs-output.c checks them with
_Static_assert.

obs-output.c keeps obs_output_valid(), every atomic on active, paused
and the encoders' paused (each loaded where it was), every pause.mutex
lock and unlock in its order, the frame interval read and
os_gettime_ns() in their order, get_first_video_encoder_index(), the
record stores, the signals and the log.

Checked in a scratch harness (not committed): master's
obs_output_pause(), obs_encoded_output_pause(), obs_raw_output_pause()
and their four helpers against the moved code, over logging stand-ins
for every lock, atomic, clock read, signal and log, on 300,000 random
outputs (flags, states, up to 16 slots filled from 6 encoders with
repeats, every record state, intervals including 1 and odd 64-bit
values, clocks near 0 and UINT64_MAX) with 1 to 4 calls each: gcc and
clang, -O0 and -O2, with and without ASan/UBSan, 0 differences in 8
builds. 10 planted mutants of the moved file (the flag test, the
already test, the video and audio lock marks, the grid's two frames,
its multiply, the start and stop tests, the end test and the offset)
are all caught.

Exported symbols are unchanged and identical on the C, hybrid and
C reference libobs (1767); the eight functions are local.

Refs #3020.
Characterization before the Rust port, against the C moved to
libobs/obs-output-pause.c: test_output_pause_steps (every platform, the
moved file on its own, ASan and UBSan), 9 cases:

- only an output with OBS_OUTPUT_CAN_PAUSE pauses;
- pausing a paused output, or unpausing a running one, succeeds with
  nothing done;
- every slot with an encoder is locked (none, the recording's one video
  and two audio encoders, gaps, every slot);
- the pause time on the 60 fps grid: no frame yet, a clock on the grid,
  one ns past a frame and one before the next, a clock a frame behind
  the last frame, and 30 fps and 1 ns frames;
- whether a record can start or end a pause, its end set once and its
  offset;
- whole pauses run the way obs-output.c runs them, on stand-in
  records: one video and two audio encoders paused, unpaused, paused
  again before the records clear, and again after (the offset adds
  up); one record not clear failing the whole pause and the unpause,
  with every lock given back; an encoded output with audio encoders
  only, which can't pause (characterized, not endorsed); and a raw
  output on its own record.

Not covered: the inputs the port changes on purpose (one encoder in two
slots, which hangs on its own pause mutex, and a frame interval of 0,
which the grid divides by).

Deliberate breaks of the moved C (the 10 mutants of the move's
harness): all 10 caught.

Refs #3020.
RED for #3020. obs_output::output_pause has its API and docs, with
todo!() bodies: allowed() and already() (obs_output_pause()'s gates),
lock_set() (whose pause records a pause locks and updates),
closest_ts() (the pause time on the video frame grid), can_start(),
can_stop(), ends() and offset() (a record's pause rules).

tests/output/output_pause.rs:
- steps_*: test_output_pause_steps.c 1:1 (9 cases, same names, values
  and expectations, with its stand-ins for obs_encoded_output_pause()
  and obs_raw_output_pause());
- edge_*: the intentional differences (one encoder in several slots
  locked, checked and updated once, at its first slot, video first,
  with a recording whose one audio encoder sits on two tracks pausing
  and unpausing; a frame interval of 0 giving the clock, with a raw
  output in a host that never reset video), and proptests of the
  pause time against the C's wrapping expression and on the grid, the
  lock set's marks, the records' rules and the gates, and any input
  without a panic.

All 19 fail on the stubs (obs-tests-core, output::output_pause).

Refs #3020.
GREEN for #3020. obs_output::output_pause implements the pause plan of
obs-output.c:

- allowed(): flags & OBS_OUTPUT_CAN_PAUSE != 0;
- already(): paused == pause;
- lock_set(): each distinct encoder marked once, at its first slot,
  video slots first;
- closest_ts(): last + ((now - last + 2 * interval) / interval) *
  interval in wrapping u64, as the C computes it; an interval of 0
  gives now;
- can_start(), can_stop(), ends(): the record rules;
- offset(): ts_offset + (ts_end - ts_start), wrapping.

Intentional differences: the C marks every slot with an encoder, so an
encoder in two slots has its plain pause mutex locked twice by
obs_encoded_output_pause() and the caller hangs (the setters check only
the slot they set, so a script or plugin can do it); here it is locked,
checked and updated once. And the C divides by the frame interval,
which stays 0 until video is first set up, so pausing a raw output in a
libobs host that never set up video divides by zero; here the pause
time is the clock. The frontend sets one encoder per slot and always
sets up video, where nothing changes. docs/features.md has the line.
The module denies clippy::todo now too.

C ABI (ffi::output_pause): eight shims on plain values, the lock set
reading the two slot arrays of opaque ids and writing the two masks.

libobs: obs-output-pause.c.h moves from libobs.core-output to its own
group libobs.ported-output-pause, whose precompiled header includes
only the unit's header. The hybrid libobs leaves the group out and
links the shims; the eight symbols are listed in rust-exports.map,
rust-hidden.txt and rust-unexports-macos.txt and stay hidden.
ci/test_ported_sources.py lists the object. Exported symbols are
unchanged and identical on the C, hybrid and C reference libobs
(1767).

Tier 1: 19/19 (obs-tests-core, output::output_pause).

Refs #3020.
Tier 3 for #3020. The original libobs/obs-output-pause.c.h is built as
oracle_obs_output_pause_* (obs-c-oracle, oracle/output_pause.c), and
tests/output/output_pause_parity.rs compares it with the shims and the
safe core exactly:

- the flag gate over every low 16-bit flag word under 16 high words
  and a stride through all of u32, and every "already" pair;
- every layout of the first two video slots and the six audio slots
  over an empty slot and three encoders (65,536, repeats included),
  also moved up the video slots;
- the record rules and offset over 14 edge timestamps cubed, and the
  pause time over those for 12 intervals;
- whole pauses and unpauses, a copy of obs_encoded_output_pause() run
  side by side on stand-in records, for every layout of four slots
  over three encoders with every record state, and raw pauses;
- proptests over full-range values, all 16 slots and call sequences.

Intentional differences: one encoder in several slots is marked once,
so the port's marks (and whole pauses) equal the C's on the layout
with the repeats emptied; a frame interval of 0 gives the clock, where
the C divides by it (never called with 0).

Mutation check: 11 planted mutants of the core (each gate, the lock
set's repeat test and bit, the grid's two frames, its multiply and its
interval-0 branch, the start, stop and end tests, and the offset): all
caught by Tier 3 and by Tier 1. 30 tests, 0.5 s at both levels.

port_comparison: output_pause/pause_unpause/256, a recording with one
video and two audio encoders paused and unpaused 256 times.

Refs #3020.
rust/README.md: the obs-output row names obs-output-pause.c.h, and the
new obs-output::output_pause row says what was swapped, what C keeps,
what is kept but not endorsed, the two intentional differences and the
tiers. naming.md's rust/obs-output row and the crate's Cargo.toml
description list obs-output-pause.c.h.

Fixes #3020.
pause_can_start() and pause_can_stop() read ts_end only once their
ts_start test passed (!ts_start && !ts_end, !!ts_start && !ts_end),
but obs_output_pause_can_start() and _can_stop() took both fields as
arguments, so obs-output.c read ts_end unconditionally. The record
rules are now one test per field, obs_output_pause_started(ts_start)
and obs_output_pause_ended(ts_end) (which also replaces
obs_output_pause_ends()), and obs-output.c joins them with ! and && in
the order it always read them. end_pause() asks
!obs_output_pause_ended(). Seven functions now, not eight.

The Rust core has started() and ended(), with can_start() and
can_stop() kept as the same joins for Rust callers and the tests; the
shims, the oracle, the characterization (its stand-ins join the field
tests as obs-output.c does), Tier 1, the parity tests and the bench
follow. The pause symbols in rust-exports.map, rust-hidden.txt and
rust-unexports-macos.txt are sorted.

Rechecked: the move harness against master, 300,000 random outputs,
gcc and clang, -O0 and -O2, with and without ASan/UBSan, 0
differences; 11 planted mutants of the moved C (the two joins
included) all caught, 9 of the moved file by the characterization. 12
mutants of the core: all caught by Tier 3 and Tier 1. Exported symbols
identical on the C, hybrid and C reference libobs (1767), the seven
local. Tier 2: 77/77 on each.

Refs #3020.
The Tier 1 proptests of output_pause ran 4096 cases at every level.
They now go through obs_c_oracle::parity::cases(4096), as the testing
policy asks, so OBS_PARITY_CASES=reduced runs a tenth of them on PRs
and in the merge queue.

Fixes #3020.
@rdoupe
rdoupe force-pushed the fix/rust-port-output-pause-plan-294 branch from b977e21 to cd010f0 Compare October 30, 2026 10:33
@rdoupe
rdoupe marked this pull request as ready for review October 30, 2026 11:19
@rdoupe
rdoupe requested a review from zackees as a code owner October 30, 2026 11:19

@zackees zackees left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coordinator review: LGTM. Thank you, @rdoupe. This is a careful port.

  • Move, then characterize, then RED → GREEN: the behaviour-neutral move into obs-output-pause.c.h keeps every atomic, mutex and signal in obs-output.c in its original order, and only the decisions on plain values move. test_output_pause_steps (9 cases, ASan/UBSan) pins the moved C before the Rust lands, and all 19 Tier 1 tests fail on the stubs.
  • Tiers: Tier 2 77/77 on both the hybrid libobs and libobs-c-reference. Tier 3 is extensive: the flag gate over every low-16 word, 65,536 slot layouts with repeats, edge timestamps cubed and whole pauses side by side, and 12 planted mutants are all caught. The _Static_asserts tie the copied flag and limits to the real ones.
  • Field tests: splitting the record rule into one test per field to keep the C's short-circuit (ts_end read only after ts_start passes) is a good catch.
  • Intentional differences: both are real upstream hazards, reachable only from plugins and hosts: one encoder in two slots taking pause.mutex twice, and a divide by zero when the frame interval is 0. They are recorded under Fixed upstream bugs in docs/features.md. The exported symbols are unchanged (1767 on C, hybrid and reference).

Queuing.

@zackees
zackees added this pull request to the merge queue Oct 30, 2026
Merged via the queue into master with commit 3e56765 Oct 30, 2026
41 checks passed
@zackees
zackees deleted the fix/rust-port-output-pause-plan-294 branch October 30, 2026 11:34
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 output pause plan

2 participants