diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index bd2c2b63..26846431 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -42,6 +42,7 @@ use crate::transform::{TxType, dequant_and_inverse_typed}; const PARTITION_NONE: usize = 0; const PARTITION_SPLIT: usize = 3; +const PARTITION_HORZ_B: usize = 5; const SB_MI: u32 = 16; const BLOCK_MI: u32 = 8; @@ -3642,9 +3643,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( } } _ => { - return Err(unsupported( - "a partition type this encoder never writes", - )); + return Err(unsupported(format!( + "a partition type this encoder never writes (value={part32})" + ))); } } } @@ -4849,6 +4850,10 @@ fn decode_inter_block( // `allow_warped_motion` bits (spec 5.11.24's `read_motion_mode`). switchable_motion_mode: bool, allow_warped_motion: bool, + // lane-warp r5: set by the HORZ_B arm -- the 32x16 top strip is decoded + // as a square 32x32 block, which over-reads a residual unless coded + // `skip`; a non-skip strip must refuse cleanly instead of desyncing. + reject_residual: bool, ) -> Result<()> { let (r, c) = at; let (px, py) = (c * SUB, r * SUB); @@ -4885,6 +4890,14 @@ fn decode_inter_block( let skip_ctx = usize::from(neighbours.above_skip[c]) + usize::from(neighbours.left_skip[r]); let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1; + // lane-warp r5: see `reject_residual` -- a square-block decode of a + // HORZ_B strip is symbol-exact only for `skip` (no residual, no + // motion_mode/warp symbol), so gate here before any further read. + if reject_residual && !skip { + return Err(unsupported( + "a non-skip 32x16 HORZ_B strip needs rectangular residual coding", + )); + } let (has_above, has_left) = (r > 0, c > 0); let (above_inter, left_inter) = (neighbours.above_inter[c], neighbours.left_inter[r]); @@ -5787,8 +5800,8 @@ fn decode_inter_block( } if std::env::var_os("EC_AV1_TRACE").is_some() { eprintln!( - "EC_TRACE mi_row={mi_row} mi_col={mi_col} skip={} is_inter=1 mv=({},{}) is_new_mv={is_new_mv} bsize={side} ref={ref_frame} filter={:?} motion_mode_eligible={} obmc_selected={} tell={}", - skip as u8, mv.0, mv.1, block_filter, motion_mode_eligible as u8, obmc_selected as u8, dec.debug_bitpos() + "EC_TRACE mi_row={mi_row} mi_col={mi_col} skip={} is_inter=1 mv=({},{}) is_new_mv={is_new_mv} bsize={side} ref={ref_frame} filter={:?} motion_mode_eligible={} obmc_selected={} warped={} tell={}", + skip as u8, mv.0, mv.1, block_filter, motion_mode_eligible as u8, obmc_selected as u8, warp_params.is_some() as u8, dec.debug_bitpos() ); } for dr in 0..bw4 { @@ -7311,7 +7324,15 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( ); match (has_cols, has_rows) { (true, true) => { - dec.symbol(&mut cdfs.partition_w64[sb_ctx]); + let part64 = dec.symbol(&mut cdfs.partition_w64[sb_ctx]); + if std::env::var_os("EC_AV1_TRACE").is_some() { + eprintln!( + "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={part64}", + sb_r * SB_MI, + sb_c * SB_MI + ); + } + let _ = part64; } (true, false) => { dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)); @@ -7334,7 +7355,15 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows), ); let part32 = if has_cols32 && has_rows32 { - dec.symbol(&mut cdfs.partition_w32[ctx32]) + let p = dec.symbol(&mut cdfs.partition_w32[ctx32]); + if std::env::var_os("EC_AV1_TRACE").is_some() { + eprintln!( + "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p}", + r32 * BLOCK_MI, + c32 * BLOCK_MI + ); + } + p } else { match (has_cols32, has_rows32) { (true, false) => { @@ -7391,6 +7420,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( skip_mode_frame, switchable_motion_mode, allow_warped_motion, + false, )?; } PARTITION_SPLIT => { @@ -7465,6 +7495,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( skip_mode_frame, switchable_motion_mode, allow_warped_motion, + false, )?; } else { let ctx16 = neighbours.partition_ctx(at16, SUB); @@ -7577,8 +7608,169 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( } } } + PARTITION_HORZ_B => { + // lane-warp r5: PARTITION_HORZ_B = 32x32 top strip + + // 16x16 bottom-left + 16x16 bottom-right. aomenc + // carves static regions into it; the strip is + // decoded as a square 32x32 block: for a `skip` + // block the symbol stream is identical to the true + // 32x16 coding (no residual, no motion_mode/warp + // symbol), and the square stamps it leaves over the + // bottom half (neighbour arrays, skip/lf grids) are + // re-stamped by the C/D leaves right after. The + // mi-granular `left_side_mi` rows of a last-block-in- + // tile strip leak 32-vs-16 only until the per-tile + // `Neighbours::new` reset. + let at32 = (r32 as usize, c32 as usize); + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + at32, + BLOCK, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + base_q_idx, + TxbSet::Luma32, + TxbSet::Luma32Inter, + TxbSet::Chroma16, + TX32, + TX16, + &scan32, + &scan16, + 3, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + true, + )?; + if (r32 + 1) as u32 * SUB_MI < mi_rows { + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + (r32 as usize + 1, c32 as usize), + SUB, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + base_q_idx, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + )?; + if (c32 + 1) as u32 * SUB_MI < mi_cols { + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + (r32 as usize + 1, c32 as usize + 1), + SUB, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + base_q_idx, + TxbSet::Luma16, + if reduced_tx_set { + TxbSet::Luma16Inter + } else { + TxbSet::Luma16InterSet1 + }, + TxbSet::Chroma8, + TX16, + TX8, + &scan16, + &scan8, + 2, + allow_high_precision_mv, + force_integer_mv, + interp_fixed, + enable_dual_filter, + tpl_frame.as_ref(), + reference_select, + enable_masked_compound, + enable_interintra_compound, + enable_jnt_comp, + order_hint_bits, + order_hint, + ref_order_hints, + skip_mode_present, + skip_mode_frame, + switchable_motion_mode, + allow_warped_motion, + false, + )?; + } + } + } _ => { - return Err(unsupported("a partition type this encoder never writes")); + return Err(unsupported(format!( + "a partition type this encoder never writes (value={part32})" + ))); } } } @@ -8333,6 +8525,7 @@ mod tests { [0; 2], false, false, + false, ) .unwrap(); diff --git a/lanes/warp-r5.charter.md b/lanes/warp-r5.charter.md new file mode 100644 index 00000000..92725f3e --- /dev/null +++ b/lanes/warp-r5.charter.md @@ -0,0 +1,71 @@ +# lane-warp r5 charter — pin refuses on an "impossible" partition after the comppin swap fix + +## Where you are +Worktree /home/user/Documents/Code/Rust/edith_codecs-warp, branch lane-warp @ c3c8ec8 +(rebased onto main e1b1543, which HAS the comppin fix: enable_interintra_compound/enable_jnt_comp +un-swapped at the decode_stream call site — do NOT re-investigate that; it is fixed and merged). +Build/test ONLY with: `env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-warp cargo test -p ec-av1 --release --lib -- --ignored --nocapture` +Never plain `cargo test` on the whole workspace. Never touch another worktree. + +## The r5 baseline fact (reproduce FIRST, 1 run) +`pinned_warp_stream_decodes_pixel_exact` (crates/ec-av1/src/stream.rs:3467, fixture +fixtures/warp-mismatch.obu, 621 bytes, aomenc seed-49 warped-motion stream, 64x64, 24 frames): +FAILS with `Unsupported { what: "AV1 tile", why: "a partition type this encoder never writes" }` +from the INTER tile walk refusal at crates/ec-av1/src/decode.rs:7581 (the `_ =>` arm). +With EC_AV1_TRACE=1: frame 0 (key) walks fine (partition_w64 value=3 then w32 zeros); +in the inter frame the last good block is `EC_TRACE mi_row=8 mi_col=0 skip=1 is_inter=1 mv=(6,8) +is_new_mv=true bsize=32 ref=4 filter=[0,0] motion_mode_eligible=1 obmc_selected=0 tell=200`, +then the next partition symbol read hits the refusal. +Historical: BEFORE the swap fix this same stream decoded all 24 frames and mismatched frame-1 +luma pixels — i.e. under the old (wrong) alignment the partition symbols happened to decode to +supported values. So either (a) lane-warp's own symbol consumption between assign_mv and the next +partition read is still wrong (r4 landed WARPED_CAUSAL 3-symbol read_motion_mode + num_proj_ref; +sites: decode.rs:4287 num_proj_ref, decode.rs:4826/5638 read_motion_mode), or (b) alignment is now +CORRECT and the stream genuinely contains an extended partition type (HORZ_A/B, VERT_A/B, +HORZ_4/VERT_4) our inter walk refuses — a capability gap, not a desync. + +## Decide (a) vs (b) FIRST — do not start porting partitions blind +Ground truth: `ffmpeg -i fixtures/warp-mismatch.obu` decodes it (the pin test itself uses +ffmpeg as oracle), so the stream is valid. Decisive checks, cheapest first: +1. Read the partition VALUE at the refusal: add the ctx+value to the refusal-site trace + (mirror the TRACE partition_w8 style at decode.rs:3603) at BOTH refusal arms (decode.rs:3646 + region and 7581). A value in 4..=9 with a PLAUSIBLE ctx = likely (b); a garbage-looking + sequence (e.g. partition after only 2 of 4 32x32 slots walked) = (a). +2. Count symbols per block vs libaom read order (class symbol-consumption-gap: count reads per + block BEFORE tracing one symbol). The block before the refusal is motion_mode_eligible=1, + bsize=32, single-ref (ref=4): confirm we read motion_mode as the 3-symbol WARPED alphabet + exactly when libaom does (libaom read_motion_mode: SIMPLE unless num_proj_ref>=1 && + allow_warped_motion && !large-mv...); check num_proj_ref's gating conditions against + libaom av1_findSamples/av1_selectSamples semantics — an eligibility disagreement on THIS + block shifts every later symbol. +3. If still ambiguous: cross-decoder RANGE compare (class compare-range-not-tell — msac RANGE + after each element, NEVER tell() absolute values; dav1d/aomdec with a state dump, or the + existing EC_AV1_TELL checkpoint machinery, env-gated, already in decode.rs). + +## Then fix +- If (a): fix the consumption gap; pin must go 24/24 pixel-exact (the test asserts vs ffmpeg). +- If (b): DO NOT silently implement all extended partitions in one round. Report the exact + partition type(s) the stream uses; implement ONLY those in the inter walk (decode.rs inter + partition match ~7000-7581), reusing the existing NONE/SPLIT/HORZ/VERT leaf plumbing; + every new arm threads neighbours/partition-ctx exactly as SPLIT does (class + tx-class-cross-cutting: grep every surface indexed by partition kind — scan, ctx, records — + and sweep in ONE round). + +## Done criteria (ALL, evidence in the report) +1. `pinned_warp_stream_decodes_pixel_exact` PASSES (24/24 frames, pixel-exact vs ffmpeg), + run twice, both green, output excerpt in report. +2. `cargo test -p ec-av1 --release --lib` (whole crate lib suite) green; paste the final + `test result:` line. +3. WIP committed to lane-warp (compiling; message prefix `wip(av1): warp r5 ...` stating what + was found and what changed). Commit even on a HANDOFF. +4. REPORT FILE written to lanes/warp-r5.report.md in THIS worktree: verdict line first + (`PASS` or `HANDOFF: `), then (a)-vs-(b) determination WITH the trace evidence, + then what changed, then anything owed. An empty or vague report = the round is void. + +## Hard rules +- ≤60 tool calls; if running out: commit + write the report as HANDOFF with exact resume state. +- Never `git checkout` a file with uncommitted work in it; never touch fixtures/ contents, + main repo, or other worktrees; never push. +- The refusal string is a CLAIM (class refusal-strings-are-claims): it may only survive if a + test proves the capability genuinely absent from the stream — here ffmpeg already decodes + the stream, so the refusal cannot stand as-is.