diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 91af85c9..0cd5b5d3 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -5797,7 +5797,7 @@ pub(crate) mod tests { frames: usize, ) -> Vec { let out = run_with_stdin( - Command::new("ffmpeg").args([ + Command::new(ffmpeg_path()).args([ "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv420p", "-", ]), stream, @@ -5857,7 +5857,7 @@ pub(crate) mod tests { frames: usize, ) -> Vec { let out = run_with_stdin( - Command::new("ffmpeg").args([ + Command::new(ffmpeg_path()).args([ "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "gray", "-", ]), stream, @@ -5888,7 +5888,7 @@ pub(crate) mod tests { frames: usize, ) -> Vec { let out = run_with_stdin( - Command::new("ffmpeg").args([ + Command::new(ffmpeg_path()).args([ "-v", "error", "-f", @@ -10221,6 +10221,33 @@ pub(crate) mod tests { ORACLE_PATH.with(|c| *c.borrow_mut() = path); } + // lane-film10fix: this thread's ffmpeg override, set by + // `set_ffmpeg_path` and consulted by `ffmpeg_path` ahead of the bare + // name. Same shape and same reason as `ORACLE_PATH` above: the control + // test `every_ffmpeg_comparator_reds_on_a_one_sample_wrong_ffmpeg` has + // to hand the `ffmpeg_decode_sequence*` helpers a DELIBERATELY WRONG + // reference, and a process-global PATH edit would leak that wrong + // reference into every sibling test decoding on another thread. The + // crate denies `unsafe_code`, so `std::env::set_var` is not available + // either; a thread-local confines the tamper to the one thread. + thread_local! { + static FFMPEG_PATH: std::cell::RefCell> = + const { std::cell::RefCell::new(None) }; + } + + /// Points this thread's `ffmpeg_decode_sequence*` helpers at `path`. + /// `None` restores the real `ffmpeg` on PATH. + fn set_ffmpeg_path(path: Option) { + FFMPEG_PATH.with(|c| *c.borrow_mut() = path); + } + + /// The `ffmpeg` every reference helper in this module spawns. + fn ffmpeg_path() -> std::path::PathBuf { + if let Some(p) = FFMPEG_PATH.with(|c| c.borrow().clone()) { + return p; + } + std::path::PathBuf::from("ffmpeg") + } /// The instrumented `aomdec` beside the `aomenc` oracle /// (`scripts/build-aom-oracle.sh` + `scripts/instrument-aom-oracle.sh`). @@ -10509,9 +10536,8 @@ pub(crate) mod tests { (1, 0), "{NAME}: arm 1 expects one decode-order frame and no hidden frames" ); - let (wy, wu, wv, n, exact) = - count_rawvideo_diffs(&stream, "oracle-control-arm1-count") - .expect("arm 1: the two sides must be byte-comparable"); + let (wy, wu, wv, n, exact) = count_rawvideo_diffs(&stream, "oracle-control-arm1-count") + .expect("arm 1: the two sides must be byte-comparable"); assert_eq!( (wy, wu, wv), (0, 0, 0), @@ -10545,8 +10571,11 @@ pub(crate) mod tests { // The real oracle's path rides in a sibling file rather than inside // the script, so a path with a quote or a space cannot mangle it and // the script body needs no `format!` escaping at all. - std::fs::write(dir.join("real-aomdec"), aomdec_path().as_os_str().as_encoded_bytes()) - .expect("recording the real oracle's path for the shim"); + std::fs::write( + dir.join("real-aomdec"), + aomdec_path().as_os_str().as_encoded_bytes(), + ) + .expect("recording the real oracle's path for the shim"); // Byte 7 of both the `--rawvideo` output and the `EC_AV1_FINAL_DUMP` // frame 0 is inside the Y plane, and its value is rotated by 128 so // the write always changes it. Nothing else is touched: the stream, @@ -10591,9 +10620,8 @@ exit 0 let reds: [bool; 5]; { set_oracle_path(Some(shim.clone())); - let panicked = |f: &dyn Fn()| { - std::panic::catch_unwind(std::panic::AssertUnwindSafe(f)).is_err() - }; + let panicked = + |f: &dyn Fn()| std::panic::catch_unwind(std::panic::AssertUnwindSafe(f)).is_err(); let rawvideo_red = panicked(&|| { let obu = std::env::temp_dir().join(format!("{NAME}-arm2.obu")); std::fs::write(&obu, &stream).expect("writing the pin for arm 2"); @@ -10651,6 +10679,397 @@ exit 0 eprintln!("{NAME}: all five oracle comparators red on a one-byte-wrong oracle"); } + /// lane-film10fix: the permanent CONTROL for the ffmpeg half of the class + /// `comparator-that-never-reads-the-oracle`. + /// + /// Its sibling above covers the five `aomdec` comparators. The `ffmpeg` + /// half had no such control, and it is the half the two 10-bit FILM gates + /// rest on: `a_10bit_128sb_film_frames_with_warp_cdef_and_interintra_...` + /// and `a_10bit_film_frames_with_small_side_globalmv_and_rect_warp_...` + /// both declare "pixel-exact" purely as + /// `assert_eq!(ours., ffmpeg_decode_sequence_10bit(...).)` + /// over 15 and 33 shown frames. If `ffmpeg_decode_sequence_10bit` ever + /// stopped reading ffmpeg's stdout -- packed our own samples into the + /// buffer it returns, say -- both gates would report exact on a decoder + /// that could be arbitrarily wrong, and nothing in the crate would go + /// red. Reading the helper's source proves it is live TODAY; only a + /// deliberately wrong reference proves it can FAIL. + /// + /// So this is the same two-arm shape, pointed at ffmpeg. The shim runs the + /// REAL ffmpeg and then rotates ONE byte of its rawvideo stdout per + /// offset in a sibling file, leaving the stream, the geometry, the frame + /// count and every other sample a genuine decode. On a pin that IS + /// byte-exact against real ffmpeg: + /// + /// 1. **arm 1, real ffmpeg: every helper is GREEN.** Without this arm, + /// arm 2's red could just be a stream that was never exact. + /// 2. **arm 2, one-sample-wrong ffmpeg, PER PLANE: every helper is RED + /// and the red names the plane that was tampered with.** Three arms, + /// one per plane, because a helper that only ever compared luma would + /// pass the Y arm and fail U and V -- and a 10-bit film gate that + /// reported "exact" while ignoring chroma entirely would be exactly + /// the class this controls. + /// + /// The three helpers are the whole reference surface in this module: + /// `ffmpeg_decode_sequence` (4:2:0 8-bit), `ffmpeg_decode_gray_sequence` + /// (monochrome, one plane) and `ffmpeg_decode_sequence_10bit` (the + /// `yuv420p10le` family both film gates use). Each is driven on a pin it + /// is known to be exact against: the 8-bit `420_odd65x65_key.obu` for the + /// first, the same stream for the third's shape arithmetic, and the + /// monochrome recipe the mono gate already builds for the second. The + /// override is thread-local, so a red arm cannot leave a tampered ffmpeg + /// behind for a sibling test on another thread. + #[test] + fn every_ffmpeg_comparator_reds_on_a_one_sample_wrong_ffmpeg() { + const NAME: &str = "every_ffmpeg_comparator_reds_on_a_one_sample_wrong_ffmpeg"; + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + // Same mutex the oracle control takes: this test's shim is + // thread-local, but the SCREAM it produces must not interleave with a + // sibling's decode in the captured log. + let _gate_lock = lock_gate_counters(); + + // The 4:2:0 8-bit arm. It BUILDS its stream with the same + // `libaom-av1` lavfi recipe the mono gate below uses rather than + // pinning one: `ffmpeg_decode_sequence` derives its frame size as + // `w*h + 2*(w*h/4)`, which is only right for EVEN dimensions -- on a + // 65x65 stream 4:2:0 chroma is ceil(65/2)^2 = 1089, not 4225/4 = + // 1056, and the helper's length assert fires (loudly, by design -- + // see `frame_count_diagnosis`). 320x240 keeps the offsets below + // exact: luma 76800 samples, chroma 160x120 = 19200 each. + let (w, h) = (320usize, 240usize); + let (ys, cs) = (w * h, (w / 2) * (h / 2)); + assert_eq!( + (ys, cs), + (76800, 19200), + "{NAME}: the byte offsets in this test are computed from this geometry" + ); + let build_8bit = { + let out = Command::new(ffmpeg_path()) + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + "testsrc2=size=320x240:rate=30:duration=1", + "-pix_fmt", + "yuv420p", + "-c:v", + "libaom-av1", + "-cpu-used", + "8", + "-b:v", + "300k", + "-f", + "obu", + "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to build the 4:2:0 8-bit arm"); + assert!( + out.status.success(), + "{NAME}: ffmpeg could not build the 8-bit arm: {}", + String::from_utf8_lossy(&out.stderr) + ); + out.stdout + }; + assert_eq!( + stream_bit_depth(&build_8bit, NAME), + 8, + "{NAME}: this arm is the 8-bit cell the byte offsets below are computed for" + ); + let our_8bit = + decode_stream(&build_8bit).expect("the 8-bit arm must decode -- arm 1 needs it exact"); + assert!( + !our_8bit.is_empty(), + "{NAME}: the 8-bit arm decoded nothing" + ); + let frames_8bit = our_8bit.len(); + + // The monochrome recipe, byte-identical to the one + // `a_real_libaom_monochrome_key_frame_decodes_pixel_exact` builds, so + // the gray helper is driven on a stream that gate already proves + // exact. A MONOCHROME stream is also this test's 4:2:0 4:2:0-free + // arm: `ffmpeg_decode_gray_sequence` returns a flat luma buffer, so + // the one flipped offset must be attributed to Y and to nothing else. + let gray_stream = { + let out = Command::new(ffmpeg_path()) + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + "testsrc2=size=64x64:rate=30:duration=1", + "-pix_fmt", + "gray", + "-c:v", + "libaom-av1", + "-cpu-used", + "8", + "-b:v", + "100k", + "-f", + "obu", + "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to build the monochrome arm"); + assert!( + out.status.success(), + "{NAME}: ffmpeg could not build the monochrome arm: {}", + String::from_utf8_lossy(&out.stderr) + ); + out.stdout + }; + let our_gray = decode_stream(&gray_stream).expect("the monochrome arm must decode"); + assert!( + !our_gray.is_empty(), + "{NAME}: the monochrome arm decoded nothing" + ); + let frames_gray = our_gray.len(); + + // ---- the one-sample-wrong ffmpeg shim --------------------------- + let dir = std::env::temp_dir().join(format!("ec-av1-{NAME}-{}", std::process::id())); + let _ = std::fs::remove_dir_all(&dir); + std::fs::create_dir_all(&dir).expect("scratch dir"); + // The real ffmpeg's path rides in a sibling file rather than inside + // the script, so a path with a space or a quote cannot mangle it and + // the script body needs no `format!` escaping. + let real = if let Some(p) = std::env::var_os("EC_AV1_FFMPEG") { + std::path::PathBuf::from(p) + } else { + let found = Command::new("ffmpeg") + .arg("-version") + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status() + .is_ok_and(|s| s.success()); + assert!(found, "{NAME}: no working ffmpeg on PATH to wrap"); + // Resolve the bare name through PATH so the shim does not depend + // on inheriting whatever PATH the test runner had. + let path = std::env::var_os("PATH").unwrap_or_default(); + std::env::split_paths(&path) + .map(|d| d.join("ffmpeg")) + .find(|p| p.is_file()) + .expect("{NAME}: ffmpeg is on PATH but not resolvable to a file") + }; + std::fs::write(dir.join("real-ffmpeg"), real.as_os_str().as_encoded_bytes()) + .expect("recording the real ffmpeg's path for the shim"); + // Each line of `offsets` is one byte of the rawvideo stdout to rotate + // by 128, so the write always changes it. Everything else -- the + // stream, the geometry, the frame count, every other sample -- is a + // genuine ffmpeg decode. stdin is inherited so the shim is a drop-in + // for the helpers' `run_with_stdin` call. + let script = r#"#!/bin/sh +REAL=$(cat "$(dirname "$0")/real-ffmpeg") +OUT=$(mktemp) +"$REAL" "$@" > "$OUT" || exit $? +while read -r o; do + [ -n "$o" ] || continue + b=$(od -An -tu1 -j "$o" -N 1 "$OUT" 2>/dev/null | tr -d ' \n') + [ -n "$b" ] || continue + esc=$(printf '\\%03o' $(( (b + 128) % 256 ))) + printf "$esc" | dd of="$OUT" bs=1 seek="$o" count=1 conv=notrunc 2>/dev/null +done < "$(dirname "$0")/offsets" +cat "$OUT" +rm -f "$OUT" +exit 0 +"#; + let shim = dir.join("one-sample-wrong-ffmpeg.sh"); + std::fs::write(&shim, script).expect("writing the ffmpeg shim"); + #[cfg(unix)] + { + use std::os::unix::fs::PermissionsExt; + std::fs::set_permissions(&shim, std::fs::Permissions::from_mode(0o755)) + .expect("the ffmpeg shim must be executable"); + } + let set_offsets = |bytes: &[usize]| { + let body: String = bytes + .iter() + .map(|b| format!("{b}\n")) + .collect::>() + .concat(); + std::fs::write(dir.join("offsets"), body).expect("writing the offsets file"); + }; + // A comparator that cannot report a difference is worse than none, so + // each arm is scored as a COUNT of differing samples, not as a panic. + let count8 = |theirs: &[Pic]| -> [usize; 3] { + let mut wrong = [0usize; 3]; + for (plane, (x, y)) in [ + (0usize, (&our_8bit[0].y, &theirs[0].y)), + (1, (&our_8bit[0].u, &theirs[0].u)), + (2, (&our_8bit[0].v, &theirs[0].v)), + ] { + wrong[plane] = x.iter().zip(y).filter(|(a, b)| a != b).count(); + } + wrong + }; + + // The 10-bit FILM pin, and the comparator both charter-named film + // gates rest on. Driven on the real stream rather than a synthetic + // one: `ffmpeg_decode_sequence_10bit` is the only reference helper + // with a per-plane split, so it is the one that could silently lose a + // plane. 1920x792 at 10 bits: luma 1920*792*2 bytes per frame, chroma + // 960*396*2. + let film = std::fs::read(crate_pin("reelc_sb128_inter_witness.obu")).unwrap_or_else(|e| { + panic!( + "{NAME}: the 10-bit film pin reelc_sb128_inter_witness.obu is missing ({e}) -- \ + restore the committed copy" + ) + }); + assert_eq!( + stream_bit_depth(&film, NAME), + 10, + "{NAME}: this arm is the 10-bit cell the byte offsets below are computed for" + ); + let our_10bit = + decode_stream(&film).expect("the 10-bit film pin must decode -- arm 1 needs it exact"); + let (fw, fh) = (1920usize, 792usize); + let film_frames = our_10bit.len(); + let (fys, fcs) = (fw * fh * 2, (fw / 2) * (fh / 2) * 2); + let count10 = |theirs: &[Pic]| -> [usize; 3] { + let mut wrong = [0usize; 3]; + for (a, b) in our_10bit.iter().zip(theirs) { + for (plane, (x, y)) in + [(0usize, (&a.y, &b.y)), (1, (&a.u, &b.u)), (2, (&a.v, &b.v))] + { + wrong[plane] += x.iter().zip(y).filter(|(p, q)| p != q).count(); + } + } + wrong + }; + let count_gray = |theirs: &[u8]| -> usize { + our_gray[0] + .y + .iter() + .zip(theirs) + .filter(|(a, b)| **a != u16::from(**b)) + .count() + }; + + // ---- arm 1: the real ffmpeg, every comparator GREEN ------------ + { + set_offsets(&[]); + set_ffmpeg_path(None); + let theirs = ffmpeg_decode_sequence(&build_8bit, w, h, frames_8bit); + assert_eq!( + count8(&theirs), + [0, 0, 0], + "{NAME}: arm 1 runs against the REAL ffmpeg, so every plane must be zero -- if \ + this is red the stream is not the byte-exact pin this control needs" + ); + let their_gray = ffmpeg_decode_gray_sequence(&gray_stream, 64, 64, frames_gray); + assert_eq!( + count_gray(&their_gray), + 0, + "{NAME}: arm 1's monochrome plane must be zero against the real ffmpeg" + ); + // arm 1's 10-bit half: the film pin is byte-exact against real + // ffmpeg on every plane of every shown frame -- that is exactly + // what `a_10bit_128sb_film_frames_with_warp_cdef_and_interintra_...` + // asserts -- so this is the cell the two charter-named film gates + // claim. + let their_10bit = ffmpeg_decode_sequence_10bit(&film, fw, fh, film_frames); + assert_eq!( + count10(&their_10bit), + [0, 0, 0], + "{NAME}: arm 1's 10-bit film pin must be zero on every plane against the real \ + ffmpeg -- if this is red the control's pin is not the byte-exact stream it needs" + ); + } + + // ---- arm 2: one sample wrong, PER PLANE ------------------------- + // The shim is thread-local, so the tampered reference is confined to + // this thread; it is cleared before anything is asserted, so a red arm + // cannot leave this test's own later work reading a wrong ffmpeg. + let mut blind: Vec = Vec::new(); + { + set_ffmpeg_path(Some(shim.clone())); + for (plane, (_name, base)) in [("Y", 0usize), ("U", ys), ("V", ys + cs)] + .into_iter() + .enumerate() + { + // Byte 1000 of the named plane: inside the 4:2:0 8-bit pin's + // luma (4225), inside its chroma (1024), or past both. + set_offsets(&[base + 1000]); + let theirs = ffmpeg_decode_sequence(&build_8bit, w, h, frames_8bit); + let got = count8(&theirs); + let want = [0usize, 0, 0]; + let mut expected = want; + expected[plane] = 1; + if got != expected { + blind.push(format!( + "ffmpeg_decode_sequence {plane} arm: counted {got:?}, expected \ + {expected:?} (exactly the one tampered sample)" + )); + } + } + // The 10-bit helper, per plane, on the 10-bit FILM pin. This is the + // arm that matters for the charter: both + // `a_10bit_128sb_film_frames_with_warp_cdef_and_interintra_...` + // and + // `a_10bit_film_frames_with_small_side_globalmv_and_rect_warp_...` + // declare "pixel-exact on every plane" using nothing but this + // helper's output. A helper that dropped U or V would leave both + // gates green while chroma went unchecked for 15 and 33 frames. + for (plane, (_name, base)) in [("Y", 0usize), ("U", fys), ("V", fys + fcs)] + .into_iter() + .enumerate() + { + // Sample 1000 of the named plane, two bytes per sample. + set_offsets(&[base + 2000]); + let theirs = ffmpeg_decode_sequence_10bit(&film, fw, fh, film_frames); + let got = count10(&theirs); + let mut expected = [0usize, 0, 0]; + expected[plane] = 1; + if got != expected { + blind.push(format!( + "ffmpeg_decode_sequence_10bit {plane} arm: counted {got:?}, expected \ + {expected:?} (exactly the one tampered sample)" + )); + } + } + // The monochrome helper: one plane, so the single flipped offset + // must show up as luma and nothing else can absorb it. + set_offsets(&[1000]); + let their_gray = ffmpeg_decode_gray_sequence(&gray_stream, 64, 64, frames_gray); + if count_gray(&their_gray) != 1 { + blind.push(format!( + "ffmpeg_decode_gray_sequence arm: counted {} differing luma samples, expected \ + exactly 1", + count_gray(&their_gray) + )); + } + set_ffmpeg_path(None); + } + let _ = std::fs::remove_dir_all(&dir); + // One assert, naming EVERY helper that failed to notice: a partial run + // would report the first and hide whether the others are covered. + assert!( + blind.is_empty(), + "{NAME}: {} of 7 ffmpeg comparator arms stayed GREEN against an ffmpeg that is wrong \ + by exactly one sample -- {blind:#?} -- they cannot fail, so their green proves \ + nothing (class `comparator-that-never-reads-the-oracle`)", + blind.len() + ); + eprintln!( + "{NAME}: ffmpeg_decode_sequence red on a one-sample-wrong Y, U and V separately; \ + ffmpeg_decode_gray_sequence red on one wrong luma sample; \ + ffmpeg_decode_sequence_10bit red on a one-sample-wrong Y, U and V of the 10-bit \ + film pin" + ); + } + /// lane-av1422anom: the odd-frame-HEIGHT 4:2:0 reconstruction defect, /// pinned and ratcheted. /// @@ -46437,6 +46856,59 @@ exit 0 ); } + /// lane-film10fix: the DECODE-ORDER half of the two charter-named 10-bit + /// film gates, against the instrumented `aomdec` rather than ffmpeg. + /// + /// `a_10bit_128sb_film_frames_with_warp_cdef_and_interintra_...` (15 shown + /// frames) and `a_10bit_film_frames_with_small_side_globalmv_and_rect_warp_...` + /// (33 shown) each hold exactly ONE hidden alt-ref frame, and both + /// compare through `ffmpeg_decode_sequence_10bit`, which emits SHOWN + /// frames only. So one frame in 16 and one in 34 of each stream is + /// outside both gates' reach -- class `gate-blind-to-hidden-frames`: a + /// defect in a hidden frame surfaces only as drift on some later shown + /// frame, if at all. Their doc comments claim the hidden frames were + /// compared byte-exact against aomdec, but that measurement lived in a + /// lane report, not in a test, so nothing re-ran it. + /// + /// This gate is that measurement, committed. + /// [`decode_all_frames_vs_oracle`] writes `EC_AV1_FINAL_DUMP` on both + /// sides (ours in `decode_stream`, the oracle's in rung 12 of + /// `scripts/instrument-aom-oracle.sh`) and byte-compares EVERY decode-order + /// frame, hidden included. Both fixtures are the same 1920x792 10-bit + /// films their own gates pin, at the sha256 those gates record. + /// + /// The frame counts are asserted, not just reported: 16 = 15 shown + 1 + /// hidden, 34 = 33 shown + 1. A stream that quietly lost its hidden ARF + /// would make this compare fewer frames and would otherwise read as a + /// pass. + #[test] + fn the_two_10bit_film_pins_match_aomdec_on_every_decode_order_frame() { + const NAME: &str = "the_two_10bit_film_pins_match_aomdec_on_every_decode_order_frame"; + let _gate_lock = lock_gate_counters(); + if !aomdec_available(NAME) { + return; + } + for (pin, frames, shown) in [ + ("reelc_sb128_inter_witness.obu", 16usize, 15usize), + ("gm_small_side_witness.obu", 34, 33), + ] { + let stream = std::fs::read(crate_pin(pin)) + .unwrap_or_else(|e| panic!("{NAME}: reading {pin}: {e}")); + let (decoded, hidden) = decode_all_frames_vs_oracle(&stream, NAME); + assert_eq!( + (decoded, hidden), + (frames, frames - shown), + "{NAME}: {pin} must decode to {frames} decode-order frames of which {shown} are \ + shown -- a stream that lost its hidden alt-ref would make the byte compare below \ + cover less than it claims" + ); + eprintln!( + "{NAME}: {pin} {decoded} decode-order frames ({hidden} hidden) byte-exact vs \ + aomdec EC_AV1_FINAL_DUMP on every plane" + ); + } + } + /// lane-t900 r11: the frame-edge MV clamp witness. /// /// `crates/ec-av1/fixtures/reelb_head_mvclamp_witness.obu` (72158 bytes, diff --git a/lanes/film10fix.report.md b/lanes/film10fix.report.md new file mode 100644 index 00000000..3914124d --- /dev/null +++ b/lanes/film10fix.report.md @@ -0,0 +1,196 @@ +# lane-film10fix — the two "pre-existing 10-BIT FILM divergences": MEASURED, both already exact + +Branch `lane-film10fix`, base `main` = `3f08ae3f`. + +## 0. The charter's premise, measured first + +The ticket asked me to fix or narrow two divergences recorded as deferred to a +"dedicated 10-bit-film round": (1) a film sample with warp + CDEF + inter-intra, +(2) small-side globalmv. Per the ticket's own instruction I reproduced both on +current `main` before believing the debt line. **Both are already exact.** The +debt line is stale. + +There is no `lanes/` report that names a 10-bit-film deferral of these two +cases. The nearest match, `lanes/av1444.report.md:251-269`, records the +opposite: those two gates FAILED at `1ad7e0fc` and `b9530604` and were +attributed to that lane's own 4:4:4 `record_uv_mode_mi` change (class +`override-slot-on-one-arm`), then FIXED there. Six suite logs +(`lanes/dq-suite.log`, `fi-suite.log`, `libdet-suite.log`, `rdoq-suite.log`, +`sse-suite.log`, `tw-suite.log`, `tpl2/3-suite.log`, `i64/suite2.log`) carry +both gates as `... ok`. + +### Case 1 — warp + CDEF + inter-intra +`crates/ec-av1/fixtures/reelc_sb128_inter_witness.obu`, 177773 B, +sha256 `09d995946d27695ef4b7b1a24a4d7ad85f8e2c8176d58ee54e825efc061f9cbc`. + +``` +$ cargo test -p ec-av1 --lib -- a_10bit_128sb_film_frames_with_warp_cdef_and_interintra_decode_pixel_exact --nocapture --test-threads=1 +a_10bit_128sb_film_frames_with_warp_cdef_and_interintra_decode_pixel_exact: + 15 shown frames pixel-exact on every plane; warp_plane_suppress=15 + cdef_idx=852 inter_sb128_vert=76 interintra_rect=118 + non_chroma_ref_ctx_skip=194 intra_in_inter_txctx=3787 edge_filter_mi_fix=206 + intra16x4_in_inter=(80, 163, 113) sub8_chroma_tx_from_ref=2 + inter_neighbour_not_smooth=370 tr_reach_longer_side=600 obmc_edge_span=33 +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 780 filtered out; finished in 8.44s +``` + +All 13 path counters fire (every one `assert!(n > 0)` in the gate), so this is +not a gate that passes by not reaching the code. + +### Case 2 — small-side globalmv +`crates/ec-av1/fixtures/gm_small_side_witness.obu`, 1158066 B, +sha256 `f1cdbcbb8d6d469c7957d70252ab42b24ab75f48a717600ffa25991458775dca`. + +``` +$ cargo test -p ec-av1 --lib -- a_10bit_film_frames_with_small_side_globalmv_and_rect_warp_reach_decode_pixel_exact --nocapture --test-threads=1 +a_10bit_film_frames_with_small_side_globalmv_and_rect_warp_reach_decode_pixel_exact: + 33 shown frames pixel-exact on every plane; gm_nontrans_small_side=1 + tr_reach_longer_side=2295 uv_mode_grid_override=138 +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 780 filtered out; finished in 21.33s +``` + +### Against `aomdec` too, on ALL decode-order frames +Both gates compare SHOWN frames only (ffmpeg emits shown frames only), so 1 of +16 and 1 of 34 decode-order frames per stream sit outside both gates — class +`gate-blind-to-hidden-frames`. Measured against the instrumented oracle's +`EC_AV1_FINAL_DUMP` (rung 12): + +``` +reelc_sb128_inter_witness.obu: 16 decode-order frames (1 hidden) byte-exact vs aomdec +gm_small_side_witness.obu: 34 decode-order frames (1 hidden) byte-exact vs aomdec +``` + +**0 wrong on all three planes, all 50 decode-order frames, both cells.** No +PREFILT/POSTDEBLOCK/POSTCDEF/FINAL stage ladder was needed: there is no +divergence to localize, so no stage is suspect and none is exonerated by +comparison. Naming a mechanism and a libaom file:line here would be fabrication. + +## 1. Non-vacuity control (the batch rule) + +A green comparator is a measurement only if it can go red. Both film gates +declare "pixel-exact on every plane" using nothing but +`ffmpeg_decode_sequence_10bit`'s output — a helper that stopped reading +ffmpeg's stdout would leave both green on a decoder that could be arbitrarily +wrong. + +**Measured with a PATH-level shim that runs the REAL ffmpeg and rotates exactly +one byte of its rawvideo stdout** (per plane, sample 1000; 1920x792 10-bit +frame = luma 3041280 B + chroma 760320 B, so byte 2000 / 3043280 / 3803600): + +| case | arm | result | +|---|---|---| +| warp+cdef+interintra | byte 2000 (Y) | `FAILED … frame 0 luma vs ffmpeg` | +| warp+cdef+interintra | byte 3043280 (U) | `FAILED … frame 0 U vs ffmpeg` | +| warp+cdef+interintra | byte 3803600 (V) | `FAILED … frame 0 V vs ffmpeg` | +| small-side globalmv | byte 2000 (Y) | `FAILED … frame 0 luma vs ffmpeg` | +| small-side globalmv | byte 3043280 (U) | `FAILED … frame 0 U vs ffmpeg` | +| small-side globalmv | byte 3803600 (V) | `FAILED … frame 0 V vs ffmpeg` | + +Six of six red, each naming the plane that was tampered with. The comparators +read the oracle. + +## 2. What I found instead, and committed + +Two real gaps, both closed. + +### 2a. The ffmpeg comparator family had NO committed control + +`every_oracle_comparator_reds_on_a_one_byte_wrong_oracle` (lane-av1cmpaudit2, +`3f08ae3f`) controls the five `aomdec` comparators. The `ffmpeg` half — the +half both charter-named film gates rest on — was audited **by reading only** +(`lanes/av1cmpaudit2.report.md:48-52`: "all reach ffmpeg through a real +`Command::output()` and compare the stdout — LIVE"). Reading proves it is live +today; only a deliberately wrong reference proves it can FAIL. + +New gate **`every_ffmpeg_comparator_reds_on_a_one_sample_wrong_ffmpeg`** +(`crates/ec-av1/src/stream.rs`), 7 arms: + +- `set_ffmpeg_path` / `ffmpeg_path()` — a THREAD-LOCAL ffmpeg override, same + shape and same reason as the existing `set_oracle_path`: a process-global + PATH edit would leak the tampered reference into every sibling test on + another thread, and the crate denies `unsafe_code` so `set_var` is out. +- arm 1, real ffmpeg: 4:2:0 8-bit (320x240), monochrome (64x64 gray) and the + 10-bit film pin (1920x792) all count `[0, 0, 0]` / `0`. Without this arm, + arm 2's red could just be a stream that was never exact. +- arm 2, one sample wrong **per plane**: `ffmpeg_decode_sequence` red on Y, + U and V separately; `ffmpeg_decode_gray_sequence` red on one luma sample; + `ffmpeg_decode_sequence_10bit` red on Y, U and V separately **of the 10-bit + film pin** — the comparator both charter-named gates use. Per-plane arms, not + one: a helper that dropped chroma would pass a luma-only arm and leave both + film gates green with chroma unchecked for 15 and 33 frames. +- All three reference helpers now spawn through the override. + +Mutation proofs (both reverted before commit): + +1. Revert `ffmpeg_decode_sequence` to the bare `"ffmpeg"` (the override no + longer reaches it) → `3 of 7 ffmpeg comparator arms stayed GREEN … + counted [0, 0, 0], expected [1, 0, 0]`, `test result: FAILED`. +2. Make `ffmpeg_decode_sequence_10bit` return zeros for V instead of ffmpeg's + samples → `arm 1's 10-bit film pin must be zero on every plane … + left: [0, 0, 5702400], right: [0, 0, 0]`, `test result: FAILED`. That is + the retracted `av1422remeasure` defect reproduced inside the 10-bit helper. + +### 2b. The hidden alt-ref frame of each film stream was outside every gate + +Both film gates' doc comments claim their hidden frames were compared +byte-exact against aomdec, but that measurement lived in a lane report +(`t900-r7`, `t900-r10`), not in a test, so nothing re-ran it. New gate +**`the_two_10bit_film_pins_match_aomdec_on_every_decode_order_frame`** runs +`decode_all_frames_vs_oracle` on both pins and asserts the frame COUNTS +(16 = 15 shown + 1 hidden, 34 = 33 + 1) before the byte compare, so a stream +that quietly lost its hidden ARF cannot make the compare cover less than it +claims. + +Mutation proof (reverted before commit): one byte wrong in our own +`EC_AV1_FINAL_DUMP` write → + +``` +decode-order frame 0 of 16 (15 shown, 1 hidden) differs from the oracle at +byte 7 (ours 128 vs 0), 1 bytes differ +test result: FAILED +``` + +## 3. Sweep + +Re-ran, on this branch, `EC_AV1_REQUIRE_AOMDEC=1 EC_AV1_REQUIRE_AOMENC=1 +EC_AV1_REQUIRE_FIXTURES=1 EC_NOMEMGUARD=1`: + +| cell | result | +|---|---| +| `a_10bit_128sb_film_frames_with_warp_cdef_and_interintra_...` | ok, 15 frames, 13/13 counters fire | +| `a_10bit_film_frames_with_small_side_globalmv_and_rect_warp_...` | ok, 33 frames, 3/3 counters fire | +| `a_10bit_film_frames_with_frame_edge_mv_clamping_...` | ok, 52 frames, mv_clamp_edge_overhang=5 | +| `a_10bit_film_frames_with_rect64_corner_tus_...` | ok, 33 frames, 64x32=148 32x64=123 | +| `a_10bit_film_hidden_arf_with_split_superblock_strips_...` | ok, 37 frames, rect64_split_txfm_publish=4 | +| `a_10bit_film_inter_frame_with_intra_1to4_strips_...` | ok, 127 strips, shown frame exact | +| `a_real_aomenc_10bit_film_grain_stream_...` | ok, grain_hits=1 | +| `the_two_10bit_film_pins_match_aomdec_on_every_decode_order_frame` (new) | ok, 16 + 34 decode-order frames | +| `every_ffmpeg_comparator_reds_on_a_one_sample_wrong_ffmpeg` (new) | ok, 7/7 arms red | +| `every_oracle_comparator_reds_on_a_one_byte_wrong_oracle` | ok, 5/5 comparators red | +| `a_real_libaom_monochrome_key_frame_...` (the gray arm's pin) | ok | + +`cargo check -p ec-av1 --all-targets`: 0 errors, 0 warnings. + +No 10-bit cell regressed. Nothing outside `crates/ec-av1/src/stream.rs` is +touched, so no other crate's gates are affected. + +## 4. not_done + +- **The 4:2:0 8-bit reference helper cannot be driven on an ODD-dimension + stream.** `ffmpeg_decode_sequence` derives its frame size as `w*h + 2*(w*h/4)`, + which is wrong for odd dimensions: 4:2:0 chroma on 65x65 is + `ceil(65/2)^2 = 1089`, not `4225/4 = 1056`. Measured: it fails LOUDLY + (`FRAME COUNT MISMATCH (4:2:0 65x65) … 6403 bytes, 66 byte(s) not a whole + frame, at 6337 B/frame`), which is the designed behaviour of + `frame_count_diagnosis` — not a silent wrong answer — so nothing is + mis-gated. Left alone: out of charter, and the loud failure is the correct + behaviour. Unblocked by a lane that teaches the helper + `((w+1)/2)*((h+1)/2)`. My control uses 320x240 for this reason and says so. +- **No full suite run.** Per the batch rule, project-wide validation is Main's + job. My sweep is the 11 cells above. +- **The 10-bit `aomdec` per-plane WRONG-SAMPLE COUNTS are 0 by whole-buffer + byte equality**, not by a counting comparator: `decode_all_frames_vs_oracle` + panics at the first differing byte. A per-plane count on a 10-bit cell would + need a 10-bit arm of `count_rawvideo_diffs`; the zero here is "0 differing + bytes across all 50 frames on all three planes", which is stronger than a + count but is not a count.