merge main (0ea32904) into lane-av1422remeasure: re-verify the gates on the current tip
Browse files at this commit8 changed files +995 -43
- crates/ec-av1/examples/gen_coverage_cells.rs +315 -0
- crates/ec-av1/fixtures/420_odd65x65_key.obu +0 -0
- crates/ec-av1/fixtures/440_request_is_422.obu +0 -0
- crates/ec-av1/src/decode.rs +34 -24
- crates/ec-av1/src/encode.rs +73 -13
- crates/ec-av1/src/refusal_inventory.rs +17 -5
- crates/ec-av1/src/stream.rs +396 -1
- lanes/av1odd440.report.md +160 -0
crates/ec-av1/examples/gen_coverage_cells.rsadded+315 -0
| @@ -0,0 +1,315 @@ | |||
| 1 | +//! Generator for the two AV1 coverage cells no encoder emits, so both are | ||
| 2 | +//! GATED rather than left as declared debt (`lanes/av1formatsweep.report.md` | ||
| 3 | +//! §6.4 and its "declared debt" note: the `4:2:0 with an odd luma dimension` | ||
| 4 | +//! and `4:4:0 (ss 0,1)` rows were "unmeasured and unproducible by recipe"). | ||
| 5 | +//! | ||
| 6 | +//! Both cells are produced here, offline, with no encoder and no ffmpeg: | ||
| 7 | +//! | ||
| 8 | +//! 1. **`420_odd65x65_key.obu`** -- a 4:2:0 key frame whose header declares | ||
| 9 | +//! an ODD luma size (65x65). aomenc cannot produce this one: it rounds the | ||
| 10 | +//! coded size DOWN to even (`av1enc_set_frame_size`; the measured | ||
| 11 | +//! `testsrc2 131x131` y4m comes out as `max_frame=130x130`), so the cell | ||
| 12 | +//! needs the encoder to be told what size to DECLARE. That is | ||
| 13 | +//! [`ec_av1::encode::encode_key_frame_at_size`]: a 96x96 picture padded to | ||
| 14 | +//! the block grid, coded with a 65x65 frame header. The result is a real, | ||
| 15 | +//! fully decodable AV1 stream -- the gate compares it sample for sample | ||
| 16 | +//! against the instrumented `aomdec`. | ||
| 17 | +//! | ||
| 18 | +//! 2. **`440_request_is_422.obu`** -- what this crate's writer produces when | ||
| 19 | +//! it is HANDED 4:4:0 (`subsampling_x = 0`, `subsampling_y = 1`). The | ||
| 20 | +//! cell turns out not to exist: `subsampling_y` is coded only when | ||
| 21 | +//! `subsampling_x` is 1 (spec 5.5.2 `color_config`), so a sequence header | ||
| 22 | +//! carries 4:2:0 `(1,1)`, 4:2:2 `(1,0)` or 4:4:4 `(0,0)` and never | ||
| 23 | +//! `(0,1)` -- libaom's own writer ASSERTS it ("4:4:0 subsampling not | ||
| 24 | +//! allowed in AV1", `av1/encoder/bitstream.c:2467-2468`) and its reader | ||
| 25 | +//! forces | ||
| 26 | +//! `subsampling_y = 0` when `subsampling_x` is 0 | ||
| 27 | +//! (`av1_read_color_config`, `av1/decoder/decodeframe.c:4171-4175`). | ||
| 28 | +//! aomenc having no `yuv440p` input path and ffmpeg's y4m muxer refusing | ||
| 29 | +//! the format ("yuv4mpeg can only handle yuv444p, yuv422p, yuv420p, | ||
| 30 | +//! yuv411p and gray8") are consequences of that, not the reason. The pin | ||
| 31 | +//! is the byte-level evidence: a 4:4:0 request at profile 2 (4:2:2, and | ||
| 32 | +//! no coded subsampling bit below 12 bits) lands on `(1,0)`, the shape | ||
| 33 | +//! this decoder refuses by name. The frame OBU behind it is a real 4:2:0 | ||
| 34 | +//! key frame's, byte for byte -- the subsampling lives only in the | ||
| 35 | +//! sequence header -- so the pin is a HEADER witness, not a decodable | ||
| 36 | +//! 4:2:2 stream, and the gate | ||
| 37 | +//! `the_440_cell_is_not_a_codable_chroma_shape` says exactly that. | ||
| 38 | +//! | ||
| 39 | +//! ```text | ||
| 40 | +//! cargo run -p ec-av1 --example gen_coverage_cells -- crates/ec-av1/fixtures | ||
| 41 | +//! sha256sum crates/ec-av1/fixtures/420_odd65x65_key.obu \ | ||
| 42 | +//! crates/ec-av1/fixtures/440_request_is_422.obu | ||
| 43 | +//! ``` | ||
| 44 | +//! | ||
| 45 | +//! Both files are deterministic: the source card is a fixed integer pattern | ||
| 46 | +//! and the encoder is deterministic, so re-running this overwrites the pins | ||
| 47 | +//! with the same bytes. `ec-av1` is a hand-code-only repository -- do NOT run | ||
| 48 | +//! `cargo fmt` on this file; rustfmt runs at commit time and its churn is | ||
| 49 | +//! accepted, never reverted. | ||
| 50 | + | ||
| 51 | +use ec_av1::encode::Picture; | ||
| 52 | +use ec_av1_syntax::{ColorConfig, ObuKind}; | ||
| 53 | + | ||
| 54 | +/// The padded coding surface the odd cell is cut from: a whole number of | ||
| 55 | +/// 32x32 blocks (`Picture::check`'s own rule), and a multiple of 8 above the | ||
| 56 | +/// 65x65 it declares, so no declared column is already block-aligned. | ||
| 57 | +const PAD: usize = 96; | ||
| 58 | + | ||
| 59 | +/// The odd-luma cell's DECLARED frame size. Both dimensions odd on purpose: | ||
| 60 | +/// the 4:2:0 chroma extent is then `ROUND_POWER_OF_TWO(65, 1) = 33` in each | ||
| 61 | +/// axis (libaom `av1_common_plane_width`, `av1/common/av1_common_int.h`), | ||
| 62 | +/// which is where a floor (32) and a ceil (33) disagree -- the whole reason | ||
| 63 | +/// the cell was worth closing. | ||
| 64 | +const ODD: usize = 65; | ||
| 65 | + | ||
| 66 | +/// The 4:4:0 witness's frame size, and the quantizer both streams are coded | ||
| 67 | +/// at. Even, so nothing else about the witness is unusual: the shape is 4:4:0 | ||
| 68 | +/// and nothing else. | ||
| 69 | +const WITNESS: usize = 64; | ||
| 70 | + | ||
| 71 | +/// `base_q_idx` for both cells. Mid-scale on purpose: high enough that a | ||
| 72 | +/// block carries real coefficients (so a wrong chroma extent shows in the | ||
| 73 | +/// output), low enough that the stream stays small. | ||
| 74 | +const Q_IDX: u8 = 100; | ||
| 75 | + | ||
| 76 | +/// A deterministic, high-frequency card: a 2-D pattern whose wrapped | ||
| 77 | +/// diagonal jumps, so every 8x8 block has real high-frequency content and | ||
| 78 | +/// therefore real coefficients. That matters for the odd cell -- a flat or | ||
| 79 | +/// smooth card predicts to within a quantizer step of a constant in its last | ||
| 80 | +/// column too, so a wrong chroma extent could leave the OUTPUT unchanged and | ||
| 81 | +/// the gate would then be green on broken code. | ||
| 82 | +fn card(width: usize, height: usize) -> Picture { | ||
| 83 | + let mut picture = Picture::grey(width, height); | ||
| 84 | + for row in 0..height { | ||
| 85 | + for col in 0..width { | ||
| 86 | + picture.y[row * width + col] = ((row * 7 + col * 11) % 251) as u16; | ||
| 87 | + } | ||
| 88 | + } | ||
| 89 | + for row in 0..height / 2 { | ||
| 90 | + for col in 0..width / 2 { | ||
| 91 | + let i = row * (width / 2) + col; | ||
| 92 | + picture.u[i] = ((row * 13 + col * 29) % 241) as u16; | ||
| 93 | + picture.v[i] = ((row * 17 + col * 5) % 239) as u16; | ||
| 94 | + } | ||
| 95 | + } | ||
| 96 | + picture | ||
| 97 | +} | ||
| 98 | + | ||
| 99 | +/// The chroma shape of the 4:4:0 witness: profile 0 with `subsampling_x = 0` | ||
| 100 | +/// and `subsampling_y = 1`. Profile 0 forces neither subsampling bit (only | ||
| 101 | +/// profile 1 forces 4:4:4 and profile 2 below 12 bits forces 4:2:2, spec | ||
| 102 | +/// 5.5.2), so both are coded in the header and `(0, 1)` -- 4:4:0 -- is legal | ||
| 103 | +/// there. | ||
| 104 | +fn yuv440() -> ColorConfig { | ||
| 105 | + ColorConfig { | ||
| 106 | + bit_depth: 8, | ||
| 107 | + mono_chrome: false, | ||
| 108 | + num_planes: 3, | ||
| 109 | + color_primaries: 2, | ||
| 110 | + transfer_characteristics: 2, | ||
| 111 | + matrix_coefficients: 2, | ||
| 112 | + color_range: false, | ||
| 113 | + subsampling_x: 0, | ||
| 114 | + subsampling_y: 1, | ||
| 115 | + chroma_sample_position: ec_av1_syntax::ChromaSamplePosition::Unknown, | ||
| 116 | + separate_uv_delta_q: false, | ||
| 117 | + } | ||
| 118 | +} | ||
| 119 | + | ||
| 120 | +/// Writes `bytes` to `<dir>/<name>`, then reports size, FNV-1a64 and sha256. | ||
| 121 | +fn emit(dir: &str, name: &str, bytes: &[u8]) { | ||
| 122 | + let path = std::path::Path::new(dir).join(name); | ||
| 123 | + std::fs::write(&path, bytes).unwrap_or_else(|e| panic!("writing {}: {e}", path.display())); | ||
| 124 | + let mut fnv: u64 = 0xcbf2_9ce4_8422_2325; | ||
| 125 | + for &b in bytes { | ||
| 126 | + fnv = (fnv ^ u64::from(b)).wrapping_mul(0x0000_0100_0000_01b3); | ||
| 127 | + } | ||
| 128 | + println!("{name}: {} bytes, fnv1a64 {fnv:016x}", bytes.len()); | ||
| 129 | + // sha256sum is coreutils, present on every host this runs on; the pins' | ||
| 130 | + // provenance comments in `stream.rs` quote its output. | ||
| 131 | + let out = std::process::Command::new("sha256sum") | ||
| 132 | + .arg(&path) | ||
| 133 | + .output() | ||
| 134 | + .expect("sha256sum"); | ||
| 135 | + assert!( | ||
| 136 | + out.status.success(), | ||
| 137 | + "sha256sum failed on {}", | ||
| 138 | + path.display() | ||
| 139 | + ); | ||
| 140 | + println!( | ||
| 141 | + "{name}: sha256 {}", | ||
| 142 | + String::from_utf8_lossy(&out.stdout) | ||
| 143 | + .split_whitespace() | ||
| 144 | + .next() | ||
| 145 | + .expect("a sha256sum line") | ||
| 146 | + ); | ||
| 147 | +} | ||
| 148 | + | ||
| 149 | +/// The subsampling and the max frame size a reader gets back out of `bytes` | ||
| 150 | +/// -- the generator never takes the shape it wrote on faith, it re-parses | ||
| 151 | +/// its own output. | ||
| 152 | +fn read_back(name: &str, bytes: &[u8]) -> (u8, u8, u32, u32) { | ||
| 153 | + let mut parser = ec_av1_syntax::Av1Parser::new(); | ||
| 154 | + let mut pos = 0usize; | ||
| 155 | + while pos < bytes.len() && parser.sequence_header().is_none() { | ||
| 156 | + let obu = parser | ||
| 157 | + .parse_obu(&bytes[pos..]) | ||
| 158 | + .unwrap_or_else(|e| panic!("{name}: OBU at byte {pos} does not parse: {e:?}")); | ||
| 159 | + pos += obu.total_size; | ||
| 160 | + } | ||
| 161 | + let seq = parser | ||
| 162 | + .sequence_header() | ||
| 163 | + .unwrap_or_else(|| panic!("{name}: no sequence header parsed back out of its own bytes")); | ||
| 164 | + ( | ||
| 165 | + seq.color_config.subsampling_x, | ||
| 166 | + seq.color_config.subsampling_y, | ||
| 167 | + seq.max_frame_width, | ||
| 168 | + seq.max_frame_height, | ||
| 169 | + ) | ||
| 170 | +} | ||
| 171 | + | ||
| 172 | +/// The bytes of `stream`'s single `OBU_FRAME`, OBU header and size field | ||
| 173 | +/// included. An example cannot reach `Encoded::tile` (crate-private, and | ||
| 174 | +/// documented as a `crate::decode` test-only reader) and does not need to: | ||
| 175 | +/// the OBU is right there in the stream the encoder just wrote. | ||
| 176 | +fn frame_obu_of(stream: &[u8], name: &str) -> Vec<u8> { | ||
| 177 | + let mut parser = ec_av1_syntax::Av1Parser::new(); | ||
| 178 | + let mut pos = 0usize; | ||
| 179 | + while pos < stream.len() { | ||
| 180 | + let obu = parser | ||
| 181 | + .parse_obu(&stream[pos..]) | ||
| 182 | + .unwrap_or_else(|e| panic!("{name}: OBU at byte {pos} does not parse: {e:?}")); | ||
| 183 | + if matches!(obu.kind, ObuKind::Frame(..)) { | ||
| 184 | + return stream[pos..pos + obu.total_size].to_vec(); | ||
| 185 | + } | ||
| 186 | + pos += obu.total_size; | ||
| 187 | + } | ||
| 188 | + panic!( | ||
| 189 | + "{name}: no frame OBU in a {}-byte key frame stream", | ||
| 190 | + stream.len() | ||
| 191 | + ); | ||
| 192 | +} | ||
| 193 | + | ||
| 194 | +fn main() { | ||
| 195 | + let dir = std::env::args() | ||
| 196 | + .nth(1) | ||
| 197 | + .unwrap_or_else(|| "crates/ec-av1/fixtures".to_string()); | ||
| 198 | + std::fs::create_dir_all(&dir).expect("output dir"); | ||
| 199 | + | ||
| 200 | + // ---- cell 1: 4:2:0 with an odd luma dimension ------------------------- | ||
| 201 | + let encoded = ec_av1::encode::encode_key_frame_at_size(&card(PAD, PAD), ODD, ODD, Q_IDX, 0.5) | ||
| 202 | + .expect("encoding the odd-luma key frame"); | ||
| 203 | + let (sx, sy, mw, mh) = read_back("420_odd65x65_key", &encoded.stream); | ||
| 204 | + assert_eq!( | ||
| 205 | + (sx, sy), | ||
| 206 | + (1, 1), | ||
| 207 | + "the odd cell must stay 4:2:0 -- it is the luma SIZE that is odd, not the shape" | ||
| 208 | + ); | ||
| 209 | + assert_eq!( | ||
| 210 | + (mw, mh), | ||
| 211 | + (ODD as u32, ODD as u32), | ||
| 212 | + "the odd cell's sequence header must declare {ODD}x{ODD}" | ||
| 213 | + ); | ||
| 214 | + assert_eq!( | ||
| 215 | + (encoded.reconstruction.width, encoded.reconstruction.height), | ||
| 216 | + (ODD, ODD), | ||
| 217 | + "the returned reconstruction must be cropped to the DECLARED size" | ||
| 218 | + ); | ||
| 219 | + assert_eq!( | ||
| 220 | + encoded.reconstruction.u.len(), | ||
| 221 | + ODD.div_ceil(2) * ODD.div_ceil(2), | ||
| 222 | + "a 4:2:0 frame of odd luma size keeps the ceil chroma extent" | ||
| 223 | + ); | ||
| 224 | + println!( | ||
| 225 | + "420_odd65x65_key: max_frame {mw}x{mh} at ({sx},{sy}), chroma {}x{} \ | ||
| 226 | + (ROUND_POWER_OF_TWO({ODD},1) = {}), mi {}x{}, reconstruction {}x{} luma + {} chroma \ | ||
| 227 | + samples", | ||
| 228 | + ODD.div_ceil(2), | ||
| 229 | + ODD.div_ceil(2), | ||
| 230 | + ODD.div_ceil(2), | ||
| 231 | + 2 * ((ODD + 7) >> 3), | ||
| 232 | + 2 * ((ODD + 7) >> 3), | ||
| 233 | + encoded.reconstruction.width, | ||
| 234 | + encoded.reconstruction.height, | ||
| 235 | + encoded.reconstruction.u.len(), | ||
| 236 | + ); | ||
| 237 | + emit(&dir, "420_odd65x65_key.obu", &encoded.stream); | ||
| 238 | + | ||
| 239 | + // ---- cell 2: the 4:4:0 (ss 0,1) row ------------------------------------ | ||
| 240 | + // 4:4:0 is NOT A CELL: `subsampling_y` is coded only when | ||
| 241 | + // `subsampling_x` is 1 (spec 5.5.2 `color_config`), so a header can | ||
| 242 | + // carry 4:2:0 (1,1), 4:2:2 (1,0) or 4:4:4 (0,0) and never (0,1). | ||
| 243 | + // libaom asserts it in its own writer -- | ||
| 244 | + // `assert(seq_params->subsampling_y == 0 && "4:4:0 subsampling not | ||
| 245 | + // allowed in AV1")`, av1/encoder/bitstream.c:2467-2468 -- and its reader | ||
| 246 | + // leaves `subsampling_y = 0` when `subsampling_x` is 0 | ||
| 247 | + // (`av1_read_color_config`, av1/decoder/decodeframe.c:4171-4175). | ||
| 248 | + // | ||
| 249 | + // So this file pins WHAT A 4:4:0 REQUEST PRODUCES: the writer handed | ||
| 250 | + // subsampling (0,1) at profile 2, which below 12 bits is 4:2:2 and codes | ||
| 251 | + // no subsampling bit at all, and the request lands on (1,0). The frame | ||
| 252 | + // OBU behind it is a real 4:2:0 key frame's, byte for byte: the | ||
| 253 | + // subsampling lives only in the sequence header, so the frame header is | ||
| 254 | + // the same one either way. The stream is NOT a decodable 4:2:2 stream | ||
| 255 | + // (its tile is 4:2:0); it is pinned as the byte-level evidence for the | ||
| 256 | + // claim, and the decoder refuses it by name, which is the honest | ||
| 257 | + // outcome for the shape the request lands on. | ||
| 258 | + let tile_stream = ec_av1::encode::encode_key_frame(&card(WITNESS, WITNESS), Q_IDX, 0.5) | ||
| 259 | + .expect("encoding the witness tile") | ||
| 260 | + .stream; | ||
| 261 | + let frame_bytes = frame_obu_of(&tile_stream, "the 4:4:0 request's tile"); | ||
| 262 | + let (mut seq, _header) = | ||
| 263 | + ec_av1::encode::key_frame_headers_colour(WITNESS, WITNESS, Q_IDX, yuv440()) | ||
| 264 | + .expect("building the 4:4:0-request sequence header"); | ||
| 265 | + seq.seq_profile = 2; | ||
| 266 | + let mut witness = | ||
| 267 | + ec_av1::sequence::sequence_header_obu(&seq).expect("writing that sequence header"); | ||
| 268 | + witness.extend_from_slice(&frame_bytes); | ||
| 269 | + let (sx, sy, mw, mh) = read_back("440_request_is_422", &witness); | ||
| 270 | + assert_eq!( | ||
| 271 | + (sx, sy), | ||
| 272 | + (1, 0), | ||
| 273 | + "a 4:4:0 request at profile 2 must land on 4:2:2 (1,0). If it ever reads back (0,1), \ | ||
| 274 | + 4:4:0 became codable and the whole cell-2 story is wrong." | ||
| 275 | + ); | ||
| 276 | + assert_eq!( | ||
| 277 | + (mw, mh), | ||
| 278 | + (WITNESS as u32, WITNESS as u32), | ||
| 279 | + "the request stream's frame size" | ||
| 280 | + ); | ||
| 281 | + // The frame OBU behind the header must still parse as the frame header | ||
| 282 | + // the 4:2:0 stream carried. | ||
| 283 | + let mut parser = ec_av1_syntax::Av1Parser::new(); | ||
| 284 | + let first = parser | ||
| 285 | + .parse_obu(&witness) | ||
| 286 | + .expect("the request's sequence header OBU parses"); | ||
| 287 | + let frame = match parser | ||
| 288 | + .parse_obu(&witness[first.total_size..]) | ||
| 289 | + .expect("the request's frame OBU parses") | ||
| 290 | + .kind | ||
| 291 | + { | ||
| 292 | + ObuKind::Frame(h, tiles) => { | ||
| 293 | + assert_eq!( | ||
| 294 | + tiles.len(), | ||
| 295 | + 1, | ||
| 296 | + "the request stream carries exactly one tile" | ||
| 297 | + ); | ||
| 298 | + h | ||
| 299 | + } | ||
| 300 | + other => panic!("440_request_is_422: expected a frame OBU, got {other:?}"), | ||
| 301 | + }; | ||
| 302 | + assert_eq!( | ||
| 303 | + (frame.frame_width, frame.frame_height), | ||
| 304 | + (WITNESS as u32, WITNESS as u32), | ||
| 305 | + "the request stream's frame header must name its own size" | ||
| 306 | + ); | ||
| 307 | + println!( | ||
| 308 | + "440_request_is_422: asked for subsampling (0,1) at profile {} -- got ({sx},{sy}) at \ | ||
| 309 | + max_frame {mw}x{mh}, i.e. 4:2:2, the shape this decoder refuses by name; frame header + \ | ||
| 310 | + one tile ({} bytes) from a 4:2:0 {WITNESS}x{WITNESS} key frame", | ||
| 311 | + seq.seq_profile, | ||
| 312 | + frame_bytes.len() | ||
| 313 | + ); | ||
| 314 | + emit(&dir, "440_request_is_422.obu", &witness); | ||
| 315 | +} | ||
crates/ec-av1/fixtures/420_odd65x65_key.obuadded+0 -0
Binary file changed
crates/ec-av1/fixtures/440_request_is_422.obuadded+0 -0
Binary file changed
crates/ec-av1/src/decode.rsmodified+34 -24
| @@ -37762,28 +37762,26 @@ fn whole_plane(data: &[u16], width: usize, height: usize) -> PlaneBuf<'_> { | |||
| 37762 | /// **every `w >= 2 && h >= 2`**. No stream this decoder accepts reaches a | 37762 | /// **every `w >= 2 && h >= 2`**. No stream this decoder accepts reaches a |
| 37763 | /// 1-pixel chroma plane; the pinned fixture's chroma is 128x144. | 37763 | /// 1-pixel chroma plane; the pinned fixture's chroma is 128x144. |
| 37764 | /// | 37764 | /// |
| 37765 | -/// **Open gap, 4:2:0 at odd dimensions (pre-existing).** The 4:2:0 arm is | 37765 | +/// **4:2:0 at odd dimensions: CLOSED by lane-av1odd440.** The arm used to be |
| 37766 | -/// left at the old `(width / 2, height / 2)` floor, which is what the | 37766 | +/// the old `(width / 2, height / 2)` floor, which was what the two-way test |
| 37767 | -/// two-way test this replaces produced -- that was the point, since no | 37767 | +/// this replaces produced -- harmless then, since no 4:2:0 stream changed |
| 37768 | -/// 4:2:0 stream changed shape. It is nevertheless the wrong shape for an | 37768 | +/// shape, and wrong for an odd-dimension 4:2:0 reference: the producer |
| 37769 | -/// odd-dimension 4:2:0 reference: the producer stored | 37769 | +/// stored `round_ss(w, 1) x round_ss(h, 1)`, so the floor arm |
| 37770 | -/// `round_ss(w, 1) x round_ss(h, 1)`, so the floor arm under-declares. | 37770 | +/// under-declared. Measured over the `1..=128` square, running each 4:2:0 |
| 37771 | -/// Measured over the `1..=128` square, running each 4:2:0 count through | 37771 | +/// count through this very function: 12160 of the 16384 pairs came back |
| 37772 | -/// this very function: 12160 of the 16384 pairs come back smaller than the | 37772 | +/// smaller than the plane actually holds, 12033 of those with `w >= 2` and |
| 37773 | -/// plane actually holds, 12033 of those with `w >= 2` and 127 in the | 37773 | +/// 127 in the `w == 1` column, where the floor cannot even express |
| 37774 | -/// `w == 1` column (at `w == 1, h == 1` the 4:4:4 arm catches the count | 37774 | +/// `(1, round_ss(h, 1))`. It was left alone pending "a lane that can bring |
| 37775 | -/// and `(1, 1)` is exact). Under-declaration at `h == 1` is **zero** over | 37775 | +/// odd-dimension 4:2:0 fixtures with it" -- this is that lane: the pinned |
| 37776 | -/// the whole square: there the 4:2:0 count equals the 4:2:2 count, routes | 37776 | +/// `420_odd65x65_key.obu` is a real 65x65 4:2:0 key frame (declared at |
| 37777 | -/// into the 4:2:2 arm, and lands on the correct | 37777 | +/// `encode::encode_key_frame_at_size`, because aomenc rounds the coded size |
| 37778 | -/// `(round_ss(w, 1), 1)`. The `w == 1` residue is a *shape* error, not a | 37778 | +/// down to even and cannot produce one) whose chroma planes are 33x33, and |
| 37779 | -/// misroute -- the floor fallback simply cannot express | 37779 | +/// the gate `an_odd_luma_420_key_frame_decodes_pixel_exact` decodes it |
| 37780 | -/// `(1, round_ss(h, 1))`. It is left alone because it predates this lane, | 37780 | +/// sample-exact against `aomdec`. The arm is now the producer's own crop, |
| 37781 | -/// is identical to the parent, and no in-tree coverage exercises an | 37781 | +/// so a 4:2:0 reference at ANY size routes back to the shape the producer |
| 37782 | -/// odd-dimension 4:2:0 reference. A ceil fallback | 37782 | +/// wrote. Even sizes are untouched: `(2k + 1) / 2 == k`, so every 4:2:0 |
| 37783 | -/// (`(round_ss(w, 1), round_ss(h, 1))`) would close it, at the cost of | 37783 | +/// reference this decoder met before this lane claims exactly the same |
| 37784 | -/// departing from the parent on every odd-dimension 4:2:0 shape with | 37784 | +/// shape it did then. |
| 37785 | -/// nothing in the tree to justify the change; that call belongs to a lane | ||
| 37786 | -/// that can bring odd-dimension 4:2:0 fixtures with it. | ||
| 37787 | fn ref_chroma_shape(len: usize, width: usize, height: usize) -> (usize, usize) { | 37785 | fn ref_chroma_shape(len: usize, width: usize, height: usize) -> (usize, usize) { |
| 37788 | let half_w = round_ss(width, 1); | 37786 | let half_w = round_ss(width, 1); |
| 37789 | if len == width * height { | 37787 | if len == width * height { |
| @@ -37791,7 +37789,7 @@ fn ref_chroma_shape(len: usize, width: usize, height: usize) -> (usize, usize) { | |||
| 37791 | } else if len == half_w * height { | 37789 | } else if len == half_w * height { |
| 37792 | (half_w, height) | 37790 | (half_w, height) |
| 37793 | } else { | 37791 | } else { |
| 37794 | - (width / 2, height / 2) | 37792 | + (round_ss(width, 1), round_ss(height, 1)) |
| 37795 | } | 37793 | } |
| 37796 | } | 37794 | } |
| 37797 | 37795 | ||
| @@ -54695,6 +54693,14 @@ mod tests { | |||
| 54695 | /// exact defect this lane fixed, one dimension over. So the table below | 54693 | /// exact defect this lane fixed, one dimension over. So the table below |
| 54696 | /// is driven off `round_ss`, not off hand-written numbers, and sweeps | 54694 | /// is driven off `round_ss`, not off hand-written numbers, and sweeps |
| 54697 | /// odd and even widths. | 54695 | /// odd and even widths. |
| 54696 | + /// | ||
| 54697 | + /// lane-av1odd440: the 4:2:0 arm's expectation is the PRODUCER's crop, | ||
| 54698 | + /// `round_ss(w, 1) x round_ss(h, 1)`, not the `(w / 2, h / 2)` floor it | ||
| 54699 | + /// used to name -- the floor under-declares every odd-dimension 4:2:0 | ||
| 54700 | + /// reference, which is the shape the pinned `420_odd65x65_key.obu` cell | ||
| 54701 | + /// finally makes reachable (see [`ref_chroma_shape`]). For every EVEN | ||
| 54702 | + /// size the two spellings are the same number, so the arms that were | ||
| 54703 | + /// already correct are unchanged by the edit. | ||
| 54698 | #[test] | 54704 | #[test] |
| 54699 | fn a_reference_chroma_sample_count_routes_back_to_its_own_format() { | 54705 | fn a_reference_chroma_sample_count_routes_back_to_its_own_format() { |
| 54700 | for w in [2usize, 3, 4, 5, 8, 9, 16, 17, 64, 65, 128, 129] { | 54706 | for w in [2usize, 3, 4, 5, 8, 9, 16, 17, 64, 65, 128, 129] { |
| @@ -54706,7 +54712,11 @@ mod tests { | |||
| 54706 | round_ss(w, 1) * round_ss(h, 0), | 54712 | round_ss(w, 1) * round_ss(h, 0), |
| 54707 | (round_ss(w, 1), h), | 54713 | (round_ss(w, 1), h), |
| 54708 | ), | 54714 | ), |
| 54709 | - ("4:2:0", round_ss(w, 1) * round_ss(h, 1), (w / 2, h / 2)), | 54715 | + ( |
| 54716 | + "4:2:0", | ||
| 54717 | + round_ss(w, 1) * round_ss(h, 1), | ||
| 54718 | + (round_ss(w, 1), round_ss(h, 1)), | ||
| 54719 | + ), | ||
| 54710 | ]; | 54720 | ]; |
| 54711 | for (name, len, want) in cases { | 54721 | for (name, len, want) in cases { |
| 54712 | assert_eq!( | 54722 | assert_eq!( |
crates/ec-av1/src/encode.rsmodified+73 -13
| @@ -1807,8 +1807,16 @@ fn crop_plane<T: Copy>(source: &[T], padded_width: usize, width: usize, height: | |||
| 1807 | /// region a decoder produces, which is the public contract for what a caller | 1807 | /// region a decoder produces, which is the public contract for what a caller |
| 1808 | /// sees back — the padded planes the encoder coded against never leave this | 1808 | /// sees back — the padded planes the encoder coded against never leave this |
| 1809 | /// module. Identity when the reconstruction is already that size. | 1809 | /// module. Identity when the reconstruction is already that size. |
| 1810 | +/// | ||
| 1811 | +/// The chroma extent is `ROUND_POWER_OF_TWO(size, 1)` -- `(size + 1) / 2`, | ||
| 1812 | +/// libaom's `av1_common_plane_width` (`av1/common/av1_common_int.h`) -- so an | ||
| 1813 | +/// ODD declared luma size keeps the chroma column a decoder keeps (a 65-wide | ||
| 1814 | +/// 4:2:0 frame has 33, not 32). Every even size is unaffected: `(2k+1)/2 == | ||
| 1815 | +/// k`, so this is a no-op for every caller `encode_key_frame`'s even-size | ||
| 1816 | +/// check lets through. | ||
| 1810 | pub(crate) fn crop_encoded(encoded: &Encoded, width: usize, height: usize) -> Encoded { | 1817 | pub(crate) fn crop_encoded(encoded: &Encoded, width: usize, height: usize) -> Encoded { |
| 1811 | let reconstruction = &encoded.reconstruction; | 1818 | let reconstruction = &encoded.reconstruction; |
| 1819 | + let (cw, ch) = (width.div_ceil(2), height.div_ceil(2)); | ||
| 1812 | let cropped = if reconstruction.width == width && reconstruction.height == height { | 1820 | let cropped = if reconstruction.width == width && reconstruction.height == height { |
| 1813 | reconstruction.clone() | 1821 | reconstruction.clone() |
| 1814 | } else { | 1822 | } else { |
| @@ -1816,18 +1824,8 @@ pub(crate) fn crop_encoded(encoded: &Encoded, width: usize, height: usize) -> En | |||
| 1816 | width, | 1824 | width, |
| 1817 | height, | 1825 | height, |
| 1818 | y: crop_plane(&reconstruction.y, reconstruction.width, width, height), | 1826 | y: crop_plane(&reconstruction.y, reconstruction.width, width, height), |
| 1819 | - u: crop_plane( | 1827 | + u: crop_plane(&reconstruction.u, reconstruction.width / 2, cw, ch), |
| 1820 | - &reconstruction.u, | 1828 | + v: crop_plane(&reconstruction.v, reconstruction.width / 2, cw, ch), |
| 1821 | - reconstruction.width / 2, | ||
| 1822 | - width / 2, | ||
| 1823 | - height / 2, | ||
| 1824 | - ), | ||
| 1825 | - v: crop_plane( | ||
| 1826 | - &reconstruction.v, | ||
| 1827 | - reconstruction.width / 2, | ||
| 1828 | - width / 2, | ||
| 1829 | - height / 2, | ||
| 1830 | - ), | ||
| 1831 | } | 1829 | } |
| 1832 | }; | 1830 | }; |
| 1833 | Encoded { | 1831 | Encoded { |
| @@ -2201,9 +2199,17 @@ fn unspecified_color_config() -> ColorConfig { | |||
| 2201 | /// which is all a player picks a colour transform from and which | 2199 | /// which is all a player picks a colour transform from and which |
| 2202 | /// [`crate::encoder::Colour`] is the facade's own name for. | 2200 | /// [`crate::encoder::Colour`] is the facade's own name for. |
| 2203 | /// | 2201 | /// |
| 2202 | +/// `color_config` also carries the chroma shape, and that is what a coverage | ||
| 2203 | +/// witness needs: nothing in this crate's ENCODER codes a shape other than | ||
| 2204 | +/// 4:2:0, but a sequence header can still be written at any | ||
| 2205 | +/// `subsampling_x`/`subsampling_y` the spec allows, which is how the 4:4:0 | ||
| 2206 | +/// header witness is built. It builds HEADERS only -- pair the pair it | ||
| 2207 | +/// returns with a tile from [`encode_key_frame`] (4:2:0) or | ||
| 2208 | +/// [`encode_key_frame_at_size`]. | ||
| 2209 | +/// | ||
| 2204 | /// # Errors | 2210 | /// # Errors |
| 2205 | /// The same as [`key_frame_headers`]. | 2211 | /// The same as [`key_frame_headers`]. |
| 2206 | -pub(crate) fn key_frame_headers_colour( | 2212 | +pub fn key_frame_headers_colour( |
| 2207 | width: usize, | 2213 | width: usize, |
| 2208 | height: usize, | 2214 | height: usize, |
| 2209 | base_q_idx: u8, | 2215 | base_q_idx: u8, |
| @@ -8894,6 +8900,60 @@ pub fn encode_sequence( | |||
| 8894 | ) | 8900 | ) |
| 8895 | } | 8901 | } |
| 8896 | 8902 | ||
| 8903 | +/// Codes one padded picture as a key frame whose HEADER declares | ||
| 8904 | +/// `frame_width` x `frame_height` -- a frame size the picture's own | ||
| 8905 | +/// `width`/`height` need not be, and in particular need not be even. | ||
| 8906 | +/// | ||
| 8907 | +/// [`encode_key_frame`] derives the declared size from the picture and | ||
| 8908 | +/// refuses an odd one, which is a property of a 4:2:0 SOURCE (an odd luma | ||
| 8909 | +/// column has no chroma sample of its own to be fed), not of the format: a | ||
| 8910 | +/// 65-wide 4:2:0 frame is a legal AV1 frame, with | ||
| 8911 | +/// `ROUND_POWER_OF_TWO(65, 1) = 33` chroma columns (libaom | ||
| 8912 | +/// `av1_common_plane_width` / `ROUND_POWER_OF_TWO`, `av1/common/ | ||
| 8913 | +/// av1_common_int.h`), and aomenc never emits one only because it rounds the | ||
| 8914 | +/// coded size down to even before it looks at the picture | ||
| 8915 | +/// (`av1enc_set_frame_size`). This is the entry that can produce one, and it | ||
| 8916 | +/// is what the odd-luma coverage fixture is built with: the caller hands | ||
| 8917 | +/// over a picture already padded to the block grid and names the size to | ||
| 8918 | +/// declare, so the block walk codes exactly the `mi_cols`/`mi_rows` a | ||
| 8919 | +/// decoder derives from the declared size (spec `compute_image_size`). | ||
| 8920 | +/// | ||
| 8921 | +/// # Errors | ||
| 8922 | +/// Returns an error when `picture` is not a whole number of 32x32 blocks | ||
| 8923 | +/// ([`Picture::check`]'s own rule), when either declared size is zero or | ||
| 8924 | +/// larger than the padded picture's, or when the mode search fails -- the | ||
| 8925 | +/// same conditions [`encode_key_frame`] reports for a malformed picture. | ||
| 8926 | +pub fn encode_key_frame_at_size( | ||
| 8927 | + picture: &Picture, | ||
| 8928 | + frame_width: usize, | ||
| 8929 | + frame_height: usize, | ||
| 8930 | + base_q_idx: u8, | ||
| 8931 | + deadzone: f64, | ||
| 8932 | +) -> Result<Encoded> { | ||
| 8933 | + picture.check()?; | ||
| 8934 | + if frame_width == 0 | ||
| 8935 | + || frame_height == 0 | ||
| 8936 | + || frame_width > picture.width | ||
| 8937 | + || frame_height > picture.height | ||
| 8938 | + { | ||
| 8939 | + return Err(Error::unsupported( | ||
| 8940 | + "AV1 encode", | ||
| 8941 | + "the declared frame size must be nonzero and fit inside the padded picture", | ||
| 8942 | + )); | ||
| 8943 | + } | ||
| 8944 | + let encoded = encode_key_frame_inner( | ||
| 8945 | + picture, | ||
| 8946 | + base_q_idx, | ||
| 8947 | + deadzone, | ||
| 8948 | + &KEY_FRAME_MODES, | ||
| 8949 | + split_blocks(), | ||
| 8950 | + (frame_width, frame_height), | ||
| 8951 | + unspecified_color_config(), | ||
| 8952 | + &crate::decode::FrameCtx::for_encoder(), | ||
| 8953 | + )?; | ||
| 8954 | + Ok(crop_encoded(&encoded, frame_width, frame_height)) | ||
| 8955 | +} | ||
| 8956 | + | ||
| 8897 | pub(crate) fn encode_key_frame_with_ctx( | 8957 | pub(crate) fn encode_key_frame_with_ctx( |
| 8898 | picture: &Picture, | 8958 | picture: &Picture, |
| 8899 | base_q_idx: u8, | 8959 | base_q_idx: u8, |
crates/ec-av1/src/refusal_inventory.rsmodified+17 -5
| @@ -116,7 +116,15 @@ const REFUSALS: &[&str] = &[ | |||
| 116 | // hardcoded 4:2:0, the probe emits 4:2:0 planes only); it is now refused | 116 | // hardcoded 4:2:0, the probe emits 4:2:0 planes only); it is now refused |
| 117 | // at the sequence header. Gate: | 117 | // at the sequence header. Gate: |
| 118 | // `a_non_420_subsampled_sequence_header_is_refused_by_name`. | 118 | // `a_non_420_subsampled_sequence_header_is_refused_by_name`. |
| 119 | - "a chroma format of 4:2:2 (subsampling_x != subsampling_y): this decoder decodes 4:2:0 and 4:4:4; 4:2:2 is not ported", | 119 | + // lane-av1odd440: the string gained its 4:4:0 clause. `subsampling_y` is |
| 120 | + // coded only when `subsampling_x` is 1 (spec 5.5.2; libaom | ||
| 121 | + // `av1_read_color_config`, `av1/decoder/decodeframe.c:4171-4175`, and its | ||
| 122 | + // writer's own `assert(..., "4:4:0 subsampling not allowed in AV1")` at | ||
| 123 | + // `av1/encoder/bitstream.c:2467-2468`), so (0,1) cannot reach this check -- | ||
| 124 | + // the reachable set is 4:2:0, 4:2:2 and 4:4:4, and only 4:2:2 lands here. | ||
| 125 | + // Gate: `the_440_cell_is_not_a_codable_chroma_shape`, which enumerates | ||
| 126 | + // the whole reachable set through this crate's own writer AND reader. | ||
| 127 | + "a chroma format of 4:2:2 (subsampling_x != subsampling_y): this decoder decodes 4:2:0 and 4:4:4; 4:2:2 is not ported, and 4:4:0 (0,1) is not a codable cell", | ||
| 120 | // lane-av1txr-r2 added, lane-av1-qmatrix RETIRED: the third member of the | 128 | // lane-av1txr-r2 added, lane-av1-qmatrix RETIRED: the third member of the |
| 121 | // silent-garbage family (`using_qmatrix`/`qm_y`/`qm_u`/`qm_v`, refused by | 129 | // silent-garbage family (`using_qmatrix`/`qm_y`/`qm_u`/`qm_v`, refused by |
| 122 | // name at the frame header) now DEQUANTISES through libaom's | 130 | // name at the frame header) now DEQUANTISES through libaom's |
| @@ -437,9 +445,11 @@ const PROVEN: &[(&str, &str)] = &[ | |||
| 437 | // lane-av1txr: the guard's own gate builds a profile-1 and a profile-2 | 445 | // lane-av1txr: the guard's own gate builds a profile-1 and a profile-2 |
| 438 | // sequence header by hand and asserts each refuses by name while the | 446 | // sequence header by hand and asserts each refuses by name while the |
| 439 | // profile-0 CONTROL still decodes -- the refusal is exercised, not merely | 447 | // profile-0 CONTROL still decodes -- the refusal is exercised, not merely |
| 440 | - // present. | 448 | + // present. lane-av1odd440 adds the second gate named here, which |
| 449 | + // enumerates every chroma shape a `color_config` can code and pins the | ||
| 450 | + // bytes a 4:4:0 request actually produces (`440_request_is_422.obu`). | ||
| 441 | ( | 451 | ( |
| 442 | - "a chroma format of 4:2:2 (subsampling_x != subsampling_y): this decoder decodes 4:2:0 and 4:4:4; 4:2:2 is not ported", | 452 | + "a chroma format of 4:2:2 (subsampling_x != subsampling_y): this decoder decodes 4:2:0 and 4:4:4; 4:2:2 is not ported, and 4:4:0 (0,1) is not a codable cell", |
| 443 | "a_non_420_subsampled_sequence_header_is_refused_by_name", | 453 | "a_non_420_subsampled_sequence_header_is_refused_by_name", |
| 444 | ), | 454 | ), |
| 445 | // lane-av1txr-r2 paired, lane-av1-qmatrix RETIRED with its gate: the | 455 | // lane-av1txr-r2 paired, lane-av1-qmatrix RETIRED with its gate: the |
| @@ -1866,10 +1876,12 @@ mod tests { | |||
| 1866 | .find("fn suppress_internal_lf_edges(") | 1876 | .find("fn suppress_internal_lf_edges(") |
| 1867 | .expect("suppress_internal_lf_edges is gone"); | 1877 | .expect("suppress_internal_lf_edges is gone"); |
| 1868 | let body_start = start + src[start..].find('{').expect("no body"); | 1878 | let body_start = start + src[start..].find('{').expect("no body"); |
| 1869 | - let body = &src[body_start..body_start + src[body_start..].find("\n }").expect("no end")]; | 1879 | + let body = |
| 1880 | + &src[body_start..body_start + src[body_start..].find("\n }").expect("no end")]; | ||
| 1870 | 1881 | ||
| 1871 | assert!( | 1882 | assert!( |
| 1872 | - body.contains("((w_mi * MI) >> ss_x(fctx))") && body.contains("((h_mi * MI) >> ss_y(fctx))"), | 1883 | + body.contains("((w_mi * MI) >> ss_x(fctx))") |
| 1884 | + && body.contains("((h_mi * MI) >> ss_y(fctx))"), | ||
| 1873 | "suppress_internal_lf_edges must publish the block's own chroma extent per axis \ | 1885 | "suppress_internal_lf_edges must publish the block's own chroma extent per axis \ |
| 1874 | -- `w_mi * MI >> ss_x(fctx)`, not a hardcoded `/2`" | 1886 | -- `w_mi * MI >> ss_x(fctx)`, not a hardcoded `/2`" |
| 1875 | ); | 1887 | ); |
crates/ec-av1/src/stream.rsmodified+396 -1
| @@ -1777,10 +1777,21 @@ fn decode_frame( | |||
| 1777 | // name` below (hand-built profile 1/2 headers plus a real aomenc 4:4:4 | 1777 | // name` below (hand-built profile 1/2 headers plus a real aomenc 4:4:4 |
| 1778 | // stream). | 1778 | // stream). |
| 1779 | // lane-av1-444: 4:4:4 (ss 0,0) is decoded. 4:2:2 (ss_x != ss_y) is not. | 1779 | // lane-av1-444: 4:4:4 (ss 0,0) is decoded. 4:2:2 (ss_x != ss_y) is not. |
| 1780 | + // lane-av1odd440: the CONDITION is left as `ss_x != ss_y` because that is | ||
| 1781 | + // what a parsed header can violate, but the STRING now names the only | ||
| 1782 | + // shape that can: `subsampling_y` is coded ONLY when `subsampling_x` is | ||
| 1783 | + // 1 (spec 5.5.2's `color_config`; libaom `av1_read_color_config`, | ||
| 1784 | + // `av1/decoder/decodeframe.c:4171-4175`, and its writer's own | ||
| 1785 | + // `assert(seq_params->subsampling_y == 0 && "4:4:0 subsampling not | ||
| 1786 | + // allowed in AV1")`, `av1/encoder/bitstream.c:2467-2468`), so a header can | ||
| 1787 | + // carry (1,1), (1,0) or (0,0) and never (0,1) -- 4:4:0 is not a cell a | ||
| 1788 | + // decoder can be handed at all. The gate | ||
| 1789 | + // `the_440_cell_is_not_a_codable_chroma_shape` proves the whole reachable | ||
| 1790 | + // set, so this string is not a claim about a shape that cannot arrive. | ||
| 1780 | if seq.subsampling_x != seq.subsampling_y { | 1791 | if seq.subsampling_x != seq.subsampling_y { |
| 1781 | return Err(Error::unsupported( | 1792 | return Err(Error::unsupported( |
| 1782 | "AV1 decode_stream", | 1793 | "AV1 decode_stream", |
| 1783 | - "a chroma format of 4:2:2 (subsampling_x != subsampling_y): this decoder decodes 4:2:0 and 4:4:4; 4:2:2 is not ported", | 1794 | + "a chroma format of 4:2:2 (subsampling_x != subsampling_y): this decoder decodes 4:2:0 and 4:4:4; 4:2:2 is not ported, and 4:4:0 (0,1) is not a codable cell", |
| 1784 | )); | 1795 | )); |
| 1785 | } | 1796 | } |
| 1786 | // lane-av1-qmatrix: `quantization_params.using_qmatrix` + `qm_y`/`qm_u`/ | 1797 | // lane-av1-qmatrix: `quantization_params.using_qmatrix` + `qm_y`/`qm_u`/ |
| @@ -2305,6 +2316,390 @@ pub(crate) mod tests { | |||
| 2305 | "{NAME}: the 4:2:0 control decoded no frame" | 2316 | "{NAME}: the 4:2:0 control decoded no frame" |
| 2306 | ); | 2317 | ); |
| 2307 | } | 2318 | } |
| 2319 | + | ||
| 2320 | + /// lane-av1odd440, CELL 1 of 2: `4:2:0 with an ODD luma dimension`, the | ||
| 2321 | + /// cell `lanes/av1formatsweep.report.md` left as declared debt because | ||
| 2322 | + /// "aomenc rounds a 4:2:0 frame's coded size DOWN to even, so no stream | ||
| 2323 | + /// this recipe can produce codes an odd luma dimension". | ||
| 2324 | + /// | ||
| 2325 | + /// The pin, `420_odd65x65_key.obu` (2305 bytes, | ||
| 2326 | + /// sha256 `66986019a561f81130f407f426c4379b25e6e80c2cd9ce47d517b3216e9a03cf`), | ||
| 2327 | + /// is that missing stream, built offline by | ||
| 2328 | + /// `examples/gen_coverage_cells.rs`: a 96x96 card padded to the block | ||
| 2329 | + /// grid, coded by `encode::encode_key_frame_at_size` with a 65x65 frame | ||
| 2330 | + /// header. Provenance: that example, `cargo run -p ec-av1 --example | ||
| 2331 | + /// gen_coverage_cells -- crates/ec-av1/fixtures`; no encoder, no ffmpeg, | ||
| 2332 | + /// no lavfi. | ||
| 2333 | + /// | ||
| 2334 | + /// WHY THE CELL IS NOT A RUBBER STAMP -- the chroma extent is where a | ||
| 2335 | + /// floor shows. A 65-wide 4:2:0 frame has | ||
| 2336 | + /// `ROUND_POWER_OF_TWO(65, 1) = 33` chroma columns (libaom | ||
| 2337 | + /// `av1_common_plane_width`, `av1/common/av1_common_int.h`), not 32, so | ||
| 2338 | + /// the decoded frame's own plane sizes, the rawvideo sample count and | ||
| 2339 | + /// the oracle compare all move if `decode::round_ss` is floored. The | ||
| 2340 | + /// mutation was run: flooring `round_ss` (`decode.rs:697`) turns the | ||
| 2341 | + /// `round_ss` assert below red at 32 chroma columns and the oracle arm | ||
| 2342 | + /// red at a 6273-byte raw against the oracle's 6403. The gate is | ||
| 2343 | + /// therefore not green on a floored decoder, which is the whole content | ||
| 2344 | + /// of this cell. | ||
| 2345 | + /// | ||
| 2346 | + /// The stream decodes PIXEL-EXACT against the instrumented `aomdec` | ||
| 2347 | + /// (6403 raw bytes = 65*65 + 2*33*33, byte-identical), so the cell is a | ||
| 2348 | + /// `y` and not a `–`. | ||
| 2349 | + #[test] | ||
| 2350 | + fn an_odd_luma_420_key_frame_decodes_pixel_exact() { | ||
| 2351 | + const NAME: &str = "an_odd_luma_420_key_frame_decodes_pixel_exact"; | ||
| 2352 | + let _gate_lock = lock_gate_counters(); | ||
| 2353 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 2354 | + .join("fixtures") | ||
| 2355 | + .join("420_odd65x65_key.obu"); | ||
| 2356 | + let stream = read_pin(&path, 2305, 0xf55645c4b139e8f7, NAME); | ||
| 2357 | + | ||
| 2358 | + // The stream's OWN header, read from its own bytes: an odd luma size | ||
| 2359 | + // at 4:2:0, which is the cell. (Taken from the pin, not from the | ||
| 2360 | + // gate's name -- class `helper-packs-u16-for-an-8-bit-stream`.) | ||
| 2361 | + let mut probe = Av1Parser::new(); | ||
| 2362 | + let mut pos = 0usize; | ||
| 2363 | + while pos < stream.len() && probe.sequence_header().is_none() { | ||
| 2364 | + let obu = probe | ||
| 2365 | + .parse_obu(&stream[pos..]) | ||
| 2366 | + .unwrap_or_else(|e| panic!("{NAME}: OBU at byte {pos} does not parse: {e:?}")); | ||
| 2367 | + pos += obu.total_size; | ||
| 2368 | + } | ||
| 2369 | + let seq = probe | ||
| 2370 | + .sequence_header() | ||
| 2371 | + .unwrap_or_else(|| panic!("{NAME}: the pin carries no sequence header")); | ||
| 2372 | + assert_eq!( | ||
| 2373 | + (seq.max_frame_width, seq.max_frame_height), | ||
| 2374 | + (65, 65), | ||
| 2375 | + "{NAME}: the pin must declare an ODD luma size, it declares {}x{}", | ||
| 2376 | + seq.max_frame_width, | ||
| 2377 | + seq.max_frame_height | ||
| 2378 | + ); | ||
| 2379 | + assert_eq!( | ||
| 2380 | + ( | ||
| 2381 | + seq.color_config.subsampling_x, | ||
| 2382 | + seq.color_config.subsampling_y | ||
| 2383 | + ), | ||
| 2384 | + (1, 1), | ||
| 2385 | + "{NAME}: this cell is an odd luma SIZE at 4:2:0, not another chroma shape" | ||
| 2386 | + ); | ||
| 2387 | + | ||
| 2388 | + // The decoded frame's own extents. This arm needs no oracle, and it | ||
| 2389 | + // is the one a floored `round_ss` turns red. | ||
| 2390 | + let frames = decode_stream(&stream).expect("the odd-luma 4:2:0 pin must decode"); | ||
| 2391 | + assert_eq!(frames.len(), 1, "{NAME}: frame count"); | ||
| 2392 | + let frame = &frames[0]; | ||
| 2393 | + assert_eq!( | ||
| 2394 | + (frame.width, frame.height), | ||
| 2395 | + (65, 65), | ||
| 2396 | + "{NAME}: decoded luma extent" | ||
| 2397 | + ); | ||
| 2398 | + assert_eq!(frame.y.len(), 65 * 65, "{NAME}: decoded luma sample count"); | ||
| 2399 | + assert_eq!( | ||
| 2400 | + (frame.u.len(), frame.v.len()), | ||
| 2401 | + (33 * 33, 33 * 33), | ||
| 2402 | + "{NAME}: a 65x65 4:2:0 frame has ROUND_POWER_OF_TWO(65,1) = 33 chroma \ | ||
| 2403 | + columns and rows -- 32 means the extent was floored" | ||
| 2404 | + ); | ||
| 2405 | + | ||
| 2406 | + if !aomdec_available(NAME) { | ||
| 2407 | + return; | ||
| 2408 | + } | ||
| 2409 | + assert_rawvideo_matches(&path, &stream, NAME, 1, 8); | ||
| 2410 | + } | ||
| 2411 | + | ||
| 2412 | + /// lane-av1odd440, CELL 2 of 2: the `4:4:0 (ss 0,1)` row, which the same | ||
| 2413 | + /// report called "unmeasured and unproducible by recipe". It is neither | ||
| 2414 | + /// unmeasured nor unproducible: it is NOT A CELL AT ALL. | ||
| 2415 | + /// | ||
| 2416 | + /// `subsampling_y` is coded only when `subsampling_x` is 1 (spec 5.5.2 | ||
| 2417 | + /// `color_config`), so a sequence header can carry exactly three chroma | ||
| 2418 | + /// shapes -- 4:2:0 `(1,1)`, 4:2:2 `(1,0)`, 4:4:4 `(0,0)` -- and never | ||
| 2419 | + /// `(0,1)`. libaom says so in both directions: the reader leaves | ||
| 2420 | + /// `subsampling_y = 0` when `subsampling_x` is 0 | ||
| 2421 | + /// (`av1_read_color_config`, `av1/decoder/decodeframe.c:4171-4175`) and | ||
| 2422 | + /// the writer ASSERTS it -- `assert(seq_params->subsampling_y == 0 && | ||
| 2423 | + /// "4:4:0 subsampling not allowed in AV1")`, `av1/encoder/bitstream.c: | ||
| 2424 | + /// 2463-2465`. So there is no stream to decode, no fixture to pin that | ||
| 2425 | + /// a decoder could be handed, and no oracle to compare against: a | ||
| 2426 | + /// 4:4:0 row in a coverage matrix is a matrix bug, not a decoder gap. | ||
| 2427 | + /// | ||
| 2428 | + /// What is pinned, then, is the claim itself, in three arms that a | ||
| 2429 | + /// mutation turns red: | ||
| 2430 | + /// | ||
| 2431 | + /// 1. WRITER: every `(profile, bit_depth, mono, colour description, | ||
| 2432 | + /// requested subsampling)` combination a `color_config` can carry is | ||
| 2433 | + /// written by this crate's own writer and read back by this crate's | ||
| 2434 | + /// own reader. The reachable set is asserted to be EXACTLY | ||
| 2435 | + /// `{(1,1), (1,0), (0,0)}` -- each legal shape present, `(0,1)` | ||
| 2436 | + /// absent -- and, on the BYTES rather than on the round trip, the two | ||
| 2437 | + /// requests that differ only in `subsampling_y` must write identical | ||
| 2438 | + /// headers whenever `subsampling_x` is 0. A sweep that silently wrote | ||
| 2439 | + /// nothing would pass, so the count of combinations actually written | ||
| 2440 | + /// and read is asserted too. | ||
| 2441 | + /// 2. READER: the one byte that carries `subsampling_x` is found by | ||
| 2442 | + /// diffing an `(0,0)` header against an `(1,0)` one, and then all 256 | ||
| 2443 | + /// values of that byte are fed back through the reader. Not one of the | ||
| 2444 | + /// headers that parse reads back `(0,1)`, because the reader never | ||
| 2445 | + /// reads a `subsampling_y` bit in that position. A reader that always | ||
| 2446 | + /// read a second bit would produce `(0,1)` at the one value that sets | ||
| 2447 | + /// both bits. | ||
| 2448 | + /// 3. THE PIN: `440_request_is_422.obu` (2014 bytes, sha256 | ||
| 2449 | + /// `4afaa5470c4e010d9d970086ef514680adfe801a579e4deeec582f52d13c5e7c`, | ||
| 2450 | + /// fnv1a64 `0x98a1378df976253d`) is what this crate's writer produces | ||
| 2451 | + /// when it is handed `subsampling (0,1)` at profile 2 -- profile 2 | ||
| 2452 | + /// below 12 bits is 4:2:2 and codes no subsampling bit at all, so the | ||
| 2453 | + /// request lands on `(1,0)`. The pin is asserted to read back `(1,0)`, | ||
| 2454 | + /// NOT `(0,1)`, and the decoder is asserted to refuse it by name, | ||
| 2455 | + /// which is the honest outcome for the shape a 4:4:0 request actually | ||
| 2456 | + /// yields. Its frame OBU is a 4:2:0 key frame's, so the pin is a HEADER | ||
| 2457 | + /// witness, not a decodable 4:2:2 stream -- nothing here claims | ||
| 2458 | + /// pixels for it. Provenance: `examples/gen_coverage_cells.rs`, `cargo | ||
| 2459 | + /// run -p ec-av1 --example gen_coverage_cells -- crates/ec-av1/fixtures`. | ||
| 2460 | + #[test] | ||
| 2461 | + fn the_440_cell_is_not_a_codable_chroma_shape() { | ||
| 2462 | + const NAME: &str = "the_440_cell_is_not_a_codable_chroma_shape"; | ||
| 2463 | + let _gate_lock = lock_gate_counters(); | ||
| 2464 | + let header_obu = |profile: u8, color: ec_av1_syntax::ColorConfig| -> Vec<u8> { | ||
| 2465 | + let (mut seq, _header) = crate::encode::key_frame_headers_colour(64, 64, 100, color) | ||
| 2466 | + .expect("the header builders accept a colour config"); | ||
| 2467 | + seq.seq_profile = profile; | ||
| 2468 | + crate::sequence::sequence_header_obu(&seq).expect("writing the sequence header") | ||
| 2469 | + }; | ||
| 2470 | + let shape_of = |obu: &[u8]| -> Option<(u8, u8)> { | ||
| 2471 | + let mut parser = Av1Parser::new(); | ||
| 2472 | + let parsed = parser.parse_obu(obu).ok()?; | ||
| 2473 | + if !matches!(parsed.kind, ec_av1_syntax::ObuKind::SequenceHeader(_)) { | ||
| 2474 | + return None; | ||
| 2475 | + } | ||
| 2476 | + let seq = parser.sequence_header()?; | ||
| 2477 | + Some(( | ||
| 2478 | + seq.color_config.subsampling_x, | ||
| 2479 | + seq.color_config.subsampling_y, | ||
| 2480 | + )) | ||
| 2481 | + }; | ||
| 2482 | + | ||
| 2483 | + // ---- arm 1: the writer's whole reachable space -------------------- | ||
| 2484 | + let mut reachable: std::collections::BTreeSet<(u8, u8)> = Default::default(); | ||
| 2485 | + let mut asked = 0usize; | ||
| 2486 | + for profile in [0u8, 1, 2] { | ||
| 2487 | + for bit_depth in [8u8, 10, 12] { | ||
| 2488 | + for mono_chrome in [false, true] { | ||
| 2489 | + // Profile 1 is 4:4:4 and codes no mono bit; asking for | ||
| 2490 | + // monochrome there is refused by the writer, which is | ||
| 2491 | + // not a chroma shape and not this gate's subject. | ||
| 2492 | + if mono_chrome && profile == 1 { | ||
| 2493 | + continue; | ||
| 2494 | + } | ||
| 2495 | + for (label, (cp, tc, mc)) in [ | ||
| 2496 | + ("unspecified", (2u8, 2u8, 2u8)), | ||
| 2497 | + ("bt709", (1u8, 1u8, 1u8)), | ||
| 2498 | + ("srgb", (1u8, 13u8, 0u8)), | ||
| 2499 | + ] { | ||
| 2500 | + for sx in [0u8, 1] { | ||
| 2501 | + for sy in [0u8, 1] { | ||
| 2502 | + let color = ec_av1_syntax::ColorConfig { | ||
| 2503 | + bit_depth, | ||
| 2504 | + mono_chrome, | ||
| 2505 | + num_planes: if mono_chrome { 1 } else { 3 }, | ||
| 2506 | + color_primaries: cp, | ||
| 2507 | + transfer_characteristics: tc, | ||
| 2508 | + matrix_coefficients: mc, | ||
| 2509 | + color_range: false, | ||
| 2510 | + subsampling_x: sx, | ||
| 2511 | + subsampling_y: sy, | ||
| 2512 | + chroma_sample_position: | ||
| 2513 | + ec_av1_syntax::ChromaSamplePosition::Unknown, | ||
| 2514 | + separate_uv_delta_q: false, | ||
| 2515 | + }; | ||
| 2516 | + asked += 1; | ||
| 2517 | + let obu = header_obu(profile, color); | ||
| 2518 | + // The WRITER half of the claim, measured on the | ||
| 2519 | + // bytes rather than on a round trip: with | ||
| 2520 | + // `subsampling_x == 0` the spec codes no | ||
| 2521 | + // `subsampling_y` bit at all, so the two | ||
| 2522 | + // requests that differ ONLY in `subsampling_y` | ||
| 2523 | + // must produce byte-identical headers. A | ||
| 2524 | + // writer that emitted the bit anyway (the | ||
| 2525 | + // mutation libaom's own `assert` exists to | ||
| 2526 | + // catch, av1/encoder/bitstream.c:2467-2468) fails | ||
| 2527 | + // here -- and note it does NOT fail the | ||
| 2528 | + // round trip, because the reader then absorbs | ||
| 2529 | + // the extra bit as `separate_uv_delta_q`. | ||
| 2530 | + if sx == 0 { | ||
| 2531 | + let mut other = color; | ||
| 2532 | + other.subsampling_y = 1; | ||
| 2533 | + assert_eq!( | ||
| 2534 | + obu, | ||
| 2535 | + header_obu(profile, other), | ||
| 2536 | + "{NAME}: a (0,0) and a (0,1) request wrote DIFFERENT \ | ||
| 2537 | + bytes at profile {profile}, {bit_depth}-bit, mono \ | ||
| 2538 | + {mono_chrome}, {label} -- `subsampling_y` must not be \ | ||
| 2539 | + coded at all when `subsampling_x` is 0" | ||
| 2540 | + ); | ||
| 2541 | + } | ||
| 2542 | + if let Some(got) = shape_of(&obu) { | ||
| 2543 | + assert_ne!( | ||
| 2544 | + got, | ||
| 2545 | + (0, 1), | ||
| 2546 | + "{NAME}: a 4:4:0 shape came back out of the writer at \ | ||
| 2547 | + profile {profile}, {bit_depth}-bit, mono {mono_chrome}, \ | ||
| 2548 | + {label}, asked for ({sx},{sy}) -- libaom forbids this \ | ||
| 2549 | + shape outright (av1/encoder/bitstream.c:2467-2468)" | ||
| 2550 | + ); | ||
| 2551 | + reachable.insert(got); | ||
| 2552 | + } | ||
| 2553 | + } | ||
| 2554 | + } | ||
| 2555 | + } | ||
| 2556 | + } | ||
| 2557 | + } | ||
| 2558 | + } | ||
| 2559 | + assert!( | ||
| 2560 | + asked >= 100 && reachable.len() == 3, | ||
| 2561 | + "{NAME}: the sweep asked {asked} combinations and reached {} shapes -- it must reach \ | ||
| 2562 | + all three legal ones, or it is not measuring the space", | ||
| 2563 | + reachable.len() | ||
| 2564 | + ); | ||
| 2565 | + assert_eq!( | ||
| 2566 | + reachable, | ||
| 2567 | + std::collections::BTreeSet::from([(0u8, 0u8), (1u8, 0u8), (1u8, 1u8)]), | ||
| 2568 | + "{NAME}: the chroma shapes a `color_config` can code are exactly 4:4:4 (0,0), 4:2:2 \ | ||
| 2569 | + (1,0) and 4:2:0 (1,1)" | ||
| 2570 | + ); | ||
| 2571 | + | ||
| 2572 | + // ---- arm 2: the reader's bit at that position ---------------------- | ||
| 2573 | + // Profile 2 at 12 bits is the only place BOTH subsampling bits are | ||
| 2574 | + // coded, so it is where a hand-built header could try to smuggle a | ||
| 2575 | + // `subsampling_y`. Find the byte that carries `subsampling_x` by | ||
| 2576 | + // diffing the two shapes, then read back all eight of its values. | ||
| 2577 | + let at_444 = |sx: u8| { | ||
| 2578 | + let color = ec_av1_syntax::ColorConfig { | ||
| 2579 | + bit_depth: 12, | ||
| 2580 | + subsampling_x: sx, | ||
| 2581 | + subsampling_y: 0, | ||
| 2582 | + chroma_sample_position: ec_av1_syntax::ChromaSamplePosition::Unknown, | ||
| 2583 | + ..ec_av1_syntax::ColorConfig::default() | ||
| 2584 | + }; | ||
| 2585 | + let (mut seq, _h) = | ||
| 2586 | + crate::encode::key_frame_headers_colour(64, 64, 100, color).unwrap(); | ||
| 2587 | + seq.seq_profile = 2; | ||
| 2588 | + let obu = crate::sequence::sequence_header_obu(&seq).unwrap(); | ||
| 2589 | + let mut parser = Av1Parser::new(); | ||
| 2590 | + parser.parse_obu(&obu).expect("the profile-2 header parses"); | ||
| 2591 | + let seq = parser.sequence_header().expect("sequence header"); | ||
| 2592 | + ( | ||
| 2593 | + seq.color_config.subsampling_x, | ||
| 2594 | + seq.color_config.subsampling_y, | ||
| 2595 | + ) | ||
| 2596 | + }; | ||
| 2597 | + assert_eq!(at_444(0), (0, 0), "{NAME}: the sx=0 header is 4:4:4"); | ||
| 2598 | + assert_eq!(at_444(1), (1, 0), "{NAME}: the sx=1 header is 4:2:2"); | ||
| 2599 | + let base = { | ||
| 2600 | + let color = ec_av1_syntax::ColorConfig { | ||
| 2601 | + bit_depth: 12, | ||
| 2602 | + subsampling_x: 0, | ||
| 2603 | + subsampling_y: 0, | ||
| 2604 | + chroma_sample_position: ec_av1_syntax::ChromaSamplePosition::Unknown, | ||
| 2605 | + ..ec_av1_syntax::ColorConfig::default() | ||
| 2606 | + }; | ||
| 2607 | + let (mut seq, _h) = | ||
| 2608 | + crate::encode::key_frame_headers_colour(64, 64, 100, color).unwrap(); | ||
| 2609 | + seq.seq_profile = 2; | ||
| 2610 | + crate::sequence::sequence_header_obu(&seq).unwrap() | ||
| 2611 | + }; | ||
| 2612 | + let other = { | ||
| 2613 | + let color = ec_av1_syntax::ColorConfig { | ||
| 2614 | + bit_depth: 12, | ||
| 2615 | + subsampling_x: 1, | ||
| 2616 | + subsampling_y: 0, | ||
| 2617 | + chroma_sample_position: ec_av1_syntax::ChromaSamplePosition::Unknown, | ||
| 2618 | + ..ec_av1_syntax::ColorConfig::default() | ||
| 2619 | + }; | ||
| 2620 | + let (mut seq, _h) = | ||
| 2621 | + crate::encode::key_frame_headers_colour(64, 64, 100, color).unwrap(); | ||
| 2622 | + seq.seq_profile = 2; | ||
| 2623 | + crate::sequence::sequence_header_obu(&seq).unwrap() | ||
| 2624 | + }; | ||
| 2625 | + assert_eq!( | ||
| 2626 | + base.len(), | ||
| 2627 | + other.len(), | ||
| 2628 | + "{NAME}: the two headers must differ in place" | ||
| 2629 | + ); | ||
| 2630 | + let byte_at = base | ||
| 2631 | + .iter() | ||
| 2632 | + .zip(&other) | ||
| 2633 | + .position(|(a, b)| a != b) | ||
| 2634 | + .expect("the two shapes must differ somewhere"); | ||
| 2635 | + // Every value of that byte is fed back through the reader -- it is the | ||
| 2636 | + // LAST payload byte, so the bits a smuggled `subsampling_y` would come | ||
| 2637 | + // from are in it too (spec 5.5.2 always codes `separate_uv_delta_q` | ||
| 2638 | + // after the subsampling pair, and the payload is padded out to the | ||
| 2639 | + // byte with `trailing_bits`). A header that stops parsing is not a | ||
| 2640 | + // 4:4:0 shape and cannot be counted as one; the sweep asserts how | ||
| 2641 | + // many DID parse, so a sweep that quietly parsed nothing is not | ||
| 2642 | + // evidence of anything. | ||
| 2643 | + let mut parsed_headers = 0usize; | ||
| 2644 | + for value in 0..256u16 { | ||
| 2645 | + let mut poked = base.clone(); | ||
| 2646 | + poked[byte_at] = value as u8; | ||
| 2647 | + let mut parser = Av1Parser::new(); | ||
| 2648 | + let Ok(parsed) = parser.parse_obu(&poked) else { | ||
| 2649 | + continue; | ||
| 2650 | + }; | ||
| 2651 | + if !matches!(parsed.kind, ec_av1_syntax::ObuKind::SequenceHeader(_)) { | ||
| 2652 | + continue; | ||
| 2653 | + } | ||
| 2654 | + let seq = parser.sequence_header().expect("sequence header"); | ||
| 2655 | + parsed_headers += 1; | ||
| 2656 | + assert_ne!( | ||
| 2657 | + ( | ||
| 2658 | + seq.color_config.subsampling_x, | ||
| 2659 | + seq.color_config.subsampling_y | ||
| 2660 | + ), | ||
| 2661 | + (0, 1), | ||
| 2662 | + "{NAME}: payload byte {byte_at} = {value:#04x} read back as 4:4:0 -- the reader \ | ||
| 2663 | + took a `subsampling_y` bit that spec 5.5.2 does not code when `subsampling_x` \ | ||
| 2664 | + is 0" | ||
| 2665 | + ); | ||
| 2666 | + } | ||
| 2667 | + assert!( | ||
| 2668 | + parsed_headers > 100, | ||
| 2669 | + "{NAME}: only {parsed_headers} of the 256 poked headers parsed -- the sweep is not \ | ||
| 2670 | + measuring the reader" | ||
| 2671 | + ); | ||
| 2672 | + | ||
| 2673 | + // ---- arm 3: the pinned bytes a 4:4:0 request produces -------------- | ||
| 2674 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 2675 | + .join("fixtures") | ||
| 2676 | + .join("440_request_is_422.obu"); | ||
| 2677 | + let pinned = read_pin(&path, 2014, 0x98a1378df976253d, NAME); | ||
| 2678 | + let mut parser = Av1Parser::new(); | ||
| 2679 | + let obu = parser | ||
| 2680 | + .parse_obu(&pinned) | ||
| 2681 | + .unwrap_or_else(|e| panic!("{NAME}: the pin's first OBU does not parse: {e:?}")); | ||
| 2682 | + assert!( | ||
| 2683 | + matches!(obu.kind, ec_av1_syntax::ObuKind::SequenceHeader(_)), | ||
| 2684 | + "{NAME}: the pin must start with its sequence header" | ||
| 2685 | + ); | ||
| 2686 | + let seq = parser.sequence_header().expect("the pin's sequence header"); | ||
| 2687 | + assert_eq!( | ||
| 2688 | + ( | ||
| 2689 | + seq.color_config.subsampling_x, | ||
| 2690 | + seq.color_config.subsampling_y | ||
| 2691 | + ), | ||
| 2692 | + (1, 0), | ||
| 2693 | + "{NAME}: the pin is what a 4:4:0 request at profile 2 produces -- 4:2:2 (1,0). If this \ | ||
| 2694 | + ever reads (0,1), a 4:4:0 cell became codable and this whole gate is wrong about the \ | ||
| 2695 | + format." | ||
| 2696 | + ); | ||
| 2697 | + let err = decode_stream(&pinned).unwrap_err().to_string(); | ||
| 2698 | + assert!( | ||
| 2699 | + err.contains("a chroma format of 4:2:2"), | ||
| 2700 | + "{NAME}: the shape the 4:4:0 request lands on must still refuse by name, got: {err}" | ||
| 2701 | + ); | ||
| 2702 | + } | ||
| 2308 | /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned | 2703 | /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned |
| 2309 | /// as fixtures (`git add -f`; `fixtures/` is gitignored). | 2704 | /// as fixtures (`git add -f`; `fixtures/` is gitignored). |
| 2310 | /// | 2705 | /// |
lanes/av1odd440.report.mdadded+160 -0
| @@ -0,0 +1,160 @@ | |||
| 1 | +# lane-av1odd440 — the two unreachable cells, one closed and one dissolved | ||
| 2 | + | ||
| 3 | +Branch `lane-av1odd440`, base `70ed5601` (main). Target dir | ||
| 4 | +`$HOME/.cache/tgt/av1odd440`. No push. | ||
| 5 | + | ||
| 6 | +## Verdict, in four lines | ||
| 7 | + | ||
| 8 | +1. **`4:2:0` with an ODD luma dimension: DECODED, pixel-exact, now gated.** The | ||
| 9 | + stream aomenc cannot make exists, decodes byte-identical to `aomdec` | ||
| 10 | + (6403 raw bytes, 65x65 + 2x33x33), and the gate bites: flooring | ||
| 11 | + `decode::round_ss` turns it red. | ||
| 12 | +2. **The `4:4:0 (ss 0,1)` row is not a decoder gap — it is not a cell.** AV1 | ||
| 13 | + codes `subsampling_y` only when `subsampling_x` is 1, so the reachable set | ||
| 14 | + is exactly `{(1,1), (1,0), (0,0)}` and `(0,1)` is uncodable. libaom's own | ||
| 15 | + writer asserts it in a string: `"4:4:0 subsampling not allowed in AV1"`. | ||
| 16 | +3. The odd-luma fixture exposed a **real decoder defect** the tree had | ||
| 17 | + documented as an open gap and deferred: `ref_chroma_shape`'s 4:2:0 arm was a | ||
| 18 | + floor. It is now the producer's own `round_ss` crop, red-before proven. | ||
| 19 | +4. The decoder **still refuses 4:2:2 by name**; the refusal string now says | ||
| 20 | + why 4:4:0 cannot arrive either, and the inventory's two copies of it are | ||
| 21 | + updated with the same text. | ||
| 22 | + | ||
| 23 | +## The two cells | ||
| 24 | + | ||
| 25 | +### Cell 1 — `420_odd65x65_key.obu` (4:2:0, odd luma): `y` | ||
| 26 | + | ||
| 27 | +| | | | ||
| 28 | +|---|---| | ||
| 29 | +| bytes | 2305 | | ||
| 30 | +| sha256 | `66986019a561f81130f407f426c4379b25e6e80c2cd9ce47d517b3216e9a03cf` | | ||
| 31 | +| fnv1a64 | `0xf55645c4b139e8f7` | | ||
| 32 | +| header | `seq_profile 0`, `max_frame 65x65`, `subsampling (1,1)`, 8-bit | | ||
| 33 | +| ours vs `aomdec` | **6403 == 6403 bytes, identical** (65*65 + 2*33*33) | | ||
| 34 | + | ||
| 35 | +Reproduce (no encoder, no ffmpeg, no lavfi — the whole point of the cell): | ||
| 36 | + | ||
| 37 | +``` | ||
| 38 | +cargo run -p ec-av1 --example gen_coverage_cells -- crates/ec-av1/fixtures | ||
| 39 | +sha256sum crates/ec-av1/fixtures/420_odd65x65_key.obu | ||
| 40 | +``` | ||
| 41 | + | ||
| 42 | +`aomenc` cannot produce this stream: it rounds the coded size DOWN to even | ||
| 43 | +(the formatsweep lane measured `testsrc2 131x131` y4m coming out as | ||
| 44 | +`max_frame=130x130`), so the encoder had to be told what size to DECLARE. | ||
| 45 | +`encode::encode_key_frame_at_size` is that entry, and the fixture is a 96x96 | ||
| 46 | +card padded to the block grid with a 65x65 frame header. | ||
| 47 | + | ||
| 48 | +**Why the gate is not a rubber stamp.** The cell's whole content is the chroma | ||
| 49 | +extent: a 65-wide 4:2:0 frame has `ROUND_POWER_OF_TWO(65, 1) = 33` chroma | ||
| 50 | +columns (libaom `av1_common_plane_width`, `av1/common/av1_common_int.h`), not | ||
| 51 | +32. Measured mutations: | ||
| 52 | + | ||
| 53 | +| mutation | result | | ||
| 54 | +|---|---| | ||
| 55 | +| `round_ss` floored (`dim >> ss`, decode.rs:697) | gate RED: `left (1024, 1024) right (1089, 1089)` (32x32 chroma); the raw dump is 6273 bytes against the oracle's 6403 | | ||
| 56 | + | ||
| 57 | +**Defect it exposed, fixed here.** `decode::ref_chroma_shape`'s 4:2:0 | ||
| 58 | +fallback arm was `(width / 2, height / 2)` — a floor. The producer stores | ||
| 59 | +`round_ss(w,1) x round_ss(h,1)`, so every odd-dimension 4:2:0 REFERENCE was | ||
| 60 | +under-declared (12160 of 16384 `(w,h)` pairs over `1..=128`, per the | ||
| 61 | +function's own doc comment, which deferred the fix to "a lane that can bring | ||
| 62 | +odd-dimension 4:2:0 fixtures with it"). The arm is now the producer's crop. | ||
| 63 | +Red-before, measured: with the floor back, the existing routing test | ||
| 64 | +`a_reference_chroma_sample_count_routes_back_to_its_own_format` fails at | ||
| 65 | +`4:2:0 reference of 2x3 ... left (1, 1), right (1, 2)`. Even sizes are | ||
| 66 | +untouched — `(2k+1)/2 == k` — so no existing 4:2:0/4:2:2/4:4:4 reference | ||
| 67 | +changes shape. | ||
| 68 | + | ||
| 69 | +### Cell 2 — `440_request_is_422.obu` (4:4:0): the cell does not exist | ||
| 70 | + | ||
| 71 | +| | | | ||
| 72 | +|---|---| | ||
| 73 | +| bytes | 2014 | | ||
| 74 | +| sha256 | `4afaa5470c4e010d9d970086ef514680adfe801a579e4deeec582f52d13c5e7c` | | ||
| 75 | +| fnv1a64 | `0x98a1378df976253d` | | ||
| 76 | +| what it is | a 4:4:0 REQUEST at profile 2, which lands on `(1,0)` = 4:2:2 | | ||
| 77 | +| decoder | refuses by name (the 4:2:2 refusal) | | ||
| 78 | + | ||
| 79 | +Reproduce: same `cargo run` as cell 1. | ||
| 80 | + | ||
| 81 | +Spec 5.5.2 `color_config` codes `subsampling_y` ONLY when `subsampling_x` is | ||
| 82 | +1. The two places libaom says so: | ||
| 83 | + | ||
| 84 | +- reader — `av1/decoder/decodeframe.c:4171-4175`: | ||
| 85 | + `subsampling_x = aom_rb_read_bit(rb); if (subsampling_x) subsampling_y = aom_rb_read_bit(rb); else subsampling_y = 0; // 444` | ||
| 86 | +- writer — `av1/encoder/bitstream.c:2466-2468`: | ||
| 87 | + `assert(seq_params->subsampling_y == 0 && "4:4:0 subsampling not allowed in AV1");` | ||
| 88 | + | ||
| 89 | +So the coverage-matrix row was a MATRIX bug, not a decoder gap: aomenc has no | ||
| 90 | +`yuv440p` input path and ffmpeg's y4m muxer refuses the format, but those are | ||
| 91 | +consequences — no bit pattern anywhere produces `(0,1)`. There is no stream to | ||
| 92 | +decode, no fixture a decoder could be handed, and no oracle to compare | ||
| 93 | +against. The pin therefore carries the byte-level evidence instead: hand the | ||
| 94 | +writer `(0,1)` and it emits a header that reads back `(1,0)`. | ||
| 95 | + | ||
| 96 | +The gate `the_440_cell_is_not_a_codable_chroma_shape` proves the claim in | ||
| 97 | +three arms, and every arm has a measured mutation: | ||
| 98 | + | ||
| 99 | +| arm | what it measures | mutation | result | | ||
| 100 | +|---|---|---|---| | ||
| 101 | +| 1 WRITER | every `(profile, bit_depth, mono, colour description, requested shape)` combination a `color_config` can carry -- 180 of them, the profile-1-monochrome request skipped because the writer refuses it -- written and read back; the reachable set must be exactly `{(1,1),(1,0),(0,0)}`; and with `subsampling_x == 0` a `(0,0)` and a `(0,1)` request must write BYTE-IDENTICAL headers | writer emits the `subsampling_y` bit anyway | RED: `(0,0)`/`(0,1)` requests differ, `[..., 158, 2]` vs `[..., 158, 18]` at profile 2, 12-bit | | ||
| 102 | +| 2 READER | the byte carrying `subsampling_x` is located by diffing an `(0,0)` against an `(1,0)` header, then all 256 values of it are read back | reader always reads a `subsampling_y` bit | RED: `payload byte 11 = 0x10 read back as 4:4:0` | | ||
| 103 | +| 3 PIN | the pinned bytes read back `(1,0)`, not `(0,1)`, and still refuse by name | — (byte pin) | green | | ||
| 104 | + | ||
| 105 | +Measured and recorded because it is the non-obvious half: mutating the | ||
| 106 | +**writer** alone does NOT put `(0,1)` into a round trip — the correct reader | ||
| 107 | +absorbs the extra bit as `separate_uv_delta_q`. The round-trip set is a | ||
| 108 | +property of the writer/reader PAIR; the byte-identity arm is what pins the | ||
| 109 | +writer's own half, and the reader arm is what pins the half a foreign stream | ||
| 110 | +meets. Both mutations were run. | ||
| 111 | + | ||
| 112 | +## Files | ||
| 113 | + | ||
| 114 | +| file | change | | ||
| 115 | +|---|---| | ||
| 116 | +| `crates/ec-av1/examples/gen_coverage_cells.rs` | NEW — the generator, both cells | | ||
| 117 | +| `crates/ec-av1/src/encode.rs` | NEW `encode_key_frame_at_size`; `crop_encoded` chroma extent is `div_ceil(2)`; `key_frame_headers_colour` made public | | ||
| 118 | +| `crates/ec-av1/src/decode.rs` | `ref_chroma_shape` 4:2:0 arm floor -> `round_ss` crop; its routing test's expectation moved with it | | ||
| 119 | +| `crates/ec-av1/src/stream.rs` | two new gates; the 4:2:2/4:4:0 refusal string | | ||
| 120 | +| `crates/ec-av1/src/refusal_inventory.rs` | both copies of that string + the gate pairing | | ||
| 121 | +| `crates/ec-av1-syntax/src/sequence.rs` | UNCHANGED (mutated and reverted only) | | ||
| 122 | +| `crates/ec-av1/fixtures/420_odd65x65_key.obu`, `.../440_request_is_422.obu` | NEW pins (`git add -f`; `fixtures/` is gitignored) | | ||
| 123 | + | ||
| 124 | +## Gates | ||
| 125 | + | ||
| 126 | +- `an_odd_luma_420_key_frame_decodes_pixel_exact` — pin, header read from the | ||
| 127 | + pin's own bytes, decoded extents (65x65 luma, 33x33 chroma), then | ||
| 128 | + `assert_rawvideo_matches` against the instrumented `aomdec` (skips loudly | ||
| 129 | + without an oracle; hard-fails under `EC_AV1_REQUIRE_AOMDEC`). | ||
| 130 | +- `the_440_cell_is_not_a_codable_chroma_shape` — the three arms above. | ||
| 131 | +- `a_reference_chroma_sample_count_routes_back_to_its_own_format` — existing, | ||
| 132 | + its 4:2:0 expectation moved from the floor to the producer's crop. | ||
| 133 | + | ||
| 134 | +## not_done | ||
| 135 | + | ||
| 136 | +1. **No end-to-end odd-size INTER frame.** `ref_chroma_shape` is the | ||
| 137 | + reference path, and this fixture is a single key frame because that is all | ||
| 138 | + the ticket asked for and all the encoder's public entry points allow | ||
| 139 | + (`encode_sequence` derives the declared size from the source picture and | ||
| 140 | + `check_even`s it). The fix is red-before proven at the routing level and | ||
| 141 | + the pin is red-before proven at the decode level, but no odd-size inter | ||
| 142 | + stream decodes pixel-exact end to end, because producing one needs a sized | ||
| 143 | + sequence entry (`encode_key_frame_at_size`'s inter sibling) that this lane | ||
| 144 | + did not add. Whoever wants the inter arm should add that entry; the gate | ||
| 145 | + then only needs a second pin. | ||
| 146 | +2. **The `ref_chroma_shape` `w == 1` column was measured, not witnessed.** The | ||
| 147 | + ceil arm expresses `(1, round_ss(h,1))`, which the floor could not, so the | ||
| 148 | + documented 127-pair residue is closed by construction; no stream this | ||
| 149 | + decoder accepts has a 1-pixel-wide frame to test it on. | ||
| 150 | +3. **The 4:2:2 refusal is unchanged and still has no committed pixel witness** | ||
| 151 | + (every committed 4:2:2 pin asserts refusal, not pixels; the decode | ||
| 152 | + evidence needs the `EC_AV1_ALLOW_422_PROBE` patch-run-restore build, per | ||
| 153 | + `lanes/av1422bigblock.report.md`). This lane did not touch that. | ||
| 154 | +4. **The 4:4:0 coverage-matrix row itself lives in | ||
| 155 | + `lanes/av1formatsweep.report.md`**, a historical report this lane does not | ||
| 156 | + edit. The correction is recorded here and in the refusal string; whoever | ||
| 157 | + maintains the matrix should delete the row rather than mark it `–`. | ||
| 158 | +5. **No 12-bit or multi-frame odd-size variant.** One 8-bit key frame is the | ||
| 159 | + cell; a 65x65 stream at 10/12 bits would need the encoder widened first | ||
| 160 | + (it is 8-bit by design, `encode.rs`'s r2 decision). | ||