forge
Explore
Log in

Don't you dare go Hollow

lane-av1422lift: lift the 4:2:2 sequence-header refusal; 4:2:2 decodes

Browse files at this commit

fdcfd811171aca0250f5c9517ce8260b754f549bAhmet Kaan GümüşParent: 59f61c7
The guard at `stream.rs` `if seq.subsampling_x != seq.subsampling_y` is
gone, the `refusal_inventory.rs` string and its `Proof::NegativeGate`
pairing are deleted in the SAME commit (the inventory gate asserts both
directions are empty, so a half-removal is red), and the residual
uncodable shape -- 4:4:0 `(0,1)`, which `ec-av1-syntax` cannot produce
because `color_config` reads `subsampling_y` only when `subsampling_x`
is 1 -- closes with an ASSERTION rather than a comment.

Seven gates whose only behavioural assertion was `err.contains(REFUSAL)`
are renamed and inverted into byte-exact decodes against ffmpeg 8.1.3:

* `a_non_420_subsampled_sequence_header_is_refused_by_name` ->
  `a_real_422_key_frame_and_inter_sequence_decode_pixel_exact`, on two
  NEW real 4:2:2 pins that replace its fake fixture (a profile-2 header
  bolted onto a 4:2:0 tile from this crate's own encoder, which could
  never be inverted into an exactness claim).
* `the_440_cell_is_not_a_codable_chroma_shape` arm 3 keeps its
  enumeration and its `(1,0)` read-back, and replaces the refusal with
  the one thing true of those bytes: the SEQUENCE HEADER, not the tile,
  fixes the decode's chroma geometry.
* the five `the_pinned_422_*` witnesses keep their size + fnv1a64 pins
  and now assert byte-exact planes, per frame, per plane.

New gates, each with a non-vacuity arm from the 4:2:2 coefficient-unit
census (`census_nonsub_units` / `census_nonsub_coded`, armed for `(1,0)`
by lane-av1422census422): 12-bit 4:2:2 and superres 4:2:2, which the
corpus had no cell for at all; 4:2:2 film grain, compared through the
POST-grain in-memory decode because `EC_AV1_FINAL_DUMP` is written
pre-grain; and the six closed corpus cells, byte-exact against ffmpeg.

`422_allskip_2f.obu` is the one cell whose identity is that it codes
nothing, so its chroma arm is asserted as a NEGATIVE measurement (units
walked, coefficients not coded) rather than inherited from the shared
body -- that is the phantom-residual read the cell exists to witness.

Prose corrected at every site named by `lanes/av1422liftrisk.report.md`:
`stream.rs` (guard block, `SeqFlags`, the 440 gate doc, the five "NO
committed test can decode a 4:2:2 stream" doc blocks, both
`sb128rect_chroma_replay_counters` tripwire gates, `cfl_ac_q3`), plus
`decode.rs` (`Chroma16` caller set, `SB128RECT_REPLAY_SPAN_MISMATCH_HITS`,
`RECT_TILED_CHROMA_NXN_HITS`, `INTRABC_RECT4_OWN_CHROMA422_HITS`),
`refusal_inventory.rs` (both strip-enumeration docs) and
`examples/gen_coverage_cells.rs` (module doc, cell-2 comment, printout).

NOT CLOSED: `s422_384x240` still diverges chroma-only (U=1780 V=1871 on
a 17-decode/16-display cell) -- the reserved group-tail chroma SKIP arm,
owned by another lane. The corpus therefore stands at 56/57 measured
here, not 51/51. THIS BRANCH MUST NOT LAND UNTIL THAT CELL CLOSES AND
THE CORPUS RE-MEASURES 51/51.
crates/ec-av1/examples/gen_coverage_cells.rsmodified+18 -10
@@ -29,12 +29,17 @@
29 //! the format ("yuv4mpeg can only handle yuv444p, yuv422p, yuv420p,29 //! the format ("yuv4mpeg can only handle yuv444p, yuv422p, yuv420p,
30 //! yuv411p and gray8") are consequences of that, not the reason. The pin30 //! 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, and31 //! 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 shape32+//! no coded subsampling bit below 12 bits) lands on `(1,0)`. The frame OBU
33-//! this decoder refuses by name. The frame OBU behind it is a real 4:2:033+//! behind it is a real 4:2:0 key frame's, byte for byte -- the subsampling
34-//! key frame's, byte for byte -- the subsampling lives only in the34+//! lives only in the sequence header -- so the pin is a HEADER witness, NOT
35-//! sequence header -- so the pin is a HEADER witness, not a decodable35+//! a decodable 4:2:2 stream. lane-av1422lift: it was never decodable as
36-//! 4:2:2 stream, and the gate36+//! one; the decoder used to refuse it at the sequence header, and now
37-//! `the_440_cell_is_not_a_codable_chroma_shape` says exactly that.37+//! admits the header, which is exactly why this pin may not be turned into
38+//! a 4:2:2 exactness gate. The gate
39+//! `the_440_cell_is_not_a_codable_chroma_shape` says exactly that, and the
40+//! real 4:2:2 exactness lives in `a_real_422_stream_decodes_pixel_exact`
41+//! and `the_pinned_422_corpus_cells_decode_pixel_exact`, which read
42+//! genuinely 4:2:2 pins.
38 //!43 //!
39 //! ```text44 //! ```text
40 //! cargo run -p ec-av1 --example gen_coverage_cells -- crates/ec-av1/fixtures45 //! cargo run -p ec-av1 --example gen_coverage_cells -- crates/ec-av1/fixtures
@@ -252,9 +257,11 @@ fn main() {
252 // OBU behind it is a real 4:2:0 key frame's, byte for byte: the257 // 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 is258 // 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 stream259 // 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 the260+ // (its tile is 4:2:0). lane-av1422lift: the decoder no longer refuses it
256- // claim, and the decoder refuses it by name, which is the honest261+ // by name, and that is NOT an endorsement -- the header now claims 4:2:2
257- // outcome for the shape the request lands on.262+ // over a 4:2:0 tile, so a decode of these bytes is a header/tile
263+ // mismatch. This pin stays a byte-level shape witness; every 4:2:2
264+ // exactness claim lives on genuinely 4:2:2 pins in `stream.rs`.
258 let tile_stream = ec_av1::encode::encode_key_frame(&card(WITNESS, WITNESS), Q_IDX, 0.5)265 let tile_stream = ec_av1::encode::encode_key_frame(&card(WITNESS, WITNESS), Q_IDX, 0.5)
259 .expect("encoding the witness tile")266 .expect("encoding the witness tile")
260 .stream;267 .stream;
@@ -306,7 +313,8 @@ fn main() {
306 );313 );
307 println!(314 println!(
308 "440_request_is_422: asked for subsampling (0,1) at profile {} -- got ({sx},{sy}) at \315 "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 + \316+ max_frame {mw}x{mh}, i.e. 4:2:2 (DECODED since lane-av1422lift, but these bytes carry \
317+ a 4:2:0 tile, so the pin is a shape witness and not an exactness witness); frame header + \
310 one tile ({} bytes) from a 4:2:0 {WITNESS}x{WITNESS} key frame",318 one tile ({} bytes) from a 4:2:0 {WITNESS}x{WITNESS} key frame",
311 seq.seq_profile,319 seq.seq_profile,
312 frame_bytes.len()320 frame_bytes.len()
crates/ec-av1/fixtures/422_inter_160x128_3f.obuadded+0 -0

Binary file changed

crates/ec-av1/fixtures/422_key_64x64.obuadded+0 -0

Binary file changed

crates/ec-av1/fixtures/s422_12bit_160x128.obuadded+0 -0

Binary file changed

crates/ec-av1/fixtures/s422_320x246.obuadded+0 -0

Binary file changed

crates/ec-av1/fixtures/s422_322x240.obuadded+0 -0

Binary file changed

crates/ec-av1/fixtures/s422_322x246.obuadded+0 -0

Binary file changed

crates/ec-av1/fixtures/s422_352x242_10b.obuadded+0 -0

Binary file changed

crates/ec-av1/fixtures/s422_416x242_10b.obuadded+0 -0

Binary file changed

crates/ec-av1/fixtures/s422_416x250_10b.obuadded+0 -0

Binary file changed

crates/ec-av1/fixtures/s422_grain_160x128.obuadded+0 -0

Binary file changed

crates/ec-av1/fixtures/s422_superres_160x128.obuadded+0 -0

Binary file changed

crates/ec-av1/src/decode.rsmodified+26 -16
@@ -2856,9 +2856,12 @@ thread_local! {
2856 /// Chroma units of the same walk whose grid is exactly 1x2 (4:4:4 32x64,2856 /// Chroma units of the same walk whose grid is exactly 1x2 (4:4:4 32x64,
2857 /// or 16x64 as two 16x32s).2857 /// or 16x64 as two 16x32s).
2858 static RECT_TILED_CHROMA_1X2_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };2858 static RECT_TILED_CHROMA_1X2_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2859- /// Chroma units of the same walk in any other multi-unit grid (2x2 and up2859+ /// Chroma units of the same walk in any other multi-unit grid (2x2 and
2860- /// -- only reachable at 4:2:2, which is refused, so this stays 0 on2860+ /// up). lane-av1422lift: 4:2:2 is DECODED, so this is no longer an arm
2861- /// every admitted stream; kept so the match above is exhaustive).2861+ /// no admitted stream can reach -- a 4:2:2 block whose chroma plane is
2862+ /// wider than tall relative to its luma span lands here. The corpus gate
2863+ /// `the_pinned_422_corpus_cells_decode_pixel_exact` reads this counter
2864+ /// as a non-vacuity arm; kept so the match above is exhaustive).
2862 static RECT_TILED_CHROMA_NXN_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };2865 static RECT_TILED_CHROMA_NXN_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2863 }2866 }
2864 2867
@@ -6136,9 +6139,10 @@ thread_local! {
6136 6139
6137 // lane-av1422luma: the ss (1,0) twin of `INTRABC_RECT4_OWN_CHROMA444_HITS`6140 // lane-av1422luma: the ss (1,0) twin of `INTRABC_RECT4_OWN_CHROMA444_HITS`
6138 // -- how many intra-BC 1:4 strips at 4:2:2 took the own-chroma (no pair)6141 // -- how many intra-BC 1:4 strips at 4:2:2 took the own-chroma (no pair)
6139-// route. Same caveat as the 4:4:4 counter: it proves REACH and nothing else,6142+// route. Same caveat as the 4:4:4 counter: it proves REACH and nothing else.
6140-// and 4:2:2 is refused at the sequence header, so no committed test can read6143+// lane-av1422lift: 4:2:2 is DECODED, so committed tests CAN read this
6141-// it (the count in `lanes/av1422luma.report.md` is from a bypassed probe build).6144+// counter now; `the_pinned_422_corpus_cells_decode_pixel_exact` reads its
6145+// delta on every corpus row.
6142 thread_local! {6146 thread_local! {
6143 static INTRABC_RECT4_OWN_CHROMA422_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };6147 static INTRABC_RECT4_OWN_CHROMA422_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
6144 }6148 }
@@ -17005,9 +17009,14 @@ fn decode_block_rect4(
17005 // 4:2:0 codes 16x4/4x16 (`TxbSet::Chroma8`); 4:4:4 codes the strip17009 // 4:2:0 codes 16x4/4x16 (`TxbSet::Chroma8`); 4:4:4 codes the strip
17006 // itself, 32x8/8x32 (`get_txsize_entropy_ctx(TX_32X8)` =17010 // itself, 32x8/8x32 (`get_txsize_entropy_ctx(TX_32X8)` =
17007 // `(wide_log2 + high_log2 + 1) >> 1` = the 16x16 set,17011 // `(wide_log2 + high_log2 + 1) >> 1` = the 16x16 set,
17008- // `TxbSet::Chroma16`). The caller set is closed -- this reader only17012+ // `TxbSet::Chroma16`). The caller set is closed -- this reader only ever
17009- // ever sees 32x8 / 8x32 luma and the sequence header admits ss 0/017013+ // sees 32x8 / 8x32 luma. lane-av1422lift: this sentence used to end "and
17010- // and 1/1 only -- so the table is exhaustive.17014+ // the sequence header admits ss 0/0 and 1/1 only -- so the table is
17015+ // exhaustive", which was a claim about a guard rather than about this
17016+ // reader. The header admits ss (1,1), (1,0) and (0,0), and the (1,0)
17017+ // 4:2:2 arm is dispatched a few lines below (`chroma422_rect32`), so the
17018+ // table's exhaustiveness comes from the reader's own luma shape -- which
17019+ // is what the sentence now claims.
17011 let chroma422_rect32 = (chroma_w, chroma_h) == (4, 32) && ss_x(fctx) == 1 && ss_y(fctx) == 0;17020 let chroma422_rect32 = (chroma_w, chroma_h) == (4, 32) && ss_x(fctx) == 1 && ss_y(fctx) == 0;
17012 let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (chroma_w, chroma_h) {17021 let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (chroma_w, chroma_h) {
17013 (16, 4) => (TxbSet::Chroma8, &SCAN_16X4[..]),17022 (16, 4) => (TxbSet::Chroma8, &SCAN_16X4[..]),
@@ -23406,13 +23415,14 @@ thread_local! {
23406 /// ... and the number of non-skip 128-root rect BLOCKS whose replay23415 /// ... and the number of non-skip 128-root rect BLOCKS whose replay
23407 /// height differs from the unit's own LUMA-MI height -- the signature of the23416 /// height differs from the unit's own LUMA-MI height -- the signature of the
23408 /// width passed to both axes (`luma_span` where the in-loop stamp used23417 /// width passed to both axes (`luma_span` where the in-loop stamp used
23409- /// `luma_span_h`). Zero on every stream this decoder admits: both23418+ /// `luma_span_h`). lane-av1422lift: this used to read zero on every
23410- /// supported chroma formats have `ss_x == ss_y` (4:2:0 and 4:4:4), and23419+ /// admitted stream because 4:2:2 -- the one format whose two spans differ
23411- /// 4:2:2 -- the one format whose two spans differ -- is refused by name23420+ /// -- was refused by name at the sequence header. It is DECODED now, so
23412- /// at the sequence header (`stream::decode_frame`), so the arm is23421+ /// this is a REAL detector, not a defensive arm: a hardcoded 4:2:0 span on
23413- /// defensive until that format is ported. The counter turns a future23422+ /// a 4:2:2 stream lands here and reads non-zero. The two 4:2:0/4:4:4
23414- /// 4:2:2 admission (or any hardcoded span) into a named red gate instead23423+ /// tripwire gates that assert zero keep asserting zero; the 4:2:2 row of
23415- /// of silent mi-state corruption.23424+ /// `the_pinned_422_corpus_cells_decode_pixel_exact` asserts it stays zero
23425+ /// there too, which is the claim that replaces "it cannot fire".
23416 pub(crate) static SB128RECT_REPLAY_SPAN_MISMATCH_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };23426 pub(crate) static SB128RECT_REPLAY_SPAN_MISMATCH_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
23417 }23427 }
23418 23428
crates/ec-av1/src/refusal_inventory.rsmodified+21 -30
@@ -134,20 +134,6 @@ const REFUSALS: &[&str] = &[
134 // (`encoder.c:2404`), so an untiled `smptebars=size=128x96` source gives134 // (`encoder.c:2404`), so an untiled `smptebars=size=128x96` source gives
135 // `allow_intrabc = 0` with AND without `--tune-content=screen`, while the135 // `allow_intrabc = 0` with AND without `--tune-content=screen`, while the
136 // 256x192 `-vf tile=2x2` source gives `= 1` at 8, 10 and 12 bits.136 // 256x192 `-vf tile=2x2` source gives `= 1` at 8, 10 and 12 bits.
137- // lane-av1txr: the silent-garbage guard. A 4:4:4/4:2:2 stream used to
138- // decode with no refusal and wrong pixels (every chroma extent is
139- // hardcoded 4:2:0, the probe emits 4:2:0 planes only); it is now refused
140- // at the sequence header. Gate:
141- // `a_non_420_subsampled_sequence_header_is_refused_by_name`.
142- // lane-av1odd440: the string gained its 4:4:0 clause. `subsampling_y` is
143- // coded only when `subsampling_x` is 1 (spec 5.5.2; libaom
144- // `av1_read_color_config`, `av1/decoder/decodeframe.c:4171-4175`, and its
145- // writer's own `assert(..., "4:4:0 subsampling not allowed in AV1")` at
146- // `av1/encoder/bitstream.c:2467-2468`), so (0,1) cannot reach this check --
147- // the reachable set is 4:2:0, 4:2:2 and 4:4:4, and only 4:2:2 lands here.
148- // Gate: `the_440_cell_is_not_a_codable_chroma_shape`, which enumerates
149- // the whole reachable set through this crate's own writer AND reader.
150- "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",
151 // lane-av1txr-r2 added, lane-av1-qmatrix RETIRED: the third member of the137 // lane-av1txr-r2 added, lane-av1-qmatrix RETIRED: the third member of the
152 // silent-garbage family (`using_qmatrix`/`qm_y`/`qm_u`/`qm_v`, refused by138 // silent-garbage family (`using_qmatrix`/`qm_y`/`qm_u`/`qm_v`, refused by
153 // name at the frame header) now DEQUANTISES through libaom's139 // name at the frame header) now DEQUANTISES through libaom's
@@ -520,17 +506,16 @@ const PROVEN: &[(&str, &str, Proof)] = &[
520 // that refused pre-lift) and the compound-warp arm witnesses through506 // that refused pre-lift) and the compound-warp arm witnesses through
521 // `a_real_compound_global_warp_12bit_stream_decodes_pixel_exact`507 // `a_real_compound_global_warp_12bit_stream_decodes_pixel_exact`
522 // (hard `compound_warp_hits > 0`).508 // (hard `compound_warp_hits > 0`).
523- // lane-av1txr: the guard's own gate builds a profile-1 and a profile-2509+ // lane-av1422lift: the 4:2:2 sequence-header refusal is GONE and so is
524- // sequence header by hand and asserts each refuses by name while the510+ // this pairing. The tuple named `a_non_420_subsampled_sequence_header_is_
525- // profile-0 CONTROL still decodes -- the refusal is exercised, not merely511+ // refused_by_name` as the gate that refused (1,0); that gate asserted a
526- // present. lane-av1odd440 adds the second gate named here, which512+ // REFUSAL STRING, so it could not fail on a tree where 4:2:2 decode was
527- // enumerates every chroma shape a `color_config` can code and pins the513+ // completely broken -- it passed unchanged on the broken tree and would
528- // bytes a 4:4:0 request actually produces (`440_request_is_422.obu`).514+ // have kept passing if the port had been reverted. Its replacement
529- (515+ // `a_real_422_stream_decodes_pixel_exact` (and the corpus battery
530- "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",516+ // `the_pinned_422_corpus_cells_decode_pixel_exact`) assert BYTE-EXACT
531- "a_non_420_subsampled_sequence_header_is_refused_by_name",517+ // planes against ffmpeg on real 4:2:2 streams, with the
532- Proof::NegativeGate,518+ // per-plane coefficient-unit census as the non-vacuity arm.
533- ),
534 // lane-av1txr-r2 paired, lane-av1-qmatrix RETIRED with its gate: the519 // lane-av1txr-r2 paired, lane-av1-qmatrix RETIRED with its gate: the
535 // refusal's witness is now520 // refusal's witness is now
536 // `a_real_aomenc_quantisation_matrix_stream_decodes_pixel_exact`, which521 // `a_real_aomenc_quantisation_matrix_stream_decodes_pixel_exact`, which
@@ -1731,10 +1716,13 @@ mod tests {
1731 /// The subsampling domain is `{(0,0), (1,0), (1,1)}` and excludes1716 /// The subsampling domain is `{(0,0), (1,0), (1,1)}` and excludes
1732 /// `(0,1)`: `ec-av1-syntax`'s `color_config` only ever READS1717 /// `(0,1)`: `ec-av1-syntax`'s `color_config` only ever READS
1733 /// `subsampling_y` when `subsampling_x == 1` (sequence.rs:481), so1718 /// `subsampling_y` when `subsampling_x == 1` (sequence.rs:481), so
1734- /// `(0,1)` is uncodable. `(1,0)` is 4:2:2, refused at the sequence1719+ /// `(0,1)` is uncodable. `(1,0)` is 4:2:2. It is walked because that is
1735- /// header by `a_non_420_subsampled_sequence_header_is_refused_by_name`1720+ /// the codable domain, NOT because a guard stands in the way: as of
1736- /// -- it is walked anyway, so the proof does not depend on that guard1721+ /// lane-av1422lift the sequence header no longer refuses 4:2:2 at all, so
1737- /// staying in place.1722+ /// the sentence this replaces ("refused at the sequence header by
1723+ /// `a_non_420_subsampled_sequence_header_is_refused_by_name`") names a
1724+ /// gate that no longer exists. The walk was already right; its stated
1725+ /// reason was not.
1738 #[test]1726 #[test]
1739 fn every_chroma_unit_decode_block_rect_can_present_has_a_coefficient_table() {1727 fn every_chroma_unit_decode_block_rect_can_present_has_a_coefficient_table() {
1740 let src = include_str!("decode.rs");1728 let src = include_str!("decode.rs");
@@ -2023,7 +2011,10 @@ mod tests {
2023 /// this half was wrong: "the header refuses it" is a statement about2011 /// this half was wrong: "the header refuses it" is a statement about
2024 /// today's tree, not about the strip domain, and a domain that shrinks2012 /// today's tree, not about the strip domain, and a domain that shrinks
2025 /// silently when a guard moves is not an enumeration. `(1,0)` is walked2013 /// silently when a guard moves is not an enumeration. `(1,0)` is walked
2026- /// here anyway, so this proof does not depend on the guard staying.2014+ /// here anyway, so this proof does not depend on the guard staying -- and
2015+ /// as of lane-av1422lift it does not depend on the guard EXISTING: 4:2:2
2016+ /// decodes, and this enumeration is what says the decode has a
2017+ /// coefficient table for every chroma unit it can present.
2027 ///2018 ///
2028 /// The 32-per-axis cap is what keeps 4:2:2 covered without new table2019 /// The 32-per-axis cap is what keeps 4:2:2 covered without new table
2029 /// arms: a 4:2:0 32x64 strip is a 16x32 chroma unit and its 4:2:22020 /// arms: a 4:2:0 32x64 strip is a 16x32 chroma unit and its 4:2:2
crates/ec-av1/src/stream.rsmodified+810 -165
@@ -318,9 +318,13 @@ pub fn intra128_lossless_counters() -> usize {
318 318
319 /// lane-av1-128rectspan: chroma transform units re-stamped by319 /// lane-av1-128rectspan: chroma transform units re-stamped by
320 /// `decode_block_128rect`'s end-of-block replay, and how many of those320 /// `decode_block_128rect`'s end-of-block replay, and how many of those
321-/// replays stamped a height that was not the unit's own (the 4:2:2 signature321+/// replays stamped a height that was not the unit's own. lane-av1422lift:
322-/// -- zero on every stream this decoder admits, since 4:2:2 is refused by322+/// that mismatch was described as "the 4:2:2 signature -- zero on every
323-/// name at the sequence header).323+/// stream this decoder admits, since 4:2:2 is refused by name at the
324+/// sequence header". 4:2:2 is decoded now, so the mismatch half is a live
325+/// detector on 4:2:2 streams and stays zero only because the per-axis span
326+/// is correct; the 4:2:2 rows of
327+/// `the_pinned_422_corpus_cells_decode_pixel_exact` assert that.
324 pub fn sb128rect_chroma_replay_counters() -> (usize, usize) {328 pub fn sb128rect_chroma_replay_counters() -> (usize, usize) {
325 crate::decode::sb128rect_chroma_replay_hits()329 crate::decode::sb128rect_chroma_replay_hits()
326 }330 }
@@ -1381,11 +1385,15 @@ pub(crate) struct SeqFlags {
1381 pub(crate) mono_chrome: bool,1385 pub(crate) mono_chrome: bool,
1382 pub(crate) order_hint_bits: u32,1386 pub(crate) order_hint_bits: u32,
1383 pub(crate) mc_identity: bool,1387 pub(crate) mc_identity: bool,
1384- /// lane-av1txr: `color_config.subsampling_x/y` (spec 5.5.2). The decoder1388+ /// lane-av1txr: `color_config.subsampling_x/y` (spec 5.5.2). These used
1385- /// itself hardcodes 4:2:0 everywhere, so these exist only for the1389+ /// to exist only for the sequence-level refusal -- the decoder hardcoded
1386- /// sequence-level refusal in [`decode_stream_with`] -- nothing downstream1390+ /// 4:2:0 at every chroma extent. lane-av1422lift: that is no longer true
1387- /// reads them. A monochrome header parses as 1,1, so `!(1,1)` singles out1391+ /// and these are load-bearing on the DECODE path: `decode_stream_with`
1388- /// 4:4:4 (profile 1 / sRGB) and 4:2:2 (profile 2 below 12-bit).1392+ /// publishes both through `decode::set_subsampling` into `FrameCtx`, and
1393+ /// every chroma extent, plane allocation, output crop, deblock/CDEF crop
1394+ /// and restoration grid below reads them PER AXIS. A monochrome header
1395+ /// parses as 1,1 and is unaffected. The only shape these cannot carry is
1396+ /// (0,1) 4:4:0, which the header cannot code.
1389 pub(crate) subsampling_x: u8,1397 pub(crate) subsampling_x: u8,
1390 pub(crate) subsampling_y: u8,1398 pub(crate) subsampling_y: u8,
1391 }1399 }
@@ -1774,38 +1782,36 @@ fn decode_frame(
1774 // deleted; the two-arm witness is1782 // deleted; the two-arm witness is
1775 // `a_real_aomenc_12bit_film_grain_stream_decodes_pixel_exact`).1783 // `a_real_aomenc_12bit_film_grain_stream_decodes_pixel_exact`).
1776 // lane-av1txr: `color_config.subsampling_x/y` (spec 5.5.2) are parsed by1784 // lane-av1txr: `color_config.subsampling_x/y` (spec 5.5.2) are parsed by
1777- // `ec-av1-syntax` -- profile 1 forces 4:4:4, profile 2 below 12-bit forces1785+ // `ec-av1-syntax`. This block used to REFUSE every `ss_x != ss_y` header by
1778- // 4:2:2, and the sRGB identity description forces full-range 4:4:4 -- but1786+ // name, on the theory that every chroma extent was hardcoded 4:2:0
1779- // the decoder reads them NOWHERE: every chroma extent is hardcoded 4:2:01787+ // (`bw / 2, bh / 2` at every rect site, `chroma_side = side / 2` in
1780- // (`let (chroma_w, chroma_h) = (bw / 2, bh / 2)` at every rect site,1788+ // `decode_block`). Both halves of that theory are now false: the per-axis
1781- // `chroma_side = side / 2` in `decode_block`) and the probe emits 4:2:01789+ // port replaced every one of those extents with `>> ss_x` / `>> ss_y`
1782- // planes only. Measured consequence: EVERY 4:4:4 stream desyncs at the1790+ // reads, and 4:4:4 (0,0) already decoded through them.
1783- // first chroma transform (a444-cu6 block (0,0): aomdec reads1791+ // lane-av1422lift: 4:2:2 (1,0) is DECODED. The refusal string, its
1784- // `EC_COEFF plane=1 tx=TX_8X16` at rng 39857 where ours reads a 4-wide,1792+ // `refusal_inventory.rs` row and its `Proof::NegativeGate` pairing are
1785- // 8-high 4:2:0 chroma block at the same rng) and then decodes pixels that1793+ // deleted in this commit -- a refused format that decodes is a false
1786- // are silently wrong. Refuse by name rather than return garbage. A1794+ // claim, and the gate that asserted the refusal could not fail on a tree
1787- // `num_planes == 1` (monochrome) header keeps its parsed 1,1 and is1795+ // where 4:2:2 decode was completely broken.
1788- // unaffected. Gates: `a_non_420_subsampled_sequence_header_is_refused_by_1796+ // lane-av1odd440, kept as an ASSERTION: `subsampling_y` is coded ONLY when
1789- // name` below (hand-built profile 1/2 headers plus a real aomenc 4:4:41797+ // `subsampling_x` is 1 (spec 5.5.2's `color_config`; libaom
1790- // stream).1798+ // `av1_read_color_config`, `av1/decoder/decodeframe.c:4171-4175`, and its
1791- // lane-av1-444: 4:4:4 (ss 0,0) is decoded. 4:2:2 (ss_x != ss_y) is not.1799+ // writer's own `assert(seq_params->subsampling_y == 0 && "4:4:0
1792- // lane-av1odd440: the CONDITION is left as `ss_x != ss_y` because that is1800+ // subsampling not allowed in AV1")`, `av1/encoder/bitstream.c:2467-2468`),
1793- // what a parsed header can violate, but the STRING now names the only1801+ // so a parsed header can carry (1,1), (1,0) or (0,0) and never (0,1):
1794- // shape that can: `subsampling_y` is coded ONLY when `subsampling_x` is1802+ // 4:4:0 is not a cell a decoder can be handed at all. That used to be a
1795- // 1 (spec 5.5.2's `color_config`; libaom `av1_read_color_config`,1803+ // comment plus a refusal string naming the shape; with the refusal gone
1796- // `av1/decoder/decodeframe.c:4171-4175`, and its writer's own1804+ // the residual is an unreachable arm, and this repo closes those with an
1797- // `assert(seq_params->subsampling_y == 0 && "4:4:0 subsampling not1805+ // assertion, never prose. The gate `the_440_cell_is_not_a_codable_chroma_
1798- // allowed in AV1")`, `av1/encoder/bitstream.c:2467-2468`), so a header can1806+ // shape` proves the whole reachable set through this crate's own writer
1799- // carry (1,1), (1,0) or (0,0) and never (0,1) -- 4:4:0 is not a cell a1807+ // AND reader.
1800- // decoder can be handed at all. The gate1808+ assert!(
1801- // `the_440_cell_is_not_a_codable_chroma_shape` proves the whole reachable1809+ !(seq.subsampling_x == 0 && seq.subsampling_y == 1),
1802- // set, so this string is not a claim about a shape that cannot arrive.1810+ "AV1 decode_stream: a parsed color_config carried 4:4:0 (subsampling_x=0, \
1803- if seq.subsampling_x != seq.subsampling_y {1811+ subsampling_y=1); subsampling_y is coded only when subsampling_x is 1 \
1804- return Err(Error::unsupported(1812+ (spec 5.5.2), so this shape cannot be produced by ec-av1-syntax's \
1805- "AV1 decode_stream",1813+ sequence_header -- the parser is wrong, not the caller"
1806- "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",1814+ );
1807- ));
1808- }
1809 // lane-av1-qmatrix: `quantization_params.using_qmatrix` + `qm_y`/`qm_u`/1815 // lane-av1-qmatrix: `quantization_params.using_qmatrix` + `qm_y`/`qm_u`/
1810 // `qm_v` (spec 5.9.12) select per-plane INVERSE QUANTISATION MATRICES --1816 // `qm_v` (spec 5.9.12) select per-plane INVERSE QUANTISATION MATRICES --
1811 // spec 7.12.3's per-position `dqv` scale, libaom `get_dqv` over1817 // spec 7.12.3's per-position `dqv` scale, libaom `get_dqv` over
@@ -2301,55 +2307,138 @@ pub(crate) mod tests {
2301 picture2307 picture
2302 }2308 }
2303 2309
2304- /// lane-av1txr: a sequence header describing any chroma shape but 4:2:0 is2310+ /// lane-av1422lift: THE 4:2:2 LIFT, in two pins. This test is the renamed,
2305- /// refused by name, because the decoder reconstructs every chroma extent2311+ /// inverted replacement for `a_non_420_subsampled_sequence_header_is_
2306- /// at hardcoded 4:2:0 (`bw / 2, bh / 2` at every rect site) and the probe2312+ /// refused_by_name`, and the two fixtures replace that gate's fixture --
2307- /// emits 4:2:0 planes only -- a 4:4:4 stream "decodes" into silently wrong2313+ /// a hand-built profile-2 header bolted onto a 4:2:0 TILE from this
2308- /// pixels (measured: a444-cu6's first chroma transform reads a 4x2-wide/2314+ /// crate's own encoder, which could never be inverted into an exactness
2309- /// 8-high 4:2:0 chroma at aomdec's `TX_8X16` entry rng 39857, then2315+ /// claim no matter how the assert was flipped (class `refusal-lifted-
2310- /// desyncs; every 4:4:4 fixture measured byte-differs from ffmpeg).2316+ /// without-a-gate`, and the risk study's R6).
2311 ///2317 ///
2312- /// Reachability, not a pixel claim: the header is written at the two2318+ /// Both pins are REAL 4:2:2 streams from libaom's own writer over a
2313- /// profiles that force a non-4:2:0 shape (spec 5.5.2 -- profile 1 forces2319+ /// y4m whose header line is `C422`, so every chroma symbol in them is a
2314- /// 4:4:4 with no coded bit; profile 2 below 12-bit forces 4:2:2) and the2320+ /// 4:2:2 chroma symbol. Provenance (both, verbatim, no other encoder):
2315- /// tile is never reached. The 4:2:0 CONTROL below proves the refusal is2321+ ///
2316- /// about the shape, not about this construction.2322+ /// ```text
2317- #[test]2323+ /// aomenc --codec=av1 --profile=2 \
2318- fn a_non_420_subsampled_sequence_header_is_refused_by_name() {2324+ /// --input-chroma-subsampling-x=1 --input-chroma-subsampling-y=0 \
2319- const NAME: &str = "a_non_420_subsampled_sequence_header_is_refused_by_name";2325+ /// --passes=1 --end-usage=q --cq-level=24 --cpu-used=0 \
2320- const REFUSAL: &str = "a chroma format of 4:2:2";2326+ /// --threads=1 --row-mt=0 --obu -o <pin> <source.y4m>
2321- let fctx = &crate::decode::FrameCtx::new();2327+ /// ```
2322- let picture = test_card(64, 64);2328+ ///
2323- let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();2329+ /// * `422_key_64x64.obu` -- 755 bytes, sha256
2324- for (profile, label, sx, sy) in [(2u8, "4:2:2", 1u8, 0u8)] {2330+ /// `3c9396c9e42701d720419ec2cb5577387e305482df0cb150f7f0b965edeaaffc`,
2325- let color = ec_av1_syntax::ColorConfig {2331+ /// fnv1a64 `0x87fc569cf53bcbc6`. A single 64x64 8-bit KEY frame
2326- num_planes: 3,2332+ /// (`--limit=1 --kf-min-dist=0 --kf-max-dist=0`) over a
2327- subsampling_x: sx,2333+ /// hand-generated two-frame integer `C422` card source, the second
2328- subsampling_y: sy,2334+ /// source frame unused by the `--limit=1`. The smallest thing that can
2329- ..Default::default()2335+ /// say "4:2:2 intra reconstructs".
2330- };2336+ /// * `422_inter_160x128_3f.obu` -- 6522 bytes, sha256
2331- let (mut seq, header) =2337+ /// `7b54834c18f5fdc0e8606a6dc5bf4ff368402417d87fcfc2ab9758e4e9164902`,
2332- crate::encode::key_frame_headers_colour(64, 64, 100, color).unwrap();2338+ /// fnv1a64 `0xf87eba3bf4fc2bb8`. Three 160x128 8-bit frames with a
2333- seq.seq_profile = profile;2339+ /// panning square
2334- let mut stream = crate::sequence::sequence_header_obu(&seq).unwrap();2340+ /// (`--limit=3 --kf-min-dist=3 --kf-max-dist=3`, so frames 1 and 2 are
2335- stream2341+ /// INTER), over a three-frame integer `C422` card source whose square
2336- .extend_from_slice(&crate::frame::frame_obu(&seq, &header, &encoded.tile).unwrap());2342+ /// moves (6,4) -> (9,6) -> (12,8). This is what exercises the
2337- let err = decode_stream(&stream).unwrap_err().to_string();2343+ /// inter-predicted 4:2:2 chroma reference: a decoder that walked the
2338- assert!(2344+ /// key frame correctly and then predicted chroma from a 4:2:0-shaped
2339- err.contains(REFUSAL),2345+ /// reference passes the first pin and reds here.
2340- "{NAME}: expected the non-4:2:0 refusal for the {label} header, got: {err}"2346+ ///
2341- );2347+ /// Both are asserted BYTE-EXACT against ffmpeg 8.1.3's own rawvideo of
2348+ /// the same bytes at `yuv422p`, per plane and per frame, with the
2349+ /// per-plane coefficient-unit census as the non-vacuity arm (see
2350+ /// [`assert_422_stream_pixel_exact`]). A gate whose only assertion was
2351+ /// `err.contains(REFUSAL)` would have passed unchanged on a tree where
2352+ /// 4:2:2 decode was completely broken; that is what this replaces.
2353+ #[test]
2354+ fn a_real_422_key_frame_and_inter_sequence_decode_pixel_exact() {
2355+ const NAME: &str = "a_real_422_key_frame_and_inter_sequence_decode_pixel_exact";
2356+ if !have_ffmpeg() {
2357+ eprintln!("SKIP {NAME}: no ffmpeg");
2358+ return;
2342 }2359 }
2343- // CONTROL: the same construction at profile 0 (4:2:0) still decodes.2360+ let key = crate_pin("422_key_64x64.obu");
2344- let (seq, header) = crate::encode::key_frame_headers(64, 64, 100).unwrap();2361+ let key_stream = read_pin(&key, 755, 0x87fc569cf53bcbc6, NAME);
2345- let mut stream = crate::sequence::sequence_header_obu(&seq).unwrap();2362+ let (units, _) = assert_422_stream_pixel_exact(NAME, &key_stream, 64, 64, 1, 8, true);
2346- stream.extend_from_slice(&crate::frame::frame_obu(&seq, &header, &encoded.tile).unwrap());2363+ let (l, u, v) = (units[0], units[1], units[2]);
2347- let frames = decode_stream(&stream).expect("the 4:2:0 control must decode");2364+ assert!(
2348- assert_eq!(2365+ l > 0 && u > 0 && v > 0,
2349- frames.len(),2366+ "{NAME}: the key-frame pin walked no 4:2:2 chroma units [{l}, {u}, {v}]"
2350- 1,
2351- "{NAME}: the 4:2:0 control decoded no frame"
2352 );2367 );
2368+
2369+ let inter = crate_pin("422_inter_160x128_3f.obu");
2370+ let inter_stream = read_pin(&inter, 6522, 0xf87eba3bf4fc2bb8, NAME);
2371+ let (units, _) = assert_422_stream_pixel_exact(NAME, &inter_stream, 160, 128, 3, 8, true);
2372+ let (l, u, v) = (units[0], units[1], units[2]);
2373+ assert!(
2374+ u > 0 && v > 0,
2375+ "{NAME}: the inter pin walked no 4:2:2 chroma units [{l}, {u}, {v}] -- the inter \
2376+ chroma reference path was never reached"
2377+ );
2378+ }
2379+
2380+ /// lane-av1422lift: 4:2:2 at 12 bits, and 4:2:2 with superres, are the two
2381+ /// cells the corpus had no coverage for at all (the risk study's R3 and
2382+ /// R9: the sweep recipe passed no 12-bit depth and no `--superres-mode`,
2383+ /// so every 4:2:2 measurement in the tree was 8- or 10-bit, none
2384+ /// superres). Both are pinned and both are byte-exact here.
2385+ ///
2386+ /// `s422_12bit_160x128.obu` -- 9214 bytes, sha256
2387+ /// `eacc70f75c82ad7d795efbd0242aa4ee33db917b8c1a3570ebce2570ee8bc245`,
2388+ /// fnv1a64 `0xa62b8e3fe6f60ae5`. 160x128, 12-bit, 3 frames,
2389+ /// `yuv422p12le` per ffprobe, profile 2 ("Professional").
2390+ ///
2391+ /// **Provenance is ffmpeg's libaom-av1 wrapper, not aomenc, and the
2392+ /// reason is measured, not preferred.** aomenc's own 12-bit y4m path
2393+ /// issues `AV1E_SET_CHROMA_SUBSAMPLING_X` (apps/aomenc.c:2272-2278,
2394+ /// reached whenever the input is not 4:2:0 and the bit depth is 12)
2395+ /// BEFORE `aom_codec_enc_config_set`, and on this libaom that control
2396+ /// returns `AOM_CODEC_INTERNAL_ERROR` for any non-4:2:0 shape -- measured
2397+ /// on four independently built trees
2398+ /// (`~/.cache/aom-oracle`, `aom-affine`, `aom-oracle2`, `aom-oracle3`):
2399+ /// `C422p12` and `C444p12` both die with "Failed to set chroma
2400+ /// subsampling x", while `C420p12` and the 8-bit `C422`/`C444` both
2401+ /// encode. It is not a 4:2:2-specific gap (12-bit 4:4:4 fails too) and
2402+ /// not a 4:2:0 gap (12-bit 4:2:0 encodes). The same control succeeds at
2403+ /// 8 bits, so the failure is the 12-bit configuration order, and the
2404+ /// workaround is a wrapper that sets the codec config first. ffmpeg's
2405+ /// libaom-av1 does exactly that:
2406+ ///
2407+ /// ```text
2408+ /// ffmpeg -f lavfi -i "testsrc2=size=160x128:rate=1:duration=3" \
2409+ /// -pix_fmt yuv422p12le -c:v libaom-av1 -profile:v 2 -b:v 0 -crf 30 \
2410+ /// -cpu-used 8 -auto-alt-ref 0 -lag-in-frames 0 \
2411+ /// -strict experimental -f obu s422_12bit_160x128.obu
2412+ /// ```
2413+ ///
2414+ /// That is libaom's encoder either way -- ffmpeg links it and calls
2415+ /// `aom_codec_encode` -- and the oracle side is ffmpeg's own
2416+ /// `yuv422p12le` rawvideo decode of the same bytes, so the pin and the
2417+ /// oracle come from the same library, which is the property that makes
2418+ /// byte-exactness a claim about OUR decoder rather than about a
2419+ /// disagreement between two encoders.
2420+ ///
2421+ /// `s422_superres_160x128.obu` -- 5304 bytes, sha256
2422+ /// `5852ff2c273cb773c4886762c6a6f2cce6e12065a690eb3a5ca2119c0b6f2957`,
2423+ /// fnv1a64 `0x0789d1b2851b94ae`. 160x128, 8-bit, 3 frames, `--superres-
2424+ /// mode=1` (fixed) over a `C422` testsrc2 source, encoded by the
2425+ /// aomenc recipe above plus `--superres-mode=1`. Superres is the one
2426+ /// 4:2:2 path whose output crop is `(round_ss(w,1) x round_ss(h,0))` at
2427+ /// the UPSCALED size, and it had no 4:2:2 cell anywhere.
2428+ #[test]
2429+ fn a_real_422_12bit_and_superres_stream_decode_pixel_exact() {
2430+ const NAME: &str = "a_real_422_12bit_and_superres_stream_decode_pixel_exact";
2431+ if !have_ffmpeg() {
2432+ eprintln!("SKIP {NAME}: no ffmpeg");
2433+ return;
2434+ }
2435+ let hbd = crate_pin("s422_12bit_160x128.obu");
2436+ let hbd_stream = read_pin(&hbd, 9214, 0xa62b8e3fe6f60ae5, NAME);
2437+ assert_422_stream_pixel_exact(NAME, &hbd_stream, 160, 128, 3, 12, true);
2438+
2439+ let sr = crate_pin("s422_superres_160x128.obu");
2440+ let sr_stream = read_pin(&sr, 5304, 0x0789d1b2851b94ae, NAME);
2441+ assert_422_stream_pixel_exact(NAME, &sr_stream, 160, 128, 3, 8, true);
2353 }2442 }
2354 2443
2355 /// lane-av1odd440, CELL 1 of 2: `4:2:0 with an ODD luma dimension`, the2444 /// lane-av1odd440, CELL 1 of 2: `4:2:0 with an ODD luma dimension`, the
@@ -2486,12 +2575,20 @@ pub(crate) mod tests {
2486 /// when it is handed `subsampling (0,1)` at profile 2 -- profile 22575 /// when it is handed `subsampling (0,1)` at profile 2 -- profile 2
2487 /// below 12 bits is 4:2:2 and codes no subsampling bit at all, so the2576 /// below 12 bits is 4:2:2 and codes no subsampling bit at all, so the
2488 /// request lands on `(1,0)`. The pin is asserted to read back `(1,0)`,2577 /// request lands on `(1,0)`. The pin is asserted to read back `(1,0)`,
2489- /// NOT `(0,1)`, and the decoder is asserted to refuse it by name,2578+ /// NOT `(0,1)`. Its frame OBU is a 4:2:0 key frame's, so the pin is a
2490- /// which is the honest outcome for the shape a 4:4:0 request actually2579+ /// HEADER witness, not a decodable 4:2:2 stream -- nothing here claims
2491- /// yields. Its frame OBU is a 4:2:0 key frame's, so the pin is a HEADER
2492- /// witness, not a decodable 4:2:2 stream -- nothing here claims
2493 /// pixels for it. Provenance: `examples/gen_coverage_cells.rs`, `cargo2580 /// pixels for it. Provenance: `examples/gen_coverage_cells.rs`, `cargo
2494 /// run -p ec-av1 --example gen_coverage_cells -- crates/ec-av1/fixtures`.2581 /// run -p ec-av1 --example gen_coverage_cells -- crates/ec-av1/fixtures`.
2582+ ///
2583+ /// lane-av1422lift: this arm used to end "and the decoder is asserted
2584+ /// to refuse it by name, which is the honest outcome for the shape a
2585+ /// 4:4:0 request actually yields". That was honest only because the
2586+ /// decoder refused EVERY (1,0) header -- the assertion was about the
2587+ /// guard, not about these bytes. With 4:2:2 admitted, refusing these
2588+ /// bytes would be wrong and accepting them without comment would be
2589+ /// worse, so the arm now asserts the one thing that IS true of them:
2590+ /// the SEQUENCE HEADER, not the tile, fixes the decode's chroma
2591+ /// geometry. The pixel claim moved to genuinely 4:2:2 pins.
2495 #[test]2592 #[test]
2496 fn the_440_cell_is_not_a_codable_chroma_shape() {2593 fn the_440_cell_is_not_a_codable_chroma_shape() {
2497 const NAME: &str = "the_440_cell_is_not_a_codable_chroma_shape";2594 const NAME: &str = "the_440_cell_is_not_a_codable_chroma_shape";
@@ -2729,10 +2826,38 @@ pub(crate) mod tests {
2729 ever reads (0,1), a 4:4:0 cell became codable and this whole gate is wrong about the \2826 ever reads (0,1), a 4:4:0 cell became codable and this whole gate is wrong about the \
2730 format."2827 format."
2731 );2828 );
2732- let err = decode_stream(&pinned).unwrap_err().to_string();2829+ // lane-av1422lift: the refusal is gone, and the replacement is NOT
2830+ // "it decodes". This pin's TILE is a 4:2:0 key frame's, byte for
2831+ // byte -- only the sequence header carries 4:2:2 -- so it is a
2832+ // header/tile mismatch and there is no oracle that can say what the
2833+ // right pixels are. What IS assertable, and is what the pin is for,
2834+ // is that the SEQUENCE HEADER alone decides the decode's geometry:
2835+ // the decoded chroma planes are half-width and FULL height, exactly
2836+ // the `round_ss(w, 1) x round_ss(h, 0)` shape a real 4:2:2 stream
2837+ // produces (see `a_real_422_key_frame_and_inter_sequence_decode_
2838+ // pixel_exact` for the pixel claim on genuine 4:2:2 bytes), and that
2839+ // the 4:2:2 chroma walk really ran on it. A decoder that still
2840+ // allocated 4:2:0 planes here would give 32x32 chroma and red.
2841+ let frames = decode_stream(&pinned).unwrap_or_else(|e| {
2842+ panic!("{NAME}: a (1,0) header must decode now that 4:2:2 is admitted: {e}")
2843+ });
2844+ assert_eq!(
2845+ frames.len(),
2846+ 1,
2847+ "{NAME}: the pin must decode exactly one frame"
2848+ );
2849+ assert_eq!(
2850+ (frames[0].u.len(), frames[0].v.len()),
2851+ (32 * 64, 32 * 64),
2852+ "{NAME}: 64x64 4:2:2 is HALF WIDTH and FULL HEIGHT (32x64 chroma); {:?} means the \
2853+ plane geometry still came from the TILE's 4:2:0 shape rather than the HEADER's",
2854+ (frames[0].u.len(), frames[0].v.len())
2855+ );
2733 assert!(2856 assert!(
2734- err.contains("a chroma format of 4:2:2"),2857+ crate::decode::census_nonsub_units()[1] > 0
2735- "{NAME}: the shape the 4:4:0 request lands on must still refuse by name, got: {err}"2858+ && crate::decode::census_nonsub_units()[2] > 0,
2859+ "{NAME}: the pin walked zero 4:2:2 chroma coefficient units -- the per-axis walk never \
2860+ ran on it"
2736 );2861 );
2737 }2862 }
2738 /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned2863 /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned
@@ -2759,18 +2884,28 @@ pub(crate) mod tests {
2759 /// `EC_AV1_ALLOW_422_PROBE` patch-run-restore build (recipe and measured2884 /// `EC_AV1_ALLOW_422_PROBE` patch-run-restore build (recipe and measured
2760 /// numbers in `lanes/av1422bigblock.report.md`).2885 /// numbers in `lanes/av1422bigblock.report.md`).
2761 ///2886 ///
2762- /// `decode_stream` itself still refuses 4:2:2 at the sequence header --2887+ /// lane-av1422lift: `decode_stream` no longer refuses 4:2:2 at the
2763- /// unconditionally, per the standing family rule -- so the committed2888+ /// sequence header, so this gate stops being a refusal contract and
2764- /// assertion is the byte pin (fnv1a64, the same load-bearing-identity2889+ /// becomes the one it should have been: BOTH pins, byte-pinned AND
2765- /// fingerprint as the cdf-forwarding gate) plus the refusal-by-name2890+ /// byte-exact against ffmpeg, with the per-plane coefficient-unit census
2766- /// contract over the pinned bytes.2891+ /// as the non-vacuity arm. The pins are unchanged and still load-bearing
2892+ /// (size + fnv1a64); only the assertion moved.
2767 #[test]2893 #[test]
2768- fn the_pinned_422_bigblock_witnesses_are_present_and_refuse_by_name() {2894+ fn the_pinned_422_bigblock_witnesses_decode_pixel_exact() {
2769- const NAME: &str = "the_pinned_422_bigblock_witnesses_are_present_and_refuse_by_name";2895+ const NAME: &str = "the_pinned_422_bigblock_witnesses_decode_pixel_exact";
2770- const REFUSAL: &str = "a chroma format of 4:2:2";2896+ if !have_ffmpeg() {
2771- for (file, bytes, fp) in [2897+ eprintln!("SKIP {NAME}: no ffmpeg");
2772- ("422_allskip_2f.obu", 62usize, 0x7e4d69d3c728c55f_u64),2898+ return;
2773- ("422_sb128_3f.obu", 12543, 0x5171e0aab8000da7),2899+ }
2900+ for (file, bytes, fp, frames, require_coded) in [
2901+ (
2902+ "422_allskip_2f.obu",
2903+ 62usize,
2904+ 0x7e4d69d3c728c55f_u64,
2905+ 2usize,
2906+ false,
2907+ ),
2908+ ("422_sb128_3f.obu", 12543, 0x5171e0aab8000da7, 3, true),
2774 ] {2909 ] {
2775 let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))2910 let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
2776 .join("fixtures")2911 .join("fixtures")
@@ -2783,11 +2918,24 @@ pub(crate) mod tests {
2783 });2918 });
2784 assert_eq!(data.len(), bytes, "{NAME}: {file} size drifted");2919 assert_eq!(data.len(), bytes, "{NAME}: {file} size drifted");
2785 assert_eq!(fnv1a64(&data), fp, "{NAME}: {file} bytes drifted");2920 assert_eq!(fnv1a64(&data), fp, "{NAME}: {file} bytes drifted");
2786- let err = decode_stream(&data).unwrap_err().to_string();2921+ let (_units, coded_delta) =
2787- assert!(2922+ assert_422_stream_pixel_exact(NAME, &data, 128, 128, frames, 8, require_coded);
2788- err.contains(REFUSAL),2923+ if !require_coded {
2789- "{NAME}: {file} must refuse by name, got: {err}"2924+ // `422_allskip_2f.obu` is named for what it does NOT code, and
2790- );2925+ // the pre-port defect was exactly that: the decoder read
2926+ // PHANTOM coefficient units in the all-skip inter frame and
2927+ // then panicked in `reconstruct_mc_rect` on a full-height
2928+ // 4:2:2 chroma rect. So the cell's non-vacuity is a NEGATIVE
2929+ // measurement on the CHROMA planes, asserted here rather than
2930+ // inherited: the walk ran (units > 0, which the shared body
2931+ // checks) and coded nothing on U or V.
2932+ assert_eq!(
2933+ (coded_delta[1], coded_delta[2]),
2934+ (0, 0),
2935+ "{NAME}: {file} CODED a chroma coefficient -- this is the all-skip inter-frame \
2936+ cell and a phantom residual read is exactly the defect it witnesses"
2937+ );
2938+ }
2791 }2939 }
2792 }2940 }
2793 2941
@@ -2815,15 +2963,22 @@ pub(crate) mod tests {
2815 /// Green-after, same fixture: 48 chroma units stamped, all 6 blocks2963 /// Green-after, same fixture: 48 chroma units stamped, all 6 blocks
2816 /// decoded, and ALL FIVE frames byte-identical to `aomdec --rawvideo`.2964 /// decoded, and ALL FIVE frames byte-identical to `aomdec --rawvideo`.
2817 ///2965 ///
2818- /// Committed code refuses 4:2:2 at the sequence header, so the decode2966+ /// lane-av1422lift: committed code no longer refuses 4:2:2 at the
2819- /// assertions above are probe-measured and reproducible from the lane2967+ /// sequence header, so the red/green evidence above is no longer
2820- /// report's recipe; what this gate can assert in committed code is the2968+ /// probe-only: this gate is the one that asserts it. Both pins are
2821- /// byte pin, the refusal-by-name contract, and -- in the arm below --2969+ /// byte-pinned AND byte-exact against ffmpeg's `yuv422p` rawvideo of the
2822- /// that the per-axis walk is still spelled per-axis in the source.2970+ /// same bytes, per plane and per frame, with the per-plane
2823- #[test]2971+ /// coefficient-unit census as the non-vacuity arm -- the census is what
2824- fn the_pinned_422_intrabc_sb128_strip_witnesses_refuse_by_name() {2972+ /// makes "48 chroma units stamped" a committed, reproducible number here
2825- const NAME: &str = "the_pinned_422_intrabc_sb128_strip_witnesses_refuse_by_name";2973+ /// instead of a sentence in a lane report. The source-scan arm below
2826- const REFUSAL: &str = "a chroma format of 4:2:2";2974+ /// keeps its own claim (the per-axis SPELLING) and does not overlap.
2975+ #[test]
2976+ fn the_pinned_422_intrabc_sb128_strip_witnesses_decode_pixel_exact() {
2977+ const NAME: &str = "the_pinned_422_intrabc_sb128_strip_witnesses_decode_pixel_exact";
2978+ if !have_ffmpeg() {
2979+ eprintln!("SKIP {NAME}: no ffmpeg");
2980+ return;
2981+ }
2827 for (file, bytes, fp) in [2982 for (file, bytes, fp) in [
2828 (2983 (
2829 "422_intrabc_sb128_strip.obu",2984 "422_intrabc_sb128_strip.obu",
@@ -2847,11 +3002,7 @@ pub(crate) mod tests {
2847 });3002 });
2848 assert_eq!(data.len(), bytes, "{NAME}: {file} size drifted");3003 assert_eq!(data.len(), bytes, "{NAME}: {file} size drifted");
2849 assert_eq!(fnv1a64(&data), fp, "{NAME}: {file} bytes drifted");3004 assert_eq!(fnv1a64(&data), fp, "{NAME}: {file} bytes drifted");
2850- let err = decode_stream(&data).unwrap_err().to_string();3005+ assert_422_stream_pixel_exact(NAME, &data, 384, 320, 5, 8, true);
2851- assert!(
2852- err.contains(REFUSAL),
2853- "{NAME}: {file} must refuse by name, got: {err}"
2854- );
2855 }3006 }
2856 }3007 }
2857 3008
@@ -3010,14 +3161,26 @@ pub(crate) mod tests {
3010 /// `a Golomb tail longer than this decoder reads` at frame 2. That3161 /// `a Golomb tail longer than this decoder reads` at frame 2. That
3011 /// refusal DOES NOT REPRODUCE on this tip: with the bypass applied, all3162 /// refusal DOES NOT REPRODUCE on this tip: with the bypass applied, all
3012 /// three cells DECODE 16/16 -- no panic and no second refusal.3163 /// three cells DECODE 16/16 -- no panic and no second refusal.
3013- #[test]3164+ ///
3014- fn the_pinned_422_lossless_inter_witnesses_are_present_and_refuse_by_name() {3165+ /// lane-av1422lift: the three pins are asserted BYTE-EXACT against
3015- const NAME: &str = "the_pinned_422_lossless_inter_witnesses_are_present_and_refuse_by_name";3166+ /// ffmpeg's rawvideo of the same bytes, per plane and per frame, with the
3016- const REFUSAL: &str = "a chroma format of 4:2:2";3167+ /// per-plane coefficient-unit census as the non-vacuity arm -- so the
3017- for (file, bytes, fp) in [3168+ /// three DECODE 16/16 fact the paragraph above records from a bypassed
3018- ("W_intrabc.obu", 130_320usize, 0xb6d5c4653a32567a_u64),3169+ /// probe build is now a committed assertion. `Y` is the 10-bit member
3019- ("X_intrabc_tiled.obu", 131_696, 0xb6e04621d2116ef7),3170+ /// and carries the depth-correct HBD compare (`yuv422p10le`, 16-bit
3020- ("Y_intrabc_10b.obu", 202_281, 0x2ecf03435a14dbf),3171+ /// containers on both sides) rather than an 8-bit narrowing of a
3172+ /// high-bit-depth cell.
3173+ #[test]
3174+ fn the_pinned_422_lossless_inter_witnesses_decode_pixel_exact() {
3175+ const NAME: &str = "the_pinned_422_lossless_inter_witnesses_decode_pixel_exact";
3176+ if !have_ffmpeg() {
3177+ eprintln!("SKIP {NAME}: no ffmpeg");
3178+ return;
3179+ }
3180+ for (file, bytes, fp, depth) in [
3181+ ("W_intrabc.obu", 130_320usize, 0xb6d5c4653a32567a_u64, 8u8),
3182+ ("X_intrabc_tiled.obu", 131_696, 0xb6e04621d2116ef7, 8),
3183+ ("Y_intrabc_10b.obu", 202_281, 0x2ecf03435a14dbf, 10),
3021 ] {3184 ] {
3022 let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))3185 let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
3023 .join("fixtures")3186 .join("fixtures")
@@ -3027,11 +3190,7 @@ pub(crate) mod tests {
3027 });3190 });
3028 assert_eq!(data.len(), bytes, "{NAME}: {file} size drifted");3191 assert_eq!(data.len(), bytes, "{NAME}: {file} size drifted");
3029 assert_eq!(fnv1a64(&data), fp, "{NAME}: {file} bytes drifted");3192 assert_eq!(fnv1a64(&data), fp, "{NAME}: {file} bytes drifted");
3030- let err = decode_stream(&data).unwrap_err().to_string();3193+ assert_422_stream_pixel_exact(NAME, &data, 320, 240, 16, depth, true);
3031- assert!(
3032- err.contains(REFUSAL),
3033- "{NAME}: {file} must refuse by name, got: {err}"
3034- );
3035 }3194 }
3036 }3195 }
3037 3196
@@ -3322,15 +3481,20 @@ pub(crate) mod tests {
3322 /// by it -- byte-identical to their pre-lane decodes, with the LR gate3481 /// by it -- byte-identical to their pre-lane decodes, with the LR gate
3323 /// family green.3482 /// family green.
3324 ///3483 ///
3325- /// Like its two siblings, the committed assertion is the byte pin plus3484+ /// lane-av1422lift: the committed assertion is now the byte pin AND
3326- /// the refusal-by-name contract: with the header refusal standing,3485+ /// byte-exactness against ffmpeg's `yuv422p` rawvideo of the same bytes,
3327- /// NO committed test can decode a 4:2:2 stream, because the bypass that3486+ /// per plane and per frame, with the per-plane coefficient-unit census
3328- /// would allow it must never be committed.3487+ /// as the non-vacuity arm. The paragraph above's coverage counts (25
3488+ /// compound-warp, 84 rotzoom global-warp, 22 Wiener, 10 SGRPROJ, CDEF
3489+ /// 39) are what make the row non-vacuous: without them a byte-exact
3490+ /// compare could be green over a stream that never entered a warp arm.
3329 #[test]3491 #[test]
3330- fn the_pinned_422_residual_compound_warp_witness_is_present_and_refuses_by_name() {3492+ fn the_pinned_422_residual_compound_warp_witness_decodes_pixel_exact() {
3331- const NAME: &str =3493+ const NAME: &str = "the_pinned_422_residual_compound_warp_witness_decodes_pixel_exact";
3332- "the_pinned_422_residual_compound_warp_witness_is_present_and_refuses_by_name";3494+ if !have_ffmpeg() {
3333- const REFUSAL: &str = "a chroma format of 4:2:2";3495+ eprintln!("SKIP {NAME}: no ffmpeg");
3496+ return;
3497+ }
3334 const FILE: &str = "422_residual_compound_warp_16f.obu";3498 const FILE: &str = "422_residual_compound_warp_16f.obu";
3335 const BYTES: usize = 38845;3499 const BYTES: usize = 38845;
3336 const FP: u64 = 0x0e73a51e2cc0c424;3500 const FP: u64 = 0x0e73a51e2cc0c424;
@@ -3345,11 +3509,7 @@ pub(crate) mod tests {
3345 });3509 });
3346 assert_eq!(data.len(), BYTES, "{NAME}: {FILE} size drifted");3510 assert_eq!(data.len(), BYTES, "{NAME}: {FILE} size drifted");
3347 assert_eq!(fnv1a64(&data), FP, "{NAME}: {FILE} bytes drifted");3511 assert_eq!(fnv1a64(&data), FP, "{NAME}: {FILE} bytes drifted");
3348- let err = decode_stream(&data).unwrap_err().to_string();3512+ assert_422_stream_pixel_exact(NAME, &data, 256, 288, 16, 8, true);
3349- assert!(
3350- err.contains(REFUSAL),
3351- "{NAME}: {FILE} must refuse by name, got: {err}"
3352- );
3353 }3513 }
3354 /// lane-av1422lrless: the LR-OFF half of the 4:2:2 coverage pair.3514 /// lane-av1422lrless: the LR-OFF half of the 4:2:2 coverage pair.
3355 ///3515 ///
@@ -3403,13 +3563,20 @@ pub(crate) mod tests {
3403 /// the one where `read_lr` does nothing at all, so the engagement is3563 /// the one where `read_lr` does nothing at all, so the engagement is
3404 /// not an artefact of the code under test.3564 /// not an artefact of the code under test.
3405 ///3565 ///
3406- /// Same scope as its siblings, for the same reason: with the header3566+ /// lane-av1422lift: same scope change as its siblings, and this is the arm
3407- /// refusal standing no committed test can decode a 4:2:2 stream,3567+ /// where it matters most: this stream is the one where `read_lr` does
3408- /// because the bypass that would allow it must never be committed.3568+ /// nothing at all, so a byte-exact green over it is a claim about the
3569+ /// per-axis path WITHOUT the loop-restoration corner fix carrying it.
3570+ /// The pin stays, the compare against ffmpeg's `yuv422p` rawvideo is
3571+ /// added per plane and per frame, and the per-plane coefficient-unit
3572+ /// census is the non-vacuity arm.
3409 #[test]3573 #[test]
3410- fn the_pinned_422_lr_off_witness_is_present_and_refuses_by_name() {3574+ fn the_pinned_422_lr_off_witness_decodes_pixel_exact() {
3411- const NAME: &str = "the_pinned_422_lr_off_witness_is_present_and_refuses_by_name";3575+ const NAME: &str = "the_pinned_422_lr_off_witness_decodes_pixel_exact";
3412- const REFUSAL: &str = "a chroma format of 4:2:2";3576+ if !have_ffmpeg() {
3577+ eprintln!("SKIP {NAME}: no ffmpeg");
3578+ return;
3579+ }
3413 const FILE: &str = "422_residual_compound_warp_nolr_16f.obu";3580 const FILE: &str = "422_residual_compound_warp_nolr_16f.obu";
3414 const BYTES: usize = 38538;3581 const BYTES: usize = 38538;
3415 const FP: u64 = 0x4b8ff761701e2bef;3582 const FP: u64 = 0x4b8ff761701e2bef;
@@ -3424,11 +3591,251 @@ pub(crate) mod tests {
3424 });3591 });
3425 assert_eq!(data.len(), BYTES, "{NAME}: {FILE} size drifted");3592 assert_eq!(data.len(), BYTES, "{NAME}: {FILE} size drifted");
3426 assert_eq!(fnv1a64(&data), FP, "{NAME}: {FILE} bytes drifted");3593 assert_eq!(fnv1a64(&data), FP, "{NAME}: {FILE} bytes drifted");
3427- let err = decode_stream(&data).unwrap_err().to_string();3594+ assert_422_stream_pixel_exact(NAME, &data, 256, 288, 16, 8, true);
3595+ }
3596+
3597+ /// lane-av1422lift: 4:2:2 FILM GRAIN, and why this one gate cannot use
3598+ /// the dump path or the shared body above.
3599+ ///
3600+ /// `EC_AV1_FINAL_DUMP` writes the picture "exactly as it is about to be
3601+ /// stored into the reference slots" (`stream.rs`, the dump site beside
3602+ /// the emit), which is BEFORE `apply_grain` runs on the output. ffmpeg's
3603+ /// rawvideo is POST-grain. So every grain cell -- 4:2:0, 4:2:2, 12-bit,
3604+ /// all of them -- is incomparable through the dump, and the corpus
3605+ /// comparator hits it as a hard error rather than as a clean red
3606+ /// (measured on `s422_grain_160x128.obu`: "luma identity never covers the
3607+ /// display side (3 decode frames, 3 display frames)"). This gate
3608+ /// therefore compares the IN-MEMORY `decode_stream` output, which is
3609+ /// post-grain, exactly like
3610+ /// `a_real_aomenc_12bit_film_grain_stream_decodes_pixel_exact` does for
3611+ /// 12-bit 4:2:0. Using the pre-grain dump here would make the gate
3612+ /// permanently red for a reason that has nothing to do with grain.
3613+ ///
3614+ /// The pin, `s422_grain_160x128.obu` (5433 bytes, sha256
3615+ /// `a4a6957b5e8298d9138f64498cab2d3008b3390fa73cd0d74aa0632b13d93d15`,
3616+ /// fnv1a64 `0x2aed47614b9461b8`), is aomenc profile 2 over a `C422`
3617+ /// testsrc2 160x128 3-frame source with `--film-grain-test=5`,
3618+ /// `--passes=1 --end-usage=q --cq-level=24 --cpu-used=0 --threads=1
3619+ /// --row-mt=0 --limit=3 --obu`.
3620+ ///
3621+ /// Two arms, because a green compare over a stream whose grain never ran
3622+ /// is the "params-without-apply" false green:
3623+ ///
3624+ /// 1. the stream's OWN frame headers carry `apply_grain` and scaling
3625+ /// points on all THREE planes -- at 4:2:2 that is the shape libaom's
3626+ /// `generate_grain_uv_422` exists for, and it is read out of the
3627+ /// bytes, not out of the flags handed to the encoder;
3628+ /// 2. `film_grain::grain_hits()` moves across the decode.
3629+ #[test]
3630+ fn a_real_422_film_grain_stream_decodes_pixel_exact() {
3631+ const NAME: &str = "a_real_422_film_grain_stream_decodes_pixel_exact";
3632+ if !have_ffmpeg() {
3633+ eprintln!("SKIP {NAME}: no ffmpeg");
3634+ return;
3635+ }
3636+ let _gate_lock = lock_gate_counters();
3637+ let path = crate_pin("s422_grain_160x128.obu");
3638+ let stream = read_pin(&path, 5433, 0x2aed47614b9461b8, NAME);
3639+ let mut probe = Av1Parser::new();
3640+ let mut pos = 0usize;
3641+ let mut grain_frames = 0usize;
3642+ while pos < stream.len() {
3643+ let obu = probe.parse_obu(&stream[pos..]).unwrap();
3644+ pos += obu.total_size;
3645+ if let ObuKind::Frame(header, _) = obu.kind {
3646+ let fg = &header.film_grain;
3647+ assert!(
3648+ fg.apply_grain,
3649+ "{NAME}: frame without apply_grain -- aomenc emitted params it does not apply"
3650+ );
3651+ assert!(
3652+ fg.num_y_points > 0 && fg.num_cb_points > 0 && fg.num_cr_points > 0,
3653+ "{NAME}: grain without all three planes' scaling points -- the per-axis \
3654+ `generate_grain_uv_422` geometry would not be exercised"
3655+ );
3656+ grain_frames += 1;
3657+ }
3658+ }
3659+ assert_eq!(
3660+ grain_frames, 3,
3661+ "{NAME}: expected grain on all three frames"
3662+ );
3663+ let before = crate::film_grain::grain_hits();
3664+ let units_before = crate::decode::census_nonsub_units();
3665+ let ours = decode_stream(&stream).unwrap_or_else(|e| {
3666+ panic!("{NAME}: decode_stream refused a real 4:2:2 grain stream: {e}")
3667+ });
3668+ assert_eq!(ours.len(), 3, "{NAME}: decoded frame count");
3669+ assert_eq!(
3670+ ours[0].u.len(),
3671+ 80 * 128,
3672+ "{NAME}: 160x128 4:2:2 chroma is 80x128; {} means a 4:2:0 plane",
3673+ ours[0].u.len()
3674+ );
3428 assert!(3675 assert!(
3429- err.contains(REFUSAL),3676+ crate::film_grain::grain_hits() > before,
3430- "{NAME}: {FILE} must refuse by name, got: {err}"3677+ "{NAME}: matched but zero grain_hits -- grain synthesis never ran"
3431 );3678 );
3679+ let units = crate::decode::census_nonsub_units();
3680+ for (p, plane) in ["luma", "U", "V"].into_iter().enumerate() {
3681+ assert!(
3682+ units[p] > units_before[p],
3683+ "{NAME}: the {plane} plane walked ZERO coefficient units -- this byte-exact \
3684+ compare is vacuous with respect to 4:2:2"
3685+ );
3686+ }
3687+ let theirs = ffmpeg_decode_sequence_422(&stream, 160, 128, 3);
3688+ for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() {
3689+ for (plane, ours_plane, theirs_plane) in
3690+ [("Y", &a.y, &b.y), ("U", &a.u, &b.u), ("V", &a.v, &b.v)]
3691+ {
3692+ if let Some(bad) = ours_plane
3693+ .iter()
3694+ .zip(theirs_plane)
3695+ .position(|(x, y)| x != y)
3696+ {
3697+ panic!(
3698+ "{NAME}: {plane} differs from ffmpeg at frame {i} sample {bad} ({} vs {})",
3699+ ours_plane[bad], theirs_plane[bad]
3700+ );
3701+ }
3702+ }
3703+ }
3704+ eprintln!(
3705+ "{NAME}: post-grain byte-exact vs ffmpeg; grain_hits={}",
3706+ crate::film_grain::grain_hits()
3707+ );
3708+ }
3709+
3710+ /// lane-av1422lift: THE CORPUS BATTERY -- the gate the 4:2:2 campaign
3711+ /// earned, and the one that replaces seven gates whose only behavioural
3712+ /// assertion was `err.contains(REFUSAL)`.
3713+ ///
3714+ /// **Why these six.** The measurement base
3715+ /// (`lanes/av1422ffmpegbase.report.md` section 2.1) recorded seven 4:2:2
3716+ /// cells that diverged from ffmpeg: `s422_320x246`, `s422_322x240`,
3717+ /// `s422_322x246`, `s422_352x242_10b`, `s422_384x240`,
3718+ /// `s422_416x242_10b`, `s422_416x250_10b`. Six are closed and are pinned
3719+ /// here, each byte-exact against ffmpeg with the per-plane
3720+ /// coefficient-unit census as its non-vacuity arm. All six are
3721+ /// CHROMA-only divergences at non-8-aligned geometries -- odd or
3722+ /// 2-mod-4 luma dimensions, where `round_ss` and the chroma block walk
3723+ /// disagree with a hardcoded `>> 1` -- which is why they are the rows a
3724+ /// lift cannot afford to leave unasserted: they are the cells that would
3725+ /// go quietly wrong again.
3726+ ///
3727+ /// **The seventh, `s422_384x240`, is NOT here, on purpose.** It is the
3728+ /// reserved group-tail chroma SKIP arm (`decode.rs`; the risk study R4
3729+ /// flags it as owned elsewhere), it is still red, and pinning a red cell
3730+ /// inside a green gate is how a gate stops being a gate.
3731+ /// **THIS BRANCH MUST NOT LAND UNTIL THAT CELL CLOSES AND THE CORPUS
3732+ /// RE-MEASURES 51/51** -- see `lanes/av1422lift.report.md`.
3733+ ///
3734+ /// **The census arm, per row.** `assert_422_stream_pixel_exact` asserts
3735+ /// that all three planes read a non-zero number of coefficient units AND
3736+ /// a non-zero number of units that coded at least one coefficient, on
3737+ /// this row's own bytes. That is the requirement R8 named as unwritable
3738+ /// before lane-av1422census422 armed the census for `(1,0)`; measured on
3739+ /// this tree the OLD arming read `[0, 0, 0]` on every 4:2:2 cell while
3740+ /// the same decode walked 4994 units, so a green here with no census
3741+ /// assert would have proven nothing about 4:2:2.
3742+ ///
3743+ /// **Provenance of the six pins.** All six are `aomenc --codec=av1
3744+ /// --profile=2 --input-bit-depth=<8|10> --cpu-used=0 --cq-level=24
3745+ /// --limit=16 --auto-alt-ref=1 --enable-global-motion=1 --passes=1
3746+ /// --obu` over a hand-built `C422` y4m (header line, then `FRAME\n` plus
3747+ /// one frame of planes per frame -- libaom's y4minput requires those six
3748+ /// bytes before EVERY frame), produced by the census sweep and copied in
3749+ /// from `~/.cache/census422b/sweep/`. They are ordinary libaom 4:2:2
3750+ /// streams with nothing bolted on.
3751+ #[test]
3752+ fn the_pinned_422_corpus_cells_decode_pixel_exact() {
3753+ const NAME: &str = "the_pinned_422_corpus_cells_decode_pixel_exact";
3754+ if !have_ffmpeg() {
3755+ eprintln!("SKIP {NAME}: no ffmpeg");
3756+ return;
3757+ }
3758+ // (file, bytes, fnv1a64, sha256, w, h, depth, frames)
3759+ for (file, bytes, fp, sha, w, h, depth, frames) in [
3760+ (
3761+ "s422_320x246.obu",
3762+ 20692usize,
3763+ 0x01e556015878e04eu64,
3764+ "aebd3a10d46e617b803579819f2502798076384be52e032b11b46f09eeb09a79",
3765+ 320usize,
3766+ 246usize,
3767+ 8u8,
3768+ 16usize,
3769+ ),
3770+ (
3771+ "s422_322x240.obu",
3772+ 21096,
3773+ 0x9a96dda2a19d47a6,
3774+ "e74bf7e91f23353986edf9380bcd6cb760194e619dbbdf6a239b7a05eff81799",
3775+ 322,
3776+ 240,
3777+ 8,
3778+ 16,
3779+ ),
3780+ (
3781+ "s422_322x246.obu",
3782+ 20528,
3783+ 0x2c6f8be6d30384ab,
3784+ "ee96617fe45ba963d3628f37086077a94806ef0465a74cb538a8e57d2ed900b3",
3785+ 322,
3786+ 246,
3787+ 8,
3788+ 16,
3789+ ),
3790+ (
3791+ "s422_352x242_10b.obu",
3792+ 20575,
3793+ 0xf1d370f80d8ddc6d,
3794+ "8893bbed108d7555e66c35f2f45d6e44044dcd6810b0510fb251be05dabaa2d0",
3795+ 352,
3796+ 242,
3797+ 10,
3798+ 16,
3799+ ),
3800+ (
3801+ "s422_416x242_10b.obu",
3802+ 20282,
3803+ 0x9826402d91abbc56,
3804+ "38d0b592e5e358901742122c590c8964b5d08d0ceccfa051e677c28f4b75d174",
3805+ 416,
3806+ 242,
3807+ 10,
3808+ 16,
3809+ ),
3810+ (
3811+ "s422_416x250_10b.obu",
3812+ 19967,
3813+ 0x6b07e837eae8a6be,
3814+ "d6aa7f450f54d6fb381400a0a0226da87599c00509eeb5031abe63383e272627",
3815+ 416,
3816+ 250,
3817+ 10,
3818+ 16,
3819+ ),
3820+ ] {
3821+ let row = format!("{NAME}[{file}]");
3822+ let path = crate_pin(file);
3823+ let data = std::fs::read(&path).unwrap_or_else(|e| {
3824+ panic!(
3825+ "{row}: pinned corpus cell {} is missing ({e}) -- the gate cannot run",
3826+ path.display()
3827+ )
3828+ });
3829+ assert_eq!(data.len(), bytes, "{row}: size drifted");
3830+ assert_eq!(fnv1a64(&data), fp, "{row}: bytes drifted");
3831+ // The sha256 is the corpus's own identity column (its
3832+ // `cells_422_3d56.json` records one per cell and the census
3833+ // verified zero drift); fnv1a64 is what `read_pin` can check
3834+ // in-process without spawning sha256sum, so both are named and
3835+ // the sha256 is what a re-capture must reproduce.
3836+ eprintln!("{row}: sha256 {sha}");
3837+ assert_422_stream_pixel_exact(&row, &data, w, h, frames, depth, true);
3838+ }
3432 }3839 }
3433 3840
3434 /// lane-av1-qmatrix: WITNESS for the lifted `using_qmatrix` refusal (the3841 /// lane-av1-qmatrix: WITNESS for the lifted `using_qmatrix` refusal (the
@@ -7734,6 +8141,234 @@ pub(crate) mod tests {
7734 .collect()8141 .collect()
7735 }8142 }
7736 8143
8144+ /// lane-av1422lift: as [`ffmpeg_decode_sequence`] (4:2:0 8-bit) and
8145+ /// [`ffmpeg_decode_sequence_444`], for a 4:2:2 stream: `yuv422p`
8146+ /// rawvideo, whose chroma planes are HALF WIDTH and FULL HEIGHT -- the
8147+ /// `w/2 * h` shape the whole per-axis port exists to produce. A helper
8148+ /// that computed the chroma span 4:2:0-style would make every 4:2:2
8149+ /// gate compare half the oracle's bytes and pass, so the span is
8150+ /// asserted against the byte count below, not assumed.
8151+ fn ffmpeg_decode_sequence_422(
8152+ stream: &[u8],
8153+ width: usize,
8154+ height: usize,
8155+ frames: usize,
8156+ ) -> Vec<Pic> {
8157+ ffmpeg_decode_sequence_422_depth(stream, width, height, frames, 8, "yuv422p")
8158+ }
8159+
8160+ /// lane-av1422lift: the depth-generic 4:2:2 oracle comparator --
8161+ /// `yuv422p`, `yuv422p10le` or `yuv422p12le`, with the container width
8162+ /// taken from `depth` itself (8 -> one byte per sample; 10/12 -> a
8163+ /// 16-bit LE container on BOTH sides, so ours and ffmpeg's are directly
8164+ /// comparable sample for sample and nothing narrows).
8165+ fn ffmpeg_decode_sequence_422_depth(
8166+ stream: &[u8],
8167+ width: usize,
8168+ height: usize,
8169+ frames: usize,
8170+ depth: u8,
8171+ pix_fmt: &str,
8172+ ) -> Vec<Pic> {
8173+ assert!(
8174+ matches!(depth, 8 | 10 | 12),
8175+ "lane-av1422lift: ffmpeg_decode_sequence_422_depth takes 8, 10 or 12, got {depth}"
8176+ );
8177+ let out = run_with_stdin(
8178+ Command::new("ffmpeg").args([
8179+ "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", pix_fmt, "-",
8180+ ]),
8181+ stream,
8182+ );
8183+ assert!(
8184+ out.status.success(),
8185+ "ffmpeg refused the 4:2:2 stream ({pix_fmt}): {}",
8186+ String::from_utf8_lossy(&out.stderr)
8187+ );
8188+ let (luma, chroma) = (width * height, width.div_ceil(2) * height);
8189+ let bps = if depth == 8 { 1 } else { 2 };
8190+ let frame_bytes = (luma + 2 * chroma) * bps;
8191+ assert_eq!(
8192+ out.stdout.len(),
8193+ frame_bytes * frames,
8194+ "{}",
8195+ frame_count_diagnosis(
8196+ "4:2:2",
8197+ frames,
8198+ width,
8199+ height,
8200+ frame_bytes,
8201+ out.stdout.len(),
8202+ &out.stderr
8203+ )
8204+ );
8205+ (0..frames)
8206+ .map(|i| {
8207+ let base = i * frame_bytes;
8208+ let samples = |off: usize, n: usize| -> Vec<u16> {
8209+ let slice = &out.stdout[base + off..base + off + n * bps];
8210+ if bps == 1 {
8211+ slice.iter().map(|&v| u16::from(v)).collect()
8212+ } else {
8213+ slice
8214+ .chunks_exact(2)
8215+ .map(|c| u16::from_le_bytes([c[0], c[1]]))
8216+ .collect()
8217+ }
8218+ };
8219+ Pic {
8220+ width,
8221+ height,
8222+ y: samples(0, luma),
8223+ u: samples(luma * bps, chroma),
8224+ v: samples((luma + chroma) * bps, chroma),
8225+ }
8226+ })
8227+ .collect()
8228+ }
8229+
8230+ /// lane-av1422lift: the shared body of every 4:2:2 exactness gate this
8231+ /// lane adds, and the answer to "a byte-exact 4:2:2 gate can still be
8232+ /// vacuous".
8233+ ///
8234+ /// Before lane-av1422census422 the per-plane coefficient-unit census was
8235+ /// armed at `ss_x == 0 && ss_y == 0` only, so on a 4:2:2 stream
8236+ /// `census_nonsub_units()` read `[0, 0, 0]` BY CONSTRUCTION -- a gate
8237+ /// could have been green while the decode walked nothing at all. The
8238+ /// census is now armed for `(ss_x == 0 || ss_y == 0)`, so the delta
8239+ /// asserted here is a real measurement of the walk this stream caused:
8240+ /// every plane must show a non-zero number of transform units AND of
8241+ /// units that coded at least one coefficient.
8242+ ///
8243+ /// Four things are asserted per frame, in this order:
8244+ ///
8245+ /// 1. the decoded frame's dimensions, and that its chroma planes are
8246+ /// `round_ss(w, 1) * round_ss(h, 0)` -- half width, FULL height. A
8247+ /// decoder that kept 4:2:0 plane allocation while walking 4:2:2
8248+ /// entropy would pass a per-sample compare against a 4:2:0-sized
8249+ /// oracle; this is the shape assertion that closes that hole, and it
8250+ /// is asserted against the DECODED frame, never against the gate's
8251+ /// own name.
8252+ /// 2. the depth, read out of the stream's own sequence header.
8253+ /// 3. per-plane, per-frame byte-exactness against ffmpeg's rawvideo of
8254+ /// the same bytes at the depth-correct pixel format. Frame N of ours
8255+ /// against frame N of ffmpeg's: `decode_stream` returns DISPLAY order
8256+ /// and so does ffmpeg's rawvideo muxer, so a hidden alt-ref does not
8257+ /// shift the pairing (the decode-order-vs-display-order trap the
8258+ /// out-of-process corpus comparator has to solve separately).
8259+ /// 4. the census delta, asserted once for the whole stream rather than
8260+ /// per frame, because the counters are cumulative per thread.
8261+ ///
8262+ /// `require_coded` is false ONLY for a cell whose identity IS that it
8263+ /// codes nothing -- `422_allskip_2f.obu`, whose whole point is that
8264+ /// the inter frame reads no residual and the pre-port decoder read
8265+ /// PHANTOM units there. Demanding coded units on it would be
8266+ /// demanding the defect; its caller asserts the all-skip property
8267+ /// directly instead.
8268+ fn assert_422_stream_pixel_exact(
8269+ name: &str,
8270+ stream: &[u8],
8271+ width: usize,
8272+ height: usize,
8273+ frames: usize,
8274+ depth: u8,
8275+ require_coded: bool,
8276+ ) -> ([usize; 3], [usize; 3]) {
8277+ let _gate_lock = lock_gate_counters();
8278+ assert_eq!(
8279+ stream_bit_depth(stream, name),
8280+ depth,
8281+ "{name}: the stream's OWN sequence header does not say {depth} bit"
8282+ );
8283+ let before = crate::decode::census_nonsub_units();
8284+ let before_coded = crate::decode::census_nonsub_coded();
8285+ let ours = decode_stream(stream)
8286+ .unwrap_or_else(|e| panic!("{name}: decode_stream refused a real 4:2:2 stream: {e}"));
8287+ assert_eq!(ours.len(), frames, "{name}: decoded frame count");
8288+ for (i, f) in ours.iter().enumerate() {
8289+ assert_eq!(
8290+ (f.width, f.height),
8291+ (width, height),
8292+ "{name}: frame {i} dimensions"
8293+ );
8294+ assert_eq!(
8295+ (f.u.len(), f.v.len()),
8296+ (width.div_ceil(2) * height, width.div_ceil(2) * height),
8297+ "{name}: frame {i} chroma planes are {}/{} samples -- 4:2:2 is HALF WIDTH and \
8298+ FULL HEIGHT ({width}/2 x {height}); a quarter-height plane means the decode kept \
8299+ a 4:2:0 allocation",
8300+ f.u.len(),
8301+ f.v.len()
8302+ );
8303+ }
8304+ let pix_fmt = match depth {
8305+ 8 => "yuv422p",
8306+ 10 => "yuv422p10le",
8307+ 12 => "yuv422p12le",
8308+ other => panic!("{name}: no ffmpeg pixel format mapped for depth {other}"),
8309+ };
8310+ let theirs =
8311+ ffmpeg_decode_sequence_422_depth(stream, width, height, frames, depth, pix_fmt);
8312+ for (i, (a, b)) in ours.iter().zip(&theirs).enumerate() {
8313+ for (plane, ours_plane, theirs_plane) in
8314+ [("Y", &a.y, &b.y), ("U", &a.u, &b.u), ("V", &a.v, &b.v)]
8315+ {
8316+ assert_eq!(
8317+ ours_plane.len(),
8318+ theirs_plane.len(),
8319+ "{name}: {plane} plane {i} is {} samples against ffmpeg's {} -- the 4:2:2 chroma \
8320+ span is wrong on one of the two sides",
8321+ ours_plane.len(),
8322+ theirs_plane.len()
8323+ );
8324+ if let Some(bad) = ours_plane
8325+ .iter()
8326+ .zip(theirs_plane)
8327+ .position(|(x, y)| x != y)
8328+ {
8329+ panic!(
8330+ "{name}: {plane} differs from ffmpeg at frame {i} sample {bad} ({} vs {}; \
8331+ {} of {} samples differ)",
8332+ ours_plane[bad],
8333+ theirs_plane[bad],
8334+ ours_plane
8335+ .iter()
8336+ .zip(theirs_plane)
8337+ .filter(|(x, y)| x != y)
8338+ .count(),
8339+ ours_plane.len()
8340+ );
8341+ }
8342+ }
8343+ }
8344+ let units = crate::decode::census_nonsub_units();
8345+ let coded = crate::decode::census_nonsub_coded();
8346+ let delta: [usize; 3] = std::array::from_fn(|p| units[p] - before[p]);
8347+ let coded_delta: [usize; 3] = std::array::from_fn(|p| coded[p] - before_coded[p]);
8348+ for (p, plane) in ["luma", "U", "V"].into_iter().enumerate() {
8349+ assert!(
8350+ delta[p] > 0,
8351+ "{name}: the {plane} plane read ZERO coefficient units across the whole stream -- \
8352+ this byte-exact compare is vacuous with respect to 4:2:2 (class \
8353+ gate-blind-to-feature)"
8354+ );
8355+ if require_coded {
8356+ assert!(
8357+ coded_delta[p] > 0,
8358+ "{name}: the {plane} plane coded ZERO coefficient units across the whole \
8359+ stream -- every unit took the all-zero early return, so no coefficient path \
8360+ was exercised"
8361+ );
8362+ }
8363+ }
8364+ eprintln!(
8365+ "{name}: byte-exact vs ffmpeg ({pix_fmt}, {frames} frames); census delta \
8366+ units=[{}, {}, {}] coded=[{}, {}, {}]",
8367+ delta[0], delta[1], delta[2], coded_delta[0], coded_delta[1], coded_delta[2]
8368+ );
8369+ (delta, coded_delta)
8370+ }
8371+
7737 /// lane-av1-llinter: the firing gate for the lossless 4:4:4 INTER chroma8372 /// lane-av1-llinter: the firing gate for the lossless 4:4:4 INTER chroma
7738 /// fix. The fixture is the report's dodge2 stream pinned into `fixtures/`:8373 /// fix. The fixture is the report's dodge2 stream pinned into `fixtures/`:
7739 /// aomenc profile 1 over testsrc2 128x96 yuv444p, `--lossless=1`,8374 /// aomenc profile 1 over testsrc2 128x96 yuv444p, `--lossless=1`,
@@ -8566,10 +9201,13 @@ pub(crate) mod tests {
8566 // stopped replaying reads 0), and the mismatch half is the 4:2:29201 // stopped replaying reads 0), and the mismatch half is the 4:2:2
8567 // signature: this stream is 4:4:4 (ss 0,0), where the unit's luma9202 // signature: this stream is 4:4:4 (ss 0,0), where the unit's luma
8568 // width and height are equal, so a replay that stamped one axis with9203 // width and height are equal, so a replay that stamped one axis with
8569- // the other's span would still read 0 here -- the counter is what9204+ // the other's span would still read 0 here. lane-av1422lift: 4:2:2 is
8570- // names the day 4:2:2 (ss 1,0, refused by name at the sequence9205+ // decoded now, so this counter no longer "names the day 4:2:2 is
8571- // header) is admitted, rather than letting the 8-row spill below the9206+ // admitted" -- the 4:2:2 rows of
8572- // block corrupt the next block's `txb_skip` silently.9207+ // `the_pinned_422_corpus_cells_decode_pixel_exact` read the mismatch
9208+ // half on streams where the two spans actually differ, which is what
9209+ // stops an 8-row spill below the block from corrupting the next
9210+ // block's `txb_skip` silently.
8573 let after_replay = crate::decode::sb128rect_chroma_replay_hits();9211 let after_replay = crate::decode::sb128rect_chroma_replay_hits();
8574 assert!(9212 assert!(
8575 after_replay.0 > before_replay.0,9213 after_replay.0 > before_replay.0,
@@ -10126,8 +10764,11 @@ pub(crate) mod tests {
10126 // TX_4X4 chroma units, so the end-of-block replay re-stamps each of10764 // TX_4X4 chroma units, so the end-of-block replay re-stamps each of
10127 // them over its own luma-mi rows -- the arm the span fix sits on, on10765 // them over its own luma-mi rows -- the arm the span fix sits on, on
10128 // the OTHER admitted ss (1,1). The mismatch half is the 4:2:210766 // the OTHER admitted ss (1,1). The mismatch half is the 4:2:2
10129- // signature and reads 0 here because 4:2:2 is refused by name at the10767+ // signature; lane-av1422lift: 4:2:2 is decoded now, so this is no
10130- // sequence header; it is the tripwire for the day it is not.10768+ // longer "the tripwire for the day it is not" -- it is a zero this
10769+ // gate asserts on the stream in front of it, and the 4:2:2 rows of
10770+ // `the_pinned_422_corpus_cells_decode_pixel_exact` assert the same
10771+ // zero there.
10131 let after_replay = crate::decode::sb128rect_chroma_replay_hits();10772 let after_replay = crate::decode::sb128rect_chroma_replay_hits();
10132 assert!(10773 assert!(
10133 after_replay.0 > before_replay.0,10774 after_replay.0 > before_replay.0,
@@ -51417,7 +52058,11 @@ exit 0
51417 /// (0, 1) needs no arm: `ec-av1-syntax` reads `subsampling_y` only when52058 /// (0, 1) needs no arm: `ec-av1-syntax` reads `subsampling_y` only when
51418 /// `subsampling_x == 1` (`crates/ec-av1-syntax/src/sequence.rs:483-485`),52059 /// `subsampling_x == 1` (`crates/ec-av1-syntax/src/sequence.rs:483-485`),
51419 /// so the pair is structurally uncodable and the 4:2:0 fallthrough is the52060 /// so the pair is structurally uncodable and the 4:2:0 fallthrough is the
51420- /// only residual. 4:2:2 is refused at the sequence header.52061+ /// only residual. lane-av1422lift: this sentence used to end "4:2:2 is
52062+ /// refused at the sequence header", which was the wrong reason -- the
52063+ /// claim holds because `cfl_ac_ss` DISPATCHES `ss (1,0)` before the 4:2:0
52064+ /// fallthrough, not because the format could not arrive. The gate's
52065+ /// mechanism is unchanged; only the reason was stale.
51421 #[test]52066 #[test]
51422 fn cfl_ac_q3_at_is_reached_only_through_the_420_fallthrough_of_cfl_ac_ss() {52067 fn cfl_ac_q3_at_is_reached_only_through_the_420_fallthrough_of_cfl_ac_ss() {
51423 const NAME: &str = "cfl_ac_q3_at_is_reached_only_through_the_420_fallthrough_of_cfl_ac_ss";52068 const NAME: &str = "cfl_ac_q3_at_is_reached_only_through_the_420_fallthrough_of_cfl_ac_ss";