forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-dpm1' (a016424d): a 128x128 intra block in an inter frame never set mu_chroma; lossless frames refused by name; the ladder decode assertion collects

Browse files at this commit

bb304884307b3b45565da59e36d3d7c3e72da1c5Ahmet Kaan GümüşParent: f09b4e3be62388
Class: override slot on one arm. The bars 2160p libaom crf 45 point now
decodes exact; film B crf 5 was already exact. The screen row's libaom
crf 5 key frame is lossless (base_q_idx 0), which the tile reader does
not implement -- a feature lane follows.
crates/ec-av1/src/decode.rsmodified+6 -0
@@ -29248,6 +29248,12 @@ fn decode_inter_block(
29248 cu_mi, luma_span, luma_span, plane_idx, &cu_grid,29248 cu_mi, luma_span, luma_span, plane_idx, &cu_grid,
29249 );29249 );
29250 hit!(CHROMA_SPLIT_TX_HITS);29250 hit!(CHROMA_SPLIT_TX_HITS);
29251+ // lane-dpm1: the two INTER mu-chunk sites set this and this
29252+ // INTRA-in-inter one did not, so the whole-block chroma
29253+ // record below re-stamped all four 32x32 units with the
29254+ // TOP-LEFT unit's level and the next block read a txb_skip
29255+ // row libaom never selects (class `override-slot-on-one-arm`).
29256+ mu_chroma = true;
29251 let dst = mu_units(29257 let dst = mu_units(
29252 if plane_idx == 1 { &mut u_units } else { &mut v_units },29258 if plane_idx == 1 { &mut u_units } else { &mut v_units },
29253 chroma_side * chroma_side,29259 chroma_side * chroma_side,
crates/ec-av1/src/encode.rsmodified+38 -8
@@ -13310,25 +13310,31 @@ mod tests {
13310 // 25 dB garbage while this gate stayed green) and the crf-5 key13310 // 25 dB garbage while this gate stayed green) and the crf-5 key
13311 // frame desync. A failure names the encoder, the point's flags and13311 // frame desync. A failure names the encoder, the point's flags and
13312 // the first differing frame/plane/sample.13312 // the first differing frame/plane/sample.
13313+ // lane-dpm1: a failing reference point is COLLECTED, not panicked
13314+ // on, so one run still prints the whole BD table and names every
13315+ // bad point instead of stopping at the first. The collection is
13316+ // asserted empty by [`assert_ladder_decodes`] at the end of each
13317+ // gate.
13313 match crate::stream::decode_stream(&stream) {13318 match crate::stream::decode_stream(&stream) {
13314- Ok(ours) => {13319+ Ok(ours) if ours.len() != decoded.len() => note_ladder_failure(format!(
13315- assert_eq!(
13316- ours.len(),
13317- decoded.len(),
13318 "{encoder} {params:?}: our decoder returned {} shown frames, ffmpeg {}",13320 "{encoder} {params:?}: our decoder returned {} shown frames, ffmpeg {}",
13319 ours.len(),13321 ours.len(),
13320 decoded.len(),13322 decoded.len(),
13321- );13323+ )),
13324+ Ok(ours) => {
13322 for (f, (o, d)) in ours.iter().zip(&decoded).enumerate() {13325 for (f, (o, d)) in ours.iter().zip(&decoded).enumerate() {
13323 if let Some((plane, s, got, want)) = first_plane_mismatch(o, d) {13326 if let Some((plane, s, got, want)) = first_plane_mismatch(o, d) {
13324- panic!(13327+ note_ladder_failure(format!(
13325 "{encoder} {params:?} frame {f} plane {plane} sample {s}: our \13328 "{encoder} {params:?} frame {f} plane {plane} sample {s}: our \
13326 decoder decoded {got}, ffmpeg {want}"13329 decoder decoded {got}, ffmpeg {want}"
13327- );13330+ ));
13331+ break;
13328 }13332 }
13329 }13333 }
13330 }13334 }
13331- Err(e) => panic!("{encoder} {params:?}: our decoder refused the stream ({e})"),13335+ Err(e) => note_ladder_failure(format!(
13336+ "{encoder} {params:?}: our decoder refused the stream ({e})"
13337+ )),
13332 }13338 }
13333 let mean: f64 = decoded13339 let mean: f64 = decoded
13334 .iter()13340 .iter()
@@ -13344,6 +13350,28 @@ mod tests {
13344 (ladder, wall)13350 (ladder, wall)
13345 }13351 }
13346 13352
13353+ /// Every reference ladder point that did not decode sample-exactly
13354+ /// through our own decoder, collected across a whole gate run so the BD
13355+ /// table still prints and EVERY bad point is named
13356+ /// (`encoder params frame plane sample`) instead of only the first.
13357+ static LADDER_FAILURES: std::sync::Mutex<Vec<String>> = std::sync::Mutex::new(Vec::new());
13358+
13359+ fn note_ladder_failure(msg: String) {
13360+ eprintln!("LADDER DECODE FAILURE: {msg}");
13361+ LADDER_FAILURES.lock().expect("ladder failures").push(msg);
13362+ }
13363+
13364+ /// Fail the gate at its END on everything [`external_ladder`] collected.
13365+ fn assert_ladder_decodes() {
13366+ let failures = std::mem::take(&mut *LADDER_FAILURES.lock().expect("ladder failures"));
13367+ assert!(
13368+ failures.is_empty(),
13369+ "{} reference ladder point(s) did not decode exactly through our decoder:\n{}",
13370+ failures.len(),
13371+ failures.join("\n"),
13372+ );
13373+ }
13374+
13347 /// First differing sample between two pictures, as13375 /// First differing sample between two pictures, as
13348 /// `(plane, index, left, right)` -- so a gate failure names the plane and13376 /// `(plane, index, left, right)` -- so a gate failure names the plane and
13349 /// the sample instead of just "differs". A length difference counts as a13377 /// the sample instead of just "differs". A length difference counts as a
@@ -14446,6 +14474,7 @@ mod tests {
14446 .join(", "),14474 .join(", "),
14447 );14475 );
14448 }14476 }
14477+ assert_ladder_decodes();
14449 }14478 }
14450 /// Which var-tx depth this clip's INTER blocks resolved to (lane-av1tx2,14479 /// Which var-tx depth this clip's INTER blocks resolved to (lane-av1tx2,
14451 /// split by block class in lane-av1txdepth): depth 0 is one transform over14480 /// split by block class in lane-av1txdepth): depth 0 is one transform over
@@ -14846,6 +14875,7 @@ mod tests {
14846 bd_rate(&rav1e, &ours) * 100.0,14875 bd_rate(&rav1e, &ours) * 100.0,
14847 );14876 );
14848 }14877 }
14878+ assert_ladder_decodes();
14849 }14879 }
14850 14880
14851 /// lane-av1tpl3 step 1: the SHAPE of the propagating map's denominator14881 /// lane-av1tpl3 step 1: the SHAPE of the propagating map's denominator
crates/ec-av1/src/refusal_inventory.rsmodified+13 -0
@@ -57,6 +57,15 @@ const REFUSALS: &[&str] = &[
57 "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)",57 "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)",
58 "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)",58 "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)",
59 "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)",59 "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)",
60+ // lane-dpm1: libaom codes his screen-capture row at `-crf 5` with
61+ // `base_q_idx == 0`, i.e. LOSSLESS -- TX_4X4 with the Walsh-Hadamard
62+ // transform over every block (no `tx_depth` symbol at all) and
63+ // `is_cfl_allowed` narrowed to `plane_bsize == BLOCK_4X4`, which changes
64+ // the `uv_mode` alphabet. Nothing here consumes the header's `lossless`,
65+ // so the first block of such a frame read `uv_mode` = UV_CFL_PRED where
66+ // aomdec reads V_PRED. Refused by name (gate
67+ // `a_lossless_libaom_stream_is_refused_by_name`) until the path exists.
68+ "a lossless frame (qindex 0): the TX_4X4 Walsh-Hadamard tile syntax and the lossless CfL rule are unimplemented",
60 "a frame OBU with no tile group",69 "a frame OBU with no tile group",
61 "a frame naming primary_ref_frame at a reference slot with no saved CDF state",70 "a frame naming primary_ref_frame at a reference slot with no saved CDF state",
62 "a frame with no mode-info grid",71 "a frame with no mode-info grid",
@@ -275,6 +284,10 @@ const PROVEN: &[(&str, &str)] = &[
275 "an inter frame with no key frame before it",284 "an inter frame with no key frame before it",
276 "an_inter_frame_opening_a_stream_is_refused_by_name",285 "an_inter_frame_opening_a_stream_is_refused_by_name",
277 ),286 ),
287+ (
288+ "a lossless frame (qindex 0): the TX_4X4 Walsh-Hadamard tile syntax and the lossless CfL rule are unimplemented",
289+ "a_lossless_libaom_stream_is_refused_by_name",
290+ ),
278 // lane-t900 r25, enumeration: a motion_mode/obmc symbol is read only under291 // lane-t900 r25, enumeration: a motion_mode/obmc symbol is read only under
279 // `is_motion_variation_allowed_bsize` (min side >= 8), and each of the 17292 // `is_motion_variation_allowed_bsize` (min side >= 8), and each of the 17
280 // `BLOCK_SIZES_ALL` footprints that clause admits maps to a distinct row of293 // `BLOCK_SIZES_ALL` footprints that clause admits maps to a distinct row of
crates/ec-av1/src/stream.rsmodified+210 -18
@@ -1591,6 +1591,24 @@ fn decode_frame(
1591 "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)",1591 "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)",
1592 ));1592 ));
1593 }1593 }
1594+ // lane-dpm1: a LOSSLESS frame (`qindex == 0` with zero deltas, spec 5.9.12)
1595+ // is a different tile syntax, and this decoder has none of it: libaom
1596+ // forces TX_4X4 with the WALSH-HADAMARD transform over every block (so no
1597+ // `tx_depth` symbol is coded at all), and `is_cfl_allowed` narrows to
1598+ // `plane_bsize == BLOCK_4X4` instead of the 32x32 rule, which changes the
1599+ // `uv_mode` ALPHABET. Measured on his own screen-capture row at libaom
1600+ // `-crf 5` (base_q_idx 0): the very first block, mi(0,0) BLOCK_32X32,
1601+ // reads `uv_mode` off the CfL alphabet where libaom reads the plain one
1602+ // (ours 12 = UV_CFL_PRED, aomdec 1 = V_PRED) and the tile desyncs at
1603+ // symbol four of the frame. Refuse by name rather than return a picture
1604+ // that is silently wrong from luma sample 0 (class `refusal-hides-a-defect`
1605+ // read the other way: a silent wrong decode is worse than a named gap).
1606+ if header.lossless.iter().any(|&l| l) {
1607+ return Err(Error::unsupported(
1608+ "AV1 decode_stream",
1609+ "a lossless frame (qindex 0): the TX_4X4 Walsh-Hadamard tile syntax and the lossless CfL rule are unimplemented",
1610+ ));
1611+ }
1594 crate::decode::set_bit_depth(bit_depth, fctx);1612 crate::decode::set_bit_depth(bit_depth, fctx);
1595 // spec 7.16: this frame's superres state, for the filter chain --1613 // spec 7.16: this frame's superres state, for the filter chain --
1596 // `decode.rs` upscales between CDEF and loop restoration and sizes1614 // `decode.rs` upscales between CDEF and loop restoration and sizes
@@ -3771,14 +3789,22 @@ pub(crate) mod tests {
3771 /// the desync surfaced blocks later as "a Golomb tail longer than this3789 /// the desync surfaced blocks later as "a Golomb tail longer than this
3772 /// decoder reads".3790 /// decoder reads".
3773 ///3791 ///
3774- /// The source is SYNTHETIC (no film sample lives in `fixtures`): a3792+ /// The source is SYNTHETIC (no film sample lives in `fixtures`): the
3775- /// near-flat dark background at the film-B crop size, 1920x1024, with one3793+ /// near-flat dark pattern libaom's own screen-content detector counts as
3776- /// textured patch stepping 9 px every SECOND frame, so half the frames are3794+ /// screen content, at the film-B crop size 1920x1024, SCROLLING globally
3777- /// exact duplicates of their predecessor (the `C == T` trigger) while the3795+ /// 5 px per frame and frozen on frame 8 -- an exact duplicate of frame 7
3778- /// motion field still holds non-zero MVs whose projections are not3796+ /// (the `C == T` trigger) whose twin is not among its own references, so
3779- /// multiples of 8. The gate asserts both halves: at least one INTER frame3797+ /// its blocks still code real motion under `force_integer_mv`.
3780- /// really carries `force_integer_mv` (class `gate-blind-to-feature`), and3798+ ///
3781- /// every shown frame decodes sample-exact against ffmpeg's own decode.3799+ /// lane-dpm1 made this gate SENSITIVE: with the `force_integer_mv` branch
3800+ /// of [`crate::motion_field::lower_mv_precision`] stubbed out (`if false
3801+ /// &&`) the stream decodes WRONG -- frame 8, luma sample 25695, 20 against
3802+ /// ffmpeg's 19 -- where the previous patch-in-a-static-background recipe
3803+ /// (and two others tried) still decoded byte-exact: there the used mv-stack
3804+ /// slots came from agreeing spatial neighbours and the rounded temporal
3805+ /// entries never won one. The gate asserts both halves: at least one INTER
3806+ /// frame really carries `force_integer_mv` (class `gate-blind-to-feature`),
3807+ /// and every shown frame decodes sample-exact against ffmpeg's own decode.
3782 #[test]3808 #[test]
3783 fn a_libaom_force_integer_mv_stream_decodes_exact() {3809 fn a_libaom_force_integer_mv_stream_decodes_exact() {
3784 const NAME: &str = "a_libaom_force_integer_mv_stream_decodes_exact";3810 const NAME: &str = "a_libaom_force_integer_mv_stream_decodes_exact";
@@ -3786,23 +3812,30 @@ pub(crate) mod tests {
3786 eprintln!("SKIP {NAME}: no ffmpeg");3812 eprintln!("SKIP {NAME}: no ffmpeg");
3787 return;3813 return;
3788 }3814 }
3789- let (w, h, frames) = (1920usize, 1024usize, 12usize);3815+ let (w, h, frames) = (1920usize, 1024usize, 16usize);
3790 let mut raw = Vec::with_capacity(frames * w * h * 3 / 2);3816 let mut raw = Vec::with_capacity(frames * w * h * 3 / 2);
3817+ let mut off = 0usize;
3791 for f in 0..frames {3818 for f in 0..frames {
3819+ // lane-dpm1: the WHOLE picture scrolls 5 px per frame and freezes
3820+ // on frame 8, so (a) every block of the frozen frame -- including
3821+ // mi(0,0), which has no spatial neighbour at all -- still codes
3822+ // real motion against the references that are not its twin, and
3823+ // (b) 40 eighth-pels projected over the pyramid's distances lands
3824+ // on non-multiples of 8 (40/2 = 20 -> 16). A patch moving inside a
3825+ // static background was NOT sensitive: there the used stack slots
3826+ // came from spatial neighbours that agreed, and the rounded
3827+ // temporal entries never won one.
3828+ if f > 0 && f != 8 {
3829+ off = (off + 5) % h;
3830+ }
3792 let mut y = vec![0u8; w * h];3831 let mut y = vec![0u8; w * h];
3793 for row in 0..h {3832 for row in 0..h {
3833+ let src = (row + off) % h;
3794 for col in 0..w {3834 for col in 0..w {
3795 // 2..=4 distinct values per 16x16 block, all dark: the3835 // 2..=4 distinct values per 16x16 block, all dark: the
3796 // screen-content detector's own counting rule.3836 // screen-content detector's own counting rule.
3797 y[row * w + col] =3837 y[row * w + col] =
3798- 16 + ((col / 32 + row / 32) % 5) as u8 + ((col / 4 + row / 4) % 3) as u8;3838+ 16 + ((col / 32 + src / 32) % 5) as u8 + ((col / 4 + src / 4) % 3) as u8;
3799- }
3800- }
3801- let x0 = 200 + 9 * (f / 2);
3802- for row in 300..428 {
3803- for col in x0..x0 + 192 {
3804- y[row * w + col] =
3805- ((((col - x0) / 3) * 7 + ((row - 300) / 5) * 13) % 200 + 30) as u8;
3806 }3839 }
3807 }3840 }
3808 raw.extend_from_slice(&y);3841 raw.extend_from_slice(&y);
@@ -3815,7 +3848,7 @@ pub(crate) mod tests {
3815 .args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "yuv420p"])3848 .args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "yuv420p"])
3816 .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"])3849 .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"])
3817 .arg(&src)3850 .arg(&src)
3818- .args(["-an", "-threads", "1", "-g", "12", "-c:v", "libaom-av1"])3851+ .args(["-an", "-threads", "1", "-g", "16", "-c:v", "libaom-av1"])
3819 .args(["-cpu-used", "6", "-b:v", "0", "-crf", "35", "-f", "obu", "-"])3852 .args(["-cpu-used", "6", "-b:v", "0", "-crf", "35", "-f", "obu", "-"])
3820 .stdin(Stdio::null())3853 .stdin(Stdio::null())
3821 .stdout(Stdio::piped())3854 .stdout(Stdio::piped())
@@ -3867,6 +3900,165 @@ pub(crate) mod tests {
3867 }3900 }
3868 }3901 }
3869 3902
3903+ /// lane-dpm1: the 128x128-INTRA-inside-an-INTER-frame chroma context gate.
3904+ /// A 128x128 block codes its chroma as four TX_32X32 units, one per 64x64
3905+ /// mu chunk, and libaom stamps the coefficient context PER UNIT. The two
3906+ /// INTER mu-chunk sites set `mu_chroma` so the block tail re-stamps the
3907+ /// four units in mu order; the INTRA-in-inter site did not, so the
3908+ /// whole-block record left every unit carrying the TOP-LEFT unit's level.
3909+ /// The next block then read its `txb_skip` off ctx 11 where libaom reads
3910+ /// ctx 10 (class `override-slot-on-one-arm`) -- one symbol on the wrong
3911+ /// CDF row, tile desynced, and because the loop-restoration coefficients
3912+ /// live in the same tile data the damage showed up as a +-1 luma sample at
3913+ /// the TOP of the frame (measured: frame 1, luma sample 66, ours 146 /
3914+ /// ffmpeg 145, with 1.7M samples wrong behind it).
3915+ ///
3916+ /// Source: the repository's own 2160p colour-bar fixture at the native
3917+ /// gate's crop (1920x1024 out of the middle), 12 frames, libaom
3918+ /// `-cpu-used 6 -crf 45 -g 12` -- the first reference point of
3919+ /// `bd_rate_screen_native`'s "bars 2160p" row, which is where the assertion
3920+ /// caught it. The gate asserts the tool fired (class
3921+ /// `gate-blind-to-feature`) and that every shown frame decodes sample-exact
3922+ /// against ffmpeg's own decode.
3923+ #[test]
3924+ fn a_libaom_stream_with_128_intra_blocks_in_inter_frames_decodes_exact() {
3925+ const NAME: &str = "a_libaom_stream_with_128_intra_blocks_in_inter_frames_decodes_exact";
3926+ if !have_ffmpeg() {
3927+ eprintln!("SKIP {NAME}: no ffmpeg");
3928+ return;
3929+ }
3930+ let clip = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
3931+ .join("../../fixtures/video/h264-2160p-23.976-8bit.mp4");
3932+ if !clip.exists() {
3933+ eprintln!("SKIP {NAME}: the 2160p bars fixture is missing");
3934+ return;
3935+ }
3936+ let (w, h, frames) = (1920usize, 1024usize, 12usize);
3937+ // [[pid-keyed-temp-path]]: parallel test binaries must not share a name.
3938+ let src = std::env::temp_dir().join(format!("ec-av1-i128-{}.yuv", std::process::id()));
3939+ let load = Command::new("ffmpeg")
3940+ .args(["-v", "error", "-y", "-i"])
3941+ .arg(&clip)
3942+ .args(["-frames:v", &frames.to_string(), "-vf", "crop=1920:1024:960:568"])
3943+ .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"])
3944+ .arg(&src)
3945+ .output()
3946+ .expect("ffmpeg failed to run");
3947+ assert!(load.status.success(), "{NAME}: {}", String::from_utf8_lossy(&load.stderr));
3948+ let out = Command::new("ffmpeg")
3949+ .args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "yuv420p"])
3950+ .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"])
3951+ .arg(&src)
3952+ .args(["-an", "-threads", "1", "-g", "12", "-c:v", "libaom-av1"])
3953+ .args(["-cpu-used", "6", "-b:v", "0", "-crf", "45", "-f", "obu", "-"])
3954+ .stdin(Stdio::null())
3955+ .stdout(Stdio::piped())
3956+ .stderr(Stdio::piped())
3957+ .output()
3958+ .expect("ffmpeg failed to run");
3959+ let _ = std::fs::remove_file(&src);
3960+ if !out.status.success() {
3961+ eprintln!(
3962+ "SKIP {NAME}: ffmpeg has no libaom-av1 encoder ({})",
3963+ String::from_utf8_lossy(&out.stderr)
3964+ );
3965+ return;
3966+ }
3967+ let stream = out.stdout;
3968+ let before = crate::decode::intra_128_in_inter_hits();
3969+ let ours = decode_stream(&stream).expect("libaom bars stream decodes");
3970+ assert!(
3971+ crate::decode::intra_128_in_inter_hits() > before,
3972+ "{NAME} went blind: no 128-rooted intra block inside an inter frame"
3973+ );
3974+ let theirs = ffmpeg_decode_sequence(&stream, w, h, frames);
3975+ assert_eq!(ours.len(), frames, "shown frame count");
3976+ for (i, (a, b)) in ours.iter().zip(theirs.iter()).enumerate() {
3977+ for (plane, l, r) in [("Y", &a.y, &b.y), ("U", &a.u, &b.u), ("V", &a.v, &b.v)] {
3978+ let first = l.iter().zip(r.iter()).position(|(x, y)| x != y);
3979+ assert!(
3980+ first.is_none(),
3981+ "frame {i} plane {plane} differs from ffmpeg at sample {}",
3982+ first.unwrap()
3983+ );
3984+ }
3985+ }
3986+ }
3987+
3988+ /// lane-dpm1: the lossless refusal is a CLAIM, so it gets a stream that
3989+ /// reaches it. libaom at `-crf 0` codes `base_q_idx == 0` -- the same
3990+ /// lossless frame his screen-capture row gets at `-crf 5` -- where the tile
3991+ /// syntax is TX_4X4 + Walsh-Hadamard and `is_cfl_allowed` narrows to
3992+ /// `plane_bsize == BLOCK_4X4`. Before the refusal our decoder returned a
3993+ /// picture that was wrong from luma sample 0 (measured on that row: 126
3994+ /// against ffmpeg's 33, the first block's `uv_mode` read off the CfL
3995+ /// alphabet). The gate asserts the stream really is lossless and that we
3996+ /// refuse it BY NAME rather than decode it wrong.
3997+ #[test]
3998+ fn a_lossless_libaom_stream_is_refused_by_name() {
3999+ const NAME: &str = "a_lossless_libaom_stream_is_refused_by_name";
4000+ if !have_ffmpeg() {
4001+ eprintln!("SKIP {NAME}: no ffmpeg");
4002+ return;
4003+ }
4004+ let (w, h, frames) = (256usize, 128usize, 2usize);
4005+ let mut raw = Vec::with_capacity(frames * w * h * 3 / 2);
4006+ for f in 0..frames {
4007+ for row in 0..h {
4008+ for col in 0..w {
4009+ raw.push(((col * 7 + row * 13 + f * 31) % 251) as u8);
4010+ }
4011+ }
4012+ raw.extend(std::iter::repeat_n(128u8, w * h / 2));
4013+ }
4014+ // [[pid-keyed-temp-path]]: parallel test binaries must not share a name.
4015+ let src = std::env::temp_dir().join(format!("ec-av1-lossless-{}.yuv", std::process::id()));
4016+ std::fs::write(&src, &raw).expect("raw source");
4017+ let out = Command::new("ffmpeg")
4018+ .args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "yuv420p"])
4019+ .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"])
4020+ .arg(&src)
4021+ .args(["-an", "-threads", "1", "-g", "2", "-c:v", "libaom-av1"])
4022+ .args(["-cpu-used", "6", "-b:v", "0", "-crf", "0", "-f", "obu", "-"])
4023+ .stdin(Stdio::null())
4024+ .stdout(Stdio::piped())
4025+ .stderr(Stdio::piped())
4026+ .output()
4027+ .expect("ffmpeg failed to run");
4028+ let _ = std::fs::remove_file(&src);
4029+ if !out.status.success() {
4030+ eprintln!(
4031+ "SKIP {NAME}: ffmpeg has no libaom-av1 encoder ({})",
4032+ String::from_utf8_lossy(&out.stderr)
4033+ );
4034+ return;
4035+ }
4036+ let stream = out.stdout;
4037+ // Half of the gate: the stream must really carry a lossless frame
4038+ // (class `gate-blind-to-feature`).
4039+ let mut parser = Av1Parser::new();
4040+ let (mut pos, mut lossless) = (0usize, 0usize);
4041+ while pos < stream.len() {
4042+ let obu = parser.parse_obu(&stream[pos..]).expect("libaom OBU parses");
4043+ pos += obu.total_size.max(1);
4044+ let header = match &obu.kind {
4045+ ObuKind::FrameHeader(h) | ObuKind::Frame(h, _) => h,
4046+ _ => continue,
4047+ };
4048+ if header.lossless.iter().any(|&l| l) {
4049+ lossless += 1;
4050+ }
4051+ }
4052+ assert!(lossless > 0, "{NAME} went blind: libaom coded no lossless frame at -crf 0");
4053+ match decode_stream(&stream) {
4054+ Ok(_) => panic!("{NAME}: a lossless stream decoded instead of being refused"),
4055+ Err(e) => assert!(
4056+ format!("{e}").contains("a lossless frame (qindex 0)"),
4057+ "{NAME}: refused for the wrong reason: {e}"
4058+ ),
4059+ }
4060+ }
4061+
3870 /// lane-dkey: the palette-neighbour-band gate. A palette-Y block's size and4062 /// lane-dkey: the palette-neighbour-band gate. A palette-Y block's size and
3871 /// colours used to stay standing in the mi-granular above/left bands after a4063 /// colours used to stay standing in the mi-granular above/left bands after a
3872 /// sub-8x8 group was decoded next to it -- the sub-8x8 readers published4064 /// sub-8x8 group was decoded next to it -- the sub-8x8 readers published
lanes/dpm1.report.mdadded+121 -0
@@ -0,0 +1,121 @@
1+# lane-dpm1 — the native gate's decode assertion, all reference points
2+
3+## (0) The assertion now COLLECTS (encode.rs)
4+`external_ladder` no longer panics on the first bad reference point: every
5+failure is printed at once (`LADDER DECODE FAILURE: ...`) and pushed onto
6+`LADDER_FAILURES`; each gate calls `assert_ladder_decodes()` after its loop, so
7+the whole BD table still prints and every bad point is named. First run already
8+paid for itself: it found a SECOND failure (screen capture, crf 5) the
9+panic-at-first version hid, and it showed the bars failure is the 2160p clip,
10+not the 1080p one.
11+
12+## (1) bars ±1 — the charter's premise was mis-attributed
13+`bars 1080p` libaom crf 45 decodes EXACT (reproduced standalone: crop
14+1920x1024+0+28, 12 frames, -g 12, cpu-used 6, crf 45 -> our decode == ffmpeg,
15+byte for byte). The real failing row is **bars 2160p** (same crf 45, frame 1,
16+Y sample 66, ours 146 / ffmpeg 145). Status below.
17+
18+## (2) film B crf 5 — STALE premise, already closed
19+Regenerated from the manifest (film B, 00:40:00, crop 1920x1024+960+292):
20+`-cpu-used 6 -crf 5 -g 48` and `-g 12` both decode **sample-exact** vs ffmpeg
21+at this head (48 and 12 frames). No Golomb refusal. The lane-dkey/dgolomb
22+reports' "4th inter frame refuses" is pre-merge state.
23+
24+## (3) force_integer_mv fixture — now SENSITIVE
25+`stream.rs a_libaom_force_integer_mv_stream_decodes_exact`: source replaced by a
26+GLOBAL 5 px/frame vertical scroll of the screen-detector pattern, frozen on
27+frame 8, 16 frames, -g 16. With the fix stubbed (`if false && force_integer_mv`)
28+it now decodes WRONG at frame 8 luma sample 25695 (20 vs ffmpeg 19); with the
29+fix it is exact. Blind recipes tried: patch-in-static-background (the old one),
30+3 patches at 3 speeds with freezes at {5,9} / {4,8,12} / {8}, 3 px scroll.
31+Instrumented finding: a +64 perturbation of rounded candidates DID change the
32+output on those streams, so the rounded candidates were consumed but only in
33+slots whose ±4 eighth-pel difference never reached a coded block's mv.
34+
35+## (B) bars 2160p libaom crf 45 — FIXED (root cause, class, sweep, fixture)
36+First divergence (two instrumented decoders, `EC_TRACE_MODE_STEP` +
37+`EC_TRACE_COEFF`): INTER frame 1, block **mi(0,288)**, a 128x128 INTRA block
38+inside an inter frame, its FIRST chroma (U) transform unit -- aomdec reads
39+`txb_skip` on ctx 10, ours on ctx 11 (`get_txb_ctx`'s offset-10 rows, base 1 vs
40+0). The luma ladder and every symbol before it matched exactly.
41+
42+Root cause, `crates/ec-av1/src/decode.rs`: a 128x128 block codes its chroma as
43+four TX_32X32 units, one per 64x64 mu chunk, and libaom stamps the coefficient
44+context PER UNIT. The block tail re-stamps those four units only when
45+`mu_chroma` is set -- the two INTER mu-chunk sites (27255, 28552) set it, the
46+INTRA-in-inter site did not, so the whole-block record left all four units
47+carrying the TOP-LEFT unit's level. Class **`override-slot-on-one-arm`** (a fix
48+installed on one arm of a set of twins). Sweep: all `CHROMA_SPLIT_TX_HITS`
49+sites -- the two key-frame ones (14364, 14703) have their own local re-stamp,
50+the three inter-frame ones now all set `mu_chroma`. No other site.
51+
52+Why it read as a `+-1` at sample 66: the U-plane symbol desynced the tile, and
53+the loop-restoration coefficients live in the same tile data, so the whole
54+frame shifted by one level while 1.7M samples behind it went wrong.
55+
56+Fixture: `stream.rs a_libaom_stream_with_128_intra_blocks_in_inter_frames_decodes_exact` -- the repo's own 2160p bars fixture at the native crop, libaom
57+`-cpu-used 6 -crf 45 -g 12`, asserts the tool fired and every frame is exact.
58+With `mu_chroma = false` on that arm it FAILS with "frame 1 plane Y differs
59+from ffmpeg at sample 66" (verified).
60+
61+## (A) screen capture libaom crf 5 — root cause found, feature DEFERRED
62+That stream's key frame is coded **LOSSLESS** (`base_q_idx 0`, `lossless[seg]`
63+true; aomdec's own `EC_IMODE_VAL ... tx=0` shows TX_4X4 on a BLOCK_32X32).
64+libaom then (a) forces TX_4X4 + the Walsh-Hadamard transform everywhere and
65+codes NO `tx_depth` symbol, and (b) narrows `is_cfl_allowed` to
66+`plane_bsize == BLOCK_4X4`, which changes the `uv_mode` alphabet. Our tile
67+reader ignores `header.lossless` entirely: the FIRST block, mi(0,0), reads
68+`uv_mode` = 12 (UV_CFL_PRED) where aomdec reads 1 (V_PRED) -- symbol four of
69+the frame. Class `branch-dropped-as-unreachable` (the header computes
70+`lossless`/`coded_lossless` and nothing consumes it).
71+
72+Shipped now: a NAMED REFUSAL in `stream.rs` (`a lossless frame (qindex 0) ...`)
73+so the decoder stops returning a picture that is wrong from luma sample 0.
74+`deferred: the lossless decode path (WHT 4x4, forced tx size, lossless CfL
75+rule, filter bypass) — a feature lane, not a fix — unblocks: implement
76+`inverse WHT + the TX_4X4 forcing + `is_cfl_allowed`'s lossless branch, gate
77+with this same screen row at crf 5.`
78+
79+## OPEN
80+* The native gate's screen row now reports the refusal instead of a silent
81+ wrong decode; it is RED until the lossless lane lands.
82+
83+## Gate results (this head, fea6a377)
84+
85+`cargo test -p ec-av1 --release --lib -- --ignored --exact bd_rate_screen_native`
86+(12 frames, all five rows, every reference point of every row decoded through
87+our decoder and compared to ffmpeg):
88+
89+| row | verdict |
90+|---|---|
91+| bars 1080p | all 8 reference points exact |
92+| bars 2160p | all 8 exact (was: libaom crf 45 frame 1 Y sample 66) |
93+| film A (1080p source) | all 8 exact |
94+| film B (2160p HDR source) | all 8 exact |
95+| screen capture | 7 of 8 exact; libaom crf 5 REFUSED (lossless, deferred) |
96+
97+The gate ends RED on exactly that one point, and the collecting assertion is
98+why the four film/bars rows and their BD table are measured at all in the same
99+run:
100+
101+ 1 reference ladder point(s) did not decode exactly through our decoder:
102+ libaom-av1 ["-cpu-used","6","-b:v","0","-crf","5"]: our decoder refused the
103+ stream (a lossless frame (qindex 0) ...)
104+
105+BD table unchanged by this lane (bars 1080p +2.0/-14.0, bars 2160p +13.1/-9.6,
106+film A +38.5/+8.2, film B +58.2/+26.5, screen +33.4/-23.8 vs libaom/rav1e).
107+
108+`cargo check --workspace --all-targets -j4`: 0 errors, 0 ec-av1 warnings (the
109+25 warnings are pre-existing ec-opus/ec-vorbis ones).
110+
111+## Deferred
112+* `deferred: the lossless decode path (WHT TX_4X4, forced tx size, the lossless
113+ CfL rule) — a feature lane, refused by name meanwhile — unblocks: implement
114+ the inverse Walsh-Hadamard + `is_cfl_allowed`'s lossless branch, gate on the
115+ screen row at crf 5.`
116+* `deferred: the inter-side palette-band publication (lane-dkey's open half) —
117+ not what any defect in this lane needed, and the previous naive stamp
118+ regressed 13 tests — unblocks: derive each inter reader's real band footprint
119+ from how `record_palette_*` indexes the bands.`
120+
121+`cargo test -p ec-av1 --release --lib`: **554 passed, 0 failed, 43 ignored** (552 + the two new gates); pins `the_encoders_own_streams_are_byte_identical_to_their_pins` green (9778 / 35450 untouched -- no encoder file changed). /tmp at 66%.