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