Skip to content

libobs: Show every 2x deinterlaced frame after a buffered source falls behind - #2048

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/deinterlace-prev-frame-flag
Oct 24, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/deinterlace-prev-frame-flag

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #2009

What and why

With Yadif 2x, Linear 2x or Discard 2x, a buffered source (the default) that falls behind could skip a frame a little later. One of the next frames was never shown, and the frame after it came a frame early in its place. Linear 2x lost both fields of that frame. Yadif 2x lost its first field.

What the user sees, before and after (the new behind cases; a 30 fps interlaced source into a 60 fps canvas; the fields shown, in order):

  • before: Linear 2x 0 1 5 7 10 11 12 … (frame 4, fields 8 and 9, never shown); Yadif 2x 0 4 6 9 10 … (field 8 skipped);
  • after: Linear 2x 0 1 5 7 8 9 10 11 12 …; Yadif 2x 0 4 6 7 8 9 10 ….

Frames 1 to 3 are already overdue when they arrive, so the walk drops frame 1 and shows only part of frames 2 and 3. That catch-up is unchanged.

The bug. ready_deinterlace_frames() (libobs/obs-source-deinterlace.c.h) walks a buffered source's queue to the last frame that is due, keeping the previous frame (prev_frame) as the pair of the frame it shows. When three frames are queued and all of them overdue, it does three things on the async_frames.num <= 2 exit:

  • it erases the first frame and returns it to async_cache with remove_async_frame();
  • it finds two frames left;
  • it sets prev_frame->prev_frame = true on the frame it has just returned.

remove_async_frame() clears the flag, but this write comes after it, and cache_video() did not clear the flag when it reused the entry. So the next frame to reuse that entry was queued already flagged. When it was picked with a frame behind it, deinterlace_get_closest_frames() took it as the previous frame of a pair and showed the frame behind it instead. The write is memory-safe: it happens under async_mutex, and cached frames stay allocated. Upstream has the same code.

The intent, and the fix. The line came with the walk in upstream 07c644c (2016, "libobs: Add deinterlacing API functions"), and it has not changed since (git log -S'prev_frame->prev_frame = true'). It is a copy of the walk's other exit (if (prev_frame) prev_frame->prev_frame = true; after the loop). There, prev_frame is the front of the queue and pairs with frame, the frame shown. Every other flag in the code also goes on async_frames.array[0]: the unbuffered path, first_frame() and that exit. In the num <= 2 block, the walk stops and the front frame is shown alone. That is frame when prev_frame is set, and the oldest frame otherwise (the !prev_frame branch). The flag was meant to give frame its previous frame as a pair, but the erase just above had already dropped that frame. There are two ways to fix it:

  • Don't flag (chosen). The exit shows the front frame alone, as it always has: the flag never reached a queued frame, so the pick at the exit does not change. Only the stale flag goes.
  • Flag the front frame (frame, async_frames.array[0]). That would pair it with the frame behind it, a frame the code has never paired at this exit, and drop one more frame every time the exit is reached. In the Tier 3 model it changes all 461 sequences that reach the exit, not just the 170 broken ones. In the behind case it shows 0 3 4 …, which drops frame 2 as well.

So the exit no longer flags anything. Because prev_frame implies frame, else if (!frame && num == 2) becomes a plain if. cache_video() also clears prev_frame when it reuses a cache entry (in the reuse loop, under async_mutex), so a frame from the cache always starts unpaired. I put the clear in cache_video(), not copy_frame_data(): copy_frame_data() also backs the public obs_source_frame_copy(), and the flag describes a frame's place in the queue, not its contents. A new entry comes from obs_source_frame_create(), which zeroes it. Each change alone fixes every RED case, in real libobs and in the model.

Rules kept. git log -L on ready_deinterlace_frames() shows #395 (09d6d8eb4), the -Wshadow rename (08098331c) and #1954 (a5dceb109). Every rule they keep is unchanged:

#1995 did not touch the walk. The six pacing functions, their Rust port and the C oracle are unchanged, so the pacing parity values do not move. The walk itself is not ported and stays C.

Tier 3 caller model (rust/obs-source/tests/source/deinterlace_pacing_parity.rs, the model from #1954 and #1995). Before this PR the model had no frame cache, so it dropped the write to the erased frame ("the C's prev_frame points to a frame already erased"). It now keeps the async cache:

  • cache_video() with clean_cache() and MAX_UNUSED_FRAME_DURATION;
  • remove_async_frame() and free_async_cache();
  • the render's release of the previous frame (deinterlace_update_async_video()).

A reused frame therefore starts with the flag its entry was left with. The walk (as before #2009, no flag, or the front frame flagged) and the clear on reuse can be switched, and the default is the C of this PR. The model also counts the exits after an erase, and the picks that paired a frame whose flag no call of that tick set. One correction to the model: a full queue (MAX_ASYNC_FRAMES) now also empties the queue, as free_async_cache() does. Before, the model only reset last_frame_ts. No existing assertion or pinned count changed: first_frame_cadences still gives 80 runs, 40 fixed and 64 as before.

RED → GREEN

  • RED commit: a315fa177. test_deinterlace_2x_field_order gets 18 cases:

    • behind (8 cases; Yadif 2x and Linear 2x; 60i into 60, 50i into 50, 50i into 60 and 60i into 50 fps). This is the cache-reuse case, reached through the public API (obs_source_output_video() and timestamps only). A source that never showed a frame shows frame 0. Right after a tick it gets frames 1 to 3 at once, stamped 4, 8 and 12 ms after frame 0, so all three are overdue at the next tick: the source's clock stood still while nothing was queued. Right after that tick, frames 4 to 9 come at once at the source's rate after frame 3. Frame 4 reuses frame 1's cache entry. From frame 4's first field on, every field must be shown in order (no two in a row dropped at 60i into 50). The frame duration must be longer than the canvas interval plus 2 ms, so frame 4 is not yet due at the tick after frame 3's. That is why 60i into 30 is not among them.
    • after_pause, buffered (10 cases; Yadif 2x and Linear 2x at the five rate pairs): libobs: Show both fields of the first 2x deinterlaced frame #1995's 150 ms pause, for a buffered source. libobs: Show both fields of the first 2x deinterlaced frame #1995 had left a comment saying a buffered source shows a frame early after a pause. It doesn't on master: these cases pass before and after this PR, and so do the model's pause cadences (150 and 500 ms). While nothing is queued, the source's clock stands still, so a pause or a late delivery never makes three frames due at once. The cases stay as a guard, and the comment is corrected.

    On master it fails 7 of 73 on all three builds (C backend, hybrid, libobs-c-reference), the same cases on each: every behind case except Yadif 2x at 60i into 50, which may drop one field in a row. Linear 2x shows 0 1 5 7 10 11 …, so frame 4 is never shown. Yadif 2x shows 0 4 6 9 10 …, so field 8 is skipped. The 10 after_pause cases and the 55 existing cases pass. That run used the RED test source against master's libobs on 0ee385f46 (the fix stashed), with each library rebuilt before the run. The test file has not changed since; the rebases since then had no conflicts.

  • GREEN: 18705403d. test_deinterlace_2x_field_order 73/73 on the C backend, the hybrid and libobs-c-reference. Each half of the fix alone also gives 73/73 on the C backend (checked once, not committed): the walk without the flag, or the clear in cache_video().

  • Real app (UI, protocol output or logging changes): none. The change shows only in the deinterlaced output, which the real-libobs test measures.

Runs on c70dbdf1c (the branch on 982335a92, with the same tree for this PR's five files as the head 18705403d), all under a private Xvfb -noreset with dbus-run-session, a fresh HOME, ulimit -c 0 and no TMPDIR:

Test C backend hybrid libobs-c-reference
test_deinterlace_2x_field_order, 10 runs 10/10 (73/73 each) 10/10 (73/73 each) 10/10 (73/73 each)
test_deinterlace_pacing_steps 23/23 23/23 23/23
test_deinterlace_pacing_steps_rust (not built: needs the Rust archive) 23/23 23/23
full ctest 410/410 417/417 (not run)
  • No rerun was needed: test_deinterlace_2x_field_order passed all 30 runs. It also passed 30/30 on 6101d6c73 (on 0ee385f46), where the full ctest passed too (403/403 and 409/409, 0 ctest skips). It now takes 146.5 s on this host, against its 300 s timeout (it is RUN_SERIAL). The behind cases wait on output ticks, not fixed sleeps, and push each burst right after a tick. Each frame has at least 7 ms of slack before the next tick on the slowest pair, in the spirit of test_deinterlace_2x_field_order is timing-sensitive (yadif 2x 60i into 60): startup underrun and load-induced hold #456.
  • libobs-c-reference is rebuilt (ninja libobs-c-reference) before every c-ref run, and its mtime is checked. The loader takes libobs-c-reference/libobs.so.30 (ldd with the run's LD_LIBRARY_PATH).
  • Full ctest: no ctest test was skipped. Inside the tests, three cases skip on each lane, as on master: open_crashes_without_obs_core in test_audio_io and test_video_io, and test_hex_float_values_ignore_comma_locale, which needs a comma-decimal locale this host does not have.
  • After the final rebase onto b3912c298 (head 18705403d): test_deinterlace_2x_field_order 73/73 and test_deinterlace_pacing_steps (and _rust) 23/23 on all three builds, once each, with libobs-c-reference rebuilt and its loading checked.

Tier 3 (soldr cargo test -p obs-data --test obs-tests-core source::): 165 passed and 1 ignored on 18705403d (the ignored one is #2021's exhaustive audio_input_parity case); 118/118 before the rebase onto #2021. There are three new tests in deinterlace_pacing_parity, each checking the C functions against the shims call for call:

  • behind_cadence, the behind cases through the model, at the four rate pairs. Before, frames 0 2 3 5 6 7 8 9 are picked, and frame 4 is paired with 5. After, 0 2 3 4 5 6 7 8 9. Each half of the fix alone gives the same picks. Flagging the front frame instead would give 0 3 4 5 ….
  • buffered_walk_cadences, the cadences of first_frame_cadences and low_rate_cadences: 25, 29.97, 50, 59.94 and 12.5 frames a second into 30 and 60 fps, buffered and unbuffered, a new source at three first timestamps, and pauses of 150 and 500 ms with and without a reset. That is 140 runs. 0 change. One run reaches the exit after an erase, no frame is reused flagged, and every run picks its frames in order. Flagging the front frame would change 1.
  • buffered_walk_sequences, the 2000 sequences of sequences_reach_every_branch (jitter, late deliveries and ticks, jumps, resets, a full queue, the buffering toggled). 461 reach the exit after an erase. 170 change, and they are exactly the 170 in which a frame reused with the flag left on was paired. No other run changes. Each half of the fix alone gives the fix's runs. Flagging the front frame would change all 461.

parity_sequences (3000 proptest cases) and sequences_reach_every_branch still pass with the cache in the model.

Other runs:

  • uv run ci/local_gate.py --test-diff origin/master on 18705403d: 3051/3051 passed, 2 skipped (existing ignored tests), doctests ok. Earlier complete runs: 3004/3004 on c70dbdf1c and 2969/2969 on 6101d6c73.
  • uv run ci/local_gate.py --lane lint: ok. --lane cross: ok. Both on 18705403d, and before that on c70dbdf1c and 6101d6c73.
  • cargo clippy -p obs-source -p obs-data --all-targets -- -D warnings is clean; cargo fmt --check and clang-format (.clang-format) are clean.
  • Exported symbols: 1766 on the C backend, the hybrid and libobs-c-reference, identical sets, on 18705403d (and on c70dbdf1c and 6101d6c73).
  • Rebased twice, onto 982335a92 and b3912c298, with no conflicts. The branch changes only docs/features.md, the two libobs files, the parity test and the field-order test, so the unity lists, source-sets.json, test-graph.json and the export lists are master's (checked by hand after each rebase). No existing test expectation changes.

Checklist

  • Base is master (or the description starts with a Stacked: note)
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits (N/A for docs-only; a focused CI fix may push RED and GREEN together)
  • User-visible change: its line in docs/features.md is added or updated (not applicable: no user-visible change)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite (the --test-diff, lint and cross lanes passed locally; nothing is stamped)
  • Warning or flag changes (-W..., ratchets): built with scripting ON (PR CI builds no OBS app: run gh workflow run ci.yml --ref <branch> for the full builds) and cross-checked with clang and MSVC (not applicable: no warning or flag change)
  • Intentional differences from C listed in the parity test header and rust/README.md (ports) (none: the walk is not ported, and the pacing functions are unchanged)

With a double-rate deinterlace mode (Yadif 2x, Linear 2x, Discard 2x), a
buffered source that falls behind can skip a whole frame later on. When
the buffered walk in ready_deinterlace_frames() finds three frames queued
and all of them overdue, it erases the first, returns it to the async
cache with remove_async_frame(), and then sets prev_frame on it.
cache_video() does not clear the flag when it reuses the entry, so the next
frame to reuse it is queued already flagged. When that frame is picked
with a frame behind it, deinterlace_get_closest_frames() takes it as the
previous frame of a pair and shows the frame behind it instead.

test_deinterlace_2x_field_order gets 18 cases:
- behind (Yadif 2x and Linear 2x; 60i into 60, 50i into 50, 50i into 60
  and 60i into 50 fps): a source that never showed a frame shows frame 0.
  Right after a tick it then gets frames 1 to 3 at once, stamped 4, 8 and
  12 ms after frame 0, so all three are overdue at the next tick. Right
  after that tick, frames 4 to 9 come at once at the source's rate after
  frame 3. Frame 4 reuses frame 1's cache entry. From frame 4's first
  field on, every field must be shown in order (no two in a row dropped
  at 60i into 50 fps).
- after_pause, buffered (Yadif 2x and Linear 2x, the five rate pairs): the
  first_frame cases' 150 ms pause, for a buffered source. A pause does not
  reach the walk's exit (the source's clock stands still while nothing is
  queued), so these pass already and guard the pause. The comment that
  called this a separate issue is dropped.

Fails as expected on the C backend: 7 of 73. All the behind cases fail
except Yadif 2x at 60i into 50 fps, which may drop one field in a row.
Linear 2x shows 0 1 5 7 10 11 ...: frame 4 (fields 8 and 9) is never
shown. Yadif 2x shows 0 4 6 9 10 ...: field 8 is skipped. The 10
after_pause cases and the 55 existing cases pass.

Refs obs-rust#2009
@rdoupe
rdoupe requested a review from zackees as a code owner October 24, 2026 04:29
…s behind

With Yadif 2x, Linear 2x or Discard 2x, a buffered source that fell
behind could skip a frame later on. When ready_deinterlace_frames()
found three frames queued and all of them overdue, it erased the first
(prev_frame), returned it to the async cache with remove_async_frame(),
found two frames left, and then set prev_frame->prev_frame on the frame
it had just returned. remove_async_frame() clears the flag, but this
write came after it, and cache_video() did not clear the flag when it
reused the entry. So the next frame to reuse the entry was queued already
flagged. When it was picked with a frame behind it,
deinterlace_get_closest_frames() took it as the previous frame of a pair
and showed the frame behind it instead: one frame early, with the
reused frame's fields skipped (with Yadif 2x, its first field).

The walk's exit no longer flags anything. The line came with the walk
(07c644c, 2016) and was copied from the walk's other exit, where
prev_frame is the front frame and is paired with frame. In this exit,
the frame shown is the front one alone, whether prev_frame is set or
not. Its previous frame has already been erased, so there is nothing to
pair it with. The pick at the exit is unchanged: the flag was never on a
queued frame. (Flagging the front frame instead would pair it with the
frame behind it and drop one more frame at every such exit.)
prev_frame implies frame, so "else if (!frame && num == 2)" becomes a
plain if. cache_video() also clears prev_frame when it reuses a cache
entry, so a frame from the cache always starts unpaired. Each change
alone fixes the RED cases. Every rule of obs-rust#395 in the walk is unchanged:
FRAME_TOLERANCE, deinterlace_offset = 0 on every buffered exit, and the
unbuffered path. The pacing functions, the Rust port and the C oracle are
unchanged.

- Tier 3: the caller model keeps the async cache (cache_video() with
  clean_cache(), remove_async_frame(), free_async_cache() and the
  render's release of the previous frame), so a reused frame starts with
  the flag its entry was left with. A full queue now also empties the
  queue in the model, as free_async_cache() does. The walk and the cache
  can each run as before obs-rust#2009 or as now:
  - behind_cadence runs the behind cases. Before, frames 0 2 3 5 6 7 8 9
    are picked (4 is paired with 5). Now 0 2 3 4 5 6 7 8 9 are picked,
    and each change alone gives the same.
  - buffered_walk_cadences runs the cadences of first_frame_cadences and
    low_rate_cadences, with pauses of 150 and 500 ms (140 runs). None
    changes: one run reaches the exit, and no frame is reused flagged.
  - buffered_walk_sequences runs the 2000 sequences of
    sequences_reach_every_branch. 461 reach the exit and 170 change, the
    170 in which a frame reused with the flag left on was paired.
    Flagging the front frame instead would change all 461.
- docs/features.md: a line under fixed upstream bugs.

test_deinterlace_2x_field_order 73/73 on the C backend, the hybrid and
libobs-c-reference.

Fixes obs-rust#2009
@rdoupe
rdoupe force-pushed the fix/deinterlace-prev-frame-flag branch from 59fb475 to 1870540 Compare October 24, 2026 04:29
@zackees
zackees added this pull request to the merge queue Oct 24, 2026
Merged via the queue into obs-rust:master with commit 3615f2d Oct 24, 2026
31 checks passed
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 24, 2026
…ust#2060)

test_obs_scripting_lua_host_macos and test_obs_scripting_python_host_macos
both create and remove ../PlugIns next to the test binaries. ctest runs
them in parallel, so one removes the folder while the other checks it, and
test_dirs fails with 0 != 1 (merge groups for obs-rust#2048 and obs-rust#2054, 2026-10-24).
A shared RESOURCE_LOCK keeps them from running at the same time.
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
rdoupe added a commit to rdoupe/obs-studio that referenced this pull request Oct 24, 2026
Behaviour-neutral extraction before the Rust port. The decisions of the
async frame copy and cache in obs-source.c.h move to
libobs/obs-source-frame-copy.c.h, declared in the new
libobs/obs-source-frame-copy.h without EXPORT (hidden, as
-fvisibility=hidden keeps them), as six functions on plain values:

- obs_source_frame_copy_plan(format, full_range, height, src, dst):
  copy_frame_data()'s copies. The colour range is copied only when the
  frame is not full range; then, per format, each plane's rows
  ((height + 1) / 2 for 4:2:0 chroma), one copy of linesize x rows in
  size_t when the two line sizes are equal (copy_frame_data_plane()),
  else rows of the smaller line size (copy_frame_data_line()). P216,
  P416 and values outside the enum copy no plane. The switch moved as
  it was. The line sizes cross as a struct of four uint32_t, by value.
- obs_source_frame_copy_cache_step(queued, cache, frame): cache_video()'s
  queue limit (MAX_ASYNC_FRAMES or more queued: clear and refuse), then
  async_texture_changed() (the size or the convert type differs: clear
  and take the size), else keep.
- obs_source_frame_copy_cache_clean(used, unused_count): one entry of
  clean_cache(): an unused entry counts one more call and is dropped at
  MAX_UNUSED_FRAME_DURATION. unused_count stays long.
- obs_source_frame_copy_full_range() and _full_range2(): the range rule
  of obs_source_output_video(), obs_source_preload_video() and
  obs_source_set_video_frame() (a frame that is not YUV is full range),
  and of their *2() variants (resolve_video_range() gives
  VIDEO_RANGE_FULL).
- obs_source_frame_copy_preload_changed(): preload_frame_changed().

obs-source.c.h keeps every memcpy(): copy_frame_data() still copies the
metadata and the colour matrix, then gets the plan and runs it, plane i
from plane i, each row offset y * line size in uint32_t as before.
cache_video() keeps async_mutex, free_async_cache(), the fields it
stores, the walk that picks the first unused entry (obs-rust#2009's prev_frame
reset included), obs_source_frame_create(), the darrays and the refcount
atomics; it passes the two convert types from get_convert_type().
clean_cache() keeps the walk, the destroy and the erase, and stores the
count only into an unused entry, as before. MAX_ASYNC_FRAMES and
MAX_UNUSED_FRAME_DURATION stay where they are, checked against the
header's copies at compile time, as are the plan's 4 planes against
MAX_AV_PLANES.

What the C now reads that it did not read before. None of these reads
changes a result:
- copy_frame_data() reads the first four line sizes of both frames for
  every format;
- cache_video() asks get_convert_type() for both convert types before
  the queue limit (a pure function; before, only a frame under the limit
  asked);
- preload_frame_changed() reads all three fields of both frames when
  there is a preload frame (before, the || stopped at the first
  difference);
- the *2() variants resolve the range where they store it, not first.

Checked against the unchanged functions of origin/master (outside the
tree, not committed): a scratch harness compiles master's
copy_frame_data_line() through cache_video(), preload_frame_changed() and
the six range lines verbatim next to the moved code, with memcpy(),
obs_source_frame_create() and _destroy() hooked, against the C
backend's libobs:
- 2,742,507 copies with fake plane pointers (every format from -3 to 32
  and the int ends against all 625 patterns of the four line sizes,
  equal, smaller, larger, 0 or any, at 11 heights; then random formats,
  heights up to UINT32_MAX and full-range line sizes) make the same
  697,179,469 memcpy() calls (destination, source, size, in order) and
  leave the same destination fields;
- 200,000 copies on real buffers write the same bytes;
- 400 sequences of 2000 steps through cache_video() with a model of
  obs_source_output_video_internal() and the renderer (frames queued,
  released, the queue stalled to its limit, 1949 frames refused there,
  and obs_source_output_video(NULL)) leave the same cache entries (frame,
  used, unused count, fields), queue, cache size, format, range,
  transfer, last_frame_ts and frame pointers after every step, and make
  the same memcpy() calls;
- 200,000 clean_cache() runs over entries of any used flag and count
  (26,755 dropped);
- every preload pair over sizes and formats around the edges, and the
  range rule over formats -300 to 300 and the int ends, both ranges and
  every video_range_type from -5 to 10.
Under ASan and UBSan (halt on error, leak detection), a run of 1,142,507
fake copies, 40,000 real ones and 80 sequences reports nothing. 13 of 14 deliberately broken moves fail the
harness; the one that survives (storing a used entry's count back) is
equivalent.

git log -L on each moved function shows only upstream history, plus the
fork's obs-rust#2048 (obs-rust#2009), whose prev_frame reset stays in cache_video().

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#2192
rdoupe added a commit to rdoupe/obs-studio that referenced this pull request Oct 24, 2026
The rust/README.md crate table now lists libobs/obs-source-frame-copy.c.h
among the rust/obs-source units, and its port table has a row for it:
the six functions and the rules each keeps (with the upstream commits
that made them), what stays C (every memcpy(), the metadata copy, frame
create and destroy, the darrays and the first-unused walk with obs-rust#2048's
prev_frame reset, async_mutex, the refcount atomics and
get_convert_type()), everything crossing by value, the wraps it keeps,
what is characterized and not endorsed (P216 and P416 copy nothing,
UINT32_MAX rows have no chroma rows, a count past 5 is never dropped,
the *2() rule keeps an explicit partial range on RGB), the intentional
difference (the long overflow at LONG_MAX, unreachable), 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_frame_copy.rs, in the sorted modules!
list: 1024 copy plans (every format and two values outside the enum at
1920 x 1080, 1281 x 721 and 3840 x 2160, equal and padded line sizes)
and 1024 frames' cache, clean, range and preload decisions, each folded
into a checksum both sides must match. Neither side allocates, so the
module's fixture check passes. On x86_64 Linux (GCC, not pinned, load
average 45; median per 1024 calls): plan 62.24 us Rust and 39.48 us C
(1.58x), cache 39.00 us Rust and 48.34 us C (0.81x), so about 22 ns
more a plan and well under 0.1 us a frame.

Fixes obs-rust#2192
rdoupe added a commit to rdoupe/obs-studio that referenced this pull request Oct 24, 2026
Behaviour-neutral extraction before the Rust port. The decisions of the
async frame copy and cache in obs-source.c.h move to
libobs/obs-source-frame-copy.c.h, declared in the new
libobs/obs-source-frame-copy.h without EXPORT (hidden, as
-fvisibility=hidden keeps them), as six functions on plain values:

- obs_source_frame_copy_plan(format, full_range, height, src, dst):
  copy_frame_data()'s copies. The colour range is copied only when the
  frame is not full range; then, per format, each plane's rows
  ((height + 1) / 2 for 4:2:0 chroma), one copy of linesize x rows in
  size_t when the two line sizes are equal (copy_frame_data_plane()),
  else rows of the smaller line size (copy_frame_data_line()). P216,
  P416 and values outside the enum copy no plane. The switch moved as
  it was. The line sizes cross as a struct of four uint32_t, by value.
- obs_source_frame_copy_cache_step(queued, cache, frame): cache_video()'s
  queue limit (MAX_ASYNC_FRAMES or more queued: clear and refuse), then
  async_texture_changed() (the size or the convert type differs: clear
  and take the size), else keep.
- obs_source_frame_copy_cache_clean(used, unused_count): one entry of
  clean_cache(): an unused entry counts one more call and is dropped at
  MAX_UNUSED_FRAME_DURATION. unused_count stays long.
- obs_source_frame_copy_full_range() and _full_range2(): the range rule
  of obs_source_output_video(), obs_source_preload_video() and
  obs_source_set_video_frame() (a frame that is not YUV is full range),
  and of their *2() variants (resolve_video_range() gives
  VIDEO_RANGE_FULL).
- obs_source_frame_copy_preload_changed(): preload_frame_changed().

obs-source.c.h keeps every memcpy(): copy_frame_data() still copies the
metadata and the colour matrix, then gets the plan and runs it, plane i
from plane i, each row offset y * line size in uint32_t as before.
cache_video() keeps async_mutex, free_async_cache(), the fields it
stores, the walk that picks the first unused entry (obs-rust#2009's prev_frame
reset included), obs_source_frame_create(), the darrays and the refcount
atomics; it passes the two convert types from get_convert_type().
clean_cache() keeps the walk, the destroy and the erase, and stores the
count only into an unused entry, as before. MAX_ASYNC_FRAMES and
MAX_UNUSED_FRAME_DURATION stay where they are, checked against the
header's copies at compile time, as are the plan's 4 planes against
MAX_AV_PLANES.

What the C now reads that it did not read before. None of these reads
changes a result:
- copy_frame_data() reads the first four line sizes of both frames for
  every format;
- cache_video() asks get_convert_type() for both convert types before
  the queue limit (a pure function; before, only a frame under the limit
  asked);
- preload_frame_changed() reads all three fields of both frames when
  there is a preload frame (before, the || stopped at the first
  difference);
- the *2() variants resolve the range where they store it, not first.

Checked against the unchanged functions of origin/master (outside the
tree, not committed): a scratch harness compiles master's
copy_frame_data_line() through cache_video(), preload_frame_changed() and
the six range lines verbatim next to the moved code, with memcpy(),
obs_source_frame_create() and _destroy() hooked, against the C
backend's libobs:
- 2,742,507 copies with fake plane pointers (every format from -3 to 32
  and the int ends against all 625 patterns of the four line sizes,
  equal, smaller, larger, 0 or any, at 11 heights; then random formats,
  heights up to UINT32_MAX and full-range line sizes) make the same
  697,179,469 memcpy() calls (destination, source, size, in order) and
  leave the same destination fields;
- 200,000 copies on real buffers write the same bytes;
- 400 sequences of 2000 steps through cache_video() with a model of
  obs_source_output_video_internal() and the renderer (frames queued,
  released, the queue stalled to its limit, 1949 frames refused there,
  and obs_source_output_video(NULL)) leave the same cache entries (frame,
  used, unused count, fields), queue, cache size, format, range,
  transfer, last_frame_ts and frame pointers after every step, and make
  the same memcpy() calls;
- 200,000 clean_cache() runs over entries of any used flag and count
  (26,755 dropped);
- every preload pair over sizes and formats around the edges, and the
  range rule over formats -300 to 300 and the int ends, both ranges and
  every video_range_type from -5 to 10.
Under ASan and UBSan (halt on error, leak detection), a run of 1,142,507
fake copies, 40,000 real ones and 80 sequences reports nothing. 13 of 14 deliberately broken moves fail the
harness; the one that survives (storing a used entry's count back) is
equivalent.

git log -L on each moved function shows only upstream history, plus the
fork's obs-rust#2048 (obs-rust#2009), whose prev_frame reset stays in cache_video().

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#2192
rdoupe added a commit to rdoupe/obs-studio that referenced this pull request Oct 24, 2026
The rust/README.md crate table now lists libobs/obs-source-frame-copy.c.h
among the rust/obs-source units, and its port table has a row for it:
the six functions and the rules each keeps (with the upstream commits
that made them), what stays C (every memcpy(), the metadata copy, frame
create and destroy, the darrays and the first-unused walk with obs-rust#2048's
prev_frame reset, async_mutex, the refcount atomics and
get_convert_type()), everything crossing by value, the wraps it keeps,
what is characterized and not endorsed (P216 and P416 copy nothing,
UINT32_MAX rows have no chroma rows, a count past 5 is never dropped,
the *2() rule keeps an explicit partial range on RGB), the intentional
difference (the long overflow at LONG_MAX, unreachable), 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_frame_copy.rs, in the sorted modules!
list: 1024 copy plans (every format and two values outside the enum at
1920 x 1080, 1281 x 721 and 3840 x 2160, equal and padded line sizes)
and 1024 frames' cache, clean, range and preload decisions, each folded
into a checksum both sides must match. Neither side allocates, so the
module's fixture check passes. On x86_64 Linux (GCC, not pinned, load
average 45; median per 1024 calls): plan 62.24 us Rust and 39.48 us C
(1.58x), cache 39.00 us Rust and 48.34 us C (0.81x), so about 22 ns
more a plan and well under 0.1 us a frame.

Fixes obs-rust#2192
chriscoveries pushed a commit to chriscoveries/obsrust-fork that referenced this pull request Oct 24, 2026
…ust#2215)

* libobs: Move the async frame copy plan into obs-source-frame-copy.c

Behaviour-neutral extraction before the Rust port. The decisions of the
async frame copy and cache in obs-source.c.h move to
libobs/obs-source-frame-copy.c.h, declared in the new
libobs/obs-source-frame-copy.h without EXPORT (hidden, as
-fvisibility=hidden keeps them), as six functions on plain values:

- obs_source_frame_copy_plan(format, full_range, height, src, dst):
  copy_frame_data()'s copies. The colour range is copied only when the
  frame is not full range; then, per format, each plane's rows
  ((height + 1) / 2 for 4:2:0 chroma), one copy of linesize x rows in
  size_t when the two line sizes are equal (copy_frame_data_plane()),
  else rows of the smaller line size (copy_frame_data_line()). P216,
  P416 and values outside the enum copy no plane. The switch moved as
  it was. The line sizes cross as a struct of four uint32_t, by value.
- obs_source_frame_copy_cache_step(queued, cache, frame): cache_video()'s
  queue limit (MAX_ASYNC_FRAMES or more queued: clear and refuse), then
  async_texture_changed() (the size or the convert type differs: clear
  and take the size), else keep.
- obs_source_frame_copy_cache_clean(used, unused_count): one entry of
  clean_cache(): an unused entry counts one more call and is dropped at
  MAX_UNUSED_FRAME_DURATION. unused_count stays long.
- obs_source_frame_copy_full_range() and _full_range2(): the range rule
  of obs_source_output_video(), obs_source_preload_video() and
  obs_source_set_video_frame() (a frame that is not YUV is full range),
  and of their *2() variants (resolve_video_range() gives
  VIDEO_RANGE_FULL).
- obs_source_frame_copy_preload_changed(): preload_frame_changed().

obs-source.c.h keeps every memcpy(): copy_frame_data() still copies the
metadata and the colour matrix, then gets the plan and runs it, plane i
from plane i, each row offset y * line size in uint32_t as before.
cache_video() keeps async_mutex, free_async_cache(), the fields it
stores, the walk that picks the first unused entry (obs-rust#2009's prev_frame
reset included), obs_source_frame_create(), the darrays and the refcount
atomics; it passes the two convert types from get_convert_type().
clean_cache() keeps the walk, the destroy and the erase, and stores the
count only into an unused entry, as before. MAX_ASYNC_FRAMES and
MAX_UNUSED_FRAME_DURATION stay where they are, checked against the
header's copies at compile time, as are the plan's 4 planes against
MAX_AV_PLANES.

What the C now reads that it did not read before. None of these reads
changes a result:
- copy_frame_data() reads the first four line sizes of both frames for
  every format;
- cache_video() asks get_convert_type() for both convert types before
  the queue limit (a pure function; before, only a frame under the limit
  asked);
- preload_frame_changed() reads all three fields of both frames when
  there is a preload frame (before, the || stopped at the first
  difference);
- the *2() variants resolve the range where they store it, not first.

Checked against the unchanged functions of origin/master (outside the
tree, not committed): a scratch harness compiles master's
copy_frame_data_line() through cache_video(), preload_frame_changed() and
the six range lines verbatim next to the moved code, with memcpy(),
obs_source_frame_create() and _destroy() hooked, against the C
backend's libobs:
- 2,742,507 copies with fake plane pointers (every format from -3 to 32
  and the int ends against all 625 patterns of the four line sizes,
  equal, smaller, larger, 0 or any, at 11 heights; then random formats,
  heights up to UINT32_MAX and full-range line sizes) make the same
  697,179,469 memcpy() calls (destination, source, size, in order) and
  leave the same destination fields;
- 200,000 copies on real buffers write the same bytes;
- 400 sequences of 2000 steps through cache_video() with a model of
  obs_source_output_video_internal() and the renderer (frames queued,
  released, the queue stalled to its limit, 1949 frames refused there,
  and obs_source_output_video(NULL)) leave the same cache entries (frame,
  used, unused count, fields), queue, cache size, format, range,
  transfer, last_frame_ts and frame pointers after every step, and make
  the same memcpy() calls;
- 200,000 clean_cache() runs over entries of any used flag and count
  (26,755 dropped);
- every preload pair over sizes and formats around the edges, and the
  range rule over formats -300 to 300 and the int ends, both ranges and
  every video_range_type from -5 to 10.
Under ASan and UBSan (halt on error, leak detection), a run of 1,142,507
fake copies, 40,000 real ones and 80 sequences reports nothing. 13 of 14 deliberately broken moves fail the
harness; the one that survives (storing a used entry's count back) is
equivalent.

git log -L on each moved function shows only upstream history, plus the
fork's obs-rust#2048 (obs-rust#2009), whose prev_frame reset stays in cache_video().

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#2192

* test: Characterize the async frame copy plan and cache decisions

test_source_frame_copy_steps compiles libobs/obs-source-frame-copy.c.h
(ASan and UBSan) and calls only its six functions through their header,
with media-io/video-io.h for the enum values. 19 cases:

- the constants (4 planes, MAX_ASYNC_FRAMES 30, MAX_UNUSED_FRAME_DURATION
  5, the step values), and a table of every enum video_format value in
  order with the planes the copy makes and each plane's rows (full or
  (height + 1) / 2);
- the copy plan of every format at 12 heights (0 to 5, 9, 719, 720 and
  1079 to 1081) with equal line sizes (one copy of line size x rows) and
  with a padded source (rows of the destination's line size); planes past
  the count are zero;
- no plane for -1, VIDEO_FORMAT_R10L + 1, 1000 and the int ends, nor for
  P216 and P416 ("Unimplemented"; characterized, not endorsed: no
  in-tree source outputs them); the colour range is still copied;
- odd heights: 4:2:0 chroma rounds up (I420, I010, NV12, P010 and I40A,
  whose alpha plane is full height), 4:2:2 keeps the full height;
- (height + 1) / 2 wraps in uint32_t: UINT32_MAX has 0 chroma rows
  (characterized, not endorsed), and the one copy's size is the size_t
  product (0xffffffff x 0xffffffff here);
- per plane of every format, the source line size equal, smaller,
  1, larger, UINT32_MAX or 0 against the destination's, a destination
  line size of 0 (rows of 0 bytes), and both 0 (one copy of 0 bytes);
  each plane decides on its own two line sizes, and a fifth is never
  read;
- the colour range for each range, from format -2 to R10L + 2;
- the queue limit at 0, MAX_ASYNC_FRAMES - 1, at it, + 1 and SIZE_MAX,
  with the keys equal and different: the limit comes first;
- async_texture_changed(): the width, the height or the convert type
  alone resets, swapped sizes reset, equal keys keep (any values);
- clean_cache(): an unused entry counts 0 to 4 up by one and is dropped
  at 5; past 5 it is never dropped (unreachable, as it is erased at 5;
  characterized, not endorsed), a used entry keeps any count and is not
  counted, and five calls from 0 drop it on the fifth;
- the range rule: YUV keeps its range, any other format and values
  outside the enum are full range; the *2() rule: VIDEO_RANGE_DEFAULT is
  partial for YUV and full otherwise, an explicit range is kept (an RGB
  frame with VIDEO_RANGE_PARTIAL stays limited there, unlike the first
  rule), a range outside the enum is not full;
- preload_frame_changed(): no preload frame is always a change; the
  width, the height or the format alone is one.

The test is in the native test graph in name order, with libm except on
MSVC. On the C backend it passes 19 of 19, also on its own with ASan
leak detection and halt on error.

Refs obs-rust#2192

* obs-source: Add Tier 1 tests for the async frame copy plan port

Tests for the port of libobs/obs-source-frame-copy.c.h to the frame_copy
module of rust/obs-source, next to conversion_plan. The safe core is a
stub (todo!()):

- copy_plan(), obs_source_frame_copy_plan() on plain values: the format
  as the C's int, the range, the height and the four line sizes of each
  frame, a CopyPlan back (the colour range flag, the count and four
  PlaneCopy of whole, bytes as usize, rows and the two strides);
- its pieces: plane_rows() (the planes of each format and whether each
  one's rows are the height or half()), half() ((height + 1) / 2 in u32)
  and plane_copy() (one plane);
- cache_step() (cache_video()'s queue limit, then texture_changed(),
  async_texture_changed() on two Keys of size and convert type) and
  clean() (one entry of clean_cache(), a CacheAge of in use, counted or
  dropped, the count a c_long as the C's long);
- full_range() and full_range2() (the range rules of
  obs_source_output_video() and its *2() variant), with is_yuv() and
  resolve_range() (format_is_yuv() and resolve_video_range());
- preload_changed() (preload_frame_changed(), the preload frame an
  Option<Shape>).
The video_format values are conversion_plan's; MAX_ASYNC_FRAMES,
MAX_UNUSED and the video_range_type values are new constants.

tests/source/frame_copy.rs ports test_source_frame_copy_steps 1:1: its
19 cases under the same names (steps_*), in the same order, with the same
inputs and expectations.

Edge cases (edge_*): half() at its ends; plane_copy() for each relation;
the plan is its pieces for formats -3 to 30 at heights up to u32::MAX;
the queue limit over every length up to 64 and usize::MAX; clean() over
counts -10 to 10 and at c_long::MAX (the C's ++ would overflow there; no
entry gets past 5, and the port wraps); the range rules against is_yuv()
and resolve_range() for formats -3 to 40 and ranges -3 to 5. Proptests
(4000 cases each): any format outside the enum copies nothing; each
plane against a model in u64 arithmetic (height + 1 reduced modulo 2^32,
then halved) for any i32 format and any u32 height and line sizes,
biased to the ends; cache_step() for any keys and queue length; clean()
for any count; preload_changed() for any shapes.

soldr cargo test -p obs-data --test obs-tests-core source::frame_copy
fails 28 of 30 with "not yet implemented". The two that pass,
steps_constants and steps_table_covers_every_format, read only the
constants and the test's own tables.

Refs obs-rust#2192

* obs-source: Port the async frame copy plan

Ports libobs/obs-source-frame-copy.c.h, the async frame copy plan and
cache decisions of obs-source.c, to the frame_copy module of
rust/obs-source. obs-source.c.h stays C: every memcpy() (it runs the
plan), the metadata copy, obs_source_frame_create() and _destroy(), the
async_cache and async_frames darrays and the walk that picks the first
unused entry, async_mutex, the refcount atomics and get_convert_type().
The hybrid libobs drops the C file and links the Rust shims in its
place.

Safe core (src/frame_copy.rs):
- plane_rows(): copy_frame_data()'s switch, a match over the format's
  int giving each plane's rows rule (the height, or half() for 4:2:0
  chroma), none for P216, P416 and any value outside the enum. Every
  format is matched by name, so a new one must be placed.
- half() is (height + 1) / 2 with wrapping_add, so UINT32_MAX gives 0
  as the C's uint32_t does; plane_copy() is one copy of
  dst x rows as a usize product (wrapping_mul, the C's size_t) when the
  line sizes are equal, else rows of the smaller line size;
  copy_plan() zips the rules with the four line sizes of each frame and
  sets the colour range flag when the frame is not full range.
- cache_step(): the queue limit (MAX_ASYNC_FRAMES) first, then
  texture_changed() on the two keys.
- clean(): an unused entry's ++unused_count in c_long, wrapping, and the
  drop when it reaches MAX_UNUSED.
- full_range() and full_range2(), with is_yuv() and resolve_range()
  (format_is_yuv() and resolve_video_range(), matched by name).
- preload_changed() on an Option<Shape>.
The module denies clippy's arithmetic, indexing, as (one allowed cast,
u32 to usize), unwrap, expect, panic, todo, unimplemented and unreachable
lints, keeps no state and takes no lock.

Shims (src/ffi/source_frame_copy.rs): the six functions, with the header's
structs mirrored #[repr(C)] and everything passed and returned by value,
so no pointer crosses and the shims read and write no memory of the
caller. The step crosses as the C's enum value. No intentional
difference, except where the C is undefined: ++unused_count overflows a
long at LONG_MAX, where the shim wraps; no entry gets past 5.

C side: the file leaves libobs.core-source for its own group,
libobs.ported-source-frame-copy (LIBOBS_PORTED_SOURCES), whose PCH is
<string.h>, media-io/video-io.h (the enums, format_is_yuv() and
resolve_video_range()) and the header. libobs.pch.h keeps the header for
obs-source.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 is
in the hybrid libobs). ci/test_ported_sources.py checks the group on
every host.

test_source_frame_copy_steps still compiles the C file into itself,
unchanged. The new test_source_frame_copy_steps_rust builds the same test
source against libobs_rust-static (and libm except on MSVC): the test
calls only the six functions and includes their header and
media-io/video-io.h, neither of which needs SIMDe, so this variant runs
the shims and the structs' layout. It passes 19 of 19.
test_video_frame, the media restart tests, the v4l2 and PipeWire camera
tests and the deinterlace tests see the swap through the hybrid.

Tier 1 source::frame_copy passes 30/30.

Refs obs-rust#2192

* obs-source: Check the async frame copy plan port against the C

Oracle (oracle/source_frame_copy.c): the original
obs-source-frame-copy.c.h, unmodified, with its six functions renamed to
oracle_* (the rename also renames the plan struct's tag, consistently),
plus the layout of the six structs (size, alignment, every offset), the
constants, the step and range values, the long, size_t, int, bool and
enum sizes, and every enum video_format value. The structs are mirrored
on the Rust side and passed by value, as the C does.

Tier 3 (tests/source/frame_copy_parity.rs, 14 tests): every call runs the
shim, the oracle and the core, and compares every field:
- the layout and the values against the C headers;
- exhaustive over format x line-size relation: 38 format values (-3 to
  30 and the int ends) against all 625 patterns of the four planes (the
  source's line size equal, smaller, larger or 0, or the destination's
  0), at 16 heights (0 to 5, 1079 to 1081 and the u32 wrap edges), 3
  destination line sizes (1920, 7, UINT32_MAX) and both ranges:
  2,280,000 plans, with one copies, row copies and no copy reached;
- the line sizes real frames have, padded and not, at real sizes;
- the cache step over every queue length up to 64 and the usize ends,
  against keys at the field ends that differ in one field alone or with
  the size swapped;
- the clean step over every count from -1000 to 1000 and the c_long ends;
- the range rules over formats -300 to 300 and the int ends, both ranges
  and every range from -10 to 10 and the int ends;
- the preload rule over every combination of shapes around the edges;
- proptests (8192 cases each) over full-range u32 heights and line sizes
  with any format, any queue length and keys, any count, any format and
  range, and any preload shapes.

Intentional difference, unreachable, kept out of the oracle on every
platform: an unused entry's ++unused_count at LONG_MAX overflows a long,
which is undefined (MSVC can trap overflows, as STATUS_INTEGER_OVERFLOW
did in obs-rust#2184's Windows run). The oracle is never called with that
input; there the shim and the core both wrap to LONG_MIN and are
compared with each other. Counts start at 0 and an entry is erased at
5. Every other input of every function is defined C on every platform:
the plan's arithmetic is unsigned (no division but (height + 1) / 2 in
uint32_t), and the formats and ranges are only converted and compared.

Tier 1 and the parity module passed 10 runs in a row with fresh seeds.
The regression files hold the seeds proptest saved while mutants failed;
all of them pass on the port.

Mutation check (once, not committed; Tier 1 with 30 tests and Tier 3
with 14 in one run, failures per mutant): 40 mutants, 31 in the core and
9 in the shims. 37 fail; the 3 that survive are equivalent.

| Mutant | Tier 1 | Tier 3 |
|---|---|---|
| half saturating / rounds down | 4 / 8 | 2 / 3 |
| I420 plane 2 full height / NV12 chroma full height | 5 / 5 | 3 / 3 |
| I40A alpha half height / I422 chroma half height | 4 / 4 | 3 / 3 |
| P216 copies plane 0 / Y800 copies nothing | 3 / 3 | 3 / 3 |
| one copy when dst >= src | 5 | 3 |
| row bytes the larger / the source's | 6 / 4 | 3 / 3 |
| one copy of a single row | 6 | 3 |
| colour range inverted / strides swapped | 4 / 6 | 3 / 3 |
| queue limit strict / at 31 | 3 / 2 | 2 / 3 |
| texture change ignores the convert type / the width | 3 / 1 | 2 / 1 |
| drop at or past the limit / used entries counted | 3 / 3 | 2 / 2 |
| count saturating / not incremented on drop | 1 / 3 | 1 / 1 |
| V210 not YUV / Y800 YUV | 3 / 3 | 1 / 1 |
| default range always partial / *2() "not partial" is full | 2 / 2 | 1 / 2 |
| RGB keeps its range / preload ignores the format / no preload is no change | 2 / 2 / 2 | 2 / 2 / 2 |
| shim: lines swapped / reset and overflow swapped / plan count capped at 3 | 0 | 3 / 3 / 3 |
| shim: in use counted / drop not set / preload always present / range2 arguments swapped | 0 | 2 / 1 / 2 / 1 |
| equivalent: one copy's size saturating (a u32 x u32 product fits a 64-bit usize) | 0 | 0 |
| equivalent: one copy's size from the source's line size (equal to the destination's) | 0 | 0 |
| equivalent: shim swaps width and height in both keys (the comparison is symmetric) | 0 | 0 |

Tier 1 does not reach the shims; Tier 3 kills every shim mutant but the
equivalent one. "count saturating" differs only at LONG_MAX, where the
oracle is not called: Tier 1's edge case and Tier 3's shim-to-core check
there kill it.

Refs obs-rust#2192

* docs: Record the async frame copy plan port

The rust/README.md crate table now lists libobs/obs-source-frame-copy.c.h
among the rust/obs-source units, and its port table has a row for it:
the six functions and the rules each keeps (with the upstream commits
that made them), what stays C (every memcpy(), the metadata copy, frame
create and destroy, the darrays and the first-unused walk with obs-rust#2048's
prev_frame reset, async_mutex, the refcount atomics and
get_convert_type()), everything crossing by value, the wraps it keeps,
what is characterized and not endorsed (P216 and P416 copy nothing,
UINT32_MAX rows have no chroma rows, a count past 5 is never dropped,
the *2() rule keeps an explicit partial range on RGB), the intentional
difference (the long overflow at LONG_MAX, unreachable), 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_frame_copy.rs, in the sorted modules!
list: 1024 copy plans (every format and two values outside the enum at
1920 x 1080, 1281 x 721 and 3840 x 2160, equal and padded line sizes)
and 1024 frames' cache, clean, range and preload decisions, each folded
into a checksum both sides must match. Neither side allocates, so the
module's fixture check passes. On x86_64 Linux (GCC, not pinned, load
average 45; median per 1024 calls): plan 62.24 us Rust and 39.48 us C
(1.58x), cache 39.00 us Rust and 48.34 us C (0.81x), so about 22 ns
more a plan and well under 0.1 us a frame.

Fixes obs-rust#2192
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug: libobs: buffered 2x deinterlacing flags a recycled frame and skips fields after it falls behind

2 participants