Repository navigation
obs-source: Port the source colour space query routing - #1990
Merged
Merged
Conversation
…ace.c Behaviour-neutral extraction before the Rust port. The decisions of obs_source_get_color_space() in obs-source.c.h move to libobs/obs-source-color-space.c.h as two pure functions, declared in the new libobs/obs-source-color-space.h without EXPORT (hidden, as -fvisibility=hidden keeps them): - obs_source_color_space_route(): which source answers. A non-filter source with no video asks its filter parent; a filter with no video asks its target (obs-rust#1493); a source with no data, or a disabled one, asks its target; an async source picks; any other asks its callback. The checks run in the same order as before. - obs_source_color_space_pick(): the async pick, the same loop: the first preferred space equal to the frame's space, else the last preferred space, else (none) the frame's space. obs_source_get_color_space() keeps data_valid(), reads info.type, info.output_flags, context.data != NULL, enabled, filter_parent != NULL and filter_target != NULL into struct obs_source_color_space_node, and follows the route: the recursion into the parent or the target, convert_video_space() of async_format and async_trc (passed to the pick), and video_get_color_space or GS_CS_SRGB, with the assert, as before. The colour spaces cross as int, so the header needs no graphics header. obs-source.c.h checks at compile time that enum gs_color_space and enum obs_source_type are int-sized, and that the header's filter type and VIDEO and ASYNC flags are OBS_SOURCE_TYPE_FILTER, OBS_SOURCE_VIDEO and OBS_SOURCE_ASYNC. The obs-rust#1493 comment moves with its check. The new file joins libobs.core-source with libobs.pch.h, which includes the new header. The exported symbol sets are unchanged (1766). Refs obs-rust#1979
test_source_color_space_steps compiles libobs/obs-source-color-space.c.h (ASan and UBSan, no libobs core) and calls only its two hidden functions, so it runs on every platform. 12 cases: - obs_source_color_space_route(), every combination of the inputs: a filter or not, the VIDEO and ASYNC flags (output_flags carries both, so the six fields are seven inputs and 128 rows), data, enabled, a filter parent and a filter target. Each row's route is written out. - Only OBS_SOURCE_TYPE_FILTER is a filter: transitions, scenes and values outside the enum route as inputs, over all 64 input rows. Only the VIDEO and ASYNC bits count: every other flag set, or OBS_SOURCE_AUDIO, changes no route. - The chains of test_filter_color_space and obs-rust#1493: the HDR async source picks; an audio filter above it asks its target, enabled or not; a video filter asks its callback, and its target when disabled or without data; a detached audio filter asks its callback; an audio-only input asks its filter parent before its target. - obs_source_color_space_pick(): no preferred spaces (NULL, or a count of 0) gives the frame's space; a match first, last or in the middle stops there, a later match included; no match gives the last preferred space, with the HDR Tone Mapping filter's list among them. Characterized, not endorsed: - a filter flagged async picks from its own async frame's space, unless obs-rust#1493's rule (no VIDEO) or the disabled rule sends it to its target; filters have no async frames, so in libobs that is GS_CS_SRGB; - with no data and nowhere to go the route is the callback or the pick (obs_source_get_color_space() checks data_valid() first, so libobs never gets there); - a value outside enum gs_color_space in the list is compared and returned as it is. It is in the native test graph, in the core suite. The real-libobs test_filter_color_space is unchanged. Refs obs-rust#1979
RED for the port of libobs/obs-source-color-space.c.h to the color_space module of rust/obs-source, next to audio_timing and deinterlace_pacing. The safe core is a stub (todo!()): route() over a Node (the source's type, output flags, and whether it has data, is enabled and has a filter parent and a filter target) giving a Route (AskParent, AskTarget, AsyncPick, Callback), and pick() of the frame's space from a slice of preferred spaces, one per hidden C function, with TYPE_FILTER, VIDEO and ASYNC. tests/source/color_space.rs ports test_source_color_space_steps 1:1: its 12 cases under the same names (steps_*), in the same order, with the same inputs and expectations, the 128-row route table and the characterized-not-endorsed cases included. Edge cases (edge_*): the route's invariants over every row and four types (a filter never asks its parent, nothing asks a parent or target it does not have, an enabled video source with data asks no one, only ASYNC picks); obs-rust#1493's rule with any other flags; and three proptests (4000 cases each): any type but OBS_SOURCE_TYPE_FILTER routes as an input and only the VIDEO and ASYNC bits count, over any i32 type and any u32 flags; the pick against a model written another way (the frame's space when the list is empty or holds it, the last entry otherwise) over lists of 0 to 8 values; and a list holding the frame's space anywhere gives it back. The tests are a module of obs-tests-core (rust/obs-data/tests/core.rs), as audio_timing's are. soldr cargo test -p obs-data --test obs-tests-core source::color_space fails 17 of 17 with "not yet implemented". Refs obs-rust#1979
Ports libobs/obs-source-color-space.c.h, the colour space query routing of obs_source_get_color_space(), to the color_space module of rust/obs-source. obs_source_get_color_space() stays C in obs-source.c.h: data_valid(), the field reads into the node, the recursion into the filter parent or target, convert_video_space() of the async frame's format and transfer, and the video_get_color_space callback (GS_CS_SRGB without one). The hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/color_space.rs): route() tries the C's rules in the C's order: a non-filter without VIDEO and with a filter parent asks the parent; a filter without VIDEO and with a target asks the target (obs-rust#1493's rule, kept exactly); a source without data, or disabled, with a target asks the target; an ASYNC source picks; anything else asks its callback. Only OBS_SOURCE_TYPE_FILTER is a filter and only the VIDEO and ASYNC bits count. pick() is the C's loop: each preferred space in turn, stopping at one equal to the frame's space, so no match leaves the last one and an empty list the frame's space. Values outside enum gs_color_space are compared and returned as they are. The module denies clippy's arithmetic, indexing, as, unwrap, expect, panic, unimplemented and unreachable lints, keeps no state and takes no lock. Shim (src/ffi/source_color_space.rs): obs_source_color_space_route() takes struct obs_source_color_space_node by value (mirrored, #[repr(C)]) and returns the C's enum values; obs_source_color_space_pick() takes the count and pointer. No source pointer crosses. Intentional difference: a null list with a count above 0 is read as empty (the C reads through the null pointer); libobs passes NULL only with a count of 0. C side: the file leaves libobs.core-source for its own group, libobs.ported-source-color-space (LIBOBS_PORTED_SOURCES), whose PCH is only obs-source-color-space.h; libobs.pch.h keeps the header for obs-source.c. The two functions are not EXPORT, so the shims are hidden: rust-hidden.txt, the local: list of rust-exports.map and rust-unexports-macos.txt. libobs-rust already links the crate's ffi. The exported symbol sets are unchanged and equal: 1766 on the C backend, the hybrid and libobs-c-reference; the two are local in all three, and the hybrid's come from the Rust archive. ci/test_ported_sources.py checks the group on every host. test_source_color_space_steps still compiles the C file into itself, unchanged. The new test_source_color_space_steps_rust builds the same test source against libobs_rust-static instead, as test_source_audio_timing_steps_rust does: the test calls the two hidden functions directly, so this variant runs the shims, the node passed by value from C included. It passes 12 of 12 on the hybrid tree. test_filter_color_space sees the swap through the hybrid. Tier 1 source::color_space passes 17/17. Refs obs-rust#1979
Oracle (oracle/source_color_space.c): the original obs-source-color-space.c.h, unmodified, with its two functions renamed to oracle_*, plus the node's layout (size, alignment, the six offsets), the size and values of the route enum and the filter type and VIDEO and ASYNC constants. The node is mirrored on the Rust side and passed by value, as obs-source.c.h passes it. Tier 3 (tests/source/color_space_parity.rs, 7 tests), comparing the route's value and the picked space: - the layout and constants against the C header, and the shim's mirror against the oracle's; - the route over every combination of the VIDEO and ASYNC flags, data, enabled, a filter parent and a filter target (64), with eight types (the four enum obs_source_type values, -1, 4 and the ends of i32: so all 128 rows of the characterization, the filter type and seven others) and sixteen sets of other flags (OBS_SOURCE_AUDIO, bits 3, 10 and 31, every other bit): 8,192 nodes, each route reached more than 100 times; and a proptest over any i32 type, any u32 flags and the four bools (20,000 cases); - the pick over every list of 0 to 5 values from -1..=4 (the four gs_color_space values and one past each end) against each of those frame spaces: 9,331 lists, 55,986 picks; and a proptest over lists of 0 to 8 arbitrary i32 values, the frame's space drawn from the list half the time so matches land first, last and in the middle (20,000 cases); both sides read the list through a pointer; - a count of 0 reads nothing on either side, with a null pointer or not; - the intentional difference, on the shim only: a null list with a count above 0 gives the frame's space. The parity module passed 20 runs in a row with fresh random seeds; no regression file came up. Mutation check (done once, not committed), with the two test modules in obs-tests-core: 33 mutants. The 27 core mutants all fail Tier 1 (2 to 7 of 17) and Tier 3 (2 or 4 of 7): each rule removed, each rule widened (filters asking their parent, sources with video asking it, any source without video asking its target, filters with video asking it, a parent or target asked without one), the disabled rule on data only, enabled only or both, the rules reordered, the async rule on the VIDEO bit or skipped for filters, any non-input type a filter, any flag counted as video, the fallback picking, and the pick without its break, giving the frame's space or the first entry with no match, GS_CS_SRGB for an empty list, skipping the last entry or stopping one late. obs-rust#1493's rule reverted fails 5 of 17 and 2 of 7. Of the 6 shim mutants, 5 fail Tier 3 (the parent and target routes swapped, the parent and target flags swapped, the type read as 0, the count less one, and the null check dropped, which aborts in from_raw_parts); Tier 1 does not reach the shims. One survives and is equivalent: has_data and enabled swapped in the shim, which the route only reads as !has_data || !enabled. Refs obs-rust#1979
The rust/README.md crate table now lists libobs/obs-source-color-space.c.h among the rust/obs-source units, and its port table has a row for it: the two functions and their rules in order (obs-rust#1493's included), what stays C (data_valid(), the field reads, the recursion, convert_video_space() and the callback), the node passed by value, the int-sized colour spaces and the compile-time checks, what the characterization pins and the port keeps, the intentional difference (a null list with a count above 0 is empty), the _rust variant of the steps test, test_filter_color_space and what Tier 3 compares. The crate's description and lib.rs say what it holds. docs/rust-port/naming.md already maps libobs/obs-source*.c.h to rust/obs-source. port_comparison gets its own bench file, benches/port_comparison/source_color_space.rs: 1024 routes over every combination of the inputs, with and without OBS_SOURCE_AUDIO, and 1024 async picks of the four frame spaces from lists of 0 to 4 preferred spaces, matched first, last, in the middle or not at all, each folded into a checksum both sides must match. On x86_64 Linux (GCC, not pinned; median per 1024 calls): route 2.05 us Rust and 2.26 us C (0.91x), async_pick 2.21 us Rust and 2.69 us C (0.82x), about 2 ns a call either way. Fixes obs-rust#1979
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 #1979
What and why
Ports the colour space query routing of
obs_source_get_color_space()inlibobs/obs-source.c.htorust/obs-source, as a new modulecolor_spacenext toaudio_timing(#1936) anddeinterlace_pacing(#1954). Every source and filter is asked its colour space when it renders, and the routing decides who answers: the source's own callback, an async source's frame, or the next source down the filter chain. #1493 fixed this for real users: an audio filter on an HDR source answeredGS_CS_SRGBfor the whole chain, so HDR Tone Mapping above it saw SDR. That rule is kept exactly, pinned in the characterization, and checked by a mutant that reverts it.Six commits:
Move (behaviour-neutral): the decisions go to
libobs/obs-source-color-space.c.has two pure functions, declared in the newobs-source-color-space.hwithoutEXPORT, so they are hidden:obs_source_color_space_route(): which source answers, with the C's rules in the C's order. A non-filter with no video asks its filter parent. A filter with no video asks its target (libobs: Fix color space query through non-video filters #1493). A source with no data, or a disabled one, asks its target. An async source picks. Anything else asks its callback.obs_source_color_space_pick(): the async pick, the same loop. It returns the first preferred space equal to the frame's space, else the last preferred space, else (with an empty list) the frame's space.obs_source_get_color_space()keepsdata_valid(), and readsinfo.type,info.output_flags,context.data != NULL,enabled,filter_parent != NULLandfilter_target != NULLintostruct obs_source_color_space_node, passed by value. It follows the route itself: the recursion into the parent or the target,convert_video_space()ofasync_formatandasync_trc(the result is passed to the pick), andvideo_get_color_spaceorGS_CS_SRGB, with the assert, as before. Colour spaces cross asint, so the header needs no graphics header.obs-source.c.hchecks at compile time thatenum gs_color_spaceandenum obs_source_typeareint-sized, and that the header's filter type and VIDEO and ASYNC flags matchobs-source.h. The file stays inlibobs.core-sourcefor this commit.Characterization:
test_source_color_space_steps, 12 cases, compiles the moved file. It covers:output_flagscarries both VIDEO and ASYNC, so the table has 128 rows (the 64 combinations of the other six inputs, for a filter and for a non-filter). Each row's route is written out;OBS_SOURCE_TYPE_FILTERcounts as a filter (transitions, scenes and out-of-enum types route as inputs), and only the VIDEO and ASYNC bits count;test_filter_color_spaceand libobs: Fix color space query through non-video filters #1493;NULL, or a count of 0), with a match first, last or in the middle, with no match, and with values outsideenum gs_color_space.It is in the core suite of the test graph, so no pinned suite count changes.
RED: Tier 1 in the crate against
todo!(). 17 of 17 fail.GREEN: the safe core and
#[no_mangle]shims, in a newlibobs.ported-source-color-spacegroup with its own PCH (only the new header). This commit updates the export lists,source-sets.json, the unity lists andci/test_ported_sources.py, and adds a_rustvariant of the steps test (see below).Tier 3: a C oracle and parity, with the mutation check.
Docs: the README rows, the crate's description and
lib.rs, and aport_comparisonbench file.docs/rust-port/naming.mdalready mapslibobs/obs-source*.c.htorust/obs-source.What changed in the C.
obs_source_get_color_space()now reads the six fields into the node, then switches on the route. The route's checks are the same expressions, in the same order. The pick's loop is unchanged; it reads the list asint(a cast of theenum gs_color_spacepointer, checked to be the same size) and its result is cast back.Kept, characterized, not endorsed:
GS_CS_SRGB;data_valid()runs first, so libobs never gets there;enum gs_color_spacein the preferred list is compared and returned as it is.Intentional difference: a null preferred list with a count above 0 is read as empty, so the pick returns the frame's space (the C reads through the null pointer). libobs passes
NULLonly with a count of 0, which both sides read as empty. The difference is listed in the parity test header and inrust/README.md.The
_rustvariant links and runs the shims.test_source_color_space_steps_rustbuilds the unchanged test source againstlibobs_rust-static, astest_source_audio_timing_steps_rustdoes. Unlike obs-output: Port the encoder ROI checks and scaling #1974, where the test only called the exported API, this test calls the two hidden functions directly. So the variant runs the shims, including the node passed by value from C. It passes 12 of 12 on the hybrid tree.Exported symbols: 1766 on the C backend, the hybrid and
libobs-c-reference, with identical sets. The two functions are local (t) in all three. In the hybrid they come fromliblibobs_rust.a(the group's object is not on the hybrid link line), and the ported group is compiled only intolibobs-c-reference.Performance (port_comparison, x86_64, GCC, not pinned; median per 1024 calls):
route: 2.05 µs Rust, 2.26 µs C (0.91x);async_pick: 2.21 µs Rust, 2.69 µs C (0.82x; 2.54 µs Rust in an earlier run).That is about 2 ns per call either way, within the run's noise.
No user-visible change, so no
docs/features.mdline.Observed, not changed (upstream behaviour, nothing unsafe):
filter_parent.obs_source_filter_add()does not check the filter's type, so this happens only when a non-filter source is added as a filter through the API. It is pinned, not relied on.RED → GREEN
064baf1d7.soldr cargo test -p obs-data --test obs-tests-core source::color_spacefails 17 of 17, every failure "not yet implemented": the 12 portedsteps_*cases and 5edge_*cases, three of them proptests. This was checked again on the rebased commit.f50a43724. Tier 1 passes 17/17. Tier 2 ran under a privateXvfb -noresetwithdbus-run-session, a fresh HOME andulimit -c 0, with no TMPDIR set:test_filter_color_spacetest_source_color_space_stepstest_source_color_space_steps_rustAll of these ran on the head,
19c6c25cb, on01843e7c5. The targeted tests also passed on all three builds before the rebase (GREEN on92a52ff7a). No ctest test was skipped. Inside the tests, three cases skip on each lane, as on master:open_crashes_without_obs_coreintest_audio_ioandtest_video_io, andtest_hex_float_values_ignore_comma_locale, which needs a comma-decimal locale this host does not have. Each c-ref run checked that the loader usedlibobs-c-reference/libobs.so.30, which was rebuilt (ninja libobs-c-reference) before every c-ref run.Tier 3,
452e4ca56(source::color_space_parity, 7 tests). Each run compares the route's value and the picked space. Runs:i32type, anyu32flags and the four bools (20,000 cases);i32values, with the frame's space drawn from the list half the time (20,000 cases). Neither uses a float strategy;The parity module passed 20 runs in a row with fresh seeds, and no regression file came up.
Mutation check (once, not committed; the two test modules in obs-tests-core): 32 of 33 mutants fail, and the one that survives is equivalent.
GS_CS_SRGB/ last entry skipped / stops one latefrom_raw_partsprecondition, inpick_null_list_is_empty_in_the_shim)has_dataandenabledswapped in the shim (the route reads them only as!has_data || !enabled)Other runs:
uv run ci/local_gate.py --test-diff origin/master(the CI changed-crates step) on the head19c6c25cb: 2959/2959 passed, 1 skipped (an existing ignored test).uv run ci/local_gate.py --lane lint: ok.--lane cross: ok. Both ran on19c6c25cb.cargo clippy -p obs-source -p obs-c-oracle -p obs-data --all-targets -D warningsis clean.ci/test_build_groups.py,ci/test_ported_sources.pyandci/test_oracle_standins.py: OK on the head.19c6c25cb.soldr cargo test -p obs-data --test obs-tests-core source::: 110/110.01843e7c5. Only theport_comparisonbench list conflicted: obs-output: Port the encoder ROI checks and scaling #1974 addedencoder_roi, and both entries are kept. After the rebase,source-sets.json,test-graph.json, the unity lists,libobs.pch.hand the three export lists were compared by hand against master: only this PR's lines differ.Checklist
master(or the description starts with a Stacked: note)docs/features.mdis added or updated (not applicable: no user-visible change)--test-diffpassed locally; nothing is stamped)-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)