From 2451a89d25485f0caee1229348cd68732234b0f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 17:10:32 +0300 Subject: [PATCH] test(av1): interior tile-row boundary gate (four rows), mirroring r7's four-column gate a_real_aomenc_stream_with_four_tile_rows_decodes_pixel_exact -- --tile-rows=2 (TileRows=4), 64x256, loop filter ON, through decode_stream. Proves an interior row boundary (row 1/2, neither top nor bottom frame edge) the two-tile-row gate's edge case (row 1 is also the bottom edge) couldn't exercise, same reason r7 needed 4 columns rather than 2. 20/20 pixel-exact vs ffmpeg, 0 refusals, hard tile_hits > 2 assert. --- crates/ec-av1/src/stream.rs | 147 ++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 3c489d6a..c726b1f7 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -6736,6 +6736,153 @@ mod tests { ); } + /// lane-tiles r8: the tile-*row* analogue of the four-tile-column gate + /// above -- `--tile-rows=2` gives aomenc `TileRows=4` (log2; uniform + /// tile spacing is always a power of two, so this is the smallest count + /// that has an interior row neither the top nor bottom frame edge, + /// mirroring why the column gate needed 4 columns rather than 3). 64x256 + /// is four 64x64 superblocks tall with `--sb-size=64`, one per tile row. + /// Loop filter ON, run through `decode_stream` itself since the + /// `rows > 1` refusal is already lifted by this commit. + #[test] + fn a_real_aomenc_stream_with_four_tile_rows_decodes_pixel_exact() { + const NAME: &str = "a_real_aomenc_stream_with_four_tile_rows_decodes_pixel_exact"; + 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, 256usize); + 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=2", + "--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 mut parser = Av1Parser::new(); + let mut pos = 0usize; + let mut rows_seen = 0u32; + while pos < stream.len() { + let obu = parser.parse_obu(&stream[pos..]).unwrap(); + pos += obu.total_size; + if let ObuKind::Frame(header, _) = &obu.kind { + rows_seen = header.tile_info.rows; + } + } + assert!( + rows_seen > 2, + "{NAME}: aomenc did not actually split into >2 tile rows (rows={rows_seen}, seed {seed})" + ); + + 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 > 2, + "{NAME}: tile_hits delta was {hits}, expected >2 -- all four tile rows must \ + actually decode, not just a subset (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); the gate never decoded \ + a four-tile-row stream" + ); + eprintln!( + "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20" + ); + } + /// lane-tiles r4/r7: the same real two-tile-column stream as the /// bypass gate above, this time run through `decode_stream` itself -- /// the entry point real callers use. Proves the `cols > 1` refusal is