forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

t06.rs4444 lines, 198.9 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-motionmode round 3: same shape as
9 /// `a_real_aomenc_stream_with_obmc_decodes_pixel_exact`, but relaxed the
10 /// `--min-partition-size=32 --max-partition-size=32` clamp (that other
11 /// gate's own doc: locked to remove partition-depth choice from the
12 /// search entirely) to `8`/`32`, to make an 8x8-leaf `OBMC_CAUSAL` pick
13 /// possible at all. Gated on [`decode::obmc_hits_8`] specifically, not
14 /// the aggregate [`decode::obmc_hits`]. Measured live (round 3, this
15 /// box): 80 attempts, 0 ever called `decode_inter_block8` at all --
16 /// `cpu-used=0`'s RD search never once splits a 16x16 down to a clean
17 /// 4-way 8x8 leaf for this smooth `gradients` fixture (large blocks
18 /// always win the RD cost there); the handful of named refusals seen
19 /// are `PARTITION_SPLIT` chosen *at* 8x8 (down to 4x4, already refused
20 /// at `decode.rs`'s `part8 != PARTITION_NONE` check) or
21 /// `allow_screen_content_tools`, neither reaching a leaf. Kept anyway
22 /// (mirrors this file's own `never_fired`-skip convention) as the
23 /// honest record of the attempt; a real 8x8 OBMC fixture needs
24 /// higher-frequency content than this gate's fixtures use, out of
25 /// round-3 budget.
26 #[test]
27 fn a_real_aomenc_stream_with_obmc_8x8_decodes_pixel_exact() {
28 const NAME: &str = "a_real_aomenc_stream_with_obmc_8x8_decodes_pixel_exact";
29 let _gate_lock = lock_gate_counters();
30 if !have_ffmpeg() {
31 eprintln!("SKIP {NAME}: no ffmpeg");
32 return;
33 }
34 if !have_aomenc() {
35 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
36 return;
37 }
38 let (width, height, frame_count) = (64usize, 64usize, 24usize);
39 let mut refusals = Vec::new();
40 let mut never_fired = 0u32;
41 let mut total_obmc8 = 0usize;
42 let n_attempts: u32 = std::env::var("EC_OBMC8_ATTEMPTS")
43 .ok()
44 .and_then(|s| s.parse().ok())
45 .unwrap_or(80);
46 for attempt in 0..n_attempts {
47 let seed = 42 + attempt % 40;
48 let duration = frame_count as f64 / 25.0;
49 // Recipe search hook: `gradients` is smooth, so aomenc's RD never
50 // splits below 16x16 and this gate never fired one 8x8 OBMC block
51 // in 45 attempts -- it "passed" by skipping (gate-blind-to-feature).
52 // EC_AV1_OBMC8_SOURCE overrides the lavfi source so a firing recipe
53 // can be searched for without a rebuild.
54 let source = std::env::var("EC_AV1_OBMC8_SOURCE").unwrap_or_else(|_| {
55 gradients_source(seed, width, height, &format!("duration={duration}:rate=25"))
56 });
57 // A source supplied through EC_AV1_OBMC8_SOURCE need not carry its
58 // own `duration=`; `-t` is the bound that always holds. Without it
59 // an endless source (`testsrc2`) fills the pipe forever and the
60 // gate hangs to its 300 s timeout.
61 let duration_arg = format!("{duration}");
62 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
63 .args([
64 "-v",
65 "error",
66 "-f",
67 "lavfi",
68 "-i",
69 &source,
70 "-t",
71 &duration_arg,
72 "-pix_fmt",
73 "yuv420p",
74 "-f",
75 "yuv4mpegpipe",
76 "-",
77 ])
78 .stdin(Stdio::null())
79 .stdout(Stdio::piped())
80 .stderr(Stdio::piped()), None, |c| c.output())
81 .expect("ffmpeg failed to run");
82 assert!(
83 y4m.status.success(),
84 "ffmpeg fixture: {}",
85 String::from_utf8_lossy(&y4m.stderr)
86 );
87 let args: Vec<&str> = vec![
88 "--codec=av1",
89 "--passes=1",
90 "--end-usage=q",
91 "--cq-level=45",
92 "--cpu-used=0",
93 "--kf-max-dist=1000",
94 "--threads=1",
95 "--row-mt=0",
96 "--auto-alt-ref=1",
97 "--lag-in-frames=16",
98 "--enable-fwd-kf=0",
99 "--enable-order-hint=1",
100 "--enable-warped-motion=0",
101 "--enable-obmc=1",
102 "--enable-masked-comp=0",
103 "--enable-interintra-comp=0",
104 "--enable-onesided-comp=0",
105 "--enable-interintra-wedge=0",
106 "--enable-smooth-interintra=0",
107 "--enable-rect-partitions=0",
108 "--enable-ab-partitions=0",
109 "--enable-1to4-partitions=0",
110 "--enable-filter-intra=0",
111 "--enable-smooth-intra=0",
112 "--enable-paeth-intra=0",
113 "--enable-directional-intra=0",
114 "--enable-angle-delta=0",
115 "--enable-tx-size-search=0",
116 "--enable-cdef=0",
117 "--enable-restoration=0",
118 "--min-partition-size=8",
119 "--max-partition-size=32",
120 "--enable-palette=0",
121 "--enable-intrabc=0",
122 "--enable-cfl-intra=0",
123 "--enable-ref-frame-mvs=0",
124 "--obu",
125 "-o",
126 "-",
127 "-",
128 ];
129 let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
130 assert!(
131 out.status.success(),
132 "aomenc refused the fixture: {}",
133 String::from_utf8_lossy(&out.stderr)
134 );
135 let stream = out.stdout;
136 let before8 = decode::obmc_hits_8();
137 let frames = match decode_stream(&stream) {
138 Err(e) => {
139 let msg = e.to_string();
140 assert!(
141 msg.contains("unsupported"),
142 "{NAME} failed outright (seed {seed}): {msg}"
143 );
144 refusals.push(format!("seed {seed}: {msg}"));
145 continue;
146 }
147 Ok(frames) => frames,
148 };
149 let fired8 = decode::obmc_hits_8() - before8;
150 total_obmc8 += fired8;
151 // class [[gate-skips-on-its-own-failure]]: a decode that succeeded
152 // is ALWAYS pixel-compared below; the hit counter only decides whether
153 // the attempt counts toward the firing total.
154 let counted = fired8 != 0;
155 if !counted {
156 never_fired += 1;
157 }
158 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
159 assert_eq!(frames.len(), frame_count);
160 let mismatched = frames
161 .iter()
162 .zip(&ffmpeg_frames)
163 .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
164 if mismatched
165 && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
166 std::fs::write(&path, &stream).expect("writing pinned stream");
167 eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
168 }
169 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
170 assert_eq!(
171 got.y, want.y,
172 "{NAME} frame {i} luma vs ffmpeg (seed {seed})"
173 );
174 assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
175 assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
176 }
177 // lane-hidden r2 (class gate-blind-to-hidden-frames): the same
178 // stream again, comparing EVERY decode-order frame -- the hidden
179 // (show_frame == 0) alt-ref frames the ffmpeg compare above
180 // cannot see, because both sides of it emit shown frames only.
181 let (hidden_total, hidden_n) = decode_all_frames_vs_oracle(&stream, NAME);
182 eprintln!(
183 "{NAME} HIDDEN: seed {seed}: {hidden_total} decode-order frames, \
184 {hidden_n} hidden, all pixel-exact vs the oracle"
185 );
186 // lane-hidden r2 SECOND ARM (the recipe above is untouched):
187 // libaom's temporal alt-ref filter absorbs this recipe's hidden
188 // frames, so the compare above is vacuous -- re-encode the same
189 // fixture with --arnr-maxframes=0 and compare THOSE.
190 if let Some((arm_total, arm_hidden)) = hidden_arnr_arm(NAME, &y4m.stdout, &args) {
191 eprintln!(
192 "{NAME} HIDDEN-ARM(--arnr-maxframes=0): seed {seed}: {arm_total} \
193 decode-order frames, {arm_hidden} hidden, all pixel-exact vs the oracle"
194 );
195 }
196 if counted {
197 eprintln!(
198 "{NAME} FIRING seed {seed}: 8x8 obmc hits {fired8} (total across attempts so far {total_obmc8})"
199 );
200 gate_buckets(NAME, 1, never_fired, refusals.len());
201 return;
202 }
203 }
204 gate_buckets(NAME, 0, never_fired, refusals.len());
205 // lane-gmaffine r2: this gate fired for three rounds only as a SKIP
206 // (gate-skips-on-its-own-failure); the 8x8 leaf is reachable now, so a
207 // sweep that never lands one firing pixel-exact attempt is a FAILURE.
208 panic!(
209 "{NAME}: {never_fired} attempts decoded but never fired an 8x8 obmc block \
210 ({total_obmc8} total 8x8 obmc hits across all attempts), and every other attempt \
211 hit a named refusal:\n{}",
212 refusals.join("\n")
213 );
214 }
215
216 /// lane-warp r5e (flipped from lane-motionmode r1's refuses-or-matches):
217 /// `--enable-warped-motion=1` streams must DECODE pixel-exact --
218 /// `av1_findSamples`/`num_proj_ref`, the 3-symbol `motion_mode` read,
219 /// the affine projection/filter, and the WARPED_CAUSAL interp-filter
220 /// derivation are all ported. A refusal naming warp, or any pixel
221 /// mismatch, fails the gate; refusals for OTHER named capabilities
222 /// (screen content tools) still skip that seed. The sweep must also
223 /// actually exercise warp (`warp_selected_hits > 0`) so a decoder that
224 /// silently stops selecting WARPED_CAUSAL cannot pass vacuously.
225 #[test]
226 fn a_real_aomenc_stream_with_warped_motion_refuses_or_matches() {
227 const NAME: &str = "a_real_aomenc_stream_with_warped_motion_refuses_or_matches";
228 let _gate_lock = lock_gate_counters();
229 if !have_ffmpeg() {
230 eprintln!("SKIP {NAME}: no ffmpeg");
231 return;
232 }
233 if !have_aomenc() {
234 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
235 return;
236 }
237 let (width, height, frame_count) = (64usize, 64usize, 24usize);
238 let mut named_refusals = 0u32;
239 let mut matched = 0u32;
240 let n_attempts: u32 = std::env::var("EC_WARP_GATE_ATTEMPTS")
241 .ok()
242 .and_then(|s| s.parse().ok())
243 .unwrap_or(40);
244 for attempt in 0..n_attempts {
245 let seed = 42 + attempt;
246 let duration = frame_count as f64 / 25.0;
247 let source =
248 gradients_source(seed, width, height, &format!("duration={duration}:rate=25"));
249 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
250 .args([
251 "-v",
252 "error",
253 "-f",
254 "lavfi",
255 "-i",
256 &source,
257 "-pix_fmt",
258 "yuv420p",
259 "-f",
260 "yuv4mpegpipe",
261 "-",
262 ])
263 .stdin(Stdio::null())
264 .stdout(Stdio::piped())
265 .stderr(Stdio::piped()), None, |c| c.output())
266 .expect("ffmpeg failed to run");
267 assert!(
268 y4m.status.success(),
269 "ffmpeg fixture: {}",
270 String::from_utf8_lossy(&y4m.stderr)
271 );
272 let args: Vec<&str> = vec![
273 "--codec=av1",
274 "--passes=1",
275 "--end-usage=q",
276 "--cq-level=45",
277 "--cpu-used=0",
278 "--kf-max-dist=1000",
279 "--threads=1",
280 "--row-mt=0",
281 "--auto-alt-ref=1",
282 "--lag-in-frames=16",
283 "--enable-fwd-kf=0",
284 "--enable-order-hint=1",
285 "--enable-warped-motion=1",
286 "--enable-obmc=1",
287 "--tune-content=default",
288 "--enable-masked-comp=0",
289 "--enable-interintra-comp=0",
290 "--enable-onesided-comp=0",
291 "--enable-interintra-wedge=0",
292 "--enable-smooth-interintra=0",
293 "--enable-rect-partitions=0",
294 "--enable-ab-partitions=0",
295 "--enable-1to4-partitions=0",
296 "--enable-filter-intra=0",
297 "--enable-smooth-intra=0",
298 "--enable-paeth-intra=0",
299 "--enable-directional-intra=0",
300 "--enable-angle-delta=0",
301 "--enable-tx-size-search=0",
302 "--enable-cdef=0",
303 "--enable-restoration=0",
304 "--max-partition-size=32",
305 "--min-partition-size=32",
306 "--enable-palette=0",
307 "--enable-intrabc=0",
308 "--enable-cfl-intra=0",
309 "--enable-ref-frame-mvs=0",
310 "--obu",
311 "-o",
312 "-",
313 "-",
314 ];
315 let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
316 assert!(
317 out.status.success(),
318 "aomenc refused the fixture: {}",
319 String::from_utf8_lossy(&out.stderr)
320 );
321 let stream = out.stdout;
322 let frames = match decode_stream(&stream) {
323 Err(e) => {
324 let msg = e.to_string();
325 assert!(
326 msg.contains("unsupported"),
327 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
328 );
329 assert!(
330 !msg.contains("warp"),
331 "{NAME} refused on warp (seed {seed}) -- warp decode is ported, this \
332 refusal must not exist: {msg}"
333 );
334 named_refusals += 1;
335 eprintln!("seed {seed} refusal (non-warp capability): {msg}");
336 continue;
337 }
338 Ok(frames) => frames,
339 };
340 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
341 assert_eq!(frames.len(), frame_count);
342 let mismatched = frames
343 .iter()
344 .zip(&ffmpeg_frames)
345 .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
346 if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
347 std::fs::write(&path, &stream).expect("writing pinned stream");
348 eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
349 }
350 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
351 assert_eq!(
352 got.y, want.y,
353 "{NAME} frame {i} luma vs ffmpeg (seed {seed})"
354 );
355 assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
356 assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
357 }
358 // lane-hidden r2 (class gate-blind-to-hidden-frames): the same
359 // stream again, comparing EVERY decode-order frame -- the hidden
360 // (show_frame == 0) alt-ref frames the ffmpeg compare above
361 // cannot see, because both sides of it emit shown frames only.
362 let (hidden_total, hidden_n) = decode_all_frames_vs_oracle(&stream, NAME);
363 eprintln!(
364 "{NAME} HIDDEN: seed {seed}: {hidden_total} decode-order frames, \
365 {hidden_n} hidden, all pixel-exact vs the oracle"
366 );
367 // lane-hidden r2 SECOND ARM (the recipe above is untouched):
368 // libaom's temporal alt-ref filter absorbs this recipe's hidden
369 // frames, so the compare above is vacuous -- re-encode the same
370 // fixture with --arnr-maxframes=0 and compare THOSE.
371 if let Some((arm_total, arm_hidden)) = hidden_arnr_arm(NAME, &y4m.stdout, &args) {
372 eprintln!(
373 "{NAME} HIDDEN-ARM(--arnr-maxframes=0): seed {seed}: {arm_total} \
374 decode-order frames, {arm_hidden} hidden, all pixel-exact vs the oracle"
375 );
376 }
377 matched += 1;
378 }
379 assert!(
380 matched > 0,
381 "{NAME}: every attempt refused on other capabilities; the gate never exercised warp"
382 );
383 assert!(
384 crate::decode::warp_selected_hits() > 0,
385 "{NAME}: {matched} matches but zero WARPED_CAUSAL blocks fired -- the gate decodes \
386 warp streams without ever selecting warp, so it proves nothing about warp"
387 );
388 eprintln!(
389 "{NAME}: {named_refusals} non-warp refusals, {matched} pixel-exact matches out of {n_attempts}, warp_selected_hits={}",
390 crate::decode::warp_selected_hits()
391 );
392 }
393
394 /// lane-superres stage 3: a real aomenc `--superres-mode=1` key-frame
395 /// sequence must decode pixel-exact vs ffmpeg/dav1d's own upscaled
396 /// output, and must actually run [`crate::superres::upscale_picture`]
397 /// (`superres_hits > 0`) -- a decoder that silently stopped upscaling
398 /// would otherwise pass vacuously (class `gate-blind-to-feature`).
399 /// `--kf-max-dist` set to the frame count keeps every frame a key
400 /// frame: inter-frame superres (a differently-scaled reference) is a
401 /// later stage of this lane, refused by name today.
402 #[test]
403 fn a_real_aomenc_superres_key_frame_sequence_decodes_pixel_exact() {
404 const NAME: &str = "a_real_aomenc_superres_key_frame_sequence_decodes_pixel_exact";
405 let _gate_lock = lock_gate_counters();
406 if !have_ffmpeg() {
407 eprintln!("SKIP {NAME}: no ffmpeg");
408 return;
409 }
410 if !have_aomenc() {
411 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
412 return;
413 }
414 let (width, height, frame_count) = (64usize, 64usize, 3usize);
415 let duration = frame_count as f64 / 25.0;
416 let source = gradients_source(7, width, height, &format!("duration={duration}:rate=25"));
417 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
418 .args([
419 "-v",
420 "error",
421 "-f",
422 "lavfi",
423 "-i",
424 &source,
425 "-pix_fmt",
426 "yuv420p",
427 "-f",
428 "yuv4mpegpipe",
429 "-",
430 ])
431 .stdin(Stdio::null())
432 .stdout(Stdio::piped())
433 .stderr(Stdio::piped()), None, |c| c.output())
434 .expect("ffmpeg failed to run");
435 assert!(
436 y4m.status.success(),
437 "ffmpeg fixture: {}",
438 String::from_utf8_lossy(&y4m.stderr)
439 );
440 let args: Vec<&str> = vec![
441 "--codec=av1",
442 "--passes=1",
443 "--end-usage=q",
444 "--cq-level=32",
445 "--cpu-used=0",
446 "--kf-max-dist=0",
447 "--threads=1",
448 "--row-mt=0",
449 "--superres-mode=1",
450 "--superres-denominator=12",
451 "--superres-kf-denominator=12",
452 "--enable-rect-partitions=0",
453 "--enable-ab-partitions=0",
454 "--enable-1to4-partitions=0",
455 "--enable-filter-intra=0",
456 "--enable-smooth-intra=0",
457 "--enable-paeth-intra=0",
458 "--enable-directional-intra=0",
459 "--enable-angle-delta=0",
460 "--enable-tx-size-search=0",
461 "--enable-cdef=0",
462 "--enable-restoration=0",
463 "--max-partition-size=32",
464 "--min-partition-size=32",
465 "--enable-palette=0",
466 "--enable-intrabc=0",
467 "--enable-cfl-intra=0",
468 "--obu",
469 "-o",
470 "-",
471 "-",
472 ];
473 let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
474 assert!(
475 out.status.success(),
476 "aomenc refused the fixture: {}",
477 String::from_utf8_lossy(&out.stderr)
478 );
479 let stream = out.stdout;
480 if let Ok(path) = std::env::var("EC_SUPERRES_STREAM_DUMP") {
481 std::fs::write(path, &stream).expect("dump stream");
482 }
483 let frames = decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME} refused: {e}"));
484 assert_eq!(frames.len(), frame_count);
485 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
486 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
487 assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg");
488 assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg");
489 assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg");
490 }
491 assert!(
492 crate::superres::superres_hits() > 0,
493 "{NAME}: matched but zero superres_hits -- the gate never actually exercised the \
494 upscaler, it proves nothing"
495 );
496 eprintln!(
497 "{NAME}: {frame_count} frames pixel-exact, superres_hits={}",
498 crate::superres::superres_hits()
499 );
500 }
501
502 /// lane-superres r10: a real aomenc key+inter `--superres-mode=1`
503 /// sequence must DECODE pixel-exact vs ffmpeg, with the frame-level
504 /// `use_superres` refusal LIFTED for inter frames -- `mc::predict_scaled`
505 /// (spec 7.11.3.3) is the only path this recipe can reach (warp/OBMC/
506 /// compound/interintra/palette/intrabc/CDEF/LR are all off, matching the
507 /// scoped refusals' own unimplemented list). A pixel match alone would
508 /// pass just as well with an unscaled reference and prove nothing
509 /// (class `gate-blind-to-feature`) -- hard-assert
510 /// `crate::mc::predict_scaled_hits() > 0` so the gate can only pass if the
511 /// scaled MC path actually ran.
512 #[test]
513 fn a_real_aomenc_key_and_inter_superres_sequence_decodes_pixel_exact() {
514 const NAME: &str = "a_real_aomenc_key_and_inter_superres_sequence_decodes_pixel_exact";
515 let _gate_lock = lock_gate_counters();
516 if !have_ffmpeg() {
517 eprintln!("SKIP {NAME}: no ffmpeg");
518 return;
519 }
520 if !have_aomenc() {
521 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
522 return;
523 }
524 let (width, height, frame_count) = (64usize, 64usize, 3usize);
525 let duration = frame_count as f64 / 25.0;
526 let source = gradients_source(11, width, height, &format!("duration={duration}:rate=25"));
527 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
528 .args([
529 "-v",
530 "error",
531 "-f",
532 "lavfi",
533 "-i",
534 &source,
535 "-pix_fmt",
536 "yuv420p",
537 "-f",
538 "yuv4mpegpipe",
539 "-",
540 ])
541 .stdin(Stdio::null())
542 .stdout(Stdio::piped())
543 .stderr(Stdio::piped()), None, |c| c.output())
544 .expect("ffmpeg failed to run");
545 assert!(
546 y4m.status.success(),
547 "ffmpeg fixture: {}",
548 String::from_utf8_lossy(&y4m.stderr)
549 );
550 let args: Vec<&str> = vec![
551 "--codec=av1",
552 "--passes=1",
553 "--end-usage=q",
554 "--cq-level=32",
555 "--cpu-used=0",
556 // `--kf-max-dist` above `frame_count` keeps only frame 0 a key
557 // frame -- frames 1/2 are the inter frames whose `use_superres`
558 // refusal this round lifts.
559 "--kf-max-dist=1000",
560 "--lag-in-frames=0",
561 "--auto-alt-ref=0",
562 "--threads=1",
563 "--row-mt=0",
564 "--sb-size=64",
565 "--superres-mode=1",
566 "--superres-denominator=12",
567 "--superres-kf-denominator=12",
568 // Forces every inter block onto the single-ref, non-warp/OBMC/
569 // interintra branch `decode_inter_block` threads `predict_scaled`
570 // through -- the only branch this round's scoped refusals leave
571 // unrefused under a scaled reference.
572 "--enable-warped-motion=0",
573 "--enable-obmc=0",
574 "--enable-masked-comp=0",
575 "--enable-interintra-comp=0",
576 "--enable-dist-wtd-comp=0",
577 "--enable-diff-wtd-comp=0",
578 "--enable-onesided-comp=0",
579 "--enable-interintra-wedge=0",
580 "--enable-smooth-interintra=0",
581 "--enable-order-hint=0",
582 "--enable-ref-frame-mvs=0",
583 "--enable-rect-partitions=0",
584 "--enable-ab-partitions=0",
585 "--enable-1to4-partitions=0",
586 "--enable-filter-intra=0",
587 "--enable-smooth-intra=0",
588 "--enable-paeth-intra=0",
589 "--enable-directional-intra=0",
590 "--enable-angle-delta=0",
591 "--enable-tx-size-search=0",
592 "--enable-cdef=0",
593 "--enable-restoration=0",
594 "--max-partition-size=32",
595 "--min-partition-size=32",
596 "--enable-palette=0",
597 "--enable-intrabc=0",
598 "--enable-cfl-intra=0",
599 "--obu",
600 "-o",
601 "-",
602 "-",
603 ];
604 let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
605 assert!(
606 out.status.success(),
607 "aomenc refused the fixture: {}",
608 String::from_utf8_lossy(&out.stderr)
609 );
610 let stream = out.stdout;
611 if let Ok(path) = std::env::var("EC_SUPERRES_INTER_STREAM_DUMP") {
612 std::fs::write(&path, &stream).expect("dump stream");
613 }
614 let frames = decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME} refused: {e}"));
615 assert_eq!(frames.len(), frame_count);
616 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
617 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
618 assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg");
619 assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg");
620 assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg");
621 }
622 assert!(
623 crate::superres::superres_hits() > 0,
624 "{NAME}: matched but zero superres_hits -- the upscaler never ran"
625 );
626 assert!(
627 crate::mc::predict_scaled_hits() > 0,
628 "{NAME}: matched but zero predict_scaled_hits -- every block took the unscaled MC \
629 path, which proves nothing about the scaled-reference code this round adds \
630 (class gate-blind-to-feature)"
631 );
632 eprintln!(
633 "{NAME}: {frame_count} frames pixel-exact, superres_hits={}, predict_scaled_hits={}",
634 crate::superres::superres_hits(),
635 crate::mc::predict_scaled_hits()
636 );
637 }
638
639 /// lane-t900 r28: the three scaled-reference (superres) refusals are
640 /// LIFTED -- an 8x8 partition leaf, a sub-8x8 inter block, and warp --
641 /// so two real `--superres-mode=1` streams whose references are all
642 /// scaled must decode PIXEL-EXACT vs ffmpeg.
643 ///
644 /// Arm A drives `--min-partition-size=4` so the split (4x4) and rect
645 /// (8x4/4x8) sub-8x8 readers and the 8x8 leaf all run over a scaled
646 /// reference; arm B turns `--enable-warped-motion=1` on, which is the
647 /// root cause this round fixed: libaom `motion_mode_allowed` drops
648 /// WARPED_CAUSAL eligibility when `av1_is_scaled(sf)`, so the 8x8 leaf
649 /// must read the 2-symbol obmc alphabet (here: no symbol at all, OBMC
650 /// off) instead of the 3-symbol motion_mode row.
651 ///
652 /// Each arm hard-asserts its own counter (class `gate-blind-to-feature`):
653 /// a pixel match with zero scaled leaves/sub-8x8 blocks/suppressed warp
654 /// eligibilities would prove nothing.
655 #[test]
656 fn real_superres_streams_with_sub8_leaf8_and_warp_decode_pixel_exact() {
657 const NAME: &str = "real_superres_streams_with_sub8_leaf8_and_warp_decode_pixel_exact";
658 let _gate_lock = lock_gate_counters();
659 if !have_ffmpeg() {
660 eprintln!("SKIP {NAME}: no ffmpeg");
661 return;
662 }
663 if !have_aomenc() {
664 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
665 return;
666 }
667 // Every tool whose scaled-reference path this round does NOT touch is
668 // off, so a mismatch can only be the lifted paths (the same scoping
669 // the r10 key+inter superres gate uses).
670 let common: [&str; 21] = [
671 "--codec=av1",
672 "--passes=1",
673 "--end-usage=q",
674 "--threads=1",
675 "--row-mt=0",
676 "--kf-max-dist=9999",
677 "--lag-in-frames=0",
678 "--auto-alt-ref=0",
679 "--cpu-used=0",
680 "--sb-size=64",
681 "--superres-mode=1",
682 "--superres-denominator=12",
683 "--superres-kf-denominator=12",
684 "--enable-obmc=0",
685 "--enable-masked-comp=0",
686 "--enable-interintra-comp=0",
687 "--enable-tx-size-search=0",
688 "--enable-cdef=0",
689 "--enable-restoration=0",
690 "--enable-palette=0",
691 "--enable-intrabc=0",
692 ];
693 struct Arm {
694 name: &'static str,
695 frames: usize,
696 cq: &'static str,
697 extra: [&'static str; 4],
698 }
699 let arms = [
700 Arm {
701 name: "sub8+leaf8",
702 frames: 4,
703 cq: "--cq-level=4",
704 extra: [
705 "--enable-warped-motion=0",
706 "--enable-rect-partitions=1",
707 "--max-partition-size=32",
708 "--min-partition-size=4",
709 ],
710 },
711 Arm {
712 name: "warp",
713 frames: 6,
714 cq: "--cq-level=20",
715 extra: [
716 "--enable-warped-motion=1",
717 "--enable-rect-partitions=1",
718 "--max-partition-size=32",
719 "--min-partition-size=8",
720 ],
721 },
722 ];
723 let (width, height) = (96usize, 96usize);
724 for arm in &arms {
725 let duration = format!("{}", arm.frames as f64 / 25.0);
726 let src = format!("mandelbrot=size={width}x{height}:rate=25");
727 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
728 .args([
729 "-v",
730 "error",
731 "-f",
732 "lavfi",
733 "-i",
734 &src,
735 "-t",
736 &duration,
737 "-pix_fmt",
738 "yuv420p",
739 "-strict",
740 "-1",
741 "-f",
742 "yuv4mpegpipe",
743 "-",
744 ])
745 .stdin(Stdio::null())
746 .stdout(Stdio::piped())
747 .stderr(Stdio::piped()), None, |c| c.output())
748 .expect("ffmpeg failed to run");
749 assert!(y4m.status.success(), "{NAME}: ffmpeg refused the fixture");
750 let limit = format!("--limit={}", arm.frames);
751 let mut args: Vec<&str> = common.to_vec();
752 args.push(&limit);
753 args.push(arm.cq);
754 args.extend_from_slice(&arm.extra);
755 args.extend_from_slice(&["--obu", "-o", "-", "-"]);
756 let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
757 assert!(
758 out.status.success(),
759 "{NAME} {}: aomenc refused the recipe: {}",
760 arm.name,
761 String::from_utf8_lossy(&out.stderr)
762 );
763 let stream = out.stdout;
764 let leaf8_before = crate::decode::scaled_leaf8_hits();
765 let sub8_before = crate::decode::scaled_sub8_hits();
766 let warp_before = crate::decode::scaled_warp_suppressed_hits();
767 let frames = decode_stream(&stream)
768 .unwrap_or_else(|e| panic!("{NAME} {}: refused: {e}", arm.name));
769 assert_eq!(frames.len(), arm.frames, "{NAME} {}", arm.name);
770 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, arm.frames);
771 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
772 assert_eq!(
773 got.y, want.y,
774 "{NAME} {} frame {i} luma vs ffmpeg",
775 arm.name
776 );
777 assert_eq!(got.u, want.u, "{NAME} {} frame {i} U vs ffmpeg", arm.name);
778 assert_eq!(got.v, want.v, "{NAME} {} frame {i} V vs ffmpeg", arm.name);
779 }
780 let (leaf8, sub8, warp) = (
781 crate::decode::scaled_leaf8_hits() - leaf8_before,
782 crate::decode::scaled_sub8_hits() - sub8_before,
783 crate::decode::scaled_warp_suppressed_hits() - warp_before,
784 );
785 eprintln!(
786 "{NAME} {}: {} frames pixel-exact, scaled leaf8={leaf8} sub8={sub8} \
787 warp_suppressed={warp}",
788 arm.name, arm.frames
789 );
790 if arm.name == "sub8+leaf8" {
791 assert!(
792 leaf8 > 0 && sub8 > 0,
793 "{NAME} {}: the lifted paths never ran (leaf8={leaf8} sub8={sub8})",
794 arm.name
795 );
796 } else {
797 assert!(
798 warp > 0,
799 "{NAME} {}: no block reached WARPED_CAUSAL eligibility under a scaled \
800 reference, so the alphabet fix is unexercised",
801 arm.name
802 );
803 }
804 }
805 }
806
807 /// lane-interintra r1: `--enable-interintra-comp=1` streams must DECODE
808 /// pixel-exact -- the interintra flag/mode/wedge-flag syntax and the
809 /// non-wedge smooth blend are ported. A refusal naming interintra fails
810 /// the gate UNLESS it is the wedge refusal (`use_wedge_interintra == 1`
811 /// is r2, and this recipe encodes with wedge off so it must not fire
812 /// either); warp/obmc are enabled and supported; refusals for OTHER
813 /// named capabilities (screen content tools) still skip that seed. The
814 /// sweep must actually exercise interintra (`interintra_hits > 0`).
815 #[test]
816 fn a_real_aomenc_stream_with_interintra_decodes_pixel_exact() {
817 const NAME: &str = "a_real_aomenc_stream_with_interintra_decodes_pixel_exact";
818 let _gate_lock = lock_gate_counters();
819 if !have_ffmpeg() {
820 eprintln!("SKIP {NAME}: no ffmpeg");
821 return;
822 }
823 if !have_aomenc() {
824 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
825 return;
826 }
827 let (width, height, frame_count) = (64usize, 64usize, 24usize);
828 // lane-midcut r1: rect interintra (`write_w != write_h`) built its
829 // intra predictor at the square `side`; this gate passed with that
830 // bug, so the shape gets its own delta-counted assert below.
831 let rect_before = crate::decode::interintra_rect_hits();
832 let mut named_refusals = 0u32;
833 let mut matched = 0u32;
834 let n_attempts: u32 = std::env::var("EC_INTERINTRA_GATE_ATTEMPTS")
835 .ok()
836 .and_then(|s| s.parse().ok())
837 .unwrap_or(40);
838 for attempt in 0..n_attempts {
839 let seed = 42 + attempt;
840 let duration = frame_count as f64 / 25.0;
841 let source =
842 gradients_source(seed, width, height, &format!("duration={duration}:rate=25"));
843 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
844 .args([
845 "-v",
846 "error",
847 "-f",
848 "lavfi",
849 "-i",
850 &source,
851 "-pix_fmt",
852 "yuv420p",
853 "-f",
854 "yuv4mpegpipe",
855 "-",
856 ])
857 .stdin(Stdio::null())
858 .stdout(Stdio::piped())
859 .stderr(Stdio::piped()), None, |c| c.output())
860 .expect("ffmpeg failed to run");
861 assert!(
862 y4m.status.success(),
863 "ffmpeg fixture: {}",
864 String::from_utf8_lossy(&y4m.stderr)
865 );
866 let args: Vec<&str> = vec![
867 "--codec=av1",
868 "--passes=1",
869 "--end-usage=q",
870 "--cq-level=45",
871 "--cpu-used=0",
872 "--kf-max-dist=1000",
873 "--threads=1",
874 "--row-mt=0",
875 "--auto-alt-ref=1",
876 "--lag-in-frames=16",
877 "--enable-fwd-kf=0",
878 "--enable-order-hint=1",
879 "--enable-warped-motion=1",
880 "--enable-obmc=1",
881 "--tune-content=default",
882 "--enable-masked-comp=0",
883 "--enable-interintra-comp=1",
884 "--enable-onesided-comp=1",
885 "--enable-interintra-wedge=0",
886 "--enable-smooth-interintra=1",
887 "--enable-rect-partitions=0",
888 "--enable-ab-partitions=0",
889 "--enable-1to4-partitions=0",
890 "--enable-filter-intra=0",
891 "--enable-smooth-intra=0",
892 "--enable-paeth-intra=0",
893 "--enable-directional-intra=0",
894 "--enable-angle-delta=0",
895 "--enable-tx-size-search=0",
896 "--enable-cdef=0",
897 "--enable-restoration=0",
898 "--max-partition-size=32",
899 "--min-partition-size=32",
900 "--enable-palette=0",
901 "--enable-intrabc=0",
902 "--enable-cfl-intra=0",
903 "--enable-ref-frame-mvs=0",
904 "--obu",
905 "-o",
906 "-",
907 "-",
908 ];
909 let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
910 assert!(
911 out.status.success(),
912 "aomenc refused the fixture: {}",
913 String::from_utf8_lossy(&out.stderr)
914 );
915 let stream = out.stdout;
916 let frames = match decode_stream(&stream) {
917 Err(e) => {
918 let msg = e.to_string();
919 assert!(
920 msg.contains("unsupported"),
921 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
922 );
923 assert!(
924 !msg.contains("warp"),
925 "{NAME} refused on warp (seed {seed}) -- warp decode is ported, this \
926 refusal must not exist: {msg}"
927 );
928 assert!(
929 !msg.contains("interintra"),
930 "{NAME} refused on interintra (seed {seed}) -- non-wedge interintra \
931 is ported and this recipe encodes with wedge off: {msg}"
932 );
933 named_refusals += 1;
934 eprintln!("seed {seed} refusal (non-warp capability): {msg}");
935 continue;
936 }
937 Ok(frames) => frames,
938 };
939 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
940 assert_eq!(frames.len(), frame_count);
941 let mismatched = frames
942 .iter()
943 .zip(&ffmpeg_frames)
944 .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
945 if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
946 std::fs::write(&path, &stream).expect("writing pinned stream");
947 eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
948 }
949 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
950 assert_eq!(
951 got.y, want.y,
952 "{NAME} frame {i} luma vs ffmpeg (seed {seed})"
953 );
954 assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
955 assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
956 }
957 // lane-hidden r2 (class gate-blind-to-hidden-frames): the same
958 // stream again, comparing EVERY decode-order frame -- the hidden
959 // (show_frame == 0) alt-ref frames the ffmpeg compare above
960 // cannot see, because both sides of it emit shown frames only.
961 let (hidden_total, hidden_n) = decode_all_frames_vs_oracle(&stream, NAME);
962 eprintln!(
963 "{NAME} HIDDEN: seed {seed}: {hidden_total} decode-order frames, \
964 {hidden_n} hidden, all pixel-exact vs the oracle"
965 );
966 // lane-hidden r2 SECOND ARM (the recipe above is untouched):
967 // libaom's temporal alt-ref filter absorbs this recipe's hidden
968 // frames, so the compare above is vacuous -- re-encode the same
969 // fixture with --arnr-maxframes=0 and compare THOSE.
970 if let Some((arm_total, arm_hidden)) = hidden_arnr_arm(NAME, &y4m.stdout, &args) {
971 eprintln!(
972 "{NAME} HIDDEN-ARM(--arnr-maxframes=0): seed {seed}: {arm_total} \
973 decode-order frames, {arm_hidden} hidden, all pixel-exact vs the oracle"
974 );
975 }
976 // lane-midcut r3 RECT ARM: the recipe above spells
977 // `--enable-rect-partitions=0 --min-partition-size=32`, so it can
978 // never produce a RECT interintra block -- the delta assert at the
979 // end of this gate was unsatisfiable on it (the gate disabled the
980 // very shape it claims to prove). Re-encode the SAME source with
981 // the rect overrides APPENDED (aomenc keeps the LAST occurrence of
982 // a repeated flag) and compare every decode-order frame of that
983 // stream against aomdec, until a rect interintra block fires.
984 if crate::decode::interintra_rect_hits() == rect_before {
985 let mut rect_args = args.clone();
986 rect_args.extend_from_slice(&[
987 "--enable-rect-partitions=1",
988 "--min-partition-size=8",
989 "--max-partition-size=64",
990 ]);
991 let out = run_with_stdin(Command::new(aomenc_path()).args(&rect_args), &y4m.stdout);
992 assert!(
993 out.status.success(),
994 "{NAME} RECT-ARM: aomenc refused its own recipe plus the rect overrides: {}",
995 String::from_utf8_lossy(&out.stderr)
996 );
997 let rect_stream = out.stdout;
998 match decode_stream(&rect_stream) {
999 Err(e) => {
1000 let msg = e.to_string();
1001 assert!(
1002 msg.contains("unsupported"),
1003 "{NAME} RECT-ARM failed outright, not a named refusal (seed {seed}): {msg}"
1004 );
1005 eprintln!("{NAME} RECT-ARM: skipped on a named refusal: {msg}");
1006 }
1007 Ok(_) => {
1008 let (total, hidden) =
1009 decode_all_frames_vs_oracle(&rect_stream, &format!("{NAME}-rect"));
1010 eprintln!(
1011 "{NAME} RECT-ARM: seed {seed}: {total} decode-order frames, {hidden} \
1012 hidden, all pixel-exact vs the oracle, interintra_rect_hits={}",
1013 crate::decode::interintra_rect_hits() - rect_before
1014 );
1015 }
1016 }
1017 }
1018 matched += 1;
1019 }
1020 assert!(
1021 matched > 0,
1022 "{NAME}: every attempt refused on other capabilities; the gate never exercised warp"
1023 );
1024 assert!(
1025 crate::decode::interintra_hits() > 0,
1026 "{NAME}: {matched} matches but zero interintra blocks fired -- the gate decodes \
1027 these streams without ever taking interintra, so it proves nothing"
1028 );
1029 // lane-defon r1: `--enable-onesided-comp=1` is spelled on this
1030 // recipe, so a UNIDIR_COMP_REFERENCE pair must actually have been
1031 // read -- otherwise the on-value proves nothing.
1032 assert!(
1033 crate::decode::uni_comp_hits() > 0,
1034 "{NAME}: {matched} matches but zero UNIDIR_COMP_REFERENCE pairs read -- \
1035 --enable-onesided-comp=1 never reached the uni_comp_ref alphabet"
1036 );
1037 assert!(
1038 crate::decode::interintra_rect_hits() > rect_before,
1039 "{NAME}: {matched} matches but zero RECTANGULAR interintra blocks fired -- the \
1040 square-only blend defect (lane-midcut r1) would pass this gate unseen"
1041 );
1042 eprintln!(
1043 "{NAME}: {named_refusals} other-capability refusals, {matched} pixel-exact matches out of {n_attempts}, interintra_hits={} interintra_rect_hits={} uni_comp_hits={}",
1044 crate::decode::interintra_hits(),
1045 crate::decode::interintra_rect_hits() - rect_before,
1046 crate::decode::uni_comp_hits()
1047 );
1048 }
1049
1050 /// lane-scaledref r1: a real aomenc `--superres-mode=1` sequence with
1051 /// compound, OBMC, interintra and 8x8 leaves ALL enabled must decode
1052 /// pixel-exact -- these are the combinations the three
1053 /// "... with a scaled reference (superres, unimplemented)" refusals used
1054 /// to cover. Each combination gets its OWN hard-asserted hit counter
1055 /// (`crate::decode::scaled_*_hits`), because an unscaled reference would
1056 /// pass the pixels and prove nothing (class `gate-blind-to-feature`), and
1057 /// a stream that scales but never takes compound/OBMC/interintra/8x8
1058 /// would prove nothing about the code this round adds either. A refusal
1059 /// naming a scaled reference is a hard failure: those are exactly the
1060 /// strings this round lifts. Other named capabilities skip that seed.
1061 #[test]
1062 fn a_real_aomenc_superres_stream_with_compound_obmc_and_interintra_decodes_pixel_exact() {
1063 const NAME: &str =
1064 "a_real_aomenc_superres_stream_with_compound_obmc_and_interintra_decodes_pixel_exact";
1065 let _gate_lock = lock_gate_counters();
1066 if !have_ffmpeg() {
1067 eprintln!("SKIP {NAME}: no ffmpeg");
1068 return;
1069 }
1070 if !have_aomenc() {
1071 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
1072 return;
1073 }
1074 let (width, height, frame_count) = (64usize, 64usize, 24usize);
1075 let mut named_refusals = 0u32;
1076 let mut matched = 0u32;
1077 let n_attempts: u32 = std::env::var("EC_SCALEDREF_GATE_ATTEMPTS")
1078 .ok()
1079 .and_then(|s| s.parse().ok())
1080 .unwrap_or(12);
1081 for attempt in 0..n_attempts {
1082 let seed = 42 + attempt;
1083 let duration = frame_count as f64 / 25.0;
1084 let source =
1085 gradients_source(seed, width, height, &format!("duration={duration}:rate=25"));
1086 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
1087 .args([
1088 "-v",
1089 "error",
1090 "-f",
1091 "lavfi",
1092 "-i",
1093 &source,
1094 "-pix_fmt",
1095 "yuv420p",
1096 "-f",
1097 "yuv4mpegpipe",
1098 "-",
1099 ])
1100 .stdin(Stdio::null())
1101 .stdout(Stdio::piped())
1102 .stderr(Stdio::piped()), None, |c| c.output())
1103 .expect("ffmpeg failed to run");
1104 assert!(
1105 y4m.status.success(),
1106 "ffmpeg fixture: {}",
1107 String::from_utf8_lossy(&y4m.stderr)
1108 );
1109 let on = |name: &str| {
1110 if std::env::var(name).as_deref() == Ok("0") {
1111 "0"
1112 } else {
1113 "1"
1114 }
1115 };
1116 // lane-scaledref r2: warp is ON. A warp-capable frame header
1117 // under a scaled reference is exactly the case r1 got wrong
1118 // (the block must read the 2-symbol `obmc_cdf`, not the
1119 // 3-symbol `motion_mode_cdf` -- libaom `motion_mode_allowed`,
1120 // blockd.h:1484), and it decoded silently wrong pixels rather
1121 // than refusing. `EC_SCALEDREF_WARP=0` turns it off for
1122 // bisecting only.
1123 let warp = format!("--enable-warped-motion={}", on("EC_SCALEDREF_WARP"));
1124 // lane-scaledref r2: `EC_SCALEDREF_MODE=3` (qthresh) lets
1125 // superres switch on and off per frame, so a compound block can
1126 // reference one scaled and one unscaled reference -- the mixed
1127 // case mode 1 (every frame scaled) never produces.
1128 let superres_mode = format!(
1129 "--superres-mode={}",
1130 std::env::var("EC_SCALEDREF_MODE").unwrap_or_else(|_| "1".into())
1131 );
1132 let obmc = format!("--enable-obmc={}", on("EC_SCALEDREF_OBMC"));
1133 let interintra = format!("--enable-interintra-comp={}", on("EC_SCALEDREF_II"));
1134 let lag = format!(
1135 "--lag-in-frames={}",
1136 if on("EC_SCALEDREF_COMP") == "0" {
1137 "0"
1138 } else {
1139 "25"
1140 }
1141 );
1142 let alt_ref = format!("--auto-alt-ref={}", on("EC_SCALEDREF_COMP"));
1143 let args: Vec<&str> = vec![
1144 "--codec=av1",
1145 "--passes=1",
1146 "--end-usage=q",
1147 "--cq-level=45",
1148 "--cpu-used=0",
1149 "--kf-max-dist=1000",
1150 "--threads=1",
1151 "--row-mt=0",
1152 "--sb-size=64",
1153 // superres on every frame, key and inter alike -- the scaled
1154 // reference this gate is about.
1155 // denominator 16 (the maximum) keeps the CODED frame
1156 // 32x64 -- a multiple of 16 both ways, so no frame-edge
1157 // 16x16 straddle forces a sub-16x16 partition this decoder
1158 // still refuses on the aligned path ("an inter partition
1159 // below 16x16"). Denominator 12 codes 43 columns and every
1160 // seed refused there.
1161 &superres_mode,
1162 "--superres-denominator=16",
1163 "--superres-kf-denominator=16",
1164 // the four combinations this round lifts (each switchable
1165 // by env for bisecting a mismatch without a rebuild)
1166 &alt_ref,
1167 &lag,
1168 "--enable-order-hint=1",
1169 &warp,
1170 &obmc,
1171 &interintra,
1172 "--enable-smooth-interintra=1",
1173 "--enable-interintra-wedge=0",
1174 "--enable-masked-comp=0",
1175 "--enable-onesided-comp=0",
1176 "--enable-fwd-kf=0",
1177 "--tune-content=default",
1178 "--max-partition-size=32",
1179 "--min-partition-size=32",
1180 // everything this decoder still refuses under any reference
1181 "--enable-rect-partitions=0",
1182 "--enable-ab-partitions=0",
1183 "--enable-1to4-partitions=0",
1184 "--enable-filter-intra=0",
1185 "--enable-smooth-intra=0",
1186 "--enable-paeth-intra=0",
1187 "--enable-directional-intra=0",
1188 "--enable-angle-delta=0",
1189 "--enable-tx-size-search=0",
1190 "--enable-cdef=0",
1191 "--enable-restoration=0",
1192 "--enable-palette=0",
1193 "--enable-intrabc=0",
1194 "--enable-cfl-intra=0",
1195 "--enable-ref-frame-mvs=0",
1196 "--obu",
1197 "-o",
1198 "-",
1199 "-",
1200 ];
1201 let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
1202 assert!(
1203 out.status.success(),
1204 "aomenc refused the fixture: {}",
1205 String::from_utf8_lossy(&out.stderr)
1206 );
1207 let stream = out.stdout;
1208 let frames = match decode_stream(&stream) {
1209 Err(e) => {
1210 let msg = e.to_string();
1211 assert!(
1212 msg.contains("unsupported"),
1213 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
1214 );
1215 assert!(
1216 !msg.contains("scaled reference"),
1217 "{NAME} refused on a scaled reference (seed {seed}) -- those refusals \
1218 are exactly what this round lifts: {msg}"
1219 );
1220 named_refusals += 1;
1221 eprintln!("seed {seed} refusal (other capability): {msg}");
1222 continue;
1223 }
1224 Ok(frames) => frames,
1225 };
1226 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
1227 assert_eq!(frames.len(), frame_count);
1228 if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
1229 let mismatched = frames
1230 .iter()
1231 .zip(&ffmpeg_frames)
1232 .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
1233 if mismatched {
1234 std::fs::write(&path, &stream).expect("writing pinned stream");
1235 eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
1236 }
1237 }
1238 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
1239 assert_eq!(
1240 got.y, want.y,
1241 "{NAME} frame {i} luma vs ffmpeg (seed {seed})"
1242 );
1243 assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
1244 assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
1245 }
1246 matched += 1;
1247 }
1248 eprintln!(
1249 "{NAME}: {named_refusals} other-capability refusals, {matched}/{n_attempts} pixel-exact, \
1250 superres_hits={} predict_scaled_hits={} scaled_compound={} scaled_warp_fallback={} \
1251 scaled_obmc={} scaled_interintra={} scaled_block8={} scaled_warp_suppressed={} mixed_scale_compound={}",
1252 crate::superres::superres_hits(),
1253 crate::mc::predict_scaled_hits(),
1254 crate::decode::scaled_compound_hits(),
1255 crate::decode::scaled_warp_fallback_hits(),
1256 crate::decode::scaled_obmc_hits(),
1257 crate::decode::scaled_interintra_hits(),
1258 crate::decode::scaled_block8_hits(),
1259 crate::decode::scaled_warp_suppressed_hits(),
1260 crate::decode::mixed_scale_compound_hits(),
1261 );
1262 assert!(
1263 matched > 0,
1264 "{NAME}: every attempt refused on other capabilities; the gate proves nothing"
1265 );
1266 assert!(
1267 crate::mc::predict_scaled_hits() > 0,
1268 "{NAME}: matched but zero predict_scaled_hits -- no block took the scaled MC path"
1269 );
1270 // The 8x8 leaf is NOT asserted here: it stays refused (no recipe
1271 // produced an 8x8 inter leaf at all), so its counter is a
1272 // diagnostic only -- see this gate's own doc and decode.rs.
1273 // `scaled_warp_suppressed` IS asserted: it counts the blocks whose
1274 // WARPED_CAUSAL eligibility libaom drops because the reference is
1275 // scaled, i.e. the blocks that must read `obmc_cdf`. Zero of them
1276 // would mean this gate's `--enable-warped-motion=1` never reached a
1277 // warp-eligible block and proves nothing about r2's fix.
1278 assert!(
1279 crate::decode::scaled_warp_suppressed_hits() > 0,
1280 "{NAME}: {matched} matches but no block had its warp eligibility \
1281 suppressed by a scaled reference -- the warp arm proves nothing"
1282 );
1283 for (hits, what) in [
1284 (
1285 crate::decode::scaled_compound_hits(),
1286 "compound with a scaled reference",
1287 ),
1288 (
1289 crate::decode::scaled_obmc_hits(),
1290 "OBMC with a scaled reference",
1291 ),
1292 (
1293 crate::decode::scaled_interintra_hits(),
1294 "interintra with a scaled reference",
1295 ),
1296 ] {
1297 assert!(
1298 hits > 0,
1299 "{NAME}: {matched} matches but zero blocks took {what}"
1300 );
1301 }
1302 }
1303
1304 /// lane-defon r1: the 10-bit one-sided-compound hole --
1305 /// `--enable-onesided-comp` was spelled on in no 10-bit gate (5 of the 15
1306 /// pin it off, the rest default), so the UNIDIR_COMP_REFERENCE alphabet
1307 /// was proven at 8 bits only while both of his films are 10-bit 4:2:0.
1308 /// `--enable-diff-wtd-comp=1` is deliberately NOT spelled here (a flag a
1309 /// gate turns on without asserting it fired is coverage theatre, class
1310 /// gate-blind-to-feature): measured this round, the 10-bit `gradients`
1311 /// fixture decodes 8/8 pixel-exact with `diffwtd_hits == 0` -- smooth
1312 /// gradients never win
1313 /// a difference-weighted mask (the 8-bit gate needs `mandelbrot`'s hard
1314 /// diagonal edge, and [`ten_bit_tool_gate`] has no mandelbrot source), so
1315 /// hard-asserting it here would fail on encoder choice, not on a decoder
1316 /// defect.
1317 #[test]
1318 fn a_real_aomenc_10bit_stream_with_onesided_compound_decodes_pixel_exact() {
1319 const NAME: &str = "a_real_aomenc_10bit_stream_with_onesided_compound_decodes_pixel_exact";
1320 let _gate_lock = lock_gate_counters();
1321 if !have_ffmpeg() {
1322 eprintln!("SKIP {NAME}: no ffmpeg");
1323 return;
1324 }
1325 if !have_aomenc() {
1326 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
1327 return;
1328 }
1329 ten_bit_tool_gate(
1330 NAME,
1331 64,
1332 64,
1333 24,
1334 &[
1335 "--enable-onesided-comp=1",
1336 "--enable-masked-comp=1",
1337 "--enable-dist-wtd-comp=0",
1338 "--cq-level=45",
1339 "--kf-max-dist=1000",
1340 "--auto-alt-ref=1",
1341 "--lag-in-frames=16",
1342 "--enable-fwd-kf=0",
1343 "--enable-order-hint=1",
1344 "--enable-global-motion=0",
1345 "--enable-warped-motion=1",
1346 "--enable-obmc=1",
1347 "--tune-content=default",
1348 "--enable-interintra-comp=0",
1349 "--enable-interintra-wedge=0",
1350 "--enable-smooth-interintra=0",
1351 "--enable-rect-partitions=0",
1352 "--enable-ab-partitions=0",
1353 "--enable-1to4-partitions=0",
1354 "--enable-filter-intra=0",
1355 "--enable-smooth-intra=0",
1356 "--enable-paeth-intra=0",
1357 "--enable-directional-intra=0",
1358 "--enable-angle-delta=0",
1359 "--enable-tx-size-search=0",
1360 "--enable-cdef=0",
1361 "--enable-restoration=0",
1362 "--max-partition-size=32",
1363 "--min-partition-size=32",
1364 "--enable-palette=0",
1365 "--enable-intrabc=0",
1366 "--enable-cfl-intra=0",
1367 "--enable-ref-frame-mvs=0",
1368 ],
1369 &[42, 43, 44, 45, 46, 47, 48, 49],
1370 &[(
1371 "uni_comp_hits",
1372 crate::decode::uni_comp_hits as fn() -> usize,
1373 )],
1374 );
1375 }
1376
1377 /// lane-defon r1: the 10-bit sibling of
1378 /// [`a_real_aomenc_stream_with_interintra_wedge_decodes_pixel_exact`] --
1379 /// `--enable-interintra-wedge=1` was spelled on in no 10-bit gate (5 of
1380 /// the 15 pin it off), and his two films are 10-bit, so the 8-bit
1381 /// gate alone proves nothing about the streams that matter. Same tool
1382 /// set as the 8-bit recipe (`--enable-masked-comp=0` keeps inter blocks
1383 /// off the COMPOUND_WEDGE path, fixed 32x32 partitions), driven through
1384 /// [`ten_bit_tool_gate`], which hard-asserts `wii_hits` moved and
1385 /// compares every plane against ffmpeg's own 10-bit decode.
1386 #[test]
1387 fn a_real_aomenc_10bit_stream_with_interintra_wedge_decodes_pixel_exact() {
1388 const NAME: &str = "a_real_aomenc_10bit_stream_with_interintra_wedge_decodes_pixel_exact";
1389 let _gate_lock = lock_gate_counters();
1390 if !have_ffmpeg() {
1391 eprintln!("SKIP {NAME}: no ffmpeg");
1392 return;
1393 }
1394 if !have_aomenc() {
1395 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
1396 return;
1397 }
1398 ten_bit_tool_gate(
1399 NAME,
1400 64,
1401 64,
1402 24,
1403 &[
1404 "--enable-interintra-wedge=1",
1405 "--enable-interintra-comp=1",
1406 "--enable-smooth-interintra=1",
1407 "--cq-level=45",
1408 "--kf-max-dist=1000",
1409 "--auto-alt-ref=1",
1410 "--lag-in-frames=16",
1411 "--enable-fwd-kf=0",
1412 "--enable-order-hint=1",
1413 "--enable-warped-motion=1",
1414 "--enable-obmc=1",
1415 "--tune-content=default",
1416 "--enable-masked-comp=0",
1417 "--enable-onesided-comp=0",
1418 "--enable-rect-partitions=0",
1419 "--enable-ab-partitions=0",
1420 "--enable-1to4-partitions=0",
1421 "--enable-filter-intra=0",
1422 "--enable-smooth-intra=0",
1423 "--enable-paeth-intra=0",
1424 "--enable-directional-intra=0",
1425 "--enable-angle-delta=0",
1426 "--enable-tx-size-search=0",
1427 "--enable-cdef=0",
1428 "--enable-restoration=0",
1429 "--max-partition-size=32",
1430 "--min-partition-size=32",
1431 "--enable-palette=0",
1432 "--enable-intrabc=0",
1433 "--enable-cfl-intra=0",
1434 "--enable-ref-frame-mvs=0",
1435 ],
1436 &[42, 43, 44, 45, 46, 47, 48, 49],
1437 &[
1438 ("wii_hits", crate::decode::wii_hits as fn() -> usize),
1439 (
1440 "interintra_hits",
1441 crate::decode::interintra_hits as fn() -> usize,
1442 ),
1443 ],
1444 );
1445 }
1446
1447 /// lane-wii r2: `--enable-interintra-wedge=1` streams must DECODE
1448 /// pixel-exact -- the wedge-interintra syntax (adapting `wedge_index`
1449 /// CDF symbol, fixed sign 0) and the wedge mask blend are ported over
1450 /// the checksum-verified codebook. `--enable-masked-comp=0` stays so
1451 /// the encoder cannot route inter blocks through the still-unported
1452 /// COMPOUND_WEDGE/DIFFWTD path. A refusal naming interintra/wedge
1453 /// fails the gate; refusals for OTHER named capabilities still skip
1454 /// that seed. Zero `wii_hits` on a run means the encoder never
1455 /// selected wedge-interintra -- soft-skipped (warned), not failed:
1456 /// that is encoder choice, not a decoder bug.
1457 #[test]
1458 fn a_real_aomenc_stream_with_interintra_wedge_decodes_pixel_exact() {
1459 const NAME: &str = "a_real_aomenc_stream_with_interintra_wedge_decodes_pixel_exact";
1460 let _gate_lock = lock_gate_counters();
1461 if !have_ffmpeg() {
1462 eprintln!("SKIP {NAME}: no ffmpeg");
1463 return;
1464 }
1465 if !have_aomenc() {
1466 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
1467 return;
1468 }
1469 let (width, height, frame_count) = (64usize, 64usize, 24usize);
1470 let mut named_refusals = 0u32;
1471 let mut matched = 0u32;
1472 let n_attempts: u32 = std::env::var("EC_WEDGE_GATE_ATTEMPTS")
1473 .ok()
1474 .and_then(|s| s.parse().ok())
1475 .unwrap_or(40);
1476 for attempt in 0..n_attempts {
1477 let seed = 42 + attempt;
1478 let duration = frame_count as f64 / 25.0;
1479 let source = if attempt % 2 == 0 {
1480 gradients_source(seed, width, height, &format!("duration={duration}:rate=25"))
1481 } else {
1482 // `end_pts` does NOT bound mandelbrot (it generated 300+
1483 // frames and hung the gate for an hour); `-t` below is the
1484 // real bound, matching every other mandelbrot gate recipe.
1485 format!("mandelbrot=size={width}x{height}:rate=25")
1486 };
1487 let duration_arg = format!("{duration}");
1488 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
1489 .args([
1490 "-v",
1491 "error",
1492 "-f",
1493 "lavfi",
1494 "-i",
1495 &source,
1496 "-pix_fmt",
1497 "yuv420p",
1498 "-t",
1499 &duration_arg,
1500 "-f",
1501 "yuv4mpegpipe",
1502 "-",
1503 ])
1504 .stdin(Stdio::null())
1505 .stdout(Stdio::piped())
1506 .stderr(Stdio::piped()), None, |c| c.output())
1507 .expect("ffmpeg failed to run");
1508 assert!(
1509 y4m.status.success(),
1510 "ffmpeg fixture: {}",
1511 String::from_utf8_lossy(&y4m.stderr)
1512 );
1513 let args: Vec<&str> = vec![
1514 "--codec=av1",
1515 "--passes=1",
1516 "--end-usage=q",
1517 "--cq-level=45",
1518 "--cpu-used=0",
1519 "--kf-max-dist=1000",
1520 "--threads=1",
1521 "--row-mt=0",
1522 "--auto-alt-ref=1",
1523 "--lag-in-frames=16",
1524 "--enable-fwd-kf=0",
1525 "--enable-order-hint=1",
1526 "--enable-warped-motion=1",
1527 "--enable-obmc=1",
1528 "--tune-content=default",
1529 "--enable-masked-comp=0",
1530 "--enable-interintra-comp=1",
1531 "--enable-onesided-comp=0",
1532 "--enable-interintra-wedge=1",
1533 "--enable-smooth-interintra=1",
1534 "--enable-rect-partitions=0",
1535 "--enable-ab-partitions=0",
1536 "--enable-1to4-partitions=0",
1537 "--enable-filter-intra=0",
1538 "--enable-smooth-intra=0",
1539 "--enable-paeth-intra=0",
1540 "--enable-directional-intra=0",
1541 "--enable-angle-delta=0",
1542 "--enable-tx-size-search=0",
1543 "--enable-cdef=0",
1544 "--enable-restoration=0",
1545 "--max-partition-size=32",
1546 "--min-partition-size=32",
1547 "--enable-palette=0",
1548 "--enable-intrabc=0",
1549 "--enable-cfl-intra=0",
1550 "--enable-ref-frame-mvs=0",
1551 "--obu",
1552 "-o",
1553 "-",
1554 "-",
1555 ];
1556 let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
1557 assert!(
1558 out.status.success(),
1559 "aomenc refused the fixture: {}",
1560 String::from_utf8_lossy(&out.stderr)
1561 );
1562 let stream = out.stdout;
1563 let frames = match decode_stream(&stream) {
1564 Err(e) => {
1565 let msg = e.to_string();
1566 assert!(
1567 msg.contains("unsupported"),
1568 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
1569 );
1570 // Verifier note (lane-wii r2): no refusal string containing
1571 // "wedge"/"interintra" exists in the decoder any more, so
1572 // string-forbidding asserts here would be vacuous (class
1573 // gate-blind-to-feature). The proof this gate carries is
1574 // pixel-exact decode plus the wii_hits count printed below.
1575 named_refusals += 1;
1576 eprintln!("seed {seed} refusal (non-wedge capability): {msg}");
1577 continue;
1578 }
1579 Ok(frames) => frames,
1580 };
1581 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
1582 assert_eq!(frames.len(), frame_count);
1583 let mismatched = frames
1584 .iter()
1585 .zip(&ffmpeg_frames)
1586 .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
1587 if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
1588 std::fs::write(&path, &stream).expect("writing pinned stream");
1589 eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
1590 }
1591 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
1592 assert_eq!(
1593 got.y, want.y,
1594 "{NAME} frame {i} luma vs ffmpeg (seed {seed})"
1595 );
1596 assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
1597 assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
1598 }
1599 // lane-hidden r2 (class gate-blind-to-hidden-frames): the same
1600 // stream again, comparing EVERY decode-order frame -- the hidden
1601 // (show_frame == 0) alt-ref frames the ffmpeg compare above
1602 // cannot see, because both sides of it emit shown frames only.
1603 let (hidden_total, hidden_n) = decode_all_frames_vs_oracle(&stream, NAME);
1604 eprintln!(
1605 "{NAME} HIDDEN: seed {seed}: {hidden_total} decode-order frames, \
1606 {hidden_n} hidden, all pixel-exact vs the oracle"
1607 );
1608 // lane-hidden r2 SECOND ARM (the recipe above is untouched):
1609 // libaom's temporal alt-ref filter absorbs this recipe's hidden
1610 // frames, so the compare above is vacuous -- re-encode the same
1611 // fixture with --arnr-maxframes=0 and compare THOSE.
1612 if let Some((arm_total, arm_hidden)) = hidden_arnr_arm(NAME, &y4m.stdout, &args) {
1613 eprintln!(
1614 "{NAME} HIDDEN-ARM(--arnr-maxframes=0): seed {seed}: {arm_total} \
1615 decode-order frames, {arm_hidden} hidden, all pixel-exact vs the oracle"
1616 );
1617 }
1618 matched += 1;
1619 }
1620 assert!(
1621 matched > 0,
1622 "{NAME}: every attempt refused on other capabilities; the gate never exercised wedge-interintra"
1623 );
1624 // Hardened from a soft-note (verifier: gate-blind-to-feature): the
1625 // recipe fired wedge-interintra on EVERY one of 6 hammer runs
1626 // (wii_hits 2-7), so a zero-hit run is a regression, not sampling.
1627 assert!(
1628 crate::decode::wii_hits() > 0,
1629 "{NAME}: {matched} pixel-exact matches but zero wedge-interintra blocks fired -- \
1630 the blend is unexercised (recipe fired 2-7 hits per run when landed)"
1631 );
1632 eprintln!(
1633 "{NAME}: {named_refusals} other-capability refusals, {matched} pixel-exact matches out of {n_attempts}, wii_hits={}",
1634 crate::decode::wii_hits()
1635 );
1636 }
1637
1638 /// lane-gmaffine r1: an inter frame whose `global_motion_params` carries a
1639 /// SIX-parameter (`AFFINE`) model for a single-reference frame -- refused
1640 /// by name since lane-gm r4 because no aomenc recipe ever reached it.
1641 /// The reason it never did is in libaom's own encoder, not in the
1642 /// content: `av1/encoder/global_motion_facade.c:24` pins the model search
1643 /// to `ROTZOOM` at both ends, so *no* `--enable-global-motion=1` command
1644 /// line over any source can produce the case. The decoder must still
1645 /// handle it (the bitstream allows it, `read_global_motion_params` reads
1646 /// params 4/5 with their own subexp references, and ffmpeg decodes it),
1647 /// so this gate widens exactly that one encoder-side search range in a
1648 /// side build and encodes with it. Everything downstream is ordinary
1649 /// libaom and the pixel oracle is still ffmpeg.
1650 ///
1651 /// Content: rotation composed with a progressive *anisotropic* stretch --
1652 /// a similarity transform plus unequal axis scaling is precisely what a
1653 /// 4-parameter ROTZOOM model cannot express, which is what makes the
1654 /// encoder's RD pick AFFINE. `affine_gm_hits()` hard-asserts that real
1655 /// blocks were predicted through the 6-parameter warp, not merely that a
1656 /// header parsed one (class `gate-blind-to-feature`).
1657 #[test]
1658 fn a_real_affine_global_motion_stream_decodes_pixel_exact() {
1659 const NAME: &str = "a_real_affine_global_motion_stream_decodes_pixel_exact";
1660 let _gate_lock = lock_gate_counters();
1661 if !have_ffmpeg() {
1662 eprintln!("SKIP {NAME}: no ffmpeg");
1663 return;
1664 }
1665 if !have_affine_aomenc() {
1666 eprintln!(
1667 "SKIP {NAME}: no affine-capable aomenc at {} (scripts/build-aom-affine-oracle.sh)",
1668 affine_aomenc_path().display()
1669 );
1670 return;
1671 }
1672 let (width, height, frame_count) = (64usize, 64usize, 24usize);
1673 let duration = frame_count as f64 / 25.0;
1674 // Both depths: his own AV1 library is yuv420p10le throughout, and a
1675 // 10-bit AFFINE warp runs the same `warp_affine` over wider samples.
1676 for depth in [8u32, 10u32] {
1677 // `-t` is the real bound on mandelbrot (it ignores `end_pts` and
1678 // has hung a gate for an hour); the 96x96 source is rotated and
1679 // then stretched horizontally only, and cropped back to 64x64.
1680 let source = format!(
1681 "mandelbrot=size=96x96:rate=25,rotate=a=0.12*t:c=black,\
1682 scale=w='ceil(96*(1+0.03*n)/2)*2':h=96:eval=frame,crop={width}:{height}"
1683 );
1684 let pix_fmt = if depth == 10 {
1685 "yuv420p10le"
1686 } else {
1687 "yuv420p"
1688 };
1689 let mut ff_args: Vec<&str> = vec![
1690 "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", pix_fmt,
1691 ];
1692 // y4m has no official 10-bit tag, same as the 10-bit gate above.
1693 if depth == 10 {
1694 ff_args.extend(["-strict", "-1"]);
1695 }
1696 let duration_arg = duration.to_string();
1697 ff_args.extend(["-t", &duration_arg, "-f", "yuv4mpegpipe", "-"]);
1698 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
1699 .args(&ff_args)
1700 .stdin(Stdio::null())
1701 .stdout(Stdio::piped())
1702 .stderr(Stdio::piped()), None, |c| c.output())
1703 .expect("ffmpeg failed to run");
1704 assert!(
1705 y4m.status.success(),
1706 "ffmpeg fixture: {}",
1707 String::from_utf8_lossy(&y4m.stderr)
1708 );
1709 let bit_depth = format!("--bit-depth={depth}");
1710 let input_bit_depth = format!("--input-bit-depth={depth}");
1711 let args: Vec<&str> = vec![
1712 "--codec=av1",
1713 "--passes=1",
1714 "--end-usage=q",
1715 "--cq-level=45",
1716 "--cpu-used=0",
1717 "--kf-max-dist=1000",
1718 "--threads=1",
1719 "--row-mt=0",
1720 "--auto-alt-ref=0",
1721 "--lag-in-frames=0",
1722 "--enable-fwd-kf=0",
1723 "--enable-order-hint=1",
1724 "--enable-global-motion=1",
1725 "--enable-warped-motion=0",
1726 "--enable-obmc=0",
1727 "--tune-content=default",
1728 "--enable-masked-comp=0",
1729 "--enable-interintra-comp=0",
1730 "--enable-onesided-comp=0",
1731 "--enable-rect-partitions=0",
1732 "--enable-ab-partitions=0",
1733 "--enable-1to4-partitions=0",
1734 "--enable-filter-intra=0",
1735 "--enable-smooth-intra=0",
1736 "--enable-paeth-intra=0",
1737 "--enable-directional-intra=0",
1738 "--enable-angle-delta=0",
1739 "--enable-tx-size-search=0",
1740 "--enable-cdef=0",
1741 "--enable-restoration=0",
1742 "--max-partition-size=32",
1743 "--min-partition-size=32",
1744 "--enable-palette=0",
1745 "--enable-intrabc=0",
1746 "--enable-cfl-intra=0",
1747 "--enable-ref-frame-mvs=0",
1748 &bit_depth,
1749 &input_bit_depth,
1750 "--obu",
1751 "-o",
1752 "-",
1753 "-",
1754 ];
1755 let out = run_with_stdin(Command::new(affine_aomenc_path()).args(&args), &y4m.stdout);
1756 assert!(
1757 out.status.success(),
1758 "aomenc refused the fixture: {}",
1759 String::from_utf8_lossy(&out.stderr)
1760 );
1761 let stream = out.stdout;
1762 let before = crate::decode::affine_gm_hits();
1763 let frames =
1764 decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME} ({depth}-bit): {e}"));
1765 let ffmpeg_frames = if depth == 10 {
1766 ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
1767 } else {
1768 ffmpeg_decode_sequence(&stream, width, height, frame_count)
1769 };
1770 assert_eq!(frames.len(), frame_count);
1771 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
1772 assert_eq!(got.y, want.y, "{NAME} {depth}-bit frame {i} luma vs ffmpeg");
1773 assert_eq!(got.u, want.u, "{NAME} {depth}-bit frame {i} U vs ffmpeg");
1774 assert_eq!(got.v, want.v, "{NAME} {depth}-bit frame {i} V vs ffmpeg");
1775 }
1776 let hits = crate::decode::affine_gm_hits() - before;
1777 assert!(
1778 hits > 0,
1779 "{NAME} ({depth}-bit): decoded pixel-exact but no block was predicted through a \
1780 6-parameter global-motion warp -- the AFFINE path is unexercised"
1781 );
1782 eprintln!(
1783 "{NAME}: {depth}-bit, {frame_count} frames pixel-exact, affine_gm_hits={hits}"
1784 );
1785 }
1786 }
1787
1788 /// lane-av1gwarp12: the SINGLE-reference GLOBAL-warp witness at 12 bits
1789 /// -- the open half lane-av112bitw recorded (engagement 0 on every prior
1790 /// 12-bit content). The decode path is the same `warp_affine` with
1791 /// `warp_round_0(12)` the local-warp witness proved, fed by
1792 /// `global_warp_params(gm_ref.params)` at `decode_inter_block`'s
1793 /// single-ref arm -- but composition had no stream: the travelling-box
1794 /// source fits only TRANSLATION global models (excluded by
1795 /// `is_global_mv_block`), and the rotating mandelbrot reached the global
1796 /// models only on compound blocks. This recipe closes it: rotation +
1797 /// uniform zoom (a similarity transform, ROTZOOM's exact family), the
1798 /// compound tools off so a global model can only ride a single-reference
1799 /// GLOBALMV block, and partitions pinned to 32 so the 8x8 leaf arm is
1800 /// structurally out of the stream. Vanilla aomenc pins its gm search to
1801 /// ROTZOOM (`global_motion_facade.c:24`), so every >TRANSLATION model a
1802 /// real aomenc emits is ROTZOOM; AFFINE needs the widened side build
1803 /// (`a_real_affine_global_motion_stream_decodes_pixel_exact`).
1804 ///
1805 /// Non-vacuous by construction: `rotzoom_gm_warp_hits()` hard-asserts a
1806 /// 16x16+ block was really predicted through the global warp with a
1807 /// ROTZOOM model, the zero `compound_warp_hits` delta keeps the
1808 /// single-reference premise honest, and every plane of every frame
1809 /// compares against ffmpeg.
1810 #[test]
1811 fn a_real_rotzoom_global_warp_12bit_stream_decodes_pixel_exact() {
1812 const NAME: &str = "a_real_rotzoom_global_warp_12bit_stream_decodes_pixel_exact";
1813 let _gate_lock = lock_gate_counters();
1814 if !have_ffmpeg() {
1815 eprintln!("SKIP {NAME}: no ffmpeg");
1816 return;
1817 }
1818 if !have_aomenc() {
1819 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
1820 return;
1821 }
1822 const W: usize = 128;
1823 const H: usize = 128;
1824 const FRAMES: usize = 16;
1825 let y4m = y4m_12bit_rotzoom_gm_source(FRAMES);
1826 let stream = encode_12bit(
1827 &y4m,
1828 FRAMES,
1829 &[
1830 "--enable-global-motion=1",
1831 "--enable-warped-motion=0",
1832 "--enable-obmc=0",
1833 "--enable-masked-comp=0",
1834 "--enable-interintra-comp=0",
1835 "--enable-onesided-comp=0",
1836 "--enable-ref-frame-mvs=0",
1837 "--min-partition-size=32",
1838 "--max-partition-size=32",
1839 ],
1840 );
1841 assert_12bit_sequence_header(&stream, NAME);
1842 let (before_rotzoom, before_affine, before_selected, before_compound) = (
1843 decode::rotzoom_gm_warp_hits(),
1844 decode::affine_gm_hits(),
1845 decode::warp_selected_hits(),
1846 decode::compound_warp_hits(),
1847 );
1848 let frames = decode_stream(&stream).unwrap_or_else(|e| {
1849 panic!("{NAME}: decode_stream refused a real 12-bit global-warp stream: {e}")
1850 });
1851 assert_eq!(frames.len(), FRAMES);
1852 let (delta_rotzoom, delta_affine, delta_selected) = (
1853 decode::rotzoom_gm_warp_hits() - before_rotzoom,
1854 decode::affine_gm_hits() - before_affine,
1855 decode::warp_selected_hits() - before_selected,
1856 );
1857 eprintln!(
1858 "{NAME}: gm_warp_engagement rotzoom(single-ref global warp)={delta_rotzoom} \
1859 affine={delta_affine} selected_local_warp={delta_selected}"
1860 );
1861 assert!(
1862 delta_rotzoom > 0,
1863 "{NAME}: decoded but no single-reference ROTZOOM global-warp block fired -- \
1864 the 12-bit single-ref global-warp path is unexercised and the pixel \
1865 compare would prove nothing"
1866 );
1867 assert_eq!(
1868 decode::compound_warp_hits() - before_compound,
1869 0,
1870 "{NAME}: a compound warp block ran -- the single-reference premise is gone"
1871 );
1872 let ffmpeg_frames = ffmpeg_decode_sequence_12bit(&stream, W, H, FRAMES);
1873 for (i, (ours, reference)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
1874 assert_eq!(ours.y, reference.y, "{NAME} frame {i} luma vs ffmpeg");
1875 assert_eq!(ours.u, reference.u, "{NAME} frame {i} U vs ffmpeg");
1876 assert_eq!(ours.v, reference.v, "{NAME} frame {i} V vs ffmpeg");
1877 }
1878 eprintln!(
1879 "{NAME}: {FRAMES} frames pixel-exact vs ffmpeg, rotzoom_gm_warp_hits={delta_rotzoom}"
1880 );
1881 }
1882
1883 /// lane-gmaffine r1 item (3): `GLOBALMV` at an 8x8 leaf, ROTZOOM global
1884 /// motion, warp built from the frame's own model.
1885 #[test]
1886 fn a_real_globalmv_8x8_leaf_stream_decodes_pixel_exact() {
1887 const NAME: &str = "a_real_globalmv_8x8_leaf_stream_decodes_pixel_exact";
1888 let _gate_lock = lock_gate_counters();
1889 if !have_ffmpeg() {
1890 eprintln!("SKIP {NAME}: no ffmpeg");
1891 return;
1892 }
1893 if !have_aomenc() {
1894 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
1895 return;
1896 }
1897 run_8x8_leaf_motion_gate(NAME, true, crate::decode::globalmv_hits_8);
1898 }
1899
1900 /// lane-gmaffine r1 item (2): `WARPED_CAUSAL` at an 8x8 leaf --
1901 /// findSamples + `av1_find_projection` + the warp filter at BLOCK_8X8.
1902 #[test]
1903 fn a_real_warped_causal_8x8_leaf_stream_decodes_pixel_exact() {
1904 const NAME: &str = "a_real_warped_causal_8x8_leaf_stream_decodes_pixel_exact";
1905 let _gate_lock = lock_gate_counters();
1906 if !have_ffmpeg() {
1907 eprintln!("SKIP {NAME}: no ffmpeg");
1908 return;
1909 }
1910 if !have_aomenc() {
1911 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
1912 return;
1913 }
1914 run_8x8_leaf_motion_gate(NAME, false, crate::decode::warp_hits_8);
1915 }
1916
1917 /// lane-rect16 r1/r2: a plain default-settings aomenc run over lavfi
1918 /// `mandelbrot` (`--cpu-used=4 --end-usage=q --cq-level=32`, no
1919 /// `--enable-*` flags) used to refuse frame 0 outright with "a partition
1920 /// below 16x16 other than a clean split". r1 root-caused the FIRST hit to
1921 /// a `PARTITION_VERT_B` `partition_w16` symbol at mi=(3,2) and wired it
1922 /// (left 8x16 real `decode_block_rect` strip + two stacked 8x8
1923 /// `decode_leaf8` leaves on the right). r2 re-measured after that fix
1924 /// (`decision-before-quantiser`-shaped: don't trust a stale premise) and
1925 /// found this stream's REAL first-hit blocker in z-order is earlier, at
1926 /// mi=(0,7): a plain `PARTITION_HORZ`. That arm is now wired too
1927 /// (`decode_leaf_rect`, sibling to `decode_leaf8` but real-mi-addressed
1928 /// for a non-square strip) -- `horz_vert_intra_hits` proves it fires.
1929 /// This exact stream's own HORZ block at mi=(0,7) is *coded* (real
1930 /// coefficients), which is NOT ported (same ceiling as VERT_B's own
1931 /// non-skip refusal -- no rectangular-transform coefficient tables at
1932 /// this size), so decode still stops there and `vert_b_intra_hits`
1933 /// never gets a chance to increment on this particular stream. This gate
1934 /// proves the HORZ arm fires and the OLD (now-false) two-clause refusal
1935 /// never reappears, not a pixel-exact decode of this stream.
1936 #[test]
1937 fn a_real_aomenc_stream_with_mandelbrot_fires_the_vert_b_partition_arm() {
1938 const NAME: &str = "a_real_aomenc_stream_with_mandelbrot_fires_the_vert_b_partition_arm";
1939 let _gate_lock = lock_gate_counters();
1940 if !have_ffmpeg() {
1941 eprintln!("SKIP {NAME}: no ffmpeg");
1942 return;
1943 }
1944 if !have_aomenc() {
1945 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
1946 return;
1947 }
1948 let (width, height) = (192usize, 128usize);
1949 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
1950 .args([
1951 "-v",
1952 "error",
1953 "-f",
1954 "lavfi",
1955 "-i",
1956 &format!("mandelbrot=size={width}x{height}"),
1957 "-pix_fmt",
1958 "yuv420p",
1959 "-t",
1960 "1",
1961 "-f",
1962 "yuv4mpegpipe",
1963 "-",
1964 ])
1965 .stdin(Stdio::null())
1966 .stdout(Stdio::piped())
1967 .stderr(Stdio::piped()), None, |c| c.output())
1968 .expect("ffmpeg failed to run");
1969 assert!(
1970 y4m.status.success(),
1971 "ffmpeg fixture: {}",
1972 String::from_utf8_lossy(&y4m.stderr)
1973 );
1974 let out = run_with_stdin(
1975 Command::new(aomenc_path()).args([
1976 "--threads=1",
1977 "--row-mt=0",
1978 "--sb-size=64",
1979 "--cpu-used=4",
1980 "--end-usage=q",
1981 "--cq-level=32",
1982 "--passes=1",
1983 "--obu",
1984 "-o",
1985 "-",
1986 "-",
1987 ]),
1988 &y4m.stdout,
1989 );
1990 assert!(
1991 out.status.success(),
1992 "aomenc refused the fixture: {}",
1993 String::from_utf8_lossy(&out.stderr)
1994 );
1995 let stream = out.stdout;
1996 // lane-rect16 r2: the recipe above was missing `--passes=1` --
1997 // without it aomenc silently ran 2-pass and wrote nothing to stdout
1998 // on pass 1 (still exit 0), so this gate always decoded an EMPTY
1999 // stream and never actually exercised the arm it claims to gate.
2000 assert!(
2001 !stream.is_empty(),
2002 "{NAME}: aomenc wrote an empty stream (missing --passes=1?)"
2003 );
2004 let result = decode_stream(&stream);
2005 // The now-lifted false claim ("codes only the square arms below
2006 // 16x16") must never appear again.
2007 if let Err(e) = &result {
2008 let msg = e.to_string();
2009 assert!(
2010 !msg.contains("this decoder codes only the square arms below 16x16"),
2011 "{NAME}: the OLD (disproved) refusal reappeared: {msg}"
2012 );
2013 }
2014 assert!(
2015 crate::decode::horz_vert_intra_hits() > 0,
2016 "{NAME}: the plain PARTITION_HORZ/VERT arm never fired on this stream (regression -- \
2017 it fired deterministically at mi=(0,7) when this gate was written)"
2018 );
2019 eprintln!(
2020 "{NAME}: horz_vert_intra_hits={}, vert_b_intra_hits={}, decode result: {:?}",
2021 crate::decode::horz_vert_intra_hits(),
2022 crate::decode::vert_b_intra_hits(),
2023 result.as_ref().map(|f| f.len()).map_err(|e| e.to_string())
2024 );
2025 }
2026
2027 /// lane-rectx r3: a real `aomenc` stream whose 16x16-level
2028 /// `PARTITION_HORZ`/`PARTITION_VERT` strips are CODED (non-skip), i.e.
2029 /// carry genuine `TX_16X8`/`TX_8X16` luma coefficients and their
2030 /// `TX_8X4`/`TX_4X8` chroma halves through [`decode_leaf_rect`]'s
2031 /// lane-rectx arm -- the refusal "a coded (non-skip) HORZ/VERT rect strip
2032 /// below 16x16" this round lifts. `--min-partition-size=8
2033 /// --max-partition-size=32 --enable-rect-partitions=1` is what makes
2034 /// aomenc reach for a 16x8 leaf at all; mandelbrot at `cq-level=24` is
2035 /// what makes those leaves non-skip (a gradient fixture codes them all
2036 /// away). `--reduced-tx-type-set=1` pins the five-symbol
2037 /// `EXT_TX_SET_DTT4_IDTX` alphabet: without it aomenc also writes
2038 /// `V_DCT`/`H_DCT`, whose 1D tx classes [`read_coeffs_rect`] still
2039 /// refuses by name (see the r3 report's open residue), so a `=0` run
2040 /// would prove nothing about the 2D path it does support.
2041 ///
2042 /// r2 shipped this path unproven; it was wrong. `TxbSet::LumaRect16x8`
2043 /// read its `tx_type` symbol from the 16x16 row, but libaom's
2044 /// `read_tx_type` indexes `intra_ext_tx_cdf[eset][txsize_sqr_map[tx_size]]`
2045 /// and `txsize_sqr_map[TX_16X8] == TX_8X8` -- a five-symbol CDF where a
2046 /// seven-symbol one belonged, desyncing at the FIRST coded rect leaf
2047 /// (whole frame wrong from pixel (0,0)).
2048 #[test]
2049 fn a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16_decodes_pixel_exact() {
2050 const NAME: &str =
2051 "a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16_decodes_pixel_exact";
2052 let _gate_lock = lock_gate_counters();
2053 if !have_ffmpeg() {
2054 eprintln!("SKIP {NAME}: no ffmpeg");
2055 return;
2056 }
2057 if !have_aomenc() {
2058 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
2059 return;
2060 }
2061 let (width, height) = (64usize, 64usize);
2062 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
2063 .args([
2064 "-v",
2065 "error",
2066 "-f",
2067 "lavfi",
2068 "-i",
2069 &format!("mandelbrot=size={width}x{height}:start_x=-0.6"),
2070 "-pix_fmt",
2071 "yuv420p",
2072 "-t",
2073 "1",
2074 "-vframes",
2075 "1",
2076 "-f",
2077 "yuv4mpegpipe",
2078 "-",
2079 ])
2080 .stdin(Stdio::null())
2081 .stdout(Stdio::piped())
2082 .stderr(Stdio::piped()), None, |c| c.output())
2083 .expect("ffmpeg failed to run");
2084 assert!(
2085 y4m.status.success(),
2086 "ffmpeg fixture: {}",
2087 String::from_utf8_lossy(&y4m.stderr)
2088 );
2089 let encode = || {
2090 let out = run_with_stdin(
2091 Command::new(aomenc_path()).args([
2092 "--codec=av1",
2093 "--passes=1",
2094 "--end-usage=q",
2095 "--cq-level=16",
2096 "--cpu-used=4",
2097 "--threads=1",
2098 "--row-mt=0",
2099 "--sb-size=64",
2100 "--kf-max-dist=0",
2101 "--enable-rect-partitions=1",
2102 "--enable-ab-partitions=0",
2103 "--enable-1to4-partitions=0",
2104 "--enable-tx-size-search=0",
2105 // Filter intra on a strip is a separate, still-refused
2106 // predictor (`filter intra on a HORZ/VERT strip`); this
2107 // gate is about the rect RESIDUAL path, so it is off here
2108 // and covered by the square filter-intra gate instead.
2109 "--enable-filter-intra=0",
2110 "--reduced-tx-type-set=1",
2111 "--min-partition-size=8",
2112 "--max-partition-size=32",
2113 "--obu",
2114 "-o",
2115 "-",
2116 "-",
2117 ]),
2118 &y4m.stdout,
2119 );
2120 assert!(
2121 out.status.success(),
2122 "aomenc refused the fixture: {}",
2123 String::from_utf8_lossy(&out.stderr)
2124 );
2125 out.stdout
2126 };
2127 // The fixture rule: an encoder output is only a pin if it reproduces.
2128 let stream = encode();
2129 assert_eq!(
2130 stream,
2131 encode(),
2132 "{NAME}: aomenc output is not reproducible for this recipe"
2133 );
2134 let before = crate::decode::rect_leaf_coeff_hits();
2135 let frames = decode_stream(&stream)
2136 .unwrap_or_else(|e| panic!("{NAME}: decode failed, not a pixel mismatch: {e}"));
2137 let fired = crate::decode::rect_leaf_coeff_hits() - before;
2138 assert!(
2139 fired > 0,
2140 "{NAME}: the stream decoded but no coded (non-skip) rect leaf fired -- \
2141 the gate proves nothing"
2142 );
2143 // The ENCODE's frame count, asserted ABOVE the oracle call: the y4m is
2144 // rendered with `-t 1` and `-vframes 1` (27566) -- one frame at the
2145 // source's default rate 25 -- and aomenc runs with no `--limit` and
2146 // `--kf-max-dist=0` (27593), so the stream codes exactly 1 frame.
2147 assert_eq!(frames.len(), 1, "{NAME}: expected one key frame");
2148 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len());
2149 assert_eq!(
2150 ffmpeg_frames.len(),
2151 frames.len(),
2152 "{NAME}: ffmpeg frame count"
2153 );
2154 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
2155 assert_eq!(
2156 got.y, want.y,
2157 "{NAME} frame {i} luma vs ffmpeg ({fired} coded rect leaves)"
2158 );
2159 assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg");
2160 assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg");
2161 }
2162 eprintln!("{NAME}: pixel-exact, rect_leaf_coeff_hits={fired}");
2163 }
2164
2165 /// lane-rectx r5: the same 16x8/8x16 rect leaves, but this time proving
2166 /// what a LATER, non-strip block reads from them. `decode_leaf_rect` took
2167 /// the mi-exact intra mode map in r4; `decode_block`/`decode_block_rect`/
2168 /// `decode_block_rect64` did not, so a 32x16 strip whose left neighbour was
2169 /// a 16x8 leaf still read the coarse per-16x16 `left_mode` slot -- which no
2170 /// sub-16x16 block ever writes -- and picked a DIFFERENT `kf_y_mode` CDF row
2171 /// for the same decoded mode value. The stream stayed in sync through mode
2172 /// info (`EC_TRACE_MODE_STEP` ranges match up to that symbol) and then
2173 /// diverged inside the block's own coefficients: the whole bottom-right
2174 /// 32x32 quadrant of this fixture decoded wrong (1650 bytes) while the
2175 /// three earlier quadrants were exact -- wrong pixels returned as success.
2176 /// `mode_mi_override_hits` counts exactly the reads where the mi-exact
2177 /// neighbour disagrees with the coarse slot, so a regression that drops the
2178 /// override again fails the counter as well as the pixels.
2179 #[test]
2180 fn a_real_aomenc_stream_whose_square_block_reads_a_sub16_neighbours_mode_decodes_pixel_exact() {
2181 const NAME: &str = "a_real_aomenc_stream_whose_square_block_reads_a_sub16_neighbours_mode_decodes_pixel_exact";
2182 let _gate_lock = lock_gate_counters();
2183 if !have_ffmpeg() {
2184 eprintln!("SKIP {NAME}: no ffmpeg");
2185 return;
2186 }
2187 if !have_aomenc() {
2188 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
2189 return;
2190 }
2191 let (width, height) = (64usize, 64usize);
2192 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
2193 .args([
2194 "-v",
2195 "error",
2196 "-f",
2197 "lavfi",
2198 "-i",
2199 &format!("rgbtestsrc=size={width}x{height}"),
2200 "-pix_fmt",
2201 "yuv420p",
2202 "-t",
2203 "1",
2204 "-vframes",
2205 "1",
2206 "-f",
2207 "yuv4mpegpipe",
2208 "-",
2209 ])
2210 .stdin(Stdio::null())
2211 .stdout(Stdio::piped())
2212 .stderr(Stdio::piped()), None, |c| c.output())
2213 .expect("ffmpeg failed to run");
2214 assert!(
2215 y4m.status.success(),
2216 "ffmpeg fixture: {}",
2217 String::from_utf8_lossy(&y4m.stderr)
2218 );
2219 // Two swept cells of the r4 sweep that decoded to completion with
2220 // WRONG pixels (1714 and 1650 bytes): `--reduced-tx-type-set` and
2221 // `--enable-filter-intra` are the two axes that move which block sizes
2222 // aomenc reaches for here; both arms are pinned.
2223 let mut total_overrides = 0usize;
2224 for (rtx, filter_intra) in [("1", "0"), ("0", "1")] {
2225 let encode = || {
2226 let out = run_with_stdin(
2227 Command::new(aomenc_path()).args([
2228 "--codec=av1",
2229 "--passes=1",
2230 "--end-usage=q",
2231 "--cq-level=32",
2232 "--cpu-used=4",
2233 "--threads=1",
2234 "--row-mt=0",
2235 "--sb-size=64",
2236 "--kf-max-dist=0",
2237 "--enable-rect-partitions=1",
2238 "--enable-ab-partitions=0",
2239 "--enable-1to4-partitions=0",
2240 "--enable-tx-size-search=0",
2241 "--enable-cdef=0",
2242 "--enable-restoration=0",
2243 &format!("--enable-filter-intra={filter_intra}"),
2244 &format!("--reduced-tx-type-set={rtx}"),
2245 "--min-partition-size=8",
2246 "--max-partition-size=32",
2247 "--obu",
2248 "-o",
2249 "-",
2250 "-",
2251 ]),
2252 &y4m.stdout,
2253 );
2254 assert!(
2255 out.status.success(),
2256 "aomenc refused the fixture: {}",
2257 String::from_utf8_lossy(&out.stderr)
2258 );
2259 out.stdout
2260 };
2261 let stream = encode();
2262 assert_eq!(
2263 stream,
2264 encode(),
2265 "{NAME}: aomenc output is not reproducible (rtx={rtx} filter_intra={filter_intra})"
2266 );
2267 let before = crate::decode::mode_mi_override_hits();
2268 let frames = decode_stream(&stream).unwrap_or_else(|e| {
2269 panic!("{NAME}: decode failed (rtx={rtx} filter_intra={filter_intra}): {e}")
2270 });
2271 // Counted only on an attempt that actually decoded AND is compared
2272 // below -- a refusal never contributes to the firing assert.
2273 let overrides = crate::decode::mode_mi_override_hits() - before;
2274 // The ENCODE's frame count, asserted ABOVE the oracle call: the y4m is
2275 // rendered ONCE outside this loop with `-t 1` and `-vframes 1`
2276 // (27792) -- one frame at the source's default rate 25 -- and aomenc
2277 // runs with no `--limit` and `--kf-max-dist=0` (27726), so both
2278 // (rtx, filter_intra) arms code exactly 1 frame.
2279 assert_eq!(frames.len(), 1, "{NAME}: expected one key frame");
2280 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len());
2281 assert_eq!(
2282 ffmpeg_frames.len(),
2283 frames.len(),
2284 "{NAME}: ffmpeg frame count"
2285 );
2286 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
2287 assert_eq!(
2288 got.y, want.y,
2289 "{NAME} frame {i} luma vs ffmpeg (rtx={rtx} filter_intra={filter_intra}, \
2290 {overrides} mi-exact mode overrides)"
2291 );
2292 assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (rtx={rtx})");
2293 assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (rtx={rtx})");
2294 }
2295 total_overrides += overrides;
2296 }
2297 assert!(
2298 total_overrides > 0,
2299 "{NAME}: no non-strip block ever read a mi-exact neighbour that disagreed with its \
2300 coarse slot -- the gate proves nothing"
2301 );
2302 eprintln!("{NAME}: pixel-exact, mode_mi_override_hits={total_overrides}");
2303 }
2304
2305 /// lane-cfl r1: the chroma intra-edge FILTER TYPE is the neighbour's
2306 /// `uv_mode` (libaom `get_filt_type`, reconintra.c: `chroma_above_mbmi`/
2307 /// `chroma_left_mbmi` -> `is_smooth` on `uv_mode`), and two whole decode
2308 /// paths passed a hardcoded `false` for it -- `decode_leaf_8x8` (every
2309 /// 8x8 leaf of a SPLIT) and `decode_leaf_rect` (every rect strip below
2310 /// 16x16), on a stale "chroma stays false (exact) until a smooth/paeth
2311 /// uv_mode can reach decode at all" comment. On top of that the coarse
2312 /// `above_uv_mode`/`left_uv_mode` cells are 16px-granular and their
2313 /// `for cell in 0..w / SUB` write runs ZERO times for any block below
2314 /// 16x16, so even the paths that DID read them saw whatever a
2315 /// 16x16-or-larger block had left there (class: context read from one
2316 /// cell / neighbour map at the wrong granularity). Result on this
2317 /// recipe: luma byte-exact, entropy ladder identical, and 40 U + 86 V
2318 /// chroma bytes wrong -- every one of them downstream of one 4x4 chroma
2319 /// block at mi(8,12) whose D135 + `angle_delta_uv=-3` left edge was
2320 /// filtered at the wrong strength (`ft=0` where the instrumented aomdec
2321 /// prints `ft=1`, left edge `95,59,30,28` vs `90,61,37,29`).
2322 ///
2323 /// Both arms hard-assert per-attempt counters for the two chroma block
2324 /// shapes involved (`UV_CFL_PRED` blocks, nonzero `angle_delta_uv`
2325 /// blocks) plus the mi-exact UV-neighbour override, and are counted only
2326 /// on an attempt that decoded AND is pixel-compared.
2327 #[test]
2328 fn a_real_aomenc_stream_whose_chroma_edge_filter_reads_a_sub16_neighbours_uv_mode_decodes_pixel_exact()
2329 {
2330 const NAME: &str = "a_real_aomenc_stream_whose_chroma_edge_filter_reads_a_sub16_neighbours_uv_mode_decodes_pixel_exact";
2331 let _gate_lock = lock_gate_counters();
2332 if !have_ffmpeg() {
2333 eprintln!("SKIP {NAME}: no ffmpeg");
2334 return;
2335 }
2336 if !have_aomenc() {
2337 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
2338 return;
2339 }
2340 let mut compared = 0usize;
2341 let (width, height) = (64usize, 64usize);
2342 // 8-bit arm = the r5 residue cell ("mandfi161"); 10-bit arm = its
2343 // twin through the same recipe at `--bit-depth=10`.
2344 for depth in [8usize, 10] {
2345 let pix = if depth == 10 {
2346 "yuv420p10le"
2347 } else {
2348 "yuv420p"
2349 };
2350 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
2351 .args([
2352 "-v",
2353 "error",
2354 "-f",
2355 "lavfi",
2356 "-i",
2357 &format!("mandelbrot=size={width}x{height}:start_x=-0.6"),
2358 "-pix_fmt",
2359 pix,
2360 "-strict",
2361 "-1",
2362 "-t",
2363 "1",
2364 "-vframes",
2365 "1",
2366 "-f",
2367 "yuv4mpegpipe",
2368 "-",
2369 ])
2370 .stdin(Stdio::null())
2371 .stdout(Stdio::piped())
2372 .stderr(Stdio::piped()), None, |c| c.output())
2373 .expect("ffmpeg failed to run");
2374 assert!(
2375 y4m.status.success(),
2376 "{NAME}: ffmpeg fixture (depth={depth}): {}",
2377 String::from_utf8_lossy(&y4m.stderr)
2378 );
2379 let encode = || {
2380 let out = run_with_stdin(
2381 Command::new(aomenc_path()).args([
2382 "--codec=av1",
2383 "--passes=1",
2384 "--end-usage=q",
2385 "--cq-level=16",
2386 "--cpu-used=4",
2387 "--threads=1",
2388 "--row-mt=0",
2389 "--sb-size=64",
2390 "--kf-max-dist=0",
2391 "--enable-rect-partitions=1",
2392 "--enable-ab-partitions=0",
2393 "--enable-1to4-partitions=0",
2394 "--enable-tx-size-search=0",
2395 "--enable-filter-intra=1",
2396 "--reduced-tx-type-set=1",
2397 "--min-partition-size=8",
2398 "--max-partition-size=32",
2399 &format!("--input-bit-depth={depth}"),
2400 &format!("--bit-depth={depth}"),
2401 "--obu",
2402 "-o",
2403 "-",
2404 "-",
2405 ]),
2406 &y4m.stdout,
2407 );
2408 assert!(
2409 out.status.success(),
2410 "aomenc refused the fixture (depth={depth}): {}",
2411 String::from_utf8_lossy(&out.stderr)
2412 );
2413 out.stdout
2414 };
2415 let stream = encode();
2416 assert_eq!(
2417 stream,
2418 encode(),
2419 "{NAME}: aomenc output is not reproducible (depth={depth})"
2420 );
2421 let before_cfl = crate::decode::cfl_block_hits();
2422 let before_angle = crate::decode::uv_angle_delta_hits();
2423 let before_uv = crate::decode::uv_mode_mi_override_hits();
2424 let frames = match decode_stream(&stream) {
2425 Ok(frames) => frames,
2426 // Only a NAMED refusal is tolerated (COMMON rule): the 10-bit
2427 // twin of this recipe still stops at another lane's open
2428 // sub-16 AB-partition / strip-filter-intra refusals, so it
2429 // cannot be compared yet. Any other error is a failure, and
2430 // `compared` below keeps the test from passing vacuously.
2431 Err(e) => {
2432 let msg = e.to_string();
2433 assert!(
2434 msg.contains("unsupported"),
2435 "{NAME}: decode failed (depth={depth}): {msg}"
2436 );
2437 eprintln!("{NAME}: depth={depth} arm refused (not compared): {msg}");
2438 continue;
2439 }
2440 };
2441 compared += 1;
2442 // Read only on an attempt that decoded AND is compared below.
2443 let cfl_blocks = crate::decode::cfl_block_hits() - before_cfl;
2444 let angle_blocks = crate::decode::uv_angle_delta_hits() - before_angle;
2445 let uv_overrides = crate::decode::uv_mode_mi_override_hits() - before_uv;
2446 // The ENCODE's frame count, asserted ABOVE the oracle call: the y4m is
2447 // rendered with `-t 1` and `-vframes 1` (27852) -- one frame at the
2448 // source's default rate 25 -- and aomenc runs with no `--limit` and
2449 // `--kf-max-dist=0` (27890), so both depths code exactly 1 frame.
2450 assert_eq!(
2451 frames.len(),
2452 1,
2453 "{NAME}: expected one key frame (depth={depth})"
2454 );
2455 let ffmpeg_frames = if depth == 10 {
2456 ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len())
2457 } else {
2458 ffmpeg_decode_sequence(&stream, width, height, frames.len())
2459 };
2460 assert_eq!(
2461 ffmpeg_frames.len(),
2462 frames.len(),
2463 "{NAME}: ffmpeg frame count"
2464 );
2465 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
2466 assert_eq!(
2467 got.y, want.y,
2468 "{NAME} frame {i} luma vs ffmpeg (depth={depth})"
2469 );
2470 assert_eq!(
2471 got.u, want.u,
2472 "{NAME} frame {i} U vs ffmpeg (depth={depth}, {cfl_blocks} CFL blocks, \
2473 {angle_blocks} nonzero-angle_delta_uv blocks, {uv_overrides} mi-exact UV \
2474 neighbour overrides)"
2475 );
2476 assert_eq!(
2477 got.v, want.v,
2478 "{NAME} frame {i} V vs ffmpeg (depth={depth}, {cfl_blocks} CFL blocks, \
2479 {angle_blocks} nonzero-angle_delta_uv blocks, {uv_overrides} mi-exact UV \
2480 neighbour overrides)"
2481 );
2482 }
2483 assert!(
2484 cfl_blocks > 0,
2485 "{NAME}: no UV_CFL_PRED block decoded (depth={depth}) -- the gate proves nothing"
2486 );
2487 assert!(
2488 angle_blocks > 0,
2489 "{NAME}: no nonzero angle_delta_uv chroma block decoded (depth={depth}) -- \
2490 the chroma intra-edge filter path never ran"
2491 );
2492 assert!(
2493 uv_overrides > 0,
2494 "{NAME}: no chroma edge-filter read ever took a mi-exact UV neighbour that \
2495 disagreed with its coarse 16x16 slot (depth={depth}) -- the r1 defect is \
2496 not exercised"
2497 );
2498 eprintln!(
2499 "{NAME}: pixel-exact at {depth}-bit, cfl_blocks={cfl_blocks} \
2500 angle_delta_uv_blocks={angle_blocks} uv_mi_overrides={uv_overrides}"
2501 );
2502 }
2503 assert!(
2504 compared > 0,
2505 "{NAME}: every arm refused -- the gate compared no pixels at all"
2506 );
2507 }
2508
2509 /// lane-reelckf r1: ReelC's key frames decoded with no refusal and WRONG
2510 /// CHROMA (luma bit-exact at every one of ten seek points), from two
2511 /// defects this gate pins:
2512 ///
2513 /// 1. a SKIPPED intra block whose `uv_mode` is `UV_CFL_PRED` still
2514 /// predicts with the CfL term -- libaom
2515 /// `predict_and_reconstruct_intra_block` (decodeframe.c) calls
2516 /// `av1_predict_intra_block_facade` unconditionally and only guards
2517 /// the residual on `mbmi->skip_txfm`. Three skip arms (the 16x16-level
2518 /// 1:4 chroma pair and the two sub-8x8 4x4 groups) dropped it.
2519 /// 2. the chroma intra-edge FILTER TYPE of a 1:4 pair comes from the
2520 /// CHROMA REFERENCE position (libaom `get_intra_edge_filter_type` ->
2521 /// `chroma_above_mbmi`/`chroma_left_mbmi`), not from the closing
2522 /// strip: at the closing strip the above cell is the pair's own first
2523 /// strip, the mi-exact UV map misses and the coarse fallback answers,
2524 /// which flipped `av1_use_intra_edge_upsample` (blk_wh 12 <= 16 for
2525 /// type 0, no upsample for type 1) and moved directional chroma by
2526 /// +-1..3.
2527 ///
2528 /// Recipe is a real `aomenc --sb-size=128 --cpu-used=0` (the shape ReelC
2529 /// uses) with 1:4 partitions and CfL on, both bit depths, and both
2530 /// counters hard-asserted per compared attempt.
2531 #[test]
2532 fn a_real_aomenc_sb128_stream_whose_skipped_cfl_and_1to4_chroma_pairs_decode_pixel_exact() {
2533 const NAME: &str =
2534 "a_real_aomenc_sb128_stream_whose_skipped_cfl_and_1to4_chroma_pairs_decode_pixel_exact";
2535 let _gate_lock = lock_gate_counters();
2536 if !have_ffmpeg() {
2537 eprintln!("SKIP {NAME}: no ffmpeg");
2538 return;
2539 }
2540 if !have_aomenc() {
2541 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
2542 return;
2543 }
2544 let mut compared = 0usize;
2545 let (width, height) = (256usize, 256usize);
2546 for depth in [8usize, 10] {
2547 let pix = if depth == 10 {
2548 "yuv420p10le"
2549 } else {
2550 "yuv420p"
2551 };
2552 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
2553 .args([
2554 "-v",
2555 "error",
2556 "-f",
2557 "lavfi",
2558 "-i",
2559 &format!(
2560 "mandelbrot=size={width}x{height},\
2561 noise=alls=20:allf=t+u:all_seed=7"
2562 ),
2563 "-pix_fmt",
2564 pix,
2565 "-strict",
2566 "-1",
2567 "-t",
2568 "1",
2569 "-vframes",
2570 "1",
2571 "-f",
2572 "yuv4mpegpipe",
2573 "-",
2574 ])
2575 .stdin(Stdio::null())
2576 .stdout(Stdio::piped())
2577 .stderr(Stdio::piped()), None, |c| c.output())
2578 .expect("ffmpeg failed to run");
2579 assert!(
2580 y4m.status.success(),
2581 "{NAME}: ffmpeg fixture (depth={depth}): {}",
2582 String::from_utf8_lossy(&y4m.stderr)
2583 );
2584 let encode = || {
2585 let out = run_with_stdin(
2586 Command::new(aomenc_path()).args([
2587 "--codec=av1",
2588 "--passes=1",
2589 "--end-usage=q",
2590 "--cq-level=52",
2591 "--cpu-used=0",
2592 "--threads=1",
2593 "--row-mt=0",
2594 "--sb-size=128",
2595 "--kf-max-dist=0",
2596 "--enable-rect-partitions=1",
2597 "--enable-ab-partitions=0",
2598 "--enable-1to4-partitions=1",
2599 "--enable-cfl-intra=1",
2600 "--enable-tx-size-search=0",
2601 "--enable-filter-intra=0",
2602 "--enable-intra-edge-filter=1",
2603 "--reduced-tx-type-set=1",
2604 "--min-partition-size=4",
2605 "--max-partition-size=32",
2606 &format!("--input-bit-depth={depth}"),
2607 &format!("--bit-depth={depth}"),
2608 "--obu",
2609 "-o",
2610 "-",
2611 "-",
2612 ]),
2613 &y4m.stdout,
2614 );
2615 assert!(
2616 out.status.success(),
2617 "aomenc refused the fixture (depth={depth}): {}",
2618 String::from_utf8_lossy(&out.stderr)
2619 );
2620 out.stdout
2621 };
2622 let stream = encode();
2623 assert_eq!(
2624 stream,
2625 encode(),
2626 "{NAME}: aomenc output is not reproducible (depth={depth})"
2627 );
2628 let before = crate::decode::reelc_chroma_counters();
2629 let frames = match decode_stream(&stream) {
2630 Ok(frames) => frames,
2631 Err(e) => {
2632 let msg = e.to_string();
2633 assert!(
2634 msg.contains("unsupported"),
2635 "{NAME}: decode failed (depth={depth}): {msg}"
2636 );
2637 eprintln!("{NAME}: depth={depth} arm refused (not compared): {msg}");
2638 continue;
2639 }
2640 };
2641 compared += 1;
2642 // Counters read only on an attempt that decoded AND is compared.
2643 let after = crate::decode::reelc_chroma_counters();
2644 let (skip_cfl, dir_pairs) = (after.0 - before.0, after.1 - before.1);
2645 // The ENCODE's frame count: the y4m is rendered with `-t 1` and
2646 // `-vframes 1` (28056) -- one frame at the source's default rate 25
2647 // -- and aomenc runs with no `--limit` and `--kf-max-dist=0`
2648 // (28088), so both depths code exactly 1 frame. Asserted ABOVE the
2649 // oracle call.
2650 assert_eq!(frames.len(), 1, "{NAME}: depth={depth} key frame");
2651 let ffmpeg_frames = if depth == 10 {
2652 ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len())
2653 } else {
2654 ffmpeg_decode_sequence(&stream, width, height, frames.len())
2655 };
2656 assert_eq!(
2657 ffmpeg_frames.len(),
2658 frames.len(),
2659 "{NAME}: ffmpeg frame count"
2660 );
2661 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
2662 assert_eq!(got.y, want.y, "{NAME} frame {i} luma (depth={depth})");
2663 assert_eq!(
2664 got.u, want.u,
2665 "{NAME} frame {i} U (depth={depth}, {skip_cfl} skipped-CfL blocks, \
2666 {dir_pairs} directional 1:4 chroma pairs)"
2667 );
2668 assert_eq!(
2669 got.v, want.v,
2670 "{NAME} frame {i} V (depth={depth}, {skip_cfl} skipped-CfL blocks, \
2671 {dir_pairs} directional 1:4 chroma pairs)"
2672 );
2673 }
2674 // Defect 1 (skipped `UV_CFL_PRED`) is NOT asserted here: 20 aomenc
2675 // recipes (cq 40..63, 9 lavfi sources, min/max-partition 4..64,
2676 // both `--sb-size=128` and 64) never made the encoder pick a
2677 // skipped 1:4 / sub-8x8 CfL block, so an assert would only ever
2678 // fire on his real film. Its evidence is ReelC's own key frames
2679 // (lanes/reelckf-r1.report.md): ss=2700 went 499 wrong chroma
2680 // samples -> 0 on this fix alone. The count is printed so a future
2681 // recipe that does reach it is visible immediately. r2 pinned that
2682 // film frame as a fixture instead:
2683 // `a_real_film_key_frame_with_a_skipped_cfl_block_decodes_pixel_exact`
2684 // hard-asserts the counter.
2685 assert!(
2686 dir_pairs > 0,
2687 "{NAME}: no directional 1:4 chroma pair decoded (depth={depth}) -- defect 2 \
2688 is not exercised"
2689 );
2690 eprintln!(
2691 "{NAME}: pixel-exact at {depth}-bit over {} frames, skipped_cfl={skip_cfl} \
2692 directional_1to4_chroma_pairs={dir_pairs}",
2693 frames.len()
2694 );
2695 }
2696 assert!(
2697 compared > 0,
2698 "{NAME}: every arm refused -- the gate compared no pixels at all"
2699 );
2700 }
2701
2702 /// lane-ab16 r1: real `aomenc --enable-ab-partitions=1` streams whose
2703 /// 16x16 blocks are split T-shaped (`PARTITION_HORZ_A`/`_HORZ_B`/
2704 /// `_VERT_A`/`_VERT_B`: two 8x8 squares plus one 16x8/8x16 strip), the
2705 /// refusals "a HORZ_A/HORZ_B/VERT_A partition below 16x16" and "a coded
2706 /// (non-skip) HORZ_B/VERT_B rect strip below 16x16" this round lifts.
2707 /// `--min-partition-size=8 --max-partition-size=16` pins the level so
2708 /// every AB symbol in the stream is a 16x16 one; the squares go through
2709 /// `decode_leaf8`, the strips through `decode_leaf_rect`'s non-skip
2710 /// coefficient path (lane-rectx). The per-arm counter is sampled per
2711 /// attempt and summed only over attempts that actually decoded AND were
2712 /// compared, and EACH of the four arms must have fired -- a run where
2713 /// aomenc's RD only ever picked HORZ_A cannot pass as proof of four
2714 /// ([[gate-blind-to-feature]]). 8-bit and 10-bit; `--tile-columns=1` is
2715 /// NOT among the attempts (base tile defect, reproducer in the r1
2716 /// report), and `--enable-tx-size-search` is left at aomenc's default
2717 /// (ON) -- pinning it off hid a panic in the TX4 sub-grid of an 8x8
2718 /// square inside a `PARTITION_VERT_A`/`_B` (r2).
2719 #[test]
2720 fn a_real_aomenc_stream_with_ab_partitions_below_16x16_decodes_pixel_exact() {
2721 const NAME: &str =
2722 "a_real_aomenc_stream_with_ab_partitions_below_16x16_decodes_pixel_exact";
2723 let _gate_lock = lock_gate_counters();
2724 if !have_ffmpeg() {
2725 eprintln!("SKIP {NAME}: no ffmpeg");
2726 return;
2727 }
2728 if !have_aomenc() {
2729 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
2730 return;
2731 }
2732 struct Attempt {
2733 src: &'static str,
2734 w: usize,
2735 h: usize,
2736 cq: u32,
2737 ten_bit: bool,
2738 tile_cols: u32,
2739 /// Left at aomenc's default (ON) instead of pinned off: reaches
2740 /// the TX4 sub-grid of an 8x8 square inside a
2741 /// `PARTITION_VERT_A`/`_B` (r2's panic), at the cost of the
2742 /// strip-level split transform lane-rectx still refuses.
2743 tx_size_search: bool,
2744 }
2745 // Recipes chosen by a ~200-cell sweep of {source, size, cq} at this
2746 // level (r1 report): one cell per arm that is pixel-exact end to end,
2747 // plus two 10-bit cells. `--tile-columns=1` is deliberately absent --
2748 // it mismatches on blocks that are plain NONE/VERT with no AB symbol
2749 // in the failing superblock, i.e. a base tile defect this lane
2750 // neither introduced nor owns (reproducer pinned in the r1 report).
2751 let attempts = [
2752 Attempt {
2753 src: "yuvtestsrc=size=64x64",
2754 w: 64,
2755 h: 64,
2756 cq: 22,
2757 ten_bit: false,
2758 tile_cols: 0,
2759 tx_size_search: false,
2760 },
2761 Attempt {
2762 src: "rgbtestsrc=size=64x64",
2763 w: 64,
2764 h: 64,
2765 cq: 20,
2766 ten_bit: false,
2767 tile_cols: 0,
2768 tx_size_search: false,
2769 },
2770 Attempt {
2771 src: "rgbtestsrc=size=64x64",
2772 w: 64,
2773 h: 64,
2774 cq: 50,
2775 ten_bit: false,
2776 tile_cols: 0,
2777 tx_size_search: false,
2778 },
2779 Attempt {
2780 src: "mandelbrot=size=64x64:start_x=-1.0",
2781 w: 64,
2782 h: 64,
2783 cq: 14,
2784 ten_bit: false,
2785 tile_cols: 0,
2786 tx_size_search: false,
2787 },
2788 // 10-bit: the only two cells of the sweep that are exact at this
2789 // depth (HORZ_A and VERT_A); the 10-bit HORZ_B/VERT_B cells all
2790 // trip the base chroma defect the r1 report pins, so those two
2791 // arms are proven 8-bit only.
2792 Attempt {
2793 src: "yuvtestsrc=size=64x64",
2794 w: 64,
2795 h: 64,
2796 cq: 30,
2797 ten_bit: true,
2798 tile_cols: 0,
2799 tx_size_search: false,
2800 },
2801 Attempt {
2802 src: "mandelbrot=size=64x64:start_x=0.4",
2803 w: 64,
2804 h: 64,
2805 cq: 30,
2806 ten_bit: true,
2807 tile_cols: 0,
2808 tx_size_search: false,
2809 },
2810 // `--enable-tx-size-search` at aomenc's default: an 8x8 square of
2811 // a VERT_A/VERT_B resolves to a 2x2 grid of TX4 units, which is
2812 // the reach lookup that had no table row and panicked (r2). These
2813 // attempts may legitimately stop at lane-rectx's still-standing
2814 // "strip with a split transform" refusal -- an `unsupported`
2815 // message is tolerated, a panic or a pixel mismatch is not, and
2816 // at least one of them must reach a TX4 unit inside a vertical AB
2817 // partition.
2818 Attempt {
2819 src: "yuvtestsrc=size=64x64",
2820 w: 64,
2821 h: 64,
2822 cq: 55,
2823 ten_bit: false,
2824 tile_cols: 0,
2825 tx_size_search: true,
2826 },
2827 Attempt {
2828 src: "yuvtestsrc=size=64x64",
2829 w: 64,
2830 h: 64,
2831 cq: 22,
2832 ten_bit: false,
2833 tile_cols: 0,
2834 tx_size_search: true,
2835 },
2836 Attempt {
2837 src: "rgbtestsrc=size=64x64",
2838 w: 64,
2839 h: 64,
2840 cq: 20,
2841 ten_bit: false,
2842 tile_cols: 0,
2843 tx_size_search: true,
2844 },
2845 Attempt {
2846 src: "mandelbrot=size=64x64:start_x=-1.0",
2847 w: 64,
2848 h: 64,
2849 cq: 14,
2850 ten_bit: false,
2851 tile_cols: 0,
2852 tx_size_search: true,
2853 },
2854 ];
2855 let mut arms = [0usize; 4];
2856 let mut compared = 0usize;
2857 let mut tx4_reached = 0usize;
2858 let mut tx4_compared = 0usize;
2859 for a in &attempts {
2860 let desc = format!(
2861 "{} cq={} {}bit tiles={}",
2862 a.src,
2863 a.cq,
2864 if a.ten_bit { 10 } else { 8 },
2865 a.tile_cols
2866 );
2867 let mut ff: Vec<String> = vec![
2868 "-v".into(),
2869 "error".into(),
2870 "-f".into(),
2871 "lavfi".into(),
2872 "-i".into(),
2873 a.src.into(),
2874 "-pix_fmt".into(),
2875 if a.ten_bit {
2876 "yuv420p10le".into()
2877 } else {
2878 "yuv420p".into()
2879 },
2880 ];
2881 if a.ten_bit {
2882 ff.push("-strict".into());
2883 ff.push("-1".into());
2884 }
2885 ff.extend([
2886 "-t".into(),
2887 "1".into(),
2888 "-vframes".into(),
2889 "1".into(),
2890 "-f".into(),
2891 "yuv4mpegpipe".into(),
2892 "-".into(),
2893 ]);
2894 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
2895 .args(&ff)
2896 .stdin(Stdio::null())
2897 .stdout(Stdio::piped())
2898 .stderr(Stdio::piped()), None, |c| c.output())
2899 .expect("ffmpeg failed to run");
2900 assert!(
2901 y4m.status.success(),
2902 "ffmpeg fixture {desc}: {}",
2903 String::from_utf8_lossy(&y4m.stderr)
2904 );
2905 let encode = || {
2906 let mut args: Vec<String> = vec![
2907 "--codec=av1".into(),
2908 "--passes=1".into(),
2909 "--end-usage=q".into(),
2910 format!("--cq-level={}", a.cq),
2911 "--cpu-used=4".into(),
2912 "--threads=1".into(),
2913 "--row-mt=0".into(),
2914 "--sb-size=64".into(),
2915 "--kf-max-dist=0".into(),
2916 "--limit=1".into(),
2917 "--enable-rect-partitions=1".into(),
2918 "--enable-ab-partitions=1".into(),
2919 "--enable-1to4-partitions=0".into(),
2920 format!("--enable-tx-size-search={}", u8::from(a.tx_size_search)),
2921 // Filter intra ON a rect strip is a separate, still-refused
2922 // predictor; this gate is about the AB partition wiring.
2923 "--enable-filter-intra=0".into(),
2924 "--reduced-tx-type-set=1".into(),
2925 "--min-partition-size=8".into(),
2926 "--max-partition-size=16".into(),
2927 format!("--tile-columns={}", a.tile_cols),
2928 ];
2929 if a.ten_bit {
2930 args.push("--input-bit-depth=10".into());
2931 args.push("--bit-depth=10".into());
2932 }
2933 args.extend(["--obu".into(), "-o".into(), "-".into(), "-".into()]);
2934 let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
2935 assert!(
2936 out.status.success(),
2937 "aomenc refused {desc}: {}",
2938 String::from_utf8_lossy(&out.stderr)
2939 );
2940 out.stdout
2941 };
2942 let stream = encode();
2943 assert!(
2944 !stream.is_empty(),
2945 "{NAME}: {desc}: aomenc wrote an empty stream"
2946 );
2947 assert_eq!(
2948 stream,
2949 encode(),
2950 "{NAME}: {desc}: aomenc output is not reproducible"
2951 );
2952 let before = crate::decode::ab16_hits_by_arm();
2953 let tx4_before = crate::decode::vert_ab_tx4_hits();
2954 let decoded = decode_stream(&stream);
2955 let tx4_this = crate::decode::vert_ab_tx4_hits() - tx4_before;
2956 // Counted even when the attempt later stops at another lane's
2957 // refusal: reaching this lookup at all is what r2 fixed.
2958 tx4_reached += tx4_this;
2959 let frames = match decoded {
2960 Ok(frames) => frames,
2961 // Only lane-rectx's split-transform strip refusal may stop a
2962 // tx-size-search attempt; a panic never reaches here at all.
2963 Err(e) if a.tx_size_search => {
2964 let msg = e.to_string();
2965 assert!(
2966 msg.contains("unsupported"),
2967 "{NAME}: {desc}: decode failed with a non-refusal error: {msg}"
2968 );
2969 eprintln!("{NAME}: {desc} refused after {tx4_this} vert-AB TX4 units: {msg}");
2970 continue;
2971 }
2972 Err(e) => panic!("{NAME}: {desc}: decode failed, not a pixel mismatch: {e}"),
2973 };
2974 let after = crate::decode::ab16_hits_by_arm();
2975 let this: Vec<usize> = (0..4).map(|i| after[i] - before[i]).collect();
2976 eprintln!("{NAME}: {desc} decoded, arms this attempt={this:?}");
2977 // The ENCODE's frame count: every attempt's y4m is rendered with
2978 // `-t 1` and `-vframes 1` (28367) -- one frame whatever the source's
2979 // rate -- and aomenc carries `--limit=1` (28401), so all six arms
2980 // code exactly 1 frame. Asserted ABOVE the oracle call.
2981 assert_eq!(frames.len(), 1, "{NAME}: {desc} key frame");
2982 let want = if a.ten_bit {
2983 ffmpeg_decode_sequence_10bit(&stream, a.w, a.h, frames.len())
2984 } else {
2985 ffmpeg_decode_sequence(&stream, a.w, a.h, frames.len())
2986 };
2987 assert_eq!(
2988 want.len(),
2989 frames.len(),
2990 "{NAME}: {desc}: ffmpeg frame count"
2991 );
2992 for (i, (got, w)) in frames.iter().zip(&want).enumerate() {
2993 assert_eq!(got.y, w.y, "{NAME}: {desc} frame {i} luma vs ffmpeg");
2994 assert_eq!(got.u, w.u, "{NAME}: {desc} frame {i} U vs ffmpeg");
2995 assert_eq!(got.v, w.v, "{NAME}: {desc} frame {i} V vs ffmpeg");
2996 }
2997 // Counted only now: the attempt decoded AND compared exact.
2998 if a.tx_size_search {
2999 tx4_compared += 1;
3000 eprintln!("{NAME}: {desc} pixel-exact, vert-AB TX4 units={tx4_this}");
3001 continue;
3002 }
3003 for i in 0..4 {
3004 arms[i] += after[i] - before[i];
3005 }
3006 compared += 1;
3007 eprintln!("{NAME}: {desc} pixel-exact");
3008 }
3009 assert_eq!(
3010 compared,
3011 attempts.iter().filter(|a| !a.tx_size_search).count(),
3012 "{NAME}: every fixed-transform attempt must decode and compare"
3013 );
3014 // Until the lane-rectsplitx merge every tx-size-search attempt stopped
3015 // at "a HORZ/VERT intra strip below 16x16 with a split transform", so
3016 // this gate could only claim that the TX4 sub-grid of an 8x8 square
3017 // inside a VERT_A/VERT_B was REACHED (`tx4_reached`, counted even on a
3018 // refused attempt). With per-TU rect prediction those same attempts now
3019 // decode to the end and compare pixel-exact, and they carry no vert-AB
3020 // TX4 unit at all -- the pre-merge nonzero count came from decodes that
3021 // were still desynced when they hit the refusal (class
3022 // counter-from-refused-stream). The full pixel compare is the stronger
3023 // claim and replaces it; the lookup's VALUES stay pinned against libaom
3024 // in `of_tu_keeps_the_ordinary_answer_and_uses_the_block_row_under_vert_ab`.
3025 eprintln!(
3026 "{NAME}: vert-AB TX4 units reached across tx-size-search attempts: {tx4_reached}"
3027 );
3028 let _ = tx4_reached;
3029 assert_eq!(
3030 tx4_compared,
3031 attempts.iter().filter(|a| a.tx_size_search).count(),
3032 "{NAME}: every --enable-tx-size-search=1 attempt must now decode to the end and \
3033 compare pixel-exact (the split-transform strip refusal these used to stop at is \
3034 lifted); the vert-AB TX4 lookup values stay pinned by \
3035 `of_tu_keeps_the_ordinary_answer_and_uses_the_block_row_under_vert_ab`"
3036 );
3037 for (i, arm) in ["HORZ_A", "HORZ_B", "VERT_A", "VERT_B"].iter().enumerate() {
3038 assert!(
3039 arms[i] > 0,
3040 "{NAME}: PARTITION_{arm} at 16x16 never fired across {compared} \
3041 compared streams -- the gate proves nothing about that arm (arms={arms:?})"
3042 );
3043 }
3044 eprintln!(
3045 "{NAME}: pixel-exact on {compared} streams, ab16 arms(HORZ_A,HORZ_B,VERT_A,VERT_B)={arms:?}"
3046 );
3047 }
3048
3049 #[test]
3050 // The recipe SEARCH, not a lane's scratch any more: 9 sources x 7 cq x
3051 // rtx on/off, 28 s measured, and it is the evidence that no aomenc rect-tx
3052 // recipe mismatches -- which is what the un-ignored rect gates rest on.
3053 #[ignore = "recipe search: 9 sources x 7 cq x rtx on/off, 28 s; establishes that no aomenc rect-tx recipe mismatches"]
3054 fn sweep_rectx_recipes() {
3055 let _gate_lock = lock_gate_counters();
3056 let srcs: Vec<String> = vec![
3057 "mandelbrot=size=64x64:start_x=0.4".into(),
3058 "mandelbrot=size=64x64:start_x=-0.6".into(),
3059 "mandelbrot=size=64x64:start_x=0.1".into(),
3060 "mandelbrot=size=128x128:start_x=0.4".into(),
3061 "mandelbrot=size=128x128:start_x=-0.6".into(),
3062 "testsrc2=size=64x64".into(),
3063 "testsrc2=size=128x128".into(),
3064 "rgbtestsrc=size=64x64".into(),
3065 "smptebars=size=128x128".into(),
3066 ];
3067 for start_x in srcs {
3068 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
3069 .args([
3070 "-v",
3071 "error",
3072 "-f",
3073 "lavfi",
3074 "-i",
3075 &start_x,
3076 "-pix_fmt",
3077 "yuv420p",
3078 "-t",
3079 "1",
3080 "-vframes",
3081 "1",
3082 "-f",
3083 "yuv4mpegpipe",
3084 "-",
3085 ])
3086 .stdin(Stdio::null())
3087 .stdout(Stdio::piped())
3088 .stderr(Stdio::piped()), None, |c| c.output())
3089 .expect("ffmpeg");
3090 assert!(y4m.status.success());
3091 let (width, height) = if start_x.contains("128x128") {
3092 (128usize, 128usize)
3093 } else {
3094 (64usize, 64usize)
3095 };
3096 for cq in [16u32, 20, 24, 28, 32, 40, 50] {
3097 for rtx in ["0", "1"] {
3098 let out = run_with_stdin(
3099 Command::new(aomenc_path()).args([
3100 "--codec=av1",
3101 "--passes=1",
3102 "--end-usage=q",
3103 &format!("--cq-level={cq}"),
3104 "--cpu-used=4",
3105 "--threads=1",
3106 "--row-mt=0",
3107 "--sb-size=64",
3108 "--kf-max-dist=0",
3109 "--enable-rect-partitions=1",
3110 "--enable-ab-partitions=0",
3111 "--enable-1to4-partitions=0",
3112 "--enable-tx-size-search=0",
3113 "--enable-cdef=0",
3114 "--enable-restoration=0",
3115 &format!("--reduced-tx-type-set={rtx}"),
3116 "--min-partition-size=8",
3117 "--max-partition-size=32",
3118 "--obu",
3119 "-o",
3120 "-",
3121 "-",
3122 ]),
3123 &y4m.stdout,
3124 );
3125 assert!(out.status.success());
3126 let stream = out.stdout;
3127 let before = crate::decode::rect_leaf_coeff_hits();
3128 let res = decode_stream(&stream);
3129 let fired = crate::decode::rect_leaf_coeff_hits() - before;
3130 match res {
3131 Err(e) => {
3132 eprintln!("x={start_x} cq={cq} rtx={rtx} fired={fired} REFUSED {e}")
3133 }
3134 Ok(frames) => {
3135 // The ENCODE's frame count: the y4m is rendered with
3136 // `-t 1` and `-vframes 1` (28747) -- one frame, and
3137 // the sources carry no explicit `:rate=` so that
3138 // `-vframes` is the binding bound -- and aomenc runs
3139 // with `--kf-max-dist=0` and no `--limit`
3140 // (28782), so all 126 arms code exactly 1 frame.
3141 // This sweep asserts no verdict, but `bad` below is
3142 // the NUMBER of mismatching frames it reports, so a
3143 // decode that showed fewer frames than the wire
3144 // would silently under-report it. Pinned here, above
3145 // the oracle call, for that reason.
3146 assert_eq!(frames.len(), 1, "x={start_x} cq={cq} rtx={rtx} key frame");
3147 let want = ffmpeg_decode_sequence(&stream, width, height, frames.len());
3148 let bad = frames
3149 .iter()
3150 .zip(&want)
3151 .filter(|(g, w)| g.y != w.y || g.u != w.u || g.v != w.v)
3152 .count();
3153 eprintln!(
3154 "x={start_x} cq={cq} rtx={rtx} fired={fired} frames={} mismatched={bad}",
3155 frames.len()
3156 );
3157 if bad == 0 {
3158 continue;
3159 }
3160 let (g, w) = (&frames[0], &want[0]);
3161 for br in 0..height / 8 {
3162 let mut line = String::new();
3163 for bc in 0..width / 8 {
3164 let mut n = 0;
3165 for row in br * 8..br * 8 + 8 {
3166 for col in bc * 8..bc * 8 + 8 {
3167 if g.y[row * width + col] != w.y[row * width + col] {
3168 n += 1;
3169 }
3170 }
3171 }
3172 line.push_str(&format!("{n:4}"));
3173 }
3174 eprintln!(" blk8 row{br}: {line}");
3175 }
3176 }
3177 }
3178 }
3179 }
3180 }
3181 }
3182
3183 /// lane-rectgate r1: every prior gate pins `--enable-rect-partitions=0
3184 /// --enable-ab-partitions=0 --min/max-partition-size=32` so aomenc never
3185 /// gets to choose a real rect/ab split. This charter's premise ("rect
3186 /// HORZ/VERT + HORZ_A/HORZ_B/VERT_A/VERT_B landed during the warp lane")
3187 /// does NOT hold: `decode_frame`'s inter-tile `match part32` only has
3188 /// arms for `PARTITION_NONE`/`SPLIT`/`HORZ_B` -- `HORZ`, `VERT`,
3189 /// `HORZ_A`, `VERT_A`, `VERT_B`, `HORZ_4`, `VERT_4` all fall into the
3190 /// generic "a partition type this encoder never writes" `_` arm. Two
3191 /// recipes were swept empirically (40 attempts each) to characterize the
3192 /// gap:
3193 /// - `--enable-rect-partitions=1 --enable-ab-partitions=1`, no
3194 /// min/max clamp: 0/40 matched -- every attempt hit either the
3195 /// screen-content refusal or a genuinely-unimplemented partition value
3196 /// (1/2/6/7/9 all observed), always somewhere in the 24-frame stream.
3197 /// - Same, but `--enable-1to4-partitions=0` explicit and
3198 /// `--min-partition-size=16`: still 0/40, `value=9` (`VERT_4`)
3199 /// dominates -- this build's `--enable-1to4-partitions=0` does NOT
3200 /// suppress `VERT_4` selection (aomenc-side, confirmed by direct flag
3201 /// toggle; outside this decoder). This recipe (below) restores the
3202 /// `--enable-rect-partitions=0 --min/max-partition-size=32` pin every
3203 /// other gate uses, flipping only `--enable-ab-partitions=1`: matches
3204 /// cleanly (33/40, rest screen-content refusals) but
3205 /// `extended_partition_hits` stayed 0 -- confirmed with the same probe
3206 /// wired into the already-green warp gate too (144 `warp_selected_hits`,
3207 /// 0 `extended_partition_hits`), so `PARTITION_HORZ_B` itself is
3208 /// apparently never chosen by aomenc for this small gradient fixture at
3209 /// `cq-level=45` regardless of clamp. No decode defect (crash or pixel
3210 /// mismatch) was found in any sweep -- every refusal is a correctly
3211 /// named, non-silent "unsupported" error. A refusal or mismatch naming
3212 /// any OTHER already-ported capability (warp, obmc, interintra) still
3213 /// fails the gate outright.
3214 #[test]
3215 fn a_real_aomenc_stream_with_free_partitions_decodes_pixel_exact() {
3216 const NAME: &str = "a_real_aomenc_stream_with_free_partitions_decodes_pixel_exact";
3217 let _gate_lock = lock_gate_counters();
3218 if !have_ffmpeg() {
3219 eprintln!("SKIP {NAME}: no ffmpeg");
3220 return;
3221 }
3222 if !have_aomenc() {
3223 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
3224 return;
3225 }
3226 let (width, height, frame_count) = (64usize, 64usize, 24usize);
3227 let mut named_refusals = 0u32;
3228 let mut matched = 0u32;
3229 let n_attempts: u32 = std::env::var("EC_RECTGATE_ATTEMPTS")
3230 .ok()
3231 .and_then(|s| s.parse().ok())
3232 .unwrap_or(40);
3233 for attempt in 0..n_attempts {
3234 let seed = 42 + attempt;
3235 let duration = frame_count as f64 / 25.0;
3236 let source =
3237 gradients_source(seed, width, height, &format!("duration={duration}:rate=25"));
3238 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
3239 .args([
3240 "-v",
3241 "error",
3242 "-f",
3243 "lavfi",
3244 "-i",
3245 &source,
3246 "-pix_fmt",
3247 "yuv420p",
3248 "-f",
3249 "yuv4mpegpipe",
3250 "-",
3251 ])
3252 .stdin(Stdio::null())
3253 .stdout(Stdio::piped())
3254 .stderr(Stdio::piped()), None, |c| c.output())
3255 .expect("ffmpeg failed to run");
3256 assert!(
3257 y4m.status.success(),
3258 "ffmpeg fixture: {}",
3259 String::from_utf8_lossy(&y4m.stderr)
3260 );
3261 let args: Vec<&str> = vec![
3262 "--codec=av1",
3263 "--passes=1",
3264 "--end-usage=q",
3265 "--cq-level=45",
3266 "--cpu-used=0",
3267 "--kf-max-dist=1000",
3268 "--threads=1",
3269 "--row-mt=0",
3270 "--auto-alt-ref=1",
3271 "--lag-in-frames=16",
3272 "--enable-fwd-kf=0",
3273 "--enable-order-hint=1",
3274 "--enable-warped-motion=1",
3275 "--enable-obmc=1",
3276 "--tune-content=default",
3277 "--enable-masked-comp=0",
3278 "--enable-interintra-comp=0",
3279 "--enable-onesided-comp=0",
3280 "--enable-interintra-wedge=0",
3281 "--enable-smooth-interintra=0",
3282 // lane-rect r2: HORZ/VERT decode for real (rect-flake-1
3283 // byte-exact: size_h + warp dims + OBMC overlap + tx height)
3284 // -- free recipe restored; remaining partition kinds refuse
3285 // by name and skip their seeds.
3286 "--enable-rect-partitions=1",
3287 "--enable-ab-partitions=1",
3288 "--enable-1to4-partitions=0",
3289 "--enable-filter-intra=0",
3290 "--enable-smooth-intra=0",
3291 "--enable-paeth-intra=0",
3292 "--enable-directional-intra=0",
3293 "--enable-angle-delta=0",
3294 "--enable-tx-size-search=0",
3295 "--enable-cdef=0",
3296 "--enable-restoration=0",
3297 "--max-partition-size=32",
3298 "--min-partition-size=16",
3299 "--enable-palette=0",
3300 "--enable-intrabc=0",
3301 "--enable-cfl-intra=0",
3302 "--enable-ref-frame-mvs=0",
3303 "--obu",
3304 "-o",
3305 "-",
3306 "-",
3307 ];
3308 let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
3309 assert!(
3310 out.status.success(),
3311 "aomenc refused the fixture: {}",
3312 String::from_utf8_lossy(&out.stderr)
3313 );
3314 let stream = out.stdout;
3315 let frames = match decode_stream(&stream) {
3316 Err(e) => {
3317 let msg = e.to_string();
3318 assert!(
3319 msg.contains("unsupported"),
3320 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
3321 );
3322 for banned in ["warp", "obmc", "interintra"] {
3323 assert!(
3324 !msg.contains(banned),
3325 "{NAME} refused on {banned} (seed {seed}) -- that capability is \
3326 ported and this recipe does not need it: {msg}"
3327 );
3328 }
3329 named_refusals += 1;
3330 eprintln!("seed {seed} refusal: {msg}");
3331 continue;
3332 }
3333 Ok(frames) => frames,
3334 };
3335 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
3336 assert_eq!(frames.len(), frame_count);
3337 let mismatched = frames
3338 .iter()
3339 .zip(&ffmpeg_frames)
3340 .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
3341 if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
3342 std::fs::write(&path, &stream).expect("writing pinned stream");
3343 eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
3344 }
3345 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
3346 assert_eq!(
3347 got.y, want.y,
3348 "{NAME} frame {i} luma vs ffmpeg (seed {seed})"
3349 );
3350 assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
3351 assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
3352 }
3353 // lane-hidden r2 (class gate-blind-to-hidden-frames): the same
3354 // stream again, comparing EVERY decode-order frame -- the hidden
3355 // (show_frame == 0) alt-ref frames the ffmpeg compare above
3356 // cannot see, because both sides of it emit shown frames only.
3357 let (hidden_total, hidden_n) = decode_all_frames_vs_oracle(&stream, NAME);
3358 eprintln!(
3359 "{NAME} HIDDEN: seed {seed}: {hidden_total} decode-order frames, \
3360 {hidden_n} hidden, all pixel-exact vs the oracle"
3361 );
3362 // lane-hidden r2 SECOND ARM (the recipe above is untouched):
3363 // libaom's temporal alt-ref filter absorbs this recipe's hidden
3364 // frames, so the compare above is vacuous -- re-encode the same
3365 // fixture with --arnr-maxframes=0 and compare THOSE.
3366 if let Some((arm_total, arm_hidden)) = hidden_arnr_arm(NAME, &y4m.stdout, &args) {
3367 eprintln!(
3368 "{NAME} HIDDEN-ARM(--arnr-maxframes=0): seed {seed}: {arm_total} \
3369 decode-order frames, {arm_hidden} hidden, all pixel-exact vs the oracle"
3370 );
3371 }
3372 matched += 1;
3373 }
3374 assert!(
3375 matched > 0,
3376 "{NAME}: every attempt refused; the gate never decoded a free-partition stream"
3377 );
3378 // lane-partitions r1: HORZ/VERT arms landed, so the diversity probe
3379 // graduates from rectgate r1's eprintln to a report line on
3380 // `rect_partition_hits`; a zero-hit run SOFT-reports (aomenc RD may
3381 // legitimately never pick a rect split in a small window -- same
3382 // sampling caveat as the masked-compound gate's zero-hit runs).
3383 // `extended_partition_hits` (HORZ_B) stays unasserted per rectgate r1.
3384 if crate::decode::rect_partition_hits() == 0 {
3385 eprintln!(
3386 "{NAME}: SOFT-NOTE -- zero HORZ/VERT strips fired this run \
3387 ({matched} matches, {named_refusals} refusals); sampling, not a regression"
3388 );
3389 } else {
3390 // r5: the desync was the tx-depth symbol being read
3391 // unconditionally where both square paths gate it on `tx_select`
3392 // -- with --enable-tx-size-search=0 the encoder writes no such
3393 // symbol and the decoder consumed one that was never there. With
3394 // that fixed the real coefficient decode is pixel-exact, so this
3395 // is a HARD assert again: strips fired but no coefficients read
3396 // would mean the coded path silently stopped being exercised.
3397 assert!(
3398 crate::decode::rect_coeff_hits() > 0,
3399 "{NAME}: {} HORZ/VERT strips fired but rect_coeff_hits==0 -- the \
3400 coded rect path is no longer exercised",
3401 crate::decode::rect_partition_hits()
3402 );
3403 }
3404 eprintln!(
3405 "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of {n_attempts}, rect_partition_hits={} rect_coeff_hits={} extended_partition_hits={} partab_hits={}",
3406 crate::decode::rect_partition_hits(),
3407 crate::decode::rect_coeff_hits(),
3408 crate::decode::extended_partition_hits(),
3409 crate::decode::partab_hits()
3410 );
3411 }
3412
3413 /// lane-partab r1: `--enable-ab-partitions=1` (aomenc default-on) INTER
3414 /// streams must consume PARTITION_HORZ_A/VERT_A/VERT_B entropy-exact AND
3415 /// decode pixel-exact -- `partab_hits() > 0` is soft-skipped on a
3416 /// zero-hit run (aomenc RD may legitimately never pick an AB split in a
3417 /// small window, same sampling caveat as wedge/rect). The INTER AB
3418 /// refusal is FORBIDDEN (decode.rs names it "an INTER 32x32 partition
3419 /// ..."); intra-frame AB refusals stay accepted named refusals -- the
3420 /// intra dispatch is a later lane. Recipe = the free-partition gate's,
3421 /// which fires AB live (r1: partab_hits 6/2/4/3/1/5 over six
3422 /// 40-attempt runs).
3423 #[test]
3424 fn a_real_aomenc_stream_with_ab_partitions_decodes_pixel_exact() {
3425 const NAME: &str = "a_real_aomenc_stream_with_ab_partitions_decodes_pixel_exact";
3426 let _gate_lock = lock_gate_counters();
3427 if !have_ffmpeg() {
3428 eprintln!("SKIP {NAME}: no ffmpeg");
3429 return;
3430 }
3431 if !have_aomenc() {
3432 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
3433 return;
3434 }
3435 let (width, height, frame_count) = (64usize, 64usize, 24usize);
3436 let mut named_refusals = 0u32;
3437 let mut matched = 0u32;
3438 let n_attempts: u32 = std::env::var("EC_RECTGATE_ATTEMPTS")
3439 .ok()
3440 .and_then(|s| s.parse().ok())
3441 .unwrap_or(40);
3442 for attempt in 0..n_attempts {
3443 let seed = 42 + attempt;
3444 let duration = frame_count as f64 / 25.0;
3445 let source =
3446 gradients_source(seed, width, height, &format!("duration={duration}:rate=25"));
3447 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
3448 .args([
3449 "-v",
3450 "error",
3451 "-f",
3452 "lavfi",
3453 "-i",
3454 &source,
3455 "-pix_fmt",
3456 "yuv420p",
3457 "-f",
3458 "yuv4mpegpipe",
3459 "-",
3460 ])
3461 .stdin(Stdio::null())
3462 .stdout(Stdio::piped())
3463 .stderr(Stdio::piped()), None, |c| c.output())
3464 .expect("ffmpeg failed to run");
3465 assert!(
3466 y4m.status.success(),
3467 "ffmpeg fixture: {}",
3468 String::from_utf8_lossy(&y4m.stderr)
3469 );
3470 let args: Vec<&str> = vec![
3471 "--codec=av1",
3472 "--passes=1",
3473 "--end-usage=q",
3474 "--cq-level=45",
3475 "--cpu-used=0",
3476 "--kf-max-dist=1000",
3477 "--threads=1",
3478 "--row-mt=0",
3479 "--auto-alt-ref=1",
3480 "--lag-in-frames=16",
3481 "--enable-fwd-kf=0",
3482 "--enable-order-hint=1",
3483 "--enable-warped-motion=1",
3484 "--enable-obmc=1",
3485 "--tune-content=default",
3486 "--enable-masked-comp=0",
3487 "--enable-interintra-comp=0",
3488 "--enable-onesided-comp=0",
3489 "--enable-interintra-wedge=0",
3490 "--enable-smooth-interintra=0",
3491 // lane-rect r2 recipe, kept byte-identical by lane-partab
3492 // r1: free partition search, 1to4 off, intra tools off.
3493 "--enable-rect-partitions=1",
3494 "--enable-ab-partitions=1",
3495 "--enable-1to4-partitions=0",
3496 "--enable-filter-intra=0",
3497 "--enable-smooth-intra=0",
3498 "--enable-paeth-intra=0",
3499 "--enable-directional-intra=0",
3500 "--enable-angle-delta=0",
3501 "--enable-tx-size-search=0",
3502 "--enable-cdef=0",
3503 "--enable-restoration=0",
3504 "--max-partition-size=32",
3505 "--min-partition-size=16",
3506 "--enable-palette=0",
3507 "--enable-intrabc=0",
3508 "--enable-cfl-intra=0",
3509 "--enable-ref-frame-mvs=0",
3510 "--obu",
3511 "-o",
3512 "-",
3513 "-",
3514 ];
3515 let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
3516 assert!(
3517 out.status.success(),
3518 "aomenc refused the fixture: {}",
3519 String::from_utf8_lossy(&out.stderr)
3520 );
3521 let stream = out.stdout;
3522 let frames = match decode_stream(&stream) {
3523 Err(e) => {
3524 let msg = e.to_string();
3525 assert!(
3526 msg.contains("unsupported"),
3527 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
3528 );
3529 for banned in ["warp", "obmc", "interintra"] {
3530 assert!(
3531 !msg.contains(banned),
3532 "{NAME} refused on {banned} (seed {seed}) -- that capability is \
3533 ported and this recipe does not need it: {msg}"
3534 );
3535 }
3536 for v in [4, 6, 7] {
3537 assert!(
3538 !msg.contains(&format!(
3539 "an INTER 32x32 partition type this encoder never writes \
3540 (value={v})"
3541 )),
3542 "{NAME} refused an INTER AB partition (value={v}, seed {seed}) -- \
3543 all three AB arms are ported, this refusal is forbidden: {msg}"
3544 );
3545 }
3546 named_refusals += 1;
3547 eprintln!("seed {seed} refusal: {msg}");
3548 continue;
3549 }
3550 Ok(frames) => frames,
3551 };
3552 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
3553 assert_eq!(frames.len(), frame_count);
3554 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
3555 assert_eq!(
3556 got.y, want.y,
3557 "{NAME} frame {i} luma vs ffmpeg (seed {seed})"
3558 );
3559 assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
3560 assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
3561 }
3562 // lane-hidden r2 (class gate-blind-to-hidden-frames): the same
3563 // stream again, comparing EVERY decode-order frame -- the hidden
3564 // (show_frame == 0) alt-ref frames the ffmpeg compare above
3565 // cannot see, because both sides of it emit shown frames only.
3566 let (hidden_total, hidden_n) = decode_all_frames_vs_oracle(&stream, NAME);
3567 eprintln!(
3568 "{NAME} HIDDEN: seed {seed}: {hidden_total} decode-order frames, \
3569 {hidden_n} hidden, all pixel-exact vs the oracle"
3570 );
3571 // lane-hidden r2 SECOND ARM (the recipe above is untouched):
3572 // libaom's temporal alt-ref filter absorbs this recipe's hidden
3573 // frames, so the compare above is vacuous -- re-encode the same
3574 // fixture with --arnr-maxframes=0 and compare THOSE.
3575 if let Some((arm_total, arm_hidden)) = hidden_arnr_arm(NAME, &y4m.stdout, &args) {
3576 eprintln!(
3577 "{NAME} HIDDEN-ARM(--arnr-maxframes=0): seed {seed}: {arm_total} \
3578 decode-order frames, {arm_hidden} hidden, all pixel-exact vs the oracle"
3579 );
3580 }
3581 matched += 1;
3582 }
3583 assert!(
3584 matched > 0,
3585 "{NAME}: every attempt refused; the gate never decoded a stream"
3586 );
3587 if crate::decode::partab_hits() == 0 {
3588 eprintln!(
3589 "{NAME}: SOFT-NOTE -- zero AB partitions fired this run \
3590 ({matched} matches, {named_refusals} refusals); sampling, not a regression"
3591 );
3592 }
3593 eprintln!(
3594 "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of {n_attempts}, partab_hits={}",
3595 crate::decode::partab_hits()
3596 );
3597 }
3598
3599 /// lane-ab32 r1: the 32x32-level AB arms (`PARTITION_HORZ_A`/`_HORZ_B`/
3600 /// `_VERT_A`/`_VERT_B` -- two 16x16 squares plus one 32x16/16x32 strip)
3601 /// are decoded on the INTRA path (decode.rs `PARTITION_HORZ_A` .. the
3602 /// 32x32 refusal) but nothing asserted they fire: the INTER AB gate above
3603 /// only SOFT-notes `partab_hits`, and the four per-arm counters
3604 /// lane-part32 added had no consumer at all (class
3605 /// `refusal-lifted-without-a-gate`). This drives a real key-frame-only
3606 /// aomenc at `--enable-ab-partitions=1 --enable-rect-partitions=1
3607 /// --sb-size=64 --min-partition-size=16 --max-partition-size=32`, so every
3608 /// AB split aomenc picks is a 32-level one, pixel-compares every
3609 /// successful decode against ffmpeg's decode of the same bytes, and
3610 /// hard-asserts each arm fired at least once over the seed sweep --
3611 /// counting deltas only from attempts that decoded AND compared (class
3612 /// `counter-from-refused-stream`).
3613 #[test]
3614 fn a_real_aomenc_stream_with_a_32_level_ab_partition_decodes_pixel_exact() {
3615 const NAME: &str = "a_real_aomenc_stream_with_a_32_level_ab_partition_decodes_pixel_exact";
3616 let _gate_lock = lock_gate_counters();
3617 if !have_ffmpeg() {
3618 eprintln!("SKIP {NAME}: no ffmpeg");
3619 return;
3620 }
3621 if !have_aomenc() {
3622 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
3623 return;
3624 }
3625 let (width, height) = (256usize, 256usize);
3626 let arms: [(&str, fn() -> usize); 4] = [
3627 ("HORZ_A_32", crate::decode::intra_horz_a_hits),
3628 ("HORZ_B_32", crate::decode::intra_horz_b_hits),
3629 ("VERT_A_32", crate::decode::intra_vert_a_hits),
3630 ("VERT_B_32", crate::decode::intra_vert_b_hits),
3631 ];
3632 let mut totals = [0usize; 4];
3633 let mut refusals: Vec<String> = Vec::new();
3634 let mut compared = 0usize;
3635 for &seed in &LR_SEEDS {
3636 // Smooth gradients code as PARTITION_NONE everywhere (r1: 16/16
3637 // attempts decoded pixel-exact with zero AB hits), so the fixture
3638 // carries seeded noise to give the intra RD a reason to split.
3639 let source = format!(
3640 "{},noise=alls=40:all_seed={seed}",
3641 gradients_source(seed, width, height, "duration=0.04:rate=25")
3642 );
3643 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
3644 .args([
3645 "-v",
3646 "error",
3647 "-f",
3648 "lavfi",
3649 "-i",
3650 &source,
3651 "-frames:v",
3652 "1",
3653 "-pix_fmt",
3654 "yuv420p",
3655 "-f",
3656 "yuv4mpegpipe",
3657 "-",
3658 ])
3659 .stdin(Stdio::null())
3660 .stdout(Stdio::piped())
3661 .stderr(Stdio::piped()), None, |c| c.output())
3662 .expect("ffmpeg failed to run");
3663 assert!(
3664 y4m.status.success(),
3665 "{NAME}: ffmpeg fixture (seed {seed}): {}",
3666 String::from_utf8_lossy(&y4m.stderr)
3667 );
3668 // The flags under test come LAST: aomenc keeps the LAST
3669 // occurrence of a repeated flag (measured 2026-09-02 by md5 of
3670 // four orderings), so an override appended after the base recipe
3671 // is the one that lands. Nothing here is repeated, and each of the
3672 // four arm counters below proves the AB flag actually arrived.
3673 let args: Vec<&str> = vec![
3674 "--codec=av1",
3675 "--passes=1",
3676 "--end-usage=q",
3677 "--cq-level=45",
3678 "--cpu-used=0",
3679 "--limit=1",
3680 "--kf-max-dist=0",
3681 "--lag-in-frames=0",
3682 "--threads=1",
3683 "--row-mt=0",
3684 "--enable-1to4-partitions=0",
3685 "--enable-filter-intra=0",
3686 "--enable-smooth-intra=0",
3687 "--enable-paeth-intra=0",
3688 "--enable-directional-intra=0",
3689 "--enable-angle-delta=0",
3690 "--enable-tx-size-search=0",
3691 "--enable-cdef=0",
3692 "--enable-restoration=0",
3693 "--enable-palette=0",
3694 "--enable-intrabc=0",
3695 "--enable-cfl-intra=0",
3696 "--enable-ref-frame-mvs=0",
3697 "--sb-size=64",
3698 "--enable-rect-partitions=1",
3699 "--enable-ab-partitions=1",
3700 "--min-partition-size=16",
3701 "--max-partition-size=32",
3702 "--obu",
3703 "-o",
3704 "-",
3705 "-",
3706 ];
3707 let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
3708 assert!(
3709 out.status.success(),
3710 "aomenc refused the fixture (seed {seed}): {}",
3711 String::from_utf8_lossy(&out.stderr)
3712 );
3713 let stream = out.stdout;
3714 let before: Vec<usize> = arms.iter().map(|(_, f)| f()).collect();
3715 let frames = match decode_stream(&stream) {
3716 Err(e) => {
3717 let msg = e.to_string();
3718 assert!(
3719 msg.contains("unsupported"),
3720 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
3721 );
3722 for v in [4, 5, 6, 7] {
3723 assert!(
3724 !msg.contains(&format!(
3725 "a 32x32 partition type this decoder does not code (value={v})"
3726 )),
3727 "{NAME} refused a 32-level AB partition (value={v}, seed {seed}) -- \
3728 all four arms are ported, this refusal is forbidden: {msg}"
3729 );
3730 }
3731 refusals.push(format!("seed {seed}: {msg}"));
3732 continue;
3733 }
3734 Ok(frames) => frames,
3735 };
3736 let deltas: Vec<usize> = arms
3737 .iter()
3738 .zip(before.iter())
3739 .map(|((_, f), b)| f() - b)
3740 .collect();
3741 let fired: Vec<String> = arms
3742 .iter()
3743 .zip(deltas.iter())
3744 .map(|((label, _), d)| format!("{label}={d}"))
3745 .collect();
3746 let fired = fired.join(" ");
3747 // The ENCODE's frame count: `gradients_source` (6015) is rendered with
3748 // `duration=0.04:rate=25` (29116) and `-frames:v 1` (29119) caps the
3749 // y4m at one frame; aomenc runs with `--limit=1` and
3750 // `--kf-max-dist=0` (29150) and so codes exactly that one. Asserted
3751 // ABOVE the oracle call -- it holds for every one of the 16 seeds.
3752 assert_eq!(frames.len(), 1, "{NAME}: seed {seed} key frame");
3753 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len());
3754 assert_eq!(
3755 frames.len(),
3756 ffmpeg_frames.len(),
3757 "{NAME}: seed {seed}: shown-frame count vs ffmpeg"
3758 );
3759 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
3760 assert_eq!(
3761 got.y, want.y,
3762 "{NAME} frame {i} luma vs ffmpeg (seed {seed}) [{fired}]"
3763 );
3764 assert_eq!(
3765 got.u, want.u,
3766 "{NAME} frame {i} U vs ffmpeg (seed {seed}) [{fired}]"
3767 );
3768 assert_eq!(
3769 got.v, want.v,
3770 "{NAME} frame {i} V vs ffmpeg (seed {seed}) [{fired}]"
3771 );
3772 }
3773 compared += 1;
3774 for (i, d) in deltas.iter().enumerate() {
3775 totals[i] += d;
3776 }
3777 }
3778 assert!(
3779 compared > 0,
3780 "{NAME}: every attempt hit a named refusal:\n{}",
3781 refusals.join("\n")
3782 );
3783 for (i, (label, _)) in arms.iter().enumerate() {
3784 assert!(
3785 totals[i] > 0,
3786 "{NAME}: {compared} attempt(s) decoded pixel-exact but {label} never fired -- \
3787 the gate would prove nothing about that arm. refusals:\n{}",
3788 refusals.join("\n")
3789 );
3790 }
3791 eprintln!(
3792 "{NAME}: {compared}/{} attempts pixel-exact, HORZ_A_32={} HORZ_B_32={} \
3793 VERT_A_32={} VERT_B_32={}, {} named refusals",
3794 LR_SEEDS.len(),
3795 totals[0],
3796 totals[1],
3797 totals[2],
3798 totals[3],
3799 refusals.len()
3800 );
3801 }
3802
3803 /// lane-ab32 r1: the 10-bit twin of the gate above -- his two films are
3804 /// yuv420p10le, so an 8-bit-only AB gate proves nothing about the streams
3805 /// that matter. Same recipe through [`ten_bit_tool_gate`], which sums the
3806 /// per-arm counters only over attempts that decoded and pixel-compared.
3807 #[test]
3808 fn a_real_aomenc_10bit_stream_with_a_32_level_ab_partition_decodes_pixel_exact() {
3809 const NAME: &str =
3810 "a_real_aomenc_10bit_stream_with_a_32_level_ab_partition_decodes_pixel_exact";
3811 if !have_ffmpeg() {
3812 eprintln!("SKIP {NAME}: no ffmpeg");
3813 return;
3814 }
3815 if !have_aomenc() {
3816 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
3817 return;
3818 }
3819 ten_bit_tool_gate(
3820 NAME,
3821 256,
3822 256,
3823 1,
3824 &[
3825 "--ec-fixture-noise",
3826 "--cq-level=45",
3827 "--limit=1",
3828 "--kf-max-dist=0",
3829 "--enable-1to4-partitions=0",
3830 "--enable-filter-intra=0",
3831 "--enable-smooth-intra=0",
3832 "--enable-paeth-intra=0",
3833 "--enable-directional-intra=0",
3834 "--enable-angle-delta=0",
3835 "--enable-tx-size-search=0",
3836 "--enable-cdef=0",
3837 "--enable-restoration=0",
3838 "--enable-palette=0",
3839 "--enable-intrabc=0",
3840 "--enable-cfl-intra=0",
3841 "--enable-ref-frame-mvs=0",
3842 // last wins: the flags under test go after the base recipe
3843 "--enable-rect-partitions=1",
3844 "--enable-ab-partitions=1",
3845 "--min-partition-size=16",
3846 "--max-partition-size=32",
3847 ],
3848 &LR_SEEDS,
3849 &[
3850 ("HORZ_A_32", crate::decode::intra_horz_a_hits),
3851 ("HORZ_B_32", crate::decode::intra_horz_b_hits),
3852 ("VERT_A_32", crate::decode::intra_vert_a_hits),
3853 ("VERT_B_32", crate::decode::intra_vert_b_hits),
3854 ],
3855 );
3856 }
3857
3858 /// 8-bit arm of [`run_fimv_motion_mode_gate`].
3859 #[test]
3860 fn a_real_force_integer_mv_warp_stream_decodes_pixel_exact() {
3861 run_fimv_motion_mode_gate(
3862 "a_real_force_integer_mv_warp_stream_decodes_pixel_exact",
3863 false,
3864 );
3865 }
3866
3867 /// 10-bit arm of [`run_fimv_motion_mode_gate`] -- both of his films are
3868 /// `yuv420p10le`.
3869 #[test]
3870 fn a_real_force_integer_mv_warp_10bit_stream_decodes_pixel_exact() {
3871 run_fimv_motion_mode_gate(
3872 "a_real_force_integer_mv_warp_10bit_stream_decodes_pixel_exact",
3873 true,
3874 );
3875 }
3876
3877 /// 8-bit arm of [`run_compound_global_warp_gate`].
3878 #[test]
3879 fn a_real_compound_global_warp_stream_decodes_pixel_exact() {
3880 run_compound_global_warp_gate(
3881 "a_real_compound_global_warp_stream_decodes_pixel_exact",
3882 8,
3883 32,
3884 false,
3885 );
3886 }
3887
3888 /// 10-bit arm of [`run_compound_global_warp_gate`] -- both of his films are
3889 /// `yuv420p10le`, and `warp_affine`'s `bd` was hardcoded 8 before r1.
3890 ///
3891 /// Un-ignored 2026-09-04: the pre-existing 10-bit compound MC defect that blocked it is gone. Ablation run by lane-cwarp r1 on this
3892 /// very recipe: with `--enable-global-motion=0 --enable-warped-motion=0`
3893 /// (no warp of any kind reachable) the 10-bit stream STILL mismatches at
3894 /// frame 1 luma, cq 32; with `--auto-alt-ref=0 --lag-in-frames=0
3895 /// --enable-dist-wtd-comp=0` (single-reference 10-bit inter only) the same
3896 /// recipe is 6/6 pixel-exact. So: 10-bit single-ref inter is exact, 10-bit
3897 /// compound is not. `mc::diffwtd_mask`'s missing `(bd - 8)` round term was
3898 /// found and fixed while bisecting this, but is NOT the whole defect.
3899 /// The warp wiring under test here is bit-depth generic.
3900 #[test]
3901 fn a_real_compound_global_warp_10bit_stream_decodes_pixel_exact() {
3902 run_compound_global_warp_gate(
3903 "a_real_compound_global_warp_10bit_stream_decodes_pixel_exact",
3904 10,
3905 32,
3906 false,
3907 );
3908 }
3909
3910 /// 12-bit arm of [`run_compound_global_warp_gate`] (lane-av112bitw): the
3911 /// same rotating-mandelbrot recipe at `--bit-depth=12`. Pre-lift the
3912 /// first `GLOBAL_GLOBALMV` block under a ROTZOOM model refused ("warped
3913 /// motion at 12 bits"); the lift runs the same `warp::warp_round_0` bump
3914 /// through `warp_affine_compound` (`reduce_bits_horiz` 5, compound
3915 /// `reduce_bits_vert` stays 7, the CONV_BUF blend bias one octave down:
3916 /// `(1 << (bd + 2)) + (1 << (bd + 1))`).
3917 #[test]
3918 fn a_real_compound_global_warp_12bit_stream_decodes_pixel_exact() {
3919 run_compound_global_warp_gate(
3920 "a_real_compound_global_warp_12bit_stream_decodes_pixel_exact",
3921 12,
3922 32,
3923 false,
3924 );
3925 }
3926
3927 /// 12-bit 8x8 compound-warp LEAF arm (lane-av112bitw, reviewer gap): the
3928 /// same recipe with the 32x32 partition pin dropped to min 8, so the RD
3929 /// can code an 8x8 `GLOBAL_GLOBALMV` leaf whose two references warp per
3930 /// slot -- `decode_inter_block8`'s `COMPOUND_WARP_HITS_8` path, which
3931 /// the 32x32-pinned compound witness structurally cannot reach. Hard-
3932 /// asserts `compound_warp_hits_8() > 0` (an 8x8 compound warp leaf bumps
3933 /// it alongside [`decode::compound_warp_hits`]; a 16x16+ one cannot), so
3934 /// a stream of only bigger warped blocks fails this gate.
3935 #[test]
3936 fn a_real_compound_global_warp_12bit_8x8_leaf_stream_decodes_pixel_exact() {
3937 run_compound_global_warp_gate(
3938 "a_real_compound_global_warp_12bit_8x8_leaf_stream_decodes_pixel_exact",
3939 12,
3940 8,
3941 true,
3942 );
3943 }
3944
3945 /// 8-bit arm of [`run_diffwtd_inferred_64x64_gate`].
3946 #[test]
3947 fn a_real_aomenc_stream_with_a_diffwtd_compound_64x64_block_decodes_pixel_exact() {
3948 run_diffwtd_inferred_64x64_gate(
3949 "a_real_aomenc_stream_with_a_diffwtd_compound_64x64_block_decodes_pixel_exact",
3950 false,
3951 );
3952 }
3953
3954 /// 10-bit arm of [`run_diffwtd_inferred_64x64_gate`] -- both of his films
3955 /// are `yuv420p10le`.
3956 #[test]
3957 fn a_real_aomenc_10bit_stream_with_a_diffwtd_compound_64x64_block_decodes_pixel_exact() {
3958 run_diffwtd_inferred_64x64_gate(
3959 "a_real_aomenc_10bit_stream_with_a_diffwtd_compound_64x64_block_decodes_pixel_exact",
3960 true,
3961 );
3962 }
3963
3964 /// lane-maskcomp r2 / lane-wedge r3: `--enable-masked-comp=1` streams
3965 /// must consume `compound_type`/`wedge_idx`/`wedge_sign`/`mask_type`
3966 /// entropy-exact AND build the real blend, DIFFWTD or WEDGE --
3967 /// `masked_compound_hits() > 0` is a hard assert and BOTH
3968 /// `COMPOUND_DIFFWTD` and `COMPOUND_WEDGE` refusals are now FORBIDDEN
3969 /// (matches interintra's own gate). r3: `--enable-dist-wtd-comp=0`
3970 /// (forces the masked choice toward wedge when comp_group_idx==1) plus
3971 /// a hard-diagonal-edge `geq` source (wedge's OBLIQUE directions favor
3972 /// a real diagonal edge over the r2 gradients content) to fire
3973 /// COMPOUND_WEDGE live; `wedge_hits()` is soft-skipped (not hard
3974 /// asserted) on a zero-hit run -- the recipe search is not proven to
3975 /// converge every run, see charter's "if no recipe fires" fallback.
3976 #[test]
3977 fn a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact() {
3978 const NAME: &str = "a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact";
3979 let _gate_lock = lock_gate_counters();
3980 if !have_ffmpeg() {
3981 eprintln!("SKIP {NAME}: no ffmpeg");
3982 return;
3983 }
3984 if !have_aomenc() {
3985 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
3986 return;
3987 }
3988 let (width, height, frame_count) = (64usize, 64usize, 24usize);
3989 let mut named_refusals = 0u32;
3990 let mut matched = 0u32;
3991 let n_attempts: u32 = std::env::var("EC_MASKCOMP_GATE_ATTEMPTS")
3992 .ok()
3993 .and_then(|s| s.parse().ok())
3994 .unwrap_or(80);
3995 for attempt in 0..n_attempts {
3996 let seed = 42 + attempt;
3997 let duration = frame_count as f64 / 25.0;
3998 // lane-wedge r3: a hard diagonal edge (not a smooth gradient)
3999 // is the content wedge's OBLIQUE master masks are shaped for --
4000 // `mandelbrot`'s pan position varies the edge angle/position
4001 // across attempts the way the r2 gradients seed did.
4002 let source = format!(
4003 "mandelbrot=size={width}x{height}:rate=25:start_x={sx}:start_y={sy}",
4004 sx = -0.6 + 0.005 * (attempt as f64),
4005 sy = -0.4 + 0.005 * (attempt as f64)
4006 );
4007 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
4008 .args([
4009 "-v",
4010 "error",
4011 "-f",
4012 "lavfi",
4013 "-i",
4014 &source,
4015 "-t",
4016 &duration.to_string(),
4017 "-pix_fmt",
4018 "yuv420p",
4019 "-f",
4020 "yuv4mpegpipe",
4021 "-",
4022 ])
4023 .stdin(Stdio::null())
4024 .stdout(Stdio::piped())
4025 .stderr(Stdio::piped()), None, |c| c.output())
4026 .expect("ffmpeg failed to run");
4027 assert!(
4028 y4m.status.success(),
4029 "ffmpeg fixture: {}",
4030 String::from_utf8_lossy(&y4m.stderr)
4031 );
4032 let args: Vec<&str> = vec![
4033 // lane-defon r1: explicit on-value (aomenc keeps the FIRST
4034 // occurrence, so overrides go before the base list).
4035 "--enable-diff-wtd-comp=1",
4036 "--codec=av1",
4037 "--passes=1",
4038 "--end-usage=q",
4039 "--cq-level=45",
4040 "--cpu-used=0",
4041 "--kf-max-dist=1000",
4042 "--threads=1",
4043 "--row-mt=0",
4044 "--auto-alt-ref=1",
4045 "--lag-in-frames=16",
4046 "--enable-fwd-kf=0",
4047 "--enable-order-hint=1",
4048 "--enable-warped-motion=1",
4049 // r3: mandelbrot's pan/zoom triggers aomenc's single-ref
4050 // GLOBALMV global-motion search (a capability distinct from
4051 // and outside this lane's scope) -- off, matching this
4052 // gate's own goal of exercising masked compound, not GM.
4053 "--enable-global-motion=0",
4054 "--enable-obmc=1",
4055 "--tune-content=default",
4056 "--enable-masked-comp=1",
4057 // r3: force the masked choice toward wedge (r2 always set
4058 // this =1; distance-weighted compound competes with the
4059 // wedge/diffwtd choice for the same comp_group_idx==1 slot).
4060 "--enable-dist-wtd-comp=0",
4061 "--enable-interintra-comp=1",
4062 "--enable-onesided-comp=0",
4063 "--enable-interintra-wedge=0",
4064 "--enable-smooth-interintra=1",
4065 "--enable-rect-partitions=0",
4066 "--enable-ab-partitions=0",
4067 "--enable-1to4-partitions=0",
4068 "--enable-filter-intra=0",
4069 "--enable-smooth-intra=0",
4070 "--enable-paeth-intra=0",
4071 "--enable-directional-intra=0",
4072 "--enable-angle-delta=0",
4073 "--enable-tx-size-search=0",
4074 "--enable-cdef=0",
4075 "--enable-restoration=0",
4076 "--max-partition-size=32",
4077 "--min-partition-size=32",
4078 "--enable-palette=0",
4079 "--enable-intrabc=0",
4080 "--enable-cfl-intra=0",
4081 "--enable-ref-frame-mvs=0",
4082 "--obu",
4083 "-o",
4084 "-",
4085 "-",
4086 ];
4087 let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
4088 assert!(
4089 out.status.success(),
4090 "aomenc refused the fixture: {}",
4091 String::from_utf8_lossy(&out.stderr)
4092 );
4093 let stream = out.stdout;
4094 let frames = match decode_stream(&stream) {
4095 Err(e) => {
4096 let msg = e.to_string();
4097 assert!(
4098 msg.contains("unsupported"),
4099 "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
4100 );
4101 assert!(
4102 !msg.contains("warp"),
4103 "{NAME} refused on warp (seed {seed}) -- warp decode is ported: {msg}"
4104 );
4105 assert!(
4106 !msg.contains("masked COMPOUND_REFERENCE"),
4107 "{NAME} refused a masked-compound block (seed {seed}) -- both DIFFWTD \
4108 and WEDGE blends are ported, this refusal is forbidden: {msg}"
4109 );
4110 assert!(
4111 !msg.contains("interintra"),
4112 "{NAME} refused on interintra (seed {seed}) -- non-wedge \
4113 interintra is ported: {msg}"
4114 );
4115 named_refusals += 1;
4116 eprintln!("seed {seed} refusal: {msg}");
4117 if std::env::var_os("EC_AV1_GATE_DUMP").is_some() {
4118 // r1's self-pin is armed via EC_AV1_GATE_DUMP=<path>
4119 // only for a real pixel MISMATCH below, not for this
4120 // still-expected named refusal.
4121 }
4122 continue;
4123 }
4124 Ok(frames) => frames,
4125 };
4126 let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
4127 assert_eq!(frames.len(), frame_count);
4128 let mismatched = frames
4129 .iter()
4130 .zip(&ffmpeg_frames)
4131 .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
4132 if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
4133 std::fs::write(&path, &stream).expect("writing pinned stream");
4134 eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
4135 }
4136 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
4137 assert_eq!(
4138 got.y, want.y,
4139 "{NAME} frame {i} luma vs ffmpeg (seed {seed})"
4140 );
4141 assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
4142 assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
4143 }
4144 // lane-hidden r2 (class gate-blind-to-hidden-frames): the same
4145 // stream again, comparing EVERY decode-order frame -- the hidden
4146 // (show_frame == 0) alt-ref frames the ffmpeg compare above
4147 // cannot see, because both sides of it emit shown frames only.
4148 let (hidden_total, hidden_n) = decode_all_frames_vs_oracle(&stream, NAME);
4149 eprintln!(
4150 "{NAME} HIDDEN: seed {seed}: {hidden_total} decode-order frames, \
4151 {hidden_n} hidden, all pixel-exact vs the oracle"
4152 );
4153 // lane-hidden r2 SECOND ARM (the recipe above is untouched):
4154 // libaom's temporal alt-ref filter absorbs this recipe's hidden
4155 // frames, so the compare above is vacuous -- re-encode the same
4156 // fixture with --arnr-maxframes=0 and compare THOSE.
4157 if let Some((arm_total, arm_hidden)) = hidden_arnr_arm(NAME, &y4m.stdout, &args) {
4158 eprintln!(
4159 "{NAME} HIDDEN-ARM(--arnr-maxframes=0): seed {seed}: {arm_total} \
4160 decode-order frames, {arm_hidden} hidden, all pixel-exact vs the oracle"
4161 );
4162 }
4163 matched += 1;
4164 }
4165 // r1: observed flaky at 40 attempts -- aomenc's cpu-used=0 RD is
4166 // run-to-run nondeterministic in whether it ever picks
4167 // comp_group_idx == 1 for this synthetic gradients content, and
4168 // allow_screen_content_tools sometimes eats most of a small seed
4169 // window (class gate-recipe-confound / never-fired-gate, memory).
4170 // 80 attempts is the mitigation, not a fix; a still-zero run here
4171 // is that sampling flake, not a decode regression -- check
4172 // masked_compound_hits/named_refusals in the panic message before
4173 // assuming a real bug.
4174 // r2: DIFFWTD is ported and gated, so a zero-hit run is no longer
4175 // soft-skipped -- hard assert, matching the interintra gate.
4176 assert!(
4177 crate::decode::masked_compound_hits() > 0,
4178 "{NAME}: zero masked-compound blocks fired ({matched} matches, {named_refusals} \
4179 other refusals out of {n_attempts}) -- gate proved nothing this run"
4180 );
4181 // lane-defon r1: `--enable-diff-wtd-comp=1` is now spelled on this
4182 // recipe, so the DIFFWTD half of MASKED_COMPOUND_HITS must fire.
4183 assert!(
4184 crate::decode::diffwtd_hits() > 0,
4185 "{NAME}: zero COMPOUND_DIFFWTD blends ({matched} matches, {named_refusals} \
4186 other refusals out of {n_attempts}) -- --enable-diff-wtd-comp=1 proved nothing"
4187 );
4188 // r3: wedge_hits() is soft-skipped, not hard-asserted -- the recipe
4189 // search (dist-wtd-comp=0 + diagonal mandelbrot content) is not
4190 // proven to fire wedge on every run; charter's fallback is to land
4191 // the checksum-verified codebook + blend with this soft path.
4192 if crate::decode::wedge_hits() == 0 {
4193 eprintln!(
4194 "{NAME}: WARNING wedge_hits()==0 this run -- COMPOUND_WEDGE never fired \
4195 ({matched} matches, {named_refusals} refusals out of {n_attempts}); codebook \
4196 is checksum-verified but unexercised live this run"
4197 );
4198 }
4199 eprintln!(
4200 "{NAME}: {named_refusals} other-capability refusals, {matched} pixel-exact matches \
4201 out of {n_attempts}, masked_compound_hits={} wedge_hits={}",
4202 crate::decode::masked_compound_hits(),
4203 crate::decode::wedge_hits()
4204 );
4205 }
4206
4207 /// lane-inter16ab r5: `COMPOUND_WEDGE` on a RECTANGULAR inter block --
4208 /// the shapes `av1_wedge_params_lookup` gives the `hgtw`/`hltw`
4209 /// codebooks (8x16/16x32/8x32 and 16x8/32x16/32x8), which this decoder
4210 /// refused by name until this round ("the wedge codebook is
4211 /// square-only"). `--enable-rect-partitions=1` with
4212 /// `--min-partition-size=16 --max-partition-size=32` is what makes
4213 /// aomenc's RD put a masked compound block on a 16x32/32x16 strip
4214 /// (measured: ~/.cache/inter16ab-tmp/rw2.sh, 24/24 streams at cq 50/55
4215 /// carry one and decode to the end at BOTH bit depths).
4216 ///
4217 /// Class `counter-from-refused-stream`: the per-shape counters are read
4218 /// as a DELTA around one attempt and only counted for attempts that
4219 /// decoded fully AND compared pixel-exact -- a refused attempt's hits
4220 /// are discarded. Every decode-order frame (including hidden alt-ref
4221 /// frames) is compared via [`decode_all_frames_vs_oracle`], and an
4222 /// attempt that mismatches while carrying NO rect wedge fails the gate
4223 /// through `oos_mismatch` rather than being blamed on this lane.
4224 #[test]
4225 fn a_real_aomenc_stream_with_a_rectangular_compound_wedge_decodes_pixel_exact() {
4226 const NAME: &str =
4227 "a_real_aomenc_stream_with_a_rectangular_compound_wedge_decodes_pixel_exact";
4228 let _gate_lock = lock_gate_counters();
4229 if !have_ffmpeg() {
4230 eprintln!("SKIP {NAME}: no ffmpeg");
4231 return;
4232 }
4233 if !have_aomenc() {
4234 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
4235 return;
4236 }
4237 let (width, height, frame_count) = (96usize, 96usize, 24usize);
4238 // Per rect shape (8x16, 16x8, 16x32, 32x16, 8x32, 32x8), summed over
4239 // the attempts that decoded AND matched.
4240 let mut shapes_proved = [0usize; 6];
4241 let (mut named_refusals, mut matched, mut oos_mismatch) = (0u32, 0u32, 0u32);
4242 let mut attempts = 0u32;
4243 for bit_depth in [8u32, 10u32] {
4244 for &cq in &[50u32, 55] {
4245 for a in 0..4u32 {
4246 attempts += 1;
4247 let duration = frame_count as f64 / 25.0;
4248 // Same hard-diagonal-edge content the square wedge gate
4249 // uses (wedge's masters are OBLIQUE), panned per attempt.
4250 let source = format!(
4251 "mandelbrot=size={width}x{height}:rate=25:start_x={sx}:start_y={sy}",
4252 sx = -0.6 + 0.01 * (a as f64),
4253 sy = -0.4 + 0.01 * (a as f64)
4254 );
4255 let pix_fmt = if bit_depth == 10 {
4256 "yuv420p10le"
4257 } else {
4258 "yuv420p"
4259 };
4260 let y4m = crate::tool_cache::cached_output_io(Command::new("ffmpeg")
4261 .args([
4262 "-v",
4263 "error",
4264 "-f",
4265 "lavfi",
4266 "-i",
4267 &source,
4268 "-t",
4269 &duration.to_string(),
4270 "-pix_fmt",
4271 pix_fmt,
4272 "-strict",
4273 "-1",
4274 "-f",
4275 "yuv4mpegpipe",
4276 "-strict",
4277 "-1",
4278 "-",
4279 ])
4280 .stdin(Stdio::null())
4281 .stdout(Stdio::piped())
4282 .stderr(Stdio::piped()), None, |c| c.output())
4283 .expect("ffmpeg failed to run");
4284 assert!(
4285 y4m.status.success(),
4286 "{NAME}: ffmpeg fixture: {}",
4287 String::from_utf8_lossy(&y4m.stderr)
4288 );
4289 let cq_arg = format!("--cq-level={cq}");
4290 let depth_arg = format!("--bit-depth={bit_depth}");
4291 let input_depth_arg = format!("--input-bit-depth={bit_depth}");
4292 let args: Vec<&str> = vec![
4293 "--codec=av1",
4294 "--passes=1",
4295 "--end-usage=q",
4296 &cq_arg,
4297 "--cpu-used=0",
4298 &depth_arg,
4299 &input_depth_arg,
4300 "--kf-max-dist=1000",
4301 "--threads=1",
4302 "--row-mt=0",
4303 "--auto-alt-ref=1",
4304 "--lag-in-frames=16",
4305 "--enable-fwd-kf=0",
4306 "--enable-order-hint=1",
4307 "--enable-warped-motion=1",
4308 "--enable-global-motion=0",
4309 "--enable-obmc=1",
4310 "--enable-diff-wtd-comp=1",
4311 "--enable-interintra-comp=1",
4312 "--enable-onesided-comp=0",
4313 "--enable-interintra-wedge=1",
4314 "--enable-smooth-interintra=1",
4315 "--enable-ab-partitions=0",
4316 "--enable-1to4-partitions=0",
4317 "--enable-filter-intra=0",
4318 "--enable-smooth-intra=0",
4319 "--enable-paeth-intra=0",
4320 "--enable-directional-intra=0",
4321 "--enable-angle-delta=0",
4322 "--enable-tx-size-search=0",
4323 "--enable-cdef=0",
4324 "--enable-restoration=0",
4325 "--enable-palette=0",
4326 "--enable-intrabc=0",
4327 "--enable-cfl-intra=0",
4328 "--enable-ref-frame-mvs=0",
4329 // Per-arm overrides LAST (aomenc keeps the last
4330 // occurrence of a repeated --enable-* flag): masked
4331 // compound ON, distance-weighted OFF so the
4332 // comp_group_idx==1 slot goes to wedge/diffwtd, and
4333 // rectangular partitions ON at 16/32 -- the shapes
4334 // the hgtw/hltw codebooks exist for.
4335 "--enable-masked-comp=1",
4336 "--enable-dist-wtd-comp=0",
4337 "--enable-rect-partitions=1",
4338 "--min-partition-size=16",
4339 "--max-partition-size=32",
4340 "--obu",
4341 "-o",
4342 "-",
4343 "-",
4344 ];
4345 let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
4346 assert!(
4347 out.status.success(),
4348 "aomenc refused the fixture: {}",
4349 String::from_utf8_lossy(&out.stderr)
4350 );
4351 let stream = out.stdout;
4352 let before = crate::stream::rect_wedge_hits();
4353 let frames = match decode_stream(&stream) {
4354 Err(e) => {
4355 let msg = e.to_string();
4356 assert!(
4357 msg.contains("unsupported"),
4358 "{NAME} failed outright, not a named refusal \
4359 ({bit_depth}-bit cq{cq} attempt {a}): {msg}"
4360 );
4361 assert!(
4362 !msg.contains("wedge codebook is square-only"),
4363 "{NAME}: the rect wedge codebook is ported -- this refusal is \
4364 forbidden ({bit_depth}-bit cq{cq} attempt {a}): {msg}"
4365 );
4366 named_refusals += 1;
4367 eprintln!("{bit_depth}-bit cq{cq} attempt {a} refusal: {msg}");
4368 continue;
4369 }
4370 Ok(frames) => frames,
4371 };
4372 let after = crate::stream::rect_wedge_hits();
4373 let fired: Vec<usize> = (0..6).map(|k| after[k] - before[k]).collect();
4374 let ffmpeg_frames = if bit_depth == 10 {
4375 ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
4376 } else {
4377 ffmpeg_decode_sequence(&stream, width, height, frame_count)
4378 };
4379 assert_eq!(frames.len(), ffmpeg_frames.len());
4380 let mismatched = frames
4381 .iter()
4382 .zip(&ffmpeg_frames)
4383 .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
4384 if fired.iter().sum::<usize>() == 0 {
4385 if mismatched {
4386 oos_mismatch += 1;
4387 eprintln!(
4388 "{NAME}: {bit_depth}-bit cq{cq} attempt {a} MISMATCHES with zero \
4389 rectangular wedge block -- another shape's defect"
4390 );
4391 }
4392 continue;
4393 }
4394 for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
4395 assert_eq!(
4396 got.y, want.y,
4397 "{NAME} frame {i} luma vs ffmpeg ({bit_depth}-bit cq{cq} attempt {a}, shapes {fired:?})"
4398 );
4399 assert_eq!(
4400 got.u, want.u,
4401 "{NAME} frame {i} U vs ffmpeg ({bit_depth}-bit cq{cq} attempt {a}, shapes {fired:?})"
4402 );
4403 assert_eq!(
4404 got.v, want.v,
4405 "{NAME} frame {i} V vs ffmpeg ({bit_depth}-bit cq{cq} attempt {a}, shapes {fired:?})"
4406 );
4407 }
4408 // class gate-blind-to-hidden-frames: the shown-frame
4409 // compare above cannot see the alt-ref frames this
4410 // recipe's --lag-in-frames=16 produces.
4411 let (hidden_total, hidden_n) = decode_all_frames_vs_oracle(&stream, NAME);
4412 eprintln!(
4413 "{NAME}: {bit_depth}-bit cq{cq} attempt {a}: shapes {fired:?}, \
4414 {hidden_total} decode-order frames ({hidden_n} hidden) pixel-exact"
4415 );
4416 for k in 0..6 {
4417 shapes_proved[k] += fired[k];
4418 }
4419 matched += 1;
4420 }
4421 }
4422 }
4423 eprintln!(
4424 "{NAME}: {named_refusals} named refusals, {matched} pixel-exact attempts out of \
4425 {attempts}, rect wedge blocks per shape \
4426 (8x16,16x8,16x32,32x16,8x32,32x8)={shapes_proved:?}, {oos_mismatch} zero-wedge \
4427 mismatches"
4428 );
4429 assert_eq!(
4430 oos_mismatch, 0,
4431 "{NAME}: {oos_mismatch} attempt(s) carrying no rectangular wedge mismatched ffmpeg \
4432 -- a defect of another shape, not a pass"
4433 );
4434 // The claim: a rectangular wedge codebook row (hgtw AND hltw) was
4435 // used on a stream that then decoded pixel-exact. 16x32 is hgtw
4436 // (h > w), 32x16 is hltw (h < w) -- one of each, so a transposed
4437 // codebook/signflip pair cannot pass this.
4438 assert!(
4439 shapes_proved[2] > 0 && shapes_proved[3] > 0,
4440 "{NAME}: no pixel-exact attempt used both an hgtw (16x32) and an hltw (32x16) \
4441 rectangular wedge codebook row (per shape {shapes_proved:?}, {matched} matches, \
4442 {named_refusals} refusals out of {attempts}) -- the recipe proved nothing"
4443 );
4444 }