Skip to content

libobs: Port the source registration rules to obs-core - #1929

Merged
zackees merged 6 commits into
obs-rust:masterfrom
rdoupe:port/obs-module-slice4
Oct 23, 2026
Merged

zackees merged 6 commits into
obs-rust:masterfrom
rdoupe:port/obs-module-slice4

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Refs #1876 (slice 4 of obs-module.c.h; more slices may follow). Unit 9 of #1846.

What and why

The fourth slice of libobs/obs-module.c.h moves to rust/obs-core: the pure decisions of obs_register_source_s(). Those are the list a source type goes in, the size limit, the output flag rules, the composite and required callback checks, and the versioned id.

Feasibility. No seam is needed. obs_register_source_s() passes the type, the flags, the size, the version and a bit for each callback that HAS_VAL() finds, and it gets back a list or an error code. The duplicate lookup (get_source_info2()), the module's source list (loadingModule), the memcpy, the size-aware HAS_VAL() checks, the transition get_width/get_height warnings, the da_push_back() calls, every log message and HANDLE_ERROR stay C. C logs from the returned code, with the same text, level and order as before.

No exported function moves, so there is no rust-exports.d fragment, and the 1766 exported symbols are unchanged. The unit is its own file, obs-module-source-rules.c.h (Rust obs_core::module_source_rules). The hybrid build drops a ported file's C, so the new functions can't go into one of the earlier slices' files. Still in obs-module.c.h: the decision chain of load_all_callback() and the output, encoder and service registration (later slices). Overlap: #1926 (slice 3) is open and touches the same README rows, lists and lib.rs docs, but not obs_register_source_s(). This branch is based on master, and the shared rows will be rebased after #1926 lands.

Commits:

  • test: Characterize the source registration rules: a new cross-platform test, test_source_registration, registered in test-graph.json like test_service_settings (under xvfb-run where a display is needed). It uses the public API only. obs_register_source_s() gets crafted obs_source_info structures and sizes, and the result is read back through obs_enum_source_types(), the input, filter and transition lists, obs_enum_input_types2(), obs_get_source_output_flags(), obs_source_get_display_name(), free_type_data and the log handler (every message and its level, in order). Covered:
    • the list each type goes in (input, filter, transition; a scene in none, with no array; any other type rejected);
    • a duplicate id and version, and another version of the same id;
    • the size limit, and sizes that cut the structure before get_name, get_width, get_height, audio_render, free_type_data, the flags, the type and the version;
    • the flag rules: an audio-only filter made async, a transition made composite, video and custom draw, with its get_width/get_height warnings;
    • the composite checks (audio before async) and the required callbacks in their order;
    • the versioned id, with the version printed as an int;
    • which check wins when several fail (type, then duplicate, then size, then composite, then required), and when the type data is freed.
  • libobs: Move the source registration rules into obs-module-source-rules.c: a behaviour-neutral extraction that changes no public function, header or signature. It adds five hidden entry points: obs_module_source_rules_list_of, _size_supported, _output_flags, _check and _versioned_id.
  • RED, GREEN, Tier 3, then docs and port_comparison.

The two reads of the flags. The C reads the caller's structure for the list and for the get_width/get_height rule (info->type, info->output_flags). It reads its copy, cut at the caller's size, for the flag rules and the composite rules (data.type, data.output_flags). _check() takes both, as the C has them.

  • Normalization only changes a filter's or a transition's flags, and the get_width/get_height rule skips both. So the two reads can differ only when the size cuts the copy before its type or flags end.
  • Such a structure also cuts off get_name, so it always fails. The two reads change which message is logged, never whether a source is registered.
  • test_short_size pins the cases where the message changes. A mutant that makes the get_width/get_height rule read the normalized flags passes test_source_registration 10/10 on the hybrid libobs. Tier 1 and Tier 3 catch it.

This is not a bug that changes behaviour, so it is kept as it is.

Safe core (rust/obs-core/src/module_source_rules.rs): list_of, size_supported, output_flags, check (with Callbacks) and versioned_id.

  • Types and flags are u32, so a value outside the enum is kept as its bits. Flag bits that the rules don't name are kept.
  • The id is bytes, with Option for NULL. With a version, a NULL id prints as (null), as the C's "%s" prints it. libobs never gets there: a NULL id crashes in the duplicate lookup first.
  • The module denies clippy's indexing, arithmetic, unwrap and panic lints.

Shim (src/ffi/module_source_rules.rs): the five C signatures.

  • The enums are u32: 32-bit on every target (unsigned int with GCC and Clang, int with MSVC).
  • The callbacks come as the C's OBS_MODULE_SOURCE_RULES_HAS_* bits.
  • The versioned id is bmalloc'd, and the caller owns it.
  • libobs/obs-module-source-rules.c.h moves to libobs.ported-module-source-rules (PCH obs-internal.h). The five symbols are hidden through rust-hidden.txt, rust-exports.map and rust-unexports-macos.txt.

Kept, characterized, not endorsed:

  • The two reads of the flags, above.
  • The version is printed as an int: 2147483648 gives _v-2147483648, and UINT32_MAX gives _v-1.
  • In obs-module.c.h (still C): the duplicate lookup reads the caller's version even when the size cuts it off. Such a type is then registered unversioned (its copy has version 0), and a later registration of the same id with version 0 is a duplicate.
  • Also still C: a size of 0 frees nothing, and the type data is freed only when the copied part holds both type_data and free_type_data.
  • The type is checked before the duplicate lookup, the duplicate before the size, and the size before the flags. The composite checks come before get_name.

Intentional differences: none.

RED → GREEN

  • Characterization: e089bc4. test_source_registration gives 10/10 on the C backend libobs. At the extraction (6201153) it is 10/10 on the C backend libobs, the hybrid libobs and libobs-c-reference.

  • RED commit: 65f18ab libobs: Add Tier 1 tests for the source registration rules port. obs_core::module_source_rules has 21 tests:

    • the ten C cases 1:1, through a model of obs_register_source_s() built on the core;
    • the edges of each function;
    • five 2048-case proptests.

    20 of them fail on todo!(); Callbacks::from_bits is not a stub. With the todo!() core linked into the swapped hybrid libobs, test_source_registration aborts in obs_startup() (exit 134, "not yet implemented" in module_source_rules.rs).

  • GREEN: b8992f1 libobs: Port the source registration rules to obs-core. Tier 1 21/21. Tier 2: test_source_registration 10/10 against the hybrid libobs and libobs-c-reference.

    • In the hybrid libobs, the five obs_module_source_rules_* symbols are the Rust shims (local), and no obs-module-source-rules object is linked.
    • libobs-c-reference and the C backend still compile the C.
  • Tier 3: 71fab4c (module_source_rules_parity.rs, 12 tests). The oracle is the unmodified C file with its entry points renamed. Its dstr_printf is the original util/dstr-libc.c, through the dstr oracle. Compared, as the C enum codes are returned:

    • list_of over 13 types around the enum and both ends of u32;
    • size_supported around sizeof(struct obs_source_info) and both ends of size_t;
    • output_flags and check exhaustively: 13 types × every subset of the five flags the rules read, for both the caller's and the normalized flags, × all 16 callback sets;
    • versioned_id over 8 ids (NULL, empty, % sequences, bytes outside ASCII) × 11 versions around both ends of int;
    • the whole decision of obs_register_source_s(): each side's five functions in the C's order, with the copy cut at the size, for 5 types × 32 flag sets × 3 callback sets × 28 sizes around every field end the registration reads;
    • six 2048-case proptests over any type, size, flags, callback bits, id and version, the last one over the whole registration.
  • Mutation check: 22 mutants of the safe core, each reverted (not committed). Each cell is the number of failing tests:

Mutant Tier 1 (of 21) Tier 3 (of 12)
a scene is unknown 5 3
a filter is an input 5 3
size < for <= 11 4
every filter async 5 4
a filter without audio (not video) async 6 4
a transition without custom draw 4 4
a scene made composite too 4 4
async checked before audio 3 4
composite rules read the caller's flags 5 4
get_width/get_height rule reads the normalized flags 2 2
async video needs get_width/get_height 3 4
only inputs need get_width/get_height 3 4
filters need get_width/get_height 3 3
get_height not required 4 4
get_name checked after the size rule 4 4
audio_render always required 4 4
audio_render never required 5 4
get_width and get_height bits swapped 1 4
version printed unsigned 3 3
version 0 versioned too 11 4
-v for _v 5 4
a NULL id empty 2 2

Two mutants were also run through Tier 2 against the hybrid libobs:

Library test_source_registration test_core_module_load Full ctest Exported symbols
C backend libobs 10/10 19/19 390/390, 0 skipped IDENTICAL (1766)
hybrid libobs 10/10 19/19 392/392, 0 skipped IDENTICAL (1766)
libobs-c-reference 10/10 19/19 392/392, 0 skipped IDENTICAL (1766)
  • Other local checks, at the head (9ef1b3c):
    • soldr cargo test -p obs-data --test obs-tests-core: 989/989 (one earlier run had 988/989: obs_core::source_profiler_parity::parity_random_sequences, which fails intermittently on master too and is not touched here) (obs_core::module_source_rules* 33/33).
    • soldr cargo test -p obs-core: passed.
    • ci/local_gate.py --lane lint and --lane cross: passed.
    • ci/test_build_groups.py, ci/test_ported_sources.py and ci/test_oracle_standins.py: passed.
  • port_comparison: soldr cargo bench -p obs-c-oracle --bench port_comparison -- module_source_rules, 3 passes pinned to one CPU, Linux x86_64, rustc 1.98.1. Each call runs once per registered source type, at startup and when a module loads.
    • The single-call rows are a nanosecond or two, which is close to the measurement floor.
    • check converts the callback bits to Callbacks and maps the result to the C code.
    • The unversioned id is copied twice (the core's Vec, then bmalloc); the C copies it once.
    • The versioned id is formatted without vsnprintf.
Benchmark Rust C Rust / C (run range)
module_source_rules/list_of 1.13 ns 1.31 ns 0.867 (0.836-1.038)
module_source_rules/size_supported 1.71 ns 1.72 ns 1.005 (0.994-1.053)
module_source_rules/output_flags 1.09 ns 1.73 ns 0.631 (0.627-0.635)
module_source_rules/check 2.50 ns 1.31 ns 1.496 (1.392-1.914)
module_source_rules/versioned_id/unversioned 30.22 ns 22.18 ns 1.368 (1.359-1.373)
module_source_rules/versioned_id/versioned 49.10 ns 93.92 ns 0.522 (0.521-0.523)
  • Real app: not applicable (no user-visible change: the same types are registered with the same flags, ids and log messages).

Windows/macOS: the cross lane compiles and links the shims, but they were not run locally. test_source_registration is 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. The oracle prints a NULL id with the C library's "%s" (glibc here, the UCRT on Windows, libc on macOS). All three print (null), as the core does.

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)
  • 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 changes)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports)

@rdoupe
rdoupe requested a review from zackees as a code owner October 23, 2026 11:45
@rdoupe
rdoupe force-pushed the port/obs-module-slice4 branch from 9ef1b3c to d41def1 Compare October 23, 2026 12:07
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 23, 2026
@rdoupe
rdoupe force-pushed the port/obs-module-slice4 branch from d41def1 to 2c95bd4 Compare October 23, 2026 12:48
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 23, 2026
@rdoupe
rdoupe force-pushed the port/obs-module-slice4 branch 2 times, most recently from 9889131 to 576e0cf Compare October 23, 2026 14:12
@zackees
zackees enabled auto-merge October 23, 2026 14:13
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 23, 2026
@rdoupe
rdoupe force-pushed the port/obs-module-slice4 branch from 576e0cf to fc720ab Compare October 23, 2026 14:55
@zackees
zackees enabled auto-merge October 23, 2026 15:12
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 23, 2026
Adds test_source_registration, a characterization of
obs_register_source_s() ahead of the port of its rules to obs-core
(slice 4 of obs-module.c.h, obs-rust#1876). Public API only:
obs_register_source_s() with crafted obs_source_info structures and
sizes, observed through obs_enum_source_types(), the input, filter and
transition lists, obs_enum_input_types2(), obs_get_source_output_flags(),
obs_source_get_display_name(), free_type_data and the log handler (every
message and its level, in order).

Covered:
- the list each type goes in (input, filter, transition; a scene in none;
  any other type rejected);
- a duplicate id and version, and another version of the same id;
- the size limit, and sizes that cut the structure before get_name,
  get_width, get_height, audio_render, free_type_data, the flags, the
  type and the version;
- the flag rules: an audio-only filter made async, a transition made
  composite, video and custom draw, with its get_width/get_height
  warnings;
- the composite checks (audio before async) and the required callbacks
  (get_name, get_width, get_height, audio_render) and their order;
- the versioned id, with the version printed as an int;
- which check wins when several fail, and when the type data is freed.

Registered in test-graph.json like test_service_settings, under xvfb-run
where a display is needed. 10 of 10 on the C backend libobs.

Refs obs-rust#1876
…es.c

Moves the pure decisions of obs_register_source_s() from obs-module.c.h
to libobs/obs-module-source-rules.c.h, ahead of their port to obs-core
(obs-rust#1876). Behaviour-neutral: no public function, header or signature
changes.

Five hidden entry points, declared in obs-internal.h without EXPORT:
- obs_module_source_rules_list_of(): the list of a type (input, filter,
  transition; none for a scene; unknown for anything else);
- obs_module_source_rules_size_supported(): size is not above the
  structure libobs knows;
- obs_module_source_rules_output_flags(): an audio-only filter made
  async, a transition made composite, video and custom draw;
- obs_module_source_rules_check(): the first composite or required
  callback rule broken, in the C's order. It takes the caller's type and
  flags for the get_width/get_height rule and the normalized flags for
  the composite rules, as the C reads them, and a bit for each callback
  HAS_VAL() finds inside the size;
- obs_module_source_rules_versioned_id(): "<id>_v<N>" through
  dstr_printf() with (int)version, or bstrdup(id) for version 0.

obs_register_source_s() keeps the duplicate lookup, the module's source
list, the memcpy, the HAS_VAL() size checks, the transition get_width/
get_height warnings, the da_push_back() calls, every log message (the
same text, level and order, picked from the returned code) and
HANDLE_ERROR. The file joins libobs.core for now, as the earlier slices
did before their ports.

test_source_registration: 10 of 10 on the C backend libobs, as before
the move.

Refs obs-rust#1876
The safe core of libobs/obs-module-source-rules.c.h (obs-rust#1876) as todo!()
stubs in rust/obs-core (module_source_rules), and its Tier 1 tests:
- list_of(), size_supported(), output_flags(), check() and
  versioned_id(), on u32 types and flags, a Callbacks set for the
  callbacks HAS_VAL() finds, and the id as bytes (None for NULL);
- the ten cases of test_source_registration one to one, in the same
  order, with the same ids, sizes and messages, through a model of
  obs_register_source_s() built on the core (the list, the duplicate
  lookup, the size, the copy cut at the size, the flags, the callbacks
  inside the size, the check, the versioned id, the log and the freed
  type data);
- the edges of each function, and five 2048-case proptests: unknown
  past the scene type, normalization only adding its bits, the first
  rule broken in the C's order, the size limit, and the id with the
  version printed as an int.

21 tests; 20 fail on todo!() (Callbacks::from_bits is not a stub).

Refs obs-rust#1876
Ports libobs/obs-module-source-rules.c.h to the module_source_rules
module of rust/obs-core. Every obs_register_source_s() (every source
type libobs and its modules register) takes its list, size, flag,
composite and required callback decisions and its versioned id from it.
The hybrid libobs drops the C file and links the Rust shims;
obs-module.c.h keeps the duplicate lookup, the module's source list, the
copy, the HAS_VAL() size checks, the type lists, the logging and
HANDLE_ERROR.

Safe core (src/module_source_rules.rs), on u32 types and flags:
- list_of(): input, filter, transition, none for a scene, unknown for
  anything else;
- size_supported(): size <= supported;
- output_flags(): a filter without video gets ASYNC, a transition
  COMPOSITE | VIDEO | CUSTOM_DRAW; every other bit is kept;
- check(): the first rule broken, in the C's order (composite audio,
  composite async, get_name, get_width, get_height, audio_render),
  with the caller's type and flags for the get_width/get_height rule
  and the normalized flags for the composite rules;
- versioned_id(): the id, "_v" and the version as an i32, or a copy of
  the id for version 0 (None for NULL; "(null)" with a version, as the
  C's "%s" prints it).
Nothing panics, indexes or overflows; the module denies clippy's
indexing, arithmetic, unwrap and panic lints.

Kept as the C has it, characterized and not endorsed (obs-rust#1876): the two
reads of the flags, which can differ only for a structure cut before
its type or flags end, and such a source always fails; the version
printed as an int. No intentional differences.

Shim (src/ffi/module_source_rules.rs): the five C signatures, the enums
as u32 (32-bit on every target), the callbacks as the C's
OBS_MODULE_SOURCE_RULES_HAS_* bits and the versioned id bmalloc'd.

C side: the file leaves libobs.core for its own group,
libobs.ported-module-source-rules (LIBOBS_PORTED_SOURCES), whose PCH is
obs-internal.h, so the C reference and the C backend keep compiling it.
The functions are declared in obs-internal.h without EXPORT, so the
shims are hidden: rust-hidden.txt, rust-exports.map and
rust-unexports-macos.txt. libobs-rust already re-exports obs-core's ffi.
ci/test_ported_sources.py expects the object in the ported inventory on
Linux, Windows and macOS.

Results: Tier 1 21 of 21. test_source_registration (10 of 10, under a
private Xvfb) passes against the C-backend libobs, the hybrid libobs
(the five symbols are the Rust shims, local, and no
obs-module-source-rules object is linked) and libobs-c-reference (which
still compiles the C). With the todo!() core the hybrid run aborts in
obs_startup() (exit 134, "not yet implemented").

Refs obs-rust#1876
…ginal C

Adds oracle/module_source_rules.c, the unmodified
libobs/obs-module-source-rules.c.h with its five entry points renamed to
oracle_*, its dstr_printf the dstr oracle's (the original
util/dstr-libc.c), and module_source_rules_parity in obs-tests-core
(12 tests). Compared, as the C enum codes are returned:
- list_of over 13 types around the enum and both ends of u32;
- size_supported around sizeof(struct obs_source_info) and both ends of
  size_t;
- output_flags and check exhaustively: 13 types x every subset of the
  five flags the rules read, for the caller's and the normalized flags,
  x all 16 callback sets (and high flag bits for output_flags);
- versioned_id over 8 ids (NULL, empty, '%' sequences, bytes outside
  ASCII) x 11 versions around both ends of int;
- the whole decision of obs_register_source_s(): each side's five
  functions in the C's order, the copy cut at the size, for 5 types x
  32 flag sets x 3 callback sets x 28 sizes around every field end the
  registration reads;
- six 2048-case proptests: any type, size, flags, callback bits, id
  and version, and the registration over type, flags, size, callback
  mask and version.

Refs obs-rust#1876
…ration rules

- rust/README.md: obs-module-source-rules.c.h in the obs-core crate row,
  and its row in the port table (what moved, what stays C, the
  characterized cases, no intentional 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_source_rules/list_of, size_supported,
  output_flags, check and versioned_id (unversioned and versioned), in
  their own file.

Refs obs-rust#1876
@rdoupe
rdoupe force-pushed the port/obs-module-slice4 branch from fc720ab to f060068 Compare October 23, 2026 15:38
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 23, 2026
@zackees
zackees added this pull request to the merge queue Oct 23, 2026
@zackees zackees mentioned this pull request Oct 23, 2026
6 of 7 tasks
Merged via the queue into obs-rust:master with commit 20839ad Oct 23, 2026
33 checks passed
MCPVOT pushed a commit to MCPVOT/obs-studio that referenced this pull request Oct 30, 2026
…-rust#1997) (obs-rust#2554)

* test: require the port_comparison units to be discovered, not listed (obs-rust#1997)

RED: the ci test demanded the hand-kept `#[path] mod` lines and the
`modules![...]` call in `port_comparison.rs` stay sorted. It now fails if
either list exists and requires the two generated includes instead.

`uv run -m unittest discover -s ci -p test_sorted_shared_lists.py`:
test_port_comparison_units_are_discovered FAILs, assertNotRegex matched
`#[path = "port_comparison/audio.rs"]`.

* build: Generate the port_comparison unit list from the directory (obs-rust#1997)

GREEN: build.rs enumerates benches/port_comparison/*.rs and writes the
#[path] module lines and the run_units() call list into OUT_DIR, so a port
adds its own file and edits nothing shared. That was the last hand-kept
list every port appended to; two ports on one file collided in the merge
queue (obs-rust#1922 vs obs-rust#1928, obs-rust#1929 vs obs-rust#1922).

The file stem is the module name, so core.rs becomes core_units.rs (a
`mod core` at the crate root would make the units' `use core::ffi` paths
ambiguous). Absolute #[path] rather than `mod x { include!() }` because
the units open with //! inner docs, which include! cannot carry.

Verified: `soldr cargo check -p obs-c-oracle --benches` is clean, and a
throwaway zzz_probe.rs appeared in the generated run_units() and compiled
with no edit to a shared file. ci/test_sorted_shared_lists.py passes.
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