forge
Explore
Log in

Don't you dare go Hollow

Pin the square-only 64x64 intra superblock inside an inter frame

Browse files at this commit

f0eee7425cedfbd9207f2d739fe0d65baa8cd0a7Ahmet Kaan GümüşParent: 3cff0d9
  • test
    • pin the square-only 64x64 intra superblock inside an inter frame
Show full message
test(av1): pin the square-only 64x64 intra superblock inside an inter frame

With rect partitions off the encoder can hand a whole 64x64 superblock of an
inter frame to an intra block. That block's uv_mode must come off the 13-symbol
no-CFL alphabet (is_cfl_allowed caps CFL at 32x32); reading the 14-symbol CFL
one gave the same DC_PRED value with the wrong interval and desynced the tile
from that block on -- silently, since the decoder then read a phantom refusal
out of the diverged stream. Gate: real aomenc, 192x128 mandelbrot, two detail
levels x two quantisers x two bit depths, 8 decode-order frames each compared
Y/U/V against ffmpeg, hard-asserting a nonzero no-CFL uv_mode counter.
crates/ec-av1/src/stream.rsmodified+160 -0
@@ -6897,6 +6897,166 @@ mod tests {
68976897 );
68986898 }
68996899 }
6900+ /// lane-sqdrift r2: the SQUARE-ONLY twin of the no-CFL `uv_mode` gate
6901+ /// above. With `--enable-rect-partitions=0` the encoder codes only
6902+ /// `PARTITION_NONE` and `PARTITION_SPLIT`, and on detailed content the RD
6903+ /// eventually hands one whole 64x64 superblock of an INTER frame to an
6904+ /// INTRA block -- `bsize == sb_size`, the one shape whose `uv_mode` must
6905+ /// come off the 13-symbol `uv_mode_no_cfl` alphabet because libaom's
6906+ /// `is_cfl_allowed` (`blockd.h`: `wide <= 32 && high <= 32`) excludes it.
6907+ ///
6908+ /// Before the fix this decoder read the 14-symbol CFL alphabet there: the
6909+ /// same `DC_PRED` value, a different interval, and the tile desynced from
6910+ /// that block on. r1 measured the damage on the pinned 192x128 stream
6911+ /// (sha256 `c6af4fb4...`): decode-order frames 0-3 pre-filter byte-exact,
6912+ /// frame 4 luma 3540 samples wrong over exactly the last superblock
6913+ /// (x 128..191, y 64..127), then 24k wrong by frame 7 -- and the decoder
6914+ /// did not even report a mismatch, it reported an intra-rect-strip refusal
6915+ /// read out of the already-desynced stream (class `refusal-from-own-desync`;
6916+ /// aomdec's own partition histogram over that stream is rect-free).
6917+ /// After the fix the same stream is byte-exact on all 8 frames.
6918+ ///
6919+ /// Distinct from the sibling gate: rect partitions OFF (so the 64x64 NONE
6920+ /// really is a whole superblock), `--min-partition-size=16`, natural
6921+ /// mandelbrot detail instead of a synthetic half-noise ramp, and 8 frames
6922+ /// of drift so a desync that survives one frame still fails here. Every
6923+ /// decode-order frame of every attempt is compared against ffmpeg, so a
6924+ /// mismatch of ANY shape fails; the gate never turns one into a SKIP.
6925+ #[test]
6926+ fn a_real_aomenc_square_only_inter_sequence_with_a_64x64_intra_superblock_decodes_pixel_exact()
6927+ {
6928+ const NAME: &str = "a_real_aomenc_square_only_inter_sequence_with_a_64x64_intra_superblock_decodes_pixel_exact";
6929+ let _gate_lock = lock_gate_counters();
6930+ if !have_ffmpeg() {
6931+ eprintln!("SKIP {NAME}: no ffmpeg");
6932+ return;
6933+ }
6934+ if !have_aomenc() {
6935+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
6936+ return;
6937+ }
6938+ let (width, height, frame_count) = (192usize, 128usize, 8usize);
6939+ for bit_depth in [8u32, 10u32] {
6940+ let (mut named_refusals, mut matched, mut carried_none) = (0u32, 0u32, 0u32);
6941+ let mut total_hits = 0usize;
6942+ for attempt in 0..4u32 {
6943+ // r1's pinned recipe is (start_scale 4.76, cq 55); the other
6944+ // three points move the detail level and the quantiser, which
6945+ // is what moves WHICH superblock the RD codes intra.
6946+ let start_scale = ["4.76", "3.20"][(attempt % 2) as usize];
6947+ let cq = [55, 45][(attempt / 2) as usize];
6948+ let duration = frame_count as f64 / 25.0;
6949+ let source = format!(
6950+ "mandelbrot=size={width}x{height}:start_scale={start_scale}:\
6951+ end_scale=0.004:end_pts=8:rate=25"
6952+ );
6953+ let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" };
6954+ let y4m = Command::new("ffmpeg")
6955+ .args([
6956+ "-v", "error", "-f", "lavfi", "-i", &source, "-vf", "hue=s=0",
6957+ "-t", &duration.to_string(), "-pix_fmt", pix_fmt, "-strict", "-1",
6958+ "-f", "yuv4mpegpipe", "-strict", "-1", "-",
6959+ ])
6960+ .stdin(Stdio::null())
6961+ .stdout(Stdio::piped())
6962+ .stderr(Stdio::piped())
6963+ .output()
6964+ .expect("ffmpeg failed to run");
6965+ assert!(
6966+ y4m.status.success(),
6967+ "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}",
6968+ String::from_utf8_lossy(&y4m.stderr)
6969+ );
6970+ let cq_arg = format!("--cq-level={cq}");
6971+ let depth_arg = format!("--bit-depth={bit_depth}");
6972+ let input_depth_arg = format!("--input-bit-depth={bit_depth}");
6973+ let args: Vec<&str> = vec![
6974+ "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=1",
6975+ "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg,
6976+ "--lag-in-frames=0", "--auto-alt-ref=0",
6977+ "--kf-min-dist=1000", "--kf-max-dist=1000",
6978+ "--enable-rect-partitions=0", "--enable-ab-partitions=0",
6979+ "--enable-1to4-partitions=0", "--min-partition-size=16",
6980+ "--max-partition-size=64", "--enable-tx-size-search=0",
6981+ "--enable-order-hint=0", "--enable-warped-motion=0", "--enable-obmc=0",
6982+ "--enable-masked-comp=0", "--enable-interintra-comp=0",
6983+ "--enable-dist-wtd-comp=0", "--enable-diff-wtd-comp=0",
6984+ "--enable-onesided-comp=0", "--enable-interintra-wedge=0",
6985+ "--enable-smooth-interintra=0", "--enable-filter-intra=0",
6986+ "--enable-smooth-intra=0", "--enable-paeth-intra=0",
6987+ "--enable-directional-intra=0", "--enable-angle-delta=0",
6988+ "--enable-cdef=0", "--enable-restoration=0", "--enable-palette=0",
6989+ "--enable-intrabc=0", "--enable-cfl-intra=0", "--enable-ref-frame-mvs=0",
6990+ "--obu", "-o", "-", "-",
6991+ ];
6992+ let mut child = Command::new(aomenc_path())
6993+ .args(&args)
6994+ .stdin(Stdio::piped())
6995+ .stdout(Stdio::piped())
6996+ .stderr(Stdio::piped())
6997+ .spawn()
6998+ .expect("aomenc failed to start");
6999+ child
7000+ .stdin
7001+ .take()
7002+ .expect("aomenc stdin")
7003+ .write_all(&y4m.stdout)
7004+ .expect("writing y4m to aomenc");
7005+ let out = child.wait_with_output().expect("aomenc failed to run");
7006+ assert!(
7007+ out.status.success(),
7008+ "aomenc refused the fixture: {}",
7009+ String::from_utf8_lossy(&out.stderr)
7010+ );
7011+ let stream = out.stdout;
7012+ let before = crate::decode::nocfl_uv_mode_hits();
7013+ let frames = match decode_stream(&stream) {
7014+ Err(e) => {
7015+ let msg = e.to_string();
7016+ assert!(
7017+ msg.contains("unsupported"),
7018+ "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \
7019+ attempt {attempt}): {msg}"
7020+ );
7021+ named_refusals += 1;
7022+ eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}");
7023+ continue;
7024+ }
7025+ Ok(frames) => frames,
7026+ };
7027+ let hits = crate::decode::nocfl_uv_mode_hits() - before;
7028+ let ffmpeg_frames = if bit_depth == 10 {
7029+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
7030+ } else {
7031+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
7032+ };
7033+ assert_eq!(frames.len(), frame_count);
7034+ if hits == 0 {
7035+ carried_none += 1;
7036+ }
7037+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
7038+ assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})");
7039+ assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})");
7040+ assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})");
7041+ }
7042+ if hits > 0 {
7043+ matched += 1;
7044+ total_hits += hits;
7045+ }
7046+ }
7047+ eprintln!(
7048+ "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {matched} pixel-exact \
7049+ attempts carrying a 64x64 intra superblock ({total_hits} no-CFL uv_mode reads), \
7050+ {carried_none} attempts carried none"
7051+ );
7052+ assert!(
7053+ matched > 0 && total_hits > 0,
7054+ "{NAME} ({bit_depth}-bit): no square-only attempt decoded a 64x64 intra block \
7055+ inside an inter frame, so the no-CFL uv_mode alphabet was never exercised -- \
7056+ gate proved nothing ({named_refusals} refusals, {carried_none} carried none)"
7057+ );
7058+ }
7059+ }
69007060
69017061 /// lane-inter4 r2: the 32x32-level inter `PARTITION_HORZ`/`PARTITION_VERT`
69027062 /// strips (32x16 / 16x32) carrying a REAL residual -- the capability r1