Skip to content

libobs: Read the output delay fields through a hidden accessor - #1550

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

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

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 20, 2026

Copy link
Copy Markdown
Collaborator

Refs #1546 (step 2 of the plan: the accessor; the deque equivalent and the port follow)

What and why

obs-output-delay.c.h reads about 15 fields of struct 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 in obs-internal.h next to do_output_signal() and the other delay functions, and defined in obs-output.c.h, returns one plain struct obs_output_delay_fields of 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, plus flags (info.flags) and name (context.name).
  • obs_output_delay_signal() wraps the static-inline do_output_signal().
  • Neither is EXPORT, so -fvisibility=hidden keeps them out of libobs.so, as with obs_hotkeys_mutex_lock in libobs: Lock the hotkey mutex through a hidden accessor #1515. They are C, not Rust shims, so rust-hidden.txt, rust-exports.map and rust-unexports-macos.txt need no entries.
  • obs-output-delay.c.h reads 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 and obs_output_set_delay() still check the output before anything else.

Design notes, against the plan in #1546:

  • context.signals is left out of the struct: its only use is the signal, and obs_output_delay_signal() covers it. That is one pointer fewer for the port.
  • info.flags and context.name are pointers too, not copied values, so they are read when the old code read them.
  • The accessor takes a const obs_output_t *, so the two const getters can use it, and casts the const away in one place (through uintptr_t, as -Wcast-qual requires). The pointers it returns are not const, as the start and stop paths write through them.
  • One struct rather than per-field accessors: one call per entry point, and one repr(C) struct on the Rust side.

Tests: test_output_delay compiles obs-output-delay.c.h without obs-output.c.h, so its harness gets test/cmocka/output_delay_fields_stub.c: the same two functions over the test's struct obs_output. That adds one source to tests.d/test_output_delay.cmake and a comment line there. No test case changes, and test_output_delay.c is untouched.

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) 334/334 334/334 IDENTICAL (1766)
Rust (ENABLE_RUST_LIBOBS=ON) 334/334 334/334 IDENTICAL (1766)

No test was skipped or not run. The export lists are also identical across the two lanes. obs_output_delay_fields / obs_output_delay_signal show up in the static symbol table of all four libobs.so builds and in none of the dynamic export tables.

  • test_output_delay: 20/20, three runs in each lane (against libobs in the C lane, libobs-with-rust in 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.
  • 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_delay merged in test: Characterize the output stream delay #1547; 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-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
@rdoupe
rdoupe requested a review from zackees as a code owner October 20, 2026 19:44
@zackees
zackees added this pull request to the merge queue Oct 20, 2026
Merged via the queue into obs-rust:master with commit 47ea17e Oct 20, 2026
23 checks passed
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
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