From 8d878fe6f28b599e7c3cc7349cefcc7f393211b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 28 Aug 2026 16:57:10 +0300 Subject: [PATCH] wip(av1): r2's skip_mode-desync theory FALSIFIED; real defect is decode-order frame 1's own reconstruction, invisible to the existing pin (hidden frame) COMPILES. Does not fix the pin. Round 3 of lane-comppin, capped at budget. STEP 1/2 OF THE CHARTER, DONE -- DECISIVE, OVERTURNS r2: Added EC_AV1_SKIPMODE_DUMP (decode.rs ~4623, ctx+tell before/after the skip_mode symbol read) and a matching hook in libaom's own read_skip_mode (/tmp/libaom-src/av1/decoder/decodemv.c ~453, EC_SKIPMODE env var, rebuilt into /tmp/libaom-src/build/decoder-debug/aomdec). Direct comparison for the frame r2 called "frame 1" (order_hint=1, the pin's 2nd *shown* frame): ctx sequence: ours 0,1,1,2 aomdec 0,1,1,2 -- MATCH result sequence: ours T,T,T,T aomdec T,T,T,T -- MATCH r2's claim ("real bitstream's block (0,0) is SINGLE-ref LAST, skip_mode false") does not hold under this direct comparison -- it was very likely an artifact of comparing OUR decode-order frame index against aomdec's own *decode*-order frame_number without accounting for AV1's hierarchical-B reorder (decode order for this pin's skip_mode-bearing frames is order_hint 7, then 3, then 1 -- NOT ascending display order; r2's manual aomdec read likely landed on a different frame_number than intended). The raw `tell` numeric gap noted in-flight this round (19 vs 5 bits before the first read) is ALSO not evidence: aom_reader_tell()/od_ec_dec_tell() is a fractional-bit *estimate*, not a raw bit-offset like our debug_bitpos() -- apples to oranges, not comparable numerically. Also confirmed from libaom source (decodemv.c ~1541-1578): comp_group_idx and compound_idx are NEVER read for a skip_mode block -- both stay at their init values (0, 1 = COMPOUND_AVERAGE) unconditionally. So compound_idx is not a desync candidate for this pin's all-skip_mode frame either, closing off the other half of r2's upgrade path 2/3 as inapplicable here (right answer, wrong question -- there is no compound_idx *read* to desync). NEW FINDING THIS ROUND (the actual lead for r4): the existing pixel-diff harness (`scratch_isolate_pinned_mismatch`) only ever compares *shown* frames (display order) against ffmpeg's own (also display-order) output -- so it never directly checks the hidden altref/bwdref frames a shown frame's compound prediction is built from. Added EC_AV1_DECODE_ORDER_DUMP (stream.rs, dumps every decoded frame's post-loop-filter Y+U+V in DECODE order, `pictures_decoded` counter) and cross-checked against aomdec's own EC_AV1_POSTFILT_DUMP for the same pin: decode-order frame 0 (keyframe): byte-exact (as already known) decode-order frame 1 (first hidden alt, predicts ONLY from the exact keyframe -- no other reference exists yet, so DPB/ref_slots corruption is RULED OUT as a cause here): 4439 / 6144 bytes differ (72%), mostly +-1/+-2 (row0 col0: 126 vs 127 ...), one outlier delta 31 at Y offset 4033 (row 63, col 1) cross-checked against aomdec's OWN pre- vs post-loop-filter dump for that same frame: only 333/6144 bytes change from its own loop filter, so the bulk of our 4439-byte gap already exists in *reconstruction*, upstream of loop filtering, not a filter-strength mismatch. This is a much cleaner, earlier, and larger divergence than the "display frame 1" comparison r1/r2 chased (worst delta 4, growing to 60 by frame 23) -- that number was symptom, not source: it is contamination flowing forward from THIS frame (decode-order 1) through refresh_frame_flags into every later reference, exactly like lane-av1blend's already-documented DPB propagation class, except here the corruption's true origin is now pinned to one fully-isolated single-reference-input frame instead of a whole GOP. R4 UPGRADE PATH, IN ORDER: 1. Add a Rust-side PRE-loop-filter dump (hook before apply_deblock is called in decode_inter_frame_tile_with_cdfs, same shape as EC_AV1_DECODE_ORDER_DUMP) and diff against aomdec's EC_AV1_PREFILT_DUMP for decode-order frame 1 specifically -- confirms whether the ~4100+ byte gap is present pre-filter (reconstruction/MC bug) as the pre-vs-post accounting above already implies, or partly filter-side. 2. If pre-filter also mismatches widely: decode-order frame 1's own blocks are skip_mode=true/compound (per the r2/r3 traces), predicting from a single known-exact source (the keyframe) with an MV this round did NOT yet verify against aomdec's own decoded MV for THIS frame (r2's MV claim was for the wrong frame per the falsification above) -- get EC_TRACE mode/mv/ref dumps from decodemv.c for decode-order frame 1 specifically (not "frame 1" by order_hint) and diff mv/ref pair block-by-block against our own EC_AV1_TRACE. 3. Given the pattern (widespread +-1/+-2, one 31-outlier) looks like either a systematic rounding bug in the compound blend/MC round-off (the ALTREF_FRAME single-ref altref-context special case in record_inter, decode.rs ~1023-1032, is one plausible site: this frame's ref pair likely *is* LAST+ALTREF) or a wrong film-grain/identity-matrix path leaking in before the DPB store -- check `film_grain.apply_grain` isn't accidentally hitting this "hidden" frame's stored (pre-grain) picture, though stream.rs's grain gating already looks correct on inspection. STEP 5 (self-pin-on-mismatch for the two gates) -- NOT reached this round, still owed to r4. Instrumentation left in place, all env-var-gated (no behaviour change when unset): EC_AV1_SKIPMODE_DUMP (decode.rs), EC_AV1_DECODE_ORDER_DUMP (stream.rs), EC_SKIPMODE (libaom decodemv.c, rebuild with `make -j12 aomdec` in /tmp/libaom-src/build/decoder-debug if stale). class: dpb-propagation-from-an-unverified-hidden-frame -- same shape as lane-av1blend's already-filed ref_slots/refresh_frame_flags class, but here the true origin is now isolated to ONE frame with only one possible input. --- crates/ec-av1/src/decode.rs | 15 +++++++++++++++ crates/ec-av1/src/stream.rs | 19 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 3e73e433..a2e070f6 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -4622,7 +4622,22 @@ fn decode_inter_block( let skip_mode_ctx = usize::from(neighbours.above_skip_mode[c]) + usize::from(neighbours.left_skip_mode[r]); + // lane-comppin r3: skip_mode desync isolation -- dump ctx + the pre-read + // MSAC tell so it can be diffed against an equivalent hook in libaom's + // own `read_skip_mode`/`av1_get_skip_mode_context`. + if std::env::var_os("EC_AV1_SKIPMODE_DUMP").is_some() { + eprintln!( + "EC_SKIPMODE r={r} c={c} ctx={skip_mode_ctx} skip_mode_present={skip_mode_present} tell_before={}", + dec.debug_bitpos() + ); + } let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1; + if std::env::var_os("EC_AV1_SKIPMODE_DUMP").is_some() { + eprintln!( + "EC_SKIPMODE r={r} c={c} result={skip_mode} tell_after={}", + dec.debug_bitpos() + ); + } if skip_mode { SKIP_MODE_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); } diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 374edbc2..82a7d18a 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -46,6 +46,7 @@ use crate::encode::Picture; pub fn decode_stream(data: &[u8]) -> Result> { let mut parser = Av1Parser::new(); let mut pictures = Vec::new(); + let mut pictures_decoded: usize = 0; // Spec 7.20/7.4: each of the 8 reference slots remembers the picture a // previous frame's `refresh_frame_flags` stored into it, exactly like the // CDF slots below -- `LAST_FRAME` names a slot via `ref_frame_idx[0]`, @@ -421,6 +422,24 @@ pub fn decode_stream(data: &[u8]) -> Result> { let _ = writeln!(f, "mv_joint {:?}", stored_cdfs.mv_joint); } } + // lane-comppin r3: decode-order (not display-order) dump of every + // frame's own post-deblock buffer -- the pre-existing pixel diff + // (`scratch_isolate_pinned_mismatch`) only ever compares *shown* + // frames, so a hidden reference (altref/bwdref) that DPB-corrupts a + // later shown frame is otherwise invisible; diff this byte-for-byte + // against `EC_AV1_POSTFILT_DUMP.fN` from the instrumented aomdec + // build to isolate whether the defect is in a hidden frame's own + // reconstruction or downstream of it. + if let Ok(path) = std::env::var("EC_AV1_DECODE_ORDER_DUMP") { + use std::io::Write; + let idx = pictures_decoded; + if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) { + let _ = f.write_all(&picture.y); + let _ = f.write_all(&picture.u); + let _ = f.write_all(&picture.v); + } + } + pictures_decoded += 1; for i in 0..NUM_REF_FRAMES { if header.refresh_frame_flags & (1 << i) != 0 { cdf_slots[i] = Some(stored_cdfs.clone());