forge
Explore
Log in

Don't you dare go Hollow

Eob_pt class-1 CDF row missing from 9 of 16 TxbSet arms -- every inter chroma block under a 1D luma tx_type read the 2D row

Browse files at this commit

abd0a086a1a6e695232562ce2428ecf768d7feb8Ahmet Kaan GümüşParent: 01c42f6
  • fix
    • eob_pt class-1 CDF row missing from 9 of 16 TxbSet arms -- every inter chroma block under a 1D luma tx_type read the 2D row
Show full message
fix(av1): eob_pt class-1 CDF row missing from 9 of 16 TxbSet arms -- every inter chroma block under a 1D luma tx_type read the 2D row

lane-eobc1 r1. libaom's av1_default_eob_multi{16,32,64,128,256,512,1024}_cdfs
are [q][PLANE_TYPES][2]; index 1 is eob_multi_ctx = (tx_class == TX_CLASS_2D)
? 0 : 1 (entropymode.h:81-82, decodetxb.c). Main carried the class-1 row for
6 of the 11 eob_pt tables and left `eob_pt_class1: None` in 9 TxbSet arms --
including Luma4Inter, Luma8Inter and ChromaRect16x8, all of which can code a
1D type. Chroma codes no tx_type symbol of its own: it inherits the colocated
luma type verbatim (av1_get_tx_type, blockd.h:1291), so an 8x8 inter leaf with
H_/V_ luma puts its 4x4 chroma on the class-1 row -- right eob value, wrong
interval, desync one symbol later, surfacing as bogus partition refusals.

Ported the remaining 5 tables (128_chroma, 512_luma/chroma, 1024_luma/chroma)
from lane-gmaffine's f5e1851, machine-extracted afresh:
scripts/extract-eob-class1.py parses token_cdfs.h, emits the [q][plane][1]
rows and `--check`s them against cdf.rs -- all 44 class-1 consts now in the
crate diff bit-exact, 0 mismatched. All 16 arms are Some; 0 `None` left.

The 512/1024 rows are libaom's untouched uniform initialiser, because
av1_get_ext_tx_set_type returns DCT_IDTX/DCTONLY once tx_size_sqr_up >=
TX_32X32 and both members are TX_CLASS_2D -- wired anyway for domain
completeness (class table-domain-narrowed), and cdf.rs's new
eob_pt_class1_rows_cover_every_size test pins exactly that split: the 8
trained rows differ from their 2D sibling, the four 32-point ones are uniform.

GATE (new, 8-bit + 10-bit): a_real_aomenc_{,10bit_}inter_sequence_with_a_
class1_chroma_eob_decodes_pixel_exact -- real aomenc, full tx set
(--reduced-tx-type-set=0 --enable-flip-idtx=1), --min/max-partition-size=8/16,
global/warp/obmc off, 4 frames of a sinusoidal-stripe luma + moving chroma
ramp; hard-asserts decode::chroma_eob_class1_hits() moved on the counted
attempt and compares every shown frame against ffmpeg. Both green.
Ablation (chroma 4x4/8x8 arms set back to None): all 12 attempts fail in both
bit depths -- 10 with bogus partition refusals, 1 with no firing.
crates/ec-av1/src/cdf.rsmodified+114 -0
@@ -3600,6 +3600,53 @@ mod tests {
36003600 }
36013601 }
36023602
3603+ /// Every `eob_pt` table libaom keeps as `[q][plane][2]` has its class-1
3604+ /// (`tx_class != TX_CLASS_2D`) row here, and it is the *other* row.
3605+ ///
3606+ /// libaom only ever trained the class-1 row where a 1D tx type can occur:
3607+ /// `av1_get_ext_tx_set_type` returns `DCT_IDTX`/`DCTONLY` once
3608+ /// `tx_size_sqr_up >= TX_32X32`, so the 512- and 1024-point rows are the
3609+ /// untouched uniform initialiser. Pinned so a future table edit cannot
3610+ /// quietly narrow the domain back to 2D-only (lane-eobc1 r1; values
3611+ /// diffed against `token_cdfs.h` by `scripts/extract-eob-class1.py`).
3612+ #[test]
3613+ fn eob_pt_class1_rows_cover_every_size() {
3614+ fn uniform(row: &[u16]) -> bool {
3615+ let n = row.len() - 1;
3616+ row[..n].iter().enumerate().all(|(i, &v)| {
3617+ let n = n as u32;
3618+ v == (((i as u32 + 1) * 32768 + n / 2) / n) as u16
3619+ })
3620+ }
3621+ let trained: [(&[u16], &[u16]); 8] = [
3622+ (&EOB_PT_16_LUMA, &EOB_PT_16_LUMA_CLASS1),
3623+ (&EOB_PT_16_CHROMA, &EOB_PT_16_CHROMA_CLASS1),
3624+ (&EOB_PT_64_LUMA, &EOB_PT_64_LUMA_CLASS1),
3625+ (&EOB_PT_64_CHROMA, &EOB_PT_64_CHROMA_CLASS1),
3626+ (&EOB_PT_128_CHROMA, &EOB_PT_128_CHROMA_CLASS1),
3627+ (&EOB_PT_256_LUMA, &EOB_PT_256_LUMA_CLASS1),
3628+ (&EOB_PT_256_CHROMA, &EOB_PT_256_CHROMA_CLASS1),
3629+ (&EOB_PT_512_LUMA, &EOB_PT_512_LUMA_CLASS1),
3630+ ];
3631+ for (two_d, class1) in trained {
3632+ assert_row_shape(class1);
3633+ assert_eq!(two_d.len(), class1.len());
3634+ }
3635+ for (two_d, class1) in &trained[..7] {
3636+ assert_ne!(two_d, class1, "class-1 row is a copy of the 2D row");
3637+ assert!(!uniform(class1), "class-1 row was never trained");
3638+ }
3639+ for row in [
3640+ &EOB_PT_512_LUMA_CLASS1[..],
3641+ &EOB_PT_512_CHROMA_CLASS1[..],
3642+ &EOB_PT_1024_LUMA_CLASS1[..],
3643+ &EOB_PT_1024_CHROMA_CLASS1[..],
3644+ ] {
3645+ assert_row_shape(row);
3646+ assert!(uniform(row), "libaom trained a 32-point class-1 row");
3647+ }
3648+ }
3649+
36033650 #[test]
36043651 fn inter_frame_tables_are_well_formed_cdfs() {
36053652 for row in INTRA_INTER {
@@ -5126,3 +5173,70 @@ pub const EOB_PT_16_CHROMA_CLASS1_Q0: [u16; 6] = [1904, 3354, 7763, 14647, 32768
51265173 pub const EOB_PT_16_CHROMA_CLASS1_Q1: [u16; 6] = [2497, 4096, 8866, 16993, 32768, 0];
51275174 pub const EOB_PT_16_CHROMA_CLASS1: [u16; 6] = [3192, 5032, 10297, 19755, 32768, 0];
51285175 pub const EOB_PT_16_CHROMA_CLASS1_Q3: [u16; 6] = [7297, 10767, 19273, 28194, 32768, 0];
5176+
5177+/// The class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling of [`EOB_PT_128_CHROMA`]
5178+/// (lane-eobc1 r1, machine-extracted from libaom `token_cdfs.h`).
5179+pub const EOB_PT_128_CHROMA_CLASS1_Q0: [u16; 9] =
5180+ [2054, 3472, 5869, 14232, 18242, 20590, 26752, 32768, 0];
5181+pub const EOB_PT_128_CHROMA_CLASS1_Q1: [u16; 9] =
5182+ [2310, 4160, 7471, 14997, 17931, 20768, 30240, 32768, 0];
5183+pub const EOB_PT_128_CHROMA_CLASS1: [u16; 9] =
5184+ [6275, 9889, 14769, 23164, 27988, 30493, 32272, 32768, 0];
5185+pub const EOB_PT_128_CHROMA_CLASS1_Q3: [u16; 9] =
5186+ [9165, 13282, 21150, 30286, 31894, 32571, 32712, 32768, 0];
5187+/// The class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling of [`EOB_PT_512_LUMA`]
5188+/// (lane-eobc1 r1, machine-extracted from libaom `token_cdfs.h`).
5189+pub const EOB_PT_512_LUMA_CLASS1_Q0: [u16; 11] = [
5190+ 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0,
5191+];
5192+pub const EOB_PT_512_LUMA_CLASS1_Q1: [u16; 11] = [
5193+ 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0,
5194+];
5195+pub const EOB_PT_512_LUMA_CLASS1: [u16; 11] = [
5196+ 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0,
5197+];
5198+pub const EOB_PT_512_LUMA_CLASS1_Q3: [u16; 11] = [
5199+ 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0,
5200+];
5201+/// The class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling of [`EOB_PT_512_CHROMA`]
5202+/// (lane-eobc1 r1, machine-extracted from libaom `token_cdfs.h`).
5203+pub const EOB_PT_512_CHROMA_CLASS1_Q0: [u16; 11] = [
5204+ 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0,
5205+];
5206+pub const EOB_PT_512_CHROMA_CLASS1_Q1: [u16; 11] = [
5207+ 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0,
5208+];
5209+pub const EOB_PT_512_CHROMA_CLASS1: [u16; 11] = [
5210+ 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0,
5211+];
5212+pub const EOB_PT_512_CHROMA_CLASS1_Q3: [u16; 11] = [
5213+ 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0,
5214+];
5215+/// The class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling of [`EOB_PT_1024_LUMA`]
5216+/// (lane-eobc1 r1, machine-extracted from libaom `token_cdfs.h`).
5217+pub const EOB_PT_1024_LUMA_CLASS1_Q0: [u16; 12] = [
5218+ 2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0,
5219+];
5220+pub const EOB_PT_1024_LUMA_CLASS1_Q1: [u16; 12] = [
5221+ 2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0,
5222+];
5223+pub const EOB_PT_1024_LUMA_CLASS1: [u16; 12] = [
5224+ 2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0,
5225+];
5226+pub const EOB_PT_1024_LUMA_CLASS1_Q3: [u16; 12] = [
5227+ 2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0,
5228+];
5229+/// The class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling of [`EOB_PT_1024_CHROMA`]
5230+/// (lane-eobc1 r1, machine-extracted from libaom `token_cdfs.h`).
5231+pub const EOB_PT_1024_CHROMA_CLASS1_Q0: [u16; 12] = [
5232+ 2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0,
5233+];
5234+pub const EOB_PT_1024_CHROMA_CLASS1_Q1: [u16; 12] = [
5235+ 2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0,
5236+];
5237+pub const EOB_PT_1024_CHROMA_CLASS1: [u16; 12] = [
5238+ 2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0,
5239+];
5240+pub const EOB_PT_1024_CHROMA_CLASS1_Q3: [u16; 12] = [
5241+ 2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0,
5242+];
crates/ec-av1/src/cdf_state.rsmodified+64 -9
@@ -225,6 +225,21 @@ pub(crate) struct Cdfs {
225225 pub eob_pt_256_chroma_class1: [u16; 10],
226226 pub eob_pt_64_chroma_class1: [u16; 8],
227227 pub eob_pt_16_chroma_class1: [u16; 6],
228+ /// `128_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see
229+ /// [`Cdfs::eob_pt_16_luma_class1`] (lane-eobc1 r1).
230+ pub eob_pt_128_chroma_class1: [u16; 9],
231+ /// `512_luma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see
232+ /// [`Cdfs::eob_pt_16_luma_class1`] (lane-eobc1 r1).
233+ pub eob_pt_512_luma_class1: [u16; 11],
234+ /// `512_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see
235+ /// [`Cdfs::eob_pt_16_luma_class1`] (lane-eobc1 r1).
236+ pub eob_pt_512_chroma_class1: [u16; 11],
237+ /// `1024_luma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see
238+ /// [`Cdfs::eob_pt_16_luma_class1`] (lane-eobc1 r1).
239+ pub eob_pt_1024_luma_class1: [u16; 12],
240+ /// `1024_chroma`'s class-1 (`TX_CLASS_HORIZ`/`VERT`) sibling, see
241+ /// [`Cdfs::eob_pt_16_luma_class1`] (lane-eobc1 r1).
242+ pub eob_pt_1024_chroma_class1: [u16; 12],
228243 /// The end-of-block offset bit of a 16x16 luma transform.
229244 pub eob_extra_luma_16: [[u16; 3]; 9],
230245 /// The same, for an 8x8 luma transform.
@@ -637,6 +652,11 @@ impl Cdfs {
637652 reset1(&mut self.eob_pt_256_chroma_class1);
638653 reset1(&mut self.eob_pt_64_chroma_class1);
639654 reset1(&mut self.eob_pt_16_chroma_class1);
655+ reset1(&mut self.eob_pt_128_chroma_class1);
656+ reset1(&mut self.eob_pt_512_luma_class1);
657+ reset1(&mut self.eob_pt_512_chroma_class1);
658+ reset1(&mut self.eob_pt_1024_luma_class1);
659+ reset1(&mut self.eob_pt_1024_chroma_class1);
640660 reset2(&mut self.eob_extra_luma_16);
641661 reset2(&mut self.eob_extra_luma_8);
642662 reset2(&mut self.eob_extra_luma_4);
@@ -886,6 +906,41 @@ impl Cdfs {
886906 cdf::EOB_PT_16_CHROMA_CLASS1,
887907 cdf::EOB_PT_16_CHROMA_CLASS1_Q3,
888908 ),
909+ eob_pt_128_chroma_class1: pick(
910+ q_ctx,
911+ cdf::EOB_PT_128_CHROMA_CLASS1_Q0,
912+ cdf::EOB_PT_128_CHROMA_CLASS1_Q1,
913+ cdf::EOB_PT_128_CHROMA_CLASS1,
914+ cdf::EOB_PT_128_CHROMA_CLASS1_Q3,
915+ ),
916+ eob_pt_512_luma_class1: pick(
917+ q_ctx,
918+ cdf::EOB_PT_512_LUMA_CLASS1_Q0,
919+ cdf::EOB_PT_512_LUMA_CLASS1_Q1,
920+ cdf::EOB_PT_512_LUMA_CLASS1,
921+ cdf::EOB_PT_512_LUMA_CLASS1_Q3,
922+ ),
923+ eob_pt_512_chroma_class1: pick(
924+ q_ctx,
925+ cdf::EOB_PT_512_CHROMA_CLASS1_Q0,
926+ cdf::EOB_PT_512_CHROMA_CLASS1_Q1,
927+ cdf::EOB_PT_512_CHROMA_CLASS1,
928+ cdf::EOB_PT_512_CHROMA_CLASS1_Q3,
929+ ),
930+ eob_pt_1024_luma_class1: pick(
931+ q_ctx,
932+ cdf::EOB_PT_1024_LUMA_CLASS1_Q0,
933+ cdf::EOB_PT_1024_LUMA_CLASS1_Q1,
934+ cdf::EOB_PT_1024_LUMA_CLASS1,
935+ cdf::EOB_PT_1024_LUMA_CLASS1_Q3,
936+ ),
937+ eob_pt_1024_chroma_class1: pick(
938+ q_ctx,
939+ cdf::EOB_PT_1024_CHROMA_CLASS1_Q0,
940+ cdf::EOB_PT_1024_CHROMA_CLASS1_Q1,
941+ cdf::EOB_PT_1024_CHROMA_CLASS1,
942+ cdf::EOB_PT_1024_CHROMA_CLASS1_Q3,
943+ ),
889944 eob_extra_luma_16: pick(
890945 q_ctx,
891946 cdf::EOB_EXTRA_LUMA_16_Q0,
@@ -1283,7 +1338,7 @@ impl Cdfs {
12831338 br: &mut self.br_luma_32,
12841339 dc_sign: &mut self.dc_sign_luma,
12851340 tx_type: None,
1286- eob_pt_class1: None,
1341+ eob_pt_class1: Some(&mut self.eob_pt_1024_luma_class1),
12871342 },
12881343 // lane-comppin r4 (REVERTED, see r4's own commit message):
12891344 // `Some(inter_tx_type_32)` looked wrong against aomdec's 32x32
@@ -1307,7 +1362,7 @@ impl Cdfs {
13071362 br: &mut self.br_luma_32,
13081363 dc_sign: &mut self.dc_sign_luma,
13091364 tx_type: Some(self.inter_tx_type_32.as_mut_slice()),
1310- eob_pt_class1: None,
1365+ eob_pt_class1: Some(&mut self.eob_pt_1024_luma_class1),
13111366 },
13121367 TxbSet::Luma64 => TxbTables {
13131368 side: 32,
@@ -1319,7 +1374,7 @@ impl Cdfs {
13191374 br: &mut self.br_luma_32,
13201375 dc_sign: &mut self.dc_sign_luma,
13211376 tx_type: None,
1322- eob_pt_class1: None,
1377+ eob_pt_class1: Some(&mut self.eob_pt_1024_luma_class1),
13231378 },
13241379 TxbSet::Luma16 => TxbTables {
13251380 side: 16,
@@ -1403,7 +1458,7 @@ impl Cdfs {
14031458 br: &mut self.br_luma_4,
14041459 dc_sign: &mut self.dc_sign_luma,
14051460 tx_type: Some(self.inter_tx_type_4.as_mut_slice()),
1406- eob_pt_class1: None,
1461+ eob_pt_class1: Some(&mut self.eob_pt_16_luma_class1),
14071462 },
14081463 TxbSet::Luma4InterSet1 => TxbTables {
14091464 side: 4,
@@ -1439,7 +1494,7 @@ impl Cdfs {
14391494 br: &mut self.br_luma_8,
14401495 dc_sign: &mut self.dc_sign_luma,
14411496 tx_type: Some(self.inter_tx_type_8.as_mut_slice()),
1442- eob_pt_class1: None,
1497+ eob_pt_class1: Some(&mut self.eob_pt_64_luma_class1),
14431498 },
14441499 TxbSet::Luma8InterSet1 => TxbTables {
14451500 side: 8,
@@ -1499,7 +1554,7 @@ impl Cdfs {
14991554 br: &mut self.br_chroma_32,
15001555 dc_sign: &mut self.dc_sign_chroma,
15011556 tx_type: None,
1502- eob_pt_class1: None,
1557+ eob_pt_class1: Some(&mut self.eob_pt_1024_chroma_class1),
15031558 },
15041559 TxbSet::LumaRect32x16 => TxbTables {
15051560 side: 32,
@@ -1511,7 +1566,7 @@ impl Cdfs {
15111566 br: &mut self.br_luma_32,
15121567 dc_sign: &mut self.dc_sign_luma,
15131568 tx_type: None,
1514- eob_pt_class1: None,
1569+ eob_pt_class1: Some(&mut self.eob_pt_512_luma_class1),
15151570 },
15161571 TxbSet::ChromaRect16x8 => TxbTables {
15171572 side: 16,
@@ -1523,7 +1578,7 @@ impl Cdfs {
15231578 br: &mut self.br_chroma_16,
15241579 dc_sign: &mut self.dc_sign_chroma,
15251580 tx_type: None,
1526- eob_pt_class1: None,
1581+ eob_pt_class1: Some(&mut self.eob_pt_128_chroma_class1),
15271582 },
15281583 TxbSet::ChromaRect32x16 => TxbTables {
15291584 side: 32,
@@ -1535,7 +1590,7 @@ impl Cdfs {
15351590 br: &mut self.br_chroma_32,
15361591 dc_sign: &mut self.dc_sign_chroma,
15371592 tx_type: None,
1538- eob_pt_class1: None,
1593+ eob_pt_class1: Some(&mut self.eob_pt_512_chroma_class1),
15391594 },
15401595 }
15411596 }
crates/ec-av1/src/decode.rsmodified+26 -0
@@ -1583,6 +1583,30 @@ pub(crate) fn angle_delta_hits() -> usize {
15831583 pub(crate) fn tx_class1_hits() -> usize {
15841584 TX_CLASS1_HITS.with(|c| c.get())
15851585 }
1586+
1587+// How many CHROMA coefficient blocks read their `eob_pt` from the class-1
1588+// (`TX_CLASS_HORIZ`/`VERT`) row, across every call on the current thread.
1589+// Chroma never codes a `tx_type` symbol -- it inherits the colocated luma
1590+// type verbatim (`av1_get_tx_type`, `blockd.h:1291`) -- so this fires only on
1591+// an inter leaf whose luma picked a 1D type, the path lane-eobc1 wired
1592+// (`eob_pt_{16,64,128,256}_chroma_class1`).
1593+thread_local! {
1594+ static CHROMA_EOB_CLASS1_HITS: std::cell::Cell<usize> =
1595+ const { std::cell::Cell::new(0) };
1596+}
1597+
1598+/// Current value of [`CHROMA_EOB_CLASS1_HITS`].
1599+pub(crate) fn chroma_eob_class1_hits() -> usize {
1600+ CHROMA_EOB_CLASS1_HITS.with(|c| c.get())
1601+}
1602+
1603+/// Counts one [`CHROMA_EOB_CLASS1_HITS`] when `plane_idx`'s inherited
1604+/// `tx_type` put this block's `eob_pt` on the class-1 row.
1605+fn note_chroma_class1(plane_idx: usize, tx_type: TxType) {
1606+ if plane_idx > 0 && TxClass::of(tx_type) != TxClass::TwoD {
1607+ CHROMA_EOB_CLASS1_HITS.with(|c| c.set(c.get() + 1));
1608+ }
1609+}
15861610 const SUB_MI: u32 = 4;
15871611 const MI: usize = 4;
15881612 const SB: usize = 64;
@@ -5861,6 +5885,7 @@ fn read_plane(
58615885 default_tx_type,
58625886 None,
58635887 )?;
5888+ note_chroma_class1(plane_idx, tx_type);
58645889 // A 64x64 luma block's transform covers the whole 64x64 area, but only its
58655890 // top-left 32x32 of frequencies are coded (spec 5.11.40); the rest of the
58665891 // dequantized grid stays zero, which `inverse_transform_2d`'s own `< 32`
@@ -9932,6 +9957,7 @@ fn read_inter_plane(
99329957 default_tx_type,
99339958 None,
99349959 )?;
9960+ note_chroma_class1(plane_idx, tx_type);
99359961 // lane-inter8 r1: a 64-point transform covers the whole 64x64 area but
99369962 // codes only its top-left 32x32 of frequencies (spec 5.11.40) -- the
99379963 // caller hands the 32-point `scan` there, and the coded corner goes into
crates/ec-av1/src/stream.rsmodified+192 -0
@@ -4515,6 +4515,198 @@ mod tests {
45154515 );
45164516 }
45174517
4518+ /// lane-eobc1 r1: an INTER sequence whose CHROMA coefficient blocks come
4519+ /// off the class-1 (`TX_CLASS_HORIZ`/`VERT`) `eob_pt` row. Chroma codes
4520+ /// no `tx_type` symbol of its own -- it inherits the colocated luma type
4521+ /// (`av1_get_tx_type`, `blockd.h:1291`) -- so an 8x8 inter leaf whose
4522+ /// luma picks `H_*`/`V_*` puts its 4x4 chroma on a CDF row this crate
4523+ /// wired for only some sizes until this round (`eob_pt_class1: None` in
4524+ /// 9 of 16 `TxbSet` arms, chroma 4x4/8x8 among them).
4525+ ///
4526+ /// The full tx set stays on (no `--reduced-tx-type-set=1`) and
4527+ /// `--enable-flip-idtx=1` is asked for explicitly; the sinusoidal-stripe
4528+ /// luma of the `tx_class1` key-frame gate is what actually resolves 1D
4529+ /// types, and the temporally-moving chroma ramp keeps chroma out of
4530+ /// `all_zero` so it has an `eob` to read at all. Attempts sweep cq and
4531+ /// stripe period; a run counts only when
4532+ /// [`decode::chroma_eob_class1_hits`] moved, and every shown frame is
4533+ /// compared pixel-exact vs ffmpeg (a decode error is a FAILURE, never a
4534+ /// SKIP -- class gate-skips-on-its-own-failure).
4535+ fn chroma_class1_eob_gate(name: &str, ten_bit: bool) {
4536+ if !have_ffmpeg() {
4537+ eprintln!("SKIP {name}: no ffmpeg");
4538+ return;
4539+ }
4540+ if !have_aomenc() {
4541+ eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display());
4542+ return;
4543+ }
4544+ let (width, height, frame_count) = (64usize, 64usize, 4usize);
4545+ let mut refusals = Vec::new();
4546+ for attempt in 0..12u32 {
4547+ let cq = 28 + (attempt % 4) * 10;
4548+ let period = [4u32, 6, 8][(attempt as usize / 4) % 3];
4549+ let y4m = Command::new("ffmpeg")
4550+ .args([
4551+ "-v",
4552+ "error",
4553+ "-f",
4554+ "lavfi",
4555+ "-i",
4556+ &format!("testsrc2=size={width}x{height}:rate=25"),
4557+ "-vf",
4558+ &format!(
4559+ "geq=lum='128+80*sin(2*PI*Y/{period})':cb='128+60*sin(2*PI*(X+8*T)/{period})':cr='128+60*sin(2*PI*(Y+8*T)/{period})',noise=alls=6:allf=t:all_seed=7"
4560+ ),
4561+ "-t",
4562+ "0.16",
4563+ "-pix_fmt",
4564+ if ten_bit { "yuv420p10le" } else { "yuv420p" },
4565+ "-strict",
4566+ "-1",
4567+ "-f",
4568+ "yuv4mpegpipe",
4569+ "-",
4570+ ])
4571+ .stdin(Stdio::null())
4572+ .stdout(Stdio::piped())
4573+ .stderr(Stdio::piped())
4574+ .output()
4575+ .expect("ffmpeg failed to run");
4576+ assert!(
4577+ y4m.status.success(),
4578+ "{name}: ffmpeg fixture: {}",
4579+ String::from_utf8_lossy(&y4m.stderr)
4580+ );
4581+ let mut args: Vec<String> = [
4582+ "--codec=av1",
4583+ "--passes=1",
4584+ "--end-usage=q",
4585+ "--cpu-used=0",
4586+ "--lag-in-frames=0",
4587+ "--auto-alt-ref=0",
4588+ "--kf-max-dist=1000",
4589+ "--error-resilient=1",
4590+ "--enable-flip-idtx=1",
4591+ "--reduced-tx-type-set=0",
4592+ "--min-partition-size=8",
4593+ "--max-partition-size=16",
4594+ // Motion tools this decoder refuses by name, kept off so a
4595+ // refusal here can only be about the coefficient path.
4596+ "--enable-global-motion=0",
4597+ "--enable-warped-motion=0",
4598+ "--enable-obmc=0",
4599+ "--enable-rect-partitions=0",
4600+ "--enable-ab-partitions=0",
4601+ "--enable-1to4-partitions=0",
4602+ "--enable-filter-intra=0",
4603+ "--enable-smooth-intra=0",
4604+ "--enable-paeth-intra=0",
4605+ "--enable-directional-intra=0",
4606+ "--enable-angle-delta=0",
4607+ "--enable-tx-size-search=0",
4608+ "--enable-cdef=0",
4609+ "--enable-restoration=0",
4610+ "--loopfilter-control=0",
4611+ "--enable-palette=0",
4612+ "--enable-intrabc=0",
4613+ "--enable-cfl-intra=0",
4614+ "--enable-ref-frame-mvs=0",
4615+ "--obu",
4616+ "-o",
4617+ "-",
4618+ "-",
4619+ ]
4620+ .iter()
4621+ .map(|s| (*s).to_string())
4622+ .collect();
4623+ args.insert(1, format!("--cq-level={cq}"));
4624+ if ten_bit {
4625+ args.insert(1, "--input-bit-depth=10".to_string());
4626+ args.insert(1, "--bit-depth=10".to_string());
4627+ }
4628+ let mut child = Command::new(aomenc_path())
4629+ .args(&args)
4630+ .stdin(Stdio::piped())
4631+ .stdout(Stdio::piped())
4632+ .stderr(Stdio::piped())
4633+ .spawn()
4634+ .expect("aomenc failed to start");
4635+ child
4636+ .stdin
4637+ .take()
4638+ .expect("aomenc stdin")
4639+ .write_all(&y4m.stdout)
4640+ .expect("writing y4m to aomenc");
4641+ let out = child.wait_with_output().expect("aomenc failed to run");
4642+ assert!(
4643+ out.status.success(),
4644+ "{name}: aomenc refused the fixture: {}",
4645+ String::from_utf8_lossy(&out.stderr)
4646+ );
4647+ let stream = out.stdout;
4648+ let before = decode::chroma_eob_class1_hits();
4649+ let frames = match decode_stream(&stream) {
4650+ Ok(frames) => frames,
4651+ // A named refusal ("unsupported: ...") is another lane's arm
4652+ // and moves this attempt on; anything else is a real decode
4653+ // failure and fails the gate on the spot.
4654+ Err(e) if e.to_string().contains("unsupported") => {
4655+ refusals.push(format!("cq={cq} period={period}: {e}"));
4656+ continue;
4657+ }
4658+ Err(e) => {
4659+ let pin = std::env::temp_dir().join(format!("{name}-refused.obu"));
4660+ let _ = std::fs::write(&pin, &stream);
4661+ panic!(
4662+ "{name}: decode_stream failed on a real aomenc stream (cq={cq} period={period}): {e} (pinned at {})",
4663+ pin.display()
4664+ );
4665+ }
4666+ };
4667+ if decode::chroma_eob_class1_hits() == before {
4668+ refusals.push(format!(
4669+ "cq={cq} period={period}: decoded, but no chroma block read a class-1 eob_pt row"
4670+ ));
4671+ continue;
4672+ }
4673+ let ffmpeg_frames = if ten_bit {
4674+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
4675+ } else {
4676+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
4677+ };
4678+ assert_eq!(frames.len(), frame_count, "{name}: frame count");
4679+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
4680+ if got.y != want.y || got.u != want.u || got.v != want.v {
4681+ let pin = std::env::temp_dir().join(format!("{name}-mismatch.obu"));
4682+ let _ = std::fs::write(&pin, &stream);
4683+ panic!(
4684+ "{name}: frame {i} mismatch vs ffmpeg (cq={cq} period={period}) -- stream pinned at {}",
4685+ pin.display()
4686+ );
4687+ }
4688+ }
4689+ return;
4690+ }
4691+ panic!("{name}: no attempt fired a class-1 chroma eob: {refusals:?}");
4692+ }
4693+
4694+ #[test]
4695+ fn a_real_aomenc_inter_sequence_with_a_class1_chroma_eob_decodes_pixel_exact() {
4696+ chroma_class1_eob_gate(
4697+ "a_real_aomenc_inter_sequence_with_a_class1_chroma_eob_decodes_pixel_exact",
4698+ false,
4699+ );
4700+ }
4701+
4702+ #[test]
4703+ fn a_real_aomenc_10bit_inter_sequence_with_a_class1_chroma_eob_decodes_pixel_exact() {
4704+ chroma_class1_eob_gate(
4705+ "a_real_aomenc_10bit_inter_sequence_with_a_class1_chroma_eob_decodes_pixel_exact",
4706+ true,
4707+ );
4708+ }
4709+
45184710 #[test]
45194711 fn a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact() {
45204712 if !have_ffmpeg() {
scripts/extract-eob-class1.pyadded+69 -0
@@ -0,0 +1,69 @@
1+#!/usr/bin/env python3
2+"""Extract libaom's eob_multi CDF rows and emit / verify our Rust consts.
3+
4+`av1_default_eob_multi{16,32,64,128,256,512,1024}_cdfs` are
5+`[TOKEN_CDF_Q_CTXS][PLANE_TYPES][2][CDF_SIZE(n)]`; the third index is
6+`eob_multi_ctx = (tx_class == TX_CLASS_2D) ? 0 : 1`. This prints the
7+class-1 (index 1) rows as `EOB_PT_<n>_<PLANE>_CLASS1[_Qk]` consts and, with
8+`--check <cdf.rs>`, diffs every const that file already defines.
9+
10+Usage: extract-eob-class1.py <token_cdfs.h> [--check <cdf.rs>]
11+"""
12+
13+import re
14+import sys
15+
16+SIZES = [16, 32, 64, 128, 256, 512, 1024]
17+QSUF = ["_Q0", "_Q1", "", "_Q3"]
18+
19+
20+def parse(src: str, size: int):
21+ m = re.search(rf"av1_default_eob_multi{size}_cdfs\b(.*?)\n\s*\n", src, re.S)
22+ if not m:
23+ sys.exit(f"table eob_multi{size} not found")
24+ rows = [
25+ [int(x) for x in r.split(",")]
26+ for r in re.findall(r"AOM_CDF\d+\(([^)]*)\)", m.group(1))
27+ ]
28+ # flat order: q-major, then plane, then class
29+ if len(rows) != 4 * 2 * 2:
30+ sys.exit(f"eob_multi{size}: expected 16 rows, got {len(rows)}")
31+ return rows
32+
33+
34+def consts(src):
35+ out = {}
36+ for size in SIZES:
37+ rows = parse(src, size)
38+ for q in range(4):
39+ for p, plane in enumerate(("LUMA", "CHROMA")):
40+ row = rows[q * 4 + p * 2 + 1]
41+ out[f"EOB_PT_{size}_{plane}_CLASS1{QSUF[q]}"] = row + [32768, 0]
42+ return out
43+
44+
45+def main():
46+ src = open(sys.argv[1]).read()
47+ want = consts(src)
48+ if "--check" in sys.argv:
49+ rs = open(sys.argv[sys.argv.index("--check") + 1]).read()
50+ seen = bad = 0
51+ for name, vals in want.items():
52+ m = re.search(rf"const {name}: \[u16; \d+\] =\s*(\[[^]]*\]);", rs)
53+ if not m:
54+ continue
55+ seen += 1
56+ got = [int(x) for x in re.findall(r"\d+", m.group(1))]
57+ if got != vals:
58+ bad += 1
59+ print(f"MISMATCH {name}\n ours {got}\n aom {vals}")
60+ print(f"checked {seen}/{len(want)} consts, {bad} mismatched")
61+ missing = [n for n in want if f"const {n}:" not in rs]
62+ print(f"missing {len(missing)}: {' '.join(sorted(missing))}")
63+ sys.exit(1 if bad else 0)
64+ for name, vals in want.items():
65+ body = ", ".join(str(v) for v in vals)
66+ print(f"pub const {name}: [u16; {len(vals)}] = [{body}];")
67+
68+
69+main()