Skip to content

libobs: Move the output protocol-list match into obs-output-protocols.c - #1831

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:refactor/output-protocol-match-move
Oct 22, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:refactor/output-protocol-match-move

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 22, 2026

Copy link
Copy Markdown
Collaborator

Refs #1829 (PR 1 of the plan: the characterization and the extraction. The port follows.)

What and why

This is a behaviour-neutral extraction before the Rust port, as the testing policy asks for part of a large file. The ;-split match inside obs_enum_output_types_with_protocol() moves from libobs/obs-output.c.h into libobs/obs-output-protocols.c.h. It decides which service outputs can stream a protocol, and the frontend picks the stream output from it. The move comes with characterization tests, because no test called these lookups. There is no Rust, no behaviour change and no public header change.

  • What moves: the loop over one output's protocols string becomes size_t obs_output_protocol_list_count(const char *protocols, const char *protocol). The loop is verbatim. Where it called enum_cb on a matching segment, it now counts the match, and the strlen() of the protocol moves in with it. A NULL list counts 0, as the while (substr && ...) did.
  • What stays: obs_enum_output_types_with_protocol() keeps the registered check, the output_types loop, the OBS_OUTPUT_SERVICE check and enum_cb. For each service output it calls enum_cb as many times as the count, and returns when enum_cb returns false. That gives the same calls in the same order: all matches of one output are consecutive calls with its id, and the early stop between them still stops at once. obs_is_output_protocol_registered(), obs_enum_output_protocols() (obs.c.h) and the registration splitter (obs-module.c.h) are not touched.
  • Hidden entry point: declared in obs-internal.h without EXPORT, so -fvisibility=hidden keeps it local (a t symbol in libobs.so, in all three libraries).
  • Build: the new file joins the existing libobs.core-output group just before obs-output.c.h, with libobs.pch.h. The group, the PCH, source-sets.json and the CMake source lists are unchanged. The moved code has no platform conditional.
  • Exported symbols: unchanged, 1766 in libobs with the C backend, in the hybrid libobs and in libobs-c-reference.

test_output_protocols (its own commit before the move, on the unchanged C) links the real libobs and uses the public API only, so it also runs the hybrid libobs. obs_startup() loads no modules there, so its outputs are the only ones registered. It registers nine service outputs with "RTMP;RTMP", "RTMP;RTMPS", "SRT", ";RTMP;;", "RTMPX", "rtmp", "HLS;", "WHIP; RIST" and "", and one plain output with "RTMP;PLAINONLY". On Linux it runs under xvfb-run with -noreset; it skips without a display. 7 cases:

  • the registered protocols (obs_enum_output_protocols()): each non-empty segment once, in registration order, case and spaces kept: RTMP, RTMPS, SRT, RTMPX, rtmp, HLS, WHIP, " RIST". An index past the end returns false and leaves the out pointer alone;
  • obs_is_output_protocol_registered(): whole, case-sensitive names. "", "Rtmp", "RTM", "RTMP;RTMPS", ";", "HLS;", "RIST", "RTMP " and the plain output's "PLAINONLY" are not registered;
  • obs_enum_output_types_with_protocol(): one call per matching segment, in registration order. "RTMP" gives proto_dup twice, then proto_rtmp_rtmps, then proto_empty_segments, and not the plain output;
  • whole names: "RTMPX" gives only proto_prefix, and "rtmp" only proto_lower;
  • an unregistered protocol, the empty one, "Rtmp", "RIST", the plain output's protocol, "RTMP;RTMPS" and ";" enumerate nothing;
  • the early stop: enum_cb returning false after 1, 2, 3 or 4 calls stops there, also between the two matches of proto_dup;
  • obs_get_output_flags() and obs_output_get_protocols() on an instance: the registered flags and string as they are, NULL for the plain output, 0 flags for an unknown id.

test_output_protocol_list_steps (new, with the move) compiles the moved file (ASan and UBSan, no libobs core) and calls only the entry point, so the port can run the same file against the Rust staticlib. It is in the obs-build C test manifest. 9 cases:

  • a NULL and an empty list;
  • whole segments: no prefix match either way, and the separator is not part of a segment;
  • case and spaces: nothing is case-folded or trimmed;
  • duplicates: two and three copies;
  • empty and trailing segments (";RTMP;;", "HLS;", ";HLS", ";;;");
  • the empty protocol;
  • bytes: \xff, bytes that are not UTF-8, precomposed and decomposed é, control bytes and DEL, % sequences;
  • a list of 100000 segments and a 1 MiB segment;
  • every list of up to 7 bytes over A, B and ; against every protocol of up to 3 bytes over the same, the empty one included (131200 pairs), against a model in the test.

Characterized, not endorsed (a comment in the tests, and in the issue). None is changed here:

  • 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 each empty segment that a ; ends, but not a trailing one. libobs never asks for it, because "" is never a registered protocol.
  • Not driven by the tests: a NULL protocol crashes in strcmp() in obs_is_output_protocol_registered(), before the match. That is fixed separately (libobs, frontend: Take a NULL protocol in the output protocol lookups #1828); this PR does not depend on it.

RED → GREEN

  • RED commit: none. This is a move plus characterization, which passes on the moved code and on master. The characterization is its own commit, 78046f858 test: Characterize the output protocol lookups, and test_output_protocols passes 7/7 there on the unchanged C against all three libraries. The move is f764f5dd1 libobs: Move the output protocol-list match into obs-output-protocols.c.
  • GREEN: test_output_protocols 7/7 and test_output_protocol_list_steps 9/9 against libobs with the C backend, the hybrid libobs and libobs-c-reference.
  • Equivalence of the move: a scratch differential program compiled master's obs_enum_output_types_with_protocol() verbatim against the moved function and the new caller (both taken from the files), over 2,000,000 random cases: up to 7 outputs, service or not, with NULL lists or lists built from atoms (RTMP, RTMPS, rtmp, RTMPX, " RIST", \xff, empty, ;, ;;, random bytes), registered and unregistered protocols, and a random early stop. It compared the callback ids in order (413,634 calls), and the count per list against master's loop for the protocol and for "": 0 differences.
  • Mutation check: 7 mutants of obs-output-protocols.c.h, each built into libobs (C backend) and the steps test, and 2 of the caller:
Mutant test_output_protocol_list_steps test_output_protocols differential
prefix match (<=, compare protocol_len) 7 of 9 fail 2 of 7 fail 644086 differ
a duplicate counts once 4 2 174178
case-insensitive (strncasecmp) 2 2 11317
first segment only 8 2 265105
the empty segment after a trailing ; scanned 3 0 (see below) 559587
segment length one too long 8 2 324045
last segment one byte short 8 3 72813
caller ignores the early stop 1
caller calls once per output 2

The trailing-segment mutant changes only the count for the empty protocol, which libobs never asks for, so through the public API it is equivalent; the steps test catches it.

  • 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 377/377 IDENTICAL (1766)
HYBRID, OBS_BUILD_C_REFERENCE=ON libobs-c-reference 377/377 IDENTICAL (1766)
OBS_LIBOBS_BACKEND=C libobs 375/375 IDENTICAL (1766)

Nothing failed, was skipped or failed to run. After rebasing onto 1751566 (#1820, #1821), the full suite was repeated on the hybrid libobs and libobs-c-reference (377/377 each). After the final rebases onto 233db44 (#1823-#1826; #1825 also edits the obs-build C test manifest next to this entry), libobs and the tests were rebuilt, and the two tests, the symbol comparison, ci/test_build_groups.py and ci/test_ported_sources.py were repeated.

  • 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_cmocka_includes.py and ci/test_naming.py pass. clang-format and gersemi are clean on the changed files.
  • Real app (UI, protocol output or logging changes): not applicable (no behaviour change).

Windows/macOS: not built there. The moved code has no host conditional. test_output_protocol_list_steps is portable C (no cmocka range assertions, no fail_msg()). test_output_protocols is registered on every platform like test_context_names (no fork, no X11 calls of its own); it has run on Linux only.

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) (this is the extraction with its characterization; the port follows)
  • 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) (not applicable: no port here)

Characterization before the protocol-list match of obs-output.c (the
';'-split loop in obs_enum_output_types_with_protocol) moves to its own
file and is ported to obs-output. Nothing calls these lookups in the
tests today.

test_output_protocols links the real libobs and uses the public API
only, so it also runs the hybrid libobs. It registers ten outputs: nine
service outputs with the lists "RTMP;RTMP", "RTMP;RTMPS", "SRT",
";RTMP;;", "RTMPX", "rtmp", "HLS;", "WHIP; RIST" and "", and one plain
output with "RTMP;PLAINONLY". 7 cases pin:
- the registered protocols: each non-empty segment once, in
  registration order, case and spaces kept (RTMP, RTMPS, SRT, RTMPX,
  rtmp, HLS, WHIP, " RIST"); an index past the end returns false and
  leaves the out pointer alone;
- obs_is_output_protocol_registered(): whole, case-sensitive names; "",
  "Rtmp", "RTM", "RTMP;RTMPS", ";", "HLS;", "RIST" and a plain output's
  protocol are not registered;
- obs_enum_output_types_with_protocol(): one call per matching segment,
  in registration order ("RTMP" gives proto_dup twice, then
  proto_rtmp_rtmps, then proto_empty_segments); "RTMP" does not match
  "RTMPX" or "rtmp"; an unregistered protocol, the empty one, and a
  plain output's protocol enumerate nothing;
- the early stop: enum_cb returning false after 1, 2, 3 or 4 calls stops
  there, also between the two matches of one output;
- obs_get_output_flags() and obs_output_get_protocols(): the registered
  flags and string as they are, NULL for the plain output.

Characterized, not endorsed: an output that lists a protocol twice is
enumerated twice. A NULL protocol is not driven: it crashes in strcmp()
on this C, a separate fix.

On Linux it runs under xvfb-run with -noreset; without a display the
cases skip.

Refs obs-rust#1829
Behavior-neutral extraction before the Rust port: the ';'-split match
inside obs_enum_output_types_with_protocol() moves from
libobs/obs-output.c.h into libobs/obs-output-protocols.c.h as
obs_output_protocol_list_count(protocols, protocol). The loop is moved
verbatim; where it called enum_cb on a matching segment, it now counts
the match, and the strlen() of the protocol moves in with it.

obs_enum_output_types_with_protocol() keeps the registered check, the
output_types loop, the OBS_OUTPUT_SERVICE check and enum_cb: for each
service output it calls enum_cb as many times as the count, and returns
when enum_cb returns false. That gives the same calls in the same order,
because all matches of one output are consecutive calls with its id.

The entry point is declared in obs-internal.h without EXPORT, so
-fvisibility=hidden keeps it local. The new file joins
libobs.core-output just before obs-output.c.h, with libobs.pch.h. No
group, PCH or source-sets.json change, and the exported symbols are
unchanged (1766).

New test test_output_protocol_list_steps compiles the moved file (ASan
and UBSan, no libobs core) and calls only the entry point, so the port
can run the same file against the Rust staticlib. 9 cases pin: a NULL
and an empty list; whole segments (no prefix match either way, the
separator is not part of a segment); case and spaces (nothing trimmed);
duplicates; empty and trailing segments; the empty protocol; high bytes,
bytes that are not UTF-8 and '%' sequences; a list of 100000 segments
and a 1 MiB segment; and every list of up to 7 bytes over "AB;" against
every protocol of up to 3 bytes, against a model. Characterized, not
endorsed: a protocol listed twice counts twice; the empty protocol
matches each empty segment a ';' ends, but not a trailing one (libobs
never asks for it). It is in the obs-build C test manifest.
test_output_protocols passes unchanged.

Refs obs-rust#1829
@rdoupe
rdoupe requested a review from zackees as a code owner October 22, 2026 21:37
@zackees
zackees added this pull request to the merge queue Oct 22, 2026
Merged via the queue into obs-rust:master with commit 8acff7b Oct 22, 2026
30 checks passed
zackees pushed a commit to rdoupe/obs-studio that referenced this pull request Oct 23, 2026
)

* libobs: Add Tier 1 tests for the output protocol-list match port

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

* libobs: Port the output protocol-list match to obs-output

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

* libobs: Check the output protocol-list match port against the C

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

* docs: Record the output protocol-list match port

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.

2 participants