Skip to content

obs-source: port obs_source_filter_remove to Rust (Fixes #5795) - #5796

Merged
rdoupe merged 4 commits into
masterfrom
port/5795-filter-remove
Nov 27, 2026
Merged

rdoupe merged 4 commits into
masterfrom
port/5795-filter-remove

Conversation

@rdoupe

@rdoupe rdoupe commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #5795.

Ports obs_source_filter_remove() to obs-source, together with its step obs_source_filter_remove_refless(). obs_source_destroy() still calls that step directly for a filter leaving its parent, so it stays reachable from C as a hidden entry: declared in obs-internal.h without EXPORT, listed in rust-hidden.d/obs-source-source_filter_remove.txt. The retarget decision was already Rust (source_filter_chain::remove_retarget); the core reuses it.

What stays C: the lock, the list read and da_erase(), the target read and write, the calldata and both signals (one adapter, so a handler that rewrites the calldata is seen by the second signal as before), the debug line, the filter_remove callback check and call, clearing the parent and target, and obs_source_release(). The Rust core reaches them through hidden, non-EXPORT adapters in libobs/obs-source-filter-remove-fields.c.h, in the live core-source group. The extracted C builds in the reference group libobs.ported-source-filter-remove for Tier 3.

The four commits, in order:

  1. Extract (libobs: extract … verbatim): both functions move unchanged into libobs/obs-source-filter-remove.c.h. The refless step loses its static, and obs-internal.h declares it in place of the static forward declaration in obs-source.c.h. No behavior change.
  2. Characterize (test: characterize …): new cmocka test test_source_filter_remove, run through the real core against both hybrid libobs and the C reference. It covers:
    • NULL arguments: one log line, source checked first, nothing released.
    • An unlisted filter (loose, on another source, or the source itself): nothing changes and nothing is released.
    • Removing the middle, first and last entry: the entry before takes the removed filter's target (none for the first). Then the global and source signals fire, with the list already shortened, the parent still set and filter_mutex free (probed from a second thread, since the mutex is recursive). Then the debug line, the callback with the parent (a type without one skips only the call), the parent and target cleared, and exactly one release (checked with a weak reference).
    • Destroying a source removes its filters the same way, from the first entry.
  3. RED (test: RED … safe core): Tier 1 mirrors over a todo!() core.
  4. GREEN: the swap and the Tier 3 differential.

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

One difference, unreachable: a NULL source passed to the hidden refless step returns false without a call. The original would follow the pointer, but its only caller (obs_source_destroy()) passes filter_parent after checking it is set.

RED

soldr cargo test -p obs-data --test obs-tests-core -- source::filter_remove::
test result: FAILED. 0 passed; 5 failed; 0 ignored; 0 measured; 6893 filtered out
panicked at rust/obs-source/src/filter_remove.rs:80:5: not yet implemented: #5795

GREEN

Tier 1 and Tier 3, on the pushed head (rebased onto #5794):

soldr cargo test -p obs-data --test obs-tests-core -- source::filter_remove source::copy_filters source::filter_set_order
test result: ok. 27 passed; 0 failed
  • What Tier 3 compares: filter_remove_parity, with oracle/source_filter_remove.c, runs the original C and the Rust exports on noise-filled sources built from the real headers. The source and a stand-in core each have a real signal handler, and obs_source_release() is a recording stand-in. It records every signal (calldata source and filter, the list length), callback (the parent passed and the filter's parent field), release and log line in order, each with the lock state. It then compares those, the list, every filter's target and parent, the return value, every other fixture byte, the lock afterwards and the last log line.
  • What Tier 3 covers: every chain of up to 7 filters, every listed filter plus an unlisted and a NULL one, every callback pattern (sampled past 4 filters), both entry points, the NULL-argument cases and a proptest.
  • Mutants: Tier 3 rejects five mutants: no retarget, no cleared links, signal under the lock, callback skipped, and no release.
  • Mutation check: running the callback after the links are cleared fails 3 Tier 1 tests and the Tier 3 test (reverted).
  • Test cost: Tier 1 0.01 s; parity 0.20 s at reduced, 1.09 s at full (debug, including the isolated child for the log handler); peak RSS 13.6 MB; no threads of its own.

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

OBS_CTEST_JOBS=10 uv run rust/tools/linux-validate/run.py --repeat 1 --tests 'test_source_filter_remove|test_filter_skip_removed|test_source_filter_chain_steps|test_source_filter_set_order|test_filter_|test_source_enum_filters|test_source_filter_index|test_source_copy_filters|test_source_duplicate|test_ws_filter|test_scene_dup'
IDENTICAL (1769 symbols)
[OFF] (C reference)  100% tests passed, 0 tests failed out of 1126
                     repeat of the filtered set: 100% tests passed, 0 tests failed out of 18
[ON]  (hybrid)       100% tests passed, 0 tests failed out of 1126
                     repeat of the filtered set: 100% tests passed, 0 tests failed out of 18

Run directly under xvfb-run, test_source_filter_remove shows [ PASSED ] 6 test(s) against both libraries, none skipped. I got the same result on the characterization commit, with nothing swapped.

Registration:

soldr cargo test -p obs-studio-rust --test obs-tests-app -- canonical_source_filter_remove canonical_source_copy_filters
test result: ok. 2 passed; 0 failed

./lint passes. ./push ran the client lint and test lanes, which passed. 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 19:00
Move obs_source_filter_remove() and obs_source_filter_remove_refless()
unchanged out of obs-source.c.h into obs-source-filter-remove.c.h, still
compiled in the live core-source group. obs_source_filter_remove_refless()
keeps its body and loses its `static`: obs_source_destroy() calls it for a
filter leaving its parent, so obs-internal.h now declares it (hidden, no
EXPORT) in place of the static forward declaration, because the new file
comes before obs-source.c.h in the unity group. 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 does nothing; a
filter on no list, on another source's list, or the source itself changes
nothing and is not released. A listed filter is erased; when it was not
the first entry, the entry before it takes its target. Then, with
filter_mutex free (probed from a second thread, the mutex is recursive),
the global source_filter_remove and the source's filter_remove signals
fire with the list already shortened and the filter's parent still set,
the debug line is logged, the type's filter_remove callback runs with the
parent (a type without one skips only that), the parent and target are
cleared, and the list's reference is released once. Destroying a source
removes its filters the same way, from the first entry.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
New obs-source module filter_remove with todo!() cores (remove,
remove_refless) over a FilterList trait, and Tier 1 mirrors of
test_source_filter_remove.c on a model that records every call: the NULL
lines (source first) with nothing touched; an unlisted filter read
through the whole list under the lock, then unlocked, nothing else; and
on every chain of up to 7 filters, every entry, with and without the
type's callback, through both entry points, the C's order: the lookup,
the entry before taking the removed one's target (none for the first),
the erase, the unlock, the signals, the log line, the callback check and
call, the cleared links, then one release (obs_source_filter_remove only).
Draining from the first entry removes each filter once in list order.

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

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Safe core filter_remove::{remove, remove_refless} over the FilterList
trait, with source_filter_chain's retarget rule, and the shims in
ffi::source_filter_remove: the exported obs_source_filter_remove()
(rust-exports.d) and the hidden obs_source_filter_remove_refless() that
obs_source_destroy() calls (rust-hidden.d; declared in obs-internal.h
without EXPORT). The shims reject NULL before any adapter runs; the lock,
count, entry, target read and write, da_erase(), unlock, the two signals
on one calldata, the debug line, the callback check and call, the cleared
links and obs_source_release() stay C in the new
obs-source-filter-remove-fields.c.h (live core-source group, no EXPORT).
The extracted C moves to the reference-only group
libobs.ported-source-filter-remove.

Tier 3 (filter_remove_parity, oracle source_filter_remove.c): the
original C and the Rust exports on noise-filled real-header sources with
real signal handlers on the source and a stand-in core, over every chain
of up to 7 filters, every listed filter plus an unlisted and a NULL one,
every callback pattern, both entry points and a proptest. It compares the
list, every target and parent, the return value, each signal, callback,
release 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":1795738856,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["084f6411e32a9f5ea69af897ae0e77476affa818"],"secs":93,"stamp":"ba11c38a1247292e7e8373dddcb206f2","tree":"03be075205fc84779b490d42a62cdf97cf454600","v":1,"via":"run"}
Ci-Attestation: {"at":1795738856,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["084f6411e32a9f5ea69af897ae0e77476affa818"],"secs":93,"stamp":"3858c593921ddb13e53e51245f4cb096","tree":"03be075205fc84779b490d42a62cdf97cf454600","v":1,"via":"run"}
Ci-Attestation: {"at":1795738856,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["084f6411e32a9f5ea69af897ae0e77476affa818"],"secs":93,"stamp":"57a59905ae1ff0e1773f143f1717ad03","tree":"03be075205fc84779b490d42a62cdf97cf454600","v":1,"via":"run"}
Ci-Attestation: {"at":1795738856,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["084f6411e32a9f5ea69af897ae0e77476affa818"],"secs":93,"stamp":"b27a4e8ac2c0b5ed447daa129859142b","tree":"03be075205fc84779b490d42a62cdf97cf454600","v":1,"via":"run"}
Ci-Attestation: {"at":1795738762,"gate":"general/all/client-lint","host":"linux-x86_64","key":"1148efbc40c1b76fbfcbc3b64d6fc8605bbd15ec9f8305831c68242928b6e630","lane":"client-lint","parents":["084f6411e32a9f5ea69af897ae0e77476affa818"],"secs":74,"stamp":"b3afd9b8b7e893491cd72891b37fbbf1","tree":"03be075205fc84779b490d42a62cdf97cf454600","v":1,"via":"run"}
Ci-Attestation: {"at":1795738856,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["084f6411e32a9f5ea69af897ae0e77476affa818"],"secs":93,"stamp":"590ea97ee986a2d9e69b23c7dc7a9b91","tree":"03be075205fc84779b490d42a62cdf97cf454600","v":1,"via":"run"}
Ci-Attestation: {"at":1795738762,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"1148efbc40c1b76fbfcbc3b64d6fc8605bbd15ec9f8305831c68242928b6e630","lane":"client-lint","parents":["084f6411e32a9f5ea69af897ae0e77476affa818"],"secs":74,"stamp":"589619d13392f5dabb32744c3c42dd1e","tree":"03be075205fc84779b490d42a62cdf97cf454600","v":1,"via":"run"}
Ci-Attestation: {"at":1795738762,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"1148efbc40c1b76fbfcbc3b64d6fc8605bbd15ec9f8305831c68242928b6e630","lane":"client-lint","parents":["084f6411e32a9f5ea69af897ae0e77476affa818"],"secs":74,"stamp":"672d936ed0350f2ab24043cd9f6b7c13","tree":"03be075205fc84779b490d42a62cdf97cf454600","v":1,"via":"run"}
Ci-Attestation: {"at":1795738762,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"1148efbc40c1b76fbfcbc3b64d6fc8605bbd15ec9f8305831c68242928b6e630","lane":"client-lint","parents":["084f6411e32a9f5ea69af897ae0e77476affa818"],"secs":74,"stamp":"5912a82e1966552649da42495c5eae3d","tree":"03be075205fc84779b490d42a62cdf97cf454600","v":1,"via":"run"}
Ci-Attestation: {"at":1795738762,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"1148efbc40c1b76fbfcbc3b64d6fc8605bbd15ec9f8305831c68242928b6e630","lane":"client-lint","parents":["084f6411e32a9f5ea69af897ae0e77476affa818"],"secs":74,"stamp":"09694a266210772b011cb8771f329267","tree":"03be075205fc84779b490d42a62cdf97cf454600","v":1,"via":"run"}
Ci-Attestation: {"at":1795738762,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"1148efbc40c1b76fbfcbc3b64d6fc8605bbd15ec9f8305831c68242928b6e630","lane":"client-lint","parents":["084f6411e32a9f5ea69af897ae0e77476affa818"],"secs":74,"stamp":"8c0d1f5cde93980c9ec80fe089842328","tree":"03be075205fc84779b490d42a62cdf97cf454600","v":1,"via":"run"}
Ci-Attestation: {"at":1795738762,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"1148efbc40c1b76fbfcbc3b64d6fc8605bbd15ec9f8305831c68242928b6e630","lane":"client-lint","parents":["084f6411e32a9f5ea69af897ae0e77476affa818"],"secs":74,"stamp":"3c436070c0da829129537d6728d54bd4","tree":"03be075205fc84779b490d42a62cdf97cf454600","v":1,"via":"run"}
Ci-Attestation: {"at":1795738762,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"1148efbc40c1b76fbfcbc3b64d6fc8605bbd15ec9f8305831c68242928b6e630","lane":"client-lint","parents":["084f6411e32a9f5ea69af897ae0e77476affa818"],"secs":74,"stamp":"6c5402bc20da5e004f2012d4ec409345","tree":"03be075205fc84779b490d42a62cdf97cf454600","v":1,"via":"run"}
Ci-Attestation: {"at":1795738762,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"1148efbc40c1b76fbfcbc3b64d6fc8605bbd15ec9f8305831c68242928b6e630","lane":"client-lint","parents":["084f6411e32a9f5ea69af897ae0e77476affa818"],"secs":74,"stamp":"09fad6e10779d932c0f5fef3af93d286","tree":"03be075205fc84779b490d42a62cdf97cf454600","v":1,"via":"run"}
Ci-Attestation: {"at":1795738762,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"1148efbc40c1b76fbfcbc3b64d6fc8605bbd15ec9f8305831c68242928b6e630","lane":"client-lint","parents":["084f6411e32a9f5ea69af897ae0e77476affa818"],"secs":74,"stamp":"fda12635b9867bb22c83f8fc759897ac","tree":"03be075205fc84779b490d42a62cdf97cf454600","v":1,"via":"run"}
Ci-Attestation: {"at":1795738762,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"1148efbc40c1b76fbfcbc3b64d6fc8605bbd15ec9f8305831c68242928b6e630","lane":"client-lint","parents":["084f6411e32a9f5ea69af897ae0e77476affa818"],"secs":74,"stamp":"d1f0828f57c5e5bb8cdc7a5eff4eb352","tree":"03be075205fc84779b490d42a62cdf97cf454600","v":1,"via":"run"}
Ci-Attestation: {"at":1795738762,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"1148efbc40c1b76fbfcbc3b64d6fc8605bbd15ec9f8305831c68242928b6e630","lane":"client-lint","parents":["084f6411e32a9f5ea69af897ae0e77476affa818"],"secs":74,"stamp":"1e62a589de6e3c3f187a19a93129b443","tree":"03be075205fc84779b490d42a62cdf97cf454600","v":1,"via":"run"}
Ci-Attestation: {"at":1795738762,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"1148efbc40c1b76fbfcbc3b64d6fc8605bbd15ec9f8305831c68242928b6e630","lane":"client-lint","parents":["084f6411e32a9f5ea69af897ae0e77476affa818"],"secs":74,"stamp":"83f7db4458cb1c1eb2979237279929cc","tree":"03be075205fc84779b490d42a62cdf97cf454600","v":1,"via":"run"}
Ci-Attestation: {"at":1795739142,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"47fbe766174d79b3310ea69595a66f74931f27ceb7c7554c50cdd49e46e4c7e3","lane":"client-test-x86_64-unknown-linux-gnu","parents":["084f6411e32a9f5ea69af897ae0e77476affa818"],"secs":286,"stamp":"191b60a63cd4334c3d7ad1b62ae25db4","tree":"03be075205fc84779b490d42a62cdf97cf454600","v":1,"via":"run"}

Client-Checks: {"checks":{"base":"b60190ad98359dd62cc0dc47ed12bc6772c3431e","coverage":"all-tracked-applicable-files","diff":[".github/workflows/build-project.yaml","build-aux/flatpak/ninja.cmake","build-aux/io.github.obs_rust.OBSStudioRust.json","ci.toml","ci/cache_metrics.py","ci/flatpak_cache_probe.py","ci/flatpak_compiler_cache.py","ci/flatpak_compiler_diagnostics.py","ci/flatpak_pch_probe.py","ci/flatpak_pruned_build_probe.py","ci/scope_exemptions.txt","ci/test_cache_metrics.py","ci/test_ci_toml.py","ci/test_flatpak_build_script.py","ci/test_flatpak_compiler_diagnostics.py","ci/test_hybrid_packaging.py","ci/test_zccache.py","docs/ci-speed-flatpak-pch-1760.md","docs/ci-tooling.md","docs/zccache-flatpak-migration-note.md","libobs/build/libobs.core-source+.h.c","libobs/build/libobs.ported-source-filter-remove+.h.c","libobs/build/ported-source-sets/source-filter-remove.json","libobs/cmake/rust-exports.d/obs-source-source_filter_remove.txt","libobs/cmake/rust-hidden.d/obs-source-source_filter_remove.txt","libobs/obs-internal.h","libobs/obs-source-filter-remove-fields.c.h","libobs/obs-source-filter-remove.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_remove_swap_is_registered.rs","rust/obs-c-oracle/oracle.d/source-filter-remove.list","rust/obs-c-oracle/oracle/source_filter_remove.c","rust/obs-source/Cargo.toml","rust/obs-source/src/ffi/mod.rs","rust/obs-source/src/ffi/source_filter_remove.rs","rust/obs-source/src/filter_remove.rs","rust/obs-source/src/lib.rs","rust/obs-source/tests/source/filter_remove.rs","rust/obs-source/tests/source/filter_remove_parity.rs","rust/obs-source/tests/source/main.rs","test/cmocka/build/test-graph.json","test/cmocka/test_source_filter_remove.c","test/cmocka/tests.d/test_source_filter_remove.cmake"],"head":"30017f40584f9616a89745ea7f38a6a44711e15e","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":"d8fdf9ec4374988b123591abf56f4ab38483d30c4d9c4d846ca23fad52812cfe","tree":"03be075205fc84779b490d42a62cdf97cf454600"}}
@rdoupe
rdoupe requested a review from zackees as a code owner November 27, 2026 00:26
@rdoupe
rdoupe enabled auto-merge November 27, 2026 00:56
@rdoupe
rdoupe added this pull request to the merge queue Nov 27, 2026
Merged via the queue into master with commit c4c8e38 Nov 27, 2026
48 checks passed
@rdoupe
rdoupe deleted the port/5795-filter-remove branch November 27, 2026 01:31
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_remove to obs-source

1 participant