forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

t07.rs4479 lines, 198.4 KiBHistoryRawDownload
1use super::*;
2use super::support::*;
3use super::gates_a::*;
4use super::gates_b::*;
5use crate::probe::run_with_stdin;
6use std::process::{Command, Stdio};
7
8 /// lane-lr r3: proves stage 1/2's exit criterion -- a real
9 /// `--enable-restoration=1` aomenc stream must survive the whole
10 /// partition walk (every symbol read entropy-exact) and land on the
11 /// NEW, narrowed refusal ("read but not applied"), never desync into
12 /// some other named refusal or an outright decode panic. Multi-superblock
13 /// fixture (192x128 = 3x2 SBs of 64px) per the charter's own trap
14 /// warning -- a single-SB fixture can never re-enter `read_lr` a second
15 /// time and would leave `SWITCHABLE_HITS`/etc. proving only one call
16 /// site, not the per-SB loop.
17 #[test]
18 fn a_real_aomenc_stream_with_restoration_reads_lr_symbols_correctly() {
19 const NAME: &str = "a_real_aomenc_stream_with_restoration_reads_lr_symbols_correctly";
20 let _gate_lock = lock_gate_counters();
21 if !have_ffmpeg() {
22 eprintln!("SKIP {NAME}: no ffmpeg");
23 return;
24 }
25 if !have_aomenc() {
26 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
27 return;
28 }
29 // lane-reelckf2 r1: 152 = 2*64+24, not 128 -- the 8-bit twin of the
30 // partial-bottom-stripe LR gate below. Stripe shapes at 128 rows are
31 // a strict subset of those at 152 (56, 64, then the 32-row tail whose
32 // below boundary is the frame's own last row).
33 let (width, height) = (192usize, 152usize);
34 let n_attempts: u32 = std::env::var("EC_LR_GATE_ATTEMPTS")
35 .ok()
36 .and_then(|s| s.parse().ok())
37 .unwrap_or(40);
38 let mut lr_refusals = 0u32;
39 let mut other_refusals = Vec::new();
40 // lane-reelckf2 r1: the two special stripe shapes this size now has.
41 let stripe0_before = crate::restoration::lr_stripe0_hits();
42 let last_stripe_before = crate::restoration::lr_last_stripe_hits();
43 for attempt in 0..n_attempts {
44 let seed = 42 + attempt;
45 // Diagnosis knob: which content makes RD pick an 8x16/16x8 strip
46 // AND filter intra on it is a search (see lanes/fistrip-r1.report.md).
47 let source = match std::env::var("EC_FISTRIP_SRC").unwrap_or_default().as_str() {
48 "bars" => format!("smptebars=size={width}x{height}:duration=0.04:rate=25"),
49 "src2" => format!("testsrc2=size={width}x{height}:duration=0.04:rate=25"),
50 "noise" => format!(
51 "nullsrc=size={width}x{height}:duration=0.04:rate=25,geq=random(1)*255:128:128"
52 ),
53 _ => gradients_source(seed, width, height, "duration=0.04:rate=25"),
54 };
55 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
56 .args(["-v", "error", "-f", "lavfi", "-i"])
57 .arg(&source)
58 .args(["-pix_fmt", "yuv420p", "-f", "yuv4mpegpipe", "-"])
59 .stdin(Stdio::null())
60 .stdout(Stdio::piped())
61 .stderr(Stdio::piped()), None, |c| c.output())
62 .expect("ffmpeg failed to run");
63 assert!(
64 y4m.status.success(),
65 "ffmpeg fixture: {}",
66 String::from_utf8_lossy(&y4m.stderr)
67 );
68 let out = run_with_stdin(
69 Command::new(aomenc_path()).args([
70 "--codec=av1",
71 "--passes=1",
72 "--end-usage=q",
73 // r3: a low cq-level (high quality/bitrate) is load-bearing --
74 // sampled live (2026-08-30) that aomenc's RD only ever picks a
75 // non-`RESTORE_NONE` frame_restoration_type at cq-level<=20 for
76 // this fixture; cq-level=45 (this gate's sibling gates' usual
77 // value) landed `uses_lr=false` on every attempt.
78 "--cq-level=15",
79 "--cpu-used=0",
80 "--threads=1",
81 "--row-mt=0",
82 // r3: this decoder always assumes 64px superblocks
83 // (`decode.rs` hardcodes `SB_MI=16`, ledger `lane-sb128`
84 // dead-ends) -- force aomenc to match rather than risk
85 // the unrelated sb128 gap eating this gate's own window.
86 "--sb-size=64",
87 "--enable-restoration=1",
88 "--enable-cdef=0",
89 "--enable-rect-partitions=0",
90 "--enable-ab-partitions=0",
91 "--enable-1to4-partitions=0",
92 "--enable-filter-intra=0",
93 "--enable-smooth-intra=0",
94 "--enable-paeth-intra=0",
95 "--enable-tx-size-search=0",
96 "--max-partition-size=32",
97 "--min-partition-size=16",
98 "--enable-palette=0",
99 "--enable-intrabc=0",
100 "--enable-cfl-intra=0",
101 "--enable-ref-frame-mvs=0",
102 "--enable-warped-motion=0",
103 "--enable-global-motion=0",
104 "--enable-masked-comp=0",
105 "--enable-interintra-comp=0",
106 "--enable-obmc=0",
107 "--obu",
108 "-o",
109 "-",
110 "-",
111 ]),
112 &y4m.stdout,
113 );
114 assert!(
115 out.status.success(),
116 "aomenc refused the fixture: {}",
117 String::from_utf8_lossy(&out.stderr)
118 );
119 let stream = out.stdout;
120 match decode_stream(&stream) {
121 Ok(pics) => {
122 // r4: the pixel filters are wired -- every `uses_lr`
123 // frame must now decode Ok AND match an independent
124 // decoder pixel-exact, not just refuse cleanly.
125 // The ENCODE's frame count: every `EC_FISTRIP_SRC` branch
126 // and the `gradients_source` default (30568-30573) render at
127 // `rate=25` with a 1-frame `duration=0.04`, and aomenc runs
128 // with no `--limit` (30590) -- so each attempt's stream codes
129 // exactly 1 frame. Asserted ABOVE the oracle call.
130 assert_eq!(pics.len(), 1, "{NAME}: seed {seed} key frame");
131 let reference = ffmpeg_decode_sequence(&stream, width, height, pics.len());
132 let mismatched = pics
133 .iter()
134 .zip(&reference)
135 .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
136 // r7: pin a mismatching stream the same way the
137 // masked-compound gate does -- lets a follow-up round
138 // decode this exact seed's bytes directly instead of
139 // re-deriving them from a live 40-attempt sweep.
140 if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
141 std::fs::write(&path, &stream).expect("writing pinned stream");
142 eprintln!(
143 "EC_AV1_GATE_DUMP: wrote mismatching LR stream (seed {seed}) to {path}"
144 );
145 }
146 for (i, (pic, refpic)) in pics.iter().zip(reference.iter()).enumerate() {
147 assert_eq!(
148 pic.y, refpic.y,
149 "{NAME}: luma mismatch (seed {seed} frame {i})"
150 );
151 assert_eq!(
152 pic.u, refpic.u,
153 "{NAME}: U mismatch (seed {seed} frame {i})"
154 );
155 assert_eq!(
156 pic.v, refpic.v,
157 "{NAME}: V mismatch (seed {seed} frame {i})"
158 );
159 }
160 lr_refusals += 1; // reused below as "attempts that actually exercised LR pixels"
161 }
162 Err(e) => {
163 let msg = e.to_string();
164 other_refusals.push(format!("seed {seed}: {msg}"));
165 }
166 }
167 }
168 assert!(
169 other_refusals.is_empty(),
170 "{NAME}: {} attempts failed outright instead of decoding:\n{}",
171 other_refusals.len(),
172 other_refusals.join("\n")
173 );
174 assert!(
175 lr_refusals > 0,
176 "{NAME}: no attempt ever decoded pixel-exact ({n_attempts} attempts)"
177 );
178 // Any real (non-`RESTORE_NONE`) filter kind is acceptable proof --
179 // aomenc's RD picks the frame-level `restoration_type` itself (not
180 // always `Switchable`; observed `Sgrproj` live at cq-level=15 for
181 // this fixture), so hard-requiring one specific arm would be the
182 // gate-recipe-confound class (ledger).
183 let total_hits = crate::restoration::wiener_hits()
184 + crate::restoration::sgrproj_hits()
185 + crate::restoration::switchable_hits();
186 assert!(
187 total_hits > 0,
188 "{NAME}: {lr_refusals} LR refusals fired but read_lr_unit never decoded a real \
189 (non-None) filter -- gate proved nothing about the symbol path"
190 );
191 // lane-reelckf2 r1: a size with a partial bottom stripe proves nothing
192 // about the two frame-edge stripe shapes unless a real filter actually
193 // ran on them (`filter_restoration_unit`).
194 assert!(
195 crate::restoration::lr_stripe0_hits() > stripe0_before
196 && crate::restoration::lr_last_stripe_hits() > last_stripe_before,
197 "{NAME}: no filtered stripe took the frame's own top/bottom row as its boundary \
198 (stripe0 +{}, last +{})",
199 crate::restoration::lr_stripe0_hits() - stripe0_before,
200 crate::restoration::lr_last_stripe_hits() - last_stripe_before
201 );
202 eprintln!(
203 "{NAME}: {lr_refusals} LR refusals, {} other refusals out of {n_attempts}, \
204 wiener_hits={} sgrproj_hits={} switchable_hits={}",
205 other_refusals.len(),
206 crate::restoration::wiener_hits(),
207 crate::restoration::sgrproj_hits(),
208 crate::restoration::switchable_hits()
209 );
210 }
211
212 /// r8: decode the ONE pinned stream `EC_AV1_GATE_DUMP` captured in r7
213 /// (`fixtures/lr-sgr-r7.obu`, seed 46) directly -- not the live
214 /// 40-attempt sweep, which reuses `v_start` coordinates across unrelated
215 /// seeds/frames and made r6's captured 9 bytes unprovable. Run with
216 /// `EC_LR_CALL_DUMP=1` set (see `restoration.rs`'s `apply_sgrproj_stripe`)
217 /// to get the real window on stderr, call-uniquely keyed to `xqd ==
218 /// [-16,-32]` rather than any coordinate.
219 /// lane-av1pinslive r4: this gate asserted NOTHING. It `eprintln!`d per-frame
220 /// mismatch flags and returned, so it could not go red on a decode regression
221 /// -- which is why r3 left it `#[ignore]`d on that fact rather than un-ignoring
222 /// it. It now carries the same three things its three siblings have: a pinned
223 /// FRAME COUNT, a length assert before the zip, and per-plane per-frame pixel
224 /// asserts. The diagnostic print is kept, and now runs BEFORE the asserts so a
225 /// failure still names the shape of the divergence.
226 ///
227 /// The frame count is the substantive fix. The old body passed `pics.len()` as
228 /// ffmpeg's EXPECTED count:
229 /// let reference = ffmpeg_decode_sequence(&stream, 192, 128, pics.len());
230 /// so a decoder that emitted ZERO frames asked ffmpeg for zero frames, the zip
231 /// compared no pairs, and the gate passed having proved nothing -- the exact
232 /// vacuous-pass shape the `cmpaudit` lane swept elsewhere in this crate. The
233 /// count now comes from the FIXTURE (`FRAMES`), so losing the frame reds on the
234 /// count instead of comparing nothing.
235 ///
236 /// On "does it compare only frame 0": the loop always visited every frame; this
237 /// pin simply holds one (`frame 0` was the only line the pre-r4 run printed).
238 /// The loop is unchanged in that respect and still visits every frame it gets.
239 ///
240 /// The `EC_LR_CALL_DUMP=1` window is unchanged and still needs that env -- but
241 /// it is a debugging session layered on a real gate now, not the gate itself.
242 #[test]
243 fn pinned_lr_sgr_stream_call_unique_dump() {
244 const NAME: &str = "pinned_lr_sgr_stream_call_unique_dump";
245 const W: usize = 192;
246 const H: usize = 128;
247 /// Measured: the pre-r4 run printed `frame 0` and no other frame line.
248 const FRAMES: usize = 1;
249 let path = std::env::var("EC_AV1_GATE_DUMP_PIN")
250 .map(std::path::PathBuf::from)
251 .unwrap_or_else(|_| crate_pin("lr-sgr-r7.obu"));
252 let stream = require_pin(&path, "lr-sgr-r7.obu");
253 let pics = decode_stream(&stream).expect("pinned lr-sgr-r7.obu must decode");
254 assert_eq!(
255 pics.len(),
256 FRAMES,
257 "{NAME}: decoded {} frame(s), the pinned stream holds {FRAMES} -- a short \
258 decode would otherwise ask ffmpeg for the same short count and compare \
259 nothing",
260 pics.len()
261 );
262 for f in &pics {
263 assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions");
264 }
265 if !have_ffmpeg() {
266 eprintln!(
267 "SKIP {NAME}: no ffmpeg -- the pixel compare IS this gate's claim, so it \
268 proves nothing here; set EC_AV1_REQUIRE_FFMPEG=1 to make that a hard \
269 failure instead"
270 );
271 return;
272 }
273 let reference = ffmpeg_decode_sequence(&stream, W, H, FRAMES);
274 assert_eq!(
275 reference.len(),
276 FRAMES,
277 "{NAME}: ffmpeg returned {} frame(s), expected {FRAMES}",
278 reference.len()
279 );
280 for (i, (got, want)) in pics.iter().zip(&reference).enumerate() {
281 let y_mismatch = got.y != want.y;
282 let u_mismatch = got.u != want.u;
283 let v_mismatch = got.v != want.v;
284 eprintln!(
285 "frame {i}: y_mismatch={y_mismatch} u_mismatch={u_mismatch} v_mismatch={v_mismatch}"
286 );
287 if y_mismatch {
288 let n = got.y.iter().zip(&want.y).filter(|(a, b)| a != b).count();
289 eprintln!(" {n} luma bytes differ / {}", got.y.len());
290 }
291 if v_mismatch {
292 let w = 96usize; // chroma plane width (192/2)
293 for (idx, (a, b)) in got.v.iter().zip(&want.v).enumerate() {
294 if a != b {
295 eprintln!(" V[{},{}] got={a} want={b}", idx / w, idx % w);
296 }
297 }
298 }
299 assert_eq!(
300 got.y, want.y,
301 "{NAME} frame {i} luma vs ffmpeg (pinned lr-sgr)"
302 );
303 assert_eq!(
304 got.u, want.u,
305 "{NAME} frame {i} U vs ffmpeg (pinned lr-sgr)"
306 );
307 assert_eq!(
308 got.v, want.v,
309 "{NAME} frame {i} V vs ffmpeg (pinned lr-sgr)"
310 );
311 }
312 eprintln!(
313 "{NAME}: {FRAMES} frame(s) byte-exact vs ffmpeg from {}",
314 path.display()
315 );
316 }
317
318 /// lane-realworld r2: `read_cdef` (spec 5.11.56) ported -- per-superblock
319 /// `cdef_idx`, wired at all five `skip`-decode sites, `apply_cdef` looks
320 /// up strength through the grid instead of a hardcoded `[0]`. Structure
321 /// copied from `a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact`
322 /// but `--enable-cdef=1` (the one thing that gate turns off) and every
323 /// *other* filter/mode feature this lane doesn't touch disabled, so a
324 /// mismatch here can only be attributed to CDEF. `cdef_idx_hits()` is a
325 /// hard assert -- a run that never reads a real cdef_idx symbol proves
326 /// nothing (class `gate-blind-to-feature`).
327 #[test]
328 fn a_real_aomenc_stream_with_cdef_decodes_pixel_exact() {
329 const NAME: &str = "a_real_aomenc_stream_with_cdef_decodes_pixel_exact";
330 let _gate_lock = lock_gate_counters();
331 if !have_ffmpeg() {
332 eprintln!("SKIP {NAME}: no ffmpeg");
333 return;
334 }
335 if !have_aomenc() {
336 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
337 return;
338 }
339 // cdef_bits selects among PER-SUPERBLOCK strengths -- a single-SB
340 // 64x64 frame (the other gates' size) gives aomenc nothing to
341 // differentiate, so it always writes bits=0 and cdef_idx is never
342 // read. 128x64 = 2 SBs is the minimum that lets aomenc's RD ever
343 // pick bits > 0. Multi-SB content at --cpu-used=0 (every other
344 // gate's setting) makes aomenc pick PARTITION_HORZ_4/VERT_B etc.
345 // at the top SB level regardless of the ab/1to4-partitions=0
346 // flags below (a real gap: this decoder's intra part64 match only
347 // covers NONE/SPLIT, and the inter path blindly assumes SPLIT --
348 // both pre-existing, out of this lane's scope); --cpu-used=4
349 // avoids that RD path entirely and needs --aq-mode=0
350 // --deltaq-mode=0 to keep delta_q/delta_lf (next lane step) off.
351 let (width, height, frame_count) = (128usize, 64usize, 24usize);
352 let mut named_refusals = 0u32;
353 let mut matched = 0u32;
354 let n_attempts: u32 = std::env::var("EC_CDEF_GATE_ATTEMPTS")
355 .ok()
356 .and_then(|s| s.parse().ok())
357 .unwrap_or(40);
358 for attempt in 0..n_attempts {
359 let seed = 42 + attempt;
360 let duration = frame_count as f64 / 25.0;
361 // mandelbrot's ringing-prone hard edges are what CDEF's RD
362 // search targets; flat gradients (charter's first guess) may
363 // never make aomenc choose cdef_bits > 0.
364 let source = format!(
365 "mandelbrot=size={width}x{height}:rate=25:start_x={sx}:start_y={sy}",
366 sx = -0.6 + 0.005 * (attempt as f64),
367 sy = -0.4 + 0.005 * (attempt as f64)
368 );
369 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
370 .args([
371 "-v",
372 "error",
373 "-f",
374 "lavfi",
375 "-i",
376 &source,
377 "-t",
378 &duration.to_string(),
379 "-pix_fmt",
380 "yuv420p",
381 "-f",
382 "yuv4mpegpipe",
383 "-",
384 ])
385 .stdin(Stdio::null())
386 .stdout(Stdio::piped())
387 .stderr(Stdio::piped()), None, |c| c.output())
388 .expect("ffmpeg failed to run");
389 assert!(
390 y4m.status.success(),
391 "ffmpeg fixture: {}",
392 String::from_utf8_lossy(&y4m.stderr)
393 );
394 let args: Vec<&str> = vec![
395 "--codec=av1",
396 "--passes=1",
397 "--end-usage=q",
398 "--cq-level=45",
399 "--cpu-used=4",
400 "--aq-mode=0",
401 "--deltaq-mode=0",
402 "--enable-cdef=0",
403 "--kf-max-dist=1000",
404 "--threads=1",
405 "--row-mt=0",
406 "--auto-alt-ref=1",
407 "--lag-in-frames=16",
408 "--enable-fwd-kf=0",
409 "--enable-order-hint=1",
410 // r2: a starved inter toolset (everything below off) pushes
411 // aomenc's RD toward exotic partition shapes (HORZ_4/VERT_B
412 // etc.) at the SB(64) level even with those partition
413 // flags off -- this decoder's part64 8/9/10-way arms and
414 // the inter path's blind SPLIT assumption don't cover that;
415 // keeping the same rich toolset the (working, ab/1to4-off)
416 // masked-compound gate uses avoids it.
417 "--enable-warped-motion=1",
418 "--enable-global-motion=0",
419 "--enable-obmc=1",
420 "--tune-content=default",
421 "--enable-masked-comp=1",
422 "--enable-dist-wtd-comp=0",
423 "--enable-interintra-comp=1",
424 "--enable-onesided-comp=0",
425 "--enable-interintra-wedge=0",
426 "--enable-smooth-interintra=1",
427 "--enable-rect-partitions=0",
428 "--enable-ab-partitions=0",
429 "--enable-1to4-partitions=0",
430 "--enable-filter-intra=0",
431 "--enable-smooth-intra=0",
432 "--enable-paeth-intra=0",
433 "--enable-directional-intra=0",
434 "--enable-angle-delta=0",
435 "--enable-tx-size-search=0",
436 "--enable-cdef=1",
437 "--enable-restoration=0",
438 "--max-partition-size=32",
439 "--min-partition-size=32",
440 "--enable-palette=0",
441 "--enable-intrabc=0",
442 "--enable-cfl-intra=0",
443 "--enable-ref-frame-mvs=0",
444 "--obu",
445 "-o",
446 "-",
447 "-",
448 ];
449 let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
450 assert!(
451 out.status.success(),
452 "aomenc refused the fixture: {}",
453 String::from_utf8_lossy(&out.stderr)
454 );
455 let stream = out.stdout;
456 let frames = match decode_stream(&stream) {
457 Err(e) => {
458 let msg = e.to_string();
459 assert!(
460 msg.contains("unsupported"),
461 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
462 );
463 assert!(
464 !msg.contains("cdef"),
465 "{NAME} refused on cdef (seed {seed}) -- cdef_idx decode is ported: {msg}"
466 );
467 named_refusals += 1;
468 eprintln!("seed {seed} refusal: {msg}");
469 continue;
470 }
471 Ok(frames) => frames,
472 };
473 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
474 assert_eq!(frames.len(), frame_count);
475 let mismatched = frames
476 .iter()
477 .zip(&ffmpeg_frames)
478 .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
479 if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
480 std::fs::write(&path, &stream).expect("writing pinned stream");
481 eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
482 }
483 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
484 assert_eq!(
485 got.y, want.y,
486 "{NAME} frame {i} luma vs ffmpeg (seed {seed})"
487 );
488 assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
489 assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
490 }
491 // lane-hidden r2 (class gate-blind-to-hidden-frames): the same
492 // stream again, comparing EVERY decode-order frame -- the hidden
493 // (show_frame == 0) alt-ref frames the ffmpeg compare above
494 // cannot see, because both sides of it emit shown frames only.
495 let (hidden_total, hidden_n) = decode_all_frames_vs_oracle(&stream, NAME);
496 eprintln!(
497 "{NAME} HIDDEN: seed {seed}: {hidden_total} decode-order frames, \
498 {hidden_n} hidden, all pixel-exact vs the oracle"
499 );
500 // lane-hidden r2 SECOND ARM (the recipe above is untouched):
501 // libaom's temporal alt-ref filter absorbs this recipe's hidden
502 // frames, so the compare above is vacuous -- re-encode the same
503 // fixture with --arnr-maxframes=0 and compare THOSE.
504 if let Some((arm_total, arm_hidden)) = hidden_arnr_arm(NAME, &y4m.stdout, &args) {
505 eprintln!(
506 "{NAME} HIDDEN-ARM(--arnr-maxframes=0): seed {seed}: {arm_total} \
507 decode-order frames, {arm_hidden} hidden, all pixel-exact vs the oracle"
508 );
509 }
510 matched += 1;
511 }
512 assert!(
513 crate::decode::cdef_idx_hits() > 0,
514 "{NAME}: zero cdef_idx blocks fired ({matched} matches, {named_refusals} other \
515 refusals out of {n_attempts}) -- gate proved nothing this run"
516 );
517 eprintln!(
518 "{NAME}: {named_refusals} other-capability refusals, {matched} pixel-exact matches \
519 out of {n_attempts}, cdef_idx_hits={}",
520 crate::decode::cdef_idx_hits()
521 );
522 }
523
524 /// lane-edgeboth r1 GATE: frame sizes whose width AND height are both
525 /// 8 mod 16, so the bottom-right corner of the frame is a partition node
526 /// with `has_rows == false && has_cols == false` at every level it
527 /// reaches -- libaom `decode_partition` forces PARTITION_SPLIT there and
528 /// reads NO symbol (`else if (!has_rows && !has_cols) partition =
529 /// PARTITION_SPLIT;`), then drops the out-of-frame children on its
530 /// `if (mi_row >= mi_rows || mi_col >= mi_cols) return;` early return.
531 /// The 64 and 32 levels already inferred that split; the 16 level refused
532 /// by name until r1, on both the intra (key) and the inter path -- so both
533 /// arms are swept here. Every compared attempt must show a 16-level
534 /// both-cut hit, and the sweep must show 32- and 64-level hits too (200x72
535 /// puts all three levels in that state: mi_cols 50, mi_rows 18, so the
536 /// nodes at mi (16,48) of size 64, 32 and 16 are all cut on both axes).
537 #[test]
538 fn a_real_aomenc_both_axes_cut_corner_block_decodes_pixel_exact() {
539 both_axes_cut_sweep(
540 "a_real_aomenc_both_axes_cut_corner_block_decodes_pixel_exact",
541 ("key", 1, "--kf-max-dist=0", "--limit=1"),
542 );
543 }
544
545 /// lane-edgeboth r1, INTER half of the same lift. Un-ignored 2026-09-04: the inter frame-edge half-strip band defect that blocked it is gone. As measured then: the inter path's both-cut corner block
546 /// itself decodes exactly (200x72 inter cq 32, luma diff bounding box rows
547 /// 64..=71 cols 15..=186 -- the corner at cols 192..=199 is clean), but the
548 /// bottom 8-row frame-edge BAND of an inter frame is wrong, and the
549 /// control 192x72 (width a multiple of 16, so zero both-cut nodes: hits
550 /// [0,0,0,0]) fails identically at rows 64..=71 cols 8..=188. That band is
551 /// the forced one-axis HORZ half strip on the inter path -- lane-oddh's
552 /// own inter gate is `#[ignore]`d for the same arm -- so this gate turns
553 /// green with that defect, not with anything this lane changed.
554 #[test]
555 fn a_real_aomenc_both_axes_cut_corner_inter_frames_decode_pixel_exact() {
556 both_axes_cut_sweep(
557 "a_real_aomenc_both_axes_cut_corner_inter_frames_decode_pixel_exact",
558 ("inter", 6, "--kf-max-dist=9999", "--limit=6"),
559 );
560 }
561
562 /// lane-tiny r4 GATE (was r1's `#[ignore]`d probe): every tiny key-frame
563 /// size real aomenc will encode, decoded pixel-exact against ffmpeg.
564 /// Tiny frames are where every edge/partial-superblock corner case is
565 /// forced, and this sweep is what found both r3's filter-intra tx_type
566 /// CDF row and r4's chroma-transform-size deblock defect -- so it
567 /// hard-asserts now: a decode error, a refusal, or one differing sample
568 /// at any size/seed fails. Only a genuinely absent oracle skips, and
569 /// `EC_AV1_REQUIRE_AOMENC=1` turns that into a failure too.
570 #[test]
571 fn a_real_aomenc_tiny_frame_size_sweep_decodes_pixel_exact() {
572 if !have_ffmpeg() || !have_aomenc() {
573 eprintln!("SKIP: no ffmpeg/aomenc");
574 return;
575 }
576 // lane-oddh r2: the second half of this list is the odd-height /
577 // odd-width ladder -- frame sizes whose last superblock row or column
578 // is a partial 64 (72 = one full SB plus 8 rows, 136 = two plus 8),
579 // which is where the frame-edge half-strip path r1 added is the only
580 // way to code the edge. 192x136 is the inter-sized member.
581 let sizes: &[(usize, usize)] = &[
582 (8, 8),
583 (16, 16),
584 (32, 32),
585 (16, 32),
586 (32, 16),
587 (64, 64),
588 (48, 48),
589 (24, 24),
590 (64, 72),
591 (72, 64),
592 (64, 136),
593 (136, 64),
594 (192, 136),
595 ];
596 let mut total_exact = 0u32;
597 for &(width, height) in sizes {
598 let mut ok = 0u32;
599 let mut bad = 0u32;
600 let mut refused = 0u32;
601 let n = 10u32;
602 for attempt in 0..n {
603 let seed = 42 + attempt;
604 let source = format!(
605 "mandelbrot=size={width}x{height}:rate=25:start_x={sx}:start_y={sy}",
606 sx = -0.6 + 0.005 * (attempt as f64),
607 sy = -0.4 + 0.005 * (attempt as f64)
608 );
609 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
610 .args([
611 "-v",
612 "error",
613 "-f",
614 "lavfi",
615 "-i",
616 &source,
617 "-t",
618 "0.04",
619 "-pix_fmt",
620 "yuv420p",
621 "-f",
622 "yuv4mpegpipe",
623 "-",
624 ])
625 .stdin(Stdio::null())
626 .stdout(Stdio::piped())
627 .stderr(Stdio::piped()), None, |c| c.output())
628 .expect("ffmpeg failed to run");
629 assert!(
630 y4m.status.success(),
631 "ffmpeg fixture: {}",
632 String::from_utf8_lossy(&y4m.stderr)
633 );
634 let max_part = width.max(height).min(64).next_power_of_two();
635 let min_part = width.min(height).next_power_of_two().max(8).min(max_part);
636 let max_part_arg = format!("--max-partition-size={max_part}");
637 let min_part_arg = format!("--min-partition-size={min_part}");
638 let args: Vec<&str> = vec![
639 "--codec=av1",
640 "--passes=1",
641 "--end-usage=q",
642 "--cq-level=32",
643 "--cpu-used=4",
644 "--kf-max-dist=0",
645 "--limit=1",
646 "--threads=1",
647 "--row-mt=0",
648 "--enable-rect-partitions=0",
649 "--enable-ab-partitions=0",
650 "--enable-1to4-partitions=0",
651 &max_part_arg,
652 &min_part_arg,
653 "--obu",
654 "-o",
655 "-",
656 "-",
657 ];
658 let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
659 assert!(
660 out.status.success(),
661 "aomenc refused: {}",
662 String::from_utf8_lossy(&out.stderr)
663 );
664 let stream = out.stdout;
665 let frames = match decode_stream(&stream) {
666 Err(e) => {
667 // A NAMED refusal is the only non-exact outcome this
668 // gate tolerates (8x8 still needs a rectangular
669 // transform); anything else is a hard failure, and
670 // the floor assert below keeps that from going
671 // vacuous.
672 let msg = e.to_string();
673 assert!(
674 msg.contains("unsupported"),
675 "{width}x{height} seed {seed}: failed outright, not a named \
676 refusal: {msg}"
677 );
678 eprintln!(" {width}x{height} seed {seed}: REFUSED {msg}");
679 refused += 1;
680 continue;
681 }
682 Ok(f) => f,
683 };
684 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
685 if frames.len() == 1
686 && frames[0].y == ffmpeg_frames[0].y
687 && frames[0].u == ffmpeg_frames[0].u
688 && frames[0].v == ffmpeg_frames[0].v
689 {
690 ok += 1;
691 } else {
692 bad += 1;
693 let nd = |a: &[u16], b: &[u16]| a.iter().zip(b).filter(|(x, y)| x != y).count();
694 let (ndy, ndu, ndv) = (
695 nd(&frames[0].y, &ffmpeg_frames[0].y),
696 nd(&frames[0].u, &ffmpeg_frames[0].u),
697 nd(&frames[0].v, &ffmpeg_frames[0].v),
698 );
699 let mut first = None;
700 for row in 0..height {
701 for col in 0..width {
702 let i = row * width + col;
703 if frames[0].y[i] != ffmpeg_frames[0].y[i] {
704 first = Some((row, col, frames[0].y[i], ffmpeg_frames[0].y[i]));
705 break;
706 }
707 }
708 if first.is_some() {
709 break;
710 }
711 }
712 let ndiff = frames[0]
713 .y
714 .iter()
715 .zip(&ffmpeg_frames[0].y)
716 .filter(|(a, b)| a != b)
717 .count();
718 eprintln!(
719 " {width}x{height} seed {seed}: MISMATCH first_diff={first:?} \
720 ndiff_luma={ndiff}/{} ndiff y/u/v={ndy}/{ndu}/{ndv}",
721 width * height
722 );
723 }
724 }
725 assert_eq!(
726 bad, 0,
727 "{width}x{height}: {bad} of {n} seeds decoded to WRONG PIXELS ({ok} exact, \
728 {refused} named refusals)"
729 );
730 eprintln!("{width}x{height}: {ok}/{n} pixel-exact, {refused} named refusals");
731 total_exact += ok;
732 }
733 // Hit counter: the sweep proved nothing unless every size x seed
734 // attempt really ran end to end (aomenc -> us -> ffmpeg compare).
735 // Floor (hit counter): 12 of the 13 sizes must decode all 10 seeds
736 // pixel-exact -- only 8x8 is allowed to refuse outright today. If a
737 // future change makes sizes refuse instead of decode, this fails
738 // rather than passing on refusals alone.
739 assert!(
740 total_exact >= 120,
741 "tiny sweep only reached {total_exact} pixel-exact attempts (floor 70) -- \
742 refusals cannot substitute for decodes"
743 );
744 eprintln!("tiny frame sweep: {total_exact} pixel-exact attempts");
745 }
746
747 /// lane-tiny r1: re-decodes the known-failing 32x32 seed 45 fixture with
748 /// `EC_AV1_TRACE` on to inspect what mode/tx this single-block frame
749 /// picked. Diagnostic only, `#[ignore]`d, run manually with --nocapture.
750 #[test]
751 #[ignore = "diagnostic, run manually with --nocapture"]
752 fn probe_tiny_32x32_trace() {
753 if !have_ffmpeg() || !have_aomenc() {
754 eprintln!("SKIP: no ffmpeg/aomenc");
755 return;
756 }
757 let (width, height) = (32usize, 32usize);
758 let attempt = 3u32; // seed 45
759 let source = format!(
760 "mandelbrot=size={width}x{height}:rate=25:start_x={sx}:start_y={sy}",
761 sx = -0.6 + 0.005 * (attempt as f64),
762 sy = -0.4 + 0.005 * (attempt as f64)
763 );
764 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
765 .args([
766 "-v",
767 "error",
768 "-f",
769 "lavfi",
770 "-i",
771 &source,
772 "-t",
773 "0.04",
774 "-pix_fmt",
775 "yuv420p",
776 "-f",
777 "yuv4mpegpipe",
778 "-",
779 ])
780 .stdin(Stdio::null())
781 .stdout(Stdio::piped())
782 .stderr(Stdio::piped()), None, |c| c.output())
783 .expect("ffmpeg failed to run");
784 assert!(y4m.status.success());
785 let args: Vec<&str> = vec![
786 "--codec=av1",
787 "--passes=1",
788 "--end-usage=q",
789 "--cq-level=32",
790 "--cpu-used=4",
791 "--kf-max-dist=0",
792 "--limit=1",
793 "--threads=1",
794 "--row-mt=0",
795 "--enable-rect-partitions=0",
796 "--enable-ab-partitions=0",
797 "--enable-1to4-partitions=0",
798 "--max-partition-size=32",
799 "--min-partition-size=32",
800 "--enable-filter-intra=0",
801 "--obu",
802 "-o",
803 "-",
804 "-",
805 ];
806 let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
807 assert!(out.status.success());
808 let stream = out.stdout;
809 let frames = decode_stream(&stream).expect("decode");
810 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
811 let mismatched = frames[0].y != ffmpeg_frames[0].y;
812 eprintln!("mismatched={mismatched}");
813 }
814
815 /// lane-tiny r2: decodes a raw OBU stream at `EC_TINY_FIXTURE_PATH` --
816 /// no ffmpeg/aomenc invocation -- so a range ladder can be run
817 /// (`EC_TRACE_MODE_STEP=1`) against the exact same bytes fed to the
818 /// oracle aomdec, byte for byte. `#[ignore]`d diagnostic, no assertion.
819 #[test]
820 // Panics with `set EC_TINY_FIXTURE_PATH to an .obu file: NotPresent`
821 // without the var -- it has no default and cannot run unattended. Prints
822 // `decoded N frame(s)` or `REFUSED: <err>`; asserts nothing.
823 #[ignore = "diagnostic: needs EC_TINY_FIXTURE_PATH naming an .obu; prints decode/REFUSED, asserts nothing"]
824 fn probe_tiny_fixture_trace() {
825 let path = std::env::var("EC_TINY_FIXTURE_PATH")
826 .expect("set EC_TINY_FIXTURE_PATH to an .obu file");
827 let stream = std::fs::read(&path).expect("reading fixture");
828 match decode_stream(&stream) {
829 Ok(frames) => {
830 eprintln!("decoded {} frame(s)", frames.len());
831 if let Ok(dump) = std::env::var("EC_TINY_FIXTURE_Y_DUMP") {
832 let bytes: Vec<u8> = frames[0].y.iter().map(|&v| v as u8).collect();
833 std::fs::write(&dump, &bytes).expect("dump y plane");
834 }
835 }
836 Err(e) => eprintln!("REFUSED: {e}"),
837 }
838 }
839
840 /// Pinned streams captured by `EC_AV1_GATE_DUMP` off
841 /// `a_real_aomenc_stream_with_warped_motion_refuses_or_matches` -- each
842 /// one is a former mismatch, kept as a regression pin (warp-mismatch:
843 /// the WARPED_CAUSAL interp-read suppression; warp-flake-7: the same
844 /// suppression for skip_mode blocks; warp-flake-5: mvstack entry
845 /// clamping; ii-flake-1..8: interintra neighbours excluded from
846 /// warp-sample gathering, ref_frame[1] == INTRA_FRAME in the mi grid).
847 /// `EC_AV1_GATE_DUMP_PIN` overrides to a single stream.
848 ///
849 /// Un-`#[ignore]`d with the pin shape fixed: the fourteen pins are COMMITTED
850 /// under `crates/ec-av1/fixtures/`, so the gate runs on a clean checkout
851 /// and carries `warp_selected_hits` 0 -> 113 over the set instead of
852 /// skipping GREEN having read nothing.
853 #[test]
854 fn pinned_warp_stream_decodes_pixel_exact() {
855 if !have_ffmpeg() {
856 eprintln!("SKIP pinned_warp_stream_decodes_pixel_exact: no ffmpeg");
857 return;
858 }
859 // Every pin is COMMITTED under `crates/ec-av1/fixtures/` and named by a
860 // string literal, which is the convention every other pinned gate here
861 // uses and the only shape the pin census can resolve name-by-name. The
862 // old shape -- one GITIGNORED root directory literal plus a runtime
863 // name list formatted against it -- can never be satisfied by a
864 // committed tree, so this gate skipped GREEN having tested nothing.
865 let pins = match std::env::var("EC_AV1_GATE_DUMP_PIN") {
866 Ok(p) => vec![std::path::PathBuf::from(p)],
867 Err(_) => vec![
868 crate_pin("warp-mismatch.obu"),
869 crate_pin("warp-flake-5.obu"),
870 crate_pin("warp-flake-7.obu"),
871 crate_pin("ii-flake-1.obu"),
872 crate_pin("ii-flake-2.obu"),
873 crate_pin("ii-flake-3.obu"),
874 crate_pin("ii-flake-5.obu"),
875 crate_pin("ii-flake-6.obu"),
876 crate_pin("ii-flake-7.obu"),
877 crate_pin("ii-flake-8.obu"),
878 // switchable_interp missing from reset_counts (counter
879 // saturation slowed the adaptation rate) -- unrelated to
880 // interintra, caught by the same gate.
881 crate_pin("ii-flake-9.obu"),
882 // lane-rect r2: HORZ strip rect defects (mvstack size_h,
883 // warp sample/projection dims, OBMC overlap, deblock tx-h).
884 crate_pin("rect-flake-1.obu"),
885 // scan_row/scan_col weight `inc` min'd by the wrong candidate
886 // axis (width vs height) -- ties reordered DRL entry 1 for a
887 // block under a 32x16 strip, and suppressed the -5 extended
888 // row scan.
889 crate_pin("rect-flake-2.obu"),
890 // overlappable_left stepped the vertical walk by the
891 // neighbour's WIDTH: a 32x16 left strip swallowed the strip
892 // below it, blending the wrong OBMC prediction there.
893 crate_pin("rect-flake-3.obu"),
894 ],
895 };
896 for path in pins {
897 eprintln!("pin: {}", path.display());
898 check_pinned_warp_stream(&path);
899 }
900 }
901
902 /// `LAST2_FRAME`/`LAST3_FRAME` are just older slots in the same forward
903 /// reference-buffer ring `LAST_FRAME`/`GOLDEN_FRAME` already prove --
904 /// dropping the golden gate's `--max-reference-frames=3
905 /// --reduced-reference-set=1` narrowing (which suppresses exactly these)
906 /// and running long enough for aomenc's own buffer rotation to reach
907 /// past the first 2 frames is the whole difference.
908 #[test]
909 fn a_real_aomenc_stream_with_a_last2_reference_decodes_pixel_exact() {
910 a_real_aomenc_single_ref_gate(
911 "a_real_aomenc_stream_with_a_last2_reference_decodes_pixel_exact",
912 crate::mvstack::LAST2_FRAME,
913 "LAST2_FRAME",
914 &["--auto-alt-ref=0", "--lag-in-frames=0"],
915 64,
916 64,
917 8,
918 120,
919 );
920 }
921
922 #[test]
923 fn a_real_aomenc_stream_with_a_last3_reference_decodes_pixel_exact() {
924 a_real_aomenc_single_ref_gate(
925 "a_real_aomenc_stream_with_a_last3_reference_decodes_pixel_exact",
926 crate::mvstack::LAST3_FRAME,
927 "LAST3_FRAME",
928 &["--auto-alt-ref=0", "--lag-in-frames=0"],
929 64,
930 64,
931 8,
932 120,
933 );
934 }
935
936 /// `BWDREF`/`ALTREF2`/`ALTREF` are all backward (display-order-forward)
937 /// references that only exist once aomenc builds a hierarchical GOP --
938 /// `--auto-alt-ref=1 --lag-in-frames` (need at least one full mini-GOP
939 /// of lookahead) is what makes aomenc code them at all; without it
940 /// every attempt would hit this decoder's own real, still-open
941 /// per-block sign-bias gap by never drawing the reference in the first
942 /// place, not by proving it correct.
943 #[test]
944 fn a_real_aomenc_stream_with_a_bwdref_reference_decodes_pixel_exact() {
945 a_real_aomenc_single_ref_gate(
946 "a_real_aomenc_stream_with_a_bwdref_reference_decodes_pixel_exact",
947 crate::mvstack::BWDREF_FRAME,
948 "BWDREF_FRAME",
949 &[
950 "--auto-alt-ref=1",
951 "--lag-in-frames=16",
952 "--enable-fwd-kf=0",
953 ],
954 64,
955 64,
956 16,
957 120,
958 );
959 }
960
961 /// lane-altref2 r1: 16 frames was too short for aomenc to ever build a
962 /// second-level alt-ref pyramid, so this gate ran 86 attempts and fired
963 /// ALTREF2 exactly zero times (class `gate-blind-to-feature`) -- the
964 /// flags were already right, only the clip length was wrong. A 64-frame
965 /// clip at the same `--lag-in-frames=16` gives aomenc enough lookahead
966 /// to schedule a 2-level GF pyramid and reliably codes ALTREF2 (4/4
967 /// hits on a plain seed-42 direct-aomenc probe; see
968 /// lanes/altref2-r1.report.md for the recipe search table). Firing is
969 /// now HARD-asserted below: the gate fails rather than skips if
970 /// `ref_hits(ALTREF2_FRAME)` does not advance.
971 #[test]
972 fn a_real_aomenc_stream_with_an_altref2_reference_decodes_pixel_exact() {
973 let before = decode::ref_hits(crate::mvstack::ALTREF2_FRAME);
974 a_real_aomenc_single_ref_gate(
975 "a_real_aomenc_stream_with_an_altref2_reference_decodes_pixel_exact",
976 crate::mvstack::ALTREF2_FRAME,
977 "ALTREF2_FRAME",
978 &[
979 "--auto-alt-ref=1",
980 "--lag-in-frames=16",
981 "--enable-fwd-kf=0",
982 ],
983 64,
984 64,
985 64,
986 120,
987 );
988 let after = decode::ref_hits(crate::mvstack::ALTREF2_FRAME);
989 assert!(
990 after > before,
991 "a_real_aomenc_stream_with_an_altref2_reference_decodes_pixel_exact: \
992 ALTREF2_FRAME never fired across 120 attempts -- the gate is vacuous \
993 again (class gate-blind-to-feature); see lanes/altref2-r1.report.md \
994 for the recipe that is supposed to make this fire"
995 );
996 }
997
998 #[test]
999 fn a_real_aomenc_stream_with_an_altref_reference_decodes_pixel_exact() {
1000 a_real_aomenc_single_ref_gate(
1001 "a_real_aomenc_stream_with_an_altref_reference_decodes_pixel_exact",
1002 crate::mvstack::ALTREF_FRAME,
1003 "ALTREF_FRAME",
1004 &[
1005 "--auto-alt-ref=1",
1006 "--lag-in-frames=16",
1007 "--enable-fwd-kf=0",
1008 ],
1009 64,
1010 64,
1011 16,
1012 120,
1013 );
1014 }
1015
1016 #[test]
1017 fn a_real_aomenc_stream_with_temporal_mvs_decodes_pixel_exact() {
1018 a_real_aomenc_temporal_mv_gate(42, 40);
1019 }
1020
1021 #[test]
1022 fn a_real_aomenc_compound_mv_stack_with_temporal_mvs_decodes_pixel_exact() {
1023 a_real_aomenc_compound_mv_stack_gate(
1024 "a_real_aomenc_compound_mv_stack_with_temporal_mvs_decodes_pixel_exact",
1025 42,
1026 30,
1027 8,
1028 64,
1029 0,
1030 64,
1031 0,
1032 );
1033 }
1034
1035 #[test]
1036 fn a_real_aomenc_compound_mv_stack_with_global_motion_decodes_pixel_exact() {
1037 a_real_aomenc_compound_mv_stack_gate(
1038 "a_real_aomenc_compound_mv_stack_with_global_motion_decodes_pixel_exact",
1039 80,
1040 30,
1041 8,
1042 64,
1043 1,
1044 64,
1045 0,
1046 );
1047 }
1048
1049 #[test]
1050 fn a_real_aomenc_10bit_compound_mv_stack_at_128_superblocks_decodes_pixel_exact() {
1051 a_real_aomenc_compound_mv_stack_gate(
1052 "a_real_aomenc_10bit_compound_mv_stack_at_128_superblocks_decodes_pixel_exact",
1053 120,
1054 30,
1055 10,
1056 128,
1057 1,
1058 64,
1059 0,
1060 );
1061 }
1062
1063 /// Was a KNOWN OPEN DEFECT (found by lane-mvtwin r1, `#[ignore]`d for it):
1064 /// a real aomenc stream 128 px wide with `--tile-columns=1` (two 64-px
1065 /// tile columns) mis-decoded frame 1's luma against ffmpeg at seed 200
1066 /// with this exact recipe. lane-t900 r15 RE-MEASURED it on the merged tip
1067 /// (after the motion-field tile clamp, the per-tile txfm/mode band resets
1068 /// and the 8x8-compound interp-filter read landed): the arm decodes
1069 /// pixel-exact, so the `#[ignore]` is removed and the multi-tile mv-stack
1070 /// coverage is live.
1071 ///
1072 /// It is also the ONLY arm that reaches r1 defect 3 (the col reach is
1073 /// clamped to `tile_col0`, not the frame edge): the counter
1074 /// `mvstack::tile_reach_clips` advanced to 60 on this stream. Defect 3
1075 /// itself is proven deterministically by
1076 /// `mvstack::tests::the_row_reach_is_clamped_to_the_tile_origin_not_the_frame_edge`.
1077 #[test]
1078 fn a_real_aomenc_compound_mv_stack_across_two_tile_columns_decodes_pixel_exact() {
1079 let name = "a_real_aomenc_compound_mv_stack_across_two_tile_columns_decodes_pixel_exact";
1080 let before = crate::mvstack::tile_reach_clips();
1081 a_real_aomenc_compound_mv_stack_gate(name, 200, 30, 8, 64, 0, 128, 1);
1082 assert!(
1083 crate::mvstack::tile_reach_clips() > before,
1084 "{name}: no block was ever built inside a tile past mi 0 -- \
1085 --tile-columns=1 did not produce a second tile column"
1086 );
1087 }
1088
1089 /// bisect scratch: decode a pinned stream exactly once -- generic
1090 /// pin-repro tool, kept for manual use.
1091 #[test]
1092 // Panics with `set EC_AV1_PIN to the .obu path: NotPresent` without the
1093 // var. Prints `OK: N frames` or `ERR: <err>` -- a one-line "does this pin
1094 // decode at all" check, so it asserts nothing by design.
1095 #[ignore = "scratch: decodes the .obu at EC_AV1_PIN and prints OK/ERR; asserts nothing"]
1096 fn scratch_decode_pinned_stream_once() {
1097 let path = std::env::var("EC_AV1_PIN").expect("set EC_AV1_PIN to the .obu path");
1098 let stream = std::fs::read(&path).expect("read pinned stream");
1099 match decode_stream(&stream) {
1100 Ok(frames) => eprintln!("OK: {} frames", frames.len()),
1101 Err(e) => eprintln!("ERR: {e}"),
1102 }
1103 }
1104
1105 /// scratch: isolate a pinned mismatching stream's first divergent pixel.
1106 #[test]
1107 // Panics with `set EC_AV1_PIN to the .obu path: NotPresent` without the
1108 // var, AND the built-in geometry defaults (W=64, H=64, N=1) are wrong for
1109 // every real pin: they are the 64x64 seed-42 pin's own numbers, so on any
1110 // other pin the run dies inside the ffmpeg oracle with a frame-size
1111 // assert (`expected 1 4:2:0 frames ... left 24576 right 6144`) instead of
1112 // saying "you forgot the geometry". Set all four.
1113 #[ignore = "scratch: needs EC_AV1_PIN plus EC_AV1_PIN_W/H/N at the pin's REAL geometry (defaults 64/64/1 are wrong for every other pin); prints the first divergent pixel per plane"]
1114 fn scratch_isolate_pinned_mismatch() {
1115 let path = std::env::var("EC_AV1_PIN").expect("set EC_AV1_PIN to the .obu path");
1116 let stream = std::fs::read(&path).expect("read pinned stream");
1117 {
1118 let mut p = Av1Parser::new();
1119 let mut pos = 0usize;
1120 while pos < stream.len() {
1121 let obu = p.parse_obu(&stream[pos..]).expect("parse");
1122 pos += obu.total_size;
1123 if let ObuKind::Frame(header, _) = obu.kind {
1124 eprintln!("interpolation_filter: {:?}", header.interpolation_filter);
1125 eprintln!("cdef: {:?}", header.cdef);
1126 eprintln!("quantization: {:?}", header.quantization);
1127 eprintln!(
1128 "coded_lossless: {:?} tx_mode: {:?}",
1129 header.coded_lossless, header.tx_mode
1130 );
1131 eprintln!("delta: {:?}", header.delta);
1132 eprintln!("segmentation: {:?}", header.segmentation);
1133 eprintln!("loop_restoration: {:?}", header.loop_restoration);
1134 eprintln!(
1135 "use_128x128_superblock: {:?} disable_cdf_update: {:?} disable_frame_end_update_cdf: {:?} primary_ref_frame: {:?} allow_high_precision_mv: {:?} force_integer_mv: {:?}",
1136 p.sequence_header().map(|s| s.use_128x128_superblock),
1137 header.disable_cdf_update,
1138 header.disable_frame_end_update_cdf,
1139 header.primary_ref_frame,
1140 header.allow_high_precision_mv,
1141 header.force_integer_mv,
1142 );
1143 }
1144 }
1145 }
1146 let width = std::env::var("EC_AV1_PIN_W")
1147 .map(|s| s.parse().unwrap())
1148 .unwrap_or(64);
1149 let height = std::env::var("EC_AV1_PIN_H")
1150 .map(|s| s.parse().unwrap())
1151 .unwrap_or(64);
1152 let frame_count = std::env::var("EC_AV1_PIN_N")
1153 .map(|s| s.parse().unwrap())
1154 .unwrap_or(4);
1155 let frames = decode_stream(&stream).expect("our decode");
1156 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
1157 // The `.min()` chain below is a scratch diagnostic that tolerates a
1158 // pinned stream whose counts disagree, but a SILENT shortfall reads as
1159 // "these frames matched" for frames nobody compared. Say how many are
1160 // actually walked.
1161 let walked = frame_count.min(frames.len()).min(ffmpeg_frames.len());
1162 if walked < frame_count {
1163 eprintln!(
1164 "pinned stream: asked for {frame_count} frames (EC_AV1_PIN_N), we show {}, ffmpeg \
1165 shows {} -- comparing the first {walked} only",
1166 frames.len(),
1167 ffmpeg_frames.len()
1168 );
1169 }
1170 for f in 0..walked {
1171 let ours = &frames[f];
1172 let theirs = &ffmpeg_frames[f];
1173 for (plane_name, a, b, w) in [
1174 ("y", &ours.y, &theirs.y, width),
1175 ("u", &ours.u, &theirs.u, width / 2),
1176 ("v", &ours.v, &theirs.v, width / 2),
1177 ] {
1178 // A short plane would zip-truncate the walk below and report
1179 // MATCH over the prefix the two share.
1180 assert_eq!(
1181 a.len(),
1182 b.len(),
1183 "frame {f} plane {plane_name}: ours has {} samples, ffmpeg's has {}",
1184 a.len(),
1185 b.len()
1186 );
1187 let mut first = None;
1188 let mut count = 0;
1189 let mut worst = 0i32;
1190 for (i, (x, y)) in a.iter().zip(b.iter()).enumerate() {
1191 if x != y {
1192 count += 1;
1193 if first.is_none() {
1194 first = Some(i);
1195 }
1196 worst = worst.max((*x as i32 - *y as i32).abs());
1197 }
1198 }
1199 if let Some(i) = first {
1200 eprintln!(
1201 "frame {f} plane {plane_name}: {count} mismatches (worst delta {worst}), first at offset {i} (row {}, col {}) ours={} theirs={}",
1202 i / w,
1203 i % w,
1204 a[i],
1205 b[i]
1206 );
1207 } else {
1208 eprintln!("frame {f} plane {plane_name}: MATCH");
1209 }
1210 }
1211 }
1212 }
1213
1214 /// Final round of the TX4/tx-class lane's own gate: `--min-partition-size=8
1215 /// --max-partition-size=8` pins every leaf to exactly 8x8 (spec
1216 /// 5.11.4's own boundary carve-out aside, which a multiple-of-8 frame
1217 /// never triggers), so a real `aomenc` stream from this recipe can only
1218 /// legitimately read `PARTITION_NONE` at every `bsize=3` node -- any
1219 /// other value this decoder sees there is a genuine desync, not a
1220 /// "partition below 8x8" the encoder actually wrote (traced live against
1221 /// a debug `aomdec` 2026-08-27: the true bitstream's own 8x8 partition
1222 /// reads are all `NONE`; the mismatch was `base_ctx`'s DC-position
1223 /// short-circuit firing for `TX_CLASS_HORIZ`/`VERT` too, off by one
1224 /// `BR` read into a spurious extra Golomb call). The sinusoidal-stripe
1225 /// `geq` source (a smooth luma ramp, not the sharp two-tone stripes that
1226 /// tripped `aomenc`'s screen-content-tools auto-detect) is what actually
1227 /// resolves `V_DCT`/`H_DCT` (`TxClass::of`) on some 8x8 TUs at this
1228 /// content's frequency; the attempt loop moves on from named refusals
1229 /// (`allow_screen_content_tools`, angle-delta) same as every other
1230 /// multi-seed recipe in this file, and only counts a run as a genuine
1231 /// firing when [`decode::tx_class1_hits`] actually moved.
1232 #[test]
1233 fn a_real_aomenc_min8_stream_with_tx_class1_decodes_pixel_exact() {
1234 if !have_ffmpeg() {
1235 eprintln!(
1236 "SKIP a_real_aomenc_min8_stream_with_tx_class1_decodes_pixel_exact: no ffmpeg"
1237 );
1238 return;
1239 }
1240 if !have_aomenc() {
1241 eprintln!(
1242 "SKIP a_real_aomenc_min8_stream_with_tx_class1_decodes_pixel_exact: no aomenc at {}",
1243 aomenc_path().display()
1244 );
1245 return;
1246 }
1247 let (width, height) = (64usize, 64usize);
1248 let mut refusals = Vec::new();
1249 let mut fired_runs = 0u32;
1250 let mut uncounted_exact = 0u32;
1251 for attempt in 0..60u32 {
1252 let cq = 20 + (attempt % 5) * 10;
1253 let period = [4u32, 6, 8, 12, 16][(attempt as usize / 5) % 5];
1254 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
1255 .args([
1256 "-v",
1257 "error",
1258 "-f",
1259 "lavfi",
1260 "-i",
1261 "testsrc2=size=64x64:rate=25",
1262 "-vf",
1263 &format!(
1264 "geq=lum='128+80*sin(2*PI*Y/{period})':cb=128:cr=128,noise=alls=6:allf=t"
1265 ),
1266 "-pix_fmt",
1267 "yuv420p",
1268 "-t",
1269 "0.04",
1270 "-f",
1271 "yuv4mpegpipe",
1272 "-",
1273 ])
1274 .stdin(Stdio::null())
1275 .stdout(Stdio::piped())
1276 .stderr(Stdio::piped()), None, |c| c.output())
1277 .expect("ffmpeg failed to run");
1278 assert!(
1279 y4m.status.success(),
1280 "ffmpeg fixture: {}",
1281 String::from_utf8_lossy(&y4m.stderr)
1282 );
1283 let out = run_with_stdin(
1284 Command::new(aomenc_path()).args([
1285 "--codec=av1",
1286 "--passes=1",
1287 "--end-usage=q",
1288 &format!("--cq-level={cq}"),
1289 "--cpu-used=0",
1290 "--enable-directional-intra=0",
1291 "--enable-smooth-intra=0",
1292 "--enable-paeth-intra=0",
1293 "--enable-rect-partitions=0",
1294 "--enable-angle-delta=0",
1295 "--enable-palette=0",
1296 "--reduced-tx-type-set=0",
1297 "--enable-restoration=0",
1298 "--enable-cdef=0",
1299 "--loopfilter-control=0",
1300 "--min-partition-size=8",
1301 "--max-partition-size=8",
1302 "--enable-ab-partitions=0",
1303 "--enable-1to4-partitions=0",
1304 "--enable-filter-intra=0",
1305 "--enable-intrabc=0",
1306 "--enable-cfl-intra=0",
1307 // use_ref_frame_mvs (temporal MV projection) is unimplemented in mvstack;
1308 // leaving it on silently desyncs symbols on inter frames (grainfix lesson).
1309 "--enable-ref-frame-mvs=0",
1310 "--tune-content=default",
1311 "--obu",
1312 "-o",
1313 "-",
1314 "-",
1315 ]),
1316 &y4m.stdout,
1317 );
1318 if !out.status.success() {
1319 refusals.push(format!(
1320 "cq={cq} period={period}: aomenc itself refused the fixture"
1321 ));
1322 continue;
1323 }
1324 let stream = out.stdout;
1325 let before = decode::tx_class1_hits();
1326 let frames = match decode_stream(&stream) {
1327 Ok(frames) => frames,
1328 Err(e) => {
1329 refusals.push(format!("cq={cq} period={period}: {e}"));
1330 continue;
1331 }
1332 };
1333 // class [[gate-skips-on-its-own-failure]]: a decode that succeeded
1334 // is ALWAYS pixel-compared below; the hit counter only decides whether
1335 // the attempt counts toward the firing total.
1336 let counted = decode::tx_class1_hits() != before;
1337 if !counted {
1338 uncounted_exact += 1;
1339 refusals.push(format!(
1340 "cq={cq} period={period}: decoded and pixel-compared, but no block read a \
1341 V_DCT/H_DCT tx_type"
1342 ));
1343 }
1344 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
1345 assert_eq!(
1346 frames[0].y, ffmpeg_frames[0].y,
1347 "luma vs ffmpeg (cq={cq} period={period})"
1348 );
1349 assert_eq!(
1350 frames[0].u, ffmpeg_frames[0].u,
1351 "U vs ffmpeg (cq={cq} period={period})"
1352 );
1353 assert_eq!(
1354 frames[0].v, ffmpeg_frames[0].v,
1355 "V vs ffmpeg (cq={cq} period={period})"
1356 );
1357 if counted {
1358 fired_runs += 1;
1359 if fired_runs >= 4 {
1360 gate_buckets(
1361 "a_real_aomenc_min8_stream_with_tx_class1_decodes_pixel_exact",
1362 fired_runs,
1363 uncounted_exact,
1364 refusals.len() - uncounted_exact as usize,
1365 );
1366 return;
1367 }
1368 }
1369 }
1370 gate_buckets(
1371 "a_real_aomenc_min8_stream_with_tx_class1_decodes_pixel_exact",
1372 fired_runs,
1373 uncounted_exact,
1374 refusals.len() - uncounted_exact as usize,
1375 );
1376 panic!(
1377 "fewer than 4 firing+pixel-exact runs out of 60 attempts:\n{}",
1378 refusals.join("\n")
1379 );
1380 }
1381
1382 /// lane-cdef r1: CDEF's per-8x8 skip band under sub-16x16 inter leaves.
1383 ///
1384 /// `apply_cdef` excludes an 8x8 luma unit whose four mi cells are all
1385 /// `skip_txfm` (libaom `cdef.c:29-38 is_8x8_block_skip`, called from
1386 /// `av1_cdef_compute_sb_list`'s dlist loop). `decode_inter_block8` -- the
1387 /// leaf path `--min-partition-size=4` makes aomenc pick for a 16x16 group
1388 /// -- wrote the loop-filter grid but never that skip band, so an all-skip
1389 /// group kept the PREVIOUS frame's flags and got filtered where libaom
1390 /// skips it (3 luma samples, decode-order frames 3 and 4 of the 192x128
1391 /// cq-8 stream below, at the frame's last 8x8 column).
1392 ///
1393 /// Both counters are hard asserts per compared attempt: `cdef_skipped_units`
1394 /// proves the all-skip dlist exclusion was actually reached, and
1395 /// `inter8_skip_band_hits` proves the 8x8 leaf path (the writer that used
1396 /// to be missing) ran on the same stream.
1397 #[test]
1398 fn a_real_aomenc_stream_with_cdef_and_sub16_inter_leaves_decodes_pixel_exact() {
1399 if !have_aomenc() {
1400 return;
1401 }
1402 let (width, height, frames) = (192usize, 128usize, 6usize);
1403 let mut refusals: Vec<String> = Vec::new();
1404 let mut fired = 0u32;
1405 let mut cdef_fired = 0u32;
1406 let mut leaf_fired = 0u32;
1407 for (depth, cq, sp) in [
1408 (8u32, 8u32, 3u32),
1409 (8, 10, 3),
1410 (8, 12, 6),
1411 (10, 8, 3),
1412 (10, 12, 6),
1413 ] {
1414 let pix = if depth == 10 {
1415 "yuv420p10le"
1416 } else {
1417 "yuv420p"
1418 };
1419 let src = format!(
1420 "color=c=gray:s={width}x{height}:d=0.24:r=25,format=gray,\
1421 geq=lum='128+58*sin((X+N*{sp})/6)+18*sin(Y/23)',format=yuv420p"
1422 );
1423 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
1424 .args([
1425 "-v",
1426 "error",
1427 "-f",
1428 "lavfi",
1429 "-i",
1430 &src,
1431 "-t",
1432 "0.24",
1433 "-pix_fmt",
1434 pix,
1435 "-strict",
1436 "-1",
1437 "-f",
1438 "yuv4mpegpipe",
1439 "-",
1440 ])
1441 .stdin(Stdio::null())
1442 .stdout(Stdio::piped())
1443 .stderr(Stdio::piped()), None, |c| c.output())
1444 .expect("ffmpeg failed to run");
1445 assert!(
1446 y4m.status.success(),
1447 "ffmpeg fixture: {}",
1448 String::from_utf8_lossy(&y4m.stderr)
1449 );
1450 let out = run_with_stdin(
1451 Command::new(aomenc_path()).args([
1452 "--codec=av1",
1453 "--passes=1",
1454 "--end-usage=q",
1455 &format!("--cq-level={cq}"),
1456 "--cpu-used=0",
1457 "--threads=1",
1458 "--row-mt=0",
1459 "--sb-size=64",
1460 &format!("--bit-depth={depth}"),
1461 &format!("--input-bit-depth={depth}"),
1462 "--enable-restoration=0",
1463 "--enable-palette=0",
1464 "--deltaq-mode=0",
1465 "--enable-filter-intra=0",
1466 "--enable-cfl-intra=0",
1467 "--enable-intrabc=0",
1468 "--lag-in-frames=0",
1469 "--enable-obmc=0",
1470 "--enable-tx-size-search=1",
1471 "--enable-rect-partitions=0",
1472 "--enable-ab-partitions=0",
1473 "--enable-1to4-partitions=0",
1474 "--min-partition-size=4",
1475 "--max-partition-size=16",
1476 // Last occurrence of a repeated --enable-* flag wins
1477 // (aomenc-last-flag-wins): CDEF stays ON, and the two
1478 // counters below prove the filter really ran.
1479 "--enable-cdef=1",
1480 "--obu",
1481 "-o",
1482 "-",
1483 "-",
1484 ]),
1485 &y4m.stdout,
1486 );
1487 assert!(
1488 out.status.success(),
1489 "aomenc refused the fixture (depth={depth} cq={cq})"
1490 );
1491 let stream = out.stdout;
1492 let skipped_before = decode::cdef_skipped_units();
1493 let leaves_before = decode::inter8_skip_band_hits();
1494 let decoded = match decode_stream(&stream) {
1495 Ok(f) => f,
1496 Err(e) => {
1497 let msg = e.to_string();
1498 assert!(
1499 msg.starts_with("unsupported: "),
1500 "decode error that is not a named refusal \
1501 (depth={depth} cq={cq}): {msg}"
1502 );
1503 refusals.push(format!("depth={depth} cq={cq}: {msg}"));
1504 continue;
1505 }
1506 };
1507 assert_eq!(decoded.len(), frames, "frame count (depth={depth} cq={cq})");
1508 // lane-leaf8tx r2: continue-and-sweep, not a per-attempt hard
1509 // assert. Lifting a refusal reshuffles WHICH attempt this gate
1510 // lands on (class [[parallel-flake-is-attempt-selection]]): the
1511 // first decoded attempt need not carry a sub-16 leaf, and
1512 // aborting there skipped the pixel compare entirely. Every
1513 // decoded attempt is compared; the counters are asserted once,
1514 // at the end, over the compared attempts.
1515 if decode::cdef_skipped_units() > skipped_before {
1516 cdef_fired += 1;
1517 }
1518 if decode::inter8_skip_band_hits() > leaves_before {
1519 leaf_fired += 1;
1520 }
1521 let reference = if depth == 10 {
1522 ffmpeg_decode_sequence_10bit(&stream, width, height, frames)
1523 } else {
1524 ffmpeg_decode_sequence(&stream, width, height, frames)
1525 };
1526 for (i, (ours, theirs)) in decoded.iter().zip(reference.iter()).enumerate() {
1527 assert_eq!(ours.y, theirs.y, "luma frame {i} (depth={depth} cq={cq})");
1528 assert_eq!(ours.u, theirs.u, "U frame {i} (depth={depth} cq={cq})");
1529 assert_eq!(ours.v, theirs.v, "V frame {i} (depth={depth} cq={cq})");
1530 }
1531 fired += 1;
1532 }
1533 // Three of the five arms land on OTHER open refusals (a non-DC chroma
1534 // mode on an 8x8 inter leaf; inter partitions below 8x8) -- the two
1535 // 8-bit cq 8/10 arms ARE the streams the defect was found on, and each
1536 // hard-asserts both counters plus all six frames on all three planes.
1537 assert!(
1538 fired >= 2,
1539 "fewer than 2 decoded+pixel-exact attempts:\n{}",
1540 refusals.join("\n")
1541 );
1542 assert!(
1543 cdef_fired > 0,
1544 "no compared attempt excluded an 8x8 CDEF unit by the all-skip rule \
1545 ({fired} compared):\n{}",
1546 refusals.join("\n")
1547 );
1548 assert!(
1549 leaf_fired > 0,
1550 "no compared attempt had a sub-16x16 inter leaf write the CDEF skip band \
1551 ({fired} compared):\n{}",
1552 refusals.join("\n")
1553 );
1554 }
1555
1556 /// lane-cdefstrip r1: the CDEF skip band under SKIPPED rectangular inter
1557 /// strips (32x8 / 8x32 / 64x16 / 16x64 / 32x64 / 64x32, the rect and 1:4
1558 /// arms), the sibling of the 8x8-leaf case lane-cdef fixed.
1559 ///
1560 /// A fresh `Neighbours` seeds `skip_grid` all-`false` ("not skip"), so any
1561 /// decode arm that resolves `skip` and forgets `fill_skip_grid_rect` makes
1562 /// `apply_cdef` FILTER an 8x8 unit libaom's `is_8x8_block_skip`
1563 /// (`cdef.c:29-38`, `av1_cdef_compute_sb_list`'s dlist test) excludes --
1564 /// a +-1 band that no entropy or prediction check can see.
1565 /// `decode::cdef_unwritten_skip_units` is the direct instrument for that
1566 /// class: it counts 8x8 CDEF units none of whose four mi cells any coded
1567 /// block wrote this frame, and this gate hard-asserts it stays 0 while
1568 /// `decode::rect_skip_band_hits` proves skipped rect strips really ran.
1569 ///
1570 /// MEASURED (lane-cdefstrip r1, 177 real aomenc streams incl. every arm
1571 /// below): the count is already 0 everywhere -- the charter's premise that
1572 /// the rect strip arms never write the band is FALSE. This gate is the
1573 /// regression fence for it, not a fix.
1574 #[test]
1575 fn a_real_aomenc_stream_with_skipped_rect_inter_strips_keeps_the_cdef_skip_band() {
1576 if !have_aomenc() {
1577 return;
1578 }
1579 let (width, height, frames) = (192usize, 128usize, 6usize);
1580 let mut refusals: Vec<String> = Vec::new();
1581 let mut fired = 0u32;
1582 // (depth, cq, source): the arms measured pixel-exact end to end in the
1583 // r1 sweep (~/.cache/cdefstrip-tmp/sw.sh). Source `b` is the two-axis
1584 // moving sinusoid that makes aomenc pick 16x64/32x64/8x32 strips at
1585 // low cq and 32x8/64x16 at high cq; `a` is lane-inter16ab's source.
1586 let src_b = "120+55*sin((X+N*4)/7)+40*sin((Y-N*2)/11)";
1587 let src_a = "128+60*sin((Y+N*3)/5)+30*sin(X/23)";
1588 for (depth, cq, lum) in [
1589 (8u32, 18u32, src_b),
1590 (8, 45, src_b),
1591 (10, 18, src_b),
1592 (10, 24, src_b),
1593 (10, 24, src_a),
1594 (8, 24, src_a),
1595 ] {
1596 let pix = if depth == 10 {
1597 "yuv420p10le"
1598 } else {
1599 "yuv420p"
1600 };
1601 let src = format!(
1602 "color=c=gray:s={width}x{height}:d=0.24:r=25,format=gray,\
1603 geq=lum='{lum}',format=yuv420p"
1604 );
1605 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
1606 .args([
1607 "-v",
1608 "error",
1609 "-f",
1610 "lavfi",
1611 "-i",
1612 &src,
1613 "-t",
1614 "0.24",
1615 "-pix_fmt",
1616 pix,
1617 "-strict",
1618 "-1",
1619 "-f",
1620 "yuv4mpegpipe",
1621 "-",
1622 ])
1623 .stdin(Stdio::null())
1624 .stdout(Stdio::piped())
1625 .stderr(Stdio::piped()), None, |c| c.output())
1626 .expect("ffmpeg failed to run");
1627 assert!(
1628 y4m.status.success(),
1629 "ffmpeg fixture: {}",
1630 String::from_utf8_lossy(&y4m.stderr)
1631 );
1632 let out = run_with_stdin(
1633 Command::new(aomenc_path()).args([
1634 "--codec=av1",
1635 "--passes=1",
1636 "--end-usage=q",
1637 &format!("--cq-level={cq}"),
1638 "--cpu-used=0",
1639 "--threads=1",
1640 "--row-mt=0",
1641 "--sb-size=64",
1642 &format!("--bit-depth={depth}"),
1643 &format!("--input-bit-depth={depth}"),
1644 "--enable-restoration=0",
1645 "--enable-palette=0",
1646 "--deltaq-mode=0",
1647 "--enable-filter-intra=0",
1648 "--enable-cfl-intra=0",
1649 "--enable-intrabc=0",
1650 "--lag-in-frames=0",
1651 "--kf-max-dist=9999",
1652 "--tile-columns=0",
1653 "--enable-tx-size-search=0",
1654 "--enable-ab-partitions=0",
1655 "--min-partition-size=8",
1656 "--max-partition-size=64",
1657 // Last occurrence wins (aomenc-last-flag-wins): the three
1658 // flags this gate is about stay last.
1659 "--enable-rect-partitions=1",
1660 "--enable-1to4-partitions=1",
1661 "--enable-cdef=1",
1662 "--obu",
1663 "-o",
1664 "-",
1665 "-",
1666 ]),
1667 &y4m.stdout,
1668 );
1669 assert!(
1670 out.status.success(),
1671 "aomenc refused the fixture (depth={depth} cq={cq})"
1672 );
1673 let stream = out.stdout;
1674 let unwritten_before = decode::cdef_unwritten_skip_units();
1675 let rect_skip_before = decode::rect_skip_band_hits();
1676 let skipped_before = decode::cdef_skipped_units();
1677 let decoded = match decode_stream(&stream) {
1678 Ok(f) => f,
1679 Err(e) => {
1680 let msg = e.to_string();
1681 assert!(
1682 msg.starts_with("unsupported: "),
1683 "decode error that is not a named refusal \
1684 (depth={depth} cq={cq}): {msg}"
1685 );
1686 refusals.push(format!("depth={depth} cq={cq}: {msg}"));
1687 continue;
1688 }
1689 };
1690 assert_eq!(decoded.len(), frames, "frame count (depth={depth} cq={cq})");
1691 assert_eq!(
1692 decode::cdef_unwritten_skip_units(),
1693 unwritten_before,
1694 "an 8x8 CDEF unit was judged from an UNWRITTEN skip band \
1695 (a decode arm resolved `skip` without `fill_skip_grid_rect`) \
1696 (depth={depth} cq={cq})"
1697 );
1698 let reference = if depth == 10 {
1699 ffmpeg_decode_sequence_10bit(&stream, width, height, frames)
1700 } else {
1701 ffmpeg_decode_sequence(&stream, width, height, frames)
1702 };
1703 for (i, (ours, theirs)) in decoded.iter().zip(reference.iter()).enumerate() {
1704 assert_eq!(ours.y, theirs.y, "luma frame {i} (depth={depth} cq={cq})");
1705 assert_eq!(ours.u, theirs.u, "U frame {i} (depth={depth} cq={cq})");
1706 assert_eq!(ours.v, theirs.v, "V frame {i} (depth={depth} cq={cq})");
1707 }
1708 // Pixels are asserted for EVERY decoded attempt above; an attempt
1709 // counts as FIRING only if this stream really exercised the class
1710 // (a skipped rect strip wrote the band AND CDEF consulted it via
1711 // the all-skip exclusion). aomenc picking no skipped strip at a
1712 // given cq is a non-firing attempt, never a weakened assert.
1713 let rect_skips = decode::rect_skip_band_hits() - rect_skip_before;
1714 let excluded = decode::cdef_skipped_units() - skipped_before;
1715 if rect_skips == 0 || excluded == 0 {
1716 refusals.push(format!(
1717 "depth={depth} cq={cq}: exact but did not fire \
1718 (skipped rect strips {rect_skips}, excluded 8x8 units {excluded})"
1719 ));
1720 continue;
1721 }
1722 fired += 1;
1723 }
1724 eprintln!(
1725 "a_real_aomenc_stream_with_skipped_rect_inter_strips_keeps_the_cdef_skip_band: \
1726 {fired} firing+exact attempts, unwritten skip-band units {}, \
1727 skipped rect strips {}, 8x8 units excluded {}\n{}",
1728 decode::cdef_unwritten_skip_units(),
1729 decode::rect_skip_band_hits(),
1730 decode::cdef_skipped_units(),
1731 refusals.join("\n")
1732 );
1733 assert!(
1734 fired >= 3,
1735 "fewer than 3 firing+pixel-exact attempts:\n{}",
1736 refusals.join("\n")
1737 );
1738 }
1739
1740 /// lane-sub8 r1: `--min-partition-size=4` on fine-detail noisy gradients
1741 /// at low cq reliably makes aomenc split an 8x8 block all the way to
1742 /// four `BLOCK_4X4` leaves (`PARTITION_SPLIT` below 8x8, spec
1743 /// `decode_partition`'s recursion bottom) -- confirmed with
1744 /// `EC_AV1_TRACE=1` against `examples/decode_probe` before this gate was
1745 /// written (`partition_w8 ... value=3` at mi=(0,0) on the very first
1746 /// block). [`decode::sub8_split_hits`] hard-asserts the path actually
1747 /// ran rather than every attempt landing on `PARTITION_NONE`.
1748 #[test]
1749 fn a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact() {
1750 if !have_ffmpeg() {
1751 eprintln!("SKIP a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact: no ffmpeg");
1752 return;
1753 }
1754 if !have_aomenc() {
1755 let msg = format!("no aomenc at {}", aomenc_path().display());
1756 assert!(
1757 std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none(),
1758 "EC_AV1_REQUIRE_AOMENC is set but {msg}"
1759 );
1760 eprintln!("SKIP a_real_aomenc_stream_with_a_sub8_split_decodes_pixel_exact: {msg}");
1761 return;
1762 }
1763 // round 2: `--enable-rect-partitions=0` was added below to keep
1764 // aomenc off HORZ/VERT-below-8x8 elsewhere in the same tile, but it
1765 // is NOT sufficient alone -- see the round-2 report
1766 // (lanes/sub8-r1.report.md) for the live finding: 0/160 attempts
1767 // across both 64x64 and a spatially-isolated single-16x16-leaf
1768 // fixture passed, and every SPLIT that fires is immediately
1769 // followed by a spurious HORZ/VERT read on the very next sibling
1770 // 8x8 leaf, which reads as a real desync left behind by
1771 // `decode_leaf_split4`/`read_intra_mode_sub8`, not an encoder
1772 // choice this recipe can dodge. Tried and rejected: shrinking the
1773 // frame to 16x16 (single 16x16 leaf, at most 4 candidate 8x8s) --
1774 // that surfaces an UNRELATED pre-existing tiny-frame edge-straddle
1775 // defect (reproduces with zero sub8 code involved, `--min-partition
1776 // -size`/`--max-partition-size` absent entirely), so it is not a
1777 // safe way to isolate the leaf count. Left red; do not "fix" this
1778 // gate by picking fixture parameters that dodge the desync without
1779 // finding it.
1780 // lane-sub8 r6: three arms. The mi-granular mode maps
1781 // (`sub8_mode_col`/`uv_mode_col` and their row twins) are per TILE --
1782 // the verifier's repro was a 128x64 `--tile-columns=1` stream (seeds
1783 // 207/228) whose every mismatching luma pixel sat at x>=64, the tile
1784 // boundary -- so one arm per tile axis is part of this gate.
1785 for (width, height, tile_args) in [
1786 (64usize, 64usize, &[][..]),
1787 (128usize, 64usize, &["--tile-columns=1"][..]),
1788 (64usize, 128usize, &["--tile-rows=1"][..]),
1789 ] {
1790 let mut refusals = Vec::new();
1791 let mut fired_runs = 0u32;
1792 for attempt in 0..40u32 {
1793 let seed = 100 + attempt;
1794 let cq = 6 + (attempt % 4) * 2;
1795 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
1796 .args([
1797 "-v",
1798 "error",
1799 "-f",
1800 "lavfi",
1801 "-i",
1802 &gradients_source(seed, width, height, "rate=25"),
1803 "-vf",
1804 // `noise` without `all_seed` re-renders differently on
1805 // every run (seeded-fixture-not-reproducible); pinning it
1806 // makes (seed, cq) name one exact stream.
1807 &format!("noise=alls=40:allf=t:all_seed={seed},format=yuv420p"),
1808 "-t",
1809 "0.04",
1810 "-f",
1811 "yuv4mpegpipe",
1812 "-",
1813 ])
1814 .stdin(Stdio::null())
1815 .stdout(Stdio::piped())
1816 .stderr(Stdio::piped()), None, |c| c.output())
1817 .expect("ffmpeg failed to run");
1818 assert!(
1819 y4m.status.success(),
1820 "ffmpeg fixture: {}",
1821 String::from_utf8_lossy(&y4m.stderr)
1822 );
1823 let out = run_with_stdin(
1824 Command::new(aomenc_path())
1825 .args([
1826 "--codec=av1",
1827 "--passes=1",
1828 "--end-usage=q",
1829 &format!("--cq-level={cq}"),
1830 "--cpu-used=0",
1831 "--threads=1",
1832 "--row-mt=0",
1833 "--sb-size=64",
1834 "--min-partition-size=4",
1835 "--max-partition-size=8",
1836 // Below 8x8 only PARTITION_NONE/SPLIT are decodable (HORZ/VERT
1837 // need a real rectangular transform, see the module doc above);
1838 // disabling rect partitions entirely -- not just AB -- keeps
1839 // aomenc from picking the still-refused HORZ/VERT arms almost
1840 // every attempt (round 2 measured ~90% HORZ/VERT-below-8x8
1841 // refusals with --enable-ab-partitions=0 alone).
1842 "--enable-rect-partitions=0",
1843 "--enable-ab-partitions=0",
1844 "--enable-1to4-partitions=1",
1845 "--enable-palette=0",
1846 "--enable-intrabc=0",
1847 "--enable-restoration=0",
1848 "--enable-cdef=0",
1849 "--loopfilter-control=0",
1850 // use_ref_frame_mvs (temporal MV projection) is unimplemented in
1851 // mvstack; this is a key-frame-only fixture, but keep it off for
1852 // safety against a run that emits a second frame.
1853 "--enable-ref-frame-mvs=0",
1854 "--limit=1",
1855 "--obu",
1856 "-o",
1857 "-",
1858 "-",
1859 ])
1860 .args(tile_args),
1861 &y4m.stdout,
1862 );
1863 if !out.status.success() {
1864 refusals.push(format!(
1865 "seed={seed} cq={cq}: aomenc itself refused the fixture"
1866 ));
1867 continue;
1868 }
1869 let stream = out.stdout;
1870 let before = decode::sub8_split_hits();
1871 let tiles_before = decode::tile_hits();
1872 let frames = match decode_stream(&stream) {
1873 Ok(frames) => frames,
1874 Err(e) => {
1875 // Only a named refusal ("unsupported: ...") is a skip
1876 // reason; any other decode error is this decoder failing.
1877 let msg = e.to_string();
1878 assert!(
1879 msg.starts_with("unsupported: "),
1880 "decode error that is not a named refusal \
1881 (seed={seed} cq={cq} tiles={tile_args:?}): {msg}"
1882 );
1883 refusals.push(format!("seed={seed} cq={cq}: {msg}"));
1884 continue;
1885 }
1886 };
1887 // gate-blind-to-feature: a tile arm must actually decode more
1888 // than one tile, not merely carry `tile_info.cols > 1`.
1889 assert!(
1890 tile_args.is_empty() || decode::tile_hits() - tiles_before >= 2,
1891 "tiles={tile_args:?} decoded only {} tile(s) (seed={seed} cq={cq})",
1892 decode::tile_hits() - tiles_before
1893 );
1894 if decode::sub8_split_hits() == before {
1895 refusals.push(format!(
1896 "seed={seed} cq={cq}: decoded, but no block read a real PARTITION_SPLIT below 8x8"
1897 ));
1898 continue;
1899 }
1900 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
1901 assert_eq!(
1902 frames[0].y, ffmpeg_frames[0].y,
1903 "luma vs ffmpeg (seed={seed} cq={cq})"
1904 );
1905 assert_eq!(
1906 frames[0].u, ffmpeg_frames[0].u,
1907 "U vs ffmpeg (seed={seed} cq={cq})"
1908 );
1909 assert_eq!(
1910 frames[0].v, ffmpeg_frames[0].v,
1911 "V vs ffmpeg (seed={seed} cq={cq})"
1912 );
1913 fired_runs += 1;
1914 if fired_runs >= 4 {
1915 break;
1916 }
1917 }
1918 assert!(
1919 fired_runs >= 4,
1920 "fewer than 4 firing+pixel-exact runs out of 40 attempts \
1921 ({width}x{height} tiles={tile_args:?}):\n{}",
1922 refusals.join("\n")
1923 );
1924 }
1925 }
1926
1927 /// lane-tx4x8: `--enable-rect-partitions=1` with `--min-partition-size=4
1928 /// --max-partition-size=8` on fine-detail noisy gradients makes aomenc
1929 /// pick `PARTITION_VERT`/`PARTITION_HORZ` at the 8x8 level -- two
1930 /// `BLOCK_4X8`/`BLOCK_8X4` leaves, the last sub-8x8 shape this decoder
1931 /// refused (it needed a real `TX_4X8`/`TX_8X4`: rect scan, 32-position
1932 /// `eob_pt`, `TX_4X4` `tx_type` row over `TX_8X8` coefficient tables).
1933 /// Both [`decode::tx4x8_coded_hits`] and [`decode::tx8x4_coded_hits`] are
1934 /// hard-asserted per firing attempt so neither orientation can ride along
1935 /// on the other ([[gate-blind-to-feature]]), and only leaves that coded
1936 /// REAL coefficients count -- a skipped leaf never runs the transform.
1937 /// Arms: 8-bit 16x16, an 8-bit `--tile-columns=1` 128x16 (the mi-granular
1938 /// mode maps are per tile), and a 10-bit 16x16 -- 16-pixel fixtures, for
1939 /// the reason the comment inside the loop gives.
1940 #[test]
1941 fn a_real_aomenc_stream_with_a_sub8_rect_leaf_decodes_pixel_exact() {
1942 const NAME: &str = "a_real_aomenc_stream_with_a_sub8_rect_leaf_decodes_pixel_exact";
1943 if !have_ffmpeg() {
1944 eprintln!("SKIP {NAME}: no ffmpeg");
1945 return;
1946 }
1947 if !have_aomenc() {
1948 let msg = format!("no aomenc at {}", aomenc_path().display());
1949 assert!(
1950 std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none(),
1951 "EC_AV1_REQUIRE_AOMENC is set but {msg}"
1952 );
1953 eprintln!("SKIP {NAME}: {msg}");
1954 return;
1955 }
1956 // 16-pixel-tall/wide fixtures on purpose: at 64x64 EVERY attempt
1957 // dies on a 16x16-LEVEL rect refusal belonging to other lanes
1958 // ("a HORZ/VERT intra strip with a split transform", "a coded
1959 // (non-skip) HORZ/VERT rect strip below 16x16", "a HORZ_A/HORZ_B/
1960 // VERT_A partition below 16x16") -- `--max-partition-size=8` does
1961 // NOT stop aomenc coding a 16x16 as two 16x8 strips, measured
1962 // 39/40 attempts refused. A 16x16 frame is one 16x16 block, so the
1963 // encoder either splits it to 8x8s (this lane's path) or codes it
1964 // whole; measured 12/12 attempts decoding, 3/12 with BOTH
1965 // orientations coded.
1966 for (width, height, tile_args, bit_depth) in [
1967 (16usize, 16usize, &[][..], 8u8),
1968 (128usize, 16usize, &["--tile-columns=1"][..], 8u8),
1969 (16usize, 16usize, &[][..], 10u8),
1970 ] {
1971 let mut refusals = Vec::new();
1972 let mut fired_runs = 0u32;
1973 let mut split_tx = 0usize;
1974 for attempt in 0..40u32 {
1975 let seed = 300 + attempt;
1976 let cq = 6 + (attempt % 4) * 2;
1977 let pix_fmt = if bit_depth == 10 {
1978 "yuv420p10le"
1979 } else {
1980 "yuv420p"
1981 };
1982 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
1983 .args([
1984 "-v",
1985 "error",
1986 "-f",
1987 "lavfi",
1988 "-i",
1989 &format!("testsrc2=size={width}x{height}:rate=25"),
1990 "-vf",
1991 &format!("noise=alls=40:allf=t:all_seed={seed},format={pix_fmt}"),
1992 "-strict",
1993 "-1",
1994 "-t",
1995 "0.04",
1996 "-f",
1997 "yuv4mpegpipe",
1998 "-",
1999 ])
2000 .stdin(Stdio::null())
2001 .stdout(Stdio::piped())
2002 .stderr(Stdio::piped()), None, |c| c.output())
2003 .expect("ffmpeg failed to run");
2004 assert!(
2005 y4m.status.success(),
2006 "ffmpeg fixture: {}",
2007 String::from_utf8_lossy(&y4m.stderr)
2008 );
2009 let out = run_with_stdin(
2010 Command::new(aomenc_path())
2011 .args([
2012 "--codec=av1",
2013 "--passes=1",
2014 "--end-usage=q",
2015 &format!("--cq-level={cq}"),
2016 "--cpu-used=0",
2017 "--threads=1",
2018 "--row-mt=0",
2019 "--sb-size=64",
2020 "--min-partition-size=4",
2021 "--max-partition-size=8",
2022 // The tool under test: rect partitions ON, at a size
2023 // where the only rect shapes are 4x8 and 8x4.
2024 "--enable-rect-partitions=1",
2025 "--enable-ab-partitions=0",
2026 "--enable-1to4-partitions=0",
2027 "--enable-palette=0",
2028 "--enable-intrabc=0",
2029 "--enable-restoration=0",
2030 "--enable-cdef=0",
2031 "--loopfilter-control=0",
2032 "--enable-ref-frame-mvs=0",
2033 // Filter intra on a 4x8/8x4 leaf is refused by name
2034 // (`predict_filter_intra` is square-only in this
2035 // decoder, the same refusal the 16x16-level strips
2036 // carry); with it on, that refusal -- not this
2037 // lane's path -- is what most attempts hit.
2038 "--enable-filter-intra=0",
2039 "--limit=1",
2040 "--obu",
2041 "-o",
2042 "-",
2043 "-",
2044 ])
2045 .args(if bit_depth == 10 {
2046 &["--input-bit-depth=10", "--bit-depth=10"][..]
2047 } else {
2048 &[][..]
2049 })
2050 .args(tile_args),
2051 &y4m.stdout,
2052 );
2053 if !out.status.success() {
2054 refusals.push(format!(
2055 "seed={seed} cq={cq}: aomenc itself refused the fixture"
2056 ));
2057 continue;
2058 }
2059 let stream = out.stdout;
2060 let vert_before = decode::tx4x8_coded_hits();
2061 let horz_before = decode::tx8x4_coded_hits();
2062 let split_before = decode::rect8_split_tx_hits();
2063 let tiles_before = decode::tile_hits();
2064 let frames = match decode_stream(&stream) {
2065 Ok(frames) => frames,
2066 Err(e) => {
2067 let msg = e.to_string();
2068 assert!(
2069 msg.starts_with("unsupported: "),
2070 "decode error that is not a named refusal \
2071 (seed={seed} cq={cq} depth={bit_depth} tiles={tile_args:?}): {msg}"
2072 );
2073 refusals.push(format!("seed={seed} cq={cq}: {msg}"));
2074 continue;
2075 }
2076 };
2077 assert!(
2078 tile_args.is_empty() || decode::tile_hits() - tiles_before >= 2,
2079 "tiles={tile_args:?} decoded only {} tile(s) (seed={seed} cq={cq})",
2080 decode::tile_hits() - tiles_before
2081 );
2082 let vert = decode::tx4x8_coded_hits() - vert_before;
2083 let horz = decode::tx8x4_coded_hits() - horz_before;
2084 if vert == 0 || horz == 0 {
2085 refusals.push(format!(
2086 "seed={seed} cq={cq}: decoded, but coded 4x8={vert} 8x4={horz} leaves"
2087 ));
2088 continue;
2089 }
2090 let ffmpeg_frames = if bit_depth == 10 {
2091 ffmpeg_decode_sequence_10bit(&stream, width, height, 1)
2092 } else {
2093 ffmpeg_decode_sequence(&stream, width, height, 1)
2094 };
2095 assert_eq!(
2096 frames[0].y, ffmpeg_frames[0].y,
2097 "luma vs ffmpeg (seed={seed} cq={cq} depth={bit_depth} tiles={tile_args:?})"
2098 );
2099 assert_eq!(
2100 frames[0].u, ffmpeg_frames[0].u,
2101 "U vs ffmpeg (seed={seed} cq={cq} depth={bit_depth})"
2102 );
2103 assert_eq!(
2104 frames[0].v, ffmpeg_frames[0].v,
2105 "V vs ffmpeg (seed={seed} cq={cq} depth={bit_depth})"
2106 );
2107 fired_runs += 1;
2108 split_tx += decode::rect8_split_tx_hits() - split_before;
2109 if fired_runs >= 4 {
2110 break;
2111 }
2112 }
2113 assert!(
2114 fired_runs >= 4,
2115 "fewer than 4 firing+pixel-exact runs out of 40 attempts \
2116 ({width}x{height} depth={bit_depth} tiles={tile_args:?}):\n{}",
2117 refusals.join("\n")
2118 );
2119 // aomenc's default `--enable-tx-size-search=1` makes TX_MODE_SELECT
2120 // the frame's tx mode, so every sub-8x8 rect leaf carries a
2121 // `tx_depth` symbol; depth 1 (two 4x4 transform units predicted one
2122 // after the other) is the half of that path a whole-leaf transform
2123 // would silently get wrong, so the gate proves it fired.
2124 assert!(
2125 split_tx > 0,
2126 "no sub-8x8 rect leaf used a split (depth-1) transform in the \
2127 {fired_runs} pixel-exact runs ({width}x{height} depth={bit_depth})"
2128 );
2129 }
2130 }
2131
2132 /// lane-fi8 r1: the sub8 rect-leaf gate above with the tool under test
2133 /// turned ON (`--enable-filter-intra=1`, appended AFTER the base recipe
2134 /// -- aomenc takes the FIRST occurrence of a repeated flag, so the base
2135 /// recipe below carries no `--enable-filter-intra` at all). A DC_PRED
2136 /// `BLOCK_4X8`/`BLOCK_8X4` leaf carries a `use_filter_intra` flag
2137 /// (`av1_filter_intra_allowed_bsize` is "both sides <= 32"), which this
2138 /// decoder read from `BLOCK_4X4`'s CDF row until this round -- the same
2139 /// VALUE, a different interval, so it desynced a block or two later
2140 /// ([[wrong-alphabet-same-value]]) -- and then refused the prediction by
2141 /// name. Per attempt, only runs whose [`decode::filter_intra_rect_sub8_hits`]
2142 /// delta is nonzero AND whose three planes match ffmpeg count; the wider
2143 /// `filter_intra_rect_hits` would be satisfied by a 16x8 strip and prove
2144 /// nothing about these shapes. Arms cover both transform depths
2145 /// (`--enable-tx-size-search=1`, where a leaf may split into two 4x4
2146 /// units each predicted from the previous one's reconstruction, and `=0`,
2147 /// one whole-leaf transform) and both bit depths.
2148 #[test]
2149 fn a_real_aomenc_stream_with_filter_intra_on_a_sub8_rect_leaf_decodes_pixel_exact() {
2150 const NAME: &str =
2151 "a_real_aomenc_stream_with_filter_intra_on_a_sub8_rect_leaf_decodes_pixel_exact";
2152 if !have_ffmpeg() {
2153 eprintln!("SKIP {NAME}: no ffmpeg");
2154 return;
2155 }
2156 if !have_aomenc() {
2157 let msg = format!("no aomenc at {}", aomenc_path().display());
2158 assert!(
2159 std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none(),
2160 "EC_AV1_REQUIRE_AOMENC is set but {msg}"
2161 );
2162 eprintln!("SKIP {NAME}: {msg}");
2163 return;
2164 }
2165 let (width, height) = (16usize, 16usize);
2166 for (tx_search, bit_depth) in [("1", 8u8), ("0", 8u8), ("1", 10u8)] {
2167 let mut refusals = Vec::new();
2168 let mut fired_runs = 0u32;
2169 let mut fi_leaves = 0usize;
2170 let mut split_tx = 0usize;
2171 for attempt in 0..80u32 {
2172 let seed = 300 + attempt;
2173 let cq = 6 + (attempt % 8) * 6;
2174 let pix_fmt = if bit_depth == 10 {
2175 "yuv420p10le"
2176 } else {
2177 "yuv420p"
2178 };
2179 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
2180 .args([
2181 "-v",
2182 "error",
2183 "-f",
2184 "lavfi",
2185 "-i",
2186 &format!("testsrc2=size={width}x{height}:rate=25"),
2187 "-vf",
2188 &format!("noise=alls=40:allf=t:all_seed={seed},format={pix_fmt}"),
2189 "-strict",
2190 "-1",
2191 "-t",
2192 "0.04",
2193 "-f",
2194 "yuv4mpegpipe",
2195 "-",
2196 ])
2197 .stdin(Stdio::null())
2198 .stdout(Stdio::piped())
2199 .stderr(Stdio::piped()), None, |c| c.output())
2200 .expect("ffmpeg failed to run");
2201 assert!(
2202 y4m.status.success(),
2203 "ffmpeg fixture: {}",
2204 String::from_utf8_lossy(&y4m.stderr)
2205 );
2206 let out = run_with_stdin(
2207 Command::new(aomenc_path())
2208 .args([
2209 "--codec=av1",
2210 "--passes=1",
2211 "--end-usage=q",
2212 &format!("--cq-level={cq}"),
2213 "--cpu-used=0",
2214 "--threads=1",
2215 "--row-mt=0",
2216 "--sb-size=64",
2217 "--min-partition-size=4",
2218 "--max-partition-size=8",
2219 "--enable-rect-partitions=1",
2220 "--enable-ab-partitions=0",
2221 "--enable-1to4-partitions=0",
2222 "--enable-palette=0",
2223 "--enable-intrabc=0",
2224 "--enable-restoration=0",
2225 "--enable-cdef=0",
2226 "--loopfilter-control=0",
2227 "--enable-ref-frame-mvs=0",
2228 // The tools under test, first occurrence in the
2229 // command line (aomenc keeps the first).
2230 "--enable-filter-intra=1",
2231 &format!("--enable-tx-size-search={tx_search}"),
2232 "--limit=1",
2233 "--obu",
2234 "-o",
2235 "-",
2236 "-",
2237 ])
2238 .args(if bit_depth == 10 {
2239 &["--input-bit-depth=10", "--bit-depth=10"][..]
2240 } else {
2241 &[][..]
2242 }),
2243 &y4m.stdout,
2244 );
2245 if !out.status.success() {
2246 refusals.push(format!("seed={seed} cq={cq}: aomenc itself refused"));
2247 continue;
2248 }
2249 let stream = out.stdout;
2250 let fi_before = decode::filter_intra_rect_sub8_hits();
2251 let split_before = decode::rect8_split_tx_hits();
2252 let frames = match decode_stream(&stream) {
2253 Ok(frames) => frames,
2254 Err(e) => {
2255 let msg = e.to_string();
2256 assert!(
2257 msg.starts_with("unsupported: "),
2258 "decode error that is not a named refusal \
2259 (seed={seed} cq={cq} depth={bit_depth} txs={tx_search}): {msg}"
2260 );
2261 refusals.push(format!("seed={seed} cq={cq}: {msg}"));
2262 continue;
2263 }
2264 };
2265 let fi = decode::filter_intra_rect_sub8_hits() - fi_before;
2266 if fi == 0 {
2267 refusals.push(format!(
2268 "seed={seed} cq={cq}: decoded, but no 4x8/8x4 leaf used filter intra"
2269 ));
2270 continue;
2271 }
2272 let ffmpeg_frames = if bit_depth == 10 {
2273 ffmpeg_decode_sequence_10bit(&stream, width, height, 1)
2274 } else {
2275 ffmpeg_decode_sequence(&stream, width, height, 1)
2276 };
2277 assert_eq!(
2278 frames[0].y, ffmpeg_frames[0].y,
2279 "luma vs ffmpeg (seed={seed} cq={cq} depth={bit_depth} txs={tx_search})"
2280 );
2281 assert_eq!(
2282 frames[0].u, ffmpeg_frames[0].u,
2283 "U vs ffmpeg (seed={seed} cq={cq} depth={bit_depth} txs={tx_search})"
2284 );
2285 assert_eq!(
2286 frames[0].v, ffmpeg_frames[0].v,
2287 "V vs ffmpeg (seed={seed} cq={cq} depth={bit_depth} txs={tx_search})"
2288 );
2289 fired_runs += 1;
2290 fi_leaves += fi;
2291 split_tx += decode::rect8_split_tx_hits() - split_before;
2292 if fired_runs >= 3 {
2293 break;
2294 }
2295 }
2296 assert!(
2297 fired_runs >= 3,
2298 "{NAME}: fewer than 3 firing+pixel-exact runs out of 80 attempts \
2299 (depth={bit_depth} txs={tx_search}), {fi_leaves} filter-intra sub8 leaves \
2300 seen:\n{}",
2301 refusals.join("\n")
2302 );
2303 if tx_search == "1" {
2304 assert!(
2305 split_tx > 0,
2306 "{NAME}: no sub-8x8 rect leaf used a split (depth-1) transform in the \
2307 {fired_runs} pixel-exact runs (depth={bit_depth})"
2308 );
2309 }
2310 eprintln!(
2311 "{NAME}: depth={bit_depth} txs={tx_search} {fired_runs} pixel-exact runs, \
2312 {fi_leaves} filter-intra 4x8/8x4 leaves, split_tx={split_tx}"
2313 );
2314 }
2315 }
2316
2317 /// lane-tx4x8 r3 ([[enumerate-table-domain]], [[tool-disabled-in-every-gate]]):
2318 /// a 16x8/8x16 intra strip whose DIRECTIONAL mode reads above-right or
2319 /// below-left samples. Which of those the decoder may read is
2320 /// `Reach::of_rect`'s answer, and until this round `rect_reach_tables`
2321 /// had no 16x8 row at all -- every 16x8 strip read libaom's `has_tr_32x16`
2322 /// row instead of `has_tr_16x8`, wrong at 10 of the 21 reachable
2323 /// superblock positions for above-right and 7 for below-left. No gate saw
2324 /// it: the sibling strip gate (`coded_rect_strip_below_16x16`) runs with
2325 /// smooth/paeth/DC modes, which never read past the block, so the wrong
2326 /// bit changed no pixel there.
2327 ///
2328 /// So this gate turns every non-directional intra tool OFF
2329 /// (`--enable-smooth-intra=0 --enable-paeth-intra=0
2330 /// --enable-filter-intra=0`) at `--min-partition-size=8
2331 /// --max-partition-size=16 --enable-rect-partitions=1`, and counts, per
2332 /// attempt, the 16x8/8x16 strips whose prediction actually reached past
2333 /// their own width or height ([`decode::rect_strip_reach_hits`], recorded
2334 /// in the predictor's edge fetch). An attempt only counts when that
2335 /// counter moved AND the frame is pixel-exact against ffmpeg.
2336 ///
2337 /// Un-ignored 2026-09-04: the sub-16x16 coded-strip and AB-partition refusals that blocked it are gone and the gate passes. When it was blocked: the 16x16-level strip decoder
2338 /// refuses every NON-SKIP 16x8/8x16 strip ("a coded (non-skip) HORZ/VERT
2339 /// rect strip below 16x16", `decode.rs`), and that is what real streams
2340 /// contain -- measured on this exact recipe, 38 of 40 attempts died on
2341 /// that refusal and 2 on a sub-16x16 AB partition, at cq 30/45/58 and at
2342 /// `--min-partition-size=16` (which yields no 16x8 at all, aomenc bounds a
2343 /// rect shape by its smaller side). The table routing is also pinned by the domain test
2344 /// `encode::tests::every_rect_shape_reaches_what_libaom_says_over_the_whole_superblock`
2345 /// against libaom's own `has_tr_*`/`has_bl_*` arrays.
2346 #[test]
2347 fn a_directional_16x8_strip_reads_the_right_above_right_samples() {
2348 const NAME: &str = "a_directional_16x8_strip_reads_the_right_above_right_samples";
2349 if !have_ffmpeg() {
2350 eprintln!("SKIP {NAME}: no ffmpeg");
2351 return;
2352 }
2353 if !have_aomenc() {
2354 let msg = format!("no aomenc at {}", aomenc_path().display());
2355 assert!(
2356 std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none(),
2357 "EC_AV1_REQUIRE_AOMENC is set but {msg}"
2358 );
2359 eprintln!("SKIP {NAME}: {msg}");
2360 return;
2361 }
2362 // 64x16, not 64x64: a 16-tall frame is a single row of 16x16 blocks,
2363 // so a HORZ arm is a 16x8 strip at column 0..3 of the superblock --
2364 // exactly the positions whose `has_tr_16x8`/`has_bl_16x8` bit the old
2365 // routing got wrong -- while the frame is too short for aomenc to
2366 // build the deep sub-16x16 partitions other lanes still refuse. It
2367 // must also be WIDER than one block: at width 16 the block is the
2368 // frame, and `x + bw < width` kills above-right before any table.
2369 for (width, height, bit_depth) in [(64usize, 16usize, 8u8), (64, 16, 10u8)] {
2370 let mut refusals = Vec::new();
2371 let mut fired_runs = 0u32;
2372 let mut reach_hits = 0usize;
2373 for attempt in 0..40u32 {
2374 let seed = 700 + attempt;
2375 // Coarse quantisers on lightly-dithered content: fine detail
2376 // at low cq makes aomenc build the sub-16x16 partitions other
2377 // lanes refuse, and 40/40 attempts died there.
2378 let cq = 45 + (attempt % 4);
2379 let half = height / 2;
2380 let pix_fmt = if bit_depth == 10 {
2381 "yuv420p10le"
2382 } else {
2383 "yuv420p"
2384 };
2385 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
2386 .args([
2387 "-v",
2388 "error",
2389 "-f",
2390 "lavfi",
2391 "-i",
2392 &format!("testsrc2=size={width}x{half}:rate=25"),
2393 "-f",
2394 "lavfi",
2395 "-i",
2396 &format!("color=c=gray:s={width}x{half}:rate=25"),
2397 "-filter_complex",
2398 &format!(
2399 "[0]noise=alls=8:allf=t:all_seed={seed}[t];[t][1]vstack,\
2400 format={pix_fmt}"
2401 ),
2402 "-strict",
2403 "-1",
2404 "-t",
2405 "0.04",
2406 "-f",
2407 "yuv4mpegpipe",
2408 "-",
2409 ])
2410 .stdin(Stdio::null())
2411 .stdout(Stdio::piped())
2412 .stderr(Stdio::piped()), None, |c| c.output())
2413 .expect("ffmpeg failed to run");
2414 assert!(
2415 y4m.status.success(),
2416 "ffmpeg fixture: {}",
2417 String::from_utf8_lossy(&y4m.stderr)
2418 );
2419 let out = run_with_stdin(
2420 Command::new(aomenc_path())
2421 .args([
2422 "--codec=av1",
2423 "--passes=1",
2424 "--end-usage=q",
2425 &format!("--cq-level={cq}"),
2426 "--cpu-used=0",
2427 "--threads=1",
2428 "--row-mt=0",
2429 "--sb-size=64",
2430 // The tool under test: 16x8/8x16 strips, predicted by
2431 // a mode that reads beyond the block.
2432 // aomenc bounds a RECT shape by its smaller side, so
2433 // `--min-partition-size=16` yields no 16x8 at all
2434 // (measured: 0 strips in 40 attempts); 8 is the
2435 // smallest value that lets a 16x16 split HORZ/VERT.
2436 "--min-partition-size=8",
2437 "--max-partition-size=16",
2438 // Largest transform per block: a split (depth-1) rect
2439 // strip is a named refusal of another lane, and it
2440 // ate every attempt while it was on.
2441 "--enable-tx-size-search=0",
2442 "--enable-rect-partitions=1",
2443 "--enable-directional-intra=1",
2444 "--enable-smooth-intra=0",
2445 "--enable-paeth-intra=0",
2446 "--enable-filter-intra=0",
2447 "--enable-ab-partitions=0",
2448 "--enable-1to4-partitions=0",
2449 "--enable-palette=0",
2450 "--enable-intrabc=0",
2451 "--enable-restoration=0",
2452 "--enable-cdef=0",
2453 "--loopfilter-control=0",
2454 "--enable-ref-frame-mvs=0",
2455 "--limit=1",
2456 "--obu",
2457 "-o",
2458 "-",
2459 "-",
2460 ])
2461 .args(if bit_depth == 10 {
2462 &["--input-bit-depth=10", "--bit-depth=10"][..]
2463 } else {
2464 &[][..]
2465 }),
2466 &y4m.stdout,
2467 );
2468 if !out.status.success() {
2469 refusals.push(format!(
2470 "seed={seed} cq={cq}: aomenc itself refused the fixture"
2471 ));
2472 continue;
2473 }
2474 let stream = out.stdout;
2475 let reach_before = decode::rect_strip_reach_hits();
2476 let pred_before = decode::rect_strip_pred_hits();
2477 let frames = match decode_stream(&stream) {
2478 Ok(frames) => frames,
2479 Err(e) => {
2480 let msg = e.to_string();
2481 assert!(
2482 msg.starts_with("unsupported: "),
2483 "decode error that is not a named refusal \
2484 (seed={seed} cq={cq} depth={bit_depth}): {msg}"
2485 );
2486 refusals.push(format!("seed={seed} cq={cq}: {msg}"));
2487 continue;
2488 }
2489 };
2490 let reached = decode::rect_strip_reach_hits() - reach_before;
2491 let predicted = decode::rect_strip_pred_hits() - pred_before;
2492 if predicted == 0 {
2493 refusals.push(format!(
2494 "seed={seed} cq={cq}: decoded, but no 16x8/8x16 strip in the frame"
2495 ));
2496 continue;
2497 }
2498 let ffmpeg_frames = if bit_depth == 10 {
2499 ffmpeg_decode_sequence_10bit(&stream, width, height, 1)
2500 } else {
2501 ffmpeg_decode_sequence(&stream, width, height, 1)
2502 };
2503 assert_eq!(
2504 frames[0].y, ffmpeg_frames[0].y,
2505 "luma vs ffmpeg (seed={seed} cq={cq} depth={bit_depth}, {predicted} strips, \
2506 {reached} of them reaching)"
2507 );
2508 assert_eq!(
2509 frames[0].u, ffmpeg_frames[0].u,
2510 "U vs ffmpeg (seed={seed} cq={cq} depth={bit_depth})"
2511 );
2512 assert_eq!(
2513 frames[0].v, ffmpeg_frames[0].v,
2514 "V vs ffmpeg (seed={seed} cq={cq} depth={bit_depth})"
2515 );
2516 fired_runs += 1;
2517 reach_hits += reached;
2518 if fired_runs >= 4 {
2519 break;
2520 }
2521 }
2522 assert!(
2523 fired_runs >= 4,
2524 "fewer than 4 firing+pixel-exact runs out of 40 attempts \
2525 ({width}x{height} depth={bit_depth}, {reach_hits} reaching strips):\n{}",
2526 refusals.join("\n")
2527 );
2528 }
2529 }
2530
2531 /// lane-av1golden7 r9's decisive fixture: a real aomenc stream (seed 59,
2532 /// `--tune-content=film`, GOLDEN_FRAME firing downstream) whose frame-0
2533 /// *intra keyframe* mismatched ffmpeg on 3855/4096 luma pixels -- traced
2534 /// to `apply_grain=true` (spec 7.18.3 grain synthesis, now implemented in
2535 /// `crate::film_grain`), entirely unrelated to GOLDEN_FRAME or frame
2536 /// ordering. Frames beyond 0 in this fixture hit an unrelated, pre-existing
2537 /// gap (`decode_inter_block`'s GOLDEN_FRAME MC path, lane-av1golden7's own
2538 /// `golden7-forwarding-mismatch.obu`), so this test truncates the stream to
2539 /// the sequence header + frame-0 OBUs only -- exactly the span the
2540 /// mismatch was traced to -- rather than reaching into `decode.rs`/`mc.rs`
2541 /// to widen MC support, which is out of this lane's scope.
2542 #[test]
2543 fn a_real_aomenc_stream_with_film_grain_decodes_pixel_exact() {
2544 if !have_ffmpeg() {
2545 eprintln!("SKIP a_real_aomenc_stream_with_film_grain_decodes_pixel_exact: no ffmpeg");
2546 return;
2547 }
2548 // lane-av1pinslive r3: this gate was LIVE while reading a GITIGNORED
2549 // pin through a `concat!` literal and `.unwrap()` -- a clean checkout
2550 // with no runner library PANICKED here rather than skipping. The bytes
2551 // are now committed at `crates/ec-av1/fixtures/golden6-mismatch.obu`
2552 // (452 bytes; sha256
2553 // `c56909b98542192b03f3a945e153475aa57a58a1586bf166513297296cb225b3`,
2554 // recovered byte-for-byte from the runner library).
2555 let data = require_pin(
2556 &std::env::var("EC_AV1_GATE_DUMP_PIN")
2557 .map(std::path::PathBuf::from)
2558 .unwrap_or_else(|_| crate_pin("golden6-mismatch.obu")),
2559 "golden6-mismatch.obu",
2560 );
2561 // Truncate right after the first `Frame` OBU (the key frame): every
2562 // byte up to there is sequence header + frame-0, which is a complete,
2563 // independently decodable single-frame stream.
2564 let mut parser = Av1Parser::new();
2565 let mut pos = 0usize;
2566 let mut frame0_end = None;
2567 while pos < data.len() {
2568 let obu = parser.parse_obu(&data[pos..]).unwrap();
2569 pos += obu.total_size;
2570 if matches!(obu.kind, ObuKind::Frame(..)) {
2571 frame0_end = Some(pos);
2572 break;
2573 }
2574 }
2575 let data = &data[..frame0_end.expect("fixture has at least one frame OBU")];
2576 let (width, height) = (64usize, 64usize);
2577 let ffmpeg_frames = ffmpeg_decode_sequence(data, width, height, 1);
2578 let decoded = decode_stream(data).unwrap();
2579 assert_eq!(decoded.len(), 1);
2580 let (got, want) = (&decoded[0], &ffmpeg_frames[0]);
2581 assert_eq!(got.y, want.y, "frame 0 luma vs ffmpeg (film grain)");
2582 assert_eq!(got.u, want.u, "frame 0 U vs ffmpeg (film grain)");
2583 assert_eq!(got.v, want.v, "frame 0 V vs ffmpeg (film grain)");
2584 }
2585
2586 /// A real-encoder sweep, not just the one pinned fixture above
2587 /// (fixture-proves-symbol-not-signal class): several fresh
2588 /// `--tune-content=film` draws at different seeds/content, each decoded
2589 /// pixel-exact against ffmpeg's own AV1 decoder (which synthesizes grain
2590 /// by default -- confirmed via `ffmpeg -h decoder=av1`, no
2591 /// `-export_side_data`/grain-disable flag is passed anywhere in this
2592 /// file).
2593 #[test]
2594 fn real_aomenc_film_grain_streams_decode_pixel_exact() {
2595 if !have_ffmpeg() {
2596 eprintln!("SKIP real_aomenc_film_grain_streams_decode_pixel_exact: no ffmpeg");
2597 return;
2598 }
2599 if !have_aomenc() {
2600 eprintln!("SKIP real_aomenc_film_grain_streams_decode_pixel_exact: no aomenc");
2601 return;
2602 }
2603 let (width, height) = (64usize, 64usize);
2604 for seed in [1u64, 2, 3] {
2605 let dir = std::env::temp_dir().join(format!(
2606 "ec-av1-filmgrain-gate-{}-{seed}",
2607 std::process::id()
2608 ));
2609 std::fs::create_dir_all(&dir).unwrap();
2610 let yuv_path = dir.join("in.yuv");
2611 let obu_path = dir.join("out.obu");
2612 let frames = 3usize;
2613 let luma = width * height;
2614 let chroma = luma / 4;
2615 let mut yuv = Vec::with_capacity((luma + 2 * chroma) * frames);
2616 for f in 0..frames {
2617 let card = panned_test_card(width, height, ((f as i32 + seed as i32) * 5) as i64);
2618 yuv.extend(card.y.iter().map(|&v| v as u8));
2619 yuv.extend(card.u.iter().map(|&v| v as u8));
2620 yuv.extend(card.v.iter().map(|&v| v as u8));
2621 }
2622 std::fs::write(&yuv_path, &yuv).unwrap();
2623 let status = Command::new(aomenc_path())
2624 .args([
2625 &format!("--width={width}"),
2626 &format!("--height={height}"),
2627 "--input-bit-depth=8",
2628 "--bit-depth=8",
2629 "--fps=25/1",
2630 &format!("--limit={frames}"),
2631 // The full constraint set of the forwarding/golden gates,
2632 // so the streams stay inside this decoder's supported
2633 // envelope and the gate isolates grain synthesis alone;
2634 // `--tune-content=film` is the one flag under test (it
2635 // enables apply_grain).
2636 "--codec=av1",
2637 "--passes=1",
2638 "--end-usage=q",
2639 "--cq-level=32",
2640 "--cpu-used=0",
2641 "--lag-in-frames=0",
2642 "--auto-alt-ref=0",
2643 "--kf-max-dist=1000",
2644 "--threads=1",
2645 "--row-mt=0",
2646 "--max-reference-frames=3",
2647 "--reduced-reference-set=1",
2648 "--enable-warped-motion=0",
2649 "--enable-obmc=0",
2650 "--enable-masked-comp=0",
2651 "--enable-interintra-comp=0",
2652 "--enable-dist-wtd-comp=0",
2653 "--enable-diff-wtd-comp=0",
2654 "--enable-onesided-comp=0",
2655 "--enable-interintra-wedge=0",
2656 "--enable-smooth-interintra=0",
2657 "--enable-rect-partitions=0",
2658 "--enable-ab-partitions=0",
2659 "--enable-1to4-partitions=0",
2660 "--enable-filter-intra=0",
2661 "--enable-smooth-intra=0",
2662 "--enable-paeth-intra=0",
2663 "--enable-directional-intra=0",
2664 "--enable-angle-delta=0",
2665 "--enable-tx-size-search=0",
2666 "--enable-cdef=0",
2667 "--enable-restoration=0",
2668 "--max-partition-size=32",
2669 "--min-partition-size=32",
2670 "--enable-palette=0",
2671 "--enable-intrabc=0",
2672 "--enable-cfl-intra=0",
2673 // Temporal MV projection (`use_ref_frame_mvs`) has no
2674 // decode path here (`mvstack.rs`'s documented corner-cut:
2675 // `zero_mv_ctx` and the mode-context GLOBALMV_OFFSET bit
2676 // are always computed as if it were off) -- this gate
2677 // isolates grain synthesis, so it must stay inside that
2678 // envelope like every other feature disabled above, not
2679 // silently decode a wrong mode context. Root cause of
2680 // this test's frame-1 mismatch: aomenc turns
2681 // `use_ref_frame_mvs` on by default once order hints are
2682 // enabled, unrelated to `--tune-content=film`.
2683 "--enable-ref-frame-mvs=0",
2684 "--tune-content=film",
2685 "--obu",
2686 "-o",
2687 ])
2688 .arg(&obu_path)
2689 .arg(&yuv_path)
2690 .stdout(Stdio::null())
2691 .stderr(Stdio::null())
2692 .status()
2693 .expect("aomenc failed to start");
2694 assert!(status.success(), "aomenc failed for seed {seed}");
2695 let encoded = std::fs::read(&obu_path).unwrap();
2696 let _ = std::fs::remove_dir_all(&dir);
2697
2698 let mut parser = ec_av1_syntax::Av1Parser::new();
2699 let mut pos = 0usize;
2700 let mut saw_grain = false;
2701 while pos < encoded.len() {
2702 let obu = parser.parse_obu(&encoded[pos..]).unwrap();
2703 pos += obu.total_size;
2704 if let ec_av1_syntax::ObuKind::Frame(header, _) = obu.kind
2705 && header.film_grain.apply_grain
2706 {
2707 saw_grain = true;
2708 }
2709 }
2710 assert!(saw_grain, "seed {seed}: aomenc did not turn on apply_grain");
2711
2712 let ffmpeg_frames = ffmpeg_decode_sequence(&encoded, width, height, frames);
2713 let decoded = decode_stream(&encoded).unwrap();
2714 assert_eq!(decoded.len(), frames, "seed {seed}");
2715 for (i, (got, want)) in decoded.iter().zip(&ffmpeg_frames).enumerate() {
2716 assert_eq!(got.y, want.y, "seed {seed} frame {i} luma vs ffmpeg");
2717 assert_eq!(got.u, want.u, "seed {seed} frame {i} U vs ffmpeg");
2718 assert_eq!(got.v, want.v, "seed {seed} frame {i} V vs ffmpeg");
2719 }
2720 }
2721 }
2722
2723 /// lane-tiles r3/r7: a real two-tile-column aomenc key frame, decoded
2724 /// through [`decode_key_frame_tile_with_cdfs`] directly with the whole
2725 /// `tiles: &[&[u8]]` list -- `decode_stream`'s `cols > 1 || rows > 1`
2726 /// refusal (this file, ~line 292) still fires for any stream this wide,
2727 /// so this gate bypasses it on purpose to prove the per-tile loop r2
2728 /// landed (fresh `SymbolDecoder`/CDF copy per tile, `Neighbours::start_tile`,
2729 /// `PlaneBuf::set_tile_origin`) actually decodes both tiles pixel-exact
2730 /// before that refusal is lifted. 128x64 is exactly two 64x64
2731 /// superblocks wide with `--tile-columns=1` (`TileCols=2`), so tile 1 is
2732 /// also the frame's own right edge -- the known gap (`PlaneBuf`'s
2733 /// tile_x0/tile_y0 only clip left/top reach, not a non-last column's
2734 /// right-edge reach) does not apply to this fixture; it would to a
2735 /// 3+-column one, proven separately by the four-tile-column gate below.
2736 /// r7: `--loopfilter-control=0` REMOVED per the charter -- `PlaneBuf`'s
2737 /// `tile_x1`/`tile_y1` clamps now receive real values at every call site
2738 /// (r6's `set_tile_origin` sweep), so this gate now proves real
2739 /// deblocking across the tile boundary too, not just decode with it off.
2740 /// Tile count itself is a structural aomenc param, not
2741 /// RD-dependent content, but this decoder's chroma smooth/paeth gap
2742 /// (`decode.rs` "a smooth or paeth chroma mode (round 2)", unrelated to
2743 /// tiles, pre-dating this lane) is content-dependent -- no aomenc flag
2744 /// disables UV-only smooth/paeth search, so a small seed sweep is
2745 /// needed the same way the sibling `a_real_aomenc_stream_with_*` gates
2746 /// retry past unrelated named refusals (every refusal in this crate is
2747 /// prefixed `"AV1 tile"` regardless of category, so unlike the sibling
2748 /// gates' `warp`/`obmc`/`interintra` banned lists there is no
2749 /// tile-specific substring to forbid here -- `matched > 0` plus the
2750 /// hard `tile_hits > 1`/pixel-exact asserts on any actual decode are
2751 /// the real proof).
2752 #[test]
2753 fn a_real_aomenc_stream_with_two_tile_columns_decodes_pixel_exact() {
2754 let fctx = &crate::decode::FrameCtx::new();
2755 const NAME: &str = "a_real_aomenc_stream_with_two_tile_columns_decodes_pixel_exact";
2756 if !have_ffmpeg() {
2757 eprintln!("SKIP {NAME}: no ffmpeg");
2758 return;
2759 }
2760 if !have_aomenc() {
2761 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
2762 return;
2763 }
2764 let (width, height) = (128usize, 64usize);
2765 let mut matched = 0u32;
2766 let mut named_refusals = 0u32;
2767 // lane-modectx r1: luma `kf_y_mode` neighbour reads whose coarse
2768 // fallback band held a previous tile's mode at a tile edge. Measured 0
2769 // -- `above_mode` is cleared per tile and `left_mode` per superblock
2770 // row -- and that is exactly why the coarse fallback is safe where
2771 // lane-mtfix's chroma one was not. Accumulated only for attempts that
2772 // then compared pixel-exact (class counter-from-refused-stream).
2773 let mut mode_edge_leaks = 0usize;
2774 for attempt in 0..20u32 {
2775 let seed = 42 + attempt;
2776 let source = gradients_source(seed, width, height, "duration=0.04:rate=25");
2777 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
2778 .args([
2779 "-v",
2780 "error",
2781 "-f",
2782 "lavfi",
2783 "-i",
2784 &source,
2785 "-pix_fmt",
2786 "yuv420p",
2787 "-f",
2788 "yuv4mpegpipe",
2789 "-",
2790 ])
2791 .stdin(Stdio::null())
2792 .stdout(Stdio::piped())
2793 .stderr(Stdio::piped()), None, |c| c.output())
2794 .expect("ffmpeg failed to run");
2795 assert!(
2796 y4m.status.success(),
2797 "ffmpeg fixture: {}",
2798 String::from_utf8_lossy(&y4m.stderr)
2799 );
2800 let out = run_with_stdin(
2801 Command::new(aomenc_path()).args([
2802 "--codec=av1",
2803 "--passes=1",
2804 "--end-usage=q",
2805 "--cq-level=45",
2806 "--cpu-used=0",
2807 "--limit=1",
2808 "--kf-max-dist=1000",
2809 "--threads=1",
2810 "--row-mt=0",
2811 "--tile-columns=1",
2812 "--tile-rows=0",
2813 // This decoder hardcodes SB_MI=16 (64px) superblocks
2814 // everywhere (`decode.rs`'s sb128 dead-end, ledger
2815 // `av1-superblock-contexts`) -- without this, aomenc's
2816 // own default 128x128 superblock makes 128x64 exactly
2817 // ONE superblock wide, so `--tile-columns=1` has nothing
2818 // to split and `cols` comes back 1.
2819 "--sb-size=64",
2820 // Deblocking crosses tile boundaries by default (spec
2821 // `loop_filter_across_tiles_enabled`); `PlaneBuf`'s
2822 // tile_x0/tile_y0 origin only ever clips a tile's own
2823 // left/top reach (r2/r3's documented known gap), so a
2824 // non-last tile column's right-edge deblock would read
2825 // into the next tile's still-undecoded/differently-
2826 // origined samples. Off here since deblocking itself is
2827 // not what this gate is proving.
2828 "--enable-rect-partitions=0",
2829 "--enable-ab-partitions=0",
2830 "--enable-1to4-partitions=0",
2831 "--enable-filter-intra=0",
2832 "--enable-smooth-intra=0",
2833 "--enable-paeth-intra=0",
2834 "--enable-directional-intra=0",
2835 "--enable-angle-delta=0",
2836 "--enable-tx-size-search=0",
2837 "--enable-cdef=0",
2838 "--enable-restoration=0",
2839 "--max-partition-size=32",
2840 "--min-partition-size=32",
2841 "--enable-palette=0",
2842 "--enable-intrabc=0",
2843 "--enable-cfl-intra=0",
2844 "--obu",
2845 "-o",
2846 "-",
2847 "-",
2848 ]),
2849 &y4m.stdout,
2850 );
2851 assert!(
2852 out.status.success(),
2853 "aomenc refused the fixture: {}",
2854 String::from_utf8_lossy(&out.stderr)
2855 );
2856 let stream = out.stdout;
2857
2858 // Parse the stream ourselves (rather than `decode_stream`, whose
2859 // multi-tile refusal is exactly what this gate exists to run
2860 // ahead of) to reach the real `Frame` OBU's `tile_info` and its
2861 // full `Vec<Tile>` -- `Av1Parser::parse_obu` already locates
2862 // every tile in a multi-tile tile group (`parse_tile_group`), it
2863 // is only `decode_stream` that ever narrows this to
2864 // `tiles.first()`.
2865 let mut parser = Av1Parser::new();
2866 let mut pos = 0usize;
2867 let mut frame = None;
2868 while pos < stream.len() {
2869 let obu_offset = pos;
2870 let obu = parser.parse_obu(&stream[pos..]).unwrap();
2871 pos += obu.total_size;
2872 if let ObuKind::Frame(header, tiles) = obu.kind {
2873 frame = Some((header, tiles, obu_offset));
2874 break;
2875 }
2876 }
2877 let (header, tiles, obu_offset) = frame.expect("stream has a Frame OBU");
2878 assert!(
2879 header.tile_info.cols > 1,
2880 "{NAME}: aomenc did not actually split into >1 tile column (cols={}, seed {seed})",
2881 header.tile_info.cols
2882 );
2883 assert_eq!(
2884 tiles.len(),
2885 header.tile_info.cols as usize,
2886 "{NAME}: expected one tile per column (seed {seed})"
2887 );
2888 // `Tile::offset` is relative to the buffer `parse_obu` was
2889 // handed (`&stream[pos..]` at the time this OBU was parsed), so
2890 // it needs `obu_offset` added back -- the same adjustment
2891 // `decode_stream` makes for its own single-tile slice above.
2892 let tile_bufs: Vec<&[u8]> = tiles
2893 .iter()
2894 .map(|t| &stream[obu_offset + t.offset..obu_offset + t.offset + t.size])
2895 .collect();
2896
2897 let enable_filter_intra = parser
2898 .sequence_header()
2899 .is_some_and(|seq| seq.enable_filter_intra);
2900 let enable_edge_filter = parser
2901 .sequence_header()
2902 .is_some_and(|seq| seq.enable_intra_edge_filter);
2903
2904 let before = crate::decode::tile_hits();
2905 let before_edge = crate::decode::mode_tile_edge_coarse_leaks();
2906 let picture = match decode_key_frame_tile_with_cdfs(
2907 &tile_bufs,
2908 &header.tile_info,
2909 header.mi_cols,
2910 header.mi_rows,
2911 header.quantization.base_q_idx,
2912 crate::quant::QuantDeltas {
2913 y_dc: i32::from(header.quantization.delta_q_y_dc),
2914 u_dc: i32::from(header.quantization.delta_q_u_dc),
2915 u_ac: i32::from(header.quantization.delta_q_u_ac),
2916 v_dc: i32::from(header.quantization.delta_q_v_dc),
2917 v_ac: i32::from(header.quantization.delta_q_v_ac),
2918 },
2919 header.frame_width,
2920 header.frame_height,
2921 enable_filter_intra,
2922 enable_edge_filter,
2923 &header.cdef,
2924 &header.loop_filter,
2925 &header.loop_restoration,
2926 None,
2927 header.tx_mode == TxMode::Select,
2928 header.reduced_tx_set,
2929 header.allow_screen_content_tools,
2930 header.allow_intrabc,
2931 header.delta,
2932 fctx,
2933 ) {
2934 Err(e) => {
2935 let msg = e.to_string();
2936 assert!(
2937 msg.contains("unsupported"),
2938 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
2939 );
2940 named_refusals += 1;
2941 eprintln!("seed {seed} refusal: {msg}");
2942 continue;
2943 }
2944 Ok((picture, _end_cdfs)) => picture,
2945 };
2946 let hits = crate::decode::tile_hits() - before;
2947 assert!(
2948 hits > 1,
2949 "{NAME}: tile_hits delta was {hits}, expected >1 -- both tiles must actually \
2950 decode, not just tile 0 (seed {seed})"
2951 );
2952
2953 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
2954 assert_eq!(
2955 picture.y, ffmpeg_frames[0].y,
2956 "{NAME}: luma vs ffmpeg (seed {seed})"
2957 );
2958 assert_eq!(
2959 picture.u, ffmpeg_frames[0].u,
2960 "{NAME}: U vs ffmpeg (seed {seed})"
2961 );
2962 assert_eq!(
2963 picture.v, ffmpeg_frames[0].v,
2964 "{NAME}: V vs ffmpeg (seed {seed})"
2965 );
2966 mode_edge_leaks += crate::decode::mode_tile_edge_coarse_leaks() - before_edge;
2967 matched += 1;
2968 }
2969 assert!(
2970 matched > 0,
2971 "{NAME}: every attempt refused ({named_refusals} refusals); the gate never decoded \
2972 a two-tile-column stream"
2973 );
2974 assert_eq!(
2975 mode_edge_leaks, 0,
2976 "{NAME}: a luma mode neighbour read at a tile edge saw a NON-DC coarse band -- the \
2977 per-tile `above_mode` / per-superblock-row `left_mode` reset that makes the coarse \
2978 fallback safe has regressed"
2979 );
2980 eprintln!(
2981 "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20, \
2982 {mode_edge_leaks} tile-edge coarse leaks"
2983 );
2984 }
2985
2986 /// lane-tiles r8 stage 1: the same bypass-the-refusal pattern as the
2987 /// two-tile-column gate above, this time for tile ROWS -- `decode_stream`
2988 /// still refuses any `tile_info.rows > 1` stream, so this gate calls
2989 /// [`decode_key_frame_tile_with_cdfs`] directly to prove the underlying
2990 /// per-tile loop (already row/col-generic: `tile_num / tile_info.cols`
2991 /// gives the row, `mi_row_starts`/`set_tile_origin`'s `y0`/`y1` are
2992 /// exactly symmetric with the column gate's `x0`/`x1`) actually decodes
2993 /// both tile rows pixel-exact before the refusal is lifted. 64x128 is
2994 /// one 64px superblock wide and two tall with `--tile-rows=1`
2995 /// (`TileRows=2`, `--tile-columns=0` keeps `cols=1` so only the row axis
2996 /// is under test). Loop filter is left ON (no
2997 /// `--loopfilter-control=0`) per the charter -- deblocking crosses tile
2998 /// row boundaries by spec default exactly as it crosses column ones, and
2999 /// `deblock_plane` runs once over the whole decoded picture after every
3000 /// tile is in, with no tile-axis distinction, so there is no reason to
3001 /// expect the row boundary to behave differently from the column one r7
3002 /// already proved -- this gate is what actually proves it either way.
3003 #[test]
3004 fn a_real_aomenc_stream_with_two_tile_rows_decodes_pixel_exact() {
3005 let fctx = &crate::decode::FrameCtx::new();
3006 const NAME: &str = "a_real_aomenc_stream_with_two_tile_rows_decodes_pixel_exact";
3007 if !have_ffmpeg() {
3008 eprintln!("SKIP {NAME}: no ffmpeg");
3009 return;
3010 }
3011 if !have_aomenc() {
3012 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
3013 return;
3014 }
3015 let (width, height) = (64usize, 128usize);
3016 let mut matched = 0u32;
3017 let mut named_refusals = 0u32;
3018 for attempt in 0..20u32 {
3019 let seed = 42 + attempt;
3020 let source = gradients_source(seed, width, height, "duration=0.04:rate=25");
3021 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
3022 .args([
3023 "-v",
3024 "error",
3025 "-f",
3026 "lavfi",
3027 "-i",
3028 &source,
3029 "-pix_fmt",
3030 "yuv420p",
3031 "-f",
3032 "yuv4mpegpipe",
3033 "-",
3034 ])
3035 .stdin(Stdio::null())
3036 .stdout(Stdio::piped())
3037 .stderr(Stdio::piped()), None, |c| c.output())
3038 .expect("ffmpeg failed to run");
3039 assert!(
3040 y4m.status.success(),
3041 "ffmpeg fixture: {}",
3042 String::from_utf8_lossy(&y4m.stderr)
3043 );
3044 let out = run_with_stdin(
3045 Command::new(aomenc_path()).args([
3046 "--codec=av1",
3047 "--passes=1",
3048 "--end-usage=q",
3049 "--cq-level=45",
3050 "--cpu-used=0",
3051 "--limit=1",
3052 "--kf-max-dist=1000",
3053 "--threads=1",
3054 "--row-mt=0",
3055 "--tile-columns=0",
3056 "--tile-rows=1",
3057 // This decoder hardcodes SB_MI=16 (64px) superblocks
3058 // everywhere; without this aomenc's own default 128x128
3059 // superblock makes 64x128 exactly ONE superblock tall,
3060 // so `--tile-rows=1` has nothing to split.
3061 "--sb-size=64",
3062 "--enable-rect-partitions=0",
3063 "--enable-ab-partitions=0",
3064 "--enable-1to4-partitions=0",
3065 "--enable-filter-intra=0",
3066 "--enable-smooth-intra=0",
3067 "--enable-paeth-intra=0",
3068 "--enable-directional-intra=0",
3069 "--enable-angle-delta=0",
3070 "--enable-tx-size-search=0",
3071 "--enable-cdef=0",
3072 "--enable-restoration=0",
3073 "--max-partition-size=32",
3074 "--min-partition-size=32",
3075 "--enable-palette=0",
3076 "--enable-intrabc=0",
3077 "--enable-cfl-intra=0",
3078 "--obu",
3079 "-o",
3080 "-",
3081 "-",
3082 ]),
3083 &y4m.stdout,
3084 );
3085 assert!(
3086 out.status.success(),
3087 "aomenc refused the fixture: {}",
3088 String::from_utf8_lossy(&out.stderr)
3089 );
3090 let stream = out.stdout;
3091
3092 let mut parser = Av1Parser::new();
3093 let mut pos = 0usize;
3094 let mut frame = None;
3095 while pos < stream.len() {
3096 let obu_offset = pos;
3097 let obu = parser.parse_obu(&stream[pos..]).unwrap();
3098 pos += obu.total_size;
3099 if let ObuKind::Frame(header, tiles) = obu.kind {
3100 frame = Some((header, tiles, obu_offset));
3101 break;
3102 }
3103 }
3104 let (header, tiles, obu_offset) = frame.expect("stream has a Frame OBU");
3105 assert!(
3106 header.tile_info.rows > 1,
3107 "{NAME}: aomenc did not actually split into >1 tile row (rows={}, seed {seed})",
3108 header.tile_info.rows
3109 );
3110 assert_eq!(
3111 tiles.len(),
3112 header.tile_info.rows as usize,
3113 "{NAME}: expected one tile per row (cols=1, seed {seed})"
3114 );
3115 let tile_bufs: Vec<&[u8]> = tiles
3116 .iter()
3117 .map(|t| &stream[obu_offset + t.offset..obu_offset + t.offset + t.size])
3118 .collect();
3119
3120 let enable_filter_intra = parser
3121 .sequence_header()
3122 .is_some_and(|seq| seq.enable_filter_intra);
3123 let enable_edge_filter = parser
3124 .sequence_header()
3125 .is_some_and(|seq| seq.enable_intra_edge_filter);
3126
3127 let before = crate::decode::tile_hits();
3128 let picture = match decode_key_frame_tile_with_cdfs(
3129 &tile_bufs,
3130 &header.tile_info,
3131 header.mi_cols,
3132 header.mi_rows,
3133 header.quantization.base_q_idx,
3134 crate::quant::QuantDeltas {
3135 y_dc: i32::from(header.quantization.delta_q_y_dc),
3136 u_dc: i32::from(header.quantization.delta_q_u_dc),
3137 u_ac: i32::from(header.quantization.delta_q_u_ac),
3138 v_dc: i32::from(header.quantization.delta_q_v_dc),
3139 v_ac: i32::from(header.quantization.delta_q_v_ac),
3140 },
3141 header.frame_width,
3142 header.frame_height,
3143 enable_filter_intra,
3144 enable_edge_filter,
3145 &header.cdef,
3146 &header.loop_filter,
3147 &header.loop_restoration,
3148 None,
3149 header.tx_mode == TxMode::Select,
3150 header.reduced_tx_set,
3151 header.allow_screen_content_tools,
3152 header.allow_intrabc,
3153 header.delta,
3154 fctx,
3155 ) {
3156 Err(e) => {
3157 let msg = e.to_string();
3158 assert!(
3159 msg.contains("unsupported"),
3160 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
3161 );
3162 named_refusals += 1;
3163 eprintln!("seed {seed} refusal: {msg}");
3164 continue;
3165 }
3166 Ok((picture, _end_cdfs)) => picture,
3167 };
3168 let hits = crate::decode::tile_hits() - before;
3169 assert!(
3170 hits > 1,
3171 "{NAME}: tile_hits delta was {hits}, expected >1 -- both tile rows must actually \
3172 decode, not just tile 0 (seed {seed})"
3173 );
3174
3175 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
3176 assert_eq!(
3177 picture.y, ffmpeg_frames[0].y,
3178 "{NAME}: luma vs ffmpeg (seed {seed})"
3179 );
3180 assert_eq!(
3181 picture.u, ffmpeg_frames[0].u,
3182 "{NAME}: U vs ffmpeg (seed {seed})"
3183 );
3184 assert_eq!(
3185 picture.v, ffmpeg_frames[0].v,
3186 "{NAME}: V vs ffmpeg (seed {seed})"
3187 );
3188 matched += 1;
3189 }
3190 assert!(
3191 matched > 0,
3192 "{NAME}: every attempt refused ({named_refusals} refusals); the gate never decoded \
3193 a two-tile-row stream"
3194 );
3195 eprintln!(
3196 "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20"
3197 );
3198 }
3199
3200 /// lane-tiles r8 stage 2/3: the same two-tile-row stream as the bypass
3201 /// gate above, this time through `decode_stream` itself -- the entry
3202 /// point real callers use, with the `rows > 1` refusal lifted (same
3203 /// commit) so this actually reaches the tile decode instead of
3204 /// refusing by name. Loop filter ON, no `--loopfilter-control=0`.
3205 #[test]
3206 fn a_real_aomenc_stream_with_two_tile_rows_decodes_through_decode_stream() {
3207 const NAME: &str = "a_real_aomenc_stream_with_two_tile_rows_decodes_through_decode_stream";
3208 if !have_ffmpeg() {
3209 eprintln!("SKIP {NAME}: no ffmpeg");
3210 return;
3211 }
3212 if !have_aomenc() {
3213 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
3214 return;
3215 }
3216 let (width, height) = (64usize, 128usize);
3217 let mut matched = 0u32;
3218 let mut named_refusals = 0u32;
3219 for attempt in 0..20u32 {
3220 let seed = 42 + attempt;
3221 let source = gradients_source(seed, width, height, "duration=0.04:rate=25");
3222 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
3223 .args([
3224 "-v",
3225 "error",
3226 "-f",
3227 "lavfi",
3228 "-i",
3229 &source,
3230 "-pix_fmt",
3231 "yuv420p",
3232 "-f",
3233 "yuv4mpegpipe",
3234 "-",
3235 ])
3236 .stdin(Stdio::null())
3237 .stdout(Stdio::piped())
3238 .stderr(Stdio::piped()), None, |c| c.output())
3239 .expect("ffmpeg failed to run");
3240 assert!(
3241 y4m.status.success(),
3242 "ffmpeg fixture: {}",
3243 String::from_utf8_lossy(&y4m.stderr)
3244 );
3245 let out = run_with_stdin(
3246 Command::new(aomenc_path()).args([
3247 "--codec=av1",
3248 "--passes=1",
3249 "--end-usage=q",
3250 "--cq-level=45",
3251 "--cpu-used=0",
3252 "--limit=1",
3253 "--kf-max-dist=1000",
3254 "--threads=1",
3255 "--row-mt=0",
3256 "--tile-columns=0",
3257 "--tile-rows=1",
3258 "--sb-size=64",
3259 "--enable-rect-partitions=0",
3260 "--enable-ab-partitions=0",
3261 "--enable-1to4-partitions=0",
3262 "--enable-filter-intra=0",
3263 "--enable-smooth-intra=0",
3264 "--enable-paeth-intra=0",
3265 "--enable-directional-intra=0",
3266 "--enable-angle-delta=0",
3267 "--enable-tx-size-search=0",
3268 "--enable-cdef=0",
3269 "--enable-restoration=0",
3270 "--max-partition-size=32",
3271 "--min-partition-size=32",
3272 "--enable-palette=0",
3273 "--enable-intrabc=0",
3274 "--enable-cfl-intra=0",
3275 "--obu",
3276 "-o",
3277 "-",
3278 "-",
3279 ]),
3280 &y4m.stdout,
3281 );
3282 assert!(
3283 out.status.success(),
3284 "aomenc refused the fixture: {}",
3285 String::from_utf8_lossy(&out.stderr)
3286 );
3287 let stream = out.stdout;
3288
3289 let before = crate::decode::tile_hits();
3290 let pictures = match decode_stream(&stream) {
3291 Err(e) => {
3292 let msg = e.to_string();
3293 assert!(
3294 msg.contains("unsupported"),
3295 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
3296 );
3297 named_refusals += 1;
3298 eprintln!("seed {seed} refusal: {msg}");
3299 continue;
3300 }
3301 Ok(pictures) => pictures,
3302 };
3303 let hits = crate::decode::tile_hits() - before;
3304 assert!(
3305 hits > 1,
3306 "{NAME}: tile_hits delta was {hits}, expected >1 -- both tile rows must actually \
3307 decode, not just tile 0 (seed {seed})"
3308 );
3309 assert_eq!(
3310 pictures.len(),
3311 1,
3312 "{NAME}: expected exactly 1 picture (seed {seed})"
3313 );
3314
3315 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
3316 assert_eq!(
3317 pictures[0].y, ffmpeg_frames[0].y,
3318 "{NAME}: luma vs ffmpeg (seed {seed})"
3319 );
3320 assert_eq!(
3321 pictures[0].u, ffmpeg_frames[0].u,
3322 "{NAME}: U vs ffmpeg (seed {seed})"
3323 );
3324 assert_eq!(
3325 pictures[0].v, ffmpeg_frames[0].v,
3326 "{NAME}: V vs ffmpeg (seed {seed})"
3327 );
3328 matched += 1;
3329 }
3330 assert!(
3331 matched > 0,
3332 "{NAME}: every attempt refused ({named_refusals} refusals); decode_stream never \
3333 decoded a two-tile-row stream"
3334 );
3335 eprintln!(
3336 "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20"
3337 );
3338 }
3339
3340 /// lane-tiles r7: the `>2 tile columns` refusal's own capability, proven
3341 /// separately from the 2-column gate above -- `--tile-columns=2` gives
3342 /// aomenc `TileCols=4` (log2), a real non-last-column right-edge case the
3343 /// 2-column fixture cannot exercise (there tile 1 IS the frame's right
3344 /// edge). 256x64 is four 64x64 superblocks wide with `--sb-size=64`, so
3345 /// each tile column is exactly one superblock. Loop filtering stays ON
3346 /// (no `--loopfilter-control=0`) to prove the same reach-bound fix also
3347 /// covers deblocking across an *interior* tile boundary, not just the
3348 /// 2-column case's boundary-that-is-also-the-frame-edge.
3349 #[test]
3350 fn a_real_aomenc_stream_with_four_tile_columns_decodes_pixel_exact() {
3351 let fctx = &crate::decode::FrameCtx::new();
3352 const NAME: &str = "a_real_aomenc_stream_with_four_tile_columns_decodes_pixel_exact";
3353 if !have_ffmpeg() {
3354 eprintln!("SKIP {NAME}: no ffmpeg");
3355 return;
3356 }
3357 if !have_aomenc() {
3358 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
3359 return;
3360 }
3361 let (width, height) = (256usize, 64usize);
3362 let mut matched = 0u32;
3363 let mut named_refusals = 0u32;
3364 for attempt in 0..20u32 {
3365 let seed = 42 + attempt;
3366 let source = gradients_source(seed, width, height, "duration=0.04:rate=25");
3367 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
3368 .args([
3369 "-v",
3370 "error",
3371 "-f",
3372 "lavfi",
3373 "-i",
3374 &source,
3375 "-pix_fmt",
3376 "yuv420p",
3377 "-f",
3378 "yuv4mpegpipe",
3379 "-",
3380 ])
3381 .stdin(Stdio::null())
3382 .stdout(Stdio::piped())
3383 .stderr(Stdio::piped()), None, |c| c.output())
3384 .expect("ffmpeg failed to run");
3385 assert!(
3386 y4m.status.success(),
3387 "ffmpeg fixture: {}",
3388 String::from_utf8_lossy(&y4m.stderr)
3389 );
3390 let out = run_with_stdin(
3391 Command::new(aomenc_path()).args([
3392 "--codec=av1",
3393 "--passes=1",
3394 "--end-usage=q",
3395 "--cq-level=45",
3396 "--cpu-used=0",
3397 "--limit=1",
3398 "--kf-max-dist=1000",
3399 "--threads=1",
3400 "--row-mt=0",
3401 "--tile-columns=2",
3402 "--tile-rows=0",
3403 "--sb-size=64",
3404 "--enable-rect-partitions=0",
3405 "--enable-ab-partitions=0",
3406 "--enable-1to4-partitions=0",
3407 "--enable-filter-intra=0",
3408 "--enable-smooth-intra=0",
3409 "--enable-paeth-intra=0",
3410 "--enable-directional-intra=0",
3411 "--enable-angle-delta=0",
3412 "--enable-tx-size-search=0",
3413 "--enable-cdef=0",
3414 "--enable-restoration=0",
3415 "--max-partition-size=32",
3416 "--min-partition-size=32",
3417 "--enable-palette=0",
3418 "--enable-intrabc=0",
3419 "--enable-cfl-intra=0",
3420 "--obu",
3421 "-o",
3422 "-",
3423 "-",
3424 ]),
3425 &y4m.stdout,
3426 );
3427 assert!(
3428 out.status.success(),
3429 "aomenc refused the fixture: {}",
3430 String::from_utf8_lossy(&out.stderr)
3431 );
3432 let stream = out.stdout;
3433
3434 let mut parser = Av1Parser::new();
3435 let mut pos = 0usize;
3436 let mut frame = None;
3437 while pos < stream.len() {
3438 let obu_offset = pos;
3439 let obu = parser.parse_obu(&stream[pos..]).unwrap();
3440 pos += obu.total_size;
3441 if let ObuKind::Frame(header, tiles) = obu.kind {
3442 frame = Some((header, tiles, obu_offset));
3443 break;
3444 }
3445 }
3446 let (header, tiles, obu_offset) = frame.expect("stream has a Frame OBU");
3447 assert!(
3448 header.tile_info.cols > 2,
3449 "{NAME}: aomenc did not actually split into >2 tile columns (cols={}, seed {seed})",
3450 header.tile_info.cols
3451 );
3452 assert_eq!(
3453 tiles.len(),
3454 header.tile_info.cols as usize,
3455 "{NAME}: expected one tile per column (seed {seed})"
3456 );
3457 let tile_bufs: Vec<&[u8]> = tiles
3458 .iter()
3459 .map(|t| &stream[obu_offset + t.offset..obu_offset + t.offset + t.size])
3460 .collect();
3461
3462 let enable_filter_intra = parser
3463 .sequence_header()
3464 .is_some_and(|seq| seq.enable_filter_intra);
3465 let enable_edge_filter = parser
3466 .sequence_header()
3467 .is_some_and(|seq| seq.enable_intra_edge_filter);
3468
3469 let before = crate::decode::tile_hits();
3470 let picture = match decode_key_frame_tile_with_cdfs(
3471 &tile_bufs,
3472 &header.tile_info,
3473 header.mi_cols,
3474 header.mi_rows,
3475 header.quantization.base_q_idx,
3476 crate::quant::QuantDeltas {
3477 y_dc: i32::from(header.quantization.delta_q_y_dc),
3478 u_dc: i32::from(header.quantization.delta_q_u_dc),
3479 u_ac: i32::from(header.quantization.delta_q_u_ac),
3480 v_dc: i32::from(header.quantization.delta_q_v_dc),
3481 v_ac: i32::from(header.quantization.delta_q_v_ac),
3482 },
3483 header.frame_width,
3484 header.frame_height,
3485 enable_filter_intra,
3486 enable_edge_filter,
3487 &header.cdef,
3488 &header.loop_filter,
3489 &header.loop_restoration,
3490 None,
3491 header.tx_mode == TxMode::Select,
3492 header.reduced_tx_set,
3493 header.allow_screen_content_tools,
3494 header.allow_intrabc,
3495 header.delta,
3496 fctx,
3497 ) {
3498 Err(e) => {
3499 let msg = e.to_string();
3500 assert!(
3501 msg.contains("unsupported"),
3502 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
3503 );
3504 named_refusals += 1;
3505 eprintln!("seed {seed} refusal: {msg}");
3506 continue;
3507 }
3508 Ok((picture, _end_cdfs)) => picture,
3509 };
3510 let hits = crate::decode::tile_hits() - before;
3511 assert!(
3512 hits > 2,
3513 "{NAME}: tile_hits delta was {hits}, expected >2 -- all four tiles must actually \
3514 decode, not just a subset (seed {seed})"
3515 );
3516
3517 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
3518 assert_eq!(
3519 picture.y, ffmpeg_frames[0].y,
3520 "{NAME}: luma vs ffmpeg (seed {seed})"
3521 );
3522 assert_eq!(
3523 picture.u, ffmpeg_frames[0].u,
3524 "{NAME}: U vs ffmpeg (seed {seed})"
3525 );
3526 assert_eq!(
3527 picture.v, ffmpeg_frames[0].v,
3528 "{NAME}: V vs ffmpeg (seed {seed})"
3529 );
3530 matched += 1;
3531 }
3532 assert!(
3533 matched > 0,
3534 "{NAME}: every attempt refused ({named_refusals} refusals); the gate never decoded \
3535 a four-tile-column stream"
3536 );
3537 eprintln!(
3538 "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20"
3539 );
3540 }
3541
3542 /// lane-tiles r8: the tile-*row* analogue of the four-tile-column gate
3543 /// above -- `--tile-rows=2` gives aomenc `TileRows=4` (log2; uniform
3544 /// tile spacing is always a power of two, so this is the smallest count
3545 /// that has an interior row neither the top nor bottom frame edge,
3546 /// mirroring why the column gate needed 4 columns rather than 3). 64x256
3547 /// is four 64x64 superblocks tall with `--sb-size=64`, one per tile row.
3548 /// Loop filter ON, run through `decode_stream` itself since the
3549 /// `rows > 1` refusal is already lifted by this commit. Also settles a
3550 /// stale documentation claim found while writing this gate: the old
3551 /// comment above `decode_stream`'s multi-tile block said
3552 /// `context_update_tile_id != 0` was refused "further down" -- no such
3553 /// refusal exists (`decode.rs` reads `tile_info.context_update_tile_id`
3554 /// generically, never hardcoded to tile 0), and this fixture's own
3555 /// aomenc runs pick 1/2/3 as often as 0 (RD-driven tile-size heuristic),
3556 /// all 20/20 pixel-exact -- so the capability was already there,
3557 /// undocumented and unproven; hard-asserted here so the proof can't go
3558 /// unnoticed if it stops firing.
3559 #[test]
3560 fn a_real_aomenc_stream_with_four_tile_rows_decodes_pixel_exact() {
3561 const NAME: &str = "a_real_aomenc_stream_with_four_tile_rows_decodes_pixel_exact";
3562 if !have_ffmpeg() {
3563 eprintln!("SKIP {NAME}: no ffmpeg");
3564 return;
3565 }
3566 if !have_aomenc() {
3567 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
3568 return;
3569 }
3570 let (width, height) = (64usize, 256usize);
3571 let mut matched = 0u32;
3572 let mut named_refusals = 0u32;
3573 let mut saw_nonzero_context_update_tile_id = false;
3574 for attempt in 0..20u32 {
3575 let seed = 42 + attempt;
3576 let source = gradients_source(seed, width, height, "duration=0.04:rate=25");
3577 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
3578 .args([
3579 "-v",
3580 "error",
3581 "-f",
3582 "lavfi",
3583 "-i",
3584 &source,
3585 "-pix_fmt",
3586 "yuv420p",
3587 "-f",
3588 "yuv4mpegpipe",
3589 "-",
3590 ])
3591 .stdin(Stdio::null())
3592 .stdout(Stdio::piped())
3593 .stderr(Stdio::piped()), None, |c| c.output())
3594 .expect("ffmpeg failed to run");
3595 assert!(
3596 y4m.status.success(),
3597 "ffmpeg fixture: {}",
3598 String::from_utf8_lossy(&y4m.stderr)
3599 );
3600 let out = run_with_stdin(
3601 Command::new(aomenc_path()).args([
3602 "--codec=av1",
3603 "--passes=1",
3604 "--end-usage=q",
3605 "--cq-level=45",
3606 "--cpu-used=0",
3607 "--limit=1",
3608 "--kf-max-dist=1000",
3609 "--threads=1",
3610 "--row-mt=0",
3611 "--tile-columns=0",
3612 "--tile-rows=2",
3613 "--sb-size=64",
3614 "--enable-rect-partitions=0",
3615 "--enable-ab-partitions=0",
3616 "--enable-1to4-partitions=0",
3617 "--enable-filter-intra=0",
3618 "--enable-smooth-intra=0",
3619 "--enable-paeth-intra=0",
3620 "--enable-directional-intra=0",
3621 "--enable-angle-delta=0",
3622 "--enable-tx-size-search=0",
3623 "--enable-cdef=0",
3624 "--enable-restoration=0",
3625 "--max-partition-size=32",
3626 "--min-partition-size=32",
3627 "--enable-palette=0",
3628 "--enable-intrabc=0",
3629 "--enable-cfl-intra=0",
3630 "--obu",
3631 "-o",
3632 "-",
3633 "-",
3634 ]),
3635 &y4m.stdout,
3636 );
3637 assert!(
3638 out.status.success(),
3639 "aomenc refused the fixture: {}",
3640 String::from_utf8_lossy(&out.stderr)
3641 );
3642 let stream = out.stdout;
3643
3644 let mut parser = Av1Parser::new();
3645 let mut pos = 0usize;
3646 let mut rows_seen = 0u32;
3647 while pos < stream.len() {
3648 let obu = parser.parse_obu(&stream[pos..]).unwrap();
3649 pos += obu.total_size;
3650 if let ObuKind::Frame(header, _) = &obu.kind {
3651 rows_seen = header.tile_info.rows;
3652 if header.tile_info.context_update_tile_id != 0 {
3653 saw_nonzero_context_update_tile_id = true;
3654 }
3655 }
3656 }
3657 assert!(
3658 rows_seen > 2,
3659 "{NAME}: aomenc did not actually split into >2 tile rows (rows={rows_seen}, seed {seed})"
3660 );
3661
3662 let before = crate::decode::tile_hits();
3663 let pictures = match decode_stream(&stream) {
3664 Err(e) => {
3665 let msg = e.to_string();
3666 assert!(
3667 msg.contains("unsupported"),
3668 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
3669 );
3670 named_refusals += 1;
3671 eprintln!("seed {seed} refusal: {msg}");
3672 continue;
3673 }
3674 Ok(pictures) => pictures,
3675 };
3676 let hits = crate::decode::tile_hits() - before;
3677 assert!(
3678 hits > 2,
3679 "{NAME}: tile_hits delta was {hits}, expected >2 -- all four tile rows must \
3680 actually decode, not just a subset (seed {seed})"
3681 );
3682 assert_eq!(
3683 pictures.len(),
3684 1,
3685 "{NAME}: expected exactly 1 picture (seed {seed})"
3686 );
3687
3688 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
3689 assert_eq!(
3690 pictures[0].y, ffmpeg_frames[0].y,
3691 "{NAME}: luma vs ffmpeg (seed {seed})"
3692 );
3693 assert_eq!(
3694 pictures[0].u, ffmpeg_frames[0].u,
3695 "{NAME}: U vs ffmpeg (seed {seed})"
3696 );
3697 assert_eq!(
3698 pictures[0].v, ffmpeg_frames[0].v,
3699 "{NAME}: V vs ffmpeg (seed {seed})"
3700 );
3701 matched += 1;
3702 }
3703 assert!(
3704 matched > 0,
3705 "{NAME}: every attempt refused ({named_refusals} refusals); the gate never decoded \
3706 a four-tile-row stream"
3707 );
3708 assert!(
3709 saw_nonzero_context_update_tile_id,
3710 "{NAME}: every attempt named context_update_tile_id=0 -- this sweep proves nothing \
3711 about the != 0 case (see the stale-refusal note above `decode_stream`'s multi-tile \
3712 comment: aomenc's own tile-size heuristic picks it, seen 1/2/3 live in a prior probe \
3713 run of this exact fixture, so a 20-attempt window not seeing it is the gate's own bug)"
3714 );
3715 eprintln!(
3716 "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20"
3717 );
3718 }
3719
3720 /// lane-tiles r4/r7: the same real two-tile-column stream as the
3721 /// bypass gate above, this time run through `decode_stream` itself --
3722 /// the entry point real callers use. Proves the `cols > 1` refusal is
3723 /// actually lifted (not just that the underlying per-tile loop works)
3724 /// for a key frame; `--loopfilter-control=0` stays here for its own
3725 /// sake (isolating the entry-point wiring from deblocking), but r7's
3726 /// `a_real_aomenc_stream_with_four_tile_columns_decodes_pixel_exact`
3727 /// bypass gate now proves loop filtering ON across a tile boundary too,
3728 /// and the `cols > 1 && loop_filter_on` / `cols > 2` refusals this
3729 /// comment used to describe are gone from `decode_stream`.
3730 #[test]
3731 fn a_real_aomenc_stream_with_two_tile_columns_decodes_through_decode_stream() {
3732 const NAME: &str =
3733 "a_real_aomenc_stream_with_two_tile_columns_decodes_through_decode_stream";
3734 if !have_ffmpeg() {
3735 eprintln!("SKIP {NAME}: no ffmpeg");
3736 return;
3737 }
3738 if !have_aomenc() {
3739 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
3740 return;
3741 }
3742 let (width, height) = (128usize, 64usize);
3743 let mut matched = 0u32;
3744 let mut named_refusals = 0u32;
3745 for attempt in 0..20u32 {
3746 let seed = 42 + attempt;
3747 let source = gradients_source(seed, width, height, "duration=0.04:rate=25");
3748 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
3749 .args([
3750 "-v",
3751 "error",
3752 "-f",
3753 "lavfi",
3754 "-i",
3755 &source,
3756 "-pix_fmt",
3757 "yuv420p",
3758 "-f",
3759 "yuv4mpegpipe",
3760 "-",
3761 ])
3762 .stdin(Stdio::null())
3763 .stdout(Stdio::piped())
3764 .stderr(Stdio::piped()), None, |c| c.output())
3765 .expect("ffmpeg failed to run");
3766 assert!(
3767 y4m.status.success(),
3768 "ffmpeg fixture: {}",
3769 String::from_utf8_lossy(&y4m.stderr)
3770 );
3771 let out = run_with_stdin(
3772 Command::new(aomenc_path()).args([
3773 "--codec=av1",
3774 "--passes=1",
3775 "--end-usage=q",
3776 "--cq-level=45",
3777 "--cpu-used=0",
3778 "--limit=1",
3779 "--kf-max-dist=1000",
3780 "--threads=1",
3781 "--row-mt=0",
3782 "--tile-columns=1",
3783 "--tile-rows=0",
3784 "--sb-size=64",
3785 "--loopfilter-control=0",
3786 "--enable-rect-partitions=0",
3787 "--enable-ab-partitions=0",
3788 "--enable-1to4-partitions=0",
3789 "--enable-filter-intra=0",
3790 "--enable-smooth-intra=0",
3791 "--enable-paeth-intra=0",
3792 "--enable-directional-intra=0",
3793 "--enable-angle-delta=0",
3794 "--enable-tx-size-search=0",
3795 "--enable-cdef=0",
3796 "--enable-restoration=0",
3797 "--max-partition-size=32",
3798 "--min-partition-size=32",
3799 "--enable-palette=0",
3800 "--enable-intrabc=0",
3801 "--enable-cfl-intra=0",
3802 "--obu",
3803 "-o",
3804 "-",
3805 "-",
3806 ]),
3807 &y4m.stdout,
3808 );
3809 assert!(
3810 out.status.success(),
3811 "aomenc refused the fixture: {}",
3812 String::from_utf8_lossy(&out.stderr)
3813 );
3814 let stream = out.stdout;
3815
3816 let before = crate::decode::tile_hits();
3817 let pictures = match decode_stream(&stream) {
3818 Err(e) => {
3819 let msg = e.to_string();
3820 assert!(
3821 msg.contains("unsupported"),
3822 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
3823 );
3824 named_refusals += 1;
3825 eprintln!("seed {seed} refusal: {msg}");
3826 continue;
3827 }
3828 Ok(pictures) => pictures,
3829 };
3830 let hits = crate::decode::tile_hits() - before;
3831 assert!(
3832 hits > 1,
3833 "{NAME}: tile_hits delta was {hits}, expected >1 -- both tiles must actually \
3834 decode, not just tile 0 (seed {seed})"
3835 );
3836 assert_eq!(
3837 pictures.len(),
3838 1,
3839 "{NAME}: expected exactly 1 picture (seed {seed})"
3840 );
3841
3842 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
3843 assert_eq!(
3844 pictures[0].y, ffmpeg_frames[0].y,
3845 "{NAME}: luma vs ffmpeg (seed {seed})"
3846 );
3847 assert_eq!(
3848 pictures[0].u, ffmpeg_frames[0].u,
3849 "{NAME}: U vs ffmpeg (seed {seed})"
3850 );
3851 assert_eq!(
3852 pictures[0].v, ffmpeg_frames[0].v,
3853 "{NAME}: V vs ffmpeg (seed {seed})"
3854 );
3855 matched += 1;
3856 }
3857 assert!(
3858 matched > 0,
3859 "{NAME}: every attempt refused ({named_refusals} refusals); decode_stream never \
3860 decoded a two-tile-column stream"
3861 );
3862 eprintln!(
3863 "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20"
3864 );
3865 }
3866
3867 /// lane-realworld r6: r5 ported `maybe_read_delta_q`/`maybe_read_delta_lf`
3868 /// and removed the whole-frame refusal, but no fixture anywhere set
3869 /// `delta_lf_present` -- the removal was unproven. `--deltaq-mode=2`
3870 /// (`DELTA_Q_PERCEPTUAL`, checked against libaom's own
3871 /// `encodeframe.c:2192-2225`) sets `delta_q_present_flag` unconditionally
3872 /// once `base_qindex > 0` (unlike the default `--deltaq-mode=1`
3873 /// `DELTA_Q_OBJECTIVE`, which additionally requires an alt-ref-eligible
3874 /// frame and `allow_deltaq_mode`'s own RD search); `--delta-lf-mode=1`
3875 /// then ANDs `delta_lf_present_flag` on top
3876 /// (`tool_cfg->enable_deltalf_mode`, `av1_cx_iface.c:1269-1270`). 128x64
3877 /// (2 SBs; this decoder hardcodes 64px SBs) is the charter's minimum for
3878 /// a per-superblock symbol to have somewhere to differ; `--cpu-used=4`
3879 /// (not the other gates' `=0`) sidesteps the multi-SB
3880 /// HORZ_4/VERT_B-at-part64 gap the cdef gate's own comment documents
3881 /// (lane-realworld r2 dead-end, part64 only covers NONE/SPLIT). Note:
3882 /// libaom hardcodes `delta_lf_multi = DEFAULT_DELTA_LF_MULTI == 0`
3883 /// (`enums.h:73`) with no CLI flag to set it -- this gate cannot and
3884 /// does not claim to exercise this decoder's `delta_lf_multi` branch;
3885 /// only the single-plane path is gate-proven.
3886 #[test]
3887 fn a_real_aomenc_stream_with_delta_q_and_delta_lf_decodes_pixel_exact() {
3888 const NAME: &str = "a_real_aomenc_stream_with_delta_q_and_delta_lf_decodes_pixel_exact";
3889 let _gate_lock = lock_gate_counters();
3890 if !have_ffmpeg() {
3891 eprintln!("SKIP {NAME}: no ffmpeg");
3892 return;
3893 }
3894 if !have_aomenc() {
3895 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
3896 return;
3897 }
3898 let (width, height, frame_count) = (128usize, 64usize, 24usize);
3899 let mut named_refusals = 0u32;
3900 let mut matched = 0u32;
3901 let n_attempts: u32 = std::env::var("EC_DELTAQ_GATE_ATTEMPTS")
3902 .ok()
3903 .and_then(|s| s.parse().ok())
3904 .unwrap_or(40);
3905 for attempt in 0..n_attempts {
3906 let seed = 42 + attempt;
3907 let duration = frame_count as f64 / 25.0;
3908 // Mandelbrot's varying local contrast is what gives
3909 // DELTA_Q_PERCEPTUAL's per-superblock RD something to
3910 // differentiate; flat gradients risk every superblock
3911 // resolving the same delta.
3912 let source = format!(
3913 "mandelbrot=size={width}x{height}:rate=25:start_x={sx}:start_y={sy}",
3914 sx = -0.6 + 0.005 * (attempt as f64),
3915 sy = -0.4 + 0.005 * (attempt as f64)
3916 );
3917 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
3918 .args([
3919 "-v",
3920 "error",
3921 "-f",
3922 "lavfi",
3923 "-i",
3924 &source,
3925 "-t",
3926 &duration.to_string(),
3927 "-pix_fmt",
3928 "yuv420p",
3929 "-f",
3930 "yuv4mpegpipe",
3931 "-",
3932 ])
3933 .stdin(Stdio::null())
3934 .stdout(Stdio::piped())
3935 .stderr(Stdio::piped()), None, |c| c.output())
3936 .expect("ffmpeg failed to run");
3937 assert!(
3938 y4m.status.success(),
3939 "ffmpeg fixture: {}",
3940 String::from_utf8_lossy(&y4m.stderr)
3941 );
3942 let args: Vec<&str> = vec![
3943 "--codec=av1",
3944 "--passes=1",
3945 "--end-usage=q",
3946 "--cq-level=45",
3947 "--cpu-used=4",
3948 "--aq-mode=0",
3949 "--deltaq-mode=2",
3950 "--delta-lf-mode=1",
3951 "--kf-max-dist=1000",
3952 "--threads=1",
3953 "--row-mt=0",
3954 "--sb-size=64",
3955 "--auto-alt-ref=1",
3956 "--lag-in-frames=16",
3957 "--enable-fwd-kf=0",
3958 "--enable-order-hint=1",
3959 "--enable-warped-motion=1",
3960 "--enable-global-motion=0",
3961 "--enable-obmc=1",
3962 "--tune-content=default",
3963 "--enable-masked-comp=1",
3964 "--enable-dist-wtd-comp=0",
3965 "--enable-interintra-comp=1",
3966 "--enable-onesided-comp=0",
3967 "--enable-interintra-wedge=0",
3968 "--enable-smooth-interintra=1",
3969 "--enable-rect-partitions=0",
3970 "--enable-ab-partitions=0",
3971 "--enable-1to4-partitions=0",
3972 "--enable-filter-intra=0",
3973 "--enable-smooth-intra=0",
3974 "--enable-paeth-intra=0",
3975 "--enable-directional-intra=0",
3976 "--enable-angle-delta=0",
3977 "--enable-tx-size-search=0",
3978 "--enable-cdef=1",
3979 "--enable-restoration=0",
3980 "--max-partition-size=32",
3981 "--min-partition-size=32",
3982 "--enable-palette=0",
3983 "--enable-intrabc=0",
3984 "--enable-cfl-intra=0",
3985 "--enable-ref-frame-mvs=0",
3986 "--obu",
3987 "-o",
3988 "-",
3989 "-",
3990 ];
3991 let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
3992 assert!(
3993 out.status.success(),
3994 "aomenc refused the fixture: {}",
3995 String::from_utf8_lossy(&out.stderr)
3996 );
3997 let stream = out.stdout;
3998 let frames = match decode_stream(&stream) {
3999 Err(e) => {
4000 let msg = e.to_string();
4001 assert!(
4002 msg.contains("unsupported"),
4003 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
4004 );
4005 assert!(
4006 !msg.contains("delta_q") && !msg.contains("delta_lf"),
4007 "{NAME} refused on delta_q/delta_lf (seed {seed}) -- that read is ported: {msg}"
4008 );
4009 named_refusals += 1;
4010 eprintln!("seed {seed} refusal: {msg}");
4011 continue;
4012 }
4013 Ok(frames) => frames,
4014 };
4015 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
4016 assert_eq!(frames.len(), frame_count);
4017 let mismatched = frames
4018 .iter()
4019 .zip(&ffmpeg_frames)
4020 .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
4021 if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
4022 std::fs::write(&path, &stream).expect("writing pinned stream");
4023 eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
4024 }
4025 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
4026 assert_eq!(
4027 got.y, want.y,
4028 "{NAME} frame {i} luma vs ffmpeg (seed {seed})"
4029 );
4030 assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
4031 assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
4032 }
4033 // lane-hidden r2 (class gate-blind-to-hidden-frames): the same
4034 // stream again, comparing EVERY decode-order frame -- the hidden
4035 // (show_frame == 0) alt-ref frames the ffmpeg compare above
4036 // cannot see, because both sides of it emit shown frames only.
4037 let (hidden_total, hidden_n) = decode_all_frames_vs_oracle(&stream, NAME);
4038 eprintln!(
4039 "{NAME} HIDDEN: seed {seed}: {hidden_total} decode-order frames, \
4040 {hidden_n} hidden, all pixel-exact vs the oracle"
4041 );
4042 // lane-hidden r2 SECOND ARM (the recipe above is untouched):
4043 // libaom's temporal alt-ref filter absorbs this recipe's hidden
4044 // frames, so the compare above is vacuous -- re-encode the same
4045 // fixture with --arnr-maxframes=0 and compare THOSE.
4046 if let Some((arm_total, arm_hidden)) = hidden_arnr_arm(NAME, &y4m.stdout, &args) {
4047 eprintln!(
4048 "{NAME} HIDDEN-ARM(--arnr-maxframes=0): seed {seed}: {arm_total} \
4049 decode-order frames, {arm_hidden} hidden, all pixel-exact vs the oracle"
4050 );
4051 }
4052 matched += 1;
4053 }
4054 assert!(
4055 matched > 0,
4056 "{NAME}: every attempt refused on other capabilities ({named_refusals} refusals); \
4057 the gate never exercised delta_q/delta_lf"
4058 );
4059 assert!(
4060 crate::decode::delta_q_hits() > 0,
4061 "{NAME}: {matched} pixel-exact matches but zero delta_q symbol groups fired -- \
4062 the reader is unexercised"
4063 );
4064 assert!(
4065 crate::decode::delta_lf_hits() > 0,
4066 "{NAME}: {matched} pixel-exact matches but zero delta_lf symbol groups fired -- \
4067 the reader is unexercised"
4068 );
4069 eprintln!(
4070 "{NAME}: {named_refusals} other-capability refusals, {matched} pixel-exact matches \
4071 out of {n_attempts}, delta_q_hits={}, delta_lf_hits={}",
4072 crate::decode::delta_q_hits(),
4073 crate::decode::delta_lf_hits()
4074 );
4075 }
4076
4077 #[test]
4078 fn a_real_aomenc_stream_with_variance_aq_segmentation_decodes_pixel_exact() {
4079 run_segmentation_gate(
4080 "a_real_aomenc_stream_with_variance_aq_segmentation_decodes_pixel_exact",
4081 "1",
4082 8,
4083 16,
4084 &["--end-usage=q", "--cq-level=45"],
4085 );
4086 }
4087
4088 // lane-seg r1 DEFERRED: an `--aq-mode=2` (complexity AQ) twin of the gate
4089 // above. libaom only switches segmentation on for complexity AQ once the
4090 // target bits per 64x64 superblock clear `sb64_target_rate >= 256`
4091 // (`aq_complexity.c:is_sb_aq_enabled`), which needs `--end-usage=vbr`;
4092 // every VBR recipe tried (cpu-used 0 and 4, 32x32 and 64x64 fixed
4093 // partitions) makes aomenc pick partition shapes OTHER lanes still refuse
4094 // (AB below 16x16, SB-level HORZ/VERT, part32 values 4/6), so 10/10
4095 // attempts refuse before a pixel is compared. The syntax exercised would
4096 // be identical to variance AQ's (both features only ever set
4097 // `SEG_LVL_ALT_Q` via `update_map`), so this is coverage, not capability.
4098 // Unblocked by the sub-16x16 rect/AB partition lanes.
4099
4100 /// His two AV1 films are both `yuv420p10le`, so every capability lands
4101 /// with a 10-bit twin (memory `his-av1-library-is-10-bit`). KEY FRAME
4102 /// ONLY (`frame_count = 1`): a 10-bit INTER frame does not decode
4103 /// pixel-exact in this crate yet, segmentation or not -- lane-seg r1 ran
4104 /// this same recipe with `--aq-mode=0` (segmentation off entirely) and it
4105 /// still mismatched at frame 2, so the 16-frame 10-bit variant would be
4106 /// gating an unrelated pre-existing gap. Variance AQ segments the key
4107 /// frame too (`aq_variance.c`, `is_frame_aq_enabled` includes
4108 /// `frame_is_intra_only`), so this still proves the 10-bit segment-id
4109 /// read and the per-segment 10-bit dequant.
4110 #[test]
4111 fn a_real_aomenc_10bit_stream_with_aq_segmentation_decodes_pixel_exact() {
4112 run_segmentation_gate(
4113 "a_real_aomenc_10bit_stream_with_aq_segmentation_decodes_pixel_exact",
4114 "1",
4115 10,
4116 1,
4117 &["--end-usage=q", "--cq-level=45"],
4118 );
4119 }
4120
4121 /// lane-tiles r7: the gate stage 2 (r6, commit 8899fc1) shipped without
4122 /// -- a real >1-tile-column stream with a genuine INTER frame (not just
4123 /// the key-frame-only two-column gate above), decoded through
4124 /// `decode_stream` itself. Same recipe as the key-frame gate
4125 /// (`--sb-size=64`, `--tile-columns=1`, `--loopfilter-control=0`, the
4126 /// same feature-disable envelope so the gate isolates the tile loop, not
4127 /// an unrelated unimplemented mode) plus `--limit=2 --kf-max-dist=1000`
4128 /// so frame 1 is a real inter frame, and `gradients_source`'s default
4129 /// `speed=0.01` rotation (undisturbed -- not overridden by the tail)
4130 /// gives it genuine motion against frame 0, so `decode_inter_frame_tile_
4131 /// with_cdfs`'s new per-tile loop and `MiGrid`'s per-tile bound actually
4132 /// have to walk a live MV stack across the tile-column boundary, not
4133 /// just replay skip/zero-mv blocks. Bounded with `duration=0.08` (2
4134 /// frames at rate=25) per the class in ledger
4135 /// `refusal-claim-disproved-by-its-own-gate`/`gate-loader-slurps-whole-
4136 /// file` (never leave an ffmpeg/lavfi generate unbounded).
4137 #[test]
4138 fn a_real_aomenc_stream_with_two_tile_columns_and_an_inter_frame_decodes_pixel_exact() {
4139 const NAME: &str =
4140 "a_real_aomenc_stream_with_two_tile_columns_and_an_inter_frame_decodes_pixel_exact";
4141 if !have_ffmpeg() {
4142 eprintln!("SKIP {NAME}: no ffmpeg");
4143 return;
4144 }
4145 if !have_aomenc() {
4146 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
4147 return;
4148 }
4149 let (width, height) = (128usize, 64usize);
4150 let frames = 2usize;
4151 let mut matched = 0u32;
4152 let mut named_refusals = 0u32;
4153 for attempt in 0..20u32 {
4154 let seed = 42 + attempt;
4155 let source = gradients_source(seed, width, height, "duration=0.08:rate=25");
4156 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
4157 .args([
4158 "-v",
4159 "error",
4160 "-f",
4161 "lavfi",
4162 "-i",
4163 &source,
4164 "-pix_fmt",
4165 "yuv420p",
4166 "-f",
4167 "yuv4mpegpipe",
4168 "-",
4169 ])
4170 .stdin(Stdio::null())
4171 .stdout(Stdio::piped())
4172 .stderr(Stdio::piped()), None, |c| c.output())
4173 .expect("ffmpeg failed to run");
4174 assert!(
4175 y4m.status.success(),
4176 "ffmpeg fixture: {}",
4177 String::from_utf8_lossy(&y4m.stderr)
4178 );
4179 let out = run_with_stdin(
4180 Command::new(aomenc_path()).args([
4181 "--codec=av1",
4182 "--passes=1",
4183 "--end-usage=q",
4184 "--cq-level=45",
4185 "--cpu-used=0",
4186 &format!("--limit={frames}"),
4187 "--kf-max-dist=1000",
4188 "--lag-in-frames=0",
4189 "--auto-alt-ref=0",
4190 "--threads=1",
4191 "--row-mt=0",
4192 "--tile-columns=1",
4193 "--tile-rows=0",
4194 "--sb-size=64",
4195 "--loopfilter-control=0",
4196 "--max-reference-frames=3",
4197 "--reduced-reference-set=1",
4198 "--enable-warped-motion=0",
4199 "--enable-obmc=0",
4200 "--enable-masked-comp=0",
4201 "--enable-interintra-comp=0",
4202 "--enable-dist-wtd-comp=0",
4203 "--enable-diff-wtd-comp=0",
4204 "--enable-onesided-comp=0",
4205 "--enable-interintra-wedge=0",
4206 "--enable-smooth-interintra=0",
4207 "--enable-ref-frame-mvs=0",
4208 "--enable-rect-partitions=0",
4209 "--enable-ab-partitions=0",
4210 "--enable-1to4-partitions=0",
4211 "--enable-filter-intra=0",
4212 "--enable-smooth-intra=0",
4213 "--enable-paeth-intra=0",
4214 "--enable-directional-intra=0",
4215 "--enable-angle-delta=0",
4216 "--enable-tx-size-search=0",
4217 "--enable-cdef=0",
4218 "--enable-restoration=0",
4219 "--max-partition-size=32",
4220 "--min-partition-size=32",
4221 "--enable-palette=0",
4222 "--enable-intrabc=0",
4223 "--enable-cfl-intra=0",
4224 "--obu",
4225 "-o",
4226 "-",
4227 "-",
4228 ]),
4229 &y4m.stdout,
4230 );
4231 assert!(
4232 out.status.success(),
4233 "aomenc refused the fixture: {}",
4234 String::from_utf8_lossy(&out.stderr)
4235 );
4236 let stream = out.stdout;
4237
4238 // Confirm aomenc actually split into >1 tile column and that
4239 // frame 1 is a real inter frame before trusting a pixel match --
4240 // otherwise a match could mean "tiles collapsed to 1" or "frame
4241 // 1 fell back to key", not "the inter tile loop ran".
4242 let mut parser = Av1Parser::new();
4243 let mut pos = 0usize;
4244 let mut saw_multi_tile_inter = false;
4245 while pos < stream.len() {
4246 let obu = parser.parse_obu(&stream[pos..]).unwrap();
4247 pos += obu.total_size;
4248 if let ObuKind::Frame(header, _) = obu.kind
4249 && header.frame_type != FrameType::Key
4250 && header.tile_info.cols > 1
4251 {
4252 saw_multi_tile_inter = true;
4253 }
4254 }
4255 assert!(
4256 saw_multi_tile_inter,
4257 "{NAME}: seed {seed} never produced a >1-tile-column inter frame (aomenc \
4258 collapsed tiling or coded frame 1 as key)"
4259 );
4260
4261 let before = crate::decode::tile_hits();
4262 let pictures = match decode_stream(&stream) {
4263 Err(e) => {
4264 let msg = e.to_string();
4265 assert!(
4266 msg.contains("unsupported"),
4267 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
4268 );
4269 named_refusals += 1;
4270 eprintln!("seed {seed} refusal: {msg}");
4271 continue;
4272 }
4273 Ok(pictures) => pictures,
4274 };
4275 let hits = crate::decode::tile_hits() - before;
4276 assert!(
4277 hits > frames,
4278 "{NAME}: tile_hits delta was {hits}, expected > {frames} -- both tiles of both \
4279 frames must actually decode (seed {seed})"
4280 );
4281 assert_eq!(
4282 pictures.len(),
4283 frames,
4284 "{NAME}: expected {frames} pictures (seed {seed})"
4285 );
4286
4287 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames);
4288 for (i, (got, want)) in pictures.iter().zip(&ffmpeg_frames).enumerate() {
4289 assert_eq!(
4290 got.y, want.y,
4291 "{NAME}: seed {seed} frame {i} luma vs ffmpeg"
4292 );
4293 assert_eq!(got.u, want.u, "{NAME}: seed {seed} frame {i} U vs ffmpeg");
4294 assert_eq!(got.v, want.v, "{NAME}: seed {seed} frame {i} V vs ffmpeg");
4295 }
4296 matched += 1;
4297 }
4298 assert!(
4299 matched > 0,
4300 "{NAME}: every attempt refused ({named_refusals} refusals); decode_stream never \
4301 decoded a two-tile-column inter frame"
4302 );
4303 eprintln!(
4304 "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20"
4305 );
4306 }
4307
4308 /// lane-tiles r9: `--num-tile-groups` makes aomenc split one frame's
4309 /// tiles across several `OBU_TILE_GROUP`s instead of folding them into
4310 /// the single `OBU_FRAME` every other gate in this file relies on --
4311 /// verified live (`scratch_probe_num_tile_groups`, this round) to emit a
4312 /// standalone `OBU_FRAME_HEADER` (`show_existing_frame == false`)
4313 /// followed by two `OBU_TILE_GROUP` OBUs, one tile each. Before this
4314 /// round `decode_stream` had no arm for `ObuKind::TileGroup` at all (it
4315 /// fell through the catch-all `continue`, silently dropping the frame),
4316 /// and its `ObuKind::FrameHeader` arm matched *every* frame header
4317 /// unconditionally, so a standalone header was misrouted into the
4318 /// `show_existing_frame` slot lookup and returned the wrong named error
4319 /// ("a show_existing_frame header naming an empty reference slot") for a
4320 /// frame that was never a show_existing_frame header. Both are fixed
4321 /// above: the `FrameHeader` arm now checks `show_existing_frame`, and a
4322 /// `pending_header`/`pending_tiles` accumulator collects tile groups
4323 /// until the frame's `cols * rows` tiles have all arrived.
4324 #[test]
4325 fn a_real_aomenc_stream_with_several_tile_group_obus_decodes_pixel_exact() {
4326 const NAME: &str = "a_real_aomenc_stream_with_several_tile_group_obus_decodes_pixel_exact";
4327 if !have_ffmpeg() {
4328 eprintln!("SKIP {NAME}: no ffmpeg");
4329 return;
4330 }
4331 if !have_aomenc() {
4332 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
4333 return;
4334 }
4335 let (width, height) = (64usize, 128usize);
4336 let mut matched = 0u32;
4337 let mut named_refusals = 0u32;
4338 let mut saw_multiple_tile_group_obus = false;
4339 for attempt in 0..20u32 {
4340 let seed = 42 + attempt;
4341 let source = gradients_source(seed, width, height, "duration=0.04:rate=25");
4342 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
4343 .args([
4344 "-v",
4345 "error",
4346 "-f",
4347 "lavfi",
4348 "-i",
4349 &source,
4350 "-pix_fmt",
4351 "yuv420p",
4352 "-f",
4353 "yuv4mpegpipe",
4354 "-",
4355 ])
4356 .stdin(Stdio::null())
4357 .stdout(Stdio::piped())
4358 .stderr(Stdio::piped()), None, |c| c.output())
4359 .expect("ffmpeg failed to run");
4360 assert!(
4361 y4m.status.success(),
4362 "ffmpeg fixture: {}",
4363 String::from_utf8_lossy(&y4m.stderr)
4364 );
4365 let out = run_with_stdin(
4366 Command::new(aomenc_path()).args([
4367 "--codec=av1",
4368 "--passes=1",
4369 "--end-usage=q",
4370 "--cq-level=45",
4371 "--cpu-used=0",
4372 "--limit=1",
4373 "--kf-max-dist=1000",
4374 "--threads=1",
4375 "--row-mt=0",
4376 "--tile-columns=0",
4377 "--tile-rows=1",
4378 "--sb-size=64",
4379 "--num-tile-groups=4",
4380 "--loopfilter-control=0",
4381 "--enable-rect-partitions=0",
4382 "--enable-ab-partitions=0",
4383 "--enable-1to4-partitions=0",
4384 "--enable-filter-intra=0",
4385 "--enable-smooth-intra=0",
4386 "--enable-paeth-intra=0",
4387 "--enable-directional-intra=0",
4388 "--enable-angle-delta=0",
4389 "--enable-tx-size-search=0",
4390 "--enable-cdef=0",
4391 "--enable-restoration=0",
4392 "--max-partition-size=32",
4393 "--min-partition-size=32",
4394 "--enable-palette=0",
4395 "--enable-intrabc=0",
4396 "--enable-cfl-intra=0",
4397 "--obu",
4398 "-o",
4399 "-",
4400 "-",
4401 ]),
4402 &y4m.stdout,
4403 );
4404 assert!(
4405 out.status.success(),
4406 "aomenc refused the fixture: {}",
4407 String::from_utf8_lossy(&out.stderr)
4408 );
4409 let stream = out.stdout;
4410
4411 let mut probe = Av1Parser::new();
4412 let mut pos = 0usize;
4413 let mut tile_group_obus = 0u32;
4414 while pos < stream.len() {
4415 let obu = probe.parse_obu(&stream[pos..]).unwrap();
4416 pos += obu.total_size;
4417 if matches!(obu.kind, ObuKind::TileGroup(_)) {
4418 tile_group_obus += 1;
4419 }
4420 }
4421 if tile_group_obus > 1 {
4422 saw_multiple_tile_group_obus = true;
4423 }
4424
4425 let before = crate::decode::tile_hits();
4426 let pictures = match decode_stream(&stream) {
4427 Err(e) => {
4428 let msg = e.to_string();
4429 assert!(
4430 msg.contains("unsupported"),
4431 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
4432 );
4433 named_refusals += 1;
4434 eprintln!("seed {seed} refusal: {msg}");
4435 continue;
4436 }
4437 Ok(pictures) => pictures,
4438 };
4439 let hits = crate::decode::tile_hits() - before;
4440 assert!(
4441 hits > 0,
4442 "{NAME}: tile_hits delta was {hits}, expected >0 (seed {seed})"
4443 );
4444 assert_eq!(
4445 pictures.len(),
4446 1,
4447 "{NAME}: expected exactly 1 picture (seed {seed})"
4448 );
4449
4450 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
4451 assert_eq!(
4452 pictures[0].y, ffmpeg_frames[0].y,
4453 "{NAME}: luma vs ffmpeg (seed {seed})"
4454 );
4455 assert_eq!(
4456 pictures[0].u, ffmpeg_frames[0].u,
4457 "{NAME}: U vs ffmpeg (seed {seed})"
4458 );
4459 assert_eq!(
4460 pictures[0].v, ffmpeg_frames[0].v,
4461 "{NAME}: V vs ffmpeg (seed {seed})"
4462 );
4463 matched += 1;
4464 }
4465 assert!(
4466 matched > 0,
4467 "{NAME}: every attempt refused ({named_refusals} refusals); decode_stream never \
4468 decoded a several-tile-group-OBUs stream"
4469 );
4470 assert!(
4471 saw_multiple_tile_group_obus,
4472 "{NAME}: no attempt actually split into more than one OBU_TILE_GROUP -- this sweep \
4473 proves nothing about the multi-tile-group case (aomenc's --num-tile-groups is \
4474 RD/heuristic-driven, same as tile sizing)"
4475 );
4476 eprintln!(
4477 "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20"
4478 );
4479 }