forge
Explore
Log in

Don't you dare go Hollow

Pin three measured-exact 4:4:4 lossy cells with live aomenc gates

Browse files at this commit

fe8f0156e2d07cf7286b200d39b6451e97884d51Ahmet Kaan GümüşParent: a460dca
  • test
    • pin three measured-exact 4:4:4 lossy cells with live aomenc gates
Show full message
test(ec-av1): pin three measured-exact 4:4:4 lossy cells with live aomenc gates

The chroma-format sweep measured odd444_66x66, odd444_130x122 and the
"superres" 256x128 stream EXACT 4/4 but committed no gate, so the
exactness was unpinned and its only red-before lived in a lane report.

Each gate re-encodes LIVE with the oracle aomenc from the sweep's recipe
(testsrc2 rate=25 yuv444p, --profile=1, cq-level=20, cpu-used=2,
--limit=4; the rate and the 4-frame limit are load-bearing -- limit=6
emits a different, larger stream), asserts the decoded geometry really is
66x66 / 130x122 / 256x128 with full-resolution chroma planes, asserts the
4:4:4-only own-extent 1:4 chroma route ran (13 / 12 / 24 gathers), and
then compares every decode-order frame against aomdec with the length
asserted first. A missing aomdec is a hard failure, not a skip: a gate
that measures exactness and then skips the compare reports green for a
decoder it never looked at.

The third cell is NOT a superres cell and is named for its geometry:
encoding 256x128 with and without --superres-mode=1 yields BYTE-IDENTICAL
OBU (15239 bytes), so the sweep's flag was a no-op on this aomenc build.

Measured red-before, mutation reverted, no decoder change kept:
- decode.rs around_c own-extent arm restored to the 4:2:0 (16,8)/(8,16)
  pair extent: 130x122 red on decode-order frame 3 at byte 2208, 11521
  bytes differ (the sweep's exact number); 256x128 red on frame 2 at byte
  192, 25296 bytes differ. 66x66 stays green -- it was exact before that
  fix too, so it is a coverage pin, not a witness for it.
- ec-av1-syntax compute_image_size's mi grid ceil floored: 66x66 red
  (restoration.rs:783, range end 4098 out of range for slice of length
  4096) and 130x122 red on frame 0 at byte 128, 22724 bytes differ;
  256x128 green, correctly -- it is a multiple of 8 in both axes.

Green on this tree: 4 decode-order frames byte-exact vs aomdec for each
cell, and the existing rect4 gate plus the mode-info source-scan guard
still pass.
crates/ec-av1/src/stream.rsmodified+230 -0
@@ -7377,7 +7377,237 @@ pub(crate) mod tests {
73777377 }
73787378 eprintln!("{NAME}: 4:2:0 control {h4} HORZ_4 / {v4} VERT_4 strips, 0 own-extent gathers");
73797379 }
7380+ /// lane-av1gates444: the live 4:4:4 LOSSY cell the chroma-format sweep
7381+ /// measured EXACT 4/4 and left unpinned. The recipe is the sweep's own
7382+ /// §6.2 encode, reproduced LIVE against the oracle `aomenc` rather than
7383+ /// from a pin, because the claim these three gates carry is a property
7384+ /// of the *decoder* at a geometry, not of a blob:
7385+ /// ```text
7386+ /// ffmpeg -f lavfi -i "testsrc2=size=<W>x<H>:rate=25" -frames:v 4 \
7387+ /// -pix_fmt yuv444p -f yuv4mpegpipe - | \
7388+ /// aomenc --codec=av1 --profile=1 --passes=1 --end-usage=q --cq-level=20 \
7389+ /// --cpu-used=2 --threads=1 --row-mt=0 --lag-in-frames=0 \
7390+ /// --kf-max-dist=100 --limit=4 --obu -o - -
7391+ /// ```
7392+ /// `rate=25` is load-bearing (testsrc2's pattern is time-parameterised)
7393+ /// and `--limit=4` is the sweep's frame count: at `--limit=6` the same
7394+ /// recipe emits 7674 / 11465 / 19121 bytes instead of the sweep's
7395+ /// 5938 / 8945 / 15239, i.e. a different stream than the one measured.
7396+ /// `--profile=1` is what makes the source 4:4:4 at all.
7397+ ///
7398+ /// Every assertion here is a non-vacuity assertion first and a pixel
7399+ /// compare second. The frame count, the per-frame geometry and the
7400+ /// FULL-RESOLUTION chroma plane length are asserted because a truncated
7401+ /// or 4:2:0-shaped decode can pass a lenient compare; the
7402+ /// `rect4_inter_own_chroma444_hits()` reach assert is there because the
7403+ /// class these cells belong to is the 4:4:4-only own-chroma-extent route
7404+ /// in [`decode_inter_block`]'s `around_c` (a 4:2:0 stream of the same
7405+ /// content leaves it at 0), and a counter at 0 would mean the gate
7406+ /// measured a different route than it names.
7407+ fn encode_444_lossy_live(name: &str, w: usize, h: usize) -> Vec<u8> {
7408+ if !have_aomenc() {
7409+ eprintln!(
7410+ "SKIP {name}: no aomenc oracle at {} -- run scripts/build-aom-oracle.sh",
7411+ aomenc_path().display()
7412+ );
7413+ return Vec::new();
7414+ }
7415+ let source = format!("testsrc2=size={w}x{h}:rate=25");
7416+ let y4m = Command::new("ffmpeg")
7417+ .args([
7418+ "-v",
7419+ "error",
7420+ "-f",
7421+ "lavfi",
7422+ "-i",
7423+ &source,
7424+ "-frames:v",
7425+ "4",
7426+ "-pix_fmt",
7427+ "yuv444p",
7428+ "-f",
7429+ "yuv4mpegpipe",
7430+ "-",
7431+ ])
7432+ .stdin(Stdio::null())
7433+ .stdout(Stdio::piped())
7434+ .stderr(Stdio::piped())
7435+ .output()
7436+ .expect("ffmpeg failed to run");
7437+ assert!(
7438+ y4m.status.success(),
7439+ "{name}: ffmpeg refused the {w}x{h} 4:4:4 source: {}",
7440+ String::from_utf8_lossy(&y4m.stderr)
7441+ );
7442+ let out = run_with_stdin(
7443+ Command::new(aomenc_path()).args([
7444+ "--codec=av1",
7445+ "--profile=1",
7446+ "--passes=1",
7447+ "--end-usage=q",
7448+ "--cq-level=20",
7449+ "--cpu-used=2",
7450+ "--threads=1",
7451+ "--row-mt=0",
7452+ "--lag-in-frames=0",
7453+ "--kf-max-dist=100",
7454+ "--limit=4",
7455+ "--obu",
7456+ "-o",
7457+ "-",
7458+ "-",
7459+ ]),
7460+ &y4m.stdout,
7461+ );
7462+ assert!(
7463+ out.status.success(),
7464+ "{name}: aomenc refused the {w}x{h} 4:4:4 lossy recipe: {}",
7465+ String::from_utf8_lossy(&out.stderr)
7466+ );
7467+ assert!(
7468+ !out.stdout.is_empty(),
7469+ "{name}: aomenc produced no OBU for {w}x{h} -- a zero-length stream would \
7470+ decode to nothing and the compare below would compare nothing"
7471+ );
7472+ out.stdout
7473+ }
7474+
7475+ /// The body every 4:4:4 lossy live gate runs: assert the oracle compare
7476+ /// CANNOT be skipped, assert the decode really is the cell it claims
7477+ /// (frame count, geometry, full-resolution chroma), assert the 4:4:4-only
7478+ /// own-extent route really ran, then compare every frame in decode order
7479+ /// against the oracle aomdec with the length asserted first.
7480+ ///
7481+ /// The aomdec assert is deliberately a HARD failure, not the
7482+ /// `if aomdec_path().is_file()` skip the older gates use: a gate that
7483+ /// measures exactness and then quietly skips the compare reports green
7484+ /// for a decoder it never looked at (class gate-blind-to-the-arm). It
7485+ /// fires only when the gate is actually running, i.e. the oracle aomenc
7486+ /// resolved -- and aomenc and aomdec ship in the same build directory,
7487+ /// so an aomdec that is missing while aomenc is present is a broken
7488+ /// oracle, not a checkout without one.
7489+ fn gate_444_lossy_live_exact(name: &str, w: usize, h: usize) {
7490+ let stream = encode_444_lossy_live(name, w, h);
7491+ if stream.is_empty() {
7492+ return; // no oracle at all: the SKIP above already said so
7493+ }
7494+ assert!(
7495+ aomdec_path().is_file(),
7496+ "{name}: the oracle aomenc resolved to {} but no aomdec sits beside it at {} -- \
7497+ the pixel compare would silently skip, which this gate treats as a failure",
7498+ aomenc_path().display(),
7499+ aomdec_path().display()
7500+ );
73807501
7502+ let _guard = lock_gate_counters();
7503+ crate::decode::reset_rect4_inter_own_chroma444_hits();
7504+ let frames = decode_stream(&stream).unwrap_or_else(|e| {
7505+ panic!("{name}: the live {w}x{h} 4:4:4 lossy stream was refused: {e}")
7506+ });
7507+ let own = crate::decode::rect4_inter_own_chroma444_hits();
7508+ assert!(
7509+ own > 0,
7510+ "{name}: no 4:4:4 1:4 inter strip read its chroma context over its own extent -- \
7511+ the route this cell is a witness for never ran (measured: 13 at 66x66, 12 at \
7512+ 130x122, 24 at 256x128)"
7513+ );
7514+ assert_eq!(
7515+ frames.len(),
7516+ 4,
7517+ "{name}: decoded {} frame(s), the recipe encodes 4 -- a short decode would make the \
7518+ oracle compare cover a prefix of the cell",
7519+ frames.len()
7520+ );
7521+ for (i, f) in frames.iter().enumerate() {
7522+ assert_eq!(
7523+ (f.width, f.height),
7524+ (w, h),
7525+ "{name}: frame {i} is {}x{}, the cell is {w}x{h}",
7526+ f.width,
7527+ f.height
7528+ );
7529+ // At 4:4:4 both chroma planes are full resolution. A decoder that
7530+ // kept a subsampled extent would hand quarter-size planes to the
7531+ // byte compare; say so here instead of letting the compare
7532+ // stand in for the shape claim.
7533+ assert_eq!(
7534+ f.u.len(),
7535+ w * h,
7536+ "{name}: frame {i} U plane is {} samples; at 4:4:4 it must be full resolution \
7537+ ({w}x{h})",
7538+ f.u.len()
7539+ );
7540+ assert_eq!(
7541+ f.v.len(),
7542+ w * h,
7543+ "{name}: frame {i} V plane is {} samples; at 4:4:4 it must be full resolution \
7544+ ({w}x{h})",
7545+ f.v.len()
7546+ );
7547+ assert_eq!(
7548+ f.y.len(),
7549+ w * h,
7550+ "{name}: frame {i} luma plane is {} samples, expected {w}x{h}",
7551+ f.y.len()
7552+ );
7553+ }
7554+ let (decoded, hidden) = decode_all_frames_vs_oracle(&stream, name);
7555+ assert_eq!(
7556+ decoded, 4,
7557+ "{name}: the oracle decoded {decoded} frame(s) in decode order, the recipe carries 4 \
7558+ (so far {hidden} hidden)"
7559+ );
7560+ eprintln!(
7561+ "{name}: {w}x{h} 4:4:4 lossy, {decoded} decode-order frame(s) byte-exact vs aomdec \
7562+ ({hidden} hidden), {own} own-extent 1:4 chroma gather(s)"
7563+ );
7564+ }
7565+
7566+ /// lane-av1gates444 cell 1: **odd coded dims, 66x66** -- the partial-frame
7567+ /// walk in BOTH axes (66 is not a multiple of 8, so the frame is a
7568+ /// partial superblock column AND a partial row). Measured EXACT 4/4 by
7569+ /// the chroma-format sweep (§6.2, 5938 bytes) and unpinned: nothing in
7570+ /// the crate would go red if the odd-dimension 4:4:4 walk regressed,
7571+ /// and the only red-before evidence was a lane report nobody re-runs.
7572+ #[test]
7573+ fn a_444_lossy_odd_66x66_stream_decodes_pixel_exact() {
7574+ gate_444_lossy_live_exact("a_444_lossy_odd_66x66_stream_decodes_pixel_exact", 66, 66);
7575+ }
7576+
7577+ /// lane-av1gates444 cell 2: **odd coded dims, 130x122** -- the
7578+ /// partial-frame RIGHT edge that the sweep found DIVERGENT (first wrong
7579+ /// sample Y(128,16), 11521 samples on frame 3) until lane-av1444rect's
7580+ /// 4:4:4 own-chroma-extent fix landed. It measures EXACT 4/4 on this
7581+ /// tree and is the discriminating geometry: 66x66 was exact at the same
7582+ /// settings while this was not, so the pair is what keeps "the 4:4:4
7583+ /// partial-frame walk is right" from being a one-geometry accident.
7584+ #[test]
7585+ fn a_444_lossy_odd_130x122_stream_decodes_pixel_exact() {
7586+ gate_444_lossy_live_exact(
7587+ "a_444_lossy_odd_130x122_stream_decodes_pixel_exact",
7588+ 130,
7589+ 122,
7590+ );
7591+ }
7592+
7593+ /// lane-av1gates444 cell 3: **256x128**, the sweep's cell recorded as
7594+ /// "4:4:4 superres 256x128 (`--superres-mode=1`)".
7595+ ///
7596+ /// IT IS NOT A SUPERRES CELL, and this gate is named for what it is
7597+ /// instead. Measured here, live: encoding 256x128 with and without
7598+ /// `--superres-mode=1` produces BYTE-IDENTICAL OBU (15239 bytes,
7599+ /// sha256 06621606…, both), so the flag is a no-op on this aomenc build
7600+ /// and the sweep's cell was a plain 4:4:4 lossy cq-20 stream that
7601+ /// happened to carry the flag. The cell's actual value is the geometry
7602+ /// plus the filter stages: 256x128 is two full 128 superblock columns,
7603+ /// and the strip walk runs there with the post-deblock/CDEF/LR chain
7604+ /// live on the later frames -- so this is the third witness for the
7605+ /// 4:4:4 lossy strip class at a geometry the 128x96 rect4 gate does not
7606+ /// cover.
7607+ #[test]
7608+ fn a_444_lossy_256x128_stream_decodes_pixel_exact() {
7609+ gate_444_lossy_live_exact("a_444_lossy_256x128_stream_decodes_pixel_exact", 256, 128);
7610+ }
73817611 /// lane-av1444rect r2 — the SAME class as the gate above, second
73827612 /// instance: `decode_rect4_16_intrabc` applied the 4:2:0 pair geometry at
73837613 /// ss (0,0), where `is_chroma_reference` makes an intra-BC 1:4 strip its