Skip to content

rust: Port obs-output-delay.c to obs-output #1546

Closed

Description

@rdoupe

Unit

Port libobs/obs-output-delay.c.h (211 lines), the stream delay, to a new crate rust/obs-output: obs_output_set_delay, obs_output_get_delay and obs_output_get_active_delay (exported), process_delay, obs_output_delay_start, obs_output_delay_stop and obs_output_cleanup_delay (hidden, declared in obs-internal.h), and the file's static push_packet, pop_packet and process_delay_data.

The file reads about 15 struct obs_output fields: delay_mutex, delay_data (a struct deque of struct delay_data), active_delay_ns, delay_sec, delay_flags, delay_cur_flags, delay_restart_refs, delay_active, delay_capturing, delay_callback, starting, reconnecting, info.flags, context.name and context.signals. It calls obs_output_actual_start / _actual_stop (hidden), obs_output_can_begin_data_capture, obs_output_initialize_encoders, obs_output_begin_data_capture, obs_encoder_packet_create_instance (hidden) / _release, and the starting / stopping signals.

Phase and position

Phase 6 (#444), libobs core through opaque seams. The file is already its own translation unit in libobs/build/libobs.core-output+.h.c, so no function extraction is needed. naming.md has no row for libobs/obs-output*; this adds libobs/obs-output-delay.c.h → rust/obs-output, a crate named after the component, so later obs-output.c units can join it. Its tests are a module of the existing core category binary, obs-tests-core; no new test binary.

Dependencies and existing tests

  • No cmocka test covers the delay. test_output_delay (PR 1) is the characterization. process_delay and the start, stop and cleanup functions are not exported, so it compiles the file into itself with a zeroed struct obs_output, stubs for the obs-output.c calls and a test clock. It characterizes the C source only (like test_wayland_hotkeys for rust: Port obs-nix-hotkey-state.c to obs-hotkey #1514), so Tier 3 is the proof of the swap.
  • struct obs_output is private and platform-sized, and Rust should not mirror it. The C users of the delay fields in obs-output.c.h stay C.
  • delay_data is a C struct deque that obs-output.c frees in destroy. The Rust side keeps it and needs a Rust equivalent of the header-inline util/deque.h (push back, peek front, pop front, with the C growth rule and bmalloc memory), with a layout test and parity against oracle wrappers of the inline functions, as darray has.
  • Layout contracts: struct delay_data (obs-internal.h), struct encoder_packet and struct encoder_packet_time (obs-encoder.h), struct deque.
  • process_delay is installed as the encoder callback, and the encoder later removes it by comparing the function pointer, so the Rust symbol must replace the C one exactly (it does under libobs-with-rust, since obs-output.c names the symbol).

Plan

  1. Characterization PR: test/cmocka/test_output_delay.c (20 cases), no change to libobs. It covers set/get delay, packets held for the delay and released oldest first, the start, stop and restart paths, cleanup, and preserve on disconnect.
  2. Accessor PR (behaviour-neutral, like libobs: Lock the hotkey mutex through a hidden accessor #1515): a hidden obs_output_delay_fields() in obs-output.c.h, declared in obs-internal.h. It returns pointers to the delay fields, plus info.flags, context.name and context.signals, in one plain struct. obs-output-delay.c.h reads through it, and a hidden obs_output_delay_signal() wraps the static-inline do_output_signal. test_output_delay gets a one-line stub source in its tests.d fragment for the accessor, as test_wayland_multiseat got hotkey_mutex_stub.c. No test case changes.
  3. util/deque.h Rust equivalent in obs-util (header-inline unit: layout test, Tier 1, Tier 3 against oracle wrappers). It can go before or alongside 2.
  4. Port PR: rust/obs-output.
    • Safe core:
      • the pop decision as a pure function of the front entry's time, now, active_delay_ns, preserve and reconnecting (hold, pop, or extend the delay to the front's age), with the strict > and the wrapping subtraction;
      • the dispatch of a popped entry (deliver, release, actual start, actual stop with the entry's time);
      • the whole-seconds getter;
      • start, stop and cleanup, generic over an output trait (lock, queue, flags, C calls), as libobs: Port the Wayland hotkey key state to obs-hotkey #1516 is generic over its lock and store.
    • Shim: the seven symbols and the repr(C) types.
    • Tests: Tier 1 ports every test_output_delay assertion 1:1, plus edge cases. Layout tests. Tier 3 parity of the C file (oracle) against the shim through the same accessor stubs and recorded calls, with a proptest over random packet, start, stop, flag and clock sequences. The C file moves to a ported group. Tier 2 OFF/ON unchanged.

No intended behaviour changes.

Activity

  1. rdoupe commented on Oct 20, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: #1546

    1. Characterization PR: test_output_delay (20 cases), no change to libobs. Opening it now.
    2. Accessor PR, behaviour-neutral (hidden obs_output_delay_fields() / obs_output_delay_signal()), after 1 merges.
    3. A util/deque.h equivalent in obs-util.
    4. The port to rust/obs-output, as its own PR.
  2. added
    claimed
    on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    claimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions