From c0c60c59abd6ecd9b8ed703bb1a643c57fdff1c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 7 Sep 2026 13:43:07 +0300 Subject: [PATCH] test(av1): the lossless refusal gets its own libaom -crf 0 gate and its inventory entry --- crates/ec-av1/src/refusal_inventory.rs | 13 +++++ crates/ec-av1/src/stream.rs | 74 ++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index cd1eec6b..3836a99e 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -57,6 +57,15 @@ const REFUSALS: &[&str] = &[ "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)", "a sub-8x8 leaf that uses intrabc (this reader has no block-vector path; the 8x8-and-up reader reconstructs one)", "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)", + // lane-dpm1: libaom codes his screen-capture row at `-crf 5` with + // `base_q_idx == 0`, i.e. LOSSLESS -- TX_4X4 with the Walsh-Hadamard + // transform over every block (no `tx_depth` symbol at all) and + // `is_cfl_allowed` narrowed to `plane_bsize == BLOCK_4X4`, which changes + // the `uv_mode` alphabet. Nothing here consumes the header's `lossless`, + // so the first block of such a frame read `uv_mode` = UV_CFL_PRED where + // aomdec reads V_PRED. Refused by name (gate + // `a_lossless_libaom_stream_is_refused_by_name`) until the path exists. + "a lossless frame (qindex 0): the TX_4X4 Walsh-Hadamard tile syntax and the lossless CfL rule are unimplemented", "a frame OBU with no tile group", "a frame naming primary_ref_frame at a reference slot with no saved CDF state", "a frame with no mode-info grid", @@ -275,6 +284,10 @@ const PROVEN: &[(&str, &str)] = &[ "an inter frame with no key frame before it", "an_inter_frame_opening_a_stream_is_refused_by_name", ), + ( + "a lossless frame (qindex 0): the TX_4X4 Walsh-Hadamard tile syntax and the lossless CfL rule are unimplemented", + "a_lossless_libaom_stream_is_refused_by_name", + ), // lane-t900 r25, enumeration: a motion_mode/obmc symbol is read only under // `is_motion_variation_allowed_bsize` (min side >= 8), and each of the 17 // `BLOCK_SIZES_ALL` footprints that clause admits maps to a distinct row of diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 9180ab34..fb982e04 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -3985,6 +3985,80 @@ pub(crate) mod tests { } } + /// lane-dpm1: the lossless refusal is a CLAIM, so it gets a stream that + /// reaches it. libaom at `-crf 0` codes `base_q_idx == 0` -- the same + /// lossless frame his screen-capture row gets at `-crf 5` -- where the tile + /// syntax is TX_4X4 + Walsh-Hadamard and `is_cfl_allowed` narrows to + /// `plane_bsize == BLOCK_4X4`. Before the refusal our decoder returned a + /// picture that was wrong from luma sample 0 (measured on that row: 126 + /// against ffmpeg's 33, the first block's `uv_mode` read off the CfL + /// alphabet). The gate asserts the stream really is lossless and that we + /// refuse it BY NAME rather than decode it wrong. + #[test] + fn a_lossless_libaom_stream_is_refused_by_name() { + const NAME: &str = "a_lossless_libaom_stream_is_refused_by_name"; + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + let (w, h, frames) = (256usize, 128usize, 2usize); + let mut raw = Vec::with_capacity(frames * w * h * 3 / 2); + for f in 0..frames { + for row in 0..h { + for col in 0..w { + raw.push(((col * 7 + row * 13 + f * 31) % 251) as u8); + } + } + raw.extend(std::iter::repeat_n(128u8, w * h / 2)); + } + // [[pid-keyed-temp-path]]: parallel test binaries must not share a name. + let src = std::env::temp_dir().join(format!("ec-av1-lossless-{}.yuv", std::process::id())); + std::fs::write(&src, &raw).expect("raw source"); + let out = Command::new("ffmpeg") + .args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "yuv420p"]) + .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"]) + .arg(&src) + .args(["-an", "-threads", "1", "-g", "2", "-c:v", "libaom-av1"]) + .args(["-cpu-used", "6", "-b:v", "0", "-crf", "0", "-f", "obu", "-"]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + let _ = std::fs::remove_file(&src); + if !out.status.success() { + eprintln!( + "SKIP {NAME}: ffmpeg has no libaom-av1 encoder ({})", + String::from_utf8_lossy(&out.stderr) + ); + return; + } + let stream = out.stdout; + // Half of the gate: the stream must really carry a lossless frame + // (class `gate-blind-to-feature`). + let mut parser = Av1Parser::new(); + let (mut pos, mut lossless) = (0usize, 0usize); + while pos < stream.len() { + let obu = parser.parse_obu(&stream[pos..]).expect("libaom OBU parses"); + pos += obu.total_size.max(1); + let header = match &obu.kind { + ObuKind::FrameHeader(h) | ObuKind::Frame(h, _) => h, + _ => continue, + }; + if header.lossless.iter().any(|&l| l) { + lossless += 1; + } + } + assert!(lossless > 0, "{NAME} went blind: libaom coded no lossless frame at -crf 0"); + match decode_stream(&stream) { + Ok(_) => panic!("{NAME}: a lossless stream decoded instead of being refused"), + Err(e) => assert!( + format!("{e}").contains("a lossless frame (qindex 0)"), + "{NAME}: refused for the wrong reason: {e}" + ), + } + } + /// lane-dkey: the palette-neighbour-band gate. A palette-Y block's size and /// colours used to stay standing in the mi-granular above/left bands after a /// sub-8x8 group was decoded next to it -- the sub-8x8 readers published