Repository navigation
obs-core: Port the source load migration and value rules - #2157
Merged
Merged
Conversation
Member
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Oct 24, 2026
…e-load.c Behaviour-neutral extraction before the Rust port. The pure decisions of obs_load_source_type() move to libobs/obs-source-load.c.h, as six functions on plain values declared in the new libobs/obs-source-load.h without EXPORT (hidden, as -fvisibility=hidden keeps them): - obs_source_load_prev_ver(stored): the saved "prev_ver" int64 as the uint32_t the source is created with (its low 32 bits, as the cast did); - obs_source_load_volume(volume): obs-rust#2128's rule, 0 when negative, INFINITY past FLT_MAX, then the float cast; - obs_source_load_balance(balance): obs-rust#2058's rule, 0 to 1, then the cast; - obs_source_load_delay(delay): obs-rust#2058's rule, a negative push-to-mute or push-to-talk delay is none; - obs_source_load_deinterlace_mode(mode): obs-rust#2120's rule, a mode past the int range is OBS_DEINTERLACE_MODE_DISABLE; - obs_source_load_monitoring_migration(prev_ver, caps, monitoring_type): before 23.2.2 a source with OBS_SOURCE_MONITOR_BY_DEFAULT becomes monitor-only and gets all six mixers; before 33.0.0 "monitoring_enabled" is stored as the (migrated) type not being none. It takes the saved int64 type and reads it as an int, as the (int) cast did. The answer is a struct: whether to set the mixers and to what, and whether to store "monitoring_enabled" and its value. obs.c.h keeps every obs_data_*() call and setter, in the same order and the same number of calls: it reads each value, passes it in, and hands the answer to the setter (obs_source_set_audio_mixers() and obs_data_set_bool() only when the plan says so, as the two ifs did). The source creation, the canvas lookup, the private settings and the filter recursion stay as they were. The constants are copied into the header (MAKE_SEMANTIC_VERSION(23, 2, 2) and (33, 0, 0), OBS_SOURCE_MONITOR_BY_DEFAULT, the two monitoring types, the six-mixer mask and OBS_DEINTERLACE_MODE_DISABLE), so it needs only stdbool.h and stdint.h; obs.c.h checks each against obs-config.h, obs-source.h, obs.h and MAX_AUDIO_MIXES with _Static_assert. The new file joins libobs.core, before obs.c.h, with libobs.pch.h, which includes the new header; source-sets.json lists it. docs/rust-port/naming.md maps it to rust/obs-core. The exported symbol set is unchanged (1766); the six functions are local. Checked in a scratch harness (not committed) that compiles origin/master's obs_load_source_type() verbatim next to this one and the moved file, on stub obs_data and source calls that record every call with its arguments (doubles and floats by bit pattern, so NaN payloads and -0 count): 10,000,000 loads under ASan and UBSan, at -O0 and -O2, with saved values drawn from the edges (NaN payloads of both signs, +-inf, -0, FLT_MAX and its neighbours, subnormals, the int and int64 ends, versions at and around 23.2.2 and 33.0.0 and those plus 2^32), random bit patterns, keys present or missing, caps with and without the cap, scene, group and filter types, and filters loaded through the recursion: 859,000,000 recorded calls, equal in order and value. Deliberately broken moves (each comparison of the volume, balance, delay and deinterlace rules, the prev_ver cast, both version bounds, the migrated type, the mixer mask, the type cast) all fail it, except a balance bound of >= 1.0, which is equivalent. git log -L on obs_load_source_type shows obs-rust#2058 (balance and delays), obs-rust#2120 (deinterlace mode) and obs-rust#2128 (volume) as the fork's changes; each rule and its comment moves as it is; the volume's "volume = INFINITY" becomes "volume = (double)INFINITY" (the same value), since INFINITY is a float and the C oracle builds with -Wdouble-promotion -Werror. Refs obs-rust#2143
test_source_load_migration_steps compiles libobs/obs-source-load.c.h into itself (ASan and UBSan) and calls only its six hidden functions, through obs-source-load.h. 19 cases pin: - the header's constants: 0x17020002 (23.2.2), 0x21000000 (33.0.0), the cap bit 0x800, the two monitoring types, the mixer mask 0x3F and the disabled deinterlace mode; - prev_ver: 0, 1, INT32_MAX and the step past it, and UINT32_MAX as themselves; characterized, not endorsed: an int64 past UINT32_MAX keeps its low 32 bits (2^32 + 23.2.1 reads as 23.2.1 and migrates, 2^32 as 0), and a negative one wraps (-1 is UINT32_MAX); - the monitoring migration at, just below and just above 23.2.2 and 33.0.0 (and 22.0.3, 23.2.0, 23.2.1, 32.255.65535 and 34.0.0): below 23.2.2 a source with the cap is monitor-only with all six mixers whatever its type; below 33.0.0 "monitoring_enabled" is stored as the type not being none; at and past 33.0.0 nothing is stored, for every type and cap; - prev_ver 0 (never saved) migrating both ways and UINT32_MAX neither; - each monitoring type and values outside the enum (3, -1, INT_MAX, INT_MIN) with no cap, the cap, every other bit and every bit; characterized, not endorsed: the saved int64 type is read as an int, so 2^32 is none and 2^32 + 1 monitor-only; - a cross of 12 versions, 8 cap sets and 11 types against the rule written out; - the volume: in range as the nearest float (ties to even, subnormals, a double below half the smallest subnormal as 0), negative values and -inf as 0, FLT_MAX and below as themselves, anything past FLT_MAX as INFINITY (characterized, not endorsed: also a value float rounding would take back to FLT_MAX), NaN of either sign and any payload as NaN; characterized, not endorsed: -0.0 stays -0.0f; - the balance: 0 to 1 as the nearest float (just under 1 rounds to 1), past 1 and +inf as 1, negative and -inf as 0, NaN as NaN, -0.0 as -0.0f (characterized, not endorsed); - the delays: 0 up to INT64_MAX as themselves, -1 down to INT64_MIN as 0; - the deinterlace mode: every enum value, 9, -1, INT_MAX and INT_MIN as themselves (the setter disables a mode it does not know, obs-rust#2120), and past the int range (INT_MAX + 1, INT_MIN - 1, UINT32_MAX, 2^32 + 1, 2^32 + 5, the int64 ends) as disabled, not as the low 32 bits. The test is in the core suite of the test graph and links libm except on MSVC. test_source_audio_ranges, test_source_volume_mix and test_deinterlace_mode_load cover the caller through the real libobs. Refs obs-rust#2143
The safe API of obs_core::source_load, with todo!() bodies: the constants (MONITOR_ONLY_BEFORE and MONITORING_ENABLED_BEFORE through semantic_version(), MONITOR_BY_DEFAULT, the two monitoring types, ALL_MIXERS, DEINTERLACE_DISABLE), MonitoringPlan (struct obs_source_load_monitoring), and prev_ver(), volume(), balance(), delay(), deinterlace_mode() and monitoring_migration(). tests/obs_core/source_load.rs ports test_source_load_migration_steps.c 1:1: its 19 cases as steps_*, under the same names, in the same order, with the same values, the "characterized, not endorsed" ones included. Six new edge_* proptests (4096 cases each) check each function against its rule written out independently: - prev_ver() as the low 32 bits of any int64; - the migration over any u32 version (weighted to 23.2.2 and 33.0.0 +-2 and the ends), any caps with and without the cap bit, and any int64 type; - volume() and balance() over f64 bit patterns (every NaN payload, subnormals, both zeros), f32 bit patterns widened, and the 64 doubles either side of FLT_MAX, 1 and 0; the in-range result is checked against the nearest float found by a search over the float bits, ties to even, not against a cast; - delay() and deinterlace_mode() over any int64, weighted to the int and int64 ends. soldr cargo test -p obs-data --test obs-tests-core -- obs_core::source_load:: fails 24 of 25 with "not yet implemented"; steps_constants, which reads only the constants, passes. Refs obs-rust#2143
Ports libobs/obs-source-load.c.h, the source load migration and value rules of obs_load_source_type(), to the source_load module of rust/obs-core. obs.c.h stays C around it: every obs_data_*() call and setter, in the same order and the same number of calls, the source creation, the canvas lookup, the private settings and the filter recursion. The hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/source_load.rs): - prev_ver(): the low 32 bits of the saved int64, as the C's cast; - volume(): 0 when below 0, infinity when above f32::MAX, else the value; then as f32 (round to nearest, ties to even, as the C's cast). The comparisons are the C's, so NaN passes both and stays NaN, and -0.0 stays -0.0; - balance(): f64::clamp(0.0, 1.0), which is the C's two comparisons (NaN and -0.0 pass through), then as f32; - delay(): u64::try_from, 0 when negative; - deinterlace_mode(): i32::try_from, DEINTERLACE_DISABLE when past the int range; - monitoring_migration(): the saved type read as its low 32 bits; before 23.2.2 with MONITOR_BY_DEFAULT, monitor-only with ALL_MIXERS; before 33.0.0, store enabled as the type not being none. The module denies clippy's arithmetic, indexing, unwrap, expect, panic, todo, unimplemented and unreachable lints, keeps no state and takes no lock. Shims (src/ffi/source_load.rs): the six functions keep the C signatures. struct obs_source_load_monitoring is mirrored #[repr(C)] and returned by value. No pointer crosses. No intentional differences. C side: the file leaves libobs.core for its own group, libobs.ported-source-load (LIBOBS_PORTED_SOURCES), whose PCH is float.h, limits.h, math.h and obs-source-load.h; libobs.pch.h keeps the header for obs.c. The 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 six functions are local in all three, and the hybrid's come from the Rust archive (no C object of the group in the hybrid libobs). ci/test_ported_sources.py checks the group on every host. test_source_load_migration_steps still compiles the C file into itself, unchanged. It has no _rust variant: linking it against libobs_rust-static was tried and fails with 404 undefined references, because the shims' archive member (an obs_core codegen unit) also holds the views and the other obs-core shims, which pull in obs-util and obs-media-io members that need libobs (blog, bcrash, the graphics context, GIO). The real-libobs tests (test_source_audio_ranges, test_source_volume_mix, test_deinterlace_mode_load and the scene collection loads) see the swap through the hybrid. Tier 1 obs_core::source_load passes 25/25. Refs obs-rust#2143
rust/obs-c-oracle/oracle/source_load.c compiles the unchanged libobs/obs-source-load.c.h with its six functions renamed oracle_*, plus its constants and the layout of struct obs_source_load_monitoring. tests/obs_core/source_load_parity.rs (13 tests) runs the shim, the C and the safe core on every input and compares the results exactly: the plan field by field, the version, delay and mode as integers, the volume and balance bit for bit (so -0.0 is not 0.0). A NaN must come out as a NaN on every side; its payload and sign are not compared, since Rust leaves them unspecified for an f64 to f32 cast and both setters map every NaN alike. - the 7 constants, and the size, alignment and every offset of the struct, against the C; - the migration exhaustively over the cap (each of the 32 caps bits alone, none, all, all but the cap) x 30 types (-3 to 5, the int and int64 ends, 2^32 +-2 either way) x 80 versions (both bounds +-3, every power of two and one below, the ends): 84,000 combinations, every branch reached; every major.minor version (65,536) with patches 0 to 3 and 0xffff, with and without the cap, for each monitoring type and 3 (2,621,440 calls); saved int64 versions (those, +-2^32 and negated) through prev_ver() into the migration; - the value rules over their edges (the 64 doubles either side of 0, 1, -1 and +-FLT_MAX, subnormals, the half-ulp and tie cases), ten NaN classes, every int64 within 64 of 0, the int ends, UINT32_MAX, +-2^32 and the int64 ends; and every 4093rd f32 bit pattern widened with its double neighbours (3,148,035 doubles, each through volume() and balance()); - proptests (8192 cases each) over any u32 version, caps and int64 type; versions within 2^24 of each bound; any int64 version through prev_ver(); f64 bit patterns; f32 bit patterns widened; and any int64 value. Tier 1 gains edge_semantic_version(): semantic_version() against MAKE_SEMANTIC_VERSION() written out for every major, minor and 16-bit patch. The parity module passed 10 runs in a row with fresh seeds. test_source_load_migration_steps passed 19/19 under ASan and UBSan. The committed regression files hold the seeds proptest saved while mutants failed; all pass on the port. Mutation check (not committed): 41 mutants, 32 in the core and 9 in the shims, each run against Tier 1 (26 tests) and Tier 3 (13). 40 fail; the one that survives is equivalent (the balance clamped to 1 - f64::EPSILON, which rounds to 1.0f). Tier 1 does not reach the shims; Tier 3 kills every shim mutant (the arguments swapped, the struct's fields reordered or swapped, the volume and balance crossed, the delay, mode and version pre-mangled, the mixers forced). A semantic_version() that drops the patch's high byte is killed by Tier 1 only (Tier 3 builds its versions with the same helper). Refs obs-rust#2143
rust/README.md gets the obs-core crate row and a port row for libobs/obs-source-load.c.h: the six hidden functions, what obs_load_source_type() keeps (every obs_data_*() call and setter in the same order and number, the source creation, the canvas lookup, the filter recursion), the C's comparisons kept (NaN through, -0.0 kept, infinity past FLT_MAX), the 32-bit truncations characterized and not endorsed, why there is no _rust variant, and what Tier 3 covers. The crate's description and lib.rs list the module. port_comparison gets its own bench file, port_comparison/source_load.rs: 1024 loads' worth of saved values (versions either side of 23.2.2 and 33.0.0, with and without the cap, every monitoring type, volumes and balances in and out of range with a NaN now and then, delays and modes either side of their ranges) through all six functions, folded into a checksum both sides must match. On this host (x86_64 Linux, release): Rust 8.92 us, C 14.34 us per 1024 loads; obs_load_source_type() makes these calls once per source or filter when a scene collection loads, none per frame. Fixes obs-rust#2143
zackees
enabled auto-merge
October 24, 2026 14:43
zackees
force-pushed
the
port/source-load
branch
from
October 24, 2026 14:43
f64aa1a to
574a311
Compare
Member
|
Coordinator: rebased after #2159 landed. #2159 turned the bench calls in |
5 of 7 tasks
This was referenced Oct 24, 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 #2143
What and why
Ports the source load migration and the value rules of
obs_load_source_type()(libobs/obs.c.h) torust/obs-core, as a new modulesource_load. These are the decisionsobs_load_source()andobs_load_private_source()make for every source and filter in a scene collection:OBS_SOURCE_MONITOR_BY_DEFAULTbecomes monitor-only and gets all six mixers; before 33.0.0,"monitoring_enabled"is stored as the (migrated) type not being none;int64range check (libobs: Disable an out-of-range deinterlace mode instead of drawing nothing #2120).Every
obs_data_*()call and setter stays in C, in the same order and the same number of calls; C passes the values it read. The source creation, the canvas lookup, the private settings and the filter recursion stay in C too.Six commits:
Move (behaviour-neutral): the decisions go to
libobs/obs-source-load.c.has six functions on plain values, declared in the newobs-source-load.hwithoutEXPORT, so they are hidden:obs_source_load_prev_ver(stored): the savedint64as theuint32_tthe source is created with;obs_source_load_volume(volume),obs_source_load_balance(balance),obs_source_load_delay(delay)andobs_source_load_deinterlace_mode(mode): each rule and its comment, moved as they were;obs_source_load_monitoring_migration(prev_ver, caps, monitoring_type)returns a struct: whether to set the mixers and to what, and whether to store"monitoring_enabled"and its value. It takes the savedint64type and reads it as anint, as the(int)cast did.obs_load_source_type()callsobs_source_set_audio_mixers()andobs_data_set_bool()only when the plan says so, as the twoifs did. The constants are copied into the header (so it needs onlystdbool.handstdint.h), and_Static_asserts inobs.c.hcheck each againstobs-config.h,obs-source.h,obs.handMAX_AUDIO_MIXES.This was checked against the original code. A scratch harness (not committed) compiles origin/master's
obs_load_source_type()verbatim next to the moved one, on stubobs_dataand source calls that record every call with its arguments (doubles and floats by bit pattern, so NaN payloads and-0count):-O0and-O2, plus 3,000,000 more on the final tree;-0,FLT_MAXand its neighbours, subnormals, theintandint64ends, versions around 23.2.2 and 33.0.0 and those plus 2^32), random bit patterns, keys present or missing, caps with and without the cap, scene, group and filter types, and filters through the recursion;Fourteen deliberately broken moves were tried. Thirteen fail the harness; the fourteenth, a balance bound of
>= 1.0, is equivalent.git log -Lonobs_load_source_typeshows libobs: Saturate push-to-talk stop times and clamp the audio balance #2058, libobs: Disable an out-of-range deinterlace mode instead of drawing nothing #2120 and libobs: Keep source volumes finite and non-negative #2128 as the fork's changes. Each rule moved as it is, except thatvolume = INFINITYbecamevolume = (double)INFINITY(the same value):INFINITYis afloat, and the C oracle builds with-Wdouble-promotion -Werrorfor macOS.Characterization:
test_source_load_migration_steps, 19 cases. It compiles the moved file (ASan and UBSan) and calls only the six functions. It pins:prev_ver0,UINT32_MAX, andint64s above it;-0, ties to even and subnormals.The test is in the core suite of the test graph and links libm except on MSVC.
RED: Tier 1 in the crate against
todo!(): the 19 C cases ported 1:1, and 6 edge proptests that check each function against its rule written out independently. The in-range floats are checked against a nearest-float search over the float bits, not against a cast.GREEN: the safe core and six
#[no_mangle]shims, in a newlibobs.ported-source-loadgroup. Its PCH isfloat.h,limits.h,math.hand the new header. This commit updates the three export lists,source-sets.json, the unity lists andci/test_ported_sources.py(every host), each in sorted place.Tier 3: a C oracle of the unchanged file, parity, the regression files, the mutation check, and one more Tier 1 edge test (
semantic_version()).Docs: the README rows, the crate's description,
lib.rs, and aport_comparisonbench file.The core denies clippy's arithmetic, indexing, unwrap, expect, panic, todo, unimplemented and unreachable lints. It keeps no state and takes no lock. Every input comes from a scene collection (any JSON number), and nothing in the core can panic on any input.
The C's comparisons are kept. NaN passes through both float rules, and the setters map it (bug: libobs: push-to-talk delays can wrap and the audio balance isn't range-checked #2051, bug: libobs: a NaN or negative source volume isn't rejected and breaks every mix the source is in #2108).
-0.0is not below 0, so it stays-0.0. A value pastFLT_MAXis infinity, even wherefloatrounding would giveFLT_MAX. The balance usesf64::clamp(0.0, 1.0), which is the same two comparisons.Kept, characterized, not endorsed:
prev_verpast 32 bits keeps its low 32 bits, so2^32 + 23.2.1reads as 23.2.1 and migrates, and-1reads asUINT32_MAX;int, so2^32is none and2^32 + 1is monitor-only;-0.0stays-0.0for the volume and the balance.Intentional differences: none. Tier 3 compares a NaN only as a NaN, not its payload or sign: Rust leaves those unspecified for an
f64tof32cast, and both setters map every NaN alike.No
_rustvariant.test_source_load_migration_steps_rustwas wired againstlibobs_rust-staticand fails to link with 404 undefined references. The shims' archive member (anobs_corecodegen unit) also holds the views and the other obs-core shims, which pull inobs-utilandobs-media-iomembers that need libobs (blog,bcrash, the graphics context, GIO). The target was removed, and itstests.dfile says why. Tier 3 compares the shims with the C instead, and the real-libobs tests see the swap through the hybrid.Tier 3 compares the shim, the C and the core on every input: the plan field by field, the integers, and the floats bit for bit.
f32bit pattern widened with its neighbours (3,148,035 doubles).u32andi64versions, any caps and types, andf64andf32bit patterns.Mutation check (not committed): 41 mutants, each run against Tier 1 (26 tests) and Tier 3 (13).
prev_ver(saturating)<=/>=, NaN mapped)-0.0lower bound,1 - ε, max/min, NaN mapped, bound -1)1 - f64::EPSILON, which rounds to1.0f|d|, wrap)<=, or/and, type not migrated, five mixers, negative types, type read four other ways, any cap, never stores, both bounds moved, cap bit 10)semantic_version()(patch's high byte dropped)|delay|, mode truncated first, fields swapped, struct reordered, negative version as 0, mixers forced)Tier 1 does not reach the shims, and Tier 3 kills every shim mutant. The
semantic_version()mutant is killed by Tier 1 only, because Tier 3 builds its versions with the same helper.Exported symbols: 1766 on the C backend, the hybrid and
libobs-c-reference, with identical sets, unchanged from master. This was checked on the move and onf64aa1a46. The six functions are local (t) in all three. In the hybrid they come from the Rust archive: no C object of the group is in the hybrid libobs.Performance (
port_comparison, x86_64 Linux, GCC, release, a loaded host; median per 1024 loads through all six functions): Rust 8.92 µs, C 14.34 µs. These run once per source or filter when a scene collection loads, never per frame. The fullport_comparisonrun stops earlier at the existingbmem/countfixture check. These numbers come from a run with only this file's benchmarks enabled, and that edit was not committed.Coverage gap: no real-libobs test loads a source with
prev_veror monitoring settings. The harness covers the moved caller, and the characterization and Tier 3 cover the decisions; a real-libobs migration test would be a separate change.Overlap: no open PR touches
libobs/obs.c.h. libobs: Move the hotkey binding press count into obs-hotkey-binding-press.c #1837 (draft) touches thelibobs.coregroup file, but not the lines this changes.No user-visible change, so no
docs/features.mdline.RED → GREEN
9f415352a.soldr cargo test -p obs-data --test obs-tests-core -- obs_core::source_load::fails 24 of 25 with "not yet implemented";steps_constants, which reads only the constants, passes.0d0167227, Tier 1 25/25. Onf64aa1a46(the head): Tier 1 26/26 and Tier 3 13/13, andtest_source_load_migration_steps19/19. The source load tests (test_source_audio_ranges,test_source_volume_mix,test_deinterlace_mode_load,test_source_load_migration_steps, the scene and filter loads, themonitoring_typetests) pass 13/13 on the C backend and 14/14 against the hybrid libobs andlibobs-c-reference. The full ctest passes 448/448 on the C backend and 462/462 against the hybrid libobs, with 0 skipped,test_deinterlace_2x_field_orderincluded (private Xvfb, fresh HOME).ci/local_gate.py --test-diff origin/masterruns 3401 Rust tests, all passing (4 skipped by the default filter);--lane lintand--lane crosspass. All onf64aa1a46.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