wip(av1): sbpart r2's SB-level HORZ/VERT gate -- fires live (sb_rect_hits>0), luma mismatch not yet bisected
Browse files at this commitda48368b87607f357c78df839f6eeef72cfaf370Parent: c0c93061 changed file +155 -0
- crates/ec-av1/src/stream.rs +155 -0
crates/ec-av1/src/stream.rsmodified+155 -0
| @@ -6357,4 +6357,159 @@ mod tests { | ||
| 6357 | 6357 | "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20" |
| 6358 | 6358 | ); |
| 6359 | 6359 | } |
| 6360 | + | |
| 6361 | + /// lane-sbpart r2: a real `aomenc` stream whose superblock-level | |
| 6362 | + /// partition decision is genuinely HORZ/VERT (not NONE/SPLIT) must | |
| 6363 | + /// decode pixel-exact through [`crate::decode::decode_block_rect64`] -- | |
| 6364 | + /// `sb_rect_hits() > 0` is a HARD assert (this round's rule: a removed | |
| 6365 | + /// refusal needs a firing gate in the same commit, not a green suite | |
| 6366 | + /// that never took the new path). Recipe = the charter's own, verified | |
| 6367 | + /// live by r1: `--min/max-partition-size=32/64` keeps the RD search | |
| 6368 | + /// from ever recursing below 32x32, so every SB-level decision is | |
| 6369 | + /// genuinely NONE/SPLIT/HORZ/VERT; a `gradients` source blended with | |
| 6370 | + /// `testsrc2` (lavfi `blend=all_mode=average`) keeps the content from | |
| 6371 | + /// being flat enough that the search stops at NONE every time. | |
| 6372 | + #[test] | |
| 6373 | + fn a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact() { | |
| 6374 | + const NAME: &str = | |
| 6375 | + "a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact"; | |
| 6376 | + let _gate_lock = lock_gate_counters(); | |
| 6377 | + if !have_ffmpeg() { | |
| 6378 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 6379 | + return; | |
| 6380 | + } | |
| 6381 | + if !have_aomenc() { | |
| 6382 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | |
| 6383 | + return; | |
| 6384 | + } | |
| 6385 | + let (width, height, frame_count) = (192usize, 128usize, 1usize); | |
| 6386 | + let mut named_refusals = 0u32; | |
| 6387 | + let mut matched = 0u32; | |
| 6388 | + let n_attempts: u32 = std::env::var("EC_SBPART_GATE_ATTEMPTS") | |
| 6389 | + .ok() | |
| 6390 | + .and_then(|s| s.parse().ok()) | |
| 6391 | + .unwrap_or(40); | |
| 6392 | + for attempt in 0..n_attempts { | |
| 6393 | + let seed = 42 + attempt; | |
| 6394 | + let duration = frame_count as f64 / 25.0; | |
| 6395 | + let source = | |
| 6396 | + gradients_source(seed, width, height, &format!("duration={duration}:rate=25")); | |
| 6397 | + let y4m = Command::new("ffmpeg") | |
| 6398 | + .args([ | |
| 6399 | + "-v", | |
| 6400 | + "error", | |
| 6401 | + "-f", | |
| 6402 | + "lavfi", | |
| 6403 | + "-i", | |
| 6404 | + &source, | |
| 6405 | + "-pix_fmt", | |
| 6406 | + "yuv420p", | |
| 6407 | + "-f", | |
| 6408 | + "yuv4mpegpipe", | |
| 6409 | + "-", | |
| 6410 | + ]) | |
| 6411 | + .stdin(Stdio::null()) | |
| 6412 | + .stdout(Stdio::piped()) | |
| 6413 | + .stderr(Stdio::piped()) | |
| 6414 | + .output() | |
| 6415 | + .expect("ffmpeg failed to run"); | |
| 6416 | + assert!( | |
| 6417 | + y4m.status.success(), | |
| 6418 | + "ffmpeg fixture: {}", | |
| 6419 | + String::from_utf8_lossy(&y4m.stderr) | |
| 6420 | + ); | |
| 6421 | + let args: Vec<&str> = vec![ | |
| 6422 | + "--codec=av1", | |
| 6423 | + "--passes=1", | |
| 6424 | + "--end-usage=q", | |
| 6425 | + "--cq-level=45", | |
| 6426 | + "--cpu-used=0", | |
| 6427 | + "--threads=1", | |
| 6428 | + "--row-mt=0", | |
| 6429 | + "--sb-size=64", | |
| 6430 | + "--enable-rect-partitions=1", | |
| 6431 | + "--enable-ab-partitions=0", | |
| 6432 | + "--enable-1to4-partitions=0", | |
| 6433 | + "--min-partition-size=32", | |
| 6434 | + "--max-partition-size=64", | |
| 6435 | + "--enable-restoration=0", | |
| 6436 | + "--enable-palette=0", | |
| 6437 | + "--deltaq-mode=0", | |
| 6438 | + "--enable-filter-intra=0", | |
| 6439 | + "--enable-cfl-intra=0", | |
| 6440 | + "--enable-intrabc=0", | |
| 6441 | + "--enable-tx-size-search=0", | |
| 6442 | + "--obu", | |
| 6443 | + "-o", | |
| 6444 | + "-", | |
| 6445 | + "-", | |
| 6446 | + ]; | |
| 6447 | + let mut child = Command::new(aomenc_path()) | |
| 6448 | + .args(&args) | |
| 6449 | + .stdin(Stdio::piped()) | |
| 6450 | + .stdout(Stdio::piped()) | |
| 6451 | + .stderr(Stdio::piped()) | |
| 6452 | + .spawn() | |
| 6453 | + .expect("aomenc failed to start"); | |
| 6454 | + child | |
| 6455 | + .stdin | |
| 6456 | + .take() | |
| 6457 | + .expect("aomenc stdin") | |
| 6458 | + .write_all(&y4m.stdout) | |
| 6459 | + .expect("writing y4m to aomenc"); | |
| 6460 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 6461 | + assert!( | |
| 6462 | + out.status.success(), | |
| 6463 | + "aomenc refused the fixture: {}", | |
| 6464 | + String::from_utf8_lossy(&out.stderr) | |
| 6465 | + ); | |
| 6466 | + let stream = out.stdout; | |
| 6467 | + let frames = match decode_stream(&stream) { | |
| 6468 | + Err(e) => { | |
| 6469 | + let msg = e.to_string(); | |
| 6470 | + assert!( | |
| 6471 | + msg.contains("unsupported"), | |
| 6472 | + "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" | |
| 6473 | + ); | |
| 6474 | + // r2: `--enable-ab-partitions=0` does NOT stop aomenc | |
| 6475 | + // choosing an SB-level HORZ_A/HORZ_B/VERT_A/VERT_B | |
| 6476 | + // (`partition_w64` value 4-7) even with | |
| 6477 | + // `--min/max-partition-size=32/64` -- a real, separate | |
| 6478 | + // encoder quirk (AB-at-64 is a different, unlanded | |
| 6479 | + // capability, lane-partab's territory is 32x32 and | |
| 6480 | + // below only) discovered live this round, not this | |
| 6481 | + // lane's HORZ/VERT gap. Only NONE/SPLIT/HORZ/VERT | |
| 6482 | + // (values 0-3) are this gate's territory; a real | |
| 6483 | + // HORZ/VERT (1/2) must still decode pixel-exact, which | |
| 6484 | + // `sb_rect_hits() > 0` below hard-proves. | |
| 6485 | + named_refusals += 1; | |
| 6486 | + eprintln!("seed {seed} refusal: {msg}"); | |
| 6487 | + continue; | |
| 6488 | + } | |
| 6489 | + Ok(frames) => frames, | |
| 6490 | + }; | |
| 6491 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); | |
| 6492 | + assert_eq!(frames.len(), frame_count); | |
| 6493 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | |
| 6494 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); | |
| 6495 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); | |
| 6496 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); | |
| 6497 | + } | |
| 6498 | + matched += 1; | |
| 6499 | + } | |
| 6500 | + assert!( | |
| 6501 | + matched > 0, | |
| 6502 | + "{NAME}: every attempt refused; the gate never decoded a stream" | |
| 6503 | + ); | |
| 6504 | + assert!( | |
| 6505 | + crate::decode::sb_rect_hits() > 0, | |
| 6506 | + "{NAME}: zero superblock-level HORZ/VERT blocks fired ({matched} matches, \ | |
| 6507 | + {named_refusals} refusals out of {n_attempts}) -- gate proved nothing this run" | |
| 6508 | + ); | |
| 6509 | + eprintln!( | |
| 6510 | + "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of \ | |
| 6511 | + {n_attempts}, sb_rect_hits={}", | |
| 6512 | + crate::decode::sb_rect_hits() | |
| 6513 | + ); | |
| 6514 | + } | |
| 6360 | 6515 | } |