Repository navigation
libobs: Move the output protocol-list match into obs-output-protocols.c - #1831
Merged
zackees merged 2 commits intoOct 22, 2026
Merged
Conversation
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
This was referenced Oct 22, 2026
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 insideobs_enum_output_types_with_protocol()moves fromlibobs/obs-output.c.hintolibobs/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.protocolsstring becomessize_t obs_output_protocol_list_count(const char *protocols, const char *protocol). The loop is verbatim. Where it calledenum_cbon a matching segment, it now counts the match, and thestrlen()of the protocol moves in with it. A NULL list counts 0, as thewhile (substr && ...)did.obs_enum_output_types_with_protocol()keeps the registered check, theoutput_typesloop, theOBS_OUTPUT_SERVICEcheck andenum_cb. For each service output it callsenum_cbas many times as the count, and returns whenenum_cbreturns 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.obs-internal.hwithoutEXPORT, so-fvisibility=hiddenkeeps it local (atsymbol inlibobs.so, in all three libraries).libobs.core-outputgroup just beforeobs-output.c.h, withlibobs.pch.h. The group, the PCH,source-sets.jsonand the CMake source lists are unchanged. The moved code has no platform conditional.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 underxvfb-runwith-noreset; it skips without a display. 7 cases: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"givesproto_duptwice, thenproto_rtmp_rtmps, thenproto_empty_segments, and not the plain output;"RTMPX"gives onlyproto_prefix, and"rtmp"onlyproto_lower;"Rtmp","RIST", the plain output's protocol,"RTMP;RTMPS"and";"enumerate nothing;enum_cbreturning false after 1, 2, 3 or 4 calls stops there, also between the two matches ofproto_dup;obs_get_output_flags()andobs_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:";RTMP;;","HLS;",";HLS",";;;");\xff, bytes that are not UTF-8, precomposed and decomposed é, control bytes and DEL,%sequences;A,Band;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:
"WHIP; RIST"registers" RIST", not"RIST".;ends, but not a trailing one. libobs never asks for it, because""is never a registered protocol.strcmp()inobs_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
78046f858test: Characterize the output protocol lookups, andtest_output_protocolspasses 7/7 there on the unchanged C against all three libraries. The move isf764f5dd1libobs: Move the output protocol-list match into obs-output-protocols.c.test_output_protocols7/7 andtest_output_protocol_list_steps9/9 against libobs with the C backend, the hybrid libobs and libobs-c-reference.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.obs-output-protocols.c.h, each built into libobs (C backend) and the steps test, and 2 of the caller:test_output_protocol_list_stepstest_output_protocols<=, compareprotocol_len)strncasecmp);scannedThe 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.
OBS_LIBOBS_BACKEND=C, andHYBRIDwithOBS_BUILD_C_REFERENCE=ON, both full builds. Fullctest -j4, headless (private Xvfb with-noreset, private D-Bus, fresh HOME):HYBRID,OBS_BUILD_C_REFERENCE=ONHYBRID,OBS_BUILD_C_REFERENCE=ONOBS_LIBOBS_BACKEND=CNothing 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.pyandci/test_ported_sources.pywere repeated.uv run ci/local_gate.py --lane lintpassed, and--lane crosspassed.ci/test_build_groups.py,ci/test_ported_sources.py,ci/test_cmocka_includes.pyandci/test_naming.pypass. clang-format and gersemi are clean on the changed files.Windows/macOS: not built there. The moved code has no host conditional.
test_output_protocol_list_stepsis portable C (no cmocka range assertions, nofail_msg()).test_output_protocolsis registered on every platform liketest_context_names(no fork, no X11 calls of its own); it has run on Linux only.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)-W..., ratchets): built with scripting ON (PR CI builds no OBS app: rungh workflow run ci.yml --ref <branch>for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)