Repository navigation
libobs: Port the output, encoder and service registration rules to obs-core - #2194
Merged
Merged
Conversation
…obs-module-type-rules.c Moves the pure decisions of obs_register_output_s(), obs_register_encoder_s() and obs_register_service_s() from obs-module.c.h to libobs/obs-module-type-rules.c.h, ahead of their port to obs-core (slice 5 of obs-module.c.h, obs-rust#1876). Behaviour-neutral: no public function, header or signature changes. Four hidden entry points, declared in obs-module-type-rules.h without EXPORT (the header copies the output flags, the encoder type and the two capabilities the rules read, and obs-module.c checks them with _Static_assert): - obs_module_type_rules_output_check(): the first callback an output type lacks for its flags (get_name, create, destroy, start, stop; protocols for a service output; encoded_packet for an encoded one, else raw_video for video and raw_audio2 or raw_audio for audio); - obs_module_type_rules_encoder_check(): a texture encoder that scales itself, then the first callback an encoder type lacks (get_name, create, destroy; encode_texture or encode_texture2 for a texture encoder, else encode; get_frame_size for an audio encoder); - obs_module_type_rules_service_check(): get_name, create, destroy, get_protocol; - obs_module_type_rules_protocol_listed(): a protocol is already in the registered list, by strcmp(). Each takes a bit for each callback HAS_VAL() finds inside the size, computed in C as before. The size limit of REGISTER_OBS_DEF() goes through slice 4's obs_module_source_rules_size_supported(). obs-module.c keeps find_output()/find_encoder()/find_service(), the memcpy() and da_push_back() of REGISTER_OBS_DEF(), the loadingModule lists, every log message (the same text, level and order, picked from the returned code), HANDLE_ERROR (free_type_data on error) and the strlist_split() of the protocols. The file joins libobs.core for now, as the earlier slices did before their ports. A scratch harness compiled master's three functions and the moved ones side by side against the same stubs and compared every lookup, log line, copy, push, strdup, split and free_type_data call and the final lists over 2,000,000 random sequences of 1 to 8 registrations (random flags, caps, types, callbacks, sizes around every field end, duplicates and protocol lists): no difference. Refs obs-rust#1876
Adds test_module_type_rules_steps, a characterization of the output, encoder and service registration rules ahead of their port to obs-core (slice 5 of obs-module.c.h, obs-rust#1876). The steps: the four hidden functions of obs-module-type-rules.c, compiled into the test from the moved file: - every combination of the five output flags the rules read (video, audio, encoded, service, multi-track): the callbacks it needs in order (raw_audio against raw_audio2, encoded_packet replacing the raw ones, protocols for a service), each one missing, all, none, only the needed ones, several missing (the first wins), and flag and callback bits the rules do not read; - encoders: audio, video and other types, against plain, scaling, texture and texture + scaling capabilities (refused before any callback), encode against encode_texture/encode_texture2, get_frame_size for audio after the encode rule; - each service callback; - the protocol dedupe: whole strings, case-sensitive, untrimmed, only the first num entries, an empty protocol, bytes outside ASCII. The callers: obs_register_output_s(), obs_register_encoder_s() and obs_register_service_s() of the real libobs through the public API (obs_enum_*_types(), obs_get_output_flags(), obs_get_encoder_caps(), obs_get_encoder_type(), obs_enum_output_protocols(), the display names, free_type_data and the log handler, every message and its level): - the message for each missing callback, and for a texture encoder that scales itself; - the order: duplicate, texture scaling, callbacks, then size; - sizes at 0 (get_name missing, nothing freed: the "outside of obs_module_load" message is never reached), one byte below a callback's end, at the end, at sizeof() and above it; - the encoder's caps read from the caller's structure even when the size ends before them (characterized, not endorsed); - the protocol merge: each new protocol once, in order, empty entries dropped, case-sensitive, nothing from a failed, duplicate or non-service output; - when the type data is freed. Registered in test-graph.json in sorted order, under xvfb-run where a display is needed (obs_startup()), with libm off MSVC. 16 of 16 on the C backend libobs. Refs obs-rust#1876
…ration rules port The safe core of libobs/obs-module-type-rules.c.h (obs-rust#1876) as todo!() stubs in rust/obs-core (module_type_rules), and its Tier 1 tests: - output_check(), encoder_check(), service_check() and protocol_listed(), on u32 flags, capabilities and types, a Callbacks set for the callbacks HAS_VAL() finds, and protocols as bytes; - the sixteen cases of test_module_type_rules_steps one to one, in the same order, with the same ids, sizes and messages: the six step cases directly, the ten caller cases through a model of the three registrations built on the core (the duplicate lookup, the callbacks inside the size, the rules, slice 4's size_supported(), the copy cut at the size, the protocol split and merge, the log and the freed type data); - the edges (Callbacks::from_bits, the constants, the size limit through slice 4's helper) and eight 2048-case proptests: the output rule reads only its five flags and its callbacks, more callbacks never hurt, the rule broken names a lacking callback, texture scaling first and only for both capabilities, any non-audio encoder type is video, a service needs its four, and the protocol match is byte equality. 27 tests; 24 fail on todo!() (Callbacks::from_bits, the constants and the size limit are not stubs). Refs obs-rust#1876
…s-core Ports libobs/obs-module-type-rules.c.h to the module_type_rules module of rust/obs-core. Every obs_register_output_s(), obs_register_encoder_s() and obs_register_service_s() (every output, encoder and service type libobs's modules register) takes its callback and texture scaling decisions and its protocol dedupe from it. The hybrid libobs drops the C file and links the Rust shims; obs-module.c.h keeps the duplicate lookups, the HAS_VAL() size checks, the copy and push, the protocol split and list, the loadingModule lists, the logging and HANDLE_ERROR, and the size limit stays slice 4's obs_module_source_rules_size_supported(). Safe core (src/module_type_rules.rs), on u32 flags, capabilities and types: - output_check(): get_name, create, destroy, start, stop; protocols for a service output; encoded_packet for an encoded one, else raw_video for video and raw_audio2 (multi-track) or raw_audio for audio; - encoder_check(): a texture encoder that scales itself first, then get_name, create, destroy; encode_texture or encode_texture2 for a texture encoder, else encode; get_frame_size for an audio encoder; - service_check(): get_name, create, destroy, get_protocol; - protocol_listed(): byte equality against the registered protocols. Nothing panics, indexes or overflows; the module denies clippy's indexing, arithmetic, unwrap and panic lints. Shim (src/ffi/module_type_rules.rs): the four C signatures, the error enum as u32 (32-bit on every target) and the callbacks as the C's OBS_MODULE_TYPE_RULES_HAS_* bits. Where the C's strcmp() would read a NULL pointer (obs-module.c passes none), a NULL protocol is listed nowhere, a NULL list is empty and a NULL entry matches nothing. C side: the file leaves libobs.core for its own group, libobs.ported-module-type-rules (LIBOBS_PORTED_SOURCES), whose PCH is obs-module-type-rules.h with string.h, so the C reference and the C backend keep compiling it. The functions are declared without EXPORT, so the shims are hidden: rust-hidden.txt, rust-exports.map and rust-unexports-macos.txt. ci/test_ported_sources.py expects the object in the ported inventory on Linux, Windows and macOS. Results: Tier 1 27 of 27. test_module_type_rules_steps (16 of 16, under a private Xvfb) passes against the C-backend libobs, the hybrid libobs (the four symbols are the Rust shims, local, and no obs-module-type-rules object is linked) and libobs-c-reference (which still compiles the C). There is no test_module_type_rules_steps_rust variant against libobs_rust-static: the archive's obs-core member pulls in the rest of the Rust libobs (obs-util with libuuid and GIO), so the test does not link on its own, and next to libobs it would carry a second copy of libobs's Rust symbols. Tier 3 compares the shims with the C instead. Refs obs-rust#1876
…les port with the original C Adds oracle/module_type_rules.c, the unmodified libobs/obs-module-type-rules.c.h with its four entry points renamed to oracle_* (its strcmp() the C library's), plus the constants of obs-module-type-rules.h, obs-output.h and obs-encoder.h and the field ends and structure sizes the registration reads, as the C sees them; and module_type_rules_parity in obs-tests-core (13 tests). Compared, as the C enum codes are returned: - the constants, against the Rust ones and the shims' codes; - output_check exhaustively: every subset of the five output flags the rules read, with six sets of the bits they do not read, x every set of the ten output callbacks, with and without the other callback bits; - encoder_check exhaustively: six types x every subset of seven capabilities (and three wide masks) x every set of the seven encoder callbacks, with and without the other bits; - service_check over every callback mask, with and without high bits; - protocol_listed over fixed lists (empty, duplicates, case, spaces, bytes outside ASCII, every prefix and suffix of the list); - the whole decision of each registration, each side's functions in the C's order: the callbacks HAS_VAL() finds inside the size by the C's own field ends, the rule, then slice 4's size limit, at every size from 0 to 16 past each structure, for every flag set and the present masks the rules tell apart (every mask for encoders and services); - five 2048-case proptests: any flags, capabilities, type and callback bits for each check, any protocol lists, and the whole decision over any kind, flags, type, present mask and size (field ends weighted). The intentional differences (NULL pointers the C's strcmp() would read) are pinned on the shim alone. No proptest regression file: no case failed. Refs obs-rust#1876
…er and service registration rules - rust/README.md: obs-module-type-rules.c.h in the obs-core crate row, and its row in the port table (what moved, what stays C, the characterized cases, the intentional NULL differences, Tier 2 and Tier 3); - docs/rust-port/naming.md, the obs-core Cargo.toml description and the lib.rs docs: the new unit; - port_comparison: module_type_rules/output_check, encoder_check (a texture video encoder and an audio encoder), service_check and protocol_listed, in their own file, in the sorted modules![] list. The protocol fixtures are owned C strings dropped when the module returns, so the leak check passes. Refs obs-rust#1876
rdoupe
force-pushed
the
port/module-type-rules
branch
from
October 24, 2026 18:07
f9dacfc to
b84376c
Compare
zackees
enabled auto-merge
October 24, 2026 18:11
This was referenced Oct 24, 2026
6 of 7 tasks
This was referenced Oct 24, 2026
This was referenced Oct 28, 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.
Refs #1876 (slice 5 of
obs-module.c.h; more slices may follow).What and why
The fifth slice of
libobs/obs-module.c.hmoves torust/obs-core: the pure decisions ofobs_register_output_s(),obs_register_encoder_s()andobs_register_service_s(). Those are the callbacks each output type needs for its flags, the callbacks each encoder type needs for its type and capabilities, the rule that a texture encoder can't scale itself, the callbacks a service needs, and the protocol dedupe of a service output.Feasibility. No seam is needed. Each registration passes its flags (outputs), its type and capabilities (encoders) and a bit for each callback that
HAS_VAL()finds inside the size, and gets back an error code. The protocol dedupe gets one protocol and the registered list, and returns whether it is already there.These stay C, in the same order as before:
find_output(),find_encoder()andfind_service();HAS_VAL()checks;memcpy()andda_push_back()ofREGISTER_OBS_DEF();strlist_split()of the protocols, and the protocol list;loadingModulelists;HANDLE_ERROR(free_type_dataon error).The size limit of
REGISTER_OBS_DEF()now calls slice 4'sobs_module_source_rules_size_supported()rather than adding a second helper.No exported function moves, so there is no
rust-exports.dfragment, and the 1766 exported symbols are unchanged. The unit is its own file,obs-module-type-rules.c.h, with its own header,obs-module-type-rules.h(Rustobs_core::module_type_rules). The header copies the five output flags, the audio encoder type and the two capabilities the rules read.obs-module.c.hchecks the copies againstobs-output.handobs-encoder.hwith_Static_assert. Still inobs-module.c.h: the decision chain ofload_all_callback()and the module loading.Overlap: no open PR touches
obs-module.c.h. #1837 touchesobs-internal.h, which this branch does not touch: the declarations are in the new header.Commits:
libobs: Move the output, encoder and service registration rules into obs-module-type-rules.c: a behaviour-neutral extraction. It changes no public function, header or signature. It adds four hidden entry points:obs_module_type_rules_output_check,_encoder_check,_service_checkand_protocol_listed.find_*,blog,memcpy,da_push_back,bstrdup,strlist_split,free_type_data).free_type_datacall, and the final lists: 53.7 million events, no difference.test: Characterize the output, encoder and service registration rules: a new cross-platform test,test_module_type_rules_steps. It is registered intest-graph.jsonin sorted order, underxvfb-runwhere a display is needed, with libm off MSVC. It has two parts.raw_audioagainstraw_audio2,encoded_packetreplacing the raw callbacks, andprotocolsfor a service. Each one missing, all, none, only the needed ones, several missing (the first wins), and flag and callback bits the rules don't read.encodeagainstencode_texture/encode_texture2, and audioget_frame_sizeafter the encode rule.obs_register_output_s(),obs_register_encoder_s()andobs_register_service_s()of the real libobs, through the public API (obs_enum_*_types(),obs_get_output_flags(),obs_get_encoder_caps(),obs_get_encoder_type(),obs_enum_output_protocols(), the display names,free_type_dataand the log handler).sizeof()and above it.port_comparison.Safe core (
rust/obs-core/src/module_type_rules.rs):output_check,encoder_check,service_check(withCallbacks) andprotocol_listed.u32, so any value a plugin passes is kept as its bits. Bits the rules don't name are ignored.Shim (
src/ffi/module_type_rules.rs): the four C signatures.u32: 32-bit on every target (unsigned intwith GCC and Clang,intwith MSVC).OBS_MODULE_TYPE_RULES_HAS_*bits.libobs/obs-module-type-rules.c.hmoves tolibobs.ported-module-type-rules. Its PCH isobs-module-type-rules.hplusstring.h.rust-hidden.txt,rust-exports.mapandrust-unexports-macos.txt.test_module_type_rules_steps_rustvariant. The archive's obs-core member pulls in the rest of the Rust libobs (obs-util with libuuid and GIO), so it does not link on its own (checked). Next to libobs it would carry a second copy of libobs's Rust symbols. Tier 3 compares the shims with the C instead, and Tier 2 runs the callers against the hybridlibobs.Kept, characterized, not endorsed:
OBS_OUTPUT_MULTI_TRACKwithoutOBS_OUTPUT_AUDIOneeds no audio callback. An encoded output needs no raw callback, whatever its video and audio flags.get_frame_size).obs-module.c.h(still C):caps. A structure cut beforecapsis registered with no caps, though the caller's said otherwise.get_nameand frees nothing. The "outside of obs_module_load" message ofREGISTER_OBS_DEF()is never reached.A bug found, not fixed here (C, in
HANDLE_ERROR, unchanged by this PR; slice 4's source registration has the same macro): the error path copies the caller's structure cut at the size, then callsfree_type_datawhen both pointers are non-NULL. A size that ends insidefree_type_dataleaves a partial pointer: one or more low bytes of the caller's pointer, then zeros. That pointer is then called. The move harness hit it (a service registered with size 137 jumped to0x80), so it skips such sizes on both sides. Only a plugin passing a size other thansizeof()of its structure can reach it, and plugins run in-process anyway. It deserves its own issue: free only when both pointers are whole inside the size.Intentional differences: the C's
strcmp()would read a NULL pointer, andobs-module.cpasses none: the protocol comes fromstrlist_split(), the entries frombstrdup(), and the list is NULL only withnum0. In those cases the shim lists a NULL protocol nowhere, treats a NULL list as empty, and matches a NULL entry with nothing.protocol_listed_null_pointerspins this.RED → GREEN
Characterization: aec272c.
test_module_type_rules_stepsgives 16/16 on the C backendlibobs(run before the latest rebase, same content).RED commit: 10a8f1a
obs-core: Add Tier 1 tests for the output, encoder and service registration rules port.obs_core::module_type_ruleshas 27 tests:24 of them fail on
todo!(), checked at 10a8f1a.Callbacks::from_bits, the constants and the size limit through slice 4's helper are not stubs.GREEN: 2e344a0
libobs: Port the output, encoder and service registration rules to obs-core. Tier 1 27/27. Tier 2:test_module_type_rules_steps16/16 andtest_source_registration10/10 against the C backendlibobs, the hybridlibobsandlibobs-c-reference.libobs, the fourobs_module_type_rules_*symbols are the Rust shims (local), and noobs-module-type-rulesobject is linked.libobs-c-referenceand the C backend still compile the C.Tier 3: b09bce7 (
module_type_rules_parity.rs, 13 tests). The oracle is the unmodified C file with its entry points renamed, itsstrcmp()the C library's. It also gives the constants and the field ends and structure sizes as the C sees them. Compared, as the C enum codes are returned:output_checkexhaustively: every subset of the five flags, with six sets of the bits the rules don't read, × every set of the ten output callbacks, with and without the other callback bits;encoder_checkexhaustively: six types × every subset of seven capabilities (plus three wide masks) × every set of the seven encoder callbacks, with and without the other bits;service_checkover every callback mask;protocol_listedover fixed lists, every prefix and suffix of them;No proptest regression file: no case failed. The oracle has no division, and none of its inputs reaches a path that traps on MSVC x64.
Mutation check: 25 mutants, each reverted (not committed): 23 of the safe core and 2 of the shim. Each cell is the number of failing tests:
startnot requiredstopchecked beforestartprotocolsrequired without the service flagprotocolsnever requiredraw_audio2for single-track audioraw_audio2raw_videonot requiredencode_texture2onlyencodeget_frame_sizefor video encodersget_frame_sizefor any type but videoget_frame_sizechecked beforeencodeget_protocolnot requireddestroynot requiredcreatechecked beforeget_nameraw_audioandraw_audio2bits swappedNO_ENCODEandNO_ENCODE_TEXTUREcodes swapped6c98110db. Nothing conflicted. Every shared list and row was hand-diffed againstmasterafterwards, and only this PR's lines are added:source-sets.json, the three export lists,ci/test_ported_sources.py,test-graph.json, the port_comparison list, the obs-core testmain.rs, the oraclelib.rs, the ffimod.rs,libobs.pch.handlibobs.core+.h.c.OBS_LIBOBS_BACKEND=C, andHYBRIDwithOBS_BUILD_C_REFERENCE=ON;libobs-c-referencebuilt explicitly). They ran headless, with a private Xvfb (-noreset), a private D-Bus, a fresh HOME and TMPDIR unset:test_module_type_rules_stepstest_source_registrationlibobslibobslibobs-c-referencetest/cmockanamesobs_register_ormodule, including the_rustvariants.test_stinger_media_duration(short_header_plays_whole_clip: the stinger clip was never shown). The machine's load average was about 25 at the time. The test passed 3 of 3 runs on its own, with the same library, and it passed on the C backend. It times a media decode and doesn't register any type.soldr cargo test -p obs-data --test obs-tests-core:obs_core::module_type_rules*40/40.ci/local_gate.py --test-diff origin/master: 3530 nextest tests, 3530 passed, 4 skipped; doctests passed.ci/local_gate.py --lane lintand--lane cross: passed.soldr cargo clippy --target x86_64-pc-windows-msvc --all-targets -- -D warnings: passed. No conversion here depends on the width ofc_long.ci/test_build_groups.py,test_ported_sources.py,test_oracle_standins.py,test_sorted_shared_lists.py,test_test_graph_sorted.py,test_cmocka_rust_static_guard.py,test_cmocka_windows_diagnostics.py,test_cmocka_includes.pyandtest_naming.py: passed.soldr cargo test -p obs-c-oracle --locked --bench port_comparison: passed (each module frees its fixtures).port_comparison:soldr cargo bench -p obs-c-oracle --bench port_comparison -- module_type_rules, 3 passes pinned to one CPU, Linux x86_64, rustc 1.98.1. The machine was heavily loaded (load average about 25), so the single-call rows, a few nanoseconds each, are near the floor and vary widely from run to run. Each call runs once per registered type (the dedupe once per protocol), at startup and when a module loads.Windows/macOS: the cross lane compiles and links the shims, and the Windows clippy run above passed, but nothing ran locally on Windows or macOS.
test_module_type_rules_stepsis a cross-platform test, but no native Windows or macOS run built it locally. On Windows and macOS, PR CI's Rust lanes run Tier 1 and Tier 3, and the merge queue's Tier 2 runs the C test.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 changes)Rebased onto master after #2171 and #2181 merged (head
b84376ccc). The only conflicts were the shared lists and the crate prose lists, merged by keeping both entries. After the rebase, the crate's Tier 1 and Tier 3 tests andsoldr cargo test -p obs-c-oracle --locked --bench port_comparisonpass. The earlier lane runs above are on the pre-rebase SHAs.