Repository navigation
libobs: Disable an out-of-range deinterlace mode instead of drawing nothing - #2120
Merged
Merged
Conversation
An async source whose deinterlace mode is not in enum obs_deinterlace_mode draws nothing. obs_source_set_deinterlace_mode() takes every mode but OBS_DEINTERLACE_MODE_DISABLE as "deinterlacing on", and get_effect() has no effect for a mode it does not know, so deinterlace_render() loops over a NULL effect. A scene collection stores the mode as an int64, and obs_load_source_type() casts it to int, so "deinterlace_mode": 99 loads a black source and 4294967298 (2^32 + 2) loads as Retro (2). test_deinterlace_mode_load (real libobs, graphics suite, Linux under a display) loads an async test source from obs_data with obs_load_source(), or creates one and calls the setter, shows it on channel 0, and pushes solid BGRA frames at the canvas rate until three output frames, read back through a raw video callback, show the source's colour (at most 3 s, so a new mode's first frames or a loaded machine do not fail a drawn source). Each check also reads the getter and the "deinterlace_mode" of obs_save_source(). - loaded_out_of_range_mode_is_disabled (99 and 9), loaded_negative_mode_is_disabled (-1) and loaded_mode_past_int_range_is_disabled (2^32 + 2): DISABLE, drawn; - set_out_of_range_mode_is_disabled (99, -1 on a source that does not deinterlace) and set_out_of_range_mode_after_a_mode_is_disabled (Yadif, then 99, then Blend 2x): DISABLE after the bad mode, drawn throughout; - valid_modes_unchanged: no key, and every mode from DISABLE to Yadif 2x, loaded and set in turn, keeps its value and is drawn; - field_order_unchanged: a stored field order of 0 is top field first, 1, 5 and -1 bottom field first, as before, and the source is drawn. Fails as expected on the C backend, the hybrid and libobs-c-reference: 5 of 7. The out-of-range cases show the source on 0 or 1 of 89 output frames and read back the bad mode (99, 9, -1); 2^32 + 2 draws but reads back 2. valid_modes_unchanged and field_order_unchanged pass. Refs obs-rust#2090
…othing An async source whose deinterlace mode was not in enum obs_deinterlace_mode drew nothing: obs_source_set_deinterlace_mode() enabled deinterlacing for it, set up the previous-frame textures and stored the mode, and get_effect() gave no effect to draw with. The getter returned the bad mode, so the Deinterlacing menu checked nothing and a saved scene collection kept it. obs_source_set_deinterlace_mode() now takes a mode outside the enum as OBS_DEINTERLACE_MODE_DISABLE, before it compares with the current mode: on a source that does not deinterlace it changes nothing, and on one that does it disables deinterlacing as DISABLE does. deinterlace_mode_known() lists the same modes as get_effect(). obs_load_source_type() reads the mode as int64 and passes DISABLE for a value past the int range, which it used to cut to its low 32 bits (2^32 + 2 loaded as Retro); the setter handles the rest. The stored mode, the getter and the saved value agree. Every valid mode, DISABLE included, takes the same path as before. The field order has no such gap: obs_source_set_deinterlace_field_order() stores "top field first" as a bool, so any value but TOP is bottom field first, and the getter and the saved value say BOTTOM. It is unchanged. The frontend's Deinterlacing menu and obs-websocket only pass enum values; obs-websocket's GetInputDeinterlaceMode already reported an unknown mode as OBS_DEINTERLACE_MODE_DISABLE. - docs/features.md: a line under fixed upstream bugs. test_deinterlace_mode_load 7/7, test_deinterlace_2x_field_order 73/73, test_deinterlace_pacing_steps 23/23 and the media restart tests on the C backend, the hybrid and libobs-c-reference. Fixes obs-rust#2090
This was referenced Oct 24, 2026
This was referenced Oct 24, 2026
zackees
pushed a commit
to rdoupe/obs-studio
that referenced
this pull request
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
zackees
pushed a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
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
zackees
pushed a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
…ce-draw.c Behaviour-neutral extraction before the Rust port. The decisions of get_effect(), deinterlace_linear_required(), deinterlace_render() and obs_source_set_deinterlace_mode() in obs-source-deinterlace.c.h move to libobs/obs-source-deinterlace-draw.c.h as ten functions on plain values, declared in the new libobs/obs-source-deinterlace-draw.h without EXPORT (hidden, as -fvisibility=hidden keeps them): - obs_source_deinterlace_draw_effect(): which effect a mode draws with, an enum C maps to the effect slot and file (NONE for DISABLE and for a mode outside the enum); - obs_source_deinterlace_draw_linear_required(): the modes that need linear sRGB input; - obs_source_deinterlace_draw_skip(): the early return of deinterlace_render(); - obs_source_deinterlace_draw_reads_linear_srgb() and obs_source_deinterlace_draw_linear_srgb(): the linear sRGB flag, and whether gs_get_linear_srgb() is read for it; - obs_source_deinterlace_draw_technique(), obs_source_deinterlace_draw_reads_white_level() and obs_source_deinterlace_draw_multiplier(): the technique (an enum C maps to "Draw", "DrawMultiply", "DrawTonemap" or "DrawMultiplyTonemap") and the multiplier for each pair of source and current colour spaces; - obs_source_deinterlace_draw_frame2(): whether the second field is due, video_time >= frame_ts + offset + half_duration - TWOX_TOLERANCE in uint64_t (obs-rust#395, obs-rust#1995, obs-rust#2048); - obs_source_deinterlace_draw_mode_change(): same, enable, disable or switch, a mode outside the enum being DISABLE (obs-rust#2120, which moves here with deinterlace_mode_known()). obs-source-deinterlace.c.h keeps every gs_* call in its order and under the same conditions, obs_load_effect() and the effect slots, convert_video_space(), obs_get_video_sdr_white_level(), enable_deinterlacing(), disable_deinterlacing() and obs_enter_graphics(). The early return still comes before convert_video_space() and gs_get_color_space(), so the decisions are separate calls rather than one plan: gs_get_linear_srgb() is still read only for a GS_CS_SRGB source (the short circuit of the old expression), and obs_get_video_sdr_white_level() only for a pair that multiplies, after gs_get_color_space(). The multiplier is the same single float division, sdr_white_level / 80.0f or 80.0f / sdr_white_level. The frame2 sum is the same uint64_t arithmetic, wrapping where it wrapped; TWOX_TOLERANCE, used only there, is now the pacing header's OBS_SOURCE_DEINTERLACE_PACING_TWOX_TOLERANCE (1000000ULL, which the old int constant converted to). Modes and colour spaces cross as int, so a value outside either enum takes the paths it took before; obs-source-deinterlace.c.h checks that both enums are int-sized. Checked against the unchanged functions of origin/master (outside the tree, not committed): both versions compiled against stubs that log every gs_* and obs_* call with its arguments (floats as their bits), and the traces compared byte for byte, under GCC -O2 and clang -O0. 100,601 effect lookups (modes -300 to 300 and random int), 585,120 renders (every texture and size combination of the early return; 9 source x 9 current spaces, in the enum and out, x the graphics linear flag x 16 modes x 20 white levels, NaNs, infinities, signed zeros and subnormals included; 200,000 random white level bit patterns; every combination of 16 edge u64 values for video_time, frame_ts and offset with 8 half durations; 300,000 random and near-threshold frame2 inputs) and 100,512 mode changes (valid or not x 16 current x 16 new modes, and a random sequence). The traces are identical; a planted change to the linear sRGB read or to the frame2 compare is caught. 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#2130
zackees
pushed a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
test_deinterlace_draw_plan_steps compiles libobs/obs-source-deinterlace-draw.c.h (ASan and UBSan) and calls only its ten hidden functions. 17 cases: - enum_values: the effect, technique and mode change numbers the C maps (and the port will return), and that each enum is int-sized; - effect_every_mode, effect_outside_enum: each mode's effect, RETRO drawing with discard 2x; none for DISABLE, -1, 99, 9 (one past YADIF_2X) and the ends of int; - linear_required_every_mode: blend, linear and yadif (and their 2x) need linear input; disable, discard, retro and modes outside the enum do not; - skip_without_texture_or_size: the early return for every combination of the two textures and widths and heights of 0, 1, 1080 and UINT32_MAX; - reads_linear_srgb_every_space, linear_srgb_every_input: gs_get_linear_srgb() is read for a GS_CS_SRGB source only; the flag is set for any other space (outside the enum included), and for SDR by the graphics flag or the mode; - technique_space_pairs, multiplier_space_pairs: the 4 x 4 pairs of source and current spaces, the technique, whether the white level is read, and the multiplier as float bits at SDR white levels of 80, 300 and 0 (300 / 80 = 3.75, 80 / 300 = 0x3e888889); - technique_outside_enum: a space outside the enum, as source or current, draws with Draw at 1 and reads no white level; - multiplier_any_level: -0, infinity, -80, 480, the smallest subnormal and NaN, each one IEEE division; - frame2_at_threshold: due at frame_ts + offset + half_duration - TWOX_TOLERANCE (>=), not 1 ns before; the half duration counted in full up to UINT32_MAX; - frame2_sum_wraps, frame2_below_tolerance_wraps: the uint64_t wraps; - mode_change_every_pair, mode_change_outside_enum, mode_change_current_outside_enum: same, enable, disable or switch for every pair of modes; a mode outside the enum disables, or does nothing when deinterlacing is off (obs-rust#2120). Characterized, not endorsed: - obs_get_video_sdr_white_level() is not checked: a level of 0 gives a multiplier of +inf from scRGB (80.0f / 0), -0 gives -inf, a negative level a negative multiplier and a NaN a NaN. OBS sets levels from 80 to 480 nits; - the frame2 threshold wraps: when frame_ts + offset + half_duration passes UINT64_MAX it lands near 0 and the second field is due at once; when half_duration is under TWOX_TOLERANCE and frame_ts + offset is smaller than the difference, it lands near UINT64_MAX and the second field is never due (a source has frame_ts and offset 0 only before its first frame, when nothing draws); - a current mode outside the enum, which obs_source_set_deinterlace_mode() no longer stores since obs-rust#2120, is not DISABLE: a mode in the enum switches, and one outside it disables, the same value included. The test is in the native test graph in name order, with libm except on MSVC, in the core suite (no suite size is pinned in rust/obs-build/tests/native.rs). On the C backend it passes 17 of 17, and test_deinterlace_2x_field_order (all five rates), test_deinterlace_pacing_steps, test_deinterlace_mode_load and test_media_restart_first_frame are unchanged and pass. Refs obs-rust#2130
zackees
pushed a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
Ports libobs/obs-source-deinterlace-draw.c.h, the deinterlace draw decisions of obs-source-deinterlace.c, to the deinterlace_draw module of rust/obs-source. obs-source-deinterlace.c.h stays C: every gs_* call in its order and under its conditions, obs_load_effect() and the effect slots, the technique names, convert_video_space(), obs_get_video_sdr_white_level(), enable_deinterlacing(), disable_deinterlacing() and obs_enter_graphics(). The hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/deinterlace_draw.rs): - effect() and effect_index(): a match over the mode's int, the C's numbers (DISCARD 0 to YADIF_2X 7, RETRO drawing with discard 2x), None for DISABLE and any value outside the enum; mode_known() is DISABLE or an effect; - linear_required(): BLEND to YADIF_2X; - skip(): no current or previous texture, or a width or height of 0; - reads_linear_srgb() (GS_CS_SRGB only) and linear_srgb() (not GS_CS_SRGB, the graphics flag, or linear_required()); - technique(), Technique with the C's numbers: DrawMultiply for SDR or 709_EXTENDED into scRGB, DrawTonemap for 709_EXTENDED into SDR, DrawMultiplyTonemap for scRGB into SDR, DrawMultiply for scRGB into 709_EXTENDED, Draw otherwise (spaces outside the enum included); reads_white_level() when it multiplies; - multiplier(): sdr_white_level / 80.0 into scRGB, 80.0 / sdr_white_level out of it, 1.0 otherwise: one f32 division, the same IEEE operation as the C's, so the bits match, NaN payloads and infinities included; - frame2(): video_time >= frame_ts + offset + half_duration - TWOX_TOLERANCE (deinterlace_pacing's), each step wrapping_* as the C's uint64_t (obs-rust#395, obs-rust#1995, obs-rust#2048); - mode_change(): a mode outside the enum is DISABLE (obs-rust#2120), then same, enable from DISABLE, disable to DISABLE, else switch. The module denies clippy's arithmetic, indexing, as, unwrap, expect, panic, todo, unimplemented and unreachable lints, keeps no state and takes no lock. Shim (src/ffi/source_deinterlace_draw.rs): the ten functions keep the C signatures, plain values in and out. The effect comes back as int (-1 for none), the technique and the mode change as the C's enum values. No intentional differences: there is no pointer to check. C side: the file leaves libobs.core-source for its own group, libobs.ported-source-deinterlace-draw (LIBOBS_PORTED_SOURCES), whose PCH is obs.h (the two enums), obs-source-deinterlace-draw.h and obs-source-deinterlace-pacing.h (TWOX_TOLERANCE). libobs.pch.h keeps the header for obs-source-deinterlace.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 ten 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_deinterlace_draw_plan_steps still compiles the C file into itself, unchanged. The new test_deinterlace_draw_plan_steps_rust builds the same test source against libobs_rust-static (and libm except on MSVC): the test calls only the ten functions and includes their header and obs.h for the enum values, so it takes libobs's include directories (SIMDe, obsconfig.h) and links the archive alone. It passes 17 of 17 against the shims. test_deinterlace_2x_field_order, test_deinterlace_mode_load and test_media_restart_first_frame see the swap through the hybrid. Tier 1 source::deinterlace_draw passes 27/27. Refs obs-rust#2130
zackees
pushed a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
Oracle (oracle/source_deinterlace_draw.c): the original obs-source-deinterlace-draw.c.h, unmodified, with its ten functions renamed to oracle_*, plus every enum value the port uses (the nine modes, the four colour spaces, the effect, technique and mode change values), TWOX_TOLERANCE and the enum, int, bool and float sizes. The rename macros also rename the three enum tags that share their function's name, so the size table names the renamed tags. The bool results are declared as u8 on the Rust side, the byte the C returns. Tier 3 (tests/source/deinterlace_draw_parity.rs, 12 tests). Every function takes and returns plain values, so each run compares the bytes of the two results: the bools as bytes, the enums as values, the multiplier as its f32 bits. - the values and sizes against the C headers; - modes: every value from -70000 to 70000, every 65521st i32 over the whole range and the ends: 205,551 modes, the effect and the linear rule; every mode change between 41 modes (1,681 pairs); - space pairs: the technique, the white level read and the multiplier for every pair of 649 spaces (-320 to 320 and four near each end of i32): 421,201 pairs; every pair of -3 to 6 at 26 special white levels (zeros, subnormals, the normal ends, 80 to 480 nits, infinities, quiet and signalling NaNs of both signs with payloads); - the linear flag for every space, both graphics flags and the 41 modes (53,218); the early return for both flags each and 18 widths and heights (1,296); - frame2 for every combination of 18 special u64 values and 10 half durations (58,320), and at the threshold -2 to +2 (16,200); - deinterlace_render()'s decisions in its order (the early return, the linear sRGB read and flag, the technique, the white level read, the multiplier only when it is read, frame2), one copy on each side: 51,840 renders; - proptests (20,000 cases each): frame2 over full-range u64 times and u32 half durations, half of them at the threshold +-3; the multiplier and technique over any space and any white level bit pattern (never a float range); the mode functions over any i32; the render decisions over all of it at once. Tier 1 and the parity module passed 10 runs in a row with fresh seeds (39/39 each). No regression file came up; the ones the todo!() stub and the mutants left were deleted. Mutation check (once, not committed): 40 mutants, Tier 1 (27 tests) and Tier 3 (12), failures per mutant. | Mutant | Tier 1 | Tier 3 | |---|---|---| | effect: RETRO as discard / YADIF_2X as yadif / DISABLE as discard | 3 / 3 / 3 | 2 / 2 / 2 | | effect_index: blend 2x is 2 | 2 | 3 | | linear_required: RETRO too / not YADIF_2X | 4 / 4 | 5 / 5 | | skip: height ignored / both textures missing only | 1 / 1 | 3 / 3 | | reads_linear_srgb: SRGB_16F too | 2 | 3 | | linear_srgb: graphics flag ignored / mode ignored | 2 / 2 | 3 / 3 | | SRGB_16F not SDR | 4 | 4 | | technique: 709_EXTENDED into SDR not tonemapped / scRGB into SDR not tonemapped / scRGB into 709_EXTENDED drawn | 2 / 2 / 4 | 4 / 4 / 4 | | reads_white_level: DrawMultiply only | 2 | 3 | | multiplier: into scRGB inverted / 80.00001 / times 1/80 / scRGB into scRGB divides | 4 / 4 / 2 / 5 | 4 / 4 / 4 / 2 | | frame2: > / saturating sum / saturating TWOX / no TWOX / half doubled | 6 / 4 / 3 / 6 / 6 | 2 / 3 / 3 / 3 / 3 | | mode_change: unknown kept (pre-obs-rust#2120) / unknown is same / same before normalizing | 4 / 4 / 3 | 2 / 2 / 2 | | shim: no effect is 0 / tonemap numbers swapped / enable and disable swapped | 0 / 0 / 0 | 3 / 4 / 2 | | shim: graphics flag negated / spaces swapped in multiplier / video_time and frame_ts swapped / modes swapped | 0 / 0 / 0 / 0 | 3 / 4 / 3 / 2 | | mode_known: DISABLE unknown | 2 | 0 | | equivalent: multiplier divided in f64 and rounded / disable tested before enable / shim frame_ts and offset swapped / shim width and height swapped | 0 / 0 / 0 / 0 | 0 / 0 / 0 / 0 | 35 are killed by Tier 3. The other five are equivalent through the C ABI: mode_known() is used only by mode_change(), which maps an unknown mode to DISABLE, so DISABLE counting as unknown changes nothing (Tier 1 kills it, as it tests mode_known() itself); a single f32 division done in f64 and rounded is correctly rounded the same; the disable test can only come first when the current mode is DISABLE and the new one is too, which is "same" before either; the sum and the size test are symmetric. Tier 1 does not reach the shim; test_deinterlace_draw_plan_steps_rust and Tier 3 do. No intentional differences: there is no pointer to check. Refs obs-rust#2130
rdoupe
added a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
* libobs: Move the source load migration and value rules into obs-source-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: Characterize the source load migration and value rules 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 * obs-core: Add Tier 1 tests for the source load migration port 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 * obs-core: Port the source load migration and value rules 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 * obs-core: Check the source load migration port against the C 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 * docs: Record the source load migration port 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
rdoupe
added a commit
to rdoupe/obs-studio
that referenced
this pull request
Oct 24, 2026
* libobs: Move the deinterlace draw decisions into obs-source-deinterlace-draw.c Behaviour-neutral extraction before the Rust port. The decisions of get_effect(), deinterlace_linear_required(), deinterlace_render() and obs_source_set_deinterlace_mode() in obs-source-deinterlace.c.h move to libobs/obs-source-deinterlace-draw.c.h as ten functions on plain values, declared in the new libobs/obs-source-deinterlace-draw.h without EXPORT (hidden, as -fvisibility=hidden keeps them): - obs_source_deinterlace_draw_effect(): which effect a mode draws with, an enum C maps to the effect slot and file (NONE for DISABLE and for a mode outside the enum); - obs_source_deinterlace_draw_linear_required(): the modes that need linear sRGB input; - obs_source_deinterlace_draw_skip(): the early return of deinterlace_render(); - obs_source_deinterlace_draw_reads_linear_srgb() and obs_source_deinterlace_draw_linear_srgb(): the linear sRGB flag, and whether gs_get_linear_srgb() is read for it; - obs_source_deinterlace_draw_technique(), obs_source_deinterlace_draw_reads_white_level() and obs_source_deinterlace_draw_multiplier(): the technique (an enum C maps to "Draw", "DrawMultiply", "DrawTonemap" or "DrawMultiplyTonemap") and the multiplier for each pair of source and current colour spaces; - obs_source_deinterlace_draw_frame2(): whether the second field is due, video_time >= frame_ts + offset + half_duration - TWOX_TOLERANCE in uint64_t (obs-rust#395, obs-rust#1995, obs-rust#2048); - obs_source_deinterlace_draw_mode_change(): same, enable, disable or switch, a mode outside the enum being DISABLE (obs-rust#2120, which moves here with deinterlace_mode_known()). obs-source-deinterlace.c.h keeps every gs_* call in its order and under the same conditions, obs_load_effect() and the effect slots, convert_video_space(), obs_get_video_sdr_white_level(), enable_deinterlacing(), disable_deinterlacing() and obs_enter_graphics(). The early return still comes before convert_video_space() and gs_get_color_space(), so the decisions are separate calls rather than one plan: gs_get_linear_srgb() is still read only for a GS_CS_SRGB source (the short circuit of the old expression), and obs_get_video_sdr_white_level() only for a pair that multiplies, after gs_get_color_space(). The multiplier is the same single float division, sdr_white_level / 80.0f or 80.0f / sdr_white_level. The frame2 sum is the same uint64_t arithmetic, wrapping where it wrapped; TWOX_TOLERANCE, used only there, is now the pacing header's OBS_SOURCE_DEINTERLACE_PACING_TWOX_TOLERANCE (1000000ULL, which the old int constant converted to). Modes and colour spaces cross as int, so a value outside either enum takes the paths it took before; obs-source-deinterlace.c.h checks that both enums are int-sized. Checked against the unchanged functions of origin/master (outside the tree, not committed): both versions compiled against stubs that log every gs_* and obs_* call with its arguments (floats as their bits), and the traces compared byte for byte, under GCC -O2 and clang -O0. 100,601 effect lookups (modes -300 to 300 and random int), 585,120 renders (every texture and size combination of the early return; 9 source x 9 current spaces, in the enum and out, x the graphics linear flag x 16 modes x 20 white levels, NaNs, infinities, signed zeros and subnormals included; 200,000 random white level bit patterns; every combination of 16 edge u64 values for video_time, frame_ts and offset with 8 half durations; 300,000 random and near-threshold frame2 inputs) and 100,512 mode changes (valid or not x 16 current x 16 new modes, and a random sequence). The traces are identical; a planted change to the linear sRGB read or to the frame2 compare is caught. 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#2130 * test: Characterize the deinterlace draw decisions test_deinterlace_draw_plan_steps compiles libobs/obs-source-deinterlace-draw.c.h (ASan and UBSan) and calls only its ten hidden functions. 17 cases: - enum_values: the effect, technique and mode change numbers the C maps (and the port will return), and that each enum is int-sized; - effect_every_mode, effect_outside_enum: each mode's effect, RETRO drawing with discard 2x; none for DISABLE, -1, 99, 9 (one past YADIF_2X) and the ends of int; - linear_required_every_mode: blend, linear and yadif (and their 2x) need linear input; disable, discard, retro and modes outside the enum do not; - skip_without_texture_or_size: the early return for every combination of the two textures and widths and heights of 0, 1, 1080 and UINT32_MAX; - reads_linear_srgb_every_space, linear_srgb_every_input: gs_get_linear_srgb() is read for a GS_CS_SRGB source only; the flag is set for any other space (outside the enum included), and for SDR by the graphics flag or the mode; - technique_space_pairs, multiplier_space_pairs: the 4 x 4 pairs of source and current spaces, the technique, whether the white level is read, and the multiplier as float bits at SDR white levels of 80, 300 and 0 (300 / 80 = 3.75, 80 / 300 = 0x3e888889); - technique_outside_enum: a space outside the enum, as source or current, draws with Draw at 1 and reads no white level; - multiplier_any_level: -0, infinity, -80, 480, the smallest subnormal and NaN, each one IEEE division; - frame2_at_threshold: due at frame_ts + offset + half_duration - TWOX_TOLERANCE (>=), not 1 ns before; the half duration counted in full up to UINT32_MAX; - frame2_sum_wraps, frame2_below_tolerance_wraps: the uint64_t wraps; - mode_change_every_pair, mode_change_outside_enum, mode_change_current_outside_enum: same, enable, disable or switch for every pair of modes; a mode outside the enum disables, or does nothing when deinterlacing is off (obs-rust#2120). Characterized, not endorsed: - obs_get_video_sdr_white_level() is not checked: a level of 0 gives a multiplier of +inf from scRGB (80.0f / 0), -0 gives -inf, a negative level a negative multiplier and a NaN a NaN. OBS sets levels from 80 to 480 nits; - the frame2 threshold wraps: when frame_ts + offset + half_duration passes UINT64_MAX it lands near 0 and the second field is due at once; when half_duration is under TWOX_TOLERANCE and frame_ts + offset is smaller than the difference, it lands near UINT64_MAX and the second field is never due (a source has frame_ts and offset 0 only before its first frame, when nothing draws); - a current mode outside the enum, which obs_source_set_deinterlace_mode() no longer stores since obs-rust#2120, is not DISABLE: a mode in the enum switches, and one outside it disables, the same value included. The test is in the native test graph in name order, with libm except on MSVC, in the core suite (no suite size is pinned in rust/obs-build/tests/native.rs). On the C backend it passes 17 of 17, and test_deinterlace_2x_field_order (all five rates), test_deinterlace_pacing_steps, test_deinterlace_mode_load and test_media_restart_first_frame are unchanged and pass. Refs obs-rust#2130 * obs-source: Add Tier 1 tests for the deinterlace draw port Tests for the port of libobs/obs-source-deinterlace-draw.c.h to the deinterlace_draw module of rust/obs-source, next to deinterlace_pacing. The safe core is a stub (todo!()): - effect() and effect_index() (obs_source_deinterlace_draw_effect(), an Effect or its index, None for no effect), mode_known(), linear_required(), skip(), reads_linear_srgb(), linear_srgb(), technique() (a Technique), reads_white_level(), multiplier() (f32), frame2() and mode_change() (a ModeChange), on plain values: modes and colour spaces as the C's int, sizes as u32, times as u64; - the enum obs_deinterlace_mode and enum gs_color_space values, and Effect, Technique and ModeChange with the C's numbers. tests/source/deinterlace_draw.rs ports test_deinterlace_draw_plan_steps 1:1: its 17 cases under the same names (steps_*), in the same order, with the same inputs and expectations, the multipliers compared as bits. Edge cases (edge_*): the mode functions for every mode from -1000 to 1000 and near the ends of i32; the technique, the white level read and the multiplier for every pair of 260 spaces around the enum and the ends of i32; the multiplier at 26 special f32 bit patterns (zeros, subnormals, the normal ends, OBS's levels, infinities, quiet and signalling NaNs of both signs with payloads) for every pair of 9 spaces, against the one division written out; frame2 over every combination of 16 special u64 values and 8 half durations, and at the threshold -2 to +2, against a model in i128 with the modulo explicit; every mode change for 20 modes. Proptests (4000 cases each): frame2 over full-range u64 times and u32 half durations, half of them at the threshold +-3; the multiplier over any space and any white level bit pattern; the mode functions and the linear flag over any i32. soldr cargo test -p obs-data --test obs-tests-core source::deinterlace_draw fails 27 of 27 with "not yet implemented". Refs obs-rust#2130 * obs-source: Port the deinterlace draw decisions Ports libobs/obs-source-deinterlace-draw.c.h, the deinterlace draw decisions of obs-source-deinterlace.c, to the deinterlace_draw module of rust/obs-source. obs-source-deinterlace.c.h stays C: every gs_* call in its order and under its conditions, obs_load_effect() and the effect slots, the technique names, convert_video_space(), obs_get_video_sdr_white_level(), enable_deinterlacing(), disable_deinterlacing() and obs_enter_graphics(). The hybrid libobs drops the C file and links the Rust shims in its place. Safe core (src/deinterlace_draw.rs): - effect() and effect_index(): a match over the mode's int, the C's numbers (DISCARD 0 to YADIF_2X 7, RETRO drawing with discard 2x), None for DISABLE and any value outside the enum; mode_known() is DISABLE or an effect; - linear_required(): BLEND to YADIF_2X; - skip(): no current or previous texture, or a width or height of 0; - reads_linear_srgb() (GS_CS_SRGB only) and linear_srgb() (not GS_CS_SRGB, the graphics flag, or linear_required()); - technique(), Technique with the C's numbers: DrawMultiply for SDR or 709_EXTENDED into scRGB, DrawTonemap for 709_EXTENDED into SDR, DrawMultiplyTonemap for scRGB into SDR, DrawMultiply for scRGB into 709_EXTENDED, Draw otherwise (spaces outside the enum included); reads_white_level() when it multiplies; - multiplier(): sdr_white_level / 80.0 into scRGB, 80.0 / sdr_white_level out of it, 1.0 otherwise: one f32 division, the same IEEE operation as the C's, so the bits match, NaN payloads and infinities included; - frame2(): video_time >= frame_ts + offset + half_duration - TWOX_TOLERANCE (deinterlace_pacing's), each step wrapping_* as the C's uint64_t (obs-rust#395, obs-rust#1995, obs-rust#2048); - mode_change(): a mode outside the enum is DISABLE (obs-rust#2120), then same, enable from DISABLE, disable to DISABLE, else switch. The module denies clippy's arithmetic, indexing, as, unwrap, expect, panic, todo, unimplemented and unreachable lints, keeps no state and takes no lock. Shim (src/ffi/source_deinterlace_draw.rs): the ten functions keep the C signatures, plain values in and out. The effect comes back as int (-1 for none), the technique and the mode change as the C's enum values. No intentional differences: there is no pointer to check. C side: the file leaves libobs.core-source for its own group, libobs.ported-source-deinterlace-draw (LIBOBS_PORTED_SOURCES), whose PCH is obs.h (the two enums), obs-source-deinterlace-draw.h and obs-source-deinterlace-pacing.h (TWOX_TOLERANCE). libobs.pch.h keeps the header for obs-source-deinterlace.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 ten 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_deinterlace_draw_plan_steps still compiles the C file into itself, unchanged. The new test_deinterlace_draw_plan_steps_rust builds the same test source against libobs_rust-static (and libm except on MSVC): the test calls only the ten functions and includes their header and obs.h for the enum values, so it takes libobs's include directories (SIMDe, obsconfig.h) and links the archive alone. It passes 17 of 17 against the shims. test_deinterlace_2x_field_order, test_deinterlace_mode_load and test_media_restart_first_frame see the swap through the hybrid. Tier 1 source::deinterlace_draw passes 27/27. Refs obs-rust#2130 * obs-source: Check the deinterlace draw port against the C Oracle (oracle/source_deinterlace_draw.c): the original obs-source-deinterlace-draw.c.h, unmodified, with its ten functions renamed to oracle_*, plus every enum value the port uses (the nine modes, the four colour spaces, the effect, technique and mode change values), TWOX_TOLERANCE and the enum, int, bool and float sizes. The rename macros also rename the three enum tags that share their function's name, so the size table names the renamed tags. The bool results are declared as u8 on the Rust side, the byte the C returns. Tier 3 (tests/source/deinterlace_draw_parity.rs, 12 tests). Every function takes and returns plain values, so each run compares the bytes of the two results: the bools as bytes, the enums as values, the multiplier as its f32 bits. - the values and sizes against the C headers; - modes: every value from -70000 to 70000, every 65521st i32 over the whole range and the ends: 205,551 modes, the effect and the linear rule; every mode change between 41 modes (1,681 pairs); - space pairs: the technique, the white level read and the multiplier for every pair of 649 spaces (-320 to 320 and four near each end of i32): 421,201 pairs; every pair of -3 to 6 at 26 special white levels (zeros, subnormals, the normal ends, 80 to 480 nits, infinities, quiet and signalling NaNs of both signs with payloads); - the linear flag for every space, both graphics flags and the 41 modes (53,218); the early return for both flags each and 18 widths and heights (1,296); - frame2 for every combination of 18 special u64 values and 10 half durations (58,320), and at the threshold -2 to +2 (16,200); - deinterlace_render()'s decisions in its order (the early return, the linear sRGB read and flag, the technique, the white level read, the multiplier only when it is read, frame2), one copy on each side: 51,840 renders; - proptests (20,000 cases each): frame2 over full-range u64 times and u32 half durations, half of them at the threshold +-3; the multiplier and technique over any space and any white level bit pattern (never a float range); the mode functions over any i32; the render decisions over all of it at once. Tier 1 and the parity module passed 10 runs in a row with fresh seeds (39/39 each). No regression file came up; the ones the todo!() stub and the mutants left were deleted. Mutation check (once, not committed): 40 mutants, Tier 1 (27 tests) and Tier 3 (12), failures per mutant. | Mutant | Tier 1 | Tier 3 | |---|---|---| | effect: RETRO as discard / YADIF_2X as yadif / DISABLE as discard | 3 / 3 / 3 | 2 / 2 / 2 | | effect_index: blend 2x is 2 | 2 | 3 | | linear_required: RETRO too / not YADIF_2X | 4 / 4 | 5 / 5 | | skip: height ignored / both textures missing only | 1 / 1 | 3 / 3 | | reads_linear_srgb: SRGB_16F too | 2 | 3 | | linear_srgb: graphics flag ignored / mode ignored | 2 / 2 | 3 / 3 | | SRGB_16F not SDR | 4 | 4 | | technique: 709_EXTENDED into SDR not tonemapped / scRGB into SDR not tonemapped / scRGB into 709_EXTENDED drawn | 2 / 2 / 4 | 4 / 4 / 4 | | reads_white_level: DrawMultiply only | 2 | 3 | | multiplier: into scRGB inverted / 80.00001 / times 1/80 / scRGB into scRGB divides | 4 / 4 / 2 / 5 | 4 / 4 / 4 / 2 | | frame2: > / saturating sum / saturating TWOX / no TWOX / half doubled | 6 / 4 / 3 / 6 / 6 | 2 / 3 / 3 / 3 / 3 | | mode_change: unknown kept (pre-obs-rust#2120) / unknown is same / same before normalizing | 4 / 4 / 3 | 2 / 2 / 2 | | shim: no effect is 0 / tonemap numbers swapped / enable and disable swapped | 0 / 0 / 0 | 3 / 4 / 2 | | shim: graphics flag negated / spaces swapped in multiplier / video_time and frame_ts swapped / modes swapped | 0 / 0 / 0 / 0 | 3 / 4 / 3 / 2 | | mode_known: DISABLE unknown | 2 | 0 | | equivalent: multiplier divided in f64 and rounded / disable tested before enable / shim frame_ts and offset swapped / shim width and height swapped | 0 / 0 / 0 / 0 | 0 / 0 / 0 / 0 | 35 are killed by Tier 3. The other five are equivalent through the C ABI: mode_known() is used only by mode_change(), which maps an unknown mode to DISABLE, so DISABLE counting as unknown changes nothing (Tier 1 kills it, as it tests mode_known() itself); a single f32 division done in f64 and rounded is correctly rounded the same; the disable test can only come first when the current mode is DISABLE and the new one is too, which is "same" before either; the sum and the size test are symmetric. Tier 1 does not reach the shim; test_deinterlace_draw_plan_steps_rust and Tier 3 do. No intentional differences: there is no pointer to check. Refs obs-rust#2130 * docs: Record the deinterlace draw port The rust/README.md crate table now lists libobs/obs-source-deinterlace-draw.c.h among the rust/obs-source units, and its port table has a row for it: the ten functions and what they decide, what stays C (every gs_* call in its order and under its conditions, obs_load_effect() and the effect slots, the technique names, convert_video_space(), obs_get_video_sdr_white_level(), enable_deinterlacing(), disable_deinterlacing() and obs_enter_graphics()), why the decisions are separate calls rather than one plan (the early return comes before convert_video_space() and gs_get_color_space()), the modes and spaces as int, the multiplier as one f32 division matching bit for bit, the frame2 wraps it keeps, no intentional differences, the _rust variant of the characterization, the real-libobs tests 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_deinterlace_draw.rs: 1024 renders (the decisions of deinterlace_render() in its order, over every pair of colour spaces, the nine modes, white levels of 80 to 480 nits and field times either side of the threshold, one in 64 returning early) and 1024 mode changes with the new mode's effect, folded into checksums both sides must match. On x86_64 Linux (GCC, not pinned, load average 13 to 17; median, two runs): render_frame 25.2 and 25.8 us Rust, 13.9 and 13.3 us C per 1024 renders (1.8x to 1.9x), about 12 ns more per render, which runs once a frame for each deinterlaced source; mode_change 4.1 and 5.8 us Rust, 6.0 and 4.2 us C, within the noise. Fixes obs-rust#2130
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 #2090
What and why
An async source (a camera, capture card or media source) whose deinterlace mode is not in
enum obs_deinterlace_modedraws nothing:obs_source_set_deinterlace_mode()takes every mode butOBS_DEINTERLACE_MODE_DISABLEas "deinterlacing on". It sets up the previous-frame textures and stores the mode.get_effect()inlibobs/obs-source-deinterlace.c.hhas no effect for a mode it does not know, sodeinterlace_render()has nothing to draw with.A scene collection stores the mode as an int64.
obs_load_source_type()cast it toint, so"deinterlace_mode": 99loaded a black source, and 4294967298 (2^32 + 2) loaded as Retro (2). The UI and obs-websocket only pass enum values, so this needs an edited or generated scene collection, a plugin or a script. Upstream has the same code.The fix:
obs_source_set_deinterlace_mode()takes a mode outside the enum asOBS_DEINTERLACE_MODE_DISABLE. It checks this before it compares with the current mode. On a source that does not deinterlace, nothing changes. On one that does, deinterlacing is disabled the same way setting DISABLE disables it.deinterlace_mode_known()lists the same modes asget_effect().obs_load_source_type()reads the mode as int64. A value past theintrange is passed as DISABLE instead of its low 32 bits. The setter handles every other value.Field order: this setter does not have the same gap.
obs_source_set_deinterlace_field_order()stores "top field first" as a bool. Any value other than TOP is bottom field first, and the getter and the saved value both say BOTTOM, so the source still draws. It is unchanged. The test pins 0, 1, 5 and -1 as before.Callers (checked, not changed):
AddDeinterlacingMenu,SetDeinterlacingMode) only sets enum values. With a bad mode loaded, it now checks Disable instead of nothing.SetInputDeinterlaceModerejects unknown names.GetInputDeinterlaceModealready reported an unknown value asOBS_DEINTERLACE_MODE_DISABLE(the first entry of its enum map).deinterlace_mode.docs/features.mdgets a line under fixed upstream bugs. Exported symbols: 1766 on the C backend, the hybrid and libobs-c-reference, and the three sets are identical.RED → GREEN
RED commit:
9a93d4a18(test: Expect an out-of-range deinterlace mode to be disabled). It addstest_deinterlace_mode_load, a real-libobs test in the graphics suite, registered intest/cmocka/build/test-graph.json. It loads an async test source from obs_data withobs_load_source(), or creates one and calls the setter. It shows the source on channel 0 and pushes solid BGRA frames at the canvas rate until three output frames, read back through a raw video callback, show the source's colour (at most 3 s). Each check also reads the getter and the saved"deinterlace_mode". On the RED commit it fails 5 of 7 on the C backend, the hybrid and libobs-c-reference:loaded_out_of_range_mode_is_disabled(99 and 9),loaded_negative_mode_is_disabled(-1),set_out_of_range_mode_is_disabled(99, -1) andset_out_of_range_mode_after_a_mode_is_disabled(Yadif, then 99, then Blend 2x): the source is shown on 0 or 1 of 89 output frames, and the getter and the saved value give back the bad mode.loaded_mode_past_int_range_is_disabled(2^32 + 2): the source draws, but it reads back 2 (Retro).valid_modes_unchanged(no key, and every mode from DISABLE to Yadif 2x, loaded and set in turn) andfield_order_unchangedpass.GREEN:
80e2eebce. Results on the C backend, the hybrid and libobs-c-reference:test_deinterlace_mode_load7/7;test_deinterlace_2x_field_order73/73;test_deinterlace_pacing_steps23/23, andtest_deinterlace_pacing_steps_rust23/23 (it links the Rust archive only);test_media_restart_first_frame4/4,test_media_restart_stale_frame5/5 andtest_media_sync_offset_restart6/6.ci/local_gate.py --test-diff origin/master,--lane lintand--lane crosspass.Which commit each run was on: the RED results are from the RED commit before the last rebase. The focused GREEN runs, the three full ctests and
--lane crossran on the GREEN commit before master moved. After rebasing onto1a008c7f4, the focused tests, the export comparison,--test-diffand--lane lintran again. On the final head80e2eebce,test_deinterlace_mode_loadandtest_deinterlace_pacing_stepspassed on all three, and--test-diffpassed. The two master commits in that last step do not touch these files.Real app (UI, protocol output or logging changes): not run. There is no change to the UI, protocol output or logging. The menu now shows Disable for a mode that used to check nothing.
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