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