Repository navigation
libobs: Show both fields of the first 2x deinterlaced frame - #1995
Merged
Merged
Conversation
rdoupe
force-pushed
the
fix/deinterlace-first-frame
branch
from
October 23, 2026 22:45
86b3b6a to
bf32f98
Compare
With a double-rate deinterlace mode (Yadif 2x, Linear 2x, Discard 2x), the first frame a source shows, or the first after a pause, has its second field skipped, or less often held too long. Its half duration is taken from the gap to deinterlace_frame_ts, which is 0 for a source that never showed a frame (half its own timestamp, truncated: 1.78 s for a capture timestamp 1000 s after boot) and the last frame shown after a pause (a 10 s pause gives 705 ms). obs_source_deinterlace_pacing_half_duration() gets two more arguments, the half duration before and the canvas interval, so the tests can state the fallback. They are not used yet: the C, the Rust port and the C oracle behave as before. - test_deinterlace_pacing_steps (and its _rust variant) and the Rust Tier 1 port: half_duration_first_frame and first_frame_half_duration_hold now expect the fixed values (half the canvas interval for a new source, the half duration before after a restart or a pause). half_duration_over_2_32_truncated and half_duration_timestamp_backwards_wraps become half_duration_after_a_pause and half_duration_timestamp_backwards, and half_duration_fallback is new. seq_unbuffered_first_frame runs the unbuffered model from a source that never showed a frame, and seq_unbuffered_12_5 pins 12.5 frames a second (80 ms gaps), which must keep its half durations from the gap. - The Tier 1 edge model and proptests take the new rule. - test_deinterlace_2x_field_order gets 15 cases that count the first frame's fields, field 0 included: first_frame (a source that never showed a frame, buffered and unbuffered) and after_pause (an unbuffered source that pauses for 150 ms, past TS_JUMP_THRESHOLD), with Linear 2x at the five rate pairs. The 40 existing cases still leave out their first two frames: their first measured frame follows the last warm-up frame back to back, so it has no frame duration either way. Fails as expected on all three builds (C backend, hybrid, libobs-c-reference): the steps test 7 of 23, Tier 1 9 of 33, and test_deinterlace_2x_field_order 10 of 55: the three first-frame cases at 60i into 60, 50i into 50 and 50i into 60 fps, and the buffered first_frame case at 50i into 30 fps (Linear 2x at 60i into 60 fps shows 0 2 3 ..., field 1 skipped). The 40 existing cases pass. Refs obs-rust#1965
With Yadif 2x, Linear 2x or Discard 2x, the first frame a source showed, and the first after a restart, a full queue or a pause, lost its second field, or was held too long. When that frame was picked with no second frame queued, its half duration was half the gap to deinterlace_frame_ts: 0 for a new source, so half its own timestamp truncated to 32 bits (1.78 s for a capture timestamp 1000 s after boot), or the last frame shown, so 705 ms after a 10 s pause. A buffered source then showed the second field only after the next frame had replaced the first; an unbuffered one held the frame past TS_JUMP_THRESHOLD, moved on as if the clock had jumped, or, when the truncation left 0.5 to 35.5 ms, held it too long. obs_source_deinterlace_pacing_half_duration() no longer takes a half duration from a gap that is no frame duration: no previous timestamp (0), one at or after the frame (a timestamp going backwards), or one more than twice TS_JUMP_THRESHOLD before it, a half duration past the threshold (a pause or a new clock). It keeps the half duration before when that is set and at most TS_JUMP_THRESHOLD, and else takes half the canvas interval, so the second field comes at the next tick. A regular stream with frames up to 140 ms apart keeps its half durations, so a source below 14.3 frames a second does not change. The C, the Rust port and the C oracle (which compiles the libobs file) change alike; every rule of obs-rust#395 and of the unbuffered hold is unchanged. - Tier 3: the sequences now count the fallbacks (no previous timestamp, backwards, past the threshold; the half duration kept or half the interval) instead of the truncation, which can no longer happen. first_frame_cadences runs 25, 29.97, 50 and 59.94 frames a second into 30 and 60 fps, buffered and unbuffered, for a new source and after a pause, through the model of the caller: the C and the shims agree, the first frame shows its fields as a source timed from a frame before it would (buffered always; unbuffered unless its next frame is there at the next tick), and from the next pick on every state is the one of before. low_rate_cadences does the same at 12.5 frames a second: every state after the first frame, and up to a pause, is the one of before. - docs/features.md: a line under fixed upstream bugs. rust/README.md and the module docs drop the characterized truncation and first-frame behaviour. test_deinterlace_pacing_steps (and _rust) 23/23, Tier 1 33/33, Tier 3 13/13, and test_deinterlace_2x_field_order 55/55 on the C backend, the hybrid and libobs-c-reference. Fixes obs-rust#1965
rdoupe
force-pushed
the
fix/deinterlace-first-frame
branch
from
October 23, 2026 23:08
bf32f98 to
f1c31cd
Compare
This was referenced Oct 24, 2026
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
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
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 #1965
What and why
With a double-rate deinterlace mode (Yadif 2x, Linear 2x, Discard 2x), the first frame a source shows lost its second field, or, less often, was held too long. The same happened to the first frame after a restart, a full queue or a pause. Now the first field pair at each start is shown correctly: the first field at the tick that picks the frame, the second at the next tick, before the next frame.
The cause is in
libobs/obs-source-deinterlace-pacing.c.h(moved and ported torust/obs-sourcedeinterlace_pacingby #1954; upstream has the same code). When the first frame is picked with no second frame queued, its half duration was half the gap todeinterlace_frame_ts:deinterlace_frame_tsis 0, so the half duration was half the frame's own timestamp, truncated to 32 bits: 1.78 s for a capture timestamp 1000 s after boot;A buffered source (the default) then showed the second field only after the next frame had replaced the first. An unbuffered one held the frame past
TS_JUMP_THRESHOLD, so it moved on as if the clock had jumped, without the second field. In about 0.8 % of starts the truncation left 0.5 to 35.5 ms instead, and the frame was held too long.The fix.
obs_source_deinterlace_pacing_half_duration()takes two more arguments, the half duration before and the canvas interval (obs->video.video_frame_interval_ns). It no longer takes a half duration from a gap that is no frame duration:prev_ts0);TS_JUMP_THRESHOLD(140 ms), which would give a half duration past the threshold: a pause or a new clock.Then it keeps the half duration before, if that is set and at most
TS_JUMP_THRESHOLD(the same limit), and otherwise takes half the canvas interval. The gap limit is twice the threshold so that a regular stream below 14.3 frames a second (frames more than 70 ms apart) keeps timing each frame from the one before, exactly as before; with a 70 ms limit, a 12.5 fps stream fell back on every frame and changed every later state. A new source therefore shows its second field at the next tick, and a source after a restart or a pause keeps the field duration it had. Both call sites indeinterlace_get_closest_frames()pass the same values, so the pair path follows the same rule. The C, the Rust port and the C oracle (which compiles the libobs file itself) change in the same way. Every rule from #395 and from the unbuffered hold (3ea98b8: the hold, its jump threshold, "don't skip ahead", the buffered offset, the re-anchor) is unchanged, and each is still pinned by its characterization case. Nothing else inobs-source-deinterlace.c.hchanges.Two commits:
Refs #1965). The two new arguments are added to the signature, unused, so that the tests can state the rule. The C, the Rust port and the oracle still behave as before.test_deinterlace_pacing_steps(and its_rustvariant) and its Tier 1 port inrust/obs-source: the half duration cases,seq_unbuffered_first_frame, which runs the unbuffered model from a source that never showed a frame, andseq_unbuffered_12_5, which pins a 12.5 fps stream (80 ms gaps) to its half durations from the gap. That case passes before and after the fix, by design.test_deinterlace_2x_field_ordergets 15 cases that count the first frame's fields from field 0, with Linear 2x at the five rate pairs:first_frame_*: a source that never showed a frame, buffered and unbuffered;after_pause_*: an unbuffered source that pauses for 150 ms.Fixes #1965): the rule in C and Rust. Tier 3 gets the cadence evidence (below) and counts the fallbacks, where it used to count the truncation, which can no longer happen. Also thedocs/features.mdline, and the README row and module docs, which drop the characterized first-frame and truncation behaviour.Cadence evidence (Tier 3
first_frame_cadences, through #1954's model of the caller: the queue, the buffered walk,first_frame()and the stores in the C's order). It covers 25, 29.97, 50 and 59.94 frames a second into 30 and 60 fps canvases, buffered and unbuffered. Each pair runs five starts: a new source whose first timestamp is 1000 s after boot, one at 5 s, and one that left 30 ms (the held-too-long case), then a 500 ms pause with and without a queue reset. That is 80 runs. Each run is compared with two references: the half duration of before, and an "ideal" one that knows the source's field duration.last_frame_ts, the offset, the half duration, the frame timestamps) is byte-equal to before in all 64 runs where the old code did not hold the first frame too long. In the other 16 runs the old code picked the next frame later, which is the bug, and the fix picks it when the ideal run does.frame_interval_ns - FRAME_TOLERANCEshows those 6 fields. But at 29.97 into 30 and 59.94 into 60 it then changes every later state: about a tick of extra latency for the whole stream. This PR keeps the latency.12.5 fps (Tier 3
low_rate_cadences): 12.5 frames a second (25 fields, 80 ms apart) into 30 and 60 fps, buffered and unbuffered, from the same five starts, 20 runs. The C and the shims agree. After a pause, every state from the stream's second frame up to the pause is byte-equal to before. From the measured frame's next pick on, every state is byte-equal to before (all 16 runs without the held-too-long start), and a new source shows its first field at its pick. With the 70 ms limit this test fails.The steps test's
seq_unbuffered_first_framechecks the same thing for the unbuffered model at the eight rate pairs and at 12.5 fps into 30 and 60:Observed, not changed:
test_deinterlace_2x_field_ordercase a 150 ms pause before its measured frames. Buffered Yadif 2x at 60i into 60 fps then showed0 1 2 5 5 5 6 ...: frame 1's fields were skipped and field 5 was held for three frames. It did the same before and after this fix. This looks like the staleprev_frameflag in the buffered walk that obs-source: Port the 2x deinterlace frame pacing #1954 described (its "Observed, not changed" item 2). So this PR adds pause cases for unbuffered sources only, and that one can be its own issue.0 1 1 1 2 3 .... Its first frame is held for one or two extra ticks, because the buffered clock starts from it; the next frame comes when it did before.RED → GREEN
RED commit:
7bb85f397. On all three builds (C backend, hybrid,libobs-c-reference):test_deinterlace_pacing_stepsand_rustfail 7 of 23. The 12.5 fps caseseq_unbuffered_12_5passes, as it should: that behaviour does not change;soldr cargo test -p obs-data --test obs-tests-core source::deinterlace_pacing) fails 9 of 33;test_deinterlace_2x_field_orderfails 10 of 55. These are the three new cases at each of 60i into 60, 50i into 50 and 50i into 60 fps, and the buffered first-frame case at 50i into 30 fps. Every one fails on its first frame: Linear 2x at 60i into 60 fps shows0 2 3 4 ..., with field 1 skipped. The 40 existing cases pass.test_deinterlace_2x_field_orderis unchanged since the RED run, which was on59577ac08(before the gap-limit change and the rebases). The steps and Tier 1 counts are from the RED code with the current tests. Against the RED code, Tier 3'sfirst_frame_cadencesfails at its first run (25 into 30 fps, buffered, new source: the second field is not shown), andlow_rate_cadencespasses.GREEN:
f1c31cd0e. Steps tests 23/23 and Tier 1 33/33. Tier 3 13/13, including both cadence tests andsequences_reach_every_branch, which reaches each fallback more than 100 times. Tier 2 results are in the table below.Real app: no UI, protocol or logging change. The change is in the fields shown, which
test_deinterlace_2x_field_orderchecks through the real libobs.Tier 2 ran under a private
Xvfb -noresetwithdbus-run-session, a fresh HOME,ulimit -c 0, no audio server and no TMPDIR set. Before every c-ref run,libobs-c-referencewas rebuilt withninja libobs-c-reference, and the run checked that the loader usedlibobs-c-reference/libobs.so.30and printed its mtime.test_deinterlace_pacing_stepstest_deinterlace_pacing_steps_rusttest_deinterlace_2x_field_order(55 cases), final ruletest_deinterlace_2x_field_order, first version (70 ms gap limit)23eec77a3(on01843e7c5). After the rebase ontoc1351a665, the steps tests and 1 more field-order run per build ran at the headf1c31cd0e.a1a6cbee9, whose gap limit wasTS_JUMP_THRESHOLD. On the field-order test the two limits behave the same: its frames are 33 to 40 ms apart, and its pause of 150 ms is past both limits.open_crashes_without_obs_coreintest_audio_ioandtest_video_io, andtest_hex_float_values_ignore_comma_locale.sequences_reach_every_branch, over 2,000 sequences:TS_JUMP_THRESHOLD(70 ms, the first version)low_rate_cadencesamong them)<TS_JUMP_THRESHOLDOther runs:
uv run ci/local_gate.py --test-diff origin/master: 2940/2940 passed, 1 skipped (an existing ignored test), at the headf1c31cd0e. It also passed on23eec77a3and on the first version.uv run ci/local_gate.py --lane lint: ok at the head.--lane cross: ok on23eec77a3. The only change since then is the rebase onto three frontend/CI commits.libobs-c-reference, with identical sets, at the head.obs_source_deinterlace_pacing_half_durationis local (t) in all three.c1351a665, then ontod33f07fb4right before posting (no conflict), then onto4ec76eda9after obs-source: Port the source colour space query routing #1990 (therust/README.mdrows conflicted); after thatsource::(115/115) and the lint lane were re-run and pass. After each rebase, thelibobs/buildunity lists,source-sets.json,test-graph.jsonand the export lists were compared by hand against master: this PR touches none of them.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 (not applicable: no warning or flag change)