Lane-av1444edge r3 -- the FIRST 4:4:4 superres cell, with the header assert the phantom cell failed
Browse files at this commit2bc3af64f8d8baf63797532986bd46b38907bfdfParent: ac21620- test
- lane-av1444edge r3 -- the FIRST 4:4:4 superres cell, with the header assert the phantom cell failed
2 changed files +229 -0
crates/ec-av1/fixtures/444_lossy_superres_256x128_d12.obuadded+0 -0
Binary file changed
crates/ec-av1/src/stream.rsmodified+229 -0
| @@ -7250,6 +7250,235 @@ pub(crate) mod tests { | ||
| 7250 | 7250 | } |
| 7251 | 7251 | } |
| 7252 | 7252 | |
| 7253 | + /// lane-av1444edge r3: the FIRST 4:4:4 superres cell in the crate, and | |
| 7254 | + /// the cell the chroma-format sweep's "4:4:4 superres" row was supposed | |
| 7255 | + /// to be. | |
| 7256 | + /// | |
| 7257 | + /// **Why this gate exists at all.** §6.2 of | |
| 7258 | + /// `lanes/av1formatsweep.report.md` recorded that cell as DIVERGENT from | |
| 7259 | + /// frame 2 with a first wrong sample of Y(192,0). It was never a superres | |
| 7260 | + /// cell: the recipe passed `--superres-mode=1` and no denominator, so | |
| 7261 | + /// libaom's `get_superres_denom_for_qindex` | |
| 7262 | + /// (`av1/encoder/superres_scale.c:143`) chose 8, and all four frame | |
| 7263 | + /// headers of that stream read `use_superres=false denom=8`. Nothing was | |
| 7264 | + /// ever scaled; it was a plain 4:4:4 lossy cq-20 stream, and its | |
| 7265 | + /// divergence was the same H1 class as the 130x122 cell beside it (see | |
| 7266 | + /// `lanes/av1444edge.report.md` §2). That is the trap this gate is built | |
| 7267 | + /// to make impossible to repeat: it asserts the scaled geometry from the | |
| 7268 | + /// PARSED HEADERS, so a future flag or heuristic change that silently | |
| 7269 | + /// unsizes the stream makes the gate red on a header assertion instead of | |
| 7270 | + /// turning into a differently-shaped exactness claim. | |
| 7271 | + /// | |
| 7272 | + /// **This is the only 4:4:4 superres coverage here.** All eight | |
| 7273 | + /// pre-existing superres gates are 4:2:0, checked rather than assumed: | |
| 7274 | + /// the two pinned fixtures parse `ss (1,1)` from their own sequence | |
| 7275 | + /// headers (`superres_kf_cdef_lr_64x64.obu` 8-bit, | |
| 7276 | + /// `superres_alltools_sb128_320x180.obu` 10-bit) and the six live-aomenc | |
| 7277 | + /// gates all feed a `yuv420p` / `yuv420p10le` source. So this cell's | |
| 7278 | + /// claim is scoped honestly: it is the FIRST 4:4:4 superres stream, not | |
| 7279 | + /// a broadening of an existing family. | |
| 7280 | + /// | |
| 7281 | + /// **The recipe** (sha256 | |
| 7282 | + /// `450caa3e31526a8973b9f64d5030a2f11b87bd60fac07aef121cb62af9bf85ff`, | |
| 7283 | + /// 14808 bytes, 4 frames, `testsrc2 256x128 rate=25` yuv444p): | |
| 7284 | + /// ```text | |
| 7285 | + /// ffmpeg -f lavfi -i "testsrc2=size=256x128:rate=25" -frames:v 4 \ | |
| 7286 | + /// -pix_fmt yuv444p -strict -1 -f yuv4mpegpipe - | \ | |
| 7287 | + /// aomenc --codec=av1 --passes=1 --end-usage=q --cq-level=20 --cpu-used=2 \ | |
| 7288 | + /// --threads=1 --row-mt=0 --lag-in-frames=0 --kf-max-dist=100 \ | |
| 7289 | + /// --limit=4 --superres-mode=1 --superres-denominator=12 \ | |
| 7290 | + /// --superres-kf-denominator=12 --obu -o - - | |
| 7291 | + /// ``` | |
| 7292 | + /// The two denominator flags are the whole point: without them the cell | |
| 7293 | + /// does not exist. Verified byte-reproducible — re-encoding this recipe | |
| 7294 | + /// reproduces the pinned 14808 bytes exactly. | |
| 7295 | + /// | |
| 7296 | + /// **What the cell exercises.** Coded 171x128 upscaled to 256x128 at | |
| 7297 | + /// `denom = 12`, so a 4:4:4 chroma plane is upscaled at FULL resolution | |
| 7298 | + /// (a 4:2:0 stream halves it first, and libaom's `av1_superres_upscale` | |
| 7299 | + /// takes a different path per chroma format). Measured `superres_hits` 4 | |
| 7300 | + /// and `mc::predict_scaled_hits` 2130 — the upscaler and scaled inter | |
| 7301 | + /// prediction both run, so the cell is not passing on an unscaled | |
| 7302 | + /// stream. | |
| 7303 | + /// | |
| 7304 | + /// Non-vacuity, four ways: the pinned bytes (length + FNV-1a); the parsed | |
| 7305 | + /// headers really are `use_superres` at `denom 12` with the SCALED coded | |
| 7306 | + /// size, and the coded width is re-derived from `UpscaledWidth` and the | |
| 7307 | + /// denominator rather than only compared to a literal, so a re-pinned | |
| 7308 | + /// fixture cannot drift past the assertion; both counters are asserted as | |
| 7309 | + /// DELTAS; and every decode-order frame is compared byte-for-byte | |
| 7310 | + /// through `decode_all_frames_vs_oracle`, which is what makes the | |
| 7311 | + /// upscaled width on both sides a real check. | |
| 7312 | + #[test] | |
| 7313 | + fn a_444_lossy_superres_stream_decodes_pixel_exact() { | |
| 7314 | + const NAME: &str = "a_444_lossy_superres_stream_decodes_pixel_exact"; | |
| 7315 | + const FIXTURE: &str = "fixtures/444_lossy_superres_256x128_d12.obu"; | |
| 7316 | + const FIXTURE_LEN: usize = 14808; | |
| 7317 | + const FIXTURE_FNV: u64 = 0x44e0_d12f_1155_0e09; | |
| 7318 | + /// Quoted so a re-pin has to be deliberate; the FNV above is what the | |
| 7319 | + /// gate actually compares, this is what a human reads. | |
| 7320 | + const FIXTURE_SHA256: &str = | |
| 7321 | + "450caa3e31526a8973b9f64d5030a2f11b87bd60fac07aef121cb62af9bf85ff"; | |
| 7322 | + const UPSCALED: (usize, usize) = (256, 128); | |
| 7323 | + const CODED: (usize, usize) = (171, 128); | |
| 7324 | + const DENOM: u8 = 12; | |
| 7325 | + const FRAMES: usize = 4; | |
| 7326 | + let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(FIXTURE); | |
| 7327 | + let stream = std::fs::read(&obu).unwrap_or_else(|e| { | |
| 7328 | + panic!( | |
| 7329 | + "{NAME}: pinned fixture {} is missing ({e}) -- the gate cannot run, \ | |
| 7330 | + which is a failure, not a skip", | |
| 7331 | + obu.display() | |
| 7332 | + ) | |
| 7333 | + }); | |
| 7334 | + assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved"); | |
| 7335 | + assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); | |
| 7336 | + | |
| 7337 | + // --- the header facts the CELL depends on, parsed not assumed ------ | |
| 7338 | + let mut parser = Av1Parser::new(); | |
| 7339 | + let mut pos = 0usize; | |
| 7340 | + let mut seq = None; | |
| 7341 | + let mut heads: Vec<FrameHeader> = Vec::new(); | |
| 7342 | + while pos < stream.len() { | |
| 7343 | + let obu = parser | |
| 7344 | + .parse_obu(&stream[pos..]) | |
| 7345 | + .unwrap_or_else(|e| panic!("{NAME}: aomenc OBU does not parse: {e:?}")); | |
| 7346 | + if obu.total_size == 0 { | |
| 7347 | + break; | |
| 7348 | + } | |
| 7349 | + pos += obu.total_size; | |
| 7350 | + match obu.kind { | |
| 7351 | + ObuKind::SequenceHeader(s) => seq = Some(s), | |
| 7352 | + ObuKind::FrameHeader(h) => heads.push(*h), | |
| 7353 | + ObuKind::Frame(h, _) => heads.push(*h), | |
| 7354 | + _ => {} | |
| 7355 | + } | |
| 7356 | + } | |
| 7357 | + let seq = seq.unwrap_or_else(|| panic!("{NAME}: the stream carries no sequence header")); | |
| 7358 | + assert_eq!( | |
| 7359 | + ( | |
| 7360 | + seq.color_config.subsampling_x, | |
| 7361 | + seq.color_config.subsampling_y | |
| 7362 | + ), | |
| 7363 | + (0, 0), | |
| 7364 | + "{NAME}: the stream is not 4:4:4 (ss = ({}, {}))", | |
| 7365 | + seq.color_config.subsampling_x, | |
| 7366 | + seq.color_config.subsampling_y | |
| 7367 | + ); | |
| 7368 | + assert_eq!( | |
| 7369 | + seq.color_config.bit_depth, 8, | |
| 7370 | + "{NAME}: not the 8-bit cell this gate names" | |
| 7371 | + ); | |
| 7372 | + assert!( | |
| 7373 | + seq.enable_superres, | |
| 7374 | + "{NAME}: the sequence header does not enable superres at all" | |
| 7375 | + ); | |
| 7376 | + assert_eq!( | |
| 7377 | + heads.len(), | |
| 7378 | + FRAMES, | |
| 7379 | + "{NAME}: {} frame headers, expected {FRAMES}", | |
| 7380 | + heads.len() | |
| 7381 | + ); | |
| 7382 | + for (i, h) in heads.iter().enumerate() { | |
| 7383 | + // The assertion the phantom cell failed. Without the denominator | |
| 7384 | + // flags aomenc picks 8 and this is false while the stream still | |
| 7385 | + // decodes, which is how a whole sweep cell ends up mislabelled. | |
| 7386 | + assert!( | |
| 7387 | + h.use_superres, | |
| 7388 | + "{NAME}: frame {i} has use_superres = false -- this is an UNSCALED \ | |
| 7389 | + stream and the gate would be measuring something other than the \ | |
| 7390 | + cell it names (class gate-blind-to-feature)" | |
| 7391 | + ); | |
| 7392 | + assert_eq!( | |
| 7393 | + h.superres_denom, DENOM, | |
| 7394 | + "{NAME}: frame {i} denominator moved from {DENOM}" | |
| 7395 | + ); | |
| 7396 | + assert_eq!( | |
| 7397 | + (h.upscaled_width as usize, h.frame_height as usize), | |
| 7398 | + (UPSCALED.0, UPSCALED.1), | |
| 7399 | + "{NAME}: frame {i} upscaled size moved" | |
| 7400 | + ); | |
| 7401 | + assert_eq!( | |
| 7402 | + (h.frame_width as usize, h.frame_height as usize), | |
| 7403 | + (CODED.0, CODED.1), | |
| 7404 | + "{NAME}: frame {i} CODED size moved -- this is the scaled half of \ | |
| 7405 | + the cell and the part an unsized stream gets wrong" | |
| 7406 | + ); | |
| 7407 | + // Re-derive rather than only compare literals, so a re-pinned | |
| 7408 | + // fixture cannot satisfy the numbers above while the scaled-size | |
| 7409 | + // arithmetic has moved under them. | |
| 7410 | + assert_eq!( | |
| 7411 | + (h.upscaled_width * 8 + u32::from(DENOM) / 2) / u32::from(DENOM), | |
| 7412 | + h.frame_width, | |
| 7413 | + "{NAME}: frame {i}: FrameWidth is not (UpscaledWidth*8 + denom/2)/denom -- \ | |
| 7414 | + the scaled size the cell rests on is not the spec's" | |
| 7415 | + ); | |
| 7416 | + } | |
| 7417 | + | |
| 7418 | + // --- the pixels ----------------------------------------------------- | |
| 7419 | + let _guard = lock_gate_counters(); | |
| 7420 | + let before_sr = crate::superres::superres_hits(); | |
| 7421 | + let before_scaled = crate::mc::predict_scaled_hits(); | |
| 7422 | + let frames = decode_stream(&stream).unwrap_or_else(|e| { | |
| 7423 | + panic!("{NAME}: the pinned 4:4:4 superres stream was refused: {e}") | |
| 7424 | + }); | |
| 7425 | + let scaled_up = crate::superres::superres_hits() - before_sr; | |
| 7426 | + let scaled_mc = crate::mc::predict_scaled_hits() - before_scaled; | |
| 7427 | + assert!( | |
| 7428 | + scaled_up > 0, | |
| 7429 | + "{NAME}: zero superres_hits -- the upscaler never ran (class \ | |
| 7430 | + gate-blind-to-feature)" | |
| 7431 | + ); | |
| 7432 | + assert!( | |
| 7433 | + scaled_mc > 0, | |
| 7434 | + "{NAME}: zero predict_scaled_hits -- no inter block read a scaled reference, \ | |
| 7435 | + so the scaled-PREDICTION half of the cell is unexercised (class \ | |
| 7436 | + gate-blind-to-feature)" | |
| 7437 | + ); | |
| 7438 | + assert_eq!(frames.len(), FRAMES, "{NAME}: decoded frame count"); | |
| 7439 | + for (i, f) in frames.iter().enumerate() { | |
| 7440 | + // The upscale must have REPLACED the frame: a decoder that | |
| 7441 | + // returned the 171-wide coded picture fails here, and without | |
| 7442 | + // this check the chroma-shape assertion below could be satisfied | |
| 7443 | + // by quarter-size planes. | |
| 7444 | + assert_eq!( | |
| 7445 | + (f.width, f.height), | |
| 7446 | + UPSCALED, | |
| 7447 | + "{NAME}: frame {i} came back {}x{}, not the UPSCALED {}x{}", | |
| 7448 | + f.width, | |
| 7449 | + f.height, | |
| 7450 | + UPSCALED.0, | |
| 7451 | + UPSCALED.1 | |
| 7452 | + ); | |
| 7453 | + assert_eq!( | |
| 7454 | + f.u.len(), | |
| 7455 | + UPSCALED.0 * UPSCALED.1, | |
| 7456 | + "{NAME}: frame {i} chroma plane is {} samples; at 4:4:4 upscaled it must \ | |
| 7457 | + be full resolution ({}x{})", | |
| 7458 | + f.u.len(), | |
| 7459 | + UPSCALED.0, | |
| 7460 | + UPSCALED.1 | |
| 7461 | + ); | |
| 7462 | + assert_eq!( | |
| 7463 | + f.v.len(), | |
| 7464 | + UPSCALED.0 * UPSCALED.1, | |
| 7465 | + "{NAME}: frame {i} V plane is {} samples, expected full resolution", | |
| 7466 | + f.v.len() | |
| 7467 | + ); | |
| 7468 | + } | |
| 7469 | + if aomdec_path().is_file() { | |
| 7470 | + let (decoded, hidden) = decode_all_frames_vs_oracle(&stream, NAME); | |
| 7471 | + eprintln!( | |
| 7472 | + "{NAME}: {decoded} decode-order frame(s) ({hidden} hidden) byte-exact vs \ | |
| 7473 | + aomdec at {UPSCALED:?} upscaled from {CODED:?} denom {DENOM}, \ | |
| 7474 | + {scaled_up} upscale(s), {scaled_mc} scaled MC block(s); fixture sha256 \ | |
| 7475 | + {FIXTURE_SHA256}" | |
| 7476 | + ); | |
| 7477 | + } else { | |
| 7478 | + eprintln!("{NAME}: no oracle aomdec, pixel arm skipped"); | |
| 7479 | + } | |
| 7480 | + } | |
| 7481 | + | |
| 7253 | 7482 | /// lane-av1lrflush: the pipelined loop-restoration band release flushes |
| 7254 | 7483 | /// RU row 0 on the inter frame whose top superblock row carries a |
| 7255 | 7484 | /// 128-root rect -- the exact shape lanes/av1444sb.report.md r2 named as |