forge
Explore
Log in

Don't you dare go Hollow

Gate r6's inter tile-loop lift -- real >1-tile-column INTER stream

Browse files at this commit

a4b8abf8ac5047b7652c19805841b396f3515807Ahmet Kaan GümüşParent: 9e42602
  • test
    • gate r6's inter tile-loop lift -- real >1-tile-column INTER stream
Show full message
test(av1): gate r6's inter tile-loop lift -- real >1-tile-column INTER stream

a_real_aomenc_stream_with_two_tile_columns_and_an_inter_frame_decodes_pixel_exact
proves decode_stream's lifted "inter frame with more than one tile" refusal:
2 tile columns, --limit=2 --kf-max-dist=1000 for a genuine inter frame 1,
gradients_source's default speed=0.01 rotation gives real motion so the MV
stack actually crosses the tile boundary. 20/20 pixel-exact vs ffmpeg, hard
tile_hits > frames assert.

Also fixes decode_inter_frame_tile_with_cdfs never incrementing TILE_HITS
(only the key-frame loop did) -- the gate's own tile-count assert would have
been vacuously blind to the inter path without this.
crates/ec-av1/src/decode.rsmodified+1 -0
@@ -9812,6 +9812,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9812 mi_row1 as usize,9812 mi_row1 as usize,
9813 mi_col1 as usize,9813 mi_col1 as usize,
9814 );9814 );
9815+ TILE_HITS.with(|c| c.set(c.get() + 1));
9815 9816
9816 for sb_r in sb_r0..sb_r1 {9817 for sb_r in sb_r0..sb_r1 {
9817 neighbours.start_row();9818 neighbours.start_row();
crates/ec-av1/src/stream.rsmodified+183 -0
@@ -6358,4 +6358,187 @@ mod tests {
6358 "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20"6358 "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20"
6359 );6359 );
6360 }6360 }
6361+
6362+ /// lane-tiles r7: the gate stage 2 (r6, commit 8899fc1) shipped without
6363+ /// -- a real >1-tile-column stream with a genuine INTER frame (not just
6364+ /// the key-frame-only two-column gate above), decoded through
6365+ /// `decode_stream` itself. Same recipe as the key-frame gate
6366+ /// (`--sb-size=64`, `--tile-columns=1`, `--loopfilter-control=0`, the
6367+ /// same feature-disable envelope so the gate isolates the tile loop, not
6368+ /// an unrelated unimplemented mode) plus `--limit=2 --kf-max-dist=1000`
6369+ /// so frame 1 is a real inter frame, and `gradients_source`'s default
6370+ /// `speed=0.01` rotation (undisturbed -- not overridden by the tail)
6371+ /// gives it genuine motion against frame 0, so `decode_inter_frame_tile_
6372+ /// with_cdfs`'s new per-tile loop and `MiGrid`'s per-tile bound actually
6373+ /// have to walk a live MV stack across the tile-column boundary, not
6374+ /// just replay skip/zero-mv blocks. Bounded with `duration=0.08` (2
6375+ /// frames at rate=25) per the class in ledger
6376+ /// `refusal-claim-disproved-by-its-own-gate`/`gate-loader-slurps-whole-
6377+ /// file` (never leave an ffmpeg/lavfi generate unbounded).
6378+ #[test]
6379+ fn a_real_aomenc_stream_with_two_tile_columns_and_an_inter_frame_decodes_pixel_exact() {
6380+ const NAME: &str =
6381+ "a_real_aomenc_stream_with_two_tile_columns_and_an_inter_frame_decodes_pixel_exact";
6382+ if !have_ffmpeg() {
6383+ eprintln!("SKIP {NAME}: no ffmpeg");
6384+ return;
6385+ }
6386+ if !have_aomenc() {
6387+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
6388+ return;
6389+ }
6390+ let (width, height) = (128usize, 64usize);
6391+ let frames = 2usize;
6392+ let mut matched = 0u32;
6393+ let mut named_refusals = 0u32;
6394+ for attempt in 0..20u32 {
6395+ let seed = 42 + attempt;
6396+ let source = gradients_source(seed, width, height, "duration=0.08:rate=25");
6397+ let y4m = Command::new("ffmpeg")
6398+ .args([
6399+ "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f",
6400+ "yuv4mpegpipe", "-",
6401+ ])
6402+ .stdin(Stdio::null())
6403+ .stdout(Stdio::piped())
6404+ .stderr(Stdio::piped())
6405+ .output()
6406+ .expect("ffmpeg failed to run");
6407+ assert!(
6408+ y4m.status.success(),
6409+ "ffmpeg fixture: {}",
6410+ String::from_utf8_lossy(&y4m.stderr)
6411+ );
6412+ let mut child = Command::new(aomenc_path())
6413+ .args([
6414+ "--codec=av1",
6415+ "--passes=1",
6416+ "--end-usage=q",
6417+ "--cq-level=45",
6418+ "--cpu-used=0",
6419+ &format!("--limit={frames}"),
6420+ "--kf-max-dist=1000",
6421+ "--lag-in-frames=0",
6422+ "--auto-alt-ref=0",
6423+ "--threads=1",
6424+ "--row-mt=0",
6425+ "--tile-columns=1",
6426+ "--tile-rows=0",
6427+ "--sb-size=64",
6428+ "--loopfilter-control=0",
6429+ "--max-reference-frames=3",
6430+ "--reduced-reference-set=1",
6431+ "--enable-warped-motion=0",
6432+ "--enable-obmc=0",
6433+ "--enable-masked-comp=0",
6434+ "--enable-interintra-comp=0",
6435+ "--enable-dist-wtd-comp=0",
6436+ "--enable-diff-wtd-comp=0",
6437+ "--enable-onesided-comp=0",
6438+ "--enable-interintra-wedge=0",
6439+ "--enable-smooth-interintra=0",
6440+ "--enable-ref-frame-mvs=0",
6441+ "--enable-rect-partitions=0",
6442+ "--enable-ab-partitions=0",
6443+ "--enable-1to4-partitions=0",
6444+ "--enable-filter-intra=0",
6445+ "--enable-smooth-intra=0",
6446+ "--enable-paeth-intra=0",
6447+ "--enable-directional-intra=0",
6448+ "--enable-angle-delta=0",
6449+ "--enable-tx-size-search=0",
6450+ "--enable-cdef=0",
6451+ "--enable-restoration=0",
6452+ "--max-partition-size=32",
6453+ "--min-partition-size=32",
6454+ "--enable-palette=0",
6455+ "--enable-intrabc=0",
6456+ "--enable-cfl-intra=0",
6457+ "--obu",
6458+ "-o",
6459+ "-",
6460+ "-",
6461+ ])
6462+ .stdin(Stdio::piped())
6463+ .stdout(Stdio::piped())
6464+ .stderr(Stdio::piped())
6465+ .spawn()
6466+ .expect("aomenc failed to start");
6467+ child
6468+ .stdin
6469+ .take()
6470+ .expect("aomenc stdin")
6471+ .write_all(&y4m.stdout)
6472+ .expect("writing y4m to aomenc");
6473+ let out = child.wait_with_output().expect("aomenc failed to run");
6474+ assert!(
6475+ out.status.success(),
6476+ "aomenc refused the fixture: {}",
6477+ String::from_utf8_lossy(&out.stderr)
6478+ );
6479+ let stream = out.stdout;
6480+
6481+ // Confirm aomenc actually split into >1 tile column and that
6482+ // frame 1 is a real inter frame before trusting a pixel match --
6483+ // otherwise a match could mean "tiles collapsed to 1" or "frame
6484+ // 1 fell back to key", not "the inter tile loop ran".
6485+ let mut parser = Av1Parser::new();
6486+ let mut pos = 0usize;
6487+ let mut saw_multi_tile_inter = false;
6488+ while pos < stream.len() {
6489+ let obu_offset = pos;
6490+ let obu = parser.parse_obu(&stream[pos..]).unwrap();
6491+ pos += obu.total_size;
6492+ if let ObuKind::Frame(header, _) = obu.kind
6493+ && header.frame_type != FrameType::Key
6494+ && header.tile_info.cols > 1
6495+ {
6496+ saw_multi_tile_inter = true;
6497+ }
6498+ }
6499+ assert!(
6500+ saw_multi_tile_inter,
6501+ "{NAME}: seed {seed} never produced a >1-tile-column inter frame (aomenc \
6502+ collapsed tiling or coded frame 1 as key)"
6503+ );
6504+
6505+ let before = crate::decode::tile_hits();
6506+ let pictures = match decode_stream(&stream) {
6507+ Err(e) => {
6508+ let msg = e.to_string();
6509+ assert!(
6510+ msg.contains("unsupported"),
6511+ "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
6512+ );
6513+ named_refusals += 1;
6514+ eprintln!("seed {seed} refusal: {msg}");
6515+ continue;
6516+ }
6517+ Ok(pictures) => pictures,
6518+ };
6519+ let hits = crate::decode::tile_hits() - before;
6520+ assert!(
6521+ hits > frames,
6522+ "{NAME}: tile_hits delta was {hits}, expected > {frames} -- both tiles of both \
6523+ frames must actually decode (seed {seed})"
6524+ );
6525+ assert_eq!(pictures.len(), frames, "{NAME}: expected {frames} pictures (seed {seed})");
6526+
6527+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames);
6528+ for (i, (got, want)) in pictures.iter().zip(&ffmpeg_frames).enumerate() {
6529+ assert_eq!(got.y, want.y, "{NAME}: seed {seed} frame {i} luma vs ffmpeg");
6530+ assert_eq!(got.u, want.u, "{NAME}: seed {seed} frame {i} U vs ffmpeg");
6531+ assert_eq!(got.v, want.v, "{NAME}: seed {seed} frame {i} V vs ffmpeg");
6532+ }
6533+ matched += 1;
6534+ }
6535+ assert!(
6536+ matched > 0,
6537+ "{NAME}: every attempt refused ({named_refusals} refusals); decode_stream never \
6538+ decoded a two-tile-column inter frame"
6539+ );
6540+ eprintln!(
6541+ "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20"
6542+ );
6543+ }
6361 }6544 }