Repository navigation
libobs: Port the output stream delay to obs-output - #1567
Merged
Merged
Conversation
RED for the port of libobs/obs-output-delay.c.h, the stream delay, to a new crate, obs-output. The safe core (obs_output::delay) is generic over the output: its delay fields, the queue, the delay lock and the libobs calls the C file makes (DelayOutput), so the C ABI shim can run it on the real struct obs_output through the hidden accessors and take delay_mutex exactly where the C takes it. The pop decision is a pure function of the front entry's time, the clock, the running delay and the preserve and reconnecting flags; the clock is a parameter, read once per call. Every function is a todo!() stub. The first twenty cases mirror test_output_delay 1:1 (same names, same assertions, in order) on a model output that records the libobs calls and whether the lock was held, as the C test's stubs do. The rest pin the edges: the strict comparison and the wrapping age, when preserve extends the delay (also shorter than it was), the truncating seconds cast, one lock per push and per pass and none in cleanup, an empty queue, a start or stop at the front while preserving, a failed capture that releases packets queued before it, and an entry the file never queues. 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:: fails 35 of 35 with "not yet implemented". Refs obs-rust#1546
libobs/obs-output-delay.c.h moves to obs_output::delay, a new crate named after the component, so later units of obs-output.c can join it. Its seven functions are what obs-output.c calls to hold an output's packets, start and stop for the stream delay: obs_output_set_delay, obs_output_get_delay and obs_output_get_active_delay (EXPORT), and process_delay, obs_output_delay_start, obs_output_delay_stop and obs_output_cleanup_delay (hidden; obs-output.c installs process_delay as the encoded packet callback by name). The safe core runs on any DelayOutput (the C output through the shim, or a model in the tests) and takes the delay lock exactly where the C takes delay_mutex: once per push and once per pass over the front, never in cleanup, and never around a callback. The pop decision is a pure function of the front entry's time, the clock, the running delay and the preserve and reconnecting flags, with the strict comparison and the wrapping age of the C. The six behaviours test_output_delay marks "characterized, not endorsed" are kept. The shim never reads struct obs_output: it goes through the hidden obs_output_delay_fields() and obs_output_delay_signal() (obs-rust#1550), and reads and writes each field at the point the C does, the os_atomic ones as atomics of their C size. delay_data stays the C struct deque of struct delay_data that obs-output.c frees; it is pushed, peeked and popped in place with obs_util::ffi::deque (obs-rust#1561). Held packets are libobs's reference-counted copies (obs_encoder_packet_create_instance, hidden in libobs) and go back through obs_encoder_packet_release. Each entry point reads os_gettime_ns() once and calls an *_at function with it, which the parity test drives with a test clock. The file leaves libobs.core-output for its own group, libobs.ported-output-delay, whose PCH is obs-internal.h alone, so the oracle and test_output_delay compile it without the core. The four hidden symbols go in rust-hidden.txt, rust-exports.map and rust-unexports-macos.txt; the three exported ones in rust-exports.d/obs-output-output_delay.txt. The exported symbol sets are unchanged. Tier 3 (oracle/output_delay.c) compares the layouts of encoder_packet, encoder_packet_time, delay_data and obs_output_delay_fields, the values the file uses, the characterization scenarios, and random sequences of packets, starts, stops, cleanups, setter and getter calls (null outputs too), flag, result and clock changes: after every step the return value, the recorded calls and whether the lock was held, the log line, the packet copies, every delay field, the deque state and every queued entry. Both sides go through the same accessor and libobs stand-ins. No intentional differences. test_output_delay compiles the C into itself and is unchanged. Fixes obs-rust#1546
zackees
enabled auto-merge
October 20, 2026 22:12
zackees
approved these changes
Oct 20, 2026
This was referenced Oct 21, 2026
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 #1546 (PR 4 of 4; #1547 added the characterization test
test_output_delay, #1550 the hidden accessors this port reads the output through, #1548 and #1561 the Rustutil/deque.h)What and why
This PR ports
libobs/obs-output-delay.c.h, the stream delay, to a new crate,rust/obs-output. The file has seven functions.obs_output_set_delay,obs_output_get_delayandobs_output_get_active_delayareEXPORT.process_delay,obs_output_delay_start,obs_output_delay_stopandobs_output_cleanup_delayare declared inobs-internal.hwithoutEXPORT;obs-output.ccalls them, and installsprocess_delayas the encoded packet callback by name.libobs-with-rustdrops the C file and links the Rust shims.obs-output, named after the component (meta: Phase 6 libobs core migration through opaque C seams #444), so later units ofobs-output.ccan join it. It is listed in naming.md, in bothrust/README.mdtables and in the testing-policyobs-tests-corerow. Its one dependency isobs-util(the deque,os_gettime_nsand bmem).src/delay.rs):pop_decision(front_ts, now, active_delay_ns, preserve, reconnecting)returnsHold,PoporExtend(age). It is a pure function with the C's strict>and wrapping subtraction.dispatchruns an entry that left the queue: a packet is delivered while the delay is active and capturing and released otherwise; a start or stop runs whatever the delay state.active_delay_secsis the whole-seconds getter, with the C's truncatingu32cast.process_delay,pop_packet,start,stopandcleanupare generic over aDelayOutputtrait (the delay fields, the queue, the lock and the libobs calls), as libobs: Port the Wayland hotkey key state to obs-hotkey #1516 is generic over its lock and store. They take the lock where the C takesdelay_mutex: once per push and once per pass over the front, never in cleanup, never around a callback.Option<&O>and aNullLog, so the null-output case (logged under the setter's name by all three) is in the core and Tier 1 ports it 1:1.cfg, nounsafe.test_output_delaymarks "characterized, not endorsed" are kept: the getters log a null output under the setter's name; the seconds getter wraps pastu32::MAXs; an entry is held while its age equals the delay (so a zero delay waits for a later packet); a clock that goes backwards releases at once; a start whose data capture fails leavesstartingset; a delay grown while reconnecting never shrinks back.src/ffi/output_delay.rs):#[repr(C)]encoder_packet,encoder_packet_time,delay_dataandobs_output_delay_fields, with layout tests.struct obs_output: it goes throughobs_output_delay_fields()andobs_output_delay_signal()(libobs: Read the output delay fields through a hidden accessor #1550). Each field is read and written where the C does; theos_atomic_*fields are sequentially consistent atomics of their C size (bool, andlongpicked bysize_of::<c_long>(), no hostcfg).delay_datastays the Cstruct dequeofstruct delay_datathatobs-output.cfrees. It is pushed, peeked and popped in place withobs_util::ffi::deque(obs-util: Add a Rust equivalent of util/deque.h #1561).obs_encoder_packet_create_instanceis hidden in libobs, butlibobs-with-rustlinks the Rust staticlib with the same objects, so the call resolves there as libobs: Port the Wayland hotkey key state to obs-hotkey #1516'sobs_hotkeys_mutex_lockdoes.delay_mutexis locked with libobs'spthread_mutex_lockon the opaque pointer (glibc, libSystem, w32-pthreads).os_gettime_ns()once, as the C does, and calls an*_atfunction with that time. The*_atfunctions are Rust-mangled (hidden by_ZN*) and are what the parity test drives with a test clock.rust-hidden.txt,rust-exports.mapandrust-unexports-macos.txt; the three exported ones are inrust-exports.d/obs-output-output_delay.txt. In bothlibobs.sobuildsnmshows the three asTand the four ast.obs-output-delay.c.hleaveslibobs.core-outputfor its own group,libobs.ported-output-delay, listed inLIBOBS_PORTED_SOURCES. The group is not host-specific, sosources.cmake,os-*.cmake, obs-build andported_sources.pyneed no change.libobs-ported-output-delay.pch.h, isobs-internal.halone: since libobs: Read the output delay fields through a hidden accessor #1550 the file needs nothing else, so the oracle andtest_output_delaycompile it without the core. The comment intests.d/test_output_delay.cmakethat named the old PCH is updated; the test and its sources are unchanged.oracle/output_delay.c): renames the seven functions with#defines, renamesos_gettime_nsto a clock the test sets (astest_output_delaydoes), and includes the original file. Everything else it calls keeps its libobs name and is defined by the test. It also exports the layouts and values, and apthread_mutex_tfor the test outputs with a held check (the C test'smutex_held()).obs_output_set_delayuses__FUNCTION__, which-Wpedanticrejects, so the include is wrapped in aGCC diagnosticpush/ignore/pop; the file is compiled unmodified.delay_callbackaborts where the C calls through a null pointer (libobs sets it before installing the delay).test_output_delay(20 cases) compiles the C file into itself and is unchanged. It passes in every lane but cannot see the swap, so Tier 3 is the proof of the swap, as the issue planned. No existing C test drives a delayed output through real libobs (none callsobs_output_set_delay), so there is no end-to-end test of the swap either; see the deliberate break below.RED → GREEN
8d60c765flibobs: Add Tier 1 tests for the output delay port. The core istodo!().soldr cargo test -p obs-data --test obs-tests-core output::fails 35 of 35 with "not yet implemented".tests/output/delay.rs) mirrorstest_output_delay1:1: the same twenty names and assertions, in order, on a model output that records the libobs calls and whether the lock was held, as the C test's stubs do.u32::MAXs, one lock per push and per pass and none in cleanup or the setters, an empty queue, a start or stop at the front while preserving, the capture flag not read when inactive, a failed capture releasing packets queued before it, restart references, a stop on an empty queue, and an entry the file never queues.obs-tests-core. No new test binary:ci/test_binary_cap.pypasses (8 of 8).66da956a3libobs: Port the output stream delay to obs-output.output::passes 40/40 (35 Tier 1, 5 Tier 2/3), and the wholeobs-tests-corebinary passes 280/280.tests/output/delay_parity.rs). Both sides run on a test output through the same stand-ins: the two accessors, the fiveobs-output.ccalls, the packet copy and release (tracked, so a delivered packet can be told from the encoder's), and the delay callback. Each records its call, with whetherdelay_mutexwas held.struct dequeand the Clong, and the eleven values the file uses (Tier 2 layout);info.flags, the stub results, the running delay, the restart count and the clock (forward, backward, wrapping). After every step it compares the return value, the recorded calls, the log line, the packet copies made and released, every delay field, the deque's size, positions and capacity, and every queued entry field by field.oracle_obs_output_set_delaythrough__FUNCTION__.os_gettime_ns()readings.elapsed > active_delay_nsto>=, then restored it. Nine more mutants of the core and shim (one pass per packet, the capture flag not checked, a forced stop, refs not cleared or not counted,startingkept on encoder failure, any flag preserving, the timing dropped, the warning text) were each killed by the two parity runs.packets_held_then_released_in_order,zero_delay_still_waits_for_the_next_packet,pop_decision_is_strict_and_wrapping, ...) and both parity runs (parity_fixed_sequences,parity_random_sequences).libobs-with-rustrebuilt: none of the 34 output, delay, encoder, mux and interleave cmocka tests failed in mode ON (34/34 passed with the mutant linked intolibobs-with-rust), because none of them sets a delay;test_output_delaycompiles the C itself and cannot see the swap. So the swap ofprocess_delayand the start/stop path is proven by Tier 3 only, as the issue planned. A real-libobs test of a delayed output would be a follow-up.output::(Tier 1 and 3, the 1024-case proptest included) passes 40/40 under AddressSanitizer (nightly-Zsanitizer=addresson the Rust side; the C oracle is uninstrumented but allocates through the ASan allocator), with no reports.ENABLE_RUST_LIBOBS=OFFandON). Each tree runs the full cmocka suite againstlibobs(OFF) and againstlibobs-with-rust(ON):ENABLE_RUST_LIBOBS=OFF)ENABLE_RUST_LIBOBS=ON)test_output_delayandtest_async_delay_audiopass in all four runs.libobs.ported-output-delay+.h.cis linked intolibobsand not intolibobs-with-rust.ci/local_gate.py:--lane lint(clang-format, gersemi, rustfmt, clippy-D warnings, Dylints, ifdef ratchet, test-binary cap): passed.--lane cross(clippy and Dylints forx86_64-pc-windows-msvcandaarch64-apple-darwin, plus a link of every test binary, the oracle included): passed.--lane cross-release: passed.--lane rust-test(soldr cargo test --workspace --locked, plus a--no-runlink forx86_64-pc-windows-gnu): passed (obs-tests-core280/280, the obs-util harness 706/706 includingexport_list).ci/test_build_groups.py,ci/test_naming.py,ci/test_ported_sources.py,ci/test_rust_scope.py,ci/test_binary_cap.py,ci/test_cmocka_includes.py: OK.Checklist
master(or the description starts with a Stacked: note)test_output_delaylanded in test: Characterize the output stream delay #1547)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): not applicable (the oracle's-Wpedanticpragma covers one include in one test-only file)