Skip to content

libobs: Port the output protocol-list match to obs-output - #1848

Merged
zackees merged 4 commits into
obs-rust:masterfrom
rdoupe:port/output-protocols
Oct 23, 2026
Merged

zackees merged 4 commits into
obs-rust:masterfrom
rdoupe:port/output-protocols

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

Fixes #1829 (PR 3 of the plan; #1831 moved the match into libobs/obs-output-protocols.c.h as the hidden obs_output_protocol_list_count() and added test_output_protocols and test_output_protocol_list_steps; #1828 made the public lookups return false for a NULL protocol and added test_output_protocol_null)

What and why

This PR ports libobs/obs-output-protocols.c.h, the output protocol-list match, to a new protocols module of rust/obs-output (#444, phase 6). The match decides which output types can stream a protocol. obs_enum_output_types_with_protocol() calls its callback once for each segment of a service output's ;-separated protocols string that equals the protocol, and the frontend picks the stream output from that (GetStreamOutputType(), the auto-configuration wizard, the codec check in Settings).

The registered check, the output_types loop, the OBS_OUTPUT_SERVICE check and the callback stay C in obs-output.c.h. obs_is_output_protocol_registered(), obs_enum_output_protocols() and the registration splitter are not touched. The hybrid libobs drops the C file and links the Rust shim in its place.

  • Safe core (src/protocols.rs): count_matches(list: &[u8], protocol: &[u8]) -> usize, as the issue sketched.
    • It works on the bytes of the two C strings before their NULs and compares them as bytes, never as str. Both inputs are untrusted: the lists come from output plugins, and the protocol from the stream service (services.json, or derived from a custom server URL).
    • Whole segments, case-sensitive, nothing trimmed: "RTMP" does not match "RTMPS", "rtmp" or " RTMP".
    • An empty list has no segment, and the segment after a trailing ; is not scanned, because the C reaches the NUL there and stops.
    • It keeps no state and denies clippy's arithmetic_side_effects, indexing_slicing, unwrap_used, expect_used, panic, todo, unimplemented and unreachable. No host cfg, no unsafe.
  • Shim (src/ffi/output_protocols.rs): obs_output_protocol_list_count, with the C signature.
    • It reads each string once, to its NUL, as the C's strlen() and strchr() do, and calls the core.
    • The module is named after the C file, like the crate's other shims (output_caption_text.rs, ...). The issue said src/ffi/protocols.rs.
  • C side:
    • obs-output-protocols.c.h leaves libobs.core-output for its own group, libobs.ported-output-protocols, listed in source-sets.json (LIBOBS_PORTED_SOURCES). Its PCH, libobs-ported-output-protocols.pch.h, is string.h and obs-internal.h. The only change to the file is that include and its header comment.
    • test_output_protocol_list_steps still compiles it into itself, unchanged.
    • ci/test_ported_sources.py checks the group on Linux, Windows and macOS.
  • Symbols: the function is declared in obs-internal.h without EXPORT, so the shim is hidden like obs_output_caption_text_page: rust-hidden.txt, the local: list of rust-exports.map, and rust-unexports-macos.txt. No rust-exports.d fragment. nm shows it as local (t) in all three libraries. The exported symbol sets are unchanged (1766).
  • Oracle (oracle/output_protocols.c): the original file, unmodified, with the function renamed to oracle_obs_output_protocol_list_count.
  • NULL inputs:
  • Intentional differences (listed in the parity test header, src/ffi/output_protocols.rs and the rust/README.md row):
  • Docs: the rust/README.md rows, the docs/rust-port/naming.md row and the crate's Cargo description. No docs/features.md line: there is no user-visible change.

test_output_protocols (7 cases) and test_output_protocol_null (4 cases) link OBS::libobs and use the public API only. In the hybrid libobs they run the Rust shim and core through obs_enum_output_types_with_protocol(), so they are the end-to-end proof on every OS.

There is no _rust variant of test_output_protocol_list_steps linking libobs_rust-static. I tried one. It does not link on Linux: the shim's archive member also holds the rest of obs-output (the delay, the interleaver and the caption text). That code needs libobs's hidden output and encoder seams (obs_output_delay_fields(), obs_output_interleave_fields(), ...) and obs-util, and the link stopped at libuuid (uuid_generate). The header of test_output_protocol_list_steps.cmake says so, as test_context_name_helpers.cmake does. So Tier 3 is the direct comparison on every OS.

RED → GREEN

  • RED commit: 133a3f5e1 libobs: Add Tier 1 tests for the output protocol-list match port. The core is todo!(). soldr cargo test -p obs-data --test obs-tests-core output::protocols:: fails 21 of 21 with "not yet implemented".
    • Tier 1 (tests/output/protocols.rs) ports test_output_protocol_list_steps 1:1: its 9 cases under the same names, in the same order, with the same assertions, the model and the exhaustive check over 131,200 pairs included. The C's NULL list has no slice. It is the shim's, and Tier 3 checks it against the C.
    • 12 new edge cases:
      • other separators and whitespace are segment bytes;
      • the match at the start, middle and end of a list;
      • one-byte segments;
      • a protocol holding a ; never matches;
      • every byte value compares as itself;
      • runs of 0 to 63 separators;
      • a NUL inside the slice is a byte;
      • a long protocol against a short list;
      • four proptests: the core equals the model over weighted bytes (high bytes, non-UTF-8, any value); appending a segment adds 1 only if it is the protocol; a segment taken from the list matches at least once and never more often than there are segments; raw bytes of every value, up to 4000, never panic.
    • The tests are a module of the existing core category binary, obs-tests-core. No new test binary.
  • GREEN: 920d00676 libobs: Port the output protocol-list match to obs-output. output::protocols:: passes 21/21.
  • Tier 3: 1d62ccf15 libobs: Check the output protocol-list match port against the C (tests/output/protocols_parity.rs). The shim, called with C strings, and the safe core under it must give the C's count for every input.
    • Exhaustive: every list of up to 7 bytes over A, B, a and ; against every protocol of up to 3 bytes over the same alphabet, the empty one included: 21,845 × 85 = 1,856,825 pairs. libobs: Move the output protocol-list match into obs-output-protocols.c #1831's steps test has 131,200. The NULL list is also checked against each protocol.
    • Characterization: every pair test_output_protocol_list_steps asks for, with its expected count; its 100,000-segment list (also with a trailing ;) and its 1 MiB segment.
    • Bytes: every non-NUL byte value as a protocol against lists of it, its neighbours and separators. A string in a longer buffer is read to its first NUL on both sides.
    • Proptests (4000 cases each):
      • lists built around a protocol from segments that equal it, its prefixes and extensions, case variants, empty segments, arbitrary non-NUL bytes and high bytes (not UTF-8), with leading, doubled and trailing ;. Each is checked against the protocol, the protocol one byte longer, one byte shorter, lowercased, and the empty protocol;
      • raw non-NUL bytes of every value, up to 2000, with extra ;, against a segment of the list, a slice of it that may cross a ;, and random bytes.
    • Excluded: only the NULL protocol, checked on the Rust side (0, with or without a list).
    • output::protocols passes 30/30. soldr cargo test -p obs-data --test obs-tests-core passes 758/758.
  • Deliberate-break check (not committed): each mutant was applied, tested and restored. 13 of 13 mutants fail Tier 3 (3 to 7 of its 9 tests each). The 10 core mutants also fail Tier 1 (4 to 13 of 21 each).
    • core:
      • a prefix match;
      • a duplicate counted once;
      • a case-insensitive compare;
      • the first segment only;
      • the segment after a trailing ; scanned;
      • an empty list counted as one empty segment;
      • every trailing ; stripped;
      • empty segments skipped;
      • a segment's first byte ignored;
      • a segment's last byte ignored;
    • shim (Tier 3 only, as Tier 1 does not see the shim):
      • the protocol passed with its NUL;
      • the two arguments swapped;
      • the list read from its second byte.
    • Tier 2: with "a duplicate counted once" built into the hybrid libobs, test_output_protocols failed enum_order_and_duplicates and enum_early_stop (5/7) and passed 7/7 against libobs-c-reference. After the restore, 7/7 against both.
  • Local, two build trees: OBS_LIBOBS_BACKEND=C, and HYBRID with OBS_BUILD_C_REFERENCE=ON, both full builds. Full ctest -j4, headless (private Xvfb with -noreset, private D-Bus, fresh HOME):
Lane Library ctest Exported symbols
HYBRID, OBS_BUILD_C_REFERENCE=ON hybrid libobs 381/381 IDENTICAL (1766)
HYBRID, OBS_BUILD_C_REFERENCE=ON libobs-c-reference 381/381 IDENTICAL (1766)
OBS_LIBOBS_BACKEND=C libobs the three protocol tests IDENTICAL (1766)

Nothing was skipped or failed to run. One build target did not compile after the rebase, on master as well: test_mp4_split_time, which since #1805 includes librtmp's mbedtls/version.h without the mbedtls include directory, and this host keeps those headers outside the default path. This PR does not touch it; its ctest entry ran the binary built before the rebase. Before the rebase onto 582a4c3ed, the full suite also passed on both (379/379); one hybrid run first failed test_async_delay_audio once under -j4 load (an audio timing test that does not touch outputs). It passed 3 of 3 alone, and the full rerun passed.

test_output_protocol_list_steps 9/9, test_output_protocols 7/7 and test_output_protocol_null 4/4 pass against all three libraries. The ported group is compiled only into libobs-c-reference (and the C-backend libobs).

  • Also run:
    • uv run ci/local_gate.py --lane lint passed, and --lane cross passed.
    • ci/test_build_groups.py, ci/test_ported_sources.py, ci/test_naming.py, ci/test_binary_cap.py and ci/test_rust_scope.py pass. export_list (obs-util) passes 3/3.
    • clang-format 22.1.3, gersemi and rustfmt are clean on the changed files.
  • Real app (UI, protocol output or logging changes): not applicable (no behaviour change). test_output_protocols drives the hybrid libobs's lookup through the same public call the frontend uses.

Windows/macOS: not built there. The core and shim have no host conditional. test_output_protocols and test_output_protocol_list_steps are built on every OS, so on Windows and macOS the swap is covered by test_output_protocols against the hybrid libobs, by Tier 3 (the rust-tests job) and by the unchanged C tests (rust-tier2). PR CI covers those builds.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • 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 (N/A for docs-only; a focused CI fix may push RED and GREEN together) (the characterization merged in libobs: Move the output protocol-list match into obs-output-protocols.c #1831)
  • 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): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

RED for the port of libobs/obs-output-protocols.c.h to a new module,
protocols, of rust/obs-output. The safe core is a stub (todo!()):
count_matches(list, protocol), how many ';'-separated segments of a
service output's protocol list equal the protocol, over the bytes of the
two C strings before their NULs, and SEPARATOR.

tests/output/protocols.rs ports test_output_protocol_list_steps 1:1: its
9 cases under the same names, in the same order, with the same
assertions, the model and the exhaustive check over 131200 pairs
included. The C's NULL list has no slice; it is the shim's, and the
parity test checks it against the C. The "characterized, not endorsed"
cases (a duplicate counts twice; the empty protocol matches the empty
segments a ';' ends, not a trailing one) are kept as such.

Edge cases: other separators and whitespace are segment bytes; the
match at the start, middle and end of a list; one-byte segments; a
protocol holding a ';' never matches; every byte value compares as
itself; runs of 0 to 63 separators; a NUL inside the slice is a byte;
a long protocol against a short list. Four proptests: the core equals
the model over weighted bytes (high bytes, non-UTF-8, any value);
appending a segment adds 1 only if it is the protocol; a segment taken
from the list matches at least once and never more often than there are
segments; raw bytes of every value, up to 4000, panic nowhere.

The tests are a module of the existing core category binary,
obs-tests-core; no new test binary.

soldr cargo test -p obs-data --test obs-tests-core output::protocols
fails 21 of 21 with "not yet implemented".

Refs obs-rust#1829
Ports libobs/obs-output-protocols.c.h to the protocols module of
rust/obs-output: how many ';'-separated segments of a service output's
protocols string equal a protocol. obs_enum_output_types_with_protocol()
(still C) calls its callback that many times for each service output,
and the frontend picks the stream output for a protocol from it. The
registered check, the output_types loop, the OBS_OUTPUT_SERVICE check
and the callback stay C in obs-output.c.h; the hybrid libobs drops the C
file and links the Rust shim in its place.

Safe core (src/protocols.rs): count_matches() over the bytes of the two
C strings before their NULs, compared as bytes, never as str: whole
segments, case-sensitive, nothing trimmed. An empty list has no segment,
and the segment after a trailing ';' is not scanned (the C reaches the
NUL there), so the empty protocol matches only the empty segments a ';'
ends. Both inputs are untrusted (output plugins, the stream service),
so the module denies clippy's indexing, arithmetic, unwrap, expect,
panic, todo, unimplemented and unreachable lints.

Shim (src/ffi/output_protocols.rs): obs_output_protocol_list_count with
the C signature reads each string to its NUL, as the C's strlen() and
strchr() do, and calls the core. A NULL list counts 0, as in C.
Intentional difference: a NULL protocol counts 0, where the C's strlen()
crashes; libobs never passes one, because the caller returns for a NULL
protocol before the match (obs-rust#1828).

Kept, characterized, not endorsed (obs-rust#1831): a protocol listed twice
counts twice, so the callback gets the same output twice; the empty
protocol's count, which libobs never asks for.

C side: the file leaves libobs.core-output for its own group,
libobs.ported-output-protocols (LIBOBS_PORTED_SOURCES), whose PCH is
string.h and obs-internal.h. The symbol is not EXPORT, so the shim is
hidden: rust-hidden.txt, the local: list of rust-exports.map and
rust-unexports-macos.txt. The exported symbol sets are unchanged (1766).
test_output_protocol_list_steps still compiles the C file into itself,
unchanged; test_output_protocols and test_output_protocol_null see the
swap through the public API. ci/test_ported_sources.py checks the group
on every host.

No test_output_protocol_list_steps_rust: the shim's member of
libobs_rust-static also holds the rest of obs-output (the delay, the
interleaver and the caption text), which needs libobs's hidden output and
encoder seams and obs-util (libuuid), so the variant does not link on its
own. The header of its .cmake says so; the Tier 3 parity tests compare
the shim with the C instead.

Refs obs-rust#1829
Oracle (oracle/output_protocols.c): the original obs-output-protocols.c.h,
unmodified, with obs_output_protocol_list_count renamed to
oracle_obs_output_protocol_list_count.

Tier 3 (tests/output/protocols_parity.rs): the shim, with C strings, and
the safe core under it must give the C's count for every input:
- every list of up to 7 bytes over 'A', 'B', 'a' and ';' against every
  protocol of up to 3 bytes over the same, the empty one included:
  21845 x 85 = 1856825 pairs (the C characterization's exhaustive check
  has 131200), and the NULL list against each protocol;
- every pair of test_output_protocol_list_steps with its expected count,
  its 100000-segment list (also with a trailing ';') and its 1 MiB
  segment;
- every non-NUL byte value as a protocol against lists of it, its
  neighbours and separators;
- a string read to its first NUL in a longer buffer, on both sides;
- proptests (4000 cases each): lists built around a protocol from
  segments that equal it, its prefixes and extensions, case variants,
  empty segments, arbitrary non-NUL bytes and high bytes (not UTF-8),
  with leading, doubled and trailing ';', against the protocol, one byte
  longer, one byte shorter, lowercased and empty; and raw non-NUL bytes of
  every value up to 2000 with extra ';', against a segment of the list, a
  slice of it that may cross a ';', and random bytes.

Excluded, the intentional difference: a NULL protocol, which the C's
strlen() crashes on and the shim counts 0, with or without a list
(checked on the Rust side).

Mutation check (done once, not committed): 13 of 13 mutants fail the
parity tests: a prefix match; a duplicate counted once; a
case-insensitive compare; the first segment only; the segment after a
trailing ';' scanned; an empty list counted as one empty segment; every
trailing ';' stripped; empty segments skipped; a segment's first byte, or
its last, ignored; and, in the shim, the protocol passed with its NUL,
the two arguments swapped, and the list read from its second byte. The
10 core mutants also fail Tier 1.

Refs obs-rust#1829
The rust/README.md rows for rust/obs-output (crate table and port table),
the naming.md row and the crate description now include
libobs/obs-output-protocols.c.h. The port row lists what stays C, the
seam, what the characterization pins and the port keeps, the intentional
difference (a NULL protocol counting 0) and what Tier 2 and Tier 3
compare.

Fixes obs-rust#1829
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.

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

2 participants