ec-av1: the 4:2:0 ffmpeg oracle helpers refuse a non-4:2:0 stream
Browse files at this commit8b97983eb5cde3edb6358449c6ac8ac52b300260Parent: 69db7582 changed files +434 -0
- crates/ec-av1/src/stream.rs +263 -0
- lanes/av1oracleguard.report.md +171 -0
crates/ec-av1/src/stream.rsmodified+263 -0
| @@ -6478,6 +6478,252 @@ pub(crate) mod tests { | |||
| 6478 | .color_config | 6478 | .color_config |
| 6479 | .bit_depth | 6479 | .bit_depth |
| 6480 | } | 6480 | } |
| 6481 | + /// The stream's OWN `color_config.subsampling_x/y` (spec 5.5.2), read | ||
| 6482 | + /// from its bytes the same way [`stream_bit_depth`] reads the depth. | ||
| 6483 | + fn stream_subsampling(stream: &[u8], name: &str) -> (u8, u8) { | ||
| 6484 | + let mut probe = Av1Parser::new(); | ||
| 6485 | + let mut pos = 0usize; | ||
| 6486 | + while pos < stream.len() && probe.sequence_header().is_none() { | ||
| 6487 | + let obu = probe | ||
| 6488 | + .parse_obu(&stream[pos..]) | ||
| 6489 | + .unwrap_or_else(|e| panic!("{name}: OBU at byte {pos} does not parse: {e:?}")); | ||
| 6490 | + pos += obu.total_size; | ||
| 6491 | + } | ||
| 6492 | + let cc = &probe | ||
| 6493 | + .sequence_header() | ||
| 6494 | + .unwrap_or_else(|| panic!("{name}: the stream carries no sequence header OBU")) | ||
| 6495 | + .color_config; | ||
| 6496 | + (cc.subsampling_x, cc.subsampling_y) | ||
| 6497 | + } | ||
| 6498 | + | ||
| 6499 | + /// The chroma shape a `(subsampling_x, subsampling_y)` pair means. | ||
| 6500 | + fn chroma_shape(sx: u8, sy: u8) -> &'static str { | ||
| 6501 | + match (sx, sy) { | ||
| 6502 | + (1, 1) => "4:2:0", | ||
| 6503 | + (1, 0) => "4:2:2", | ||
| 6504 | + (0, 0) => "4:4:4", | ||
| 6505 | + (0, 1) => "4:4:0", | ||
| 6506 | + _ => "an unassigned subsampling", | ||
| 6507 | + } | ||
| 6508 | + } | ||
| 6509 | + | ||
| 6510 | + /// lane-av1oracleguard: HARD REFUSAL for the 4:2:0 ffmpeg oracle helpers. | ||
| 6511 | + /// | ||
| 6512 | + /// `ffmpeg_decode_sequence`, `ffmpeg_decode_sequence_10bit` and | ||
| 6513 | + /// `ffmpeg_decode_sequence_12bit` ask ffmpeg for `-pix_fmt yuv420p*` and | ||
| 6514 | + /// size chroma at `width * height / 4`. Those are the 4:2:0 numbers, so | ||
| 6515 | + /// for a stream that is NOT (1,1) ffmpeg does not fail -- it CONVERTS, | ||
| 6516 | + /// and the helper then slices a 4:2:0-shaped picture out of it. A 4:2:2 | ||
| 6517 | + /// gate built on one of them compares the wrong planes and passes green: | ||
| 6518 | + /// the exact failure `lanes/av1subsizesweep.report.md` names. The correct | ||
| 6519 | + /// siblings (`ffmpeg_decode_sequence_422` / `_422_depth` / | ||
| 6520 | + /// `ffmpeg_decode_sequence_444`) exist and take the same bytes, so the | ||
| 6521 | + /// refusal points at them by name rather than leaving the caller to | ||
| 6522 | + /// rediscover the shape. | ||
| 6523 | + /// | ||
| 6524 | + /// Refused by SUBSAMPLING read from the stream's own sequence header, not | ||
| 6525 | + /// from the caller's `width`/`height` (class | ||
| 6526 | + /// `helper-assumes-the-shape-the-gate-name-implies`). | ||
| 6527 | + fn assert_420_oracle_stream(stream: &[u8], helper: &str, sibling: &str) { | ||
| 6528 | + let (sx, sy) = stream_subsampling(stream, helper); | ||
| 6529 | + assert!( | ||
| 6530 | + (sx, sy) == (1, 1), | ||
| 6531 | + "{helper} REFUSED a ({sx},{sy}) stream: this helper asks ffmpeg for a 4:2:0 \ | ||
| 6532 | + pix_fmt, which CONVERTS the stream's real {} chroma down to 4:2:0 instead of \ | ||
| 6533 | + failing, then sizes chroma at `width * height / 4` rather than the {} shape. A \ | ||
| 6534 | + gate built on it would compare converted planes against real ones and pass green. \ | ||
| 6535 | + Use `{sibling}` for a ({sx},{sy}) stream.", | ||
| 6536 | + chroma_shape(sx, sy), | ||
| 6537 | + chroma_shape(sx, sy), | ||
| 6538 | + ); | ||
| 6539 | + } | ||
| 6540 | + /// lane-av1oracleguard: run `f`, return the panic MESSAGE it raised (or | ||
| 6541 | + /// `None` if it did not panic). The panic hook is silenced so a refusal | ||
| 6542 | + /// that PASSES its gate prints nothing -- the assertion is the return. | ||
| 6543 | + fn panic_message<F: FnOnce()>(f: F) -> Option<String> { | ||
| 6544 | + let hook = std::panic::take_hook(); | ||
| 6545 | + std::panic::set_hook(Box::new(|_| {})); | ||
| 6546 | + let caught = std::panic::catch_unwind(std::panic::AssertUnwindSafe(f)); | ||
| 6547 | + std::panic::set_hook(hook); | ||
| 6548 | + match caught { | ||
| 6549 | + Ok(()) => None, | ||
| 6550 | + Err(payload) => Some( | ||
| 6551 | + payload | ||
| 6552 | + .downcast_ref::<String>() | ||
| 6553 | + .cloned() | ||
| 6554 | + .or_else(|| payload.downcast_ref::<&str>().map(|s| (*s).to_string())) | ||
| 6555 | + .unwrap_or_else(|| "<non-string panic payload>".to_string()), | ||
| 6556 | + ), | ||
| 6557 | + } | ||
| 6558 | + } | ||
| 6559 | + | ||
| 6560 | + /// lane-av1oracleguard, direction 1 of 2: the 4:2:0 helper's COMPARATOR | ||
| 6561 | + /// still bites on a real 4:2:0 pin, so the refusal added above did not | ||
| 6562 | + /// buy its non-vacuity by making the helper stop comparing. | ||
| 6563 | + /// | ||
| 6564 | + /// `420_mixll_256x128_6f.obu` is 8-bit 4:2:0 at 256x128. Ours and ffmpeg | ||
| 6565 | + /// agree on every sample of every output frame (bad == 0), then ONE U | ||
| 6566 | + /// sample of the oracle is flipped and the same count must move to 1. A | ||
| 6567 | + /// count that stays 0 on a flipped oracle is a comparator that compares | ||
| 6568 | + /// nothing, and the refusal would then be the only thing this gate could | ||
| 6569 | + /// prove. | ||
| 6570 | + #[test] | ||
| 6571 | + fn a_420_oracle_comparator_counts_a_flipped_oracle_sample() { | ||
| 6572 | + const NAME: &str = "a_420_oracle_comparator_counts_a_flipped_oracle_sample"; | ||
| 6573 | + let _gate_lock = lock_gate_counters(); | ||
| 6574 | + if !have_ffmpeg() { | ||
| 6575 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 6576 | + return; | ||
| 6577 | + } | ||
| 6578 | + let path = crate_pin("420_mixll_256x128_6f.obu"); | ||
| 6579 | + let data = std::fs::read(&path) | ||
| 6580 | + .unwrap_or_else(|e| panic!("{NAME}: the committed pin is missing ({e})")); | ||
| 6581 | + assert_eq!(data.len(), 22336, "{NAME}: pin size drifted"); | ||
| 6582 | + assert_eq!( | ||
| 6583 | + fnv1a64(&data), | ||
| 6584 | + 5694016005779287373, | ||
| 6585 | + "{NAME}: pin bytes drifted" | ||
| 6586 | + ); | ||
| 6587 | + assert_eq!( | ||
| 6588 | + stream_subsampling(&data, NAME), | ||
| 6589 | + (1, 1), | ||
| 6590 | + "{NAME}: this cell must be a 4:2:0 pin -- the refusal arm uses other pins" | ||
| 6591 | + ); | ||
| 6592 | + | ||
| 6593 | + let decoded = decode_stream(&data) | ||
| 6594 | + .unwrap_or_else(|e| panic!("{NAME}: the committed 4:2:0 pin did not decode: {e}")); | ||
| 6595 | + let want = ffmpeg_decode_sequence(&data, 256, 128, decoded.len()); | ||
| 6596 | + assert_eq!(decoded.len(), want.len(), "{NAME}: decoded/frame count"); | ||
| 6597 | + | ||
| 6598 | + let plane_mismatches = |ours: &[Pic], theirs: &[Pic], plane: u8| -> usize { | ||
| 6599 | + ours.iter() | ||
| 6600 | + .zip(theirs) | ||
| 6601 | + .map(|(a, b)| { | ||
| 6602 | + let (a, b) = match plane { | ||
| 6603 | + 0 => (&a.y, &b.y), | ||
| 6604 | + 1 => (&a.u, &b.u), | ||
| 6605 | + _ => (&a.v, &b.v), | ||
| 6606 | + }; | ||
| 6607 | + a.iter().zip(b).filter(|&(x, y)| x != y).count() | ||
| 6608 | + }) | ||
| 6609 | + .sum() | ||
| 6610 | + }; | ||
| 6611 | + let clean: Vec<usize> = (0..3) | ||
| 6612 | + .map(|p| plane_mismatches(&decoded, &want, p)) | ||
| 6613 | + .collect(); | ||
| 6614 | + assert_eq!( | ||
| 6615 | + clean, | ||
| 6616 | + vec![0, 0, 0], | ||
| 6617 | + "{NAME}: the 4:2:0 oracle arm is not byte-exact to start with, so a flipped sample \ | ||
| 6618 | + would prove nothing" | ||
| 6619 | + ); | ||
| 6620 | + | ||
| 6621 | + // Flip exactly one oracle sample and the count MUST move. | ||
| 6622 | + let mut flipped = want.clone(); | ||
| 6623 | + flipped[0].u[0] ^= 1; | ||
| 6624 | + let moved: Vec<usize> = (0..3) | ||
| 6625 | + .map(|p| plane_mismatches(&decoded, &flipped, p)) | ||
| 6626 | + .collect(); | ||
| 6627 | + assert_eq!( | ||
| 6628 | + moved, | ||
| 6629 | + vec![0, 1, 0], | ||
| 6630 | + "{NAME}: one flipped oracle U sample must move the U comparison count 0 -> 1 and \ | ||
| 6631 | + leave Y and V at 0; got {moved:?} -- the comparator does not bite, so this gate \ | ||
| 6632 | + cannot tell a working oracle arm from a vacuous one" | ||
| 6633 | + ); | ||
| 6634 | + eprintln!( | ||
| 6635 | + "{NAME}: clean per-plane counts {clean:?}, after one flipped oracle U sample {moved:?}" | ||
| 6636 | + ); | ||
| 6637 | + } | ||
| 6638 | + | ||
| 6639 | + /// lane-av1oracleguard, direction 2 of 2 (8-bit): the 4:2:0 helper must | ||
| 6640 | + /// REFUSE a real 4:2:2 pin instead of letting ffmpeg convert it. The | ||
| 6641 | + /// message must name the REAL subsampling AND the sibling to use -- a | ||
| 6642 | + /// bare "wrong shape" would leave the caller to rediscover the fix. | ||
| 6643 | + /// | ||
| 6644 | + /// Before this lane, `ffmpeg_decode_sequence(&422_key_64x64, 64, 64, 1)` | ||
| 6645 | + /// RETURNED a 4:2:0-converted picture without complaint, which is the | ||
| 6646 | + /// silent-green the refusal exists to stop. This gate needs no ffmpeg at | ||
| 6647 | + /// all: the guard runs before the spawn, so a host without ffmpeg still | ||
| 6648 | + /// proves the refusal. | ||
| 6649 | + #[test] | ||
| 6650 | + fn a_420_oracle_helper_refuses_a_422_pin() { | ||
| 6651 | + const NAME: &str = "a_420_oracle_helper_refuses_a_422_pin"; | ||
| 6652 | + let _gate_lock = lock_gate_counters(); | ||
| 6653 | + let path = crate_pin("422_key_64x64.obu"); | ||
| 6654 | + let stream = read_pin(&path, 755, 0x87fc569cf53bcbc6, NAME); | ||
| 6655 | + assert_eq!( | ||
| 6656 | + stream_subsampling(&stream, NAME), | ||
| 6657 | + (1, 0), | ||
| 6658 | + "{NAME}: the pin must really be 4:2:2 (1,0), or this proves nothing" | ||
| 6659 | + ); | ||
| 6660 | + let msg = panic_message(|| { | ||
| 6661 | + ffmpeg_decode_sequence(&stream, 64, 64, 1); | ||
| 6662 | + }) | ||
| 6663 | + .unwrap_or_else(|| { | ||
| 6664 | + panic!( | ||
| 6665 | + "{NAME}: ffmpeg_decode_sequence ACCEPTED a (1,0) stream. ffmpeg converted it to \ | ||
| 6666 | + 4:2:0 and the helper returned a green-looking comparison" | ||
| 6667 | + ) | ||
| 6668 | + }); | ||
| 6669 | + for needle in ["(1,0)", "4:2:2", "ffmpeg_decode_sequence_422"] { | ||
| 6670 | + assert!( | ||
| 6671 | + msg.contains(needle), | ||
| 6672 | + "{NAME}: the refusal must name {needle:?}; it said: {msg}" | ||
| 6673 | + ); | ||
| 6674 | + } | ||
| 6675 | + eprintln!("{NAME}: refused -> {msg}"); | ||
| 6676 | + } | ||
| 6677 | + | ||
| 6678 | + /// lane-av1oracleguard, direction 2 of 2 (high depth): the same refusal on | ||
| 6679 | + /// `ffmpeg_decode_sequence_10bit` and `_12bit`, which ask ffmpeg for | ||
| 6680 | + /// `yuv420p10le`/`yuv420p12le` and slice chroma at `width * height / 4` | ||
| 6681 | + /// exactly as the 8-bit helper does. Pinned 4:2:2 at both depths. | ||
| 6682 | + #[test] | ||
| 6683 | + fn a_420_high_bit_depth_oracle_helpers_refuse_a_422_pin() { | ||
| 6684 | + const NAME: &str = "a_420_high_bit_depth_oracle_helpers_refuse_a_422_pin"; | ||
| 6685 | + let _gate_lock = lock_gate_counters(); | ||
| 6686 | + let cells: [(&str, usize, u64, fn(&[u8]) -> Vec<Pic>); 2] = [ | ||
| 6687 | + ( | ||
| 6688 | + "s422_352x242_10b.obu", | ||
| 6689 | + 20575, | ||
| 6690 | + 17425395593908182125, | ||
| 6691 | + |s: &[u8]| ffmpeg_decode_sequence_10bit(s, 352, 242, 1), | ||
| 6692 | + ), | ||
| 6693 | + ( | ||
| 6694 | + "s422_12bit_160x128.obu", | ||
| 6695 | + 9214, | ||
| 6696 | + 0xa62b8e3fe6f60ae5, | ||
| 6697 | + |s: &[u8]| ffmpeg_decode_sequence_12bit(s, 160, 128, 1), | ||
| 6698 | + ), | ||
| 6699 | + ]; | ||
| 6700 | + for (file, len, fnv, call) in cells { | ||
| 6701 | + let path = crate_pin(file); | ||
| 6702 | + let stream = read_pin(&path, len, fnv, NAME); | ||
| 6703 | + assert_eq!( | ||
| 6704 | + stream_subsampling(&stream, NAME), | ||
| 6705 | + (1, 0), | ||
| 6706 | + "{NAME}/{file}: the pin must really be 4:2:2 (1,0), or this proves nothing" | ||
| 6707 | + ); | ||
| 6708 | + let msg = panic_message(|| { | ||
| 6709 | + call(&stream); | ||
| 6710 | + }) | ||
| 6711 | + .unwrap_or_else(|| { | ||
| 6712 | + panic!( | ||
| 6713 | + "{NAME}/{file}: the 4:2:0 high-bit-depth oracle helper ACCEPTED a (1,0) \ | ||
| 6714 | + stream -- ffmpeg converted it and the helper returned a comparison that \ | ||
| 6715 | + could pass green" | ||
| 6716 | + ) | ||
| 6717 | + }); | ||
| 6718 | + for needle in ["(1,0)", "4:2:2", "ffmpeg_decode_sequence_422_depth"] { | ||
| 6719 | + assert!( | ||
| 6720 | + msg.contains(needle), | ||
| 6721 | + "{NAME}/{file}: the refusal must name {needle:?}; it said: {msg}" | ||
| 6722 | + ); | ||
| 6723 | + } | ||
| 6724 | + eprintln!("{NAME}/{file}: refused -> {msg}"); | ||
| 6725 | + } | ||
| 6726 | + } | ||
| 6481 | 6727 | ||
| 6482 | /// Packs decoded planes the way `aomdec --rawvideo` writes them for | 6728 | /// Packs decoded planes the way `aomdec --rawvideo` writes them for |
| 6483 | /// `bit_depth`: 1 byte per sample at 8-bit, 2 bytes little-endian at | 6729 | /// `bit_depth`: 1 byte per sample at 8-bit, 2 bytes little-endian at |
| @@ -6777,6 +7023,13 @@ pub(crate) mod tests { | |||
| 6777 | height: usize, | 7023 | height: usize, |
| 6778 | frames: usize, | 7024 | frames: usize, |
| 6779 | ) -> Vec<Pic> { | 7025 | ) -> Vec<Pic> { |
| 7026 | + // lane-av1oracleguard: this helper's numbers are 4:2:0's. A (1,0) or | ||
| 7027 | + // (0,0) stream would be CONVERTED by ffmpeg rather than refused. | ||
| 7028 | + assert_420_oracle_stream( | ||
| 7029 | + stream, | ||
| 7030 | + "ffmpeg_decode_sequence", | ||
| 7031 | + "ffmpeg_decode_sequence_422 (4:2:2) or ffmpeg_decode_sequence_444 (4:4:4)", | ||
| 7032 | + ); | ||
| 6780 | let out = run_with_stdin( | 7033 | let out = run_with_stdin( |
| 6781 | Command::new(ffmpeg_path()).args([ | 7034 | Command::new(ffmpeg_path()).args([ |
| 6782 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", | 7035 | "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", |
| @@ -6868,6 +7121,11 @@ pub(crate) mod tests { | |||
| 6868 | height: usize, | 7121 | height: usize, |
| 6869 | frames: usize, | 7122 | frames: usize, |
| 6870 | ) -> Vec<Pic> { | 7123 | ) -> Vec<Pic> { |
| 7124 | + assert_420_oracle_stream( | ||
| 7125 | + stream, | ||
| 7126 | + "ffmpeg_decode_sequence_10bit", | ||
| 7127 | + "ffmpeg_decode_sequence_422_depth(.., 10, \"yuv422p10le\") (4:2:2); ffmpeg_decode_sequence_444 is 8-bit only", | ||
| 7128 | + ); | ||
| 6871 | let out = run_with_stdin( | 7129 | let out = run_with_stdin( |
| 6872 | Command::new(ffmpeg_path()).args([ | 7130 | Command::new(ffmpeg_path()).args([ |
| 6873 | "-v", | 7131 | "-v", |
| @@ -17170,6 +17428,11 @@ exit 0 | |||
| 17170 | height: usize, | 17428 | height: usize, |
| 17171 | frames: usize, | 17429 | frames: usize, |
| 17172 | ) -> Vec<Pic> { | 17430 | ) -> Vec<Pic> { |
| 17431 | + assert_420_oracle_stream( | ||
| 17432 | + stream, | ||
| 17433 | + "ffmpeg_decode_sequence_12bit", | ||
| 17434 | + "ffmpeg_decode_sequence_422_depth(.., 12, \"yuv422p12le\") (4:2:2); ffmpeg_decode_sequence_444 is 8-bit only", | ||
| 17435 | + ); | ||
| 17173 | let out = run_with_stdin( | 17436 | let out = run_with_stdin( |
| 17174 | Command::new("ffmpeg").args([ | 17437 | Command::new("ffmpeg").args([ |
| 17175 | "-v", | 17438 | "-v", |
lanes/av1oracleguard.report.mdadded+171 -0
| @@ -0,0 +1,171 @@ | |||
| 1 | +# lane/av1oracleguard — the 4:2:0 ffmpeg oracle helpers now REFUSE a non-4:2:0 stream | ||
| 2 | + | ||
| 3 | +Base `main` = `b8385c93` ("Merge lane/ecimagewallclock"). | ||
| 4 | +Worktree `~/Documents/Code/Rust/edith_codecs-oracleguard`, own | ||
| 5 | +`CARGO_TARGET_DIR=~/.cache/tgt/av1oracleguard`. | ||
| 6 | + | ||
| 7 | +## The hazard, and why it was silent | ||
| 8 | + | ||
| 9 | +`crates/ec-av1/src/stream.rs`'s 4:2:0 oracle helpers ask ffmpeg for a 4:2:0 | ||
| 10 | +pix_fmt and size chroma at `width * height / 4`: | ||
| 11 | + | ||
| 12 | +| helper | pix_fmt | chroma span | | ||
| 13 | +|---|---|---| | ||
| 14 | +| `ffmpeg_decode_sequence` (`7033` call site) | `yuv420p` | `w*h/4` | | ||
| 15 | +| `ffmpeg_decode_sequence_10bit` (`7125`) | `yuv420p10le` | `w*h/4` | | ||
| 16 | +| `ffmpeg_decode_sequence_12bit` (`17428`) | `yuv420p12le` | `w*h/4` | | ||
| 17 | + | ||
| 18 | +The failure mode is that **ffmpeg does not refuse a mismatched stream — it | ||
| 19 | +CONVERTS**. It emits a 4:2:0 picture, so the helper's own byte-count assert | ||
| 20 | +(`out.stdout.len() == frame_bytes * frames`) passes, the helper returns a `Vec<Pic>`, | ||
| 21 | +and a gate built on it compares CONVERTED chroma against our REAL 4:2:2 chroma. | ||
| 22 | +`lanes/av1subsizesweep.report.md:245` names exactly this: *"a future 4:2:2 gate | ||
| 23 | +using them compares half the oracle's bytes and passes green."* | ||
| 24 | + | ||
| 25 | +The correct siblings already existed: `ffmpeg_decode_sequence_422`, | ||
| 26 | +`ffmpeg_decode_sequence_422_depth`, `ffmpeg_decode_sequence_444`. | ||
| 27 | + | ||
| 28 | +## The change | ||
| 29 | + | ||
| 30 | +One shared guard, called as the FIRST statement of each helper — before the | ||
| 31 | +ffmpeg spawn, so a host without ffmpeg still proves the refusal. | ||
| 32 | + | ||
| 33 | +- `stream_subsampling(stream, name) -> (u8, u8)` (`6527` region): the stream's | ||
| 34 | + OWN `color_config.subsampling_x/y`, read from its sequence-header OBUs with | ||
| 35 | + `Av1Parser`, using the existing `stream_bit_depth` / `assert_12bit_sequence_header` | ||
| 36 | + loop. Never inferred from the caller's `width`/`height`. | ||
| 37 | +- `chroma_shape(sx, sy)`: (1,1)→4:2:0, (1,0)→4:2:2, (0,0)→4:4:4, (0,1)→4:4:0. | ||
| 38 | +- `assert_420_oracle_stream(stream, helper, sibling)`: asserts `(sx,sy) == (1,1)`. | ||
| 39 | + The message names the real subsampling, the chroma shape it means, the reason | ||
| 40 | + (`CONVERTS` + `width*height/4`), and the sibling to use. | ||
| 41 | + | ||
| 42 | +The diff is **256 insertions, 0 deletions, 0 modified lines** — every existing | ||
| 43 | +line is byte-identical, so the 4:2:0 path is unchanged by construction, not by | ||
| 44 | +argument. | ||
| 45 | + | ||
| 46 | +Sample of the message actually produced: | ||
| 47 | + | ||
| 48 | +``` | ||
| 49 | +ffmpeg_decode_sequence REFUSED a (1,0) stream: this helper asks ffmpeg for a | ||
| 50 | +4:2:0 pix_fmt, which CONVERTS the stream's real 4:2:2 chroma down to 4:2:0 | ||
| 51 | +instead of failing, then sizes chroma at `width * height / 4` rather than the | ||
| 52 | +4:2:2 shape. A gate built on it would compare converted planes against real | ||
| 53 | +ones and pass green. Use `ffmpeg_decode_sequence_422 (4:2:2) or | ||
| 54 | +ffmpeg_decode_sequence_444 (4:4:4)` for a (1,0) stream. | ||
| 55 | +``` | ||
| 56 | + | ||
| 57 | +### Class sweep: the 10-bit sibling | ||
| 58 | + | ||
| 59 | +`lanes/av1subsizesweep.report.md:245` calls the unguarded set "the 4:2:0 trio". | ||
| 60 | +`ffmpeg_decode_sequence_10bit` is the identical hazard (`yuv420p10le`, same | ||
| 61 | +`w*h/4` span) and got the same one-line guard. It was NOT in the original | ||
| 62 | +assignment's target list; it is reported here rather than silently widened. | ||
| 63 | + | ||
| 64 | +`probe.rs::source` (`:81`, listed at the same table row) is deliberately NOT this | ||
| 65 | +class: it loads a clip and *asks* ffmpeg to convert it to `yuv420p`, then asserts | ||
| 66 | +the converted shape. It is a source-card loader, not an AV1 OBU oracle. Left | ||
| 67 | +untouched, deliberately. | ||
| 68 | + | ||
| 69 | +## Non-vacuity, both directions | ||
| 70 | + | ||
| 71 | +**Direction 1 — the comparator still bites** (`a_420_oracle_comparator_counts_a_flipped_oracle_sample`). | ||
| 72 | +Pin `420_mixll_256x128_6f.obu` (22336 B, fnv1a64 `5694016005779287373`), | ||
| 73 | +8-bit 4:2:0 at 256x128. Asserts the pin's own subsampling is (1,1), decodes it | ||
| 74 | +with `decode_stream`, takes `ffmpeg_decode_sequence(&data, 256, 128, n)`, and | ||
| 75 | +counts per-plane mismatches: **`[0, 0, 0]`**. Then flips exactly one oracle | ||
| 76 | +sample (`flipped[0].u[0] ^= 1`) and re-counts: **`[0, 1, 0]`** — the U count | ||
| 77 | +moved by exactly 1, Y and V unmoved. Measured output: | ||
| 78 | + | ||
| 79 | +``` | ||
| 80 | +a_420_oracle_comparator_counts_a_flipped_oracle_sample: clean per-plane counts | ||
| 81 | +[0, 0, 0], after one flipped oracle U sample [0, 1, 0] | ||
| 82 | +``` | ||
| 83 | + | ||
| 84 | +This also IS the "4:2:0 behaviour is byte-identical" evidence: the helper still | ||
| 85 | +produces a picture ours matches sample-for-sample on a real 4:2:0 pin. | ||
| 86 | + | ||
| 87 | +**Direction 2 — the refusal fires** (two tests). | ||
| 88 | + | ||
| 89 | +- `a_420_oracle_helper_refuses_a_422_pin`: `422_key_64x64.obu` (755 B, | ||
| 90 | + fnv1a64 `0x87fc569cf53bcbc6`), (1,0), into `ffmpeg_decode_sequence(…, 64, 64, 1)`. | ||
| 91 | +- `a_420_high_bit_depth_oracle_helpers_refuse_a_422_pin`: `s422_352x242_10b.obu` | ||
| 92 | + (20575 B) into `_10bit`, and `s422_12bit_160x128.obu` (9214 B, | ||
| 93 | + fnv1a64 `0xa62b8e3fe6f60ae5`) into `_12bit`. Both (1,0). | ||
| 94 | + | ||
| 95 | +Each asserts the pin's own subsampling first (so the test cannot pass on a pin | ||
| 96 | +that stopped being 4:2:2), then runs the helper under `catch_unwind` with the | ||
| 97 | +panic hook silenced, and requires the message to contain `(1,0)`, `4:2:2` AND | ||
| 98 | +the sibling name. `#[should_panic(expected = …)]` was rejected: it matches one | ||
| 99 | +substring, so it could not prove the sibling is named. | ||
| 100 | + | ||
| 101 | +**Red-before (mutation)**: reducing `assert_420_oracle_stream` to | ||
| 102 | +`fn assert_420_oracle_stream(_: &[u8], _: &str, _: &str) {}` turns BOTH refusal | ||
| 103 | +tests red, and the failure text is the hazard itself: | ||
| 104 | + | ||
| 105 | +``` | ||
| 106 | +a_420_oracle_helper_refuses_a_422_pin: ffmpeg_decode_sequence ACCEPTED a (1,0) | ||
| 107 | +stream. ffmpeg converted it to 4:2:0 and the helper returned a green-looking | ||
| 108 | +comparison | ||
| 109 | +``` | ||
| 110 | + | ||
| 111 | +Guard restored; both green again. | ||
| 112 | + | ||
| 113 | +## Did any existing test build on a 4:2:0 helper with a non-4:2:0 stream? | ||
| 114 | + | ||
| 115 | +**No — none.** Reported, not adapted, as asked. | ||
| 116 | + | ||
| 117 | +Two independent checks: | ||
| 118 | + | ||
| 119 | +1. A static scan of every test function in `stream.rs` that calls one of the | ||
| 120 | + three guarded helpers AND references a fixture whose name contains | ||
| 121 | + `422`/`440`/`444`/`441` returns exactly two rows: this lane's own refusal | ||
| 122 | + tests. No pre-existing gate feeds a wrong-shape pin to a 4:2:0 helper. | ||
| 123 | +2. A runtime check: `EC_AV1_REQUIRE_FFMPEG=1 cargo test -p ec-av1 --lib -- 422 | ||
| 124 | + 440 444 441 chroma_shape subsampling` → **68 passed, 0 failed** (35.9 s). | ||
| 125 | + If any of those 4:2:2/4:4:0 gates had been silently converted, the new guard | ||
| 126 | + would have turned them red there. | ||
| 127 | + | ||
| 128 | +A third scan checked the four generically-named tests that matched a loose | ||
| 129 | +`422|440|444` regex in their bodies (`a_lossless_libaom_inter_frame_decodes_sample_exact`, | ||
| 130 | +`a_lossless_16x4_chroma_pair_repairs_the_measured_site`, | ||
| 131 | +`a_real_aomenc_rect_strip_palette_decodes_pixel_exact`, | ||
| 132 | +`a_superres_key_frame_with_cdef_and_loop_restoration_decodes_pixel_exact`) — all | ||
| 133 | +four source their fixtures from `-pix_fmt yuv420p`/`yuv420p10le` y4m or from an | ||
| 134 | +8-bit 4:2:0 encode. Genuine 4:2:0 inputs. | ||
| 135 | + | ||
| 136 | +## Runs | ||
| 137 | + | ||
| 138 | +| run | result | | ||
| 139 | +|---|---| | ||
| 140 | +| `cargo test -p ec-av1 --lib -- <the three new gates>` `EC_AV1_REQUIRE_FFMPEG=1` | **3 passed, 0 failed** | | ||
| 141 | +| same, guard mutated to a no-op | **0 passed, 2 failed** (the two refusal tests) | | ||
| 142 | +| `cargo test -p ec-av1 --lib -- 422 440 444 441 chroma_shape subsampling` | **68 passed, 0 failed** | | ||
| 143 | +| `cargo test -p ec-av1 --lib -- pinned pinned_` | **24 passed, 0 failed, 2 ignored** | | ||
| 144 | +| `cargo test -p ec-av1 --lib -- pixel_exact` | **257 passed, 0 failed** (924 s) | | ||
| 145 | + | ||
| 146 | +`EC_AV1_REQUIRE_FFMPEG=1` on every one of them, so a missing ffmpeg could not | ||
| 147 | +silently green a gate. No server suite was staged for this lane; the full `ec-av1` | ||
| 148 | +suite is the main agent's call. | ||
| 149 | + | ||
| 150 | +## Not closed, stated plainly | ||
| 151 | + | ||
| 152 | +1. **No full-suite run.** The 4:2:0 helpers have ~180 call sites and the | ||
| 153 | + `pixel_exact` family alone is 257 tests. That family and the shape-filtered | ||
| 154 | + run are green, and both the static scan and those runs say no caller feeds a | ||
| 155 | + wrong-shape stream — but that is a scoped claim, not a whole-suite claim. | ||
| 156 | + The remaining filtered-out tests include the `aomenc`-sourced gates, which | ||
| 157 | + SKIP on this host (no `aomenc` on PATH) and need a server run to execute. | ||
| 158 | + | ||
| 159 | +2. **`assert_420_oracle_stream` panics; it does not return `Result`.** That is | ||
| 160 | + deliberate — every oracle helper in this file is assert-based, and changing | ||
| 161 | + the 8-bit one to `Result` would ripple through 176 call sites. The refusal | ||
| 162 | + message names the sibling so a caller that trips it has the fix in front of | ||
| 163 | + it. A `Result`-returning variant would be a separate, larger lane. | ||
| 164 | +3. **`ffmpeg_decode_sequence_444` has no depth-generic sibling.** The refusal | ||
| 165 | + message says so explicitly ("`ffmpeg_decode_sequence_444` is 8-bit only") | ||
| 166 | + rather than naming a helper that does not exist at 10/12-bit. A high-depth | ||
| 167 | + 4:4:4 oracle is a real gap, not one this lane closed. | ||
| 168 | +4. **The guard proves the shape, not the depth.** `assert_12bit_sequence_header` | ||
| 169 | + already covers depth for the 12-bit gates; `_10bit` has no depth assert | ||
| 170 | + (`stream_bit_depth` exists and could be applied the same way). Out of scope | ||
| 171 | + here, named so it is not lost. | ||
| \ No newline at end of file | \ No newline at end of file | ||