| 1 | use super::*; |
| 2 | use super::support::*; |
| 3 | use super::gates_a::*; |
| 4 | use super::gates_b::*; |
| 5 | use crate::probe::run_with_stdin; |
| 6 | use std::process::{Command, Stdio}; |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 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 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 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 | |
| 58 | |
| 59 | |
| 60 | |
| 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 | |
| 152 | |
| 153 | |
| 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 | |
| 178 | |
| 179 | |
| 180 | |
| 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 | |
| 187 | |
| 188 | |
| 189 | |
| 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 | |
| 206 | |
| 207 | |
| 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 | |
| 217 | |
| 218 | |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 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 | |
| 359 | |
| 360 | |
| 361 | |
| 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 | |
| 368 | |
| 369 | |
| 370 | |
| 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 | |
| 395 | |
| 396 | |
| 397 | |
| 398 | |
| 399 | |
| 400 | |
| 401 | |
| 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 | |
| 503 | |
| 504 | |
| 505 | |
| 506 | |
| 507 | |
| 508 | |
| 509 | |
| 510 | |
| 511 | |
| 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 | |
| 557 | |
| 558 | |
| 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 | |
| 569 | |
| 570 | |
| 571 | |
| 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 | |
| 640 | |
| 641 | |
| 642 | |
| 643 | |
| 644 | |
| 645 | |
| 646 | |
| 647 | |
| 648 | |
| 649 | |
| 650 | |
| 651 | |
| 652 | |
| 653 | |
| 654 | |
| 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 | |
| 668 | |
| 669 | |
| 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 | |
| 808 | |
| 809 | |
| 810 | |
| 811 | |
| 812 | |
| 813 | |
| 814 | |
| 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 | |
| 829 | |
| 830 | |
| 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 | |
| 958 | |
| 959 | |
| 960 | |
| 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 | |
| 967 | |
| 968 | |
| 969 | |
| 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 | |
| 977 | |
| 978 | |
| 979 | |
| 980 | |
| 981 | |
| 982 | |
| 983 | |
| 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 | |
| 1030 | |
| 1031 | |
| 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 | |
| 1051 | |
| 1052 | |
| 1053 | |
| 1054 | |
| 1055 | |
| 1056 | |
| 1057 | |
| 1058 | |
| 1059 | |
| 1060 | |
| 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 | |
| 1117 | |
| 1118 | |
| 1119 | |
| 1120 | |
| 1121 | |
| 1122 | |
| 1123 | let warp = format!("--enable-warped-motion={}", on("EC_SCALEDREF_WARP")); |
| 1124 | |
| 1125 | |
| 1126 | |
| 1127 | |
| 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 | |
| 1154 | |
| 1155 | |
| 1156 | |
| 1157 | |
| 1158 | |
| 1159 | |
| 1160 | |
| 1161 | &superres_mode, |
| 1162 | "--superres-denominator=16", |
| 1163 | "--superres-kf-denominator=16", |
| 1164 | |
| 1165 | |
| 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 | |
| 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 | |
| 1271 | |
| 1272 | |
| 1273 | |
| 1274 | |
| 1275 | |
| 1276 | |
| 1277 | |
| 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 | |
| 1305 | |
| 1306 | |
| 1307 | |
| 1308 | |
| 1309 | |
| 1310 | |
| 1311 | |
| 1312 | |
| 1313 | |
| 1314 | |
| 1315 | |
| 1316 | |
| 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 | |
| 1378 | |
| 1379 | |
| 1380 | |
| 1381 | |
| 1382 | |
| 1383 | |
| 1384 | |
| 1385 | |
| 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 | |
| 1448 | |
| 1449 | |
| 1450 | |
| 1451 | |
| 1452 | |
| 1453 | |
| 1454 | |
| 1455 | |
| 1456 | |
| 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 | |
| 1483 | |
| 1484 | |
| 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 | |
| 1571 | |
| 1572 | |
| 1573 | |
| 1574 | |
| 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 | |
| 1600 | |
| 1601 | |
| 1602 | |
| 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 | |
| 1609 | |
| 1610 | |
| 1611 | |
| 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 | |
| 1625 | |
| 1626 | |
| 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 | |
| 1639 | |
| 1640 | |
| 1641 | |
| 1642 | |
| 1643 | |
| 1644 | |
| 1645 | |
| 1646 | |
| 1647 | |
| 1648 | |
| 1649 | |
| 1650 | |
| 1651 | |
| 1652 | |
| 1653 | |
| 1654 | |
| 1655 | |
| 1656 | |
| 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 | |
| 1675 | |
| 1676 | for depth in [8u32, 10u32] { |
| 1677 | |
| 1678 | |
| 1679 | |
| 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 | |
| 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 | |
| 1789 | |
| 1790 | |
| 1791 | |
| 1792 | |
| 1793 | |
| 1794 | |
| 1795 | |
| 1796 | |
| 1797 | |
| 1798 | |
| 1799 | |
| 1800 | |
| 1801 | |
| 1802 | |
| 1803 | |
| 1804 | |
| 1805 | |
| 1806 | |
| 1807 | |
| 1808 | |
| 1809 | |
| 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 | |
| 1884 | |
| 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 | |
| 1901 | |
| 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 | |
| 1918 | |
| 1919 | |
| 1920 | |
| 1921 | |
| 1922 | |
| 1923 | |
| 1924 | |
| 1925 | |
| 1926 | |
| 1927 | |
| 1928 | |
| 1929 | |
| 1930 | |
| 1931 | |
| 1932 | |
| 1933 | |
| 1934 | |
| 1935 | |
| 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 | |
| 1997 | |
| 1998 | |
| 1999 | |
| 2000 | assert!( |
| 2001 | !stream.is_empty(), |
| 2002 | "{NAME}: aomenc wrote an empty stream (missing --passes=1?)" |
| 2003 | ); |
| 2004 | let result = decode_stream(&stream); |
| 2005 | |
| 2006 | |
| 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 | |
| 2028 | |
| 2029 | |
| 2030 | |
| 2031 | |
| 2032 | |
| 2033 | |
| 2034 | |
| 2035 | |
| 2036 | |
| 2037 | |
| 2038 | |
| 2039 | |
| 2040 | |
| 2041 | |
| 2042 | |
| 2043 | |
| 2044 | |
| 2045 | |
| 2046 | |
| 2047 | |
| 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 | |
| 2106 | |
| 2107 | |
| 2108 | |
| 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 | |
| 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 | |
| 2144 | |
| 2145 | |
| 2146 | |
| 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 | |
| 2166 | |
| 2167 | |
| 2168 | |
| 2169 | |
| 2170 | |
| 2171 | |
| 2172 | |
| 2173 | |
| 2174 | |
| 2175 | |
| 2176 | |
| 2177 | |
| 2178 | |
| 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 | |
| 2220 | |
| 2221 | |
| 2222 | |
| 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 | |
| 2272 | |
| 2273 | let overrides = crate::decode::mode_mi_override_hits() - before; |
| 2274 | |
| 2275 | |
| 2276 | |
| 2277 | |
| 2278 | |
| 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 | |
| 2306 | |
| 2307 | |
| 2308 | |
| 2309 | |
| 2310 | |
| 2311 | |
| 2312 | |
| 2313 | |
| 2314 | |
| 2315 | |
| 2316 | |
| 2317 | |
| 2318 | |
| 2319 | |
| 2320 | |
| 2321 | |
| 2322 | |
| 2323 | |
| 2324 | |
| 2325 | |
| 2326 | |
| 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 | |
| 2343 | |
| 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 | |
| 2427 | |
| 2428 | |
| 2429 | |
| 2430 | |
| 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 | |
| 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 | |
| 2447 | |
| 2448 | |
| 2449 | |
| 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 | |
| 2510 | |
| 2511 | |
| 2512 | |
| 2513 | |
| 2514 | |
| 2515 | |
| 2516 | |
| 2517 | |
| 2518 | |
| 2519 | |
| 2520 | |
| 2521 | |
| 2522 | |
| 2523 | |
| 2524 | |
| 2525 | |
| 2526 | |
| 2527 | |
| 2528 | |
| 2529 | |
| 2530 | |
| 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 | |
| 2643 | let after = crate::decode::reelc_chroma_counters(); |
| 2644 | let (skip_cfl, dir_pairs) = (after.0 - before.0, after.1 - before.1); |
| 2645 | |
| 2646 | |
| 2647 | |
| 2648 | |
| 2649 | |
| 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 | |
| 2675 | |
| 2676 | |
| 2677 | |
| 2678 | |
| 2679 | |
| 2680 | |
| 2681 | |
| 2682 | |
| 2683 | |
| 2684 | |
| 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 | |
| 2703 | |
| 2704 | |
| 2705 | |
| 2706 | |
| 2707 | |
| 2708 | |
| 2709 | |
| 2710 | |
| 2711 | |
| 2712 | |
| 2713 | |
| 2714 | |
| 2715 | |
| 2716 | |
| 2717 | |
| 2718 | |
| 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 | |
| 2740 | |
| 2741 | |
| 2742 | |
| 2743 | tx_size_search: bool, |
| 2744 | } |
| 2745 | |
| 2746 | |
| 2747 | |
| 2748 | |
| 2749 | |
| 2750 | |
| 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 | |
| 2789 | |
| 2790 | |
| 2791 | |
| 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 | |
| 2811 | |
| 2812 | |
| 2813 | |
| 2814 | |
| 2815 | |
| 2816 | |
| 2817 | |
| 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 | |
| 2922 | |
| 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 | |
| 2957 | |
| 2958 | tx4_reached += tx4_this; |
| 2959 | let frames = match decoded { |
| 2960 | Ok(frames) => frames, |
| 2961 | |
| 2962 | |
| 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 | |
| 2978 | |
| 2979 | |
| 2980 | |
| 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 | |
| 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 | |
| 3015 | |
| 3016 | |
| 3017 | |
| 3018 | |
| 3019 | |
| 3020 | |
| 3021 | |
| 3022 | |
| 3023 | |
| 3024 | |
| 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 | |
| 3051 | |
| 3052 | |
| 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 | |
| 3136 | |
| 3137 | |
| 3138 | |
| 3139 | |
| 3140 | |
| 3141 | |
| 3142 | |
| 3143 | |
| 3144 | |
| 3145 | |
| 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 | |
| 3184 | |
| 3185 | |
| 3186 | |
| 3187 | |
| 3188 | |
| 3189 | |
| 3190 | |
| 3191 | |
| 3192 | |
| 3193 | |
| 3194 | |
| 3195 | |
| 3196 | |
| 3197 | |
| 3198 | |
| 3199 | |
| 3200 | |
| 3201 | |
| 3202 | |
| 3203 | |
| 3204 | |
| 3205 | |
| 3206 | |
| 3207 | |
| 3208 | |
| 3209 | |
| 3210 | |
| 3211 | |
| 3212 | |
| 3213 | |
| 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 | |
| 3283 | |
| 3284 | |
| 3285 | |
| 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 | |
| 3354 | |
| 3355 | |
| 3356 | |
| 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 | |
| 3363 | |
| 3364 | |
| 3365 | |
| 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 | |
| 3379 | |
| 3380 | |
| 3381 | |
| 3382 | |
| 3383 | |
| 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 | |
| 3391 | |
| 3392 | |
| 3393 | |
| 3394 | |
| 3395 | |
| 3396 | |
| 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 | |
| 3414 | |
| 3415 | |
| 3416 | |
| 3417 | |
| 3418 | |
| 3419 | |
| 3420 | |
| 3421 | |
| 3422 | |
| 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 | |
| 3492 | |
| 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 | |
| 3563 | |
| 3564 | |
| 3565 | |
| 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 | |
| 3572 | |
| 3573 | |
| 3574 | |
| 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 | |
| 3600 | |
| 3601 | |
| 3602 | |
| 3603 | |
| 3604 | |
| 3605 | |
| 3606 | |
| 3607 | |
| 3608 | |
| 3609 | |
| 3610 | |
| 3611 | |
| 3612 | |
| 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 | |
| 3637 | |
| 3638 | |
| 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 | |
| 3669 | |
| 3670 | |
| 3671 | |
| 3672 | |
| 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 | |
| 3748 | |
| 3749 | |
| 3750 | |
| 3751 | |
| 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 | |
| 3804 | |
| 3805 | |
| 3806 | |
| 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 | |
| 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 | |
| 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 | |
| 3868 | |
| 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 | |
| 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 | |
| 3889 | |
| 3890 | |
| 3891 | |
| 3892 | |
| 3893 | |
| 3894 | |
| 3895 | |
| 3896 | |
| 3897 | |
| 3898 | |
| 3899 | |
| 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 | |
| 3911 | |
| 3912 | |
| 3913 | |
| 3914 | |
| 3915 | |
| 3916 | |
| 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 | |
| 3928 | |
| 3929 | |
| 3930 | |
| 3931 | |
| 3932 | |
| 3933 | |
| 3934 | |
| 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 | |
| 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 | |
| 3955 | |
| 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 | |
| 3965 | |
| 3966 | |
| 3967 | |
| 3968 | |
| 3969 | |
| 3970 | |
| 3971 | |
| 3972 | |
| 3973 | |
| 3974 | |
| 3975 | |
| 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 | |
| 3999 | |
| 4000 | |
| 4001 | |
| 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 | |
| 4034 | |
| 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 | |
| 4050 | |
| 4051 | |
| 4052 | |
| 4053 | "--enable-global-motion=0", |
| 4054 | "--enable-obmc=1", |
| 4055 | "--tune-content=default", |
| 4056 | "--enable-masked-comp=1", |
| 4057 | |
| 4058 | |
| 4059 | |
| 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 | |
| 4119 | |
| 4120 | |
| 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 | |
| 4145 | |
| 4146 | |
| 4147 | |
| 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 | |
| 4154 | |
| 4155 | |
| 4156 | |
| 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 | |
| 4166 | |
| 4167 | |
| 4168 | |
| 4169 | |
| 4170 | |
| 4171 | |
| 4172 | |
| 4173 | |
| 4174 | |
| 4175 | |
| 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 | |
| 4182 | |
| 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 | |
| 4189 | |
| 4190 | |
| 4191 | |
| 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 | |
| 4208 | |
| 4209 | |
| 4210 | |
| 4211 | |
| 4212 | |
| 4213 | |
| 4214 | |
| 4215 | |
| 4216 | |
| 4217 | |
| 4218 | |
| 4219 | |
| 4220 | |
| 4221 | |
| 4222 | |
| 4223 | |
| 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 | |
| 4239 | |
| 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 | |
| 4249 | |
| 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 | |
| 4330 | |
| 4331 | |
| 4332 | |
| 4333 | |
| 4334 | |
| 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 | |
| 4409 | |
| 4410 | |
| 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 | |
| 4435 | |
| 4436 | |
| 4437 | |
| 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 | } |