forge
Explore
Log in

Don't you dare go Hollow

merge main into lane-tiles (r8 start)

Browse files at this commit

aad3d34b9cf26c37463974b0a929330a3ca24674Ahmet Kaan GümüşParent: 3290985547a1fa
crates/ec-av1/examples/decode_probe.rsadded+38 -0
@@ -0,0 +1,38 @@
1+//! Where does a real stream stop? Decode one AV1 file and print the answer.
2+//!
3+//! The gates in [`ec_av1::stream`] each pin one capability against one encoder
4+//! recipe. This asks the complementary question -- given a stream someone
5+//! actually produced, which refusal comes first -- and it is how the refusal
6+//! distribution in commit 2be815f was measured rather than reasoned about:
7+//!
8+//! ```text
9+//! aomenc --codec=av1 --obu -o s.obu --passes=1 --cpu-used=4 --limit=4 in.y4m
10+//! cargo run -p ec-av1 --example decode_probe -- s.obu
11+//! ```
12+//!
13+//! Note `--obu`: [`ec_av1::stream::decode_stream`] takes a raw OBU stream, and
14+//! an IVF file decodes as zero frames rather than as an error.
15+//!
16+//! That run is also what disproved three refusal strings claiming an encoder
17+//! never writes a case it demonstrably writes, so this is a first-class
18+//! instrument, not a scratch file.
19+fn main() {
20+ let Some(path) = std::env::args().nth(1) else {
21+ eprintln!("usage: decode_probe <stream.obu>");
22+ std::process::exit(2);
23+ };
24+ let data = match std::fs::read(&path) {
25+ Ok(data) => data,
26+ Err(e) => {
27+ eprintln!("{path}: {e}");
28+ std::process::exit(2);
29+ }
30+ };
31+ match ec_av1::stream::decode_stream(&data) {
32+ Ok(frames) if frames.is_empty() => {
33+ println!("OK but EMPTY: no frames -- is {path} an IVF rather than a raw OBU stream?");
34+ }
35+ Ok(frames) => println!("OK: {} frames decoded", frames.len()),
36+ Err(e) => println!("REFUSED: {e}"),
37+ }
38+}
crates/ec-av1/src/decode.rsmodified+6 -3
@@ -5317,14 +5317,17 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
5317 }5317 }
5318 _ => {5318 _ => {
5319 return Err(unsupported(format!(5319 return Err(unsupported(format!(
5320- "a partition type this encoder never writes (value={part32})"5320+ "a 32x32 partition type this decoder does not code (value={part32})"
5321 )));5321 )));
5322 }5322 }
5323 }5323 }
5324 }5324 }
5325 }5325 }
5326 _ => {5326 _ => {
5327- return Err(unsupported("a partition type this encoder never writes"));5327+ return Err(unsupported(
5328+ "a superblock-level partition type other than NONE or SPLIT (this \
5329+ decoder's intra tile path codes only those two at 64x64)",
5330+ ));
5328 }5331 }
5329 }5332 }
5330 }5333 }
@@ -10998,7 +11001,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
10998 }11001 }
10999 _ => {11002 _ => {
11000 return Err(unsupported(format!(11003 return Err(unsupported(format!(
11001- "an INTER 32x32 partition type this encoder never writes (value={part32})"11004+ "an INTER 32x32 partition type this decoder does not code (value={part32})"
11002 )));11005 )));
11003 }11006 }
11004 }11007 }
crates/ec-av1/src/refusal_inventory.rsmodified+65 -2
@@ -29,7 +29,6 @@ const CAPABILITY_CLAIMS: &[&str] = &[
29 "a nonzero angle delta (this encoder never writes one)",29 "a nonzero angle delta (this encoder never writes one)",
30 "a partition below 16x16 other than a clean split (this encoder never writes one)",30 "a partition below 16x16 other than a clean split (this encoder never writes one)",
31 "a partition below 8x8 (this encoder never writes one)",31 "a partition below 8x8 (this encoder never writes one)",
32- "a partition type this encoder never writes",
33 "a tx_type symbol on a rectangular transform (never expected at this size)",32 "a tx_type symbol on a rectangular transform (never expected at this size)",
34 ];33 ];
35 34
@@ -38,7 +37,12 @@ const REFUSALS: &[&str] = &[
38 "GLOBALMV (round 3)",37 "GLOBALMV (round 3)",
39 "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",38 "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
40 "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",39 "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet",
40+ "a 32x32 partition type this decoder does not code (value={part32})",
41 "a Golomb tail longer than this decoder reads",41 "a Golomb tail longer than this decoder reads",
42+ "a stream whose bit depth is not 8 (this decoder reconstructs into 8-bit planes)",
43+ "a tx_type symbol outside its CDF's own set: {t}",
44+ "an INTER 32x32 partition type this decoder does not code (value={part32})",
45+ "a superblock-level partition type other than NONE or SPLIT (this decoder's intra tile path codes only those two at 64x64)",
42 "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)",46 "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)",
43 "a HORZ/VERT intra strip with a split transform (per-unit rect prediction is not ported)",47 "a HORZ/VERT intra strip with a split transform (per-unit rect prediction is not ported)",
44 "a block that actually uses a palette (UV) -- reconstruction is out of scope",48 "a block that actually uses a palette (UV) -- reconstruction is out of scope",
@@ -67,9 +71,27 @@ const REFUSALS: &[&str] = &[
67 "filter intra on a HORZ/VERT strip (this decoder predicts square-only)",71 "filter intra on a HORZ/VERT strip (this decoder predicts square-only)",
68 ];72 ];
69 73
74+/// Gates whose `Err` arm turns a decode failure into a printed SKIP rather than
75+/// a test failure.
76+///
77+/// A gate named `..._decodes_pixel_exact` that cannot decode has failed, and
78+/// swallowing the error keeps the suite green while the gate proves nothing --
79+/// the same vacuum as a gate whose feature never fires, arrived at from the
80+/// other side. These four predate the attempt-loop pattern the newer gates use
81+/// (encode several fixtures, require at least one to decode, hard-assert the
82+/// firing count). They are pinned here so the set cannot grow while they are
83+/// converted one at a time.
84+#[cfg(test)]
85+const GATES_THAT_SKIP_ON_A_DECODE_ERROR: &[&str] = &[
86+ "a_real_aomenc_filter_intra_stream_decodes_pixel_exact",
87+ "a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact",
88+ "a_real_aomenc_intra_stream_with_deblocking_decodes_pixel_exact",
89+ "a_real_libaom_gradients_stream_with_cdef_decodes_pixel_exact",
90+];
91+
70 #[cfg(test)]92 #[cfg(test)]
71 mod tests {93 mod tests {
72- use super::{CAPABILITY_CLAIMS, REFUSALS};94+ use super::{CAPABILITY_CLAIMS, GATES_THAT_SKIP_ON_A_DECODE_ERROR, REFUSALS};
73 use std::collections::BTreeSet;95 use std::collections::BTreeSet;
74 96
75 /// Every distinct `unsupported(...)` reason on the decode path.97 /// Every distinct `unsupported(...)` reason on the decode path.
@@ -86,6 +108,10 @@ mod tests {
86 for (start, _) in src.match_indices("unsupported(") {108 for (start, _) in src.match_indices("unsupported(") {
87 // `Error::unsupported(` and the bare helper both end here.109 // `Error::unsupported(` and the bare helper both end here.
88 let mut i = start + "unsupported(".len();110 let mut i = start + "unsupported(".len();
111+ // `unsupported(format!("..."))` is the same refusal, one layer in.
112+ if src[i..].starts_with("format!(") {
113+ i += "format!(".len();
114+ }
89 let mut last: Option<String> = None;115 let mut last: Option<String> = None;
90 loop {116 loop {
91 while i < bytes.len() && (bytes[i] as char).is_whitespace() {117 while i < bytes.len() && (bytes[i] as char).is_whitespace() {
@@ -184,4 +210,41 @@ mod tests {
184 );210 );
185 }211 }
186 }212 }
213+
214+ /// No NEW gate may quietly turn a decode error into a skip.
215+ #[test]
216+ fn gates_that_swallow_a_decode_error_are_declared() {
217+ let src = include_str!("stream.rs");
218+ let mut found: BTreeSet<String> = BTreeSet::new();
219+ for (i, _) in src.match_indices("\"SKIP ") {
220+ let rest = &src[i + "\"SKIP ".len()..];
221+ let Some(colon) = rest.find(':') else { continue };
222+ let name = &rest[..colon];
223+ if !name.chars().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '_') {
224+ continue;
225+ }
226+ // The tail of the message says what was skipped. Only "{e}" -- the
227+ // decode error itself -- is the shape this test is about; "no
228+ // ffmpeg"/"no aomenc" are tool absence, governed by
229+ // EC_AV1_REQUIRE_AOMENC instead.
230+ let Some(end) = rest.find("\"") else { continue };
231+ if rest[colon..end].contains("{e}") {
232+ found.insert(name.to_owned());
233+ }
234+ }
235+ let listed: BTreeSet<&str> = GATES_THAT_SKIP_ON_A_DECODE_ERROR.iter().copied().collect();
236+ let added: Vec<&String> = found.iter().filter(|n| !listed.contains(n.as_str())).collect();
237+ assert!(
238+ added.is_empty(),
239+ "these gates turn a decode error into a printed SKIP and are not declared: \
240+ {added:#?}\nA gate that cannot decode has failed -- assert on the error, or use \
241+ the attempt-loop pattern (several fixtures, at least one must decode, firing count \
242+ hard-asserted)."
243+ );
244+ let stale: Vec<&&str> = listed.iter().filter(|n| !found.contains(**n)).collect();
245+ assert!(
246+ stale.is_empty(),
247+ "{stale:#?} no longer swallow a decode error -- delete them from the list."
248+ );
249+ }
187 }250 }
crates/ec-av1/src/stream.rsmodified+27 -6
@@ -120,9 +120,14 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
120 let ObuKind::Frame(header, tiles) = obu.kind else {120 let ObuKind::Frame(header, tiles) = obu.kind else {
121 continue;121 continue;
122 };122 };
123- let tile = tiles.first().ok_or_else(|| {123+ // Every tile is decoded below through `tile_bufs`; this only rejects a
124- Error::unsupported("AV1 decode_stream", "a frame OBU with no tile group")124+ // frame OBU that carries no tile group at all.
125- })?;125+ if tiles.is_empty() {
126+ return Err(Error::unsupported(
127+ "AV1 decode_stream",
128+ "a frame OBU with no tile group",
129+ ));
130+ }
126 // `read_cdef` (spec `decodeframe.c`, called at the first non-skip131 // `read_cdef` (spec `decodeframe.c`, called at the first non-skip
127 // block of each 64x64) only reads a literal `cdef_idx` when132 // block of each 64x64) only reads a literal `cdef_idx` when
128 // `cdef_bits > 0`; at `cdef_bits == 0` there is nothing to read (a133 // `cdef_bits > 0`; at `cdef_bits == 0` there is nothing to read (a
@@ -165,6 +170,25 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
165 // intrabc call at all -- that symbol is intra-frame-only). A170 // intrabc call at all -- that symbol is intra-frame-only). A
166 // genuine palette/intrabc use still refuses by name deeper in the171 // genuine palette/intrabc use still refuses by name deeper in the
167 // block readers, so no whole-frame refusal is needed here anymore.172 // block readers, so no whole-frame refusal is needed here anymore.
173+ // Both AV1 files in this box's own library (a 2160p HDR10 encode and a
174+ // 1080p one, probed 2026-08-30 through `examples/decode_probe`) are
175+ // `yuv420p10le`, and every buffer this decoder reconstructs into --
176+ // `Picture`'s `y`/`u`/`v` -- is `Vec<u8>`. A 10- or 12-bit stream would
177+ // therefore be reconstructed into 8-bit samples and compared against a
178+ // 10-bit reference, which is silent wrongness rather than a desync: no
179+ // symbol goes unread, the pixels are just quietly truncated. Refuse it
180+ // by name until the planes are widened. `bit_depth` defaults to 8 when
181+ // no sequence header has been seen, which is the existing behaviour for
182+ // every fixture in this crate.
183+ if parser
184+ .sequence_header()
185+ .is_some_and(|seq| seq.color_config.bit_depth != 8)
186+ {
187+ return Err(Error::unsupported(
188+ "AV1 decode_stream",
189+ "a stream whose bit depth is not 8 (this decoder reconstructs into 8-bit planes)",
190+ ));
191+ }
168 if header.delta.q_present || header.delta.lf_present {192 if header.delta.q_present || header.delta.lf_present {
169 return Err(Error::unsupported(193 return Err(Error::unsupported(
170 "AV1 decode_stream",194 "AV1 decode_stream",
@@ -306,8 +330,6 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
306 // `Tile::offset` is relative to the buffer `parse_obu` was handed330 // `Tile::offset` is relative to the buffer `parse_obu` was handed
307 // (`&data[pos..]` at the time this OBU was parsed), so it is relative331 // (`&data[pos..]` at the time this OBU was parsed), so it is relative
308 // to `obu_offset`, not to `data` as a whole.332 // to `obu_offset`, not to `data` as a whole.
309- let start = obu_offset + tile.offset;
310- let tile_bytes = data.get(start..start + tile.size).ok_or(Error::NeedMore)?;
311 let tile_bufs: Vec<&[u8]> = tiles333 let tile_bufs: Vec<&[u8]> = tiles
312 .iter()334 .iter()
313 .map(|t| {335 .map(|t| {
@@ -6645,7 +6667,6 @@ mod tests {
6645 let mut pos = 0usize;6667 let mut pos = 0usize;
6646 let mut saw_multi_tile_inter = false;6668 let mut saw_multi_tile_inter = false;
6647 while pos < stream.len() {6669 while pos < stream.len() {
6648- let obu_offset = pos;
6649 let obu = parser.parse_obu(&stream[pos..]).unwrap();6670 let obu = parser.parse_obu(&stream[pos..]).unwrap();
6650 pos += obu.total_size;6671 pos += obu.total_size;
6651 if let ObuKind::Frame(header, _) = obu.kind6672 if let ObuKind::Frame(header, _) = obu.kind