Repository navigation
libobs: Port the output protocol-list match to obs-output - #1848
Merged
Merged
Conversation
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
This was referenced Oct 23, 2026
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.
Fixes #1829 (PR 3 of the plan; #1831 moved the match into
libobs/obs-output-protocols.c.has the hiddenobs_output_protocol_list_count()and addedtest_output_protocolsandtest_output_protocol_list_steps; #1828 made the public lookups return false for a NULL protocol and addedtest_output_protocol_null)What and why
This PR ports
libobs/obs-output-protocols.c.h, the output protocol-list match, to a newprotocolsmodule ofrust/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;-separatedprotocolsstring 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_typesloop, theOBS_OUTPUT_SERVICEcheck and the callback stay C inobs-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.src/protocols.rs):count_matches(list: &[u8], protocol: &[u8]) -> usize, as the issue sketched.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)."RTMP"does not match"RTMPS","rtmp"or" RTMP".;is not scanned, because the C reaches the NUL there and stops.arithmetic_side_effects,indexing_slicing,unwrap_used,expect_used,panic,todo,unimplementedandunreachable. No hostcfg, nounsafe.src/ffi/output_protocols.rs):obs_output_protocol_list_count, with the C signature.strlen()andstrchr()do, and calls the core.output_caption_text.rs, ...). The issue saidsrc/ffi/protocols.rs.obs-output-protocols.c.hleaveslibobs.core-outputfor its own group,libobs.ported-output-protocols, listed insource-sets.json(LIBOBS_PORTED_SOURCES). Its PCH,libobs-ported-output-protocols.pch.h, isstring.handobs-internal.h. The only change to the file is that include and its header comment.test_output_protocol_list_stepsstill compiles it into itself, unchanged.ci/test_ported_sources.pychecks the group on Linux, Windows and macOS.obs-internal.hwithoutEXPORT, so the shim is hidden likeobs_output_caption_text_page:rust-hidden.txt, thelocal:list ofrust-exports.map, andrust-unexports-macos.txt. Norust-exports.dfragment.nmshows it as local (t) in all three libraries. The exported symbol sets are unchanged (1766).oracle/output_protocols.c): the original file, unmodified, with the function renamed tooracle_obs_output_protocol_list_count.while (substr && ...)).strlen()crashes on it, with or without a list. The shim counts 0, the answer every public lookup gives a NULL protocol since libobs, frontend: Take a NULL protocol in the output protocol lookups #1828.src/ffi/output_protocols.rsand therust/README.mdrow):obs_enum_output_types_with_protocol()returns for a NULL protocol before the match (libobs, frontend: Take a NULL protocol in the output protocol lookups #1828). So nothing in libobs can see this difference.;ends, but not the one after a trailing;, and nothing in an empty list. libobs never asks for it, because""is never a registered protocol.rust/README.mdrows, thedocs/rust-port/naming.mdrow and the crate's Cargodescription. Nodocs/features.mdline: there is no user-visible change.test_output_protocols(7 cases) andtest_output_protocol_null(4 cases) linkOBS::libobsand use the public API only. In the hybrid libobs they run the Rust shim and core throughobs_enum_output_types_with_protocol(), so they are the end-to-end proof on every OS.There is no
_rustvariant oftest_output_protocol_list_stepslinkinglibobs_rust-static. I tried one. It does not link on Linux: the shim's archive member also holds the rest ofobs-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 oftest_output_protocol_list_steps.cmakesays so, astest_context_name_helpers.cmakedoes. So Tier 3 is the direct comparison on every OS.RED → GREEN
133a3f5e1libobs: Add Tier 1 tests for the output protocol-list match port. The core istodo!().soldr cargo test -p obs-data --test obs-tests-core output::protocols::fails 21 of 21 with "not yet implemented".tests/output/protocols.rs) portstest_output_protocol_list_steps1: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.;never matches;obs-tests-core. No new test binary.920d00676libobs: Port the output protocol-list match to obs-output.output::protocols::passes 21/21.1d62ccf15libobs: 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.A,B,aand;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.test_output_protocol_list_stepsasks for, with its expected count; its 100,000-segment list (also with a trailing;) and its 1 MiB segment.;. Each is checked against the protocol, the protocol one byte longer, one byte shorter, lowercased, and the empty protocol;;, against a segment of the list, a slice of it that may cross a;, and random bytes.output::protocolspasses 30/30.soldr cargo test -p obs-data --test obs-tests-corepasses 758/758.;scanned;;stripped;test_output_protocolsfailedenum_order_and_duplicatesandenum_early_stop(5/7) and passed 7/7 against libobs-c-reference. After the restore, 7/7 against both.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 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'smbedtls/version.hwithout 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 onto582a4c3ed, the full suite also passed on both (379/379); one hybrid run first failedtest_async_delay_audioonce under-j4load (an audio timing test that does not touch outputs). It passed 3 of 3 alone, and the full rerun passed.test_output_protocol_list_steps9/9,test_output_protocols7/7 andtest_output_protocol_null4/4 pass against all three libraries. The ported group is compiled only into libobs-c-reference (and the C-backend libobs).uv run ci/local_gate.py --lane lintpassed, and--lane crosspassed.ci/test_build_groups.py,ci/test_ported_sources.py,ci/test_naming.py,ci/test_binary_cap.pyandci/test_rust_scope.pypass.export_list(obs-util) passes 3/3.test_output_protocolsdrives 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_protocolsandtest_output_protocol_list_stepsare built on every OS, so on Windows and macOS the swap is covered bytest_output_protocolsagainst the hybrid libobs, by Tier 3 (therust-testsjob) and by the unchanged C tests (rust-tier2). PR CI covers those builds.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)