forge
Explore
Log in

Don't you dare go Hollow

Code the palette syntax on a rect intra strip inside a screen-content inter frame

Browse files at this commit

7ee66806683dda3c7f2371f79b1c27c249f233aaAhmet Kaan GümüşParent: 8f932d5
  • feat
    • code the palette syntax on a rect intra strip inside a screen-content inter frame
Show full message
feat(av1): code the palette syntax on a rect intra strip inside a screen-content inter frame

read_palette_mode_info has no square-only term: a --tune-content=screen
inter frame writes palette_y_mode (and palette_uv_mode) for every block
whose shape palette_bsize_ctx_wh admits, intra strips included. The inter
path's intra arm skipped both symbols and refused the whole case by name,
and a real stream reaches that refusal -- measured with decode_probe on
testsrc2 256x192 --tune-content=screen --enable-palette=0
--enable-intrabc=0: an 8x16 strip at 8-bit, a 16x8 one at 10-bit.

The 2:1 reader now codes the syntax itself (mode context 0 and no cache:
no block this decoder produces can USE a palette, and the arms it shares
with the key-frame path refuse that by name), and the 1:4 arm goes through
read_intra_mode_rect, which already did. Both arms of the new gate decode
ten frames pixel-exact against ffmpeg with 63 strips counted each.

Six earlier encodes with the palette SEARCH on never reach an inter frame
at all: the key frame stops on the separate palette-reconstruction refusal
first (class refusal-hides-a-defect).
crates/ec-av1/src/decode.rsmodified+53 -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
crates/ec-av1/src/refusal_inventory.rsmodified+11 -2
@@ -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)",
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