diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index be8f124f..cc5d084e 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -730,6 +730,19 @@ pub(crate) fn rect_partition_hits() -> usize { RECT_PARTITION_HITS.with(|c| c.get()) } +// lane-inter8 r1: how many superblocks an inter tile coded as a single +// whole-SB `PARTITION_NONE` 64x64 inter block (the case aomenc picks for +// static content, previously a named refusal). +thread_local! { + static INTER_SB_NONE_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`INTER_SB_NONE_HITS`]. +pub(crate) fn inter_sb_none_hits() -> usize { + INTER_SB_NONE_HITS.with(|c| c.get()) +} + // lane-rectwire r2: how many `PARTITION_HORZ`/`VERT` strips actually decoded // real (non-skip) coefficients through [`read_coeffs_rect`] -- proves the // rect coefficient reader itself fired, not just the strip-level partition @@ -7779,6 +7792,23 @@ fn read_inter_plane( default_tx_type, None, )?; + // lane-inter8 r1: a 64-point transform covers the whole 64x64 area but + // codes only its top-left 32x32 of frequencies (spec 5.11.40) -- the + // caller hands the 32-point `scan` there, and the coded corner goes into + // the top-left of the true `side`-sized grid before dequantization + // (dqDenom is keyed by the true size, not the corner's), mirroring + // [`read_plane`]'s own `tx_side != side` branch. Every other transform + // this decoder codes has `tx_side == side`, so this is inert below 64. + let tx_side = side.min(32); + let grid = if tx_side == side { + grid + } else { + let mut full = vec![0i32; side * side]; + for row in 0..tx_side { + full[row * side..][..tx_side].copy_from_slice(&grid[row * tx_side..][..tx_side]); + } + full + }; let (dc_delta, ac_delta) = plane_q_delta(plane_idx); let residual = dequant_and_inverse_typed(&grid, side, bit_depth(), CURRENT_Q_IDX.with(|c| c.get()), dc_delta, ac_delta, tx_type); plane.reconstruct_mc(x, y, side, prediction, &residual); @@ -9120,7 +9150,17 @@ fn decode_inter_block( 8 => 3, 16 => 6, 32 => 9, - _ => unreachable!("decode_inter_block leaf side is 8/16/32"), + // lane-inter8 r1: `av1_is_wedge_used` is false at 64x64 + // (`av1_wedge_params_lookup[BLOCK_64X64].wedge_types == + // 0`), so a real encoder writes NO `compound_type` symbol + // there -- COMPOUND_DIFFWTD is inferred. Reading one + // would desync, so refuse by name rather than guess the + // inferred-DIFFWTD blend this round. + _ => { + return Err(unsupported( + "a masked compound 64x64 inter block (compound_type is inferred, not coded, at this size)", + )) + } }; let compound_type = dec.symbol(&mut cdfs.compound_type[wedge_bsize]); if compound_type == 0 { @@ -12085,10 +12125,72 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( } (false, false) => PARTITION_SPLIT, }; + if part64 == PARTITION_NONE { + // lane-inter8 r1: the whole superblock as one 64x64 inter + // block. `SB`-sized syntax throughout (size_group 3, same as + // 32x32 -- `size_group_lookup[BLOCK_64X64] == 3`), luma + // coefficients through `TxbSet::Luma64` with the 32-point + // scan (TX_64X64 codes only its top-left corner, spec + // 5.11.40 -- `read_inter_plane` widens the corner back to + // 64x64 before the inverse transform), chroma as a plain + // 32x32 `TxbSet::Chroma32`. TX_64X64 carries no `tx_type` + // symbol at all, so the intra/inter luma sets coincide. + INTER_SB_NONE_HITS.with(|c| c.set(c.get() + 1)); + decode_inter_block( + &mut dec, + &mut cdfs, + &mut neighbours, + &mut grid, + sb_at, + SB, + mi_cols, + mi_rows, + &mut y, + &mut u, + &mut v, + &ref_y, + &ref_u, + &ref_v, + &ref_slots, + &sign_bias_table, + &global_motion, + base_q_idx, + TxbSet::Luma64, + TxbSet::Luma64, + TxbSet::Chroma32, + TX32, + TX32, + &scan32, + &scan32, + 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, + false, + SB, + SB, + allow_screen_content_tools, + frame_width as usize, + )?; + continue; + } if part64 != PARTITION_SPLIT { return Err(unsupported( - "an inter SB-level partition type other than SPLIT (this decoder's \ - inter tile path only recurses a superblock as SPLIT)", + "an inter SB-level partition type other than NONE or SPLIT (this decoder's \ + inter tile path recurses a superblock only as SPLIT)", )); } diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index fb771602..38600731 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -67,7 +67,8 @@ const REFUSALS: &[&str] = &[ "an inter frame using TxMode::Select (this decoder's inter path never reads a tx_depth symbol, so it desyncs after the first block's mode)", "an inter frame whose global motion for a single-reference frame is AFFINE (unverified this round; ROTZOOM/TRANSLATION/IDENTITY are proven)", "an inter frame with no key frame before it", - "an inter SB-level partition type other than SPLIT (this decoder's inter tile path only recurses a superblock as SPLIT)", + "an inter SB-level partition type other than NONE or SPLIT (this decoder's inter tile path recurses a superblock only as SPLIT)", + "a masked compound 64x64 inter block (compound_type is inferred, not coded, at this size)", "an inter partition below 16x16 (8x8 and smaller inter blocks are not coded yet)", "an intra mode this decoder does not code (round 2)", "an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 8a2b0df0..593f8875 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -2759,6 +2759,165 @@ mod tests { /// single-`LAST_FRAME` P frame (no alt-ref/backward reference this /// decoder's inter path does not model), `--kf-max-dist` past the clip's /// own length keeps frame 0 the only key frame. + /// lane-inter8 r1: the inter tile path's SB-level `PARTITION_NONE` -- a + /// whole 64x64 superblock coded as ONE inter block, which is what aomenc + /// picks for static content and which this decoder refused by name + /// ("an inter SB-level partition type other than SPLIT") until this + /// round. HARD-asserts [`decode::inter_sb_none_hits`] moved (the arm + /// really fired, class refusal-lifted-without-a-gate) and every frame is + /// pixel-exact vs ffmpeg; a decode error is a FAILURE here, never a SKIP + /// (class gate-skips-on-its-own-failure). + fn inter_sb_none_gate(name: &str, ten_bit: bool) { + if !have_ffmpeg() { + eprintln!("SKIP {name}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display()); + return; + } + let (width, height, frame_count) = (64usize, 64usize, 4usize); + // A deterministic synthetic source with real motion (a static source + // codes every inter frame as skip and never exercises the residual + // path); bounded with `-t` (class gate-loader-slurps-whole-file). + let y4m = Command::new("ffmpeg") + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + "mandelbrot=size=64x64:rate=25", + "-t", + "0.16", + "-pix_fmt", + if ten_bit { "yuv420p10le" } else { "yuv420p" }, + // y4m calls 10-bit unofficial (same as the 10-bit key-frame + // gate's own fixture). + "-strict", + "-1", + "-f", + "yuv4mpegpipe", + "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "{name}: ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let mut args: Vec = [ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=40", + "--cpu-used=0", + "--lag-in-frames=0", + "--auto-alt-ref=0", + "--kf-max-dist=1000", + // No cross-frame CDF forwarding in this fixture (see the + // deblocking gate's own note). + "--error-resilient=1", + // This gate targets the SB-level NONE arm only: rect/AB/1-to-4 + // partitions and sub-16x16 splits stay off so a failure here + // cannot be another lane's missing arm. + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--min-partition-size=32", + "--max-partition-size=64", + "--enable-filter-intra=0", + "--enable-smooth-intra=0", + "--enable-paeth-intra=0", + "--enable-directional-intra=0", + "--enable-angle-delta=0", + "--enable-tx-size-search=0", + "--enable-cdef=0", + "--enable-restoration=0", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-cfl-intra=0", + "--enable-ref-frame-mvs=0", + "--obu", + "-o", + "-", + "-", + ] + .iter() + .map(|s| (*s).to_string()) + .collect(); + if ten_bit { + args.insert(1, "--input-bit-depth=10".to_string()); + args.insert(1, "--bit-depth=10".to_string()); + } + let mut child = Command::new(aomenc_path()) + .args(&args) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m.stdout) + .expect("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "{name}: aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let before = decode::inter_sb_none_hits(); + let frames = match decode_stream(&stream) { + Ok(frames) => frames, + Err(e) => { + let pin = std::env::temp_dir().join(format!("{name}-refused.obu")); + let _ = std::fs::write(&pin, &stream); + panic!("{name}: decode_stream refused a real aomenc stream: {e} (pinned at {})", pin.display()); + } + }; + assert!( + decode::inter_sb_none_hits() > before, + "{name}: no whole-superblock inter PARTITION_NONE fired -- this gate proves nothing" + ); + let ffmpeg_frames = if ten_bit { + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) + } else { + ffmpeg_decode_sequence(&stream, width, height, frame_count) + }; + assert_eq!(frames.len(), frame_count, "{name}: frame count"); + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + if got.y != want.y || got.u != want.u || got.v != want.v { + let pin = std::env::temp_dir().join(format!("{name}-mismatch.obu")); + let _ = std::fs::write(&pin, &stream); + panic!("{name}: frame {i} mismatch vs ffmpeg -- stream pinned at {}", pin.display()); + } + } + } + + #[test] + fn a_real_aomenc_inter_sequence_with_a_whole_superblock_block_decodes_pixel_exact() { + inter_sb_none_gate( + "a_real_aomenc_inter_sequence_with_a_whole_superblock_block_decodes_pixel_exact", + false, + ); + } + + #[test] + fn a_real_aomenc_10bit_inter_sequence_with_a_whole_superblock_block_decodes_pixel_exact() { + inter_sb_none_gate( + "a_real_aomenc_10bit_inter_sequence_with_a_whole_superblock_block_decodes_pixel_exact", + true, + ); + } + #[test] fn a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact() { if !have_ffmpeg() {