diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs new file mode 100644 index 00000000..a7edca41 --- /dev/null +++ b/crates/ec-av1/examples/decode_probe.rs @@ -0,0 +1,38 @@ +//! Where does a real stream stop? Decode one AV1 file and print the answer. +//! +//! The gates in [`ec_av1::stream`] each pin one capability against one encoder +//! recipe. This asks the complementary question -- given a stream someone +//! actually produced, which refusal comes first -- and it is how the refusal +//! distribution in commit 2be815f was measured rather than reasoned about: +//! +//! ```text +//! aomenc --codec=av1 --obu -o s.obu --passes=1 --cpu-used=4 --limit=4 in.y4m +//! cargo run -p ec-av1 --example decode_probe -- s.obu +//! ``` +//! +//! Note `--obu`: [`ec_av1::stream::decode_stream`] takes a raw OBU stream, and +//! an IVF file decodes as zero frames rather than as an error. +//! +//! That run is also what disproved three refusal strings claiming an encoder +//! never writes a case it demonstrably writes, so this is a first-class +//! instrument, not a scratch file. +fn main() { + let Some(path) = std::env::args().nth(1) else { + eprintln!("usage: decode_probe "); + std::process::exit(2); + }; + let data = match std::fs::read(&path) { + Ok(data) => data, + Err(e) => { + eprintln!("{path}: {e}"); + std::process::exit(2); + } + }; + match ec_av1::stream::decode_stream(&data) { + Ok(frames) if frames.is_empty() => { + println!("OK but EMPTY: no frames -- is {path} an IVF rather than a raw OBU stream?"); + } + Ok(frames) => println!("OK: {} frames decoded", frames.len()), + Err(e) => println!("REFUSED: {e}"), + } +} diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 34f2a933..18123925 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -5317,14 +5317,17 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( } _ => { return Err(unsupported(format!( - "a partition type this encoder never writes (value={part32})" + "a 32x32 partition type this decoder does not code (value={part32})" ))); } } } } _ => { - return Err(unsupported("a partition type this encoder never writes")); + return Err(unsupported( + "a superblock-level partition type other than NONE or SPLIT (this \ + decoder's intra tile path codes only those two at 64x64)", + )); } } } @@ -10998,7 +11001,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( } _ => { return Err(unsupported(format!( - "an INTER 32x32 partition type this encoder never writes (value={part32})" + "an INTER 32x32 partition type this decoder does not code (value={part32})" ))); } } diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index c1eca051..230c8bf6 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -29,7 +29,6 @@ const CAPABILITY_CLAIMS: &[&str] = &[ "a nonzero angle delta (this encoder never writes one)", "a partition below 16x16 other than a clean split (this encoder never writes one)", "a partition below 8x8 (this encoder never writes one)", - "a partition type this encoder never writes", "a tx_type symbol on a rectangular transform (never expected at this size)", ]; @@ -38,7 +37,12 @@ const REFUSALS: &[&str] = &[ "GLOBALMV (round 3)", "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", + "a 32x32 partition type this decoder does not code (value={part32})", "a Golomb tail longer than this decoder reads", + "a stream whose bit depth is not 8 (this decoder reconstructs into 8-bit planes)", + "a tx_type symbol outside its CDF's own set: {t}", + "an INTER 32x32 partition type this decoder does not code (value={part32})", + "a superblock-level partition type other than NONE or SPLIT (this decoder's intra tile path codes only those two at 64x64)", "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", "a HORZ/VERT intra strip with a split transform (per-unit rect prediction is not ported)", "a block that actually uses a palette (UV) -- reconstruction is out of scope", @@ -67,9 +71,27 @@ const REFUSALS: &[&str] = &[ "filter intra on a HORZ/VERT strip (this decoder predicts square-only)", ]; +/// Gates whose `Err` arm turns a decode failure into a printed SKIP rather than +/// a test failure. +/// +/// A gate named `..._decodes_pixel_exact` that cannot decode has failed, and +/// swallowing the error keeps the suite green while the gate proves nothing -- +/// the same vacuum as a gate whose feature never fires, arrived at from the +/// other side. These four predate the attempt-loop pattern the newer gates use +/// (encode several fixtures, require at least one to decode, hard-assert the +/// firing count). They are pinned here so the set cannot grow while they are +/// converted one at a time. +#[cfg(test)] +const GATES_THAT_SKIP_ON_A_DECODE_ERROR: &[&str] = &[ + "a_real_aomenc_filter_intra_stream_decodes_pixel_exact", + "a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact", + "a_real_aomenc_intra_stream_with_deblocking_decodes_pixel_exact", + "a_real_libaom_gradients_stream_with_cdef_decodes_pixel_exact", +]; + #[cfg(test)] mod tests { - use super::{CAPABILITY_CLAIMS, REFUSALS}; + use super::{CAPABILITY_CLAIMS, GATES_THAT_SKIP_ON_A_DECODE_ERROR, REFUSALS}; use std::collections::BTreeSet; /// Every distinct `unsupported(...)` reason on the decode path. @@ -86,6 +108,10 @@ mod tests { for (start, _) in src.match_indices("unsupported(") { // `Error::unsupported(` and the bare helper both end here. let mut i = start + "unsupported(".len(); + // `unsupported(format!("..."))` is the same refusal, one layer in. + if src[i..].starts_with("format!(") { + i += "format!(".len(); + } let mut last: Option = None; loop { while i < bytes.len() && (bytes[i] as char).is_whitespace() { @@ -184,4 +210,41 @@ mod tests { ); } } + + /// No NEW gate may quietly turn a decode error into a skip. + #[test] + fn gates_that_swallow_a_decode_error_are_declared() { + let src = include_str!("stream.rs"); + let mut found: BTreeSet = BTreeSet::new(); + for (i, _) in src.match_indices("\"SKIP ") { + let rest = &src[i + "\"SKIP ".len()..]; + let Some(colon) = rest.find(':') else { continue }; + let name = &rest[..colon]; + if !name.chars().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_') { + continue; + } + // The tail of the message says what was skipped. Only "{e}" -- the + // decode error itself -- is the shape this test is about; "no + // ffmpeg"/"no aomenc" are tool absence, governed by + // EC_AV1_REQUIRE_AOMENC instead. + let Some(end) = rest.find("\"") else { continue }; + if rest[colon..end].contains("{e}") { + found.insert(name.to_owned()); + } + } + let listed: BTreeSet<&str> = GATES_THAT_SKIP_ON_A_DECODE_ERROR.iter().copied().collect(); + let added: Vec<&String> = found.iter().filter(|n| !listed.contains(n.as_str())).collect(); + assert!( + added.is_empty(), + "these gates turn a decode error into a printed SKIP and are not declared: \ + {added:#?}\nA gate that cannot decode has failed -- assert on the error, or use \ + the attempt-loop pattern (several fixtures, at least one must decode, firing count \ + hard-asserted)." + ); + let stale: Vec<&&str> = listed.iter().filter(|n| !found.contains(**n)).collect(); + assert!( + stale.is_empty(), + "{stale:#?} no longer swallow a decode error -- delete them from the list." + ); + } } diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 4f857c1c..94285209 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -120,9 +120,14 @@ pub fn decode_stream(data: &[u8]) -> Result> { let ObuKind::Frame(header, tiles) = obu.kind else { continue; }; - let tile = tiles.first().ok_or_else(|| { - Error::unsupported("AV1 decode_stream", "a frame OBU with no tile group") - })?; + // Every tile is decoded below through `tile_bufs`; this only rejects a + // frame OBU that carries no tile group at all. + if tiles.is_empty() { + return Err(Error::unsupported( + "AV1 decode_stream", + "a frame OBU with no tile group", + )); + } // `read_cdef` (spec `decodeframe.c`, called at the first non-skip // block of each 64x64) only reads a literal `cdef_idx` when // `cdef_bits > 0`; at `cdef_bits == 0` there is nothing to read (a @@ -165,6 +170,25 @@ pub fn decode_stream(data: &[u8]) -> Result> { // intrabc call at all -- that symbol is intra-frame-only). A // genuine palette/intrabc use still refuses by name deeper in the // block readers, so no whole-frame refusal is needed here anymore. + // Both AV1 files in this box's own library (a 2160p HDR10 encode and a + // 1080p one, probed 2026-08-30 through `examples/decode_probe`) are + // `yuv420p10le`, and every buffer this decoder reconstructs into -- + // `Picture`'s `y`/`u`/`v` -- is `Vec`. A 10- or 12-bit stream would + // therefore be reconstructed into 8-bit samples and compared against a + // 10-bit reference, which is silent wrongness rather than a desync: no + // symbol goes unread, the pixels are just quietly truncated. Refuse it + // by name until the planes are widened. `bit_depth` defaults to 8 when + // no sequence header has been seen, which is the existing behaviour for + // every fixture in this crate. + if parser + .sequence_header() + .is_some_and(|seq| seq.color_config.bit_depth != 8) + { + return Err(Error::unsupported( + "AV1 decode_stream", + "a stream whose bit depth is not 8 (this decoder reconstructs into 8-bit planes)", + )); + } if header.delta.q_present || header.delta.lf_present { return Err(Error::unsupported( "AV1 decode_stream", @@ -306,8 +330,6 @@ pub fn decode_stream(data: &[u8]) -> Result> { // `Tile::offset` is relative to the buffer `parse_obu` was handed // (`&data[pos..]` at the time this OBU was parsed), so it is relative // to `obu_offset`, not to `data` as a whole. - let start = obu_offset + tile.offset; - let tile_bytes = data.get(start..start + tile.size).ok_or(Error::NeedMore)?; let tile_bufs: Vec<&[u8]> = tiles .iter() .map(|t| { @@ -6645,7 +6667,6 @@ mod tests { let mut pos = 0usize; let mut saw_multi_tile_inter = false; while pos < stream.len() { - let obu_offset = pos; let obu = parser.parse_obu(&stream[pos..]).unwrap(); pos += obu.total_size; if let ObuKind::Frame(header, _) = obu.kind