Skip to content

obs-source: port obs_source_filter_add to Rust (Fixes #5799) - #5800

Merged
rdoupe merged 4 commits into
masterfrom
port/5799-filter-add
Nov 27, 2026
Merged

rdoupe merged 4 commits into
masterfrom
port/5799-filter-add

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #5799.

Ports obs_source_filter_add() to obs-source. The safe core filter_add::add runs over a FilterList trait and reuses source_filter_chain's add gates, compatibility rule, reference step and add target. The exported entry is the shim in ffi::source_filter_add (listed in rust-exports.d); it rejects NULL before any adapter runs.

What stays C: the lock, the count and entry reads, the parent read, the "already present" warning, the info id and output flags, obs_source_get_ref(), the parent and target writes, da_insert() at index 0, the unlock, the two signals on one calldata, the debug line, and the filter_add callback check and call. The Rust core reaches them through hidden, non-EXPORT adapters in libobs/obs-source-filter-add-fields.c.h, in the live core-source group. The extracted C builds in the reference group libobs.ported-source-filter-add for Tier 3.

The four commits, in order:

  1. Extract: obs_source_filter_add() moves unchanged into libobs/obs-source-filter-add.c.h, still in the live core-source group. No behavior change.
  2. Characterize: new cmocka test test_source_filter_add, through the real core against both hybrid libobs and the C reference. It covers:
    • NULL source or filter: the validity line once (source first), nothing referenced.
    • A filter already on the list, or parented on another source: the "already present" warning with filter_mutex held (probed from a second thread, the mutex is recursive), nothing changed.
    • An audio filter on a video source is refused without a line; a source whose type is missing (it owns its info id) takes it.
    • A filter whose last reference is gone (re-added from its child's filter_remove callback during destruction): the 'filter' validity line, not added.
    • Otherwise each filter goes to the front holding its own reference, parent the source, target the old first filter (the source on an empty list); then, with filter_mutex free, the global and source filter_add signals fire with the list already holding it, the debug line is logged, and the type's callback runs with the parent (a type without one skips only that).
  3. RED: Tier 1 mirrors over a todo!() core.
  4. GREEN: the swap, the Tier 3 differential and the registration test.

No public-header, existing-C-test, WebSocket or workflow edits. Tier 4 does not apply. No user-visible change, so no features ledger line.

RED

soldr cargo test -p obs-data --test obs-tests-core -- source::filter_add::
test result: FAILED. 0 passed; 6 failed
panicked at rust/obs-source/src/filter_add.rs:86:5: not yet implemented: #5799

GREEN

Tier 1 and Tier 3, on the pushed head (rebased onto current master):

soldr cargo test -p obs-data --test obs-tests-core -- source::filter_add
test result: ok. 7 passed; 0 failed; 0 ignored; 0 measured; 6913 filtered out; finished in 1.35s
  • What Tier 3 compares: filter_add_parity, with oracle/source_filter_add.c, runs the original C and the Rust export on noise-filled sources built from the real headers, with real signal handlers on the source and a stand-in core and a recording obs_source_get_ref(). It compares the list, every target and parent, each reference, signal, callback and log line in order with the lock state, every other fixture byte, the lock afterwards and the last log line.
  • What Tier 3 covers: every chain of up to 7 filters; every filter of the fixture listed or not, parented elsewhere or not; with and without its callback; four flag pairs; with and without an owned info id; a failed reference; and a proptest.
  • Mutants: Tier 3 rejects five: no parent write, the source as target, signal under the lock, callback skipped, and no warning.

Tier 2, the C test run unchanged against both libraries:

OBS_CTEST_JOBS=10 uv run rust/tools/linux-validate/run.py --repeat 1 --tests 'test_source_filter_add'
100% tests passed, 0 tests failed out of 1127
[ON] repeat of the filtered set: 100% tests passed, 0 tests failed out of 1

Run directly under xvfb-run, test_source_filter_add shows [ PASSED ] 5 test(s) against hybrid libobs and against libobs-c-reference (ldd confirms which library loads), none skipped.

Registration:

soldr cargo test -p obs-studio-rust --test obs-tests-app -- source_filter_add
test native_build::canonical_source_filter_add_swap_is_registered::canonical_source_filter_add_swap_is_registered ... ok

./lint passes. The final commit is not signed here, so the PR runs the full selected CI.

🤖 Generated with Claude Code

rdoupe and others added 4 commits November 26, 2026 20:47
Move obs_source_filter_add() unchanged out of obs-source.c.h into
obs-source-filter-add.c.h, still compiled in the live core-source group.
It is EXPORT and declared in obs.h, and filter_compatible() is already
declared in obs-internal.h, so the earlier position in the unity group
needs no new declaration. No Rust, no behavior change.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
New cmocka test through the real core (xvfb-run, skips without a display),
against hybrid libobs and the C reference: a NULL source or filter logs
the validity check's line once (the source first) and references nothing;
a filter already on the list, or one with a parent on another source,
logs the "already present" warning with filter_mutex held (probed from a
second thread, the mutex is recursive) and changes nothing; an audio
filter on a video source is refused without a line, while a source whose
type is missing (it owns its info id) takes it; a filter whose last
reference is gone (re-added from its own child's filter_remove callback
while it is destroyed) logs the 'filter' validity line and is not added.
Otherwise each filter goes to the front of the list holding its own
reference, its parent the source and its target the old first filter (the
source on an empty list); then, with filter_mutex free, the global
source_filter_add and the source's filter_add signals fire with the list
already holding it, the debug line is logged, and the type's filter_add
callback runs with the parent (a type without one skips only that).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
New obs-source module filter_add with a todo!() core over a FilterList
trait, and Tier 1 mirrors of test_source_filter_add.c on a model that
records every call: the NULL lines (source first) with nothing touched;
on every chain of up to 6 filters, with and without the type's callback,
on a source that owns its info id or not, the C's order: the lookup and
the parent read under the lock, the info id check and (when it applies)
the two output flags, the reference, the parent, the count and old first
filter for the target, the insert at the front, the unlock, the signals,
the log line, the callback check and call. Every listed entry and a
filter parented elsewhere warn under the lock and unlock; over every
flag pair, a filter that does not fit is refused without a line unless
the source owns its info id; a filter that can't be referenced logs the
'filter' line and unlocks; successive adds chain each to the previous.

    soldr cargo test -p obs-data --test obs-tests-core -- source::filter_add::
    test result: FAILED. 0 passed; 6 failed
    panicked at rust/obs-source/src/filter_add.rs:86:5: not yet implemented: #5799

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Safe core filter_add::add over the FilterList trait, with
source_filter_chain's add gates, compatibility rule, ref step and add
target, and the shim in ffi::source_filter_add: the exported
obs_source_filter_add() (rust-exports.d). The shim rejects NULL before any
adapter runs; the lock, count, entry, parent read, the "already present"
warning, the info id and output flags, obs_source_get_ref(), the parent
and target writes, da_insert() at index 0, the unlock, the two signals on
one calldata, the debug line and the callback check and call stay C in
the new obs-source-filter-add-fields.c.h (live core-source group, no
EXPORT). The extracted C moves to the reference-only group
libobs.ported-source-filter-add.

Tier 3 (filter_add_parity, oracle source_filter_add.c): the original C
and the Rust export on noise-filled real-header sources with real signal
handlers on the source and a stand-in core and a recording
obs_source_get_ref(), over every chain of up to 7 filters, every filter
of the fixture listed or not, parented elsewhere or not, with and without
its callback, four flag pairs, with and without an owned info id and a
failed reference, and a proptest. It compares the list, every target and
parent, each reference, signal, callback and log line in order with the
lock state, every other byte, the lock after and the last log line, and
rejects five mutants. Registration test in obs-build; rust/README row.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Ci-Attestation: {"at":1795745180,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["e2337ac685b92a852b8b16fcae0ccf9baf4bac37"],"secs":97,"stamp":"75ecfa68847da50faf8096c4500b0a37","tree":"6193de933fe9f46ee6677d796f5b477fe9781352","v":1,"via":"run"}
Ci-Attestation: {"at":1795745180,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["e2337ac685b92a852b8b16fcae0ccf9baf4bac37"],"secs":97,"stamp":"7ab00d83bd371503893025c71fd54bb8","tree":"6193de933fe9f46ee6677d796f5b477fe9781352","v":1,"via":"run"}
Ci-Attestation: {"at":1795745180,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["e2337ac685b92a852b8b16fcae0ccf9baf4bac37"],"secs":97,"stamp":"c4519b29b6000a9b736bf7a4816121ba","tree":"6193de933fe9f46ee6677d796f5b477fe9781352","v":1,"via":"run"}
Ci-Attestation: {"at":1795745180,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["e2337ac685b92a852b8b16fcae0ccf9baf4bac37"],"secs":97,"stamp":"1c9674beb4f73f567362af269c7eed9c","tree":"6193de933fe9f46ee6677d796f5b477fe9781352","v":1,"via":"run"}
Ci-Attestation: {"at":1795745082,"gate":"general/all/client-lint","host":"linux-x86_64","key":"f2d4cff0530bc8f8a2b0c11ec85aa9ba4807d944aaf44897523959ffd266070c","lane":"client-lint","parents":["e2337ac685b92a852b8b16fcae0ccf9baf4bac37"],"secs":69,"stamp":"8c54f07719e7dc5669d101fbe2175b98","tree":"6193de933fe9f46ee6677d796f5b477fe9781352","v":1,"via":"run"}
Ci-Attestation: {"at":1795745180,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["e2337ac685b92a852b8b16fcae0ccf9baf4bac37"],"secs":97,"stamp":"5ddabdc22bc89f243e95e44ca7cefb24","tree":"6193de933fe9f46ee6677d796f5b477fe9781352","v":1,"via":"run"}
Ci-Attestation: {"at":1795745083,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"f2d4cff0530bc8f8a2b0c11ec85aa9ba4807d944aaf44897523959ffd266070c","lane":"client-lint","parents":["e2337ac685b92a852b8b16fcae0ccf9baf4bac37"],"secs":69,"stamp":"da3c6055275f5c530c27e7ca8767e8da","tree":"6193de933fe9f46ee6677d796f5b477fe9781352","v":1,"via":"run"}
Ci-Attestation: {"at":1795745083,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"f2d4cff0530bc8f8a2b0c11ec85aa9ba4807d944aaf44897523959ffd266070c","lane":"client-lint","parents":["e2337ac685b92a852b8b16fcae0ccf9baf4bac37"],"secs":69,"stamp":"5a83f3664350a0eeb767d861de88a3e0","tree":"6193de933fe9f46ee6677d796f5b477fe9781352","v":1,"via":"run"}
Ci-Attestation: {"at":1795745083,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"f2d4cff0530bc8f8a2b0c11ec85aa9ba4807d944aaf44897523959ffd266070c","lane":"client-lint","parents":["e2337ac685b92a852b8b16fcae0ccf9baf4bac37"],"secs":69,"stamp":"ee369276e761cad07967c9c4f8a86366","tree":"6193de933fe9f46ee6677d796f5b477fe9781352","v":1,"via":"run"}
Ci-Attestation: {"at":1795745083,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"f2d4cff0530bc8f8a2b0c11ec85aa9ba4807d944aaf44897523959ffd266070c","lane":"client-lint","parents":["e2337ac685b92a852b8b16fcae0ccf9baf4bac37"],"secs":69,"stamp":"6966519a58b0fd52f3a75a903ffb56df","tree":"6193de933fe9f46ee6677d796f5b477fe9781352","v":1,"via":"run"}
Ci-Attestation: {"at":1795745082,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"f2d4cff0530bc8f8a2b0c11ec85aa9ba4807d944aaf44897523959ffd266070c","lane":"client-lint","parents":["e2337ac685b92a852b8b16fcae0ccf9baf4bac37"],"secs":69,"stamp":"206d3869f0f19007b4218b7e90e88b19","tree":"6193de933fe9f46ee6677d796f5b477fe9781352","v":1,"via":"run"}
Ci-Attestation: {"at":1795745082,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"f2d4cff0530bc8f8a2b0c11ec85aa9ba4807d944aaf44897523959ffd266070c","lane":"client-lint","parents":["e2337ac685b92a852b8b16fcae0ccf9baf4bac37"],"secs":69,"stamp":"cb8479667049290ea599401eba7ca350","tree":"6193de933fe9f46ee6677d796f5b477fe9781352","v":1,"via":"run"}
Ci-Attestation: {"at":1795745083,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"f2d4cff0530bc8f8a2b0c11ec85aa9ba4807d944aaf44897523959ffd266070c","lane":"client-lint","parents":["e2337ac685b92a852b8b16fcae0ccf9baf4bac37"],"secs":69,"stamp":"192c9f12968cf99fe0cd45c1935ff0f9","tree":"6193de933fe9f46ee6677d796f5b477fe9781352","v":1,"via":"run"}
Ci-Attestation: {"at":1795745083,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"f2d4cff0530bc8f8a2b0c11ec85aa9ba4807d944aaf44897523959ffd266070c","lane":"client-lint","parents":["e2337ac685b92a852b8b16fcae0ccf9baf4bac37"],"secs":69,"stamp":"ea8cfde7abb7e5396c7f5382a13d45e1","tree":"6193de933fe9f46ee6677d796f5b477fe9781352","v":1,"via":"run"}
Ci-Attestation: {"at":1795745083,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"f2d4cff0530bc8f8a2b0c11ec85aa9ba4807d944aaf44897523959ffd266070c","lane":"client-lint","parents":["e2337ac685b92a852b8b16fcae0ccf9baf4bac37"],"secs":69,"stamp":"94214b0ba0ea0c15fdb8b1d2ccedbfcb","tree":"6193de933fe9f46ee6677d796f5b477fe9781352","v":1,"via":"run"}
Ci-Attestation: {"at":1795745083,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"f2d4cff0530bc8f8a2b0c11ec85aa9ba4807d944aaf44897523959ffd266070c","lane":"client-lint","parents":["e2337ac685b92a852b8b16fcae0ccf9baf4bac37"],"secs":69,"stamp":"38b4967646a8a5d4337abd78d4f00205","tree":"6193de933fe9f46ee6677d796f5b477fe9781352","v":1,"via":"run"}
Ci-Attestation: {"at":1795745082,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"f2d4cff0530bc8f8a2b0c11ec85aa9ba4807d944aaf44897523959ffd266070c","lane":"client-lint","parents":["e2337ac685b92a852b8b16fcae0ccf9baf4bac37"],"secs":69,"stamp":"6210ecef07d920a99bff0c62cb82989e","tree":"6193de933fe9f46ee6677d796f5b477fe9781352","v":1,"via":"run"}
Ci-Attestation: {"at":1795745082,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"f2d4cff0530bc8f8a2b0c11ec85aa9ba4807d944aaf44897523959ffd266070c","lane":"client-lint","parents":["e2337ac685b92a852b8b16fcae0ccf9baf4bac37"],"secs":69,"stamp":"49c77b4090264e5af8f54591f14d1310","tree":"6193de933fe9f46ee6677d796f5b477fe9781352","v":1,"via":"run"}
Ci-Attestation: {"at":1795745430,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"eae314ef606ac643113b9b4ad20ed7e801eb4c1f02a74429cbd391ea8358b2a5","lane":"client-test-x86_64-unknown-linux-gnu","parents":["e2337ac685b92a852b8b16fcae0ccf9baf4bac37"],"secs":250,"stamp":"f023fdf74b955c77e3c3689b88392d86","tree":"6193de933fe9f46ee6677d796f5b477fe9781352","v":1,"via":"run"}

Client-Checks: {"checks":{"base":"b152594daca3044db3bbaad0f73aa8e25da57c6a","coverage":"all-tracked-applicable-files","diff":["libobs/build/libobs.core-source+.h.c","libobs/build/libobs.ported-source-filter-add+.h.c","libobs/build/ported-source-sets/source-filter-add.json","libobs/cmake/rust-exports.d/obs-source-source_filter_add.txt","libobs/obs-source-filter-add-fields.c.h","libobs/obs-source-filter-add.c.h","libobs/obs-source.c.h","rust/README.md","rust/obs-build/tests/native.rs","rust/obs-build/tests/native/registration/canonical_source_filter_add_swap_is_registered.rs","rust/obs-c-oracle/oracle.d/source-filter-add.list","rust/obs-c-oracle/oracle/source_filter_add.c","rust/obs-source/Cargo.toml","rust/obs-source/src/ffi/mod.rs","rust/obs-source/src/ffi/source_filter_add.rs","rust/obs-source/src/filter_add.rs","rust/obs-source/src/lib.rs","rust/obs-source/tests/source/filter_add.rs","rust/obs-source/tests/source/filter_add_parity.rs","rust/obs-source/tests/source/main.rs","test/cmocka/build/test-graph.json","test/cmocka/test_source_filter_add.c","test/cmocka/tests.d/test_source_filter_add.cmake"],"head":"a618826ac0e3df873746467e18f75853e6a12b49","tools":{"orchestrator-python":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]","schema-dependencies":"3.13.16 (main, Oct 14 2026, 01:04:01) [Clang 23.1.3 ]\n{'jsonschema': '4.26.0', 'json_source_map': '1.0.5'}","uv":"uv 0.13.5 (x86_64-unknown-linux-gnu)","xmllint":"xmllint: using libxml version 21504-GITv2.15.4\n   compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 DTDValid HTML C14N Catalog XPath XPointer XInclude Iconv ICU ISO8859X Regexps Automata RelaxNG Schemas Schematron Modules Debug Zlib"},"tracked-digest":"5aa7a053673baa626998f03a16a58d8e74449aa5d8fc5c2d195916322f20ae36","tree":"6193de933fe9f46ee6677d796f5b477fe9781352"}}
@rdoupe
rdoupe requested a review from zackees as a code owner November 27, 2026 02:10
@obs-rust-project-manager obs-rust-project-manager Bot moved this to Ready to merge in obs-rust Multiview Nov 27, 2026
@rdoupe
rdoupe added this pull request to the merge queue Nov 27, 2026
Merged via the queue into master with commit 28261c4 Nov 27, 2026
48 checks passed
@rdoupe
rdoupe deleted the port/5799-filter-add branch November 27, 2026 03:41
@obs-rust-project-manager obs-rust-project-manager Bot moved this from Ready to merge to Done in obs-rust Multiview Nov 27, 2026
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.

rust: Port obs_source_filter_add to obs-source

1 participant