Skip to content

rust: Port the output protocol-list match in obs-output.c to obs-output #1829

Closed

Description

@rdoupe

Port the protocol-list match of libobs/obs-output.c.h to rust/obs-output as a new module, protocols. It decides which output types can stream a given protocol: obs_enum_output_types_with_protocol() walks the registered service outputs and calls the callback for each one whose ;-separated protocols string holds the protocol. The frontend uses it to pick the stream output for a third-party protocol (GetStreamOutputType(), the auto-configuration wizard) and to check codec support in Settings. If it is wrong, a stream picks the wrong output type or none, so OBS fails to go live or uses an output that cannot speak the protocol.

The unit, about 15 lines: the ;-split loop inside obs_enum_output_types_with_protocol() (master obs-output.c.h 2762-2783, the inner loop 2771-2781). Each segment is compared whole and byte for byte (strlen/strncmp), so "RTMP" does not match "RTMPS" or "rtmp". A protocol listed twice in one output's string calls the callback twice for that output.

These stay C: the output_types loop, the OBS_OUTPUT_SERVICE check and the callback calls; obs_is_output_protocol_registered() and obs_enum_output_protocols() (obs.c.h); and the registration splitter in obs_register_output_s() (obs-module.c.h, strlist_split), which is in another file and group.

Phase and position

Phase 6 (#444), libobs core through opaque seams. It joins rust/obs-output, which holds the delay, interleave and caption text ports. It is part of a large file, so it goes in through function extraction (testing-policy.md, "Extracting a function before porting it"), as the caption text did (#1618, #1620). It is in the core-output+ unity group, which has no other move or port open. Its Rust tests join the crate's existing test binary.

Dependencies and existing tests

  • No dependency on libobs internals. The seam is size_t obs_output_protocol_list_count(const char *protocols, const char *protocol): how many segments of the list equal the protocol (0 for a NULL list). C calls the callback that many times for the output and stops on false. That gives the same calls in the same order as today, because all matches for one output are consecutive.
  • Today no test calls these lookups. PR 1 adds two (below).
  • Input: the protocol comes from the stream service (services.json, or derived from a custom server URL by rtmp-custom), and the lists come from output plugins. Both are untrusted bytes: any byte but NUL, not necessarily UTF-8. The port compares bytes, never str, and must not panic.

Plan

  1. Characterization and extraction PR (behaviour-neutral, two commits):
    • test_output_protocols (real libobs, public API only, so it also runs the hybrid libobs). It registers service outputs with "RTMP;RTMP", "RTMP;RTMPS", "SRT", ";RTMP;;", "RTMPX", "rtmp", "HLS;", "WHIP; RIST" and "", plus a plain output with a list. It pins the registered protocols and their order, the registered check, the enumerate order, duplicates (two calls), the early stop (also between two matches of one output), whole names and case, unregistered protocols, and obs_output_get_protocols() / obs_get_output_flags().
    • The move: the loop goes into libobs/obs-output-protocols.c.h as the hidden entry point obs_output_protocol_list_count() (declared in obs-internal.h without EXPORT). The file joins libobs.core-output just before obs-output.c.h, with libobs.pch.h.
    • test_output_protocol_list_steps, which compiles the moved file (no libobs core) and calls only the entry point: NULL and empty lists, whole segments, case, spaces, duplicates, empty and trailing segments, the empty protocol, high bytes, a 100000-segment list and a 1 MiB segment, and an exhaustive check over short lists against a model.
  2. NULL fix (separate PR, from master): obs_is_output_protocol_registered(NULL) and obs_enum_output_types_with_protocol(NULL, ...) crash in strcmp() today. That fix is in obs.c.h and does not touch the moved file, so the two PRs do not depend on each other. Once both are in, the characterization can add the NULL cases.
  3. Port PR (RED, then GREEN):
    • obs_output::protocols, a safe core fn count_matches(list: &[u8], protocol: &[u8]) -> usize, and src/ffi/protocols.rs for the entry point (a NULL list gives 0). The C file moves to a ported group, libobs.ported-output-protocols, with its .pch.h, source-sets.json entry and export fragments (hidden, as obs_output_caption_text_page is); ci/test_ported_sources.py gets the object.
    • Tests:
      • Tier 1 ports every test_output_protocol_list_steps expectation 1:1.
      • Tier 3 checks parity against the moved C through obs-c-oracle (oracle/output_protocols.c): a proptest over byte strings made of ;, empty segments, prefixes, case variants and arbitrary non-NUL bytes, and protocols taken from the list, near it, or random.
      • Tier 2: test_output_protocol_list_steps_rust, the unchanged .c linked against libobs_rust-static, if it links on its own (as test_scene_bounds_place_rust does); otherwise the header of its .cmake says why, as for test_context_name_helpers. test_output_protocols runs the hybrid libobs unchanged.
      • Tier 4 does not apply (no protocol or UI change).
    • Docs: the rust/README.md rows, and the docs/rust-port/naming.md row for rust/obs-output (add obs-output-protocols.c.h).

For the reviewer to decide

  • Seam shape. A count, not a callback across the boundary: the Rust core stays pure, and C keeps the output table and the callback. The equivalence holds because the matches of one output are consecutive calls with the same id. The alternative, passing the callback into Rust, buys nothing.
  • Behaviours the characterization pins, not endorses (none is changed by the move or the port):
    • An output that lists a protocol twice is enumerated twice.
    • Nothing is trimmed or case-folded: "WHIP; RIST" registers " RIST", not "RIST".
    • The empty protocol matches the empty segments that a ; ends, but not a trailing one. libobs never asks for it, because "" is never a registered protocol.

Activity

  1. rdoupe commented on Oct 22, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: #1829

    1. Characterization and move PR (next, ready): the protocol-list match moved into libobs/obs-output-protocols.c.h as a hidden count, with test_output_protocols (real libobs, 7 cases) and test_output_protocol_list_steps (9 cases, exhaustive pairs). No behaviour change.
    2. The NULL-protocol fix is separate, in libobs, frontend: Take a NULL protocol in the output protocol lookups #1828.
    3. Port to rust/obs-output (module protocols) with oracle parity.
  2. added
    claimed
    on Oct 22, 2026
  3. rdoupe commented on Oct 22, 2026

    @rdoupe
    CollaboratorAuthor

    Port is up in #1848. The only intentional difference from C: a NULL protocol counts 0 where C's strlen() would crash. libobs never passes one, since #1828 returns before the match. The behaviours pinned in #1831 are kept: a duplicate counts twice, and the empty protocol matches only the empty segments a ; ends.

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