Repository navigation
obs-output: Port the output pause plan - #3024
Merged
Merged
Conversation
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
force-pushed
the
fix/rust-port-output-pause-plan-294
branch
from
October 30, 2026 10:33
b977e21 to
cd010f0
Compare
rdoupe
marked this pull request as ready for review
October 30, 2026 11:19
zackees
reviewed
Oct 30, 2026
zackees
left a comment
Member
There was a problem hiding this comment.
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.hkeeps every atomic, mutex and signal inobs-output.cin 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_endread only afterts_startpasses) is a good catch. - Intentional differences: both are real upstream hazards, reachable only from plugins and hosts: one encoder in two slots taking
pause.mutextwice, and a divide by zero when the frame interval is 0. They are recorded under Fixed upstream bugs indocs/features.md. The exported symbols are unchanged (1767 on C, hybrid and reference).
Queuing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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) torust/obs-outputas the moduleoutput_pause, in six commits and two review follow-ups:libobs: Move output pause plan to own file): the decisions ofobs_output_pause(),obs_encoded_output_pause(),obs_raw_output_pause()and their helpers move, behaviour-neutral, tolibobs/obs-output-pause.c.has hidden functions on plain values: theOBS_OUTPUT_CAN_PAUSEgate, 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.ckeepsobs_output_valid(), every atomic onactive,pausedand the encoders'paused(each loaded where it was), everypause.mutexlock and unlock in its order, the frame interval read andos_gettime_ns(),get_first_video_encoder_index(), the record stores, the signals and the log.test_output_pause_steps(9 cases, the moved C on its own, ASan/UBSan).obs_output::output_pauseontodo!()stubs.libobs.ported-output-pause, hidden in all three export lists.oracle_obs_output_pause_*, parity tests and aport_comparisonbench.rust/README.md,naming.md, the crate description.libobs: Test pause record fields one at a time):pause_can_start()andpause_can_stop()readts_endonly once theirts_starttest passed, which a two-field function lost. The record rules are now one test per field,obs_output_pause_started()andobs_output_pause_ended(), joined with!and&&inobs-output.cin the original order (seven functions in all). The pause symbols in the three export lists are sorted.obs-output: Scale pause Tier 1 cases by CI level: the Tier 1 proptests go throughobs_c_oracle::parity::cases().Intentional differences (fixed in the port; reachable only from plugins, scripts and libobs hosts):
obs_encoded_output_pause()locks the same encoder's plainpause.mutextwice. The port locks, checks and updates each distinct encoder once;docs/features.mdhas the line under Fixed upstream bugs. No upstream issue.RED → GREEN
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).output::output_pause).ctest -R 'pause|output|encoder|replay|record', among themtest_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 againstlibobs-c-reference, 0 skipped, under a private Xvfb.output::output_pause_parity, 11 cases): the flag gate over every low 16-bit flag word under 16 high words and a stride throughu32, 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.--test-diff origin/master5278 passed, 6 skipped;--lane lintand--lane crossok;cargo clippy --workspace --target x86_64-pc-windows-msvc --all-targetsclean.port_comparison(output_pause/pause_unpause/256): Rust 8.6 µs, C 9.7 µs.output::output_pause); no own threads.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 inobs-output.cincluded) and the 9 in the moved file by the characterization.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC