forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-t900' (074283d1): screen-content inter frames code palette syntax on rect intra strips; partition-alphabet and var-tx leaf enumerations prove 5 more refusals (13 proven)

Browse files at this commit

b0b1b4741df357f143570be6e2d55f00c908d841Ahmet Kaan GümüşParent: 1a546745b764e4
crates/ec-av1/src/decode.rsmodified+128 -9
@@ -2521,6 +2521,25 @@ thread_local! {
2521 const { std::cell::Cell::new([0; 3]) };2521 const { std::cell::Cell::new([0; 3]) };
2522 }2522 }
2523 2523
2524+// lane-t900 r21: rect intra strips inside an inter frame that read the
2525+// screen-content palette syntax (`allow_screen_content_tools` set and the
2526+// strip's own shape admitted by `palette_bsize_ctx_wh`) -- the site a blanket
2527+// refusal used to guard, so this counter is what keeps its witness gate
2528+// non-vacuous.
2529+thread_local! {
2530+ static INTRA_RECT_IN_INTER_SCREEN_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
2531+}
2532+
2533+/// Current value of [`INTRA_RECT_IN_INTER_SCREEN_HITS`].
2534+pub(crate) fn intra_rect_in_inter_screen_hits() -> usize {
2535+ INTRA_RECT_IN_INTER_SCREEN_HITS.with(std::cell::Cell::get)
2536+}
2537+
2538+/// Resets [`INTRA_RECT_IN_INTER_SCREEN_HITS`] before a decode.
2539+pub(crate) fn reset_intra_rect_in_inter_screen_hits() {
2540+ INTRA_RECT_IN_INTER_SCREEN_HITS.with(|c| c.set(0));
2541+}
2542+
2524 /// Current value of [`INTRA_RECT_IN_INTER_SPLIT_TX_HITS`], indexed by tx depth.2543 /// Current value of [`INTRA_RECT_IN_INTER_SPLIT_TX_HITS`], indexed by tx depth.
2525 pub(crate) fn intra_rect_in_inter_split_tx_hits() -> [usize; 3] {2544 pub(crate) fn intra_rect_in_inter_split_tx_hits() -> [usize; 3] {
2526 INTRA_RECT_IN_INTER_SPLIT_TX_HITS.with(std::cell::Cell::get)2545 INTRA_RECT_IN_INTER_SPLIT_TX_HITS.with(std::cell::Cell::get)
@@ -7852,15 +7871,14 @@ fn decode_intra_rect_in_inter(
7852 "an intra-coded {bw}x{bh} block on the inter block path (no size-group/tx-category row for that shape here)"7871 "an intra-coded {bw}x{bh} block on the inter block path (no size-group/tx-category row for that shape here)"
7853 )));7872 )));
7854 };7873 };
7855- // [`read_intra_mode_rect`]'s own refusal: palette/intrabc syntax is7874+ // lane-t900 r21: this arm used to refuse EVERY rect strip of a
7856- // consumed for square blocks only, so a strip in a screen-content frame7875+ // screen-content frame ("palette syntax is consumed for square blocks
7857- // would skip symbols the encoder wrote.7876+ // only"). It is not: [`read_intra_mode_rect`] generalised the palette read
7858- if allow_screen_content_tools {7877+ // to rect blocks on the key-frame path, and the 1:4 arm below goes through
7859- return Err(unsupported(7878+ // it, while the 2:1 reader inlined further down now codes the same syntax
7860- "a HORZ/VERT intra strip in a screen-content frame (palette syntax \7879+ // itself. A real `--tune-content=screen` inter stream reached this refusal
7861- is consumed for square blocks only)",7880+ // on 8x16 / 16x8 strips (gate
7862- ));7881+ // `a_real_aomenc_screen_inter_sequence_codes_palette_syntax_on_rect_intra_strips`).
7863- }
7864 // lane-intra14 r1: a 1:4 strip decodes through the very readers the KEY7882 // lane-intra14 r1: a 1:4 strip decodes through the very readers the KEY
7865 // FRAME path already proves for this shape ([`decode_block_rect4`] at the7883 // FRAME path already proves for this shape ([`decode_block_rect4`] at the
7866 // 32 level, [`decode_block_rect64`] at 64 -- both already handle the 1:47884 // 32 level, [`decode_block_rect64`] at 64 -- both already handle the 1:4
@@ -7991,6 +8009,32 @@ fn decode_intra_rect_in_inter(
7991 UV_ANGLE_DELTA_HITS.with(|h| h.set(h.get() + 1));8009 UV_ANGLE_DELTA_HITS.with(|h| h.set(h.get() + 1));
7992 INTRA_IN_INTER_ANGLE_DELTA_UV_HITS.with(|h| h.set(h.get() + 1));8010 INTRA_IN_INTER_ANGLE_DELTA_UV_HITS.with(|h| h.set(h.get() + 1));
7993 }8011 }
8012+ // `read_palette_mode_info` (spec 5.11.13), in the position
8013+ // `read_intra_block_mode_info` writes it: after the chroma mode and
8014+ // before `filter_intra`. lane-t900 r21: a `--tune-content=screen` inter
8015+ // frame writes `palette_y_mode`/`palette_uv_mode` for every block whose
8016+ // shape [`palette_bsize_ctx_wh`] admits, intra strips included, so
8017+ // skipping the syntax here desynced the tile at the strip's own symbol.
8018+ // No block this decoder produces can USE a palette (the arms below refuse
8019+ // by name), so the neighbour mode context is 0 and there is no cache --
8020+ // the same stand-in [`read_intra_mode_rect`] uses when its caller has none.
8021+ if allow_screen_content_tools
8022+ && let Some(bsize_ctx) = palette_bsize_ctx_wh(bw, bh)
8023+ {
8024+ INTRA_RECT_IN_INTER_SCREEN_HITS.with(|c| c.set(c.get() + 1));
8025+ if mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[bsize_ctx][0]) != 0 {
8026+ return Err(unsupported(
8027+ "a block that actually uses a palette (Y) -- reconstruction is out of scope",
8028+ ));
8029+ }
8030+ // A 2:1 strip of at least 8x8 is always a chroma reference, so
8031+ // `read_palette_mode_info`'s `xd->is_chroma_ref` guard holds here.
8032+ if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[0]) != 0 {
8033+ return Err(unsupported(
8034+ "a block that actually uses a palette (UV) -- reconstruction is out of scope",
8035+ ));
8036+ }
8037+ }
7994 // lane-fiinter (merged on main for the square intra-in-inter arm):8038 // lane-fiinter (merged on main for the square intra-in-inter arm):
7995 // `read_filter_intra_mode_info` is the tail of8039 // `read_filter_intra_mode_info` is the tail of
7996 // `read_intra_block_mode_info`, after the palette syntax (refused whole8040 // `read_intra_block_mode_info`, after the palette syntax (refused whole
@@ -14351,6 +14395,81 @@ fn sub_tx_size_map_matches_libaom() {
14351 }14395 }
14352 }14396 }
14353 14397
14398+/// The domain of var-tx leaf sizes, enumerated against the two refusals that
14399+/// name a leaf "larger than 32x32" / "larger than 64x64".
14400+///
14401+/// [`read_var_tx_size`] emits a leaf in exactly three places, and each one is
14402+/// either the unit it was entered with or a `sub_tx_size_map` step below it:
14403+/// the depth cap, the `!split` return, and libaom's `sub_txs == TX_4X4` early
14404+/// return. So the leaf set reachable from an entry unit is that unit plus the
14405+/// chain of `sub_tx_size_map` steps under it, capped at `MAX_VARTX_DEPTH` --
14406+/// which this test enumerates, and over which no leaf is ever larger than the
14407+/// entry.
14408+///
14409+/// That closes both refusals:
14410+///
14411+/// * [`read_block_tx_size_rect`]'s `bw.max(bh) > 64` branch enters every unit
14412+/// at TX_64X64 (`max_txsize_rect_lookup[BLOCK_128X64]`), so "larger than
14413+/// 64x64" names a leaf the tree cannot produce;
14414+/// * [`read_block_tx_size`] enters at `side.min(64)` with a ceiling of 32
14415+/// below the 128 root. The only entry that exceeds that ceiling is 64x64,
14416+/// reached only when `side == 64`, and then the block is ONE unit whose only
14417+/// above-ceiling leaf is the whole 64x64 unit itself -- which is the `single`
14418+/// case the refusal is guarded by.
14419+#[test]
14420+fn a_var_tx_tree_never_presents_a_leaf_larger_than_the_unit_it_entered() {
14421+ // Every leaf `read_var_tx_size` can reach from `entry`, as (depth, w, h).
14422+ fn reachable(entry: (usize, usize), depth: usize, out: &mut Vec<(usize, usize, usize)>) {
14423+ out.push((depth, entry.0, entry.1));
14424+ if depth == MAX_VARTX_DEPTH {
14425+ return;
14426+ }
14427+ let sub = sub_tx_size_map(entry.0, entry.1);
14428+ if sub == (4, 4) {
14429+ out.push((depth + 1, 4, 4));
14430+ return;
14431+ }
14432+ reachable(sub, depth + 1, out);
14433+ }
14434+
14435+ for entry in [(4, 4), (8, 8), (16, 16), (32, 32), (64, 64)] {
14436+ let mut leaves = Vec::new();
14437+ reachable(entry, 0, &mut leaves);
14438+ for (depth, w, h) in &leaves {
14439+ assert!(
14440+ w.max(h) <= &entry.0.max(entry.1),
14441+ "a {}x{} unit reaches a {w}x{h} leaf at depth {depth}",
14442+ entry.0,
14443+ entry.1
14444+ );
14445+ }
14446+ // Above-ceiling leaves of a 64x64 entry: the entry itself, at depth 0.
14447+ if entry == (64, 64) {
14448+ let above: Vec<&(usize, usize, usize)> =
14449+ leaves.iter().filter(|(_, w, h)| w.max(h) > &32).collect();
14450+ assert_eq!(above, [&(0usize, 64usize, 64usize)], "64x64 entry, leaves above 32");
14451+ }
14452+ }
14453+
14454+ // The entry size and ceiling each caller uses, over the block sides that
14455+ // reach them (`read_block_tx_size`'s square path; the 128-root rect path
14456+ // enters at a fixed 64).
14457+ for side in [8usize, 16, 32, 64, 128] {
14458+ let max_tx = side.min(64);
14459+ let ceiling = if side > 64 { 64 } else { 32 };
14460+ let units = (side / max_tx) * (side / max_tx);
14461+ if max_tx <= ceiling {
14462+ continue;
14463+ }
14464+ assert_eq!(
14465+ (side, units),
14466+ (64, 1),
14467+ "a {side}px block enters var-tx at {max_tx} over a ceiling of {ceiling} in \
14468+ {units} units -- an above-ceiling leaf there would NOT be the `single` case"
14469+ );
14470+ }
14471+}
14472+
14354 /// `read_var_tx_size` (spec 5.11.17, libaom `decodeframe.c`14473 /// `read_var_tx_size` (spec 5.11.17, libaom `decodeframe.c`
14355 /// `read_tx_size_vartx`): the recursive `txfm_split` tree of one14474 /// `read_tx_size_vartx`): the recursive `txfm_split` tree of one
14356 /// max-transform-sized unit of an inter block, collecting the resolved leaf14475 /// max-transform-sized unit of an inter block, collecting the resolved leaf
crates/ec-av1/src/refusal_inventory.rsmodified+168 -3
@@ -103,8 +103,17 @@ const REFUSALS: &[&str] = &[
103 // what is left is the 1:4 shape, whose `bsize_to_tx_size_cat` breaks the103 // what is left is the 1:4 shape, whose `bsize_to_tx_size_cat` breaks the
104 // size-group/category diagonal the 2:1 shapes share.104 // size-group/category diagonal the 2:1 shapes share.
105 "an intra-coded {bw}x{bh} block on the inter block path (no size-group/tx-category row for that shape here)",105 "an intra-coded {bw}x{bh} block on the inter block path (no size-group/tx-category row for that shape here)",
106- // The same arm's screen-content gate: palette/intrabc syntax is consumed106+ // lane-t900 r21 NARROWED this: the string used to guard EVERY rect intra
107- // for square blocks only, so a strip in such a frame would skip symbols.107+ // strip of a screen-content inter frame, and a real
108+ // `--tune-content=screen` stream reached it on an 8x16 (8-bit) / 16x8
109+ // (10-bit) strip. The 2:1 reader now codes the palette syntax itself and
110+ // the 1:4 arm goes through `read_intra_mode_rect`, which already did --
111+ // both arms of gate
112+ // `a_real_aomenc_screen_inter_sequence_codes_palette_syntax_on_rect_intra_strips`
113+ // decode ten frames pixel-exact with the strips counted. What still
114+ // refuses is a 16x4/4x16 strip and a 128-root half, neither of which is
115+ // palette-eligible (`palette_bsize_ctx_wh` wants `8 <= min`, `max <= 64`)
116+ // and neither of which has a witness stream yet.
108 "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)",117 "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)",
109 "warp prediction with a scaled reference (superres, unimplemented)",118 "warp prediction with a scaled reference (superres, unimplemented)",
110 "an 8x8 partition leaf under a scaled reference (superres, unimplemented)",119 "an 8x8 partition leaf under a scaled reference (superres, unimplemented)",
@@ -166,6 +175,47 @@ const PROVEN: &[(&str, &str)] = &[
166 "a rectangular transform unit whose shape has no coefficient scan table here",175 "a rectangular transform unit whose shape has no coefficient scan table here",
167 "every_rect_transform_shape_the_census_lists_has_a_coefficient_table_and_scan",176 "every_rect_transform_shape_the_census_lists_has_a_coefficient_table_and_scan",
168 ),177 ),
178+ // lane-t900 r21, enumeration: a var-tx leaf is never larger than the unit
179+ // the tree was entered with, and both callers enter at or below their own
180+ // ceiling (the one case that does not, a 64px block at TX_64X64, is the
181+ // `single` whole-block case the refusal is guarded by).
182+ (
183+ "an inter var-tx tree with a leaf transform larger than 32x32",
184+ "a_var_tx_tree_never_presents_a_leaf_larger_than_the_unit_it_entered",
185+ ),
186+ (
187+ "an inter var-tx tree with a leaf transform larger than 64x64",
188+ "a_var_tx_tree_never_presents_a_leaf_larger_than_the_unit_it_entered",
189+ ),
190+ // Pre-existing proofs, registered by lane-t900 r21: a negative gate (a
191+ // hand-built 12-bit sequence header is refused BY THIS EXACT STRING rather
192+ // than decoded wrong) and a witness gate (a real aomenc screen key frame
193+ // reaches intrabc on a rect strip, so the refusal names a shape a real
194+ // encoder does write).
195+ // lane-t900 r21, enumeration: `partition_w32` is a ten-symbol CDF and
196+ // `partition_w128` an eight-symbol one, and every `match` carrying one of
197+ // these three fallbacks has an arm for each value of its own alphabet, so
198+ // no stream can reach them.
199+ (
200+ "a 32x32 partition type this decoder does not code (value={part32})",
201+ "every_partition_value_of_an_enumerated_alphabet_has_an_arm",
202+ ),
203+ (
204+ "an INTER 32x32 partition type this decoder does not code (value={part32})",
205+ "every_partition_value_of_an_enumerated_alphabet_has_an_arm",
206+ ),
207+ (
208+ "a 128x128 superblock partition value outside the 8-symbol alphabet",
209+ "every_partition_value_of_an_enumerated_alphabet_has_an_arm",
210+ ),
211+ (
212+ "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)",
213+ "a_twelve_bit_sequence_header_is_refused_by_name",
214+ ),
215+ (
216+ "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)",
217+ "a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips",
218+ ),
169 ];219 ];
170 220
171 /// Gates whose `Err` arm turns a decode failure into a printed SKIP rather than221 /// Gates whose `Err` arm turns a decode failure into a printed SKIP rather than
@@ -345,12 +395,127 @@ mod tests {
345 );395 );
346 }396 }
347 397
398+ /// The partition alphabets, enumerated against the arms that code them.
399+ ///
400+ /// A partition value is a CDF symbol, and `SymbolDecoder::symbol_fixed`
401+ /// cannot return one outside `0..nsyms` -- so a `match` whose arms cover
402+ /// its whole alphabet has an unreachable fallback, and the refusal that
403+ /// fallback carries names a value no stream can present. This test finds
404+ /// each such `match` by the refusal in its OWN fallback arm (rather than
405+ /// by line number, which drifts) and enumerates the alphabet against the
406+ /// arm patterns, ranges included.
407+ ///
408+ /// The refusals stay in the code: a partition value is a `usize`, so the
409+ /// match needs a fallback arm, and a named refusal is a better one than a
410+ /// panic (class `branch-dropped-as-unreachable`). What this removes is the
411+ /// UNMEASURED part of the claim.
412+ ///
413+ /// Not every partition fallback belongs here: the ones that name a shape
414+ /// this decoder genuinely does not code yet (the 128-root consumers) are
415+ /// live refusals, and the 16x16-level inter chain is an `if`/`else if`
416+ /// ladder rather than a match, so it needs its own enumerator.
417+ #[test]
418+ fn every_partition_value_of_an_enumerated_alphabet_has_an_arm() {
419+ const NAMES: [&str; 10] = [
420+ "PARTITION_NONE",
421+ "PARTITION_HORZ",
422+ "PARTITION_VERT",
423+ "PARTITION_SPLIT",
424+ "PARTITION_HORZ_A",
425+ "PARTITION_HORZ_B",
426+ "PARTITION_VERT_A",
427+ "PARTITION_VERT_B",
428+ "PARTITION_HORZ_4",
429+ "PARTITION_VERT_4",
430+ ];
431+ // (the refusal in the fallback arm, the alphabet its CDF codes)
432+ let blocks: [(&str, usize); 3] = [
433+ ("a 32x32 partition type this decoder does not code", crate::cdf::PARTITION_W32[0].len() - 1),
434+ ("an INTER 32x32 partition type this decoder does not code", crate::cdf::PARTITION_W32[0].len() - 1),
435+ ("a 128x128 superblock partition value outside the 8-symbol alphabet", crate::cdf::PARTITION_W128[0].len() - 1),
436+ ];
437+ // A pattern's own tokens, plus every value of an inclusive range
438+ // (`p if (PARTITION_HORZ_A..=PARTITION_VERT_B).contains(&p)` is four
439+ // arms in one).
440+ let covered = |head: &str| -> BTreeSet<usize> {
441+ let mut out = BTreeSet::new();
442+ let idx: Vec<usize> = head
443+ .split(|c: char| !(c.is_ascii_alphanumeric() || c == '_'))
444+ .filter_map(|tok| NAMES.iter().position(|n| *n == tok))
445+ .collect();
446+ if head.contains("..=") && idx.len() == 2 {
447+ for v in idx[0]..=idx[1] {
448+ out.insert(v);
449+ }
450+ }
451+ out.extend(idx);
452+ out
453+ };
454+
455+ let src = include_str!("decode.rs");
456+ let lines: Vec<&str> = src.lines().collect();
457+ let indent = |l: &str| l.len() - l.trim_start().len();
458+ let mut found = 0usize;
459+ for (i, line) in lines.iter().enumerate() {
460+ let t = line.trim();
461+ if !(t.starts_with("match part") && t.ends_with('{')) {
462+ continue;
463+ }
464+ let outer = indent(line);
465+ let close = " ".repeat(outer) + "}";
466+ let (mut arms, mut fallback) = (BTreeSet::new(), String::new());
467+ let mut in_fallback = false;
468+ for l in &lines[i + 1..] {
469+ if *l == close {
470+ break;
471+ }
472+ // Arm patterns sit exactly one level in; anything deeper is an
473+ // arm's body, nested matches and `part == PARTITION_*` reads
474+ // included.
475+ if indent(l) != outer + 4 && !l.trim().is_empty() {
476+ if in_fallback {
477+ fallback.push_str(l.trim());
478+ }
479+ continue;
480+ }
481+ if !l.contains("=>") {
482+ continue;
483+ }
484+ in_fallback = l.trim_start().starts_with("_ =>");
485+ arms.extend(covered(l.split("=>").next().unwrap_or("")));
486+ }
487+ let Some((reason, alphabet)) =
488+ blocks.iter().find(|(reason, _)| fallback.contains(reason))
489+ else {
490+ continue;
491+ };
492+ found += 1;
493+ let missing: Vec<usize> = (0..*alphabet).filter(|v| !arms.contains(v)).collect();
494+ assert!(
495+ missing.is_empty(),
496+ "the `match` at decode.rs:{} refuses {reason:?} but has no arm for {:?} -- that \
497+ is a real gap in its {alphabet}-value alphabet, not a dead refusal",
498+ i + 1,
499+ missing.iter().map(|v| NAMES[*v]).collect::<Vec<_>>()
500+ );
501+ }
502+ assert_eq!(
503+ found,
504+ blocks.len(),
505+ "not every enumerated partition refusal was located in decode.rs"
506+ );
507+ }
508+
348 /// Every entry of [`PROVEN`] must still name a live refusal and a test509 /// Every entry of [`PROVEN`] must still name a live refusal and a test
349 /// that exists, and the count it prints is the inventory's numerator.510 /// that exists, and the count it prints is the inventory's numerator.
350 #[test]511 #[test]
351 fn every_proven_refusal_names_a_test_that_exists() {512 fn every_proven_refusal_names_a_test_that_exists() {
352 let found = decode_path_refusals();513 let found = decode_path_refusals();
353- let sources = [include_str!("stream.rs"), include_str!("decode.rs")];514+ let sources = [
515+ include_str!("stream.rs"),
516+ include_str!("decode.rs"),
517+ include_str!("refusal_inventory.rs"),
518+ ];
354 for (reason, gate) in PROVEN {519 for (reason, gate) in PROVEN {
355 assert!(520 assert!(
356 found.contains(*reason),521 found.contains(*reason),
crates/ec-av1/src/stream.rsmodified+137 -0
@@ -30179,6 +30179,143 @@ mod tests {
30179 );30179 );
30180 }30180 }
30181 30181
30182+ /// lane-t900 r21: the witness for the palette SYNTAX on a rect intra strip
30183+ /// inside a screen-content INTER frame.
30184+ ///
30185+ /// `read_palette_mode_info` is gated by the frame's
30186+ /// `allow_screen_content_tools` and by the block's own shape
30187+ /// (`palette_bsize_ctx_wh`: `min(w,h) >= 8`, `max(w,h) <= 64`),
30188+ /// with no square-only term -- so a `--tune-content=screen` inter frame
30189+ /// writes `palette_y_mode` (and `palette_uv_mode`) for an 8x16 or 16x8
30190+ /// intra strip exactly as for a square block. This decoder's inter-path
30191+ /// intra arm skipped both symbols and refused the whole case by name ("a
30192+ /// HORZ/VERT intra strip in a screen-content frame (palette syntax is
30193+ /// consumed for square blocks only)"), which a real stream reached:
30194+ /// measured with `decode_probe`, `testsrc2` 256x192 at
30195+ /// `--tune-content=screen --enable-palette=0 --enable-intrabc=0` stops on
30196+ /// that refusal at an 8x16 strip (8-bit) / a 16x8 one (10-bit).
30197+ ///
30198+ /// Both arms now decode all ten frames pixel-exact against ffmpeg, and
30199+ /// [`decode::intra_rect_in_inter_screen_hits`] counts the strips that read
30200+ /// the syntax -- hard-asserted, because an attempt with no such strip
30201+ /// proves nothing about the case the refusal named.
30202+ ///
30203+ /// Note `--enable-palette=0`: the encoder's palette SEARCH is what this
30204+ /// gate must switch off, not the syntax. With it on, the key frame codes
30205+ /// a block that really uses a palette and stops on the separate,
30206+ /// still-live "a block that actually uses a palette (Y)" refusal before
30207+ /// any inter frame is reached (class `refusal-hides-a-defect`, measured on
30208+ /// six such encodes).
30209+ #[test]
30210+ fn a_real_aomenc_screen_inter_sequence_codes_palette_syntax_on_rect_intra_strips() {
30211+ screen_rect_intra_palette_syntax_gate(8);
30212+ }
30213+
30214+ /// The 10-bit arm (both of the user's films are `yuv420p10le`).
30215+ #[test]
30216+ fn a_real_aomenc_10bit_screen_inter_sequence_codes_palette_syntax_on_rect_intra_strips() {
30217+ screen_rect_intra_palette_syntax_gate(10);
30218+ }
30219+
30220+ fn screen_rect_intra_palette_syntax_gate(bit_depth: u32) {
30221+ let name = format!("screen_rect_intra_palette_syntax_gate({bit_depth})");
30222+ if !have_ffmpeg() {
30223+ eprintln!("SKIP {name}: no ffmpeg");
30224+ return;
30225+ }
30226+ if !have_aomenc() {
30227+ eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display());
30228+ return;
30229+ }
30230+ let (width, height, frame_count) = (256usize, 192usize, 10usize);
30231+ let y4m = Command::new("ffmpeg")
30232+ .args([
30233+ "-v", "error", "-f", "lavfi", "-i", "testsrc2=s=256x192:r=25", "-t", "0.4",
30234+ "-pix_fmt", "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-",
30235+ ])
30236+ .stdin(Stdio::null())
30237+ .stdout(Stdio::piped())
30238+ .stderr(Stdio::piped())
30239+ .output()
30240+ .expect("ffmpeg failed to run");
30241+ assert!(y4m.status.success(), "{name}: ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr));
30242+ // The source stays 8-bit for both arms: `--bit-depth=10
30243+ // --input-bit-depth=8` is the recipe that was measured to reach the
30244+ // refusal, and the arm's point is the coded syntax, not the input.
30245+ let depth_arg = format!("--bit-depth={bit_depth}");
30246+ let cq_arg = format!("--cq-level={}", if bit_depth == 10 { 45 } else { 40 });
30247+ let mut child = Command::new(aomenc_path())
30248+ .args([
30249+ "--codec=av1",
30250+ "--passes=1",
30251+ "--end-usage=q",
30252+ "--cpu-used=0",
30253+ "--lag-in-frames=0",
30254+ "--kf-max-dist=30",
30255+ "--limit=10",
30256+ "--threads=1",
30257+ "--tile-columns=0",
30258+ "--enable-rect-partitions=1",
30259+ "--enable-1to4-partitions=1",
30260+ "--min-partition-size=8",
30261+ "--sb-size=64",
30262+ "--input-bit-depth=8",
30263+ // `allow_screen_content_tools` in every frame header comes
30264+ // from here; the two searches below stay off so the KEY frame
30265+ // does not stop on a palette/intrabc RECONSTRUCTION refusal
30266+ // before an inter frame exists.
30267+ "--tune-content=screen",
30268+ "--enable-palette=0",
30269+ "--enable-intrabc=0",
30270+ ])
30271+ .args([&depth_arg, &cq_arg])
30272+ .args(["--obu", "-o", "-", "-"])
30273+ .stdin(Stdio::piped())
30274+ .stdout(Stdio::piped())
30275+ .stderr(Stdio::piped())
30276+ .spawn()
30277+ .expect("aomenc failed to start");
30278+ child
30279+ .stdin
30280+ .take()
30281+ .expect("aomenc stdin")
30282+ .write_all(&y4m.stdout)
30283+ .or_else(|e| match e.kind() {
30284+ std::io::ErrorKind::BrokenPipe => Ok(()),
30285+ _ => Err(e),
30286+ })
30287+ .expect("writing y4m to aomenc");
30288+ let out = child.wait_with_output().expect("aomenc failed to run");
30289+ assert!(
30290+ out.status.success(),
30291+ "{name}: aomenc refused the fixture: {}",
30292+ String::from_utf8_lossy(&out.stderr)
30293+ );
30294+ let stream = out.stdout;
30295+ decode::reset_intra_rect_in_inter_screen_hits();
30296+ let frames = decode_stream(&stream).unwrap_or_else(|e| {
30297+ panic!("{name}: decode failed -- the case this gate exists for: {e}")
30298+ });
30299+ let strips = decode::intra_rect_in_inter_screen_hits();
30300+ eprintln!("{name}: {} frames, {strips} rect intra strip(s) read the palette syntax", frames.len());
30301+ assert_eq!(frames.len(), frame_count, "{name}: frame count");
30302+ let ffmpeg_frames = if bit_depth == 10 {
30303+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
30304+ } else {
30305+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
30306+ };
30307+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
30308+ assert_eq!(got.y, want.y, "{name}: frame {i} luma vs ffmpeg");
30309+ assert_eq!(got.u, want.u, "{name}: frame {i} U vs ffmpeg");
30310+ assert_eq!(got.v, want.v, "{name}: frame {i} V vs ffmpeg");
30311+ }
30312+ assert!(
30313+ strips > 0,
30314+ "{name}: no rect intra strip of a screen-content frame read the palette syntax -- \
30315+ the gate is vacuous, the recipe stopped producing the shape"
30316+ );
30317+ }
30318+
30182 /// lane-intra14 r4: the FILM witness for an intra block on a 1:4 partition30319 /// lane-intra14 r4: the FILM witness for an intra block on a 1:4 partition
30183 /// inside an INTER frame -- `crates/ec-av1/fixtures/reelb_intra14_witness.obu`,30320 /// inside an INTER frame -- `crates/ec-av1/fixtures/reelb_intra14_witness.obu`,
30184 /// 163057 bytes, sha25630321 /// 163057 bytes, sha256