forge
Explore
Log in

Don't you dare go Hollow

Gate tile rows below decode_stream's refusal (bypass)

Browse files at this commit

b50bec7bf5d5163177211ce1e7e88f2733458314Ahmet Kaan GümüşParent: aad3d34
  • test
    • gate tile rows below decode_stream's refusal (bypass)
Show full message
test(av1): gate tile rows below decode_stream's refusal (bypass)

a_real_aomenc_stream_with_two_tile_rows_decodes_pixel_exact -- 64x128,
--tile-rows=1 (TileRows=2), calls decode_key_frame_tile_with_cdfs
directly (decode_stream still refuses tile_info.rows > 1). Loop filter
left ON per the charter, not bypassed with --loopfilter-control=0 --
deblock_plane runs once over the whole picture with no tile-axis
distinction, and the per-tile loop is already row/col-generic
(tile_num / tile_info.cols, set_tile_origin's y0/y1 symmetric with the
column gate's x0/x1). 20/20 pixel-exact vs ffmpeg, 0 named refusals,
hard tile_hits > 1 assert. Proves the underlying row decode + row
deblocking correct before the refusal is touched.
crates/ec-av1/src/stream.rsmodified+205 -0
@@ -6221,6 +6221,211 @@ mod tests {
62216221 );
62226222 }
62236223
6224+ /// lane-tiles r8 stage 1: the same bypass-the-refusal pattern as the
6225+ /// two-tile-column gate above, this time for tile ROWS -- `decode_stream`
6226+ /// still refuses any `tile_info.rows > 1` stream, so this gate calls
6227+ /// [`decode_key_frame_tile_with_cdfs`] directly to prove the underlying
6228+ /// per-tile loop (already row/col-generic: `tile_num / tile_info.cols`
6229+ /// gives the row, `mi_row_starts`/`set_tile_origin`'s `y0`/`y1` are
6230+ /// exactly symmetric with the column gate's `x0`/`x1`) actually decodes
6231+ /// both tile rows pixel-exact before the refusal is lifted. 64x128 is
6232+ /// one 64px superblock wide and two tall with `--tile-rows=1`
6233+ /// (`TileRows=2`, `--tile-columns=0` keeps `cols=1` so only the row axis
6234+ /// is under test). Loop filter is left ON (no
6235+ /// `--loopfilter-control=0`) per the charter -- deblocking crosses tile
6236+ /// row boundaries by spec default exactly as it crosses column ones, and
6237+ /// `deblock_plane` runs once over the whole decoded picture after every
6238+ /// tile is in, with no tile-axis distinction, so there is no reason to
6239+ /// expect the row boundary to behave differently from the column one r7
6240+ /// already proved -- this gate is what actually proves it either way.
6241+ #[test]
6242+ fn a_real_aomenc_stream_with_two_tile_rows_decodes_pixel_exact() {
6243+ const NAME: &str = "a_real_aomenc_stream_with_two_tile_rows_decodes_pixel_exact";
6244+ if !have_ffmpeg() {
6245+ eprintln!("SKIP {NAME}: no ffmpeg");
6246+ return;
6247+ }
6248+ if !have_aomenc() {
6249+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
6250+ return;
6251+ }
6252+ let (width, height) = (64usize, 128usize);
6253+ let mut matched = 0u32;
6254+ let mut named_refusals = 0u32;
6255+ for attempt in 0..20u32 {
6256+ let seed = 42 + attempt;
6257+ let source = gradients_source(seed, width, height, "duration=0.04:rate=25");
6258+ let y4m = Command::new("ffmpeg")
6259+ .args([
6260+ "-v",
6261+ "error",
6262+ "-f",
6263+ "lavfi",
6264+ "-i",
6265+ &source,
6266+ "-pix_fmt",
6267+ "yuv420p",
6268+ "-f",
6269+ "yuv4mpegpipe",
6270+ "-",
6271+ ])
6272+ .stdin(Stdio::null())
6273+ .stdout(Stdio::piped())
6274+ .stderr(Stdio::piped())
6275+ .output()
6276+ .expect("ffmpeg failed to run");
6277+ assert!(
6278+ y4m.status.success(),
6279+ "ffmpeg fixture: {}",
6280+ String::from_utf8_lossy(&y4m.stderr)
6281+ );
6282+ let mut child = Command::new(aomenc_path())
6283+ .args([
6284+ "--codec=av1",
6285+ "--passes=1",
6286+ "--end-usage=q",
6287+ "--cq-level=45",
6288+ "--cpu-used=0",
6289+ "--limit=1",
6290+ "--kf-max-dist=1000",
6291+ "--threads=1",
6292+ "--row-mt=0",
6293+ "--tile-columns=0",
6294+ "--tile-rows=1",
6295+ // This decoder hardcodes SB_MI=16 (64px) superblocks
6296+ // everywhere; without this aomenc's own default 128x128
6297+ // superblock makes 64x128 exactly ONE superblock tall,
6298+ // so `--tile-rows=1` has nothing to split.
6299+ "--sb-size=64",
6300+ "--enable-rect-partitions=0",
6301+ "--enable-ab-partitions=0",
6302+ "--enable-1to4-partitions=0",
6303+ "--enable-filter-intra=0",
6304+ "--enable-smooth-intra=0",
6305+ "--enable-paeth-intra=0",
6306+ "--enable-directional-intra=0",
6307+ "--enable-angle-delta=0",
6308+ "--enable-tx-size-search=0",
6309+ "--enable-cdef=0",
6310+ "--enable-restoration=0",
6311+ "--max-partition-size=32",
6312+ "--min-partition-size=32",
6313+ "--enable-palette=0",
6314+ "--enable-intrabc=0",
6315+ "--enable-cfl-intra=0",
6316+ "--obu",
6317+ "-o",
6318+ "-",
6319+ "-",
6320+ ])
6321+ .stdin(Stdio::piped())
6322+ .stdout(Stdio::piped())
6323+ .stderr(Stdio::piped())
6324+ .spawn()
6325+ .expect("aomenc failed to start");
6326+ child
6327+ .stdin
6328+ .take()
6329+ .expect("aomenc stdin")
6330+ .write_all(&y4m.stdout)
6331+ .expect("writing y4m to aomenc");
6332+ let out = child.wait_with_output().expect("aomenc failed to run");
6333+ assert!(
6334+ out.status.success(),
6335+ "aomenc refused the fixture: {}",
6336+ String::from_utf8_lossy(&out.stderr)
6337+ );
6338+ let stream = out.stdout;
6339+
6340+ let mut parser = Av1Parser::new();
6341+ let mut pos = 0usize;
6342+ let mut frame = None;
6343+ while pos < stream.len() {
6344+ let obu_offset = pos;
6345+ let obu = parser.parse_obu(&stream[pos..]).unwrap();
6346+ pos += obu.total_size;
6347+ if let ObuKind::Frame(header, tiles) = obu.kind {
6348+ frame = Some((header, tiles, obu_offset));
6349+ break;
6350+ }
6351+ }
6352+ let (header, tiles, obu_offset) = frame.expect("stream has a Frame OBU");
6353+ assert!(
6354+ header.tile_info.rows > 1,
6355+ "{NAME}: aomenc did not actually split into >1 tile row (rows={}, seed {seed})",
6356+ header.tile_info.rows
6357+ );
6358+ assert_eq!(
6359+ tiles.len(),
6360+ header.tile_info.rows as usize,
6361+ "{NAME}: expected one tile per row (cols=1, seed {seed})"
6362+ );
6363+ let tile_bufs: Vec<&[u8]> = tiles
6364+ .iter()
6365+ .map(|t| &stream[obu_offset + t.offset..obu_offset + t.offset + t.size])
6366+ .collect();
6367+
6368+ let enable_filter_intra = parser
6369+ .sequence_header()
6370+ .is_some_and(|seq| seq.enable_filter_intra);
6371+ let enable_edge_filter = parser
6372+ .sequence_header()
6373+ .is_some_and(|seq| seq.enable_intra_edge_filter);
6374+
6375+ let before = crate::decode::tile_hits();
6376+ let picture = match decode_key_frame_tile_with_cdfs(
6377+ &tile_bufs,
6378+ &header.tile_info,
6379+ header.mi_cols,
6380+ header.mi_rows,
6381+ header.quantization.base_q_idx,
6382+ header.frame_width,
6383+ header.frame_height,
6384+ enable_filter_intra,
6385+ enable_edge_filter,
6386+ &header.cdef,
6387+ &header.loop_filter,
6388+ None,
6389+ header.tx_mode == TxMode::Select,
6390+ header.reduced_tx_set,
6391+ header.allow_screen_content_tools,
6392+ header.allow_intrabc,
6393+ ) {
6394+ Err(e) => {
6395+ let msg = e.to_string();
6396+ assert!(
6397+ msg.contains("unsupported"),
6398+ "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
6399+ );
6400+ named_refusals += 1;
6401+ eprintln!("seed {seed} refusal: {msg}");
6402+ continue;
6403+ }
6404+ Ok((picture, _end_cdfs)) => picture,
6405+ };
6406+ let hits = crate::decode::tile_hits() - before;
6407+ assert!(
6408+ hits > 1,
6409+ "{NAME}: tile_hits delta was {hits}, expected >1 -- both tile rows must actually \
6410+ decode, not just tile 0 (seed {seed})"
6411+ );
6412+
6413+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
6414+ assert_eq!(picture.y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg (seed {seed})");
6415+ assert_eq!(picture.u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg (seed {seed})");
6416+ assert_eq!(picture.v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg (seed {seed})");
6417+ matched += 1;
6418+ }
6419+ assert!(
6420+ matched > 0,
6421+ "{NAME}: every attempt refused ({named_refusals} refusals); the gate never decoded \
6422+ a two-tile-row stream"
6423+ );
6424+ eprintln!(
6425+ "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20"
6426+ );
6427+ }
6428+
62246429 /// lane-tiles r7: the `>2 tile columns` refusal's own capability, proven
62256430 /// separately from the 2-column gate above -- `--tile-columns=2` gives
62266431 /// aomenc `TileCols=4` (log2), a real non-last-column right-edge case the