diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 230c8bf6..07f6e339 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -52,7 +52,6 @@ const REFUSALS: &[&str] = &[ "a frame naming primary_ref_frame at a reference slot with no saved CDF state", "a frame with delta_q_present or delta_lf_present set (this decoder never reads the per-superblock delta symbols)", "a frame with loop restoration enabled (this decoder never reads the per-unit lr symbols)", - "a frame with more than one tile row (only tile columns are proven pixel-exact so far)", "a frame with no mode-info grid", "a frame with segmentation enabled (this decoder never reads a per-block segment_id symbol)", "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 7bfa18d0..3c489d6a 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -307,26 +307,23 @@ pub fn decode_stream(data: &[u8]) -> Result> { // naming a different tile there is refused rather than silently // forwarding the wrong tile's table. // - // lane-tiles r4/r6/r7: the multi-tile refusal itself is scoped, not - // blanket. `decode_key_frame_tile_with_cdfs` and (r6) + // lane-tiles r4/r6/r7/r8: the multi-tile refusal itself is scoped, + // not blanket. `decode_key_frame_tile_with_cdfs` and (r6) // `decode_inter_frame_tile_with_cdfs` both genuinely loop every // tile, `mvstack.rs`'s `MiGrid` is bounded per tile // (`MiGrid::set_tile_bounds`), and `PlaneBuf`'s `tile_x0/y0/x1/y1` // origin receives real values at every call site (r6's - // `set_tile_origin` sweep). r7 proved the two remaining named gaps - // both closed: `a_real_aomenc_stream_with_two_tile_columns_and_an_ - // inter_frame_decodes_pixel_exact` (inter frame, 2 tile columns) and - // `a_real_aomenc_stream_with_four_tile_columns_decodes_pixel_exact` - // (>2 columns AND loop filtering ON, an interior tile boundary) -- - // 20/20 pixel-exact each. Only tile *rows* stay unproven and - // refused; tile *columns* (any count) and loop filtering across - // them are no longer capped. - if header.tile_info.rows > 1 { - return Err(Error::unsupported( - "AV1 decode_stream", - "a frame with more than one tile row (only tile columns are proven pixel-exact so far)", - )); - } + // `set_tile_origin` sweep). r7 proved the two remaining + // tile-*column* gaps closed (inter frames, >2 columns with loop + // filtering on). r8 proved tile *rows* the same way: the per-tile + // loop's row math (`tile_num / tile_info.cols`, + // `mi_row_starts`/`set_tile_origin`'s `y0`/`y1`) is exactly + // symmetric with the column path already proven, and + // `a_real_aomenc_stream_with_two_tile_rows_decodes_pixel_exact` + // (bypass gate, loop filter ON) confirmed it: 20/20 pixel-exact. + // `a_real_aomenc_stream_with_two_tile_rows_decodes_through_decode_ + // stream` below re-proves it through this entry point. Tile columns + // and tile rows (any count, loop filter on) are no longer capped. // `Tile::offset` is relative to the buffer `parse_obu` was handed // (`&data[pos..]` at the time this OBU was parsed), so it is relative // to `obu_offset`, not to `data` as a whole. @@ -6426,6 +6423,135 @@ mod tests { ); } + /// lane-tiles r8 stage 2/3: the same two-tile-row stream as the bypass + /// gate above, this time through `decode_stream` itself -- the entry + /// point real callers use, with the `rows > 1` refusal lifted (same + /// commit) so this actually reaches the tile decode instead of + /// refusing by name. Loop filter ON, no `--loopfilter-control=0`. + #[test] + fn a_real_aomenc_stream_with_two_tile_rows_decodes_through_decode_stream() { + const NAME: &str = "a_real_aomenc_stream_with_two_tile_rows_decodes_through_decode_stream"; + 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) = (64usize, 128usize); + let mut matched = 0u32; + let mut named_refusals = 0u32; + for attempt in 0..20u32 { + let seed = 42 + attempt; + let source = gradients_source(seed, width, height, "duration=0.04:rate=25"); + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", + "yuv4mpegpipe", "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let mut child = Command::new(aomenc_path()) + .args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=45", + "--cpu-used=0", + "--limit=1", + "--kf-max-dist=1000", + "--threads=1", + "--row-mt=0", + "--tile-columns=0", + "--tile-rows=1", + "--sb-size=64", + "--enable-rect-partitions=0", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--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", + "--max-partition-size=32", + "--min-partition-size=32", + "--enable-palette=0", + "--enable-intrabc=0", + "--enable-cfl-intra=0", + "--obu", + "-o", + "-", + "-", + ]) + .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(), + "aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + + let before = crate::decode::tile_hits(); + let pictures = match decode_stream(&stream) { + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" + ); + named_refusals += 1; + eprintln!("seed {seed} refusal: {msg}"); + continue; + } + Ok(pictures) => pictures, + }; + let hits = crate::decode::tile_hits() - before; + assert!( + hits > 1, + "{NAME}: tile_hits delta was {hits}, expected >1 -- both tile rows must actually \ + decode, not just tile 0 (seed {seed})" + ); + assert_eq!(pictures.len(), 1, "{NAME}: expected exactly 1 picture (seed {seed})"); + + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1); + assert_eq!(pictures[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})"); + assert_eq!(pictures[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})"); + assert_eq!(pictures[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})"); + matched += 1; + } + assert!( + matched > 0, + "{NAME}: every attempt refused ({named_refusals} refusals); decode_stream never \ + decoded a two-tile-row stream" + ); + eprintln!( + "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20" + ); + } + /// lane-tiles r7: the `>2 tile columns` refusal's own capability, proven /// separately from the 2-column gate above -- `--tile-columns=2` gives /// aomenc `TileCols=4` (log2), a real non-last-column right-edge case the