Repository navigation
libobs: Read the output delay fields through a hidden accessor - #1550
Merged
Merged
Conversation
Behavior-neutral seam before the Rust port of obs-output-delay.c: the port should not mirror the private, platform-sized struct obs_output. obs_output_delay_fields(), defined in obs-output.c and declared in obs-internal.h, returns one plain struct of pointers to the delay fields of an output (delay_mutex, delay_data, active_delay_ns, delay_sec, delay_flags, delay_cur_flags, delay_restart_refs, delay_active, delay_capturing, delay_callback, starting, reconnecting) and to info.flags and context.name. obs_output_delay_signal() wraps the static inline do_output_signal(). Neither is EXPORT, so -fvisibility=hidden keeps them out of libobs, and the exported symbol set stays the same. obs-output-delay.c now reads and writes the output 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; the getters and obs_output_set_delay() still check the output first. test_output_delay compiles obs-output-delay.c without obs-output.c, so its harness gains output_delay_fields_stub.c, the same two functions over the test's struct obs_output. No test case changes. Refs obs-rust#1546
6 of 7 tasks
chriscoveries
pushed a commit
to chriscoveries/obsrust-fork
that referenced
this pull request
Oct 20, 2026
* libobs: Add Tier 1 tests for the output delay port 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: Port the output stream delay to obs-output 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
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.
Refs #1546 (step 2 of the plan: the accessor; the deque equivalent and the port follow)
What and why
obs-output-delay.c.hreads about 15 fields ofstruct obs_output, which is private and platform-sized. The Rust port should not mirror that struct, 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_delay_fields(), declared inobs-internal.hnext todo_output_signal()and the other delay functions, and defined inobs-output.c.h, returns one plainstruct obs_output_delay_fieldsof pointers into the output:delay_mutex,delay_data,active_delay_ns,delay_sec,delay_flags,delay_cur_flags,delay_restart_refs,delay_active,delay_capturing,delay_callback,starting,reconnecting, plusflags(info.flags) andname(context.name).obs_output_delay_signal()wraps the static-inlinedo_output_signal().EXPORT, so-fvisibility=hiddenkeeps them out oflibobs.so, as withobs_hotkeys_mutex_lockin libobs: Lock the hotkey mutex through a hidden accessor #1515. They are C, not Rust shims, sorust-hidden.txt,rust-exports.mapandrust-unexports-macos.txtneed no entries.obs-output-delay.c.hreads and writes the output only through these. Each public or hidden entry point fetches the struct once and passes it to the static helpers. The pointers alias the fields themselves, so every field is still read and written at the same point, under the same lock, with the same atomics. The getters andobs_output_set_delay()still check the output before anything else.Design notes, against the plan in #1546:
context.signalsis left out of the struct: its only use is the signal, andobs_output_delay_signal()covers it. That is one pointer fewer for the port.info.flagsandcontext.nameare pointers too, not copied values, so they are read when the old code read them.const obs_output_t *, so the two const getters can use it, and casts the const away in one place (throughuintptr_t, as-Wcast-qualrequires). The pointers it returns are not const, as the start and stop paths write through them.repr(C)struct on the Rust side.Tests:
test_output_delaycompilesobs-output-delay.c.hwithoutobs-output.c.h, so its harness getstest/cmocka/output_delay_fields_stub.c: the same two functions over the test'sstruct obs_output. That adds one source totests.d/test_output_delay.cmakeand a comment line there. No test case changes, andtest_output_delay.cis untouched.RED → GREEN
ENABLE_RUST_LIBOBS=OFFandON), headless (private Xvfb, private D-Bus, fresh HOME). Each runs the full cmocka suite againstlibobsand againstlibobs-with-rust:ENABLE_RUST_LIBOBS=OFF)ENABLE_RUST_LIBOBS=ON)No test was skipped or not run. The export lists are also identical across the two lanes.
obs_output_delay_fields/obs_output_delay_signalshow up in the static symbol table of all fourlibobs.sobuilds and in none of the dynamic export tables.test_output_delay: 20/20, three runs in each lane (againstlibobsin the C lane,libobs-with-rustin the Rust lane). Also 20/20 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; the Windows and macOS C link of the new hidden functions is left to PR CI.Checklist
mastertest_output_delaymerged in test: Characterize the output stream delay #1547; no RED here (behaviour-neutral seam)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): not applicable