diff --git a/crates/ec-av1/examples/gen_coverage_cells.rs b/crates/ec-av1/examples/gen_coverage_cells.rs
new file mode 100644
index 00000000..60af552e
--- /dev/null
+++ b/crates/ec-av1/examples/gen_coverage_cells.rs
@@ -0,0 +1,315 @@
+//! Generator for the two AV1 coverage cells no encoder emits, so both are
+//! GATED rather than left as declared debt (`lanes/av1formatsweep.report.md`
+//! §6.4 and its "declared debt" note: the `4:2:0 with an odd luma dimension`
+//! and `4:4:0 (ss 0,1)` rows were "unmeasured and unproducible by recipe").
+//!
+//! Both cells are produced here, offline, with no encoder and no ffmpeg:
+//!
+//! 1. **`420_odd65x65_key.obu`** -- a 4:2:0 key frame whose header declares
+//! an ODD luma size (65x65). aomenc cannot produce this one: it rounds the
+//! coded size DOWN to even (`av1enc_set_frame_size`; the measured
+//! `testsrc2 131x131` y4m comes out as `max_frame=130x130`), so the cell
+//! needs the encoder to be told what size to DECLARE. That is
+//! [`ec_av1::encode::encode_key_frame_at_size`]: a 96x96 picture padded to
+//! the block grid, coded with a 65x65 frame header. The result is a real,
+//! fully decodable AV1 stream -- the gate compares it sample for sample
+//! against the instrumented `aomdec`.
+//!
+//! 2. **`440_request_is_422.obu`** -- what this crate's writer produces when
+//! it is HANDED 4:4:0 (`subsampling_x = 0`, `subsampling_y = 1`). The
+//! cell turns out not to exist: `subsampling_y` is coded only when
+//! `subsampling_x` is 1 (spec 5.5.2 `color_config`), so a sequence header
+//! carries 4:2:0 `(1,1)`, 4:2:2 `(1,0)` or 4:4:4 `(0,0)` and never
+//! `(0,1)` -- libaom's own writer ASSERTS it ("4:4:0 subsampling not
+//! allowed in AV1", `av1/encoder/bitstream.c:2467-2468`) and its reader
+//! forces
+//! `subsampling_y = 0` when `subsampling_x` is 0
+//! (`av1_read_color_config`, `av1/decoder/decodeframe.c:4171-4175`).
+//! aomenc having no `yuv440p` input path and ffmpeg's y4m muxer refusing
+//! the format ("yuv4mpeg can only handle yuv444p, yuv422p, yuv420p,
+//! yuv411p and gray8") are consequences of that, not the reason. The pin
+//! is the byte-level evidence: a 4:4:0 request at profile 2 (4:2:2, and
+//! no coded subsampling bit below 12 bits) lands on `(1,0)`, the shape
+//! this decoder refuses by name. The frame OBU behind it is a real 4:2:0
+//! key frame's, byte for byte -- the subsampling lives only in the
+//! sequence header -- so the pin is a HEADER witness, not a decodable
+//! 4:2:2 stream, and the gate
+//! `the_440_cell_is_not_a_codable_chroma_shape` says exactly that.
+//!
+//! ```text
+//! cargo run -p ec-av1 --example gen_coverage_cells -- crates/ec-av1/fixtures
+//! sha256sum crates/ec-av1/fixtures/420_odd65x65_key.obu \
+//! crates/ec-av1/fixtures/440_request_is_422.obu
+//! ```
+//!
+//! Both files are deterministic: the source card is a fixed integer pattern
+//! and the encoder is deterministic, so re-running this overwrites the pins
+//! with the same bytes. `ec-av1` is a hand-code-only repository -- do NOT run
+//! `cargo fmt` on this file; rustfmt runs at commit time and its churn is
+//! accepted, never reverted.
+
+use ec_av1::encode::Picture;
+use ec_av1_syntax::{ColorConfig, ObuKind};
+
+/// The padded coding surface the odd cell is cut from: a whole number of
+/// 32x32 blocks (`Picture::check`'s own rule), and a multiple of 8 above the
+/// 65x65 it declares, so no declared column is already block-aligned.
+const PAD: usize = 96;
+
+/// The odd-luma cell's DECLARED frame size. Both dimensions odd on purpose:
+/// the 4:2:0 chroma extent is then `ROUND_POWER_OF_TWO(65, 1) = 33` in each
+/// axis (libaom `av1_common_plane_width`, `av1/common/av1_common_int.h`),
+/// which is where a floor (32) and a ceil (33) disagree -- the whole reason
+/// the cell was worth closing.
+const ODD: usize = 65;
+
+/// The 4:4:0 witness's frame size, and the quantizer both streams are coded
+/// at. Even, so nothing else about the witness is unusual: the shape is 4:4:0
+/// and nothing else.
+const WITNESS: usize = 64;
+
+/// `base_q_idx` for both cells. Mid-scale on purpose: high enough that a
+/// block carries real coefficients (so a wrong chroma extent shows in the
+/// output), low enough that the stream stays small.
+const Q_IDX: u8 = 100;
+
+/// A deterministic, high-frequency card: a 2-D pattern whose wrapped
+/// diagonal jumps, so every 8x8 block has real high-frequency content and
+/// therefore real coefficients. That matters for the odd cell -- a flat or
+/// smooth card predicts to within a quantizer step of a constant in its last
+/// column too, so a wrong chroma extent could leave the OUTPUT unchanged and
+/// the gate would then be green on broken code.
+fn card(width: usize, height: usize) -> Picture {
+ let mut picture = Picture::grey(width, height);
+ for row in 0..height {
+ for col in 0..width {
+ picture.y[row * width + col] = ((row * 7 + col * 11) % 251) as u16;
+ }
+ }
+ for row in 0..height / 2 {
+ for col in 0..width / 2 {
+ let i = row * (width / 2) + col;
+ picture.u[i] = ((row * 13 + col * 29) % 241) as u16;
+ picture.v[i] = ((row * 17 + col * 5) % 239) as u16;
+ }
+ }
+ picture
+}
+
+/// The chroma shape of the 4:4:0 witness: profile 0 with `subsampling_x = 0`
+/// and `subsampling_y = 1`. Profile 0 forces neither subsampling bit (only
+/// profile 1 forces 4:4:4 and profile 2 below 12 bits forces 4:2:2, spec
+/// 5.5.2), so both are coded in the header and `(0, 1)` -- 4:4:0 -- is legal
+/// there.
+fn yuv440() -> ColorConfig {
+ ColorConfig {
+ bit_depth: 8,
+ mono_chrome: false,
+ num_planes: 3,
+ color_primaries: 2,
+ transfer_characteristics: 2,
+ matrix_coefficients: 2,
+ color_range: false,
+ subsampling_x: 0,
+ subsampling_y: 1,
+ chroma_sample_position: ec_av1_syntax::ChromaSamplePosition::Unknown,
+ separate_uv_delta_q: false,
+ }
+}
+
+/// Writes `bytes` to `
/`, then reports size, FNV-1a64 and sha256.
+fn emit(dir: &str, name: &str, bytes: &[u8]) {
+ let path = std::path::Path::new(dir).join(name);
+ std::fs::write(&path, bytes).unwrap_or_else(|e| panic!("writing {}: {e}", path.display()));
+ let mut fnv: u64 = 0xcbf2_9ce4_8422_2325;
+ for &b in bytes {
+ fnv = (fnv ^ u64::from(b)).wrapping_mul(0x0000_0100_0000_01b3);
+ }
+ println!("{name}: {} bytes, fnv1a64 {fnv:016x}", bytes.len());
+ // sha256sum is coreutils, present on every host this runs on; the pins'
+ // provenance comments in `stream.rs` quote its output.
+ let out = std::process::Command::new("sha256sum")
+ .arg(&path)
+ .output()
+ .expect("sha256sum");
+ assert!(
+ out.status.success(),
+ "sha256sum failed on {}",
+ path.display()
+ );
+ println!(
+ "{name}: sha256 {}",
+ String::from_utf8_lossy(&out.stdout)
+ .split_whitespace()
+ .next()
+ .expect("a sha256sum line")
+ );
+}
+
+/// The subsampling and the max frame size a reader gets back out of `bytes`
+/// -- the generator never takes the shape it wrote on faith, it re-parses
+/// its own output.
+fn read_back(name: &str, bytes: &[u8]) -> (u8, u8, u32, u32) {
+ let mut parser = ec_av1_syntax::Av1Parser::new();
+ let mut pos = 0usize;
+ while pos < bytes.len() && parser.sequence_header().is_none() {
+ let obu = parser
+ .parse_obu(&bytes[pos..])
+ .unwrap_or_else(|e| panic!("{name}: OBU at byte {pos} does not parse: {e:?}"));
+ pos += obu.total_size;
+ }
+ let seq = parser
+ .sequence_header()
+ .unwrap_or_else(|| panic!("{name}: no sequence header parsed back out of its own bytes"));
+ (
+ seq.color_config.subsampling_x,
+ seq.color_config.subsampling_y,
+ seq.max_frame_width,
+ seq.max_frame_height,
+ )
+}
+
+/// The bytes of `stream`'s single `OBU_FRAME`, OBU header and size field
+/// included. An example cannot reach `Encoded::tile` (crate-private, and
+/// documented as a `crate::decode` test-only reader) and does not need to:
+/// the OBU is right there in the stream the encoder just wrote.
+fn frame_obu_of(stream: &[u8], name: &str) -> Vec {
+ let mut parser = ec_av1_syntax::Av1Parser::new();
+ let mut pos = 0usize;
+ while pos < stream.len() {
+ let obu = parser
+ .parse_obu(&stream[pos..])
+ .unwrap_or_else(|e| panic!("{name}: OBU at byte {pos} does not parse: {e:?}"));
+ if matches!(obu.kind, ObuKind::Frame(..)) {
+ return stream[pos..pos + obu.total_size].to_vec();
+ }
+ pos += obu.total_size;
+ }
+ panic!(
+ "{name}: no frame OBU in a {}-byte key frame stream",
+ stream.len()
+ );
+}
+
+fn main() {
+ let dir = std::env::args()
+ .nth(1)
+ .unwrap_or_else(|| "crates/ec-av1/fixtures".to_string());
+ std::fs::create_dir_all(&dir).expect("output dir");
+
+ // ---- cell 1: 4:2:0 with an odd luma dimension -------------------------
+ let encoded = ec_av1::encode::encode_key_frame_at_size(&card(PAD, PAD), ODD, ODD, Q_IDX, 0.5)
+ .expect("encoding the odd-luma key frame");
+ let (sx, sy, mw, mh) = read_back("420_odd65x65_key", &encoded.stream);
+ assert_eq!(
+ (sx, sy),
+ (1, 1),
+ "the odd cell must stay 4:2:0 -- it is the luma SIZE that is odd, not the shape"
+ );
+ assert_eq!(
+ (mw, mh),
+ (ODD as u32, ODD as u32),
+ "the odd cell's sequence header must declare {ODD}x{ODD}"
+ );
+ assert_eq!(
+ (encoded.reconstruction.width, encoded.reconstruction.height),
+ (ODD, ODD),
+ "the returned reconstruction must be cropped to the DECLARED size"
+ );
+ assert_eq!(
+ encoded.reconstruction.u.len(),
+ ODD.div_ceil(2) * ODD.div_ceil(2),
+ "a 4:2:0 frame of odd luma size keeps the ceil chroma extent"
+ );
+ println!(
+ "420_odd65x65_key: max_frame {mw}x{mh} at ({sx},{sy}), chroma {}x{} \
+ (ROUND_POWER_OF_TWO({ODD},1) = {}), mi {}x{}, reconstruction {}x{} luma + {} chroma \
+ samples",
+ ODD.div_ceil(2),
+ ODD.div_ceil(2),
+ ODD.div_ceil(2),
+ 2 * ((ODD + 7) >> 3),
+ 2 * ((ODD + 7) >> 3),
+ encoded.reconstruction.width,
+ encoded.reconstruction.height,
+ encoded.reconstruction.u.len(),
+ );
+ emit(&dir, "420_odd65x65_key.obu", &encoded.stream);
+
+ // ---- cell 2: the 4:4:0 (ss 0,1) row ------------------------------------
+ // 4:4:0 is NOT A CELL: `subsampling_y` is coded only when
+ // `subsampling_x` is 1 (spec 5.5.2 `color_config`), so a header can
+ // carry 4:2:0 (1,1), 4:2:2 (1,0) or 4:4:4 (0,0) and never (0,1).
+ // libaom asserts it in its own writer --
+ // `assert(seq_params->subsampling_y == 0 && "4:4:0 subsampling not
+ // allowed in AV1")`, av1/encoder/bitstream.c:2467-2468 -- and its reader
+ // leaves `subsampling_y = 0` when `subsampling_x` is 0
+ // (`av1_read_color_config`, av1/decoder/decodeframe.c:4171-4175).
+ //
+ // So this file pins WHAT A 4:4:0 REQUEST PRODUCES: the writer handed
+ // subsampling (0,1) at profile 2, which below 12 bits is 4:2:2 and codes
+ // no subsampling bit at all, and the request lands on (1,0). The frame
+ // OBU behind it is a real 4:2:0 key frame's, byte for byte: the
+ // subsampling lives only in the sequence header, so the frame header is
+ // the same one either way. The stream is NOT a decodable 4:2:2 stream
+ // (its tile is 4:2:0); it is pinned as the byte-level evidence for the
+ // claim, and the decoder refuses it by name, which is the honest
+ // outcome for the shape the request lands on.
+ let tile_stream = ec_av1::encode::encode_key_frame(&card(WITNESS, WITNESS), Q_IDX, 0.5)
+ .expect("encoding the witness tile")
+ .stream;
+ let frame_bytes = frame_obu_of(&tile_stream, "the 4:4:0 request's tile");
+ let (mut seq, _header) =
+ ec_av1::encode::key_frame_headers_colour(WITNESS, WITNESS, Q_IDX, yuv440())
+ .expect("building the 4:4:0-request sequence header");
+ seq.seq_profile = 2;
+ let mut witness =
+ ec_av1::sequence::sequence_header_obu(&seq).expect("writing that sequence header");
+ witness.extend_from_slice(&frame_bytes);
+ let (sx, sy, mw, mh) = read_back("440_request_is_422", &witness);
+ assert_eq!(
+ (sx, sy),
+ (1, 0),
+ "a 4:4:0 request at profile 2 must land on 4:2:2 (1,0). If it ever reads back (0,1), \
+ 4:4:0 became codable and the whole cell-2 story is wrong."
+ );
+ assert_eq!(
+ (mw, mh),
+ (WITNESS as u32, WITNESS as u32),
+ "the request stream's frame size"
+ );
+ // The frame OBU behind the header must still parse as the frame header
+ // the 4:2:0 stream carried.
+ let mut parser = ec_av1_syntax::Av1Parser::new();
+ let first = parser
+ .parse_obu(&witness)
+ .expect("the request's sequence header OBU parses");
+ let frame = match parser
+ .parse_obu(&witness[first.total_size..])
+ .expect("the request's frame OBU parses")
+ .kind
+ {
+ ObuKind::Frame(h, tiles) => {
+ assert_eq!(
+ tiles.len(),
+ 1,
+ "the request stream carries exactly one tile"
+ );
+ h
+ }
+ other => panic!("440_request_is_422: expected a frame OBU, got {other:?}"),
+ };
+ assert_eq!(
+ (frame.frame_width, frame.frame_height),
+ (WITNESS as u32, WITNESS as u32),
+ "the request stream's frame header must name its own size"
+ );
+ println!(
+ "440_request_is_422: asked for subsampling (0,1) at profile {} -- got ({sx},{sy}) at \
+ max_frame {mw}x{mh}, i.e. 4:2:2, the shape this decoder refuses by name; frame header + \
+ one tile ({} bytes) from a 4:2:0 {WITNESS}x{WITNESS} key frame",
+ seq.seq_profile,
+ frame_bytes.len()
+ );
+ emit(&dir, "440_request_is_422.obu", &witness);
+}
diff --git a/crates/ec-av1/fixtures/420_odd65x65_key.obu b/crates/ec-av1/fixtures/420_odd65x65_key.obu
new file mode 100644
index 0000000000000000000000000000000000000000..806027dfab5e248b66efb41967d93dfe6aa6e00d
GIT binary patch
literal 2305
zcmV+c3I6sH0168L002Rn1O_QH0Dv;@5flK~09j?01b`qQ`ApSUai!WxE%+Bkt;(3x
zdY6{^}pxuL%XPesot76HE#ZLK{n6A!xj
z(IA7GS4pnyd{@0&0R$d1%`_c30T6%t_3Rj&7@+8|dEjmJttc9Pt3~XFQe^HV0@DXT
zKGXCMbFZ4}@o$!y+vxt>sV06cv7$$~a`B!6#3$x2TD~>^iCO#UWRZS%p-APFob|fV
zmaa=`2(-8^%3!CdlN$HOXLFFRPtKSh9_h5-b&)bA1|6->30b%!t!v1Bb|1G;s7X#d
zp=bXEA#(1#Ecm(98CP*`Hjw=Y0OC$S&4H{XX}ldNF%jEM*{x8)CXqcQM!k`Vyu5J$
z!GcR-H}1|WN>3QeE${!9ZI7)*J^&n`-ij=~LPC}MWc=`wm8%qAzXgJuU+AZb`j3#*
z3Ff-#2%o45jqoAe>DcoDPcklNF-o`si2R?=^=!cQz6II5>8j!^aU%CfEp7Z%5lh7>
znijQO#xfrM;B8FR)TGt@C0}^M&U-EOH!Ev{-^U*!H5*JfCQeT4Z{VKQq`;SWry7=BuFl|do!vnesRakjrNZxTZE
zuxiqNZ#HA2dw{xJ-0X;j=;dX<=7(0(l>3|~;rtS!r$>q5V>zEPKzfFA+}1RUA4^^q
zBUbdVTa0xbErN>tBk7*#Ac2$tFUsrQg2#Zr+?f-e=?~T)JDB4%`eIGGqnb>cLM(D5
z);NPqj$$mpv9(ypr@0(T*UOa^wL?)u>!ku1T>ub0T)GaRq$Jt>-chu3f+a9!+)%s<05XD1QhoV=qYz1e6(pB@i1V14M<
z#Km|RG~~|saBoQ#1t9<&@r?dCH@HPnsW-aJV^JF_XS#biR}M;hhggP>^ykNFUTRE+
z$g+lmhh_H{P1r2xEImLA$3QsyrlMRAzLgFz1>cqgH+BF9#YJ=}s)+i}wLW9{|4it2
zfl8cbUW$3?3~JmDshoEH`T~(`?@~K*^VhM$bL9|RKyS@HP@Qw0
zr3ndEDm`@cU(J;eXj-k*UYh>e1arcizc_cssWps_bHk!lIl<2Ah|>iXP(Q*X`uYPG!b>7-|zsKC^!>fW&
z2eIa8kPJY=h?)byw1sL7FJLAJO1Ux0yPc(AXk;*+?;Naw@w}hu+jSnJg`VO3J*K1?
zN*0-?$=~)9$k?Xn9-%Ba13aqQ4SzEQr_Riw6jwypW+Wrh2ar*hf(+qub47`#F8$_D
zGtZRef~!{9?W=;qr2-NZ1SW$&1D-TR(*0Vv4LSQ}^MF(d`T&f%e*gXSr3pDXjD?yi
z98UImE)=abT(X^;Y~xJs*wtMeGkph|RUkmyEJtr?IhyN8T12mF&MzpR-VHCeB*|v<
zbA)acK{AXn7yg3EI#hGhR*S7PLtMwFCgN4uV3YnA>>mL)wgq}>u(3lK@&7*;QusuB
zoe6PSifLRpRf-%hfdnkX>j=KaC#xc_=QH1JC4`Y@Wp;Qw56PssknGmMw)*^nf3$8=
zw@epNVf44edt>vikqIkXR%Zq9aP+$-7WI>PM5sDH?#`4xA;w~s;XPrNNfNo5PwT6%
z0B%wAa3f(&b2z<tzr}if#<|e6p
z{}k)!7UhL3sWYoD&-*9JR1#JcP;P@BCb%g5XF{UrRfWWuqBkBx0vRU=Cw6E{5_md9
z+2hNK7CO~$jks;B>Gk;5xy#vKgc~z!Z~shT
zktO}O*hA9TO^3B3$hfOT4qXElxb|!EI}bk1hO#Tf@X|VF?qR!#
zoKm&JDjK!sn~4$q7U%ze+micVozl?iC5czXZv>!;Fai7cIfO?puNvY|H*ADr@7T+6
zCvSzxm!ynh&J02t?IM$<2*EUQ!5CO&o|$*fcTvvp*Xcs5+Rz3vUORlFbGe1)6dPOMQca*lgi|W7QCwQNQ+*4370b>b2EU%~gjsRIxPRSF=`WTwnd^w~+N@A4
boHZ?Jygeg6P1i$x-|;aO*$k71(AqM9pW<$x
literal 0
HcmV?d00001
diff --git a/crates/ec-av1/fixtures/440_request_is_422.obu b/crates/ec-av1/fixtures/440_request_is_422.obu
new file mode 100644
index 0000000000000000000000000000000000000000..d7f8592e105c59045a5f7e7f522afd3056b62023
GIT binary patch
literal 2014
zcmV<42O;Z^5bBeTGByGZHdGBbnnW6RE~SaanI*o@UkR;m{J5
z)w;?YY{u@ixE%S&(Aq<+JtMq(%*2$2xoJ;R9h?95CWYnpk|sAIF;ye
z&%S#YNXY6G>Jr#2DcRYCAZ?MO4UW!5@g0176%S=Xl@^~ginuCbk4kLWu5d*j9FFoQ
z`W4jF+bDEdlyfNRHP+8L#zUHGnRkr%%f=7k`b_LTM>s$?R2!mq>xZ(unSvp&^;di+
zt&Gw6*Ckp(N15k~+HCtv+@9+GyEpJD1Hp+E63XmlJW`K4IYe*5)RUAeN@}viHk3^}
z=dkngTJFYN1gLnOWp+VWsxlF!o9KMUgG|sey`RAtbNwljC_i>sZ(px2(i`G-urCon`aT<
zP<;nY1@H`!KDs-t9E}IL3mQ-ZZYs-;#n@2a(?RQquBCS+pQfh{h?)1|ilcoj}wO2@Q>;
zuuYqP8$`fyYiL<LoH%4hI%LrwBrWZyu;Zk
z&yY#(Q6&-iA^cP7?fLD3Q`kE8Gki}uJOduIFT0^-Nc^hC2^?t%vZ4R@g<7|nw}0{8
zQGgldG&%+`dA{pFa{F_E9_DA-Cf9mHx#2ttDBk*FNbg^v_yAiu=IGGlonX9ipmv4o
z8*p`0rbu;9la(Y>7@on73zB~S5mw+Hpwp;?3i2YY0!T*XOlUl*Y9@e!%bTFk4)L-z
zoo2_h)|kb|TZ4=vZf5~~DTGoQ#gxNZ=E#!;x#UiZOd;A-57z;$<^UM%sZ~l*B;}hj
z&wwjA2OCT(JaYgXtX*JqNzDKGbj28wO|sWu{80-Zf2@n^krL
zX*@jA#4~aw!%kVGW_NwfhbjD%>S}j}C}gxfGq89fz~9>ugO4+D6scJVJ1wi}JkbK9
zo7d$Q9I{pgZrAL;%Z&ObDEu1m^nzZ$lIwoVg3bFE?QU$W^?Av9181(;6$&=3*+#w^D?zxwh%;7YM(ZwWqswGaa+ImGsG2v6Oq#|1*>>XL)%5
zJ(SFZHy!&)4_i$QTfWT4Q+bG$z`$9q`YasWyqR1N5L>-Z>Q52uHoUJuqaXbYgVM6s
zDg*IEVO_$9S!cA?9FdXmrS!eKV~V{jrd8{BBeQ{KD=m~b5||tIN}-uCmliwtKC2Jg
zf+6VM%A~WUcuktkI$RXS%K>KwP1YClB9k@^ii30|9oPNYNziVTC>1D3ljA8dH=2_N
zUvpWK3;gh~F#q9oP$)xzJXq~LOCfuG?hArj!SFuXpEpWTAj)jxBDXZ_U&9TG_^kuo
znGD&S8Bp#`$sqS_W$7SSpf~baxlN3gYeWOA;{7a=8f4ru-tWPtn$oVrq;+fqF-kpr
zn1KyHbfP&PwH4hf^-;`zCVc3fTvij8*0loKYJT0Kl(*>~F0SToQAo-?zKANZh{E2L
z=)%cJ`PH?6LCfRr?dWrXC-%gv1*yr)s66-MaEL)k|K=6<@bS>ap`0L9SL7S(d8;mQ
zg@^}g4$;UU^v&oSx6_#0XtKhXtZl6GK|unCeuiWDp<8}W=988wOp~Fvv*$}m!pX}F
z$W1~$7j6G%l)VVS)RJP)H8T1rg(XukT61b)s6zLPl6aA$c!@+)oHKMHkQLgvuiar8;nma%akB+z?aQU0y2qwMz&
wPQY8O*beP2Df9QN$X|K{`vKG{e02g3Fvbqw$VOMmbi%3H!8U0<_+(@kYgVG_+5i9m
literal 0
HcmV?d00001
diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs
index 9b93baa4..c93e3a29 100644
--- a/crates/ec-av1/src/decode.rs
+++ b/crates/ec-av1/src/decode.rs
@@ -37762,28 +37762,26 @@ fn whole_plane(data: &[u16], width: usize, height: usize) -> PlaneBuf<'_> {
/// **every `w >= 2 && h >= 2`**. No stream this decoder accepts reaches a
/// 1-pixel chroma plane; the pinned fixture's chroma is 128x144.
///
-/// **Open gap, 4:2:0 at odd dimensions (pre-existing).** The 4:2:0 arm is
-/// left at the old `(width / 2, height / 2)` floor, which is what the
-/// two-way test this replaces produced -- that was the point, since no
-/// 4:2:0 stream changed shape. It is nevertheless the wrong shape for an
-/// odd-dimension 4:2:0 reference: the producer stored
-/// `round_ss(w, 1) x round_ss(h, 1)`, so the floor arm under-declares.
-/// Measured over the `1..=128` square, running each 4:2:0 count through
-/// this very function: 12160 of the 16384 pairs come back smaller than the
-/// plane actually holds, 12033 of those with `w >= 2` and 127 in the
-/// `w == 1` column (at `w == 1, h == 1` the 4:4:4 arm catches the count
-/// and `(1, 1)` is exact). Under-declaration at `h == 1` is **zero** over
-/// the whole square: there the 4:2:0 count equals the 4:2:2 count, routes
-/// into the 4:2:2 arm, and lands on the correct
-/// `(round_ss(w, 1), 1)`. The `w == 1` residue is a *shape* error, not a
-/// misroute -- the floor fallback simply cannot express
-/// `(1, round_ss(h, 1))`. It is left alone because it predates this lane,
-/// is identical to the parent, and no in-tree coverage exercises an
-/// odd-dimension 4:2:0 reference. A ceil fallback
-/// (`(round_ss(w, 1), round_ss(h, 1))`) would close it, at the cost of
-/// departing from the parent on every odd-dimension 4:2:0 shape with
-/// nothing in the tree to justify the change; that call belongs to a lane
-/// that can bring odd-dimension 4:2:0 fixtures with it.
+/// **4:2:0 at odd dimensions: CLOSED by lane-av1odd440.** The arm used to be
+/// the old `(width / 2, height / 2)` floor, which was what the two-way test
+/// this replaces produced -- harmless then, since no 4:2:0 stream changed
+/// shape, and wrong for an odd-dimension 4:2:0 reference: the producer
+/// stored `round_ss(w, 1) x round_ss(h, 1)`, so the floor arm
+/// under-declared. Measured over the `1..=128` square, running each 4:2:0
+/// count through this very function: 12160 of the 16384 pairs came back
+/// smaller than the plane actually holds, 12033 of those with `w >= 2` and
+/// 127 in the `w == 1` column, where the floor cannot even express
+/// `(1, round_ss(h, 1))`. It was left alone pending "a lane that can bring
+/// odd-dimension 4:2:0 fixtures with it" -- this is that lane: the pinned
+/// `420_odd65x65_key.obu` is a real 65x65 4:2:0 key frame (declared at
+/// `encode::encode_key_frame_at_size`, because aomenc rounds the coded size
+/// down to even and cannot produce one) whose chroma planes are 33x33, and
+/// the gate `an_odd_luma_420_key_frame_decodes_pixel_exact` decodes it
+/// sample-exact against `aomdec`. The arm is now the producer's own crop,
+/// so a 4:2:0 reference at ANY size routes back to the shape the producer
+/// wrote. Even sizes are untouched: `(2k + 1) / 2 == k`, so every 4:2:0
+/// reference this decoder met before this lane claims exactly the same
+/// shape it did then.
fn ref_chroma_shape(len: usize, width: usize, height: usize) -> (usize, usize) {
let half_w = round_ss(width, 1);
if len == width * height {
@@ -37791,7 +37789,7 @@ fn ref_chroma_shape(len: usize, width: usize, height: usize) -> (usize, usize) {
} else if len == half_w * height {
(half_w, height)
} else {
- (width / 2, height / 2)
+ (round_ss(width, 1), round_ss(height, 1))
}
}
@@ -54695,6 +54693,14 @@ mod tests {
/// exact defect this lane fixed, one dimension over. So the table below
/// is driven off `round_ss`, not off hand-written numbers, and sweeps
/// odd and even widths.
+ ///
+ /// lane-av1odd440: the 4:2:0 arm's expectation is the PRODUCER's crop,
+ /// `round_ss(w, 1) x round_ss(h, 1)`, not the `(w / 2, h / 2)` floor it
+ /// used to name -- the floor under-declares every odd-dimension 4:2:0
+ /// reference, which is the shape the pinned `420_odd65x65_key.obu` cell
+ /// finally makes reachable (see [`ref_chroma_shape`]). For every EVEN
+ /// size the two spellings are the same number, so the arms that were
+ /// already correct are unchanged by the edit.
#[test]
fn a_reference_chroma_sample_count_routes_back_to_its_own_format() {
for w in [2usize, 3, 4, 5, 8, 9, 16, 17, 64, 65, 128, 129] {
@@ -54706,7 +54712,11 @@ mod tests {
round_ss(w, 1) * round_ss(h, 0),
(round_ss(w, 1), h),
),
- ("4:2:0", round_ss(w, 1) * round_ss(h, 1), (w / 2, h / 2)),
+ (
+ "4:2:0",
+ round_ss(w, 1) * round_ss(h, 1),
+ (round_ss(w, 1), round_ss(h, 1)),
+ ),
];
for (name, len, want) in cases {
assert_eq!(
diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs
index dbeae7c4..f5aff96f 100644
--- a/crates/ec-av1/src/encode.rs
+++ b/crates/ec-av1/src/encode.rs
@@ -1807,8 +1807,16 @@ fn crop_plane(source: &[T], padded_width: usize, width: usize, height:
/// region a decoder produces, which is the public contract for what a caller
/// sees back — the padded planes the encoder coded against never leave this
/// module. Identity when the reconstruction is already that size.
+///
+/// The chroma extent is `ROUND_POWER_OF_TWO(size, 1)` -- `(size + 1) / 2`,
+/// libaom's `av1_common_plane_width` (`av1/common/av1_common_int.h`) -- so an
+/// ODD declared luma size keeps the chroma column a decoder keeps (a 65-wide
+/// 4:2:0 frame has 33, not 32). Every even size is unaffected: `(2k+1)/2 ==
+/// k`, so this is a no-op for every caller `encode_key_frame`'s even-size
+/// check lets through.
pub(crate) fn crop_encoded(encoded: &Encoded, width: usize, height: usize) -> Encoded {
let reconstruction = &encoded.reconstruction;
+ let (cw, ch) = (width.div_ceil(2), height.div_ceil(2));
let cropped = if reconstruction.width == width && reconstruction.height == height {
reconstruction.clone()
} else {
@@ -1816,18 +1824,8 @@ pub(crate) fn crop_encoded(encoded: &Encoded, width: usize, height: usize) -> En
width,
height,
y: crop_plane(&reconstruction.y, reconstruction.width, width, height),
- u: crop_plane(
- &reconstruction.u,
- reconstruction.width / 2,
- width / 2,
- height / 2,
- ),
- v: crop_plane(
- &reconstruction.v,
- reconstruction.width / 2,
- width / 2,
- height / 2,
- ),
+ u: crop_plane(&reconstruction.u, reconstruction.width / 2, cw, ch),
+ v: crop_plane(&reconstruction.v, reconstruction.width / 2, cw, ch),
}
};
Encoded {
@@ -2201,9 +2199,17 @@ fn unspecified_color_config() -> ColorConfig {
/// which is all a player picks a colour transform from and which
/// [`crate::encoder::Colour`] is the facade's own name for.
///
+/// `color_config` also carries the chroma shape, and that is what a coverage
+/// witness needs: nothing in this crate's ENCODER codes a shape other than
+/// 4:2:0, but a sequence header can still be written at any
+/// `subsampling_x`/`subsampling_y` the spec allows, which is how the 4:4:0
+/// header witness is built. It builds HEADERS only -- pair the pair it
+/// returns with a tile from [`encode_key_frame`] (4:2:0) or
+/// [`encode_key_frame_at_size`].
+///
/// # Errors
/// The same as [`key_frame_headers`].
-pub(crate) fn key_frame_headers_colour(
+pub fn key_frame_headers_colour(
width: usize,
height: usize,
base_q_idx: u8,
@@ -8894,6 +8900,60 @@ pub fn encode_sequence(
)
}
+/// Codes one padded picture as a key frame whose HEADER declares
+/// `frame_width` x `frame_height` -- a frame size the picture's own
+/// `width`/`height` need not be, and in particular need not be even.
+///
+/// [`encode_key_frame`] derives the declared size from the picture and
+/// refuses an odd one, which is a property of a 4:2:0 SOURCE (an odd luma
+/// column has no chroma sample of its own to be fed), not of the format: a
+/// 65-wide 4:2:0 frame is a legal AV1 frame, with
+/// `ROUND_POWER_OF_TWO(65, 1) = 33` chroma columns (libaom
+/// `av1_common_plane_width` / `ROUND_POWER_OF_TWO`, `av1/common/
+/// av1_common_int.h`), and aomenc never emits one only because it rounds the
+/// coded size down to even before it looks at the picture
+/// (`av1enc_set_frame_size`). This is the entry that can produce one, and it
+/// is what the odd-luma coverage fixture is built with: the caller hands
+/// over a picture already padded to the block grid and names the size to
+/// declare, so the block walk codes exactly the `mi_cols`/`mi_rows` a
+/// decoder derives from the declared size (spec `compute_image_size`).
+///
+/// # Errors
+/// Returns an error when `picture` is not a whole number of 32x32 blocks
+/// ([`Picture::check`]'s own rule), when either declared size is zero or
+/// larger than the padded picture's, or when the mode search fails -- the
+/// same conditions [`encode_key_frame`] reports for a malformed picture.
+pub fn encode_key_frame_at_size(
+ picture: &Picture,
+ frame_width: usize,
+ frame_height: usize,
+ base_q_idx: u8,
+ deadzone: f64,
+) -> Result {
+ picture.check()?;
+ if frame_width == 0
+ || frame_height == 0
+ || frame_width > picture.width
+ || frame_height > picture.height
+ {
+ return Err(Error::unsupported(
+ "AV1 encode",
+ "the declared frame size must be nonzero and fit inside the padded picture",
+ ));
+ }
+ let encoded = encode_key_frame_inner(
+ picture,
+ base_q_idx,
+ deadzone,
+ &KEY_FRAME_MODES,
+ split_blocks(),
+ (frame_width, frame_height),
+ unspecified_color_config(),
+ &crate::decode::FrameCtx::for_encoder(),
+ )?;
+ Ok(crop_encoded(&encoded, frame_width, frame_height))
+}
+
pub(crate) fn encode_key_frame_with_ctx(
picture: &Picture,
base_q_idx: u8,
diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs
index ec69cc57..174c2d0c 100644
--- a/crates/ec-av1/src/refusal_inventory.rs
+++ b/crates/ec-av1/src/refusal_inventory.rs
@@ -116,7 +116,15 @@ const REFUSALS: &[&str] = &[
// hardcoded 4:2:0, the probe emits 4:2:0 planes only); it is now refused
// at the sequence header. Gate:
// `a_non_420_subsampled_sequence_header_is_refused_by_name`.
- "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",
+ // lane-av1odd440: the string gained its 4:4:0 clause. `subsampling_y` is
+ // coded only when `subsampling_x` is 1 (spec 5.5.2; libaom
+ // `av1_read_color_config`, `av1/decoder/decodeframe.c:4171-4175`, and its
+ // writer's own `assert(..., "4:4:0 subsampling not allowed in AV1")` at
+ // `av1/encoder/bitstream.c:2467-2468`), so (0,1) cannot reach this check --
+ // the reachable set is 4:2:0, 4:2:2 and 4:4:4, and only 4:2:2 lands here.
+ // Gate: `the_440_cell_is_not_a_codable_chroma_shape`, which enumerates
+ // the whole reachable set through this crate's own writer AND reader.
+ "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",
// lane-av1txr-r2 added, lane-av1-qmatrix RETIRED: the third member of the
// silent-garbage family (`using_qmatrix`/`qm_y`/`qm_u`/`qm_v`, refused by
// name at the frame header) now DEQUANTISES through libaom's
@@ -437,9 +445,11 @@ const PROVEN: &[(&str, &str)] = &[
// lane-av1txr: the guard's own gate builds a profile-1 and a profile-2
// sequence header by hand and asserts each refuses by name while the
// profile-0 CONTROL still decodes -- the refusal is exercised, not merely
- // present.
+ // present. lane-av1odd440 adds the second gate named here, which
+ // enumerates every chroma shape a `color_config` can code and pins the
+ // bytes a 4:4:0 request actually produces (`440_request_is_422.obu`).
(
- "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",
+ "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",
"a_non_420_subsampled_sequence_header_is_refused_by_name",
),
// lane-av1txr-r2 paired, lane-av1-qmatrix RETIRED with its gate: the
@@ -1866,10 +1876,12 @@ mod tests {
.find("fn suppress_internal_lf_edges(")
.expect("suppress_internal_lf_edges is gone");
let body_start = start + src[start..].find('{').expect("no body");
- let body = &src[body_start..body_start + src[body_start..].find("\n }").expect("no end")];
+ let body =
+ &src[body_start..body_start + src[body_start..].find("\n }").expect("no end")];
assert!(
- body.contains("((w_mi * MI) >> ss_x(fctx))") && body.contains("((h_mi * MI) >> ss_y(fctx))"),
+ body.contains("((w_mi * MI) >> ss_x(fctx))")
+ && body.contains("((h_mi * MI) >> ss_y(fctx))"),
"suppress_internal_lf_edges must publish the block's own chroma extent per axis \
-- `w_mi * MI >> ss_x(fctx)`, not a hardcoded `/2`"
);
diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs
index c372e945..ad0dd678 100644
--- a/crates/ec-av1/src/stream.rs
+++ b/crates/ec-av1/src/stream.rs
@@ -1777,10 +1777,21 @@ fn decode_frame(
// name` below (hand-built profile 1/2 headers plus a real aomenc 4:4:4
// stream).
// lane-av1-444: 4:4:4 (ss 0,0) is decoded. 4:2:2 (ss_x != ss_y) is not.
+ // lane-av1odd440: the CONDITION is left as `ss_x != ss_y` because that is
+ // what a parsed header can violate, but the STRING now names the only
+ // shape that can: `subsampling_y` is coded ONLY when `subsampling_x` is
+ // 1 (spec 5.5.2's `color_config`; libaom `av1_read_color_config`,
+ // `av1/decoder/decodeframe.c:4171-4175`, and its writer's own
+ // `assert(seq_params->subsampling_y == 0 && "4:4:0 subsampling not
+ // allowed in AV1")`, `av1/encoder/bitstream.c:2467-2468`), so a header can
+ // carry (1,1), (1,0) or (0,0) and never (0,1) -- 4:4:0 is not a cell a
+ // decoder can be handed at all. The gate
+ // `the_440_cell_is_not_a_codable_chroma_shape` proves the whole reachable
+ // set, so this string is not a claim about a shape that cannot arrive.
if seq.subsampling_x != seq.subsampling_y {
return Err(Error::unsupported(
"AV1 decode_stream",
- "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",
+ "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",
));
}
// lane-av1-qmatrix: `quantization_params.using_qmatrix` + `qm_y`/`qm_u`/
@@ -2305,6 +2316,390 @@ pub(crate) mod tests {
"{NAME}: the 4:2:0 control decoded no frame"
);
}
+
+ /// lane-av1odd440, CELL 1 of 2: `4:2:0 with an ODD luma dimension`, the
+ /// cell `lanes/av1formatsweep.report.md` left as declared debt because
+ /// "aomenc rounds a 4:2:0 frame's coded size DOWN to even, so no stream
+ /// this recipe can produce codes an odd luma dimension".
+ ///
+ /// The pin, `420_odd65x65_key.obu` (2305 bytes,
+ /// sha256 `66986019a561f81130f407f426c4379b25e6e80c2cd9ce47d517b3216e9a03cf`),
+ /// is that missing stream, built offline by
+ /// `examples/gen_coverage_cells.rs`: a 96x96 card padded to the block
+ /// grid, coded by `encode::encode_key_frame_at_size` with a 65x65 frame
+ /// header. Provenance: that example, `cargo run -p ec-av1 --example
+ /// gen_coverage_cells -- crates/ec-av1/fixtures`; no encoder, no ffmpeg,
+ /// no lavfi.
+ ///
+ /// WHY THE CELL IS NOT A RUBBER STAMP -- the chroma extent is where a
+ /// floor shows. A 65-wide 4:2:0 frame has
+ /// `ROUND_POWER_OF_TWO(65, 1) = 33` chroma columns (libaom
+ /// `av1_common_plane_width`, `av1/common/av1_common_int.h`), not 32, so
+ /// the decoded frame's own plane sizes, the rawvideo sample count and
+ /// the oracle compare all move if `decode::round_ss` is floored. The
+ /// mutation was run: flooring `round_ss` (`decode.rs:697`) turns the
+ /// `round_ss` assert below red at 32 chroma columns and the oracle arm
+ /// red at a 6273-byte raw against the oracle's 6403. The gate is
+ /// therefore not green on a floored decoder, which is the whole content
+ /// of this cell.
+ ///
+ /// The stream decodes PIXEL-EXACT against the instrumented `aomdec`
+ /// (6403 raw bytes = 65*65 + 2*33*33, byte-identical), so the cell is a
+ /// `y` and not a `–`.
+ #[test]
+ fn an_odd_luma_420_key_frame_decodes_pixel_exact() {
+ const NAME: &str = "an_odd_luma_420_key_frame_decodes_pixel_exact";
+ let _gate_lock = lock_gate_counters();
+ let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
+ .join("fixtures")
+ .join("420_odd65x65_key.obu");
+ let stream = read_pin(&path, 2305, 0xf55645c4b139e8f7, NAME);
+
+ // The stream's OWN header, read from its own bytes: an odd luma size
+ // at 4:2:0, which is the cell. (Taken from the pin, not from the
+ // gate's name -- class `helper-packs-u16-for-an-8-bit-stream`.)
+ let mut probe = Av1Parser::new();
+ let mut pos = 0usize;
+ while pos < stream.len() && probe.sequence_header().is_none() {
+ let obu = probe
+ .parse_obu(&stream[pos..])
+ .unwrap_or_else(|e| panic!("{NAME}: OBU at byte {pos} does not parse: {e:?}"));
+ pos += obu.total_size;
+ }
+ let seq = probe
+ .sequence_header()
+ .unwrap_or_else(|| panic!("{NAME}: the pin carries no sequence header"));
+ assert_eq!(
+ (seq.max_frame_width, seq.max_frame_height),
+ (65, 65),
+ "{NAME}: the pin must declare an ODD luma size, it declares {}x{}",
+ seq.max_frame_width,
+ seq.max_frame_height
+ );
+ assert_eq!(
+ (
+ seq.color_config.subsampling_x,
+ seq.color_config.subsampling_y
+ ),
+ (1, 1),
+ "{NAME}: this cell is an odd luma SIZE at 4:2:0, not another chroma shape"
+ );
+
+ // The decoded frame's own extents. This arm needs no oracle, and it
+ // is the one a floored `round_ss` turns red.
+ let frames = decode_stream(&stream).expect("the odd-luma 4:2:0 pin must decode");
+ assert_eq!(frames.len(), 1, "{NAME}: frame count");
+ let frame = &frames[0];
+ assert_eq!(
+ (frame.width, frame.height),
+ (65, 65),
+ "{NAME}: decoded luma extent"
+ );
+ assert_eq!(frame.y.len(), 65 * 65, "{NAME}: decoded luma sample count");
+ assert_eq!(
+ (frame.u.len(), frame.v.len()),
+ (33 * 33, 33 * 33),
+ "{NAME}: a 65x65 4:2:0 frame has ROUND_POWER_OF_TWO(65,1) = 33 chroma \
+ columns and rows -- 32 means the extent was floored"
+ );
+
+ if !aomdec_available(NAME) {
+ return;
+ }
+ assert_rawvideo_matches(&path, &stream, NAME, 1, 8);
+ }
+
+ /// lane-av1odd440, CELL 2 of 2: the `4:4:0 (ss 0,1)` row, which the same
+ /// report called "unmeasured and unproducible by recipe". It is neither
+ /// unmeasured nor unproducible: it is NOT A CELL AT ALL.
+ ///
+ /// `subsampling_y` is coded only when `subsampling_x` is 1 (spec 5.5.2
+ /// `color_config`), so a sequence header can carry exactly three chroma
+ /// shapes -- 4:2:0 `(1,1)`, 4:2:2 `(1,0)`, 4:4:4 `(0,0)` -- and never
+ /// `(0,1)`. libaom says so in both directions: the reader leaves
+ /// `subsampling_y = 0` when `subsampling_x` is 0
+ /// (`av1_read_color_config`, `av1/decoder/decodeframe.c:4171-4175`) and
+ /// the writer ASSERTS it -- `assert(seq_params->subsampling_y == 0 &&
+ /// "4:4:0 subsampling not allowed in AV1")`, `av1/encoder/bitstream.c:
+ /// 2463-2465`. So there is no stream to decode, no fixture to pin that
+ /// a decoder could be handed, and no oracle to compare against: a
+ /// 4:4:0 row in a coverage matrix is a matrix bug, not a decoder gap.
+ ///
+ /// What is pinned, then, is the claim itself, in three arms that a
+ /// mutation turns red:
+ ///
+ /// 1. WRITER: every `(profile, bit_depth, mono, colour description,
+ /// requested subsampling)` combination a `color_config` can carry is
+ /// written by this crate's own writer and read back by this crate's
+ /// own reader. The reachable set is asserted to be EXACTLY
+ /// `{(1,1), (1,0), (0,0)}` -- each legal shape present, `(0,1)`
+ /// absent -- and, on the BYTES rather than on the round trip, the two
+ /// requests that differ only in `subsampling_y` must write identical
+ /// headers whenever `subsampling_x` is 0. A sweep that silently wrote
+ /// nothing would pass, so the count of combinations actually written
+ /// and read is asserted too.
+ /// 2. READER: the one byte that carries `subsampling_x` is found by
+ /// diffing an `(0,0)` header against an `(1,0)` one, and then all 256
+ /// values of that byte are fed back through the reader. Not one of the
+ /// headers that parse reads back `(0,1)`, because the reader never
+ /// reads a `subsampling_y` bit in that position. A reader that always
+ /// read a second bit would produce `(0,1)` at the one value that sets
+ /// both bits.
+ /// 3. THE PIN: `440_request_is_422.obu` (2014 bytes, sha256
+ /// `4afaa5470c4e010d9d970086ef514680adfe801a579e4deeec582f52d13c5e7c`,
+ /// fnv1a64 `0x98a1378df976253d`) is what this crate's writer produces
+ /// when it is handed `subsampling (0,1)` at profile 2 -- profile 2
+ /// below 12 bits is 4:2:2 and codes no subsampling bit at all, so the
+ /// request lands on `(1,0)`. The pin is asserted to read back `(1,0)`,
+ /// NOT `(0,1)`, and the decoder is asserted to refuse it by name,
+ /// which is the honest outcome for the shape a 4:4:0 request actually
+ /// yields. Its frame OBU is a 4:2:0 key frame's, so the pin is a HEADER
+ /// witness, not a decodable 4:2:2 stream -- nothing here claims
+ /// pixels for it. Provenance: `examples/gen_coverage_cells.rs`, `cargo
+ /// run -p ec-av1 --example gen_coverage_cells -- crates/ec-av1/fixtures`.
+ #[test]
+ fn the_440_cell_is_not_a_codable_chroma_shape() {
+ const NAME: &str = "the_440_cell_is_not_a_codable_chroma_shape";
+ let _gate_lock = lock_gate_counters();
+ let header_obu = |profile: u8, color: ec_av1_syntax::ColorConfig| -> Vec {
+ let (mut seq, _header) = crate::encode::key_frame_headers_colour(64, 64, 100, color)
+ .expect("the header builders accept a colour config");
+ seq.seq_profile = profile;
+ crate::sequence::sequence_header_obu(&seq).expect("writing the sequence header")
+ };
+ let shape_of = |obu: &[u8]| -> Option<(u8, u8)> {
+ let mut parser = Av1Parser::new();
+ let parsed = parser.parse_obu(obu).ok()?;
+ if !matches!(parsed.kind, ec_av1_syntax::ObuKind::SequenceHeader(_)) {
+ return None;
+ }
+ let seq = parser.sequence_header()?;
+ Some((
+ seq.color_config.subsampling_x,
+ seq.color_config.subsampling_y,
+ ))
+ };
+
+ // ---- arm 1: the writer's whole reachable space --------------------
+ let mut reachable: std::collections::BTreeSet<(u8, u8)> = Default::default();
+ let mut asked = 0usize;
+ for profile in [0u8, 1, 2] {
+ for bit_depth in [8u8, 10, 12] {
+ for mono_chrome in [false, true] {
+ // Profile 1 is 4:4:4 and codes no mono bit; asking for
+ // monochrome there is refused by the writer, which is
+ // not a chroma shape and not this gate's subject.
+ if mono_chrome && profile == 1 {
+ continue;
+ }
+ for (label, (cp, tc, mc)) in [
+ ("unspecified", (2u8, 2u8, 2u8)),
+ ("bt709", (1u8, 1u8, 1u8)),
+ ("srgb", (1u8, 13u8, 0u8)),
+ ] {
+ for sx in [0u8, 1] {
+ for sy in [0u8, 1] {
+ let color = ec_av1_syntax::ColorConfig {
+ bit_depth,
+ mono_chrome,
+ num_planes: if mono_chrome { 1 } else { 3 },
+ color_primaries: cp,
+ transfer_characteristics: tc,
+ matrix_coefficients: mc,
+ color_range: false,
+ subsampling_x: sx,
+ subsampling_y: sy,
+ chroma_sample_position:
+ ec_av1_syntax::ChromaSamplePosition::Unknown,
+ separate_uv_delta_q: false,
+ };
+ asked += 1;
+ let obu = header_obu(profile, color);
+ // The WRITER half of the claim, measured on the
+ // bytes rather than on a round trip: with
+ // `subsampling_x == 0` the spec codes no
+ // `subsampling_y` bit at all, so the two
+ // requests that differ ONLY in `subsampling_y`
+ // must produce byte-identical headers. A
+ // writer that emitted the bit anyway (the
+ // mutation libaom's own `assert` exists to
+ // catch, av1/encoder/bitstream.c:2467-2468) fails
+ // here -- and note it does NOT fail the
+ // round trip, because the reader then absorbs
+ // the extra bit as `separate_uv_delta_q`.
+ if sx == 0 {
+ let mut other = color;
+ other.subsampling_y = 1;
+ assert_eq!(
+ obu,
+ header_obu(profile, other),
+ "{NAME}: a (0,0) and a (0,1) request wrote DIFFERENT \
+ bytes at profile {profile}, {bit_depth}-bit, mono \
+ {mono_chrome}, {label} -- `subsampling_y` must not be \
+ coded at all when `subsampling_x` is 0"
+ );
+ }
+ if let Some(got) = shape_of(&obu) {
+ assert_ne!(
+ got,
+ (0, 1),
+ "{NAME}: a 4:4:0 shape came back out of the writer at \
+ profile {profile}, {bit_depth}-bit, mono {mono_chrome}, \
+ {label}, asked for ({sx},{sy}) -- libaom forbids this \
+ shape outright (av1/encoder/bitstream.c:2467-2468)"
+ );
+ reachable.insert(got);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ assert!(
+ asked >= 100 && reachable.len() == 3,
+ "{NAME}: the sweep asked {asked} combinations and reached {} shapes -- it must reach \
+ all three legal ones, or it is not measuring the space",
+ reachable.len()
+ );
+ assert_eq!(
+ reachable,
+ std::collections::BTreeSet::from([(0u8, 0u8), (1u8, 0u8), (1u8, 1u8)]),
+ "{NAME}: the chroma shapes a `color_config` can code are exactly 4:4:4 (0,0), 4:2:2 \
+ (1,0) and 4:2:0 (1,1)"
+ );
+
+ // ---- arm 2: the reader's bit at that position ----------------------
+ // Profile 2 at 12 bits is the only place BOTH subsampling bits are
+ // coded, so it is where a hand-built header could try to smuggle a
+ // `subsampling_y`. Find the byte that carries `subsampling_x` by
+ // diffing the two shapes, then read back all eight of its values.
+ let at_444 = |sx: u8| {
+ let color = ec_av1_syntax::ColorConfig {
+ bit_depth: 12,
+ subsampling_x: sx,
+ subsampling_y: 0,
+ chroma_sample_position: ec_av1_syntax::ChromaSamplePosition::Unknown,
+ ..ec_av1_syntax::ColorConfig::default()
+ };
+ let (mut seq, _h) =
+ crate::encode::key_frame_headers_colour(64, 64, 100, color).unwrap();
+ seq.seq_profile = 2;
+ let obu = crate::sequence::sequence_header_obu(&seq).unwrap();
+ let mut parser = Av1Parser::new();
+ parser.parse_obu(&obu).expect("the profile-2 header parses");
+ let seq = parser.sequence_header().expect("sequence header");
+ (
+ seq.color_config.subsampling_x,
+ seq.color_config.subsampling_y,
+ )
+ };
+ assert_eq!(at_444(0), (0, 0), "{NAME}: the sx=0 header is 4:4:4");
+ assert_eq!(at_444(1), (1, 0), "{NAME}: the sx=1 header is 4:2:2");
+ let base = {
+ let color = ec_av1_syntax::ColorConfig {
+ bit_depth: 12,
+ subsampling_x: 0,
+ subsampling_y: 0,
+ chroma_sample_position: ec_av1_syntax::ChromaSamplePosition::Unknown,
+ ..ec_av1_syntax::ColorConfig::default()
+ };
+ let (mut seq, _h) =
+ crate::encode::key_frame_headers_colour(64, 64, 100, color).unwrap();
+ seq.seq_profile = 2;
+ crate::sequence::sequence_header_obu(&seq).unwrap()
+ };
+ let other = {
+ let color = ec_av1_syntax::ColorConfig {
+ bit_depth: 12,
+ subsampling_x: 1,
+ subsampling_y: 0,
+ chroma_sample_position: ec_av1_syntax::ChromaSamplePosition::Unknown,
+ ..ec_av1_syntax::ColorConfig::default()
+ };
+ let (mut seq, _h) =
+ crate::encode::key_frame_headers_colour(64, 64, 100, color).unwrap();
+ seq.seq_profile = 2;
+ crate::sequence::sequence_header_obu(&seq).unwrap()
+ };
+ assert_eq!(
+ base.len(),
+ other.len(),
+ "{NAME}: the two headers must differ in place"
+ );
+ let byte_at = base
+ .iter()
+ .zip(&other)
+ .position(|(a, b)| a != b)
+ .expect("the two shapes must differ somewhere");
+ // Every value of that byte is fed back through the reader -- it is the
+ // LAST payload byte, so the bits a smuggled `subsampling_y` would come
+ // from are in it too (spec 5.5.2 always codes `separate_uv_delta_q`
+ // after the subsampling pair, and the payload is padded out to the
+ // byte with `trailing_bits`). A header that stops parsing is not a
+ // 4:4:0 shape and cannot be counted as one; the sweep asserts how
+ // many DID parse, so a sweep that quietly parsed nothing is not
+ // evidence of anything.
+ let mut parsed_headers = 0usize;
+ for value in 0..256u16 {
+ let mut poked = base.clone();
+ poked[byte_at] = value as u8;
+ let mut parser = Av1Parser::new();
+ let Ok(parsed) = parser.parse_obu(&poked) else {
+ continue;
+ };
+ if !matches!(parsed.kind, ec_av1_syntax::ObuKind::SequenceHeader(_)) {
+ continue;
+ }
+ let seq = parser.sequence_header().expect("sequence header");
+ parsed_headers += 1;
+ assert_ne!(
+ (
+ seq.color_config.subsampling_x,
+ seq.color_config.subsampling_y
+ ),
+ (0, 1),
+ "{NAME}: payload byte {byte_at} = {value:#04x} read back as 4:4:0 -- the reader \
+ took a `subsampling_y` bit that spec 5.5.2 does not code when `subsampling_x` \
+ is 0"
+ );
+ }
+ assert!(
+ parsed_headers > 100,
+ "{NAME}: only {parsed_headers} of the 256 poked headers parsed -- the sweep is not \
+ measuring the reader"
+ );
+
+ // ---- arm 3: the pinned bytes a 4:4:0 request produces --------------
+ let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
+ .join("fixtures")
+ .join("440_request_is_422.obu");
+ let pinned = read_pin(&path, 2014, 0x98a1378df976253d, NAME);
+ let mut parser = Av1Parser::new();
+ let obu = parser
+ .parse_obu(&pinned)
+ .unwrap_or_else(|e| panic!("{NAME}: the pin's first OBU does not parse: {e:?}"));
+ assert!(
+ matches!(obu.kind, ec_av1_syntax::ObuKind::SequenceHeader(_)),
+ "{NAME}: the pin must start with its sequence header"
+ );
+ let seq = parser.sequence_header().expect("the pin's sequence header");
+ assert_eq!(
+ (
+ seq.color_config.subsampling_x,
+ seq.color_config.subsampling_y
+ ),
+ (1, 0),
+ "{NAME}: the pin is what a 4:4:0 request at profile 2 produces -- 4:2:2 (1,0). If this \
+ ever reads (0,1), a 4:4:0 cell became codable and this whole gate is wrong about the \
+ format."
+ );
+ let err = decode_stream(&pinned).unwrap_err().to_string();
+ assert!(
+ err.contains("a chroma format of 4:2:2"),
+ "{NAME}: the shape the 4:4:0 request lands on must still refuse by name, got: {err}"
+ );
+ }
/// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned
/// as fixtures (`git add -f`; `fixtures/` is gitignored).
///
diff --git a/lanes/av1odd440.report.md b/lanes/av1odd440.report.md
new file mode 100644
index 00000000..eb4f0d69
--- /dev/null
+++ b/lanes/av1odd440.report.md
@@ -0,0 +1,160 @@
+# lane-av1odd440 — the two unreachable cells, one closed and one dissolved
+
+Branch `lane-av1odd440`, base `70ed5601` (main). Target dir
+`$HOME/.cache/tgt/av1odd440`. No push.
+
+## Verdict, in four lines
+
+1. **`4:2:0` with an ODD luma dimension: DECODED, pixel-exact, now gated.** The
+ stream aomenc cannot make exists, decodes byte-identical to `aomdec`
+ (6403 raw bytes, 65x65 + 2x33x33), and the gate bites: flooring
+ `decode::round_ss` turns it red.
+2. **The `4:4:0 (ss 0,1)` row is not a decoder gap — it is not a cell.** AV1
+ codes `subsampling_y` only when `subsampling_x` is 1, so the reachable set
+ is exactly `{(1,1), (1,0), (0,0)}` and `(0,1)` is uncodable. libaom's own
+ writer asserts it in a string: `"4:4:0 subsampling not allowed in AV1"`.
+3. The odd-luma fixture exposed a **real decoder defect** the tree had
+ documented as an open gap and deferred: `ref_chroma_shape`'s 4:2:0 arm was a
+ floor. It is now the producer's own `round_ss` crop, red-before proven.
+4. The decoder **still refuses 4:2:2 by name**; the refusal string now says
+ why 4:4:0 cannot arrive either, and the inventory's two copies of it are
+ updated with the same text.
+
+## The two cells
+
+### Cell 1 — `420_odd65x65_key.obu` (4:2:0, odd luma): `y`
+
+| | |
+|---|---|
+| bytes | 2305 |
+| sha256 | `66986019a561f81130f407f426c4379b25e6e80c2cd9ce47d517b3216e9a03cf` |
+| fnv1a64 | `0xf55645c4b139e8f7` |
+| header | `seq_profile 0`, `max_frame 65x65`, `subsampling (1,1)`, 8-bit |
+| ours vs `aomdec` | **6403 == 6403 bytes, identical** (65*65 + 2*33*33) |
+
+Reproduce (no encoder, no ffmpeg, no lavfi — the whole point of the cell):
+
+```
+cargo run -p ec-av1 --example gen_coverage_cells -- crates/ec-av1/fixtures
+sha256sum crates/ec-av1/fixtures/420_odd65x65_key.obu
+```
+
+`aomenc` cannot produce this stream: it rounds the coded size DOWN to even
+(the formatsweep lane measured `testsrc2 131x131` y4m coming out as
+`max_frame=130x130`), so the encoder had to be told what size to DECLARE.
+`encode::encode_key_frame_at_size` is that entry, and the fixture is a 96x96
+card padded to the block grid with a 65x65 frame header.
+
+**Why the gate is not a rubber stamp.** The cell's whole content is the chroma
+extent: a 65-wide 4:2:0 frame has `ROUND_POWER_OF_TWO(65, 1) = 33` chroma
+columns (libaom `av1_common_plane_width`, `av1/common/av1_common_int.h`), not
+32. Measured mutations:
+
+| mutation | result |
+|---|---|
+| `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 |
+
+**Defect it exposed, fixed here.** `decode::ref_chroma_shape`'s 4:2:0
+fallback arm was `(width / 2, height / 2)` — a floor. The producer stores
+`round_ss(w,1) x round_ss(h,1)`, so every odd-dimension 4:2:0 REFERENCE was
+under-declared (12160 of 16384 `(w,h)` pairs over `1..=128`, per the
+function's own doc comment, which deferred the fix to "a lane that can bring
+odd-dimension 4:2:0 fixtures with it"). The arm is now the producer's crop.
+Red-before, measured: with the floor back, the existing routing test
+`a_reference_chroma_sample_count_routes_back_to_its_own_format` fails at
+`4:2:0 reference of 2x3 ... left (1, 1), right (1, 2)`. Even sizes are
+untouched — `(2k+1)/2 == k` — so no existing 4:2:0/4:2:2/4:4:4 reference
+changes shape.
+
+### Cell 2 — `440_request_is_422.obu` (4:4:0): the cell does not exist
+
+| | |
+|---|---|
+| bytes | 2014 |
+| sha256 | `4afaa5470c4e010d9d970086ef514680adfe801a579e4deeec582f52d13c5e7c` |
+| fnv1a64 | `0x98a1378df976253d` |
+| what it is | a 4:4:0 REQUEST at profile 2, which lands on `(1,0)` = 4:2:2 |
+| decoder | refuses by name (the 4:2:2 refusal) |
+
+Reproduce: same `cargo run` as cell 1.
+
+Spec 5.5.2 `color_config` codes `subsampling_y` ONLY when `subsampling_x` is
+1. The two places libaom says so:
+
+- reader — `av1/decoder/decodeframe.c:4171-4175`:
+ `subsampling_x = aom_rb_read_bit(rb); if (subsampling_x) subsampling_y = aom_rb_read_bit(rb); else subsampling_y = 0; // 444`
+- writer — `av1/encoder/bitstream.c:2466-2468`:
+ `assert(seq_params->subsampling_y == 0 && "4:4:0 subsampling not allowed in AV1");`
+
+So the coverage-matrix row was a MATRIX bug, not a decoder gap: aomenc has no
+`yuv440p` input path and ffmpeg's y4m muxer refuses the format, but those are
+consequences — no bit pattern anywhere produces `(0,1)`. There is no stream to
+decode, no fixture a decoder could be handed, and no oracle to compare
+against. The pin therefore carries the byte-level evidence instead: hand the
+writer `(0,1)` and it emits a header that reads back `(1,0)`.
+
+The gate `the_440_cell_is_not_a_codable_chroma_shape` proves the claim in
+three arms, and every arm has a measured mutation:
+
+| arm | what it measures | mutation | result |
+|---|---|---|---|
+| 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 |
+| 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` |
+| 3 PIN | the pinned bytes read back `(1,0)`, not `(0,1)`, and still refuse by name | — (byte pin) | green |
+
+Measured and recorded because it is the non-obvious half: mutating the
+**writer** alone does NOT put `(0,1)` into a round trip — the correct reader
+absorbs the extra bit as `separate_uv_delta_q`. The round-trip set is a
+property of the writer/reader PAIR; the byte-identity arm is what pins the
+writer's own half, and the reader arm is what pins the half a foreign stream
+meets. Both mutations were run.
+
+## Files
+
+| file | change |
+|---|---|
+| `crates/ec-av1/examples/gen_coverage_cells.rs` | NEW — the generator, both cells |
+| `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 |
+| `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 |
+| `crates/ec-av1/src/stream.rs` | two new gates; the 4:2:2/4:4:0 refusal string |
+| `crates/ec-av1/src/refusal_inventory.rs` | both copies of that string + the gate pairing |
+| `crates/ec-av1-syntax/src/sequence.rs` | UNCHANGED (mutated and reverted only) |
+| `crates/ec-av1/fixtures/420_odd65x65_key.obu`, `.../440_request_is_422.obu` | NEW pins (`git add -f`; `fixtures/` is gitignored) |
+
+## Gates
+
+- `an_odd_luma_420_key_frame_decodes_pixel_exact` — pin, header read from the
+ pin's own bytes, decoded extents (65x65 luma, 33x33 chroma), then
+ `assert_rawvideo_matches` against the instrumented `aomdec` (skips loudly
+ without an oracle; hard-fails under `EC_AV1_REQUIRE_AOMDEC`).
+- `the_440_cell_is_not_a_codable_chroma_shape` — the three arms above.
+- `a_reference_chroma_sample_count_routes_back_to_its_own_format` — existing,
+ its 4:2:0 expectation moved from the floor to the producer's crop.
+
+## not_done
+
+1. **No end-to-end odd-size INTER frame.** `ref_chroma_shape` is the
+ reference path, and this fixture is a single key frame because that is all
+ the ticket asked for and all the encoder's public entry points allow
+ (`encode_sequence` derives the declared size from the source picture and
+ `check_even`s it). The fix is red-before proven at the routing level and
+ the pin is red-before proven at the decode level, but no odd-size inter
+ stream decodes pixel-exact end to end, because producing one needs a sized
+ sequence entry (`encode_key_frame_at_size`'s inter sibling) that this lane
+ did not add. Whoever wants the inter arm should add that entry; the gate
+ then only needs a second pin.
+2. **The `ref_chroma_shape` `w == 1` column was measured, not witnessed.** The
+ ceil arm expresses `(1, round_ss(h,1))`, which the floor could not, so the
+ documented 127-pair residue is closed by construction; no stream this
+ decoder accepts has a 1-pixel-wide frame to test it on.
+3. **The 4:2:2 refusal is unchanged and still has no committed pixel witness**
+ (every committed 4:2:2 pin asserts refusal, not pixels; the decode
+ evidence needs the `EC_AV1_ALLOW_422_PROBE` patch-run-restore build, per
+ `lanes/av1422bigblock.report.md`). This lane did not touch that.
+4. **The 4:4:0 coverage-matrix row itself lives in
+ `lanes/av1formatsweep.report.md`**, a historical report this lane does not
+ edit. The correction is recorded here and in the refusal string; whoever
+ maintains the matrix should delete the row rather than mark it `–`.
+5. **No 12-bit or multi-frame odd-size variant.** One 8-bit key frame is the
+ cell; a 65x65 stream at 10/12 bits would need the encoder widened first
+ (it is 8-bit by design, `encode.rs`'s r2 decision).