Reconstruct palette blocks inside inter frames, and fix the palette colour-index CDF counter reset
Browse files at this commit6a16223660f0b67160f83e1be35e86348e466a4bParent: 236830d- feat
- reconstruct palette blocks inside inter frames, and fix the palette colour-index CDF counter reset
8 changed files +184 -22
- crates/ec-av1/examples/decode_probe.rs +2 -0
- crates/ec-av1/fixtures/palette_screen_strip16_witness_10bit.obu +0 -0
- crates/ec-av1/fixtures/palette_screen_witness.obu +0 -0
- crates/ec-av1/fixtures/palette_screen_witness_10bit.obu +0 -0
- crates/ec-av1/src/cdf_state.rs +25 -2
- crates/ec-av1/src/decode.rs +20 -17
- crates/ec-av1/src/refusal_inventory.rs +13 -3
- crates/ec-av1/src/stream.rs +124 -0
crates/ec-av1/examples/decode_probe.rsmodified+2 -0
| @@ -34,6 +34,8 @@ fn main() { | |||
| 34 | let (h, v, c) = ec_av1::stream::rect4_32_counters(); | 34 | let (h, v, c) = ec_av1::stream::rect4_32_counters(); |
| 35 | println!("rect4_32: horz={h} vert={v} coded={c}"); | 35 | println!("rect4_32: horz={h} vert={v} coded={c}"); |
| 36 | println!("rect_intrabc_reads: {}", ec_av1::stream::rect_intrabc_reads()); | 36 | println!("rect_intrabc_reads: {}", ec_av1::stream::rect_intrabc_reads()); |
| 37 | + let (pal_y, pal_uv) = ec_av1::stream::intra_in_inter_palette_hits(); | ||
| 38 | + println!("intra_in_inter_palette: y={pal_y} uv={pal_uv}"); | ||
| 37 | println!( | 39 | println!( |
| 38 | "rect64_corner_tu: 64x32={} 32x64={}", | 40 | "rect64_corner_tu: 64x32={} 32x64={}", |
| 39 | ec_av1::stream::rect64_corner_tu_hits(0), | 41 | ec_av1::stream::rect64_corner_tu_hits(0), |
crates/ec-av1/fixtures/palette_screen_strip16_witness_10bit.obuadded+0 -0
Binary file changed
crates/ec-av1/fixtures/palette_screen_witness.obuadded+0 -0
Binary file changed
crates/ec-av1/fixtures/palette_screen_witness_10bit.obuadded+0 -0
Binary file changed
crates/ec-av1/src/cdf_state.rsmodified+25 -2
| @@ -759,6 +759,19 @@ fn reset3<const N: usize, const M: usize, const K: usize>(a: &mut [[[u16; N]; M] | |||
| 759 | a.iter_mut().for_each(reset2); | 759 | a.iter_mut().for_each(reset2); |
| 760 | } | 760 | } |
| 761 | 761 | ||
| 762 | +/// [`reset3`] for a table whose ALPHABET grows with its first index: the | ||
| 763 | +/// palette colour-index CDFs are `[u16; 9]` rows read as `[..=n]` with | ||
| 764 | +/// `n = idx + 2`, so their symbol counter sits at index `n`, not `N - 1`. | ||
| 765 | +fn reset_var_alphabet<const N: usize, const M: usize, const K: usize>( | ||
| 766 | + a: &mut [[[u16; N]; M]; K], | ||
| 767 | +) { | ||
| 768 | + for (idx, rows) in a.iter_mut().enumerate() { | ||
| 769 | + for row in rows.iter_mut() { | ||
| 770 | + row[idx + 2] = 0; | ||
| 771 | + } | ||
| 772 | + } | ||
| 773 | +} | ||
| 774 | + | ||
| 762 | impl MvComponentCdfs { | 775 | impl MvComponentCdfs { |
| 763 | fn reset_counts(&mut self) { | 776 | fn reset_counts(&mut self) { |
| 764 | reset1(&mut self.class); | 777 | reset1(&mut self.class); |
| @@ -926,8 +939,18 @@ impl Cdfs { | |||
| 926 | reset2(&mut self.palette_y_size); | 939 | reset2(&mut self.palette_y_size); |
| 927 | reset2(&mut self.palette_uv_mode); | 940 | reset2(&mut self.palette_uv_mode); |
| 928 | reset2(&mut self.palette_uv_size); | 941 | reset2(&mut self.palette_uv_size); |
| 929 | - reset3(&mut self.palette_y_color_index); | 942 | + // lane-t900 r22 (class cdf-counter-not-reset): the two colour-index |
| 930 | - reset3(&mut self.palette_uv_color_index); | 943 | + // tables are the only VARIABLE-ALPHABET ones here -- the reader takes |
| 944 | + // `[..=n]` of a `[u16; 9]` row, so `update_cdf`'s symbol counter lives | ||
| 945 | + // at index `n` (= table index + 2), not at the array's last entry. | ||
| 946 | + // `reset3` zeroed slot 8, which no `n < 8` row ever uses, so every | ||
| 947 | + // palette colour-index row crossed a frame boundary with a SATURATED | ||
| 948 | + // count (32) and adapted at rate 6 where libaom, counting from 0, | ||
| 949 | + // adapts at rate 4: the first inter-frame palette block's map desynced | ||
| 950 | + // at its third colour-index symbol (witness `palette_screen_witness.obu`, | ||
| 951 | + // decode-order frame 3, mi(40,0), Y map (0,2)). | ||
| 952 | + reset_var_alphabet(&mut self.palette_y_color_index); | ||
| 953 | + reset_var_alphabet(&mut self.palette_uv_color_index); | ||
| 931 | reset1(&mut self.intrabc); | 954 | reset1(&mut self.intrabc); |
| 932 | reset1(&mut self.restore_wiener); | 955 | reset1(&mut self.restore_wiener); |
| 933 | reset1(&mut self.restore_sgrproj); | 956 | reset1(&mut self.restore_sgrproj); |
crates/ec-av1/src/decode.rsmodified+20 -17
| @@ -6710,7 +6710,12 @@ fn decode_color_index_map_wh( | |||
| 6710 | let (ctx, color_order) = palette_color_index_context(&map, bw, row, col, n); | 6710 | let (ctx, color_order) = palette_color_index_context(&map, bw, row, col, n); |
| 6711 | if trace { | 6711 | if trace { |
| 6712 | let (rng, _) = dec.debug_state(); | 6712 | let (rng, _) = dec.debug_state(); |
| 6713 | - eprintln!("EC_PAL row={row} col={col} ctx={ctx} n={n} rng={rng}"); | 6713 | + let row_cdf = if uv { |
| 6714 | + &cdfs.palette_uv_color_index[n - 2][ctx] | ||
| 6715 | + } else { | ||
| 6716 | + &cdfs.palette_y_color_index[n - 2][ctx] | ||
| 6717 | + }; | ||
| 6718 | + eprintln!("EC_PAL row={row} col={col} ctx={ctx} n={n} cdf0={} cnt={} rng={rng}", row_cdf[0], row_cdf[n]); | ||
| 6714 | } | 6719 | } |
| 6715 | let symbol = if uv { | 6720 | let symbol = if uv { |
| 6716 | dec.symbol(&mut cdfs.palette_uv_color_index[n - 2][ctx][..=n]) | 6721 | dec.symbol(&mut cdfs.palette_uv_color_index[n - 2][ctx][..=n]) |
| @@ -6922,7 +6927,7 @@ fn read_intra_mode_rect( | |||
| 6922 | if use_palette_y { | 6927 | if use_palette_y { |
| 6923 | if palette.is_none() { | 6928 | if palette.is_none() { |
| 6924 | return Err(unsupported( | 6929 | return Err(unsupported( |
| 6925 | - "a block that actually uses a palette (Y@rect) -- reconstruction is out of scope", | 6930 | + "a block that actually uses a palette (Y) -- reconstruction is out of scope", |
| 6926 | )); | 6931 | )); |
| 6927 | } | 6932 | } |
| 6928 | let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]); | 6933 | let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]); |
| @@ -7733,12 +7738,13 @@ fn decode_intra_rect_in_inter( | |||
| 7733 | // [`INTRA_IN_INTER_MODE`] switches to `read_intra_block_mode_info`'s | 7738 | // [`INTRA_IN_INTER_MODE`] switches to `read_intra_block_mode_info`'s |
| 7734 | // `y_mode[0]` plus the `skip` this caller already read. | 7739 | // `y_mode[0]` plus the `skip` this caller already read. |
| 7735 | if let Some((horz, has_chroma)) = strip16 { | 7740 | if let Some((horz, has_chroma)) = strip16 { |
| 7736 | - if allow_screen_content_tools { | 7741 | + // lane-t900 r22: the screen-content refusal here was STALE (class |
| 7737 | - return Err(unsupported( | 7742 | + // stale-premise): [`decode_rect4_16_strip`] takes |
| 7738 | - "a HORZ/VERT intra strip in a screen-content frame (palette syntax \ | 7743 | + // `allow_screen_content_tools` and reads the whole palette syntax |
| 7739 | - is consumed for square blocks only)", | 7744 | + // (mode/size/colours/colour-index map, its own `palette_ctx_and_cache_mi` |
| 7740 | - )); | 7745 | + // pair) -- the key frame proves that body. Lifted with the 10-bit |
| 7741 | - } | 7746 | + // witness `palette_screen_witness_10bit.obu`, whose inter frames carry |
| 7747 | + // 16x4/4x16 intra strips inside a `--tune-content=screen` frame. | ||
| 7742 | debug_assert_eq!((bw, bh), if horz { (16, 4) } else { (4, 16) }); | 7748 | debug_assert_eq!((bw, bh), if horz { (16, 4) } else { (4, 16) }); |
| 7743 | INTRA_IN_INTER_MODE.with(|c| c.set(Some((0, skip)))); | 7749 | INTRA_IN_INTER_MODE.with(|c| c.set(Some((0, skip)))); |
| 7744 | let res = decode_rect4_16_strip( | 7750 | let res = decode_rect4_16_strip( |
| @@ -8088,9 +8094,6 @@ fn decode_intra_rect_in_inter( | |||
| 8088 | PALETTE_HITS.with(|c| c.set(c.get() + 1)); | 8094 | PALETTE_HITS.with(|c| c.set(c.get() + 1)); |
| 8089 | PALETTE_RECT_HITS.with(|c| c.set(c.get() + 1)); | 8095 | PALETTE_RECT_HITS.with(|c| c.set(c.get() + 1)); |
| 8090 | INTRA_IN_INTER_PALETTE_Y_HITS.with(|c| c.set(c.get() + 1)); | 8096 | INTRA_IN_INTER_PALETTE_Y_HITS.with(|c| c.set(c.get() + 1)); |
| 8091 | - if crate::envflags::env_flag!("EC_PALII") { | ||
| 8092 | - eprintln!("EC_PALII yrect mi={mi_r},{mi_c} bw={bw} bh={bh} n={n} skip={skip}"); | ||
| 8093 | - } | ||
| 8094 | PaletteY { size: n, colors, map } | 8097 | PaletteY { size: n, colors, map } |
| 8095 | }); | 8098 | }); |
| 8096 | let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| { | 8099 | let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| { |
| @@ -10891,7 +10894,7 @@ fn read_intra_mode( | |||
| 10891 | if use_palette_y { | 10894 | if use_palette_y { |
| 10892 | if palette.is_none() { | 10895 | if palette.is_none() { |
| 10893 | return Err(unsupported( | 10896 | return Err(unsupported( |
| 10894 | - "a block that actually uses a palette (Y@square) -- reconstruction is out of scope", | 10897 | + "a block that actually uses a palette (Y) -- reconstruction is out of scope", |
| 10895 | )); | 10898 | )); |
| 10896 | } | 10899 | } |
| 10897 | let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]); | 10900 | let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]); |
| @@ -23470,6 +23473,9 @@ fn decode_inter_block( | |||
| 23470 | let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]); | 23473 | let n = 2 + dec.symbol(&mut cdfs.palette_y_size[bsize_ctx]); |
| 23471 | palette_y_pending = Some((n, read_palette_colors_y(dec, n, &palette_cache))); | 23474 | palette_y_pending = Some((n, read_palette_colors_y(dec, n, &palette_cache))); |
| 23472 | } | 23475 | } |
| 23476 | + if crate::envflags::env_flag!("EC_PALSYN") { | ||
| 23477 | + eprintln!("EC_PALSYN_PRE sq mi={rmi},{cmi} bw={write_w} bh={write_h} mode={mode} uv={uv_mode} ctx={palette_ctx} y={} rng={}", palette_y_pending.map_or(0, |(n, _)| n), dec.debug_state().0); | ||
| 23478 | + } | ||
| 23473 | let use_palette_uv = | 23479 | let use_palette_uv = |
| 23474 | uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[usize::from(use_palette_y)]) != 0; | 23480 | uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[usize::from(use_palette_y)]) != 0; |
| 23475 | if crate::envflags::env_flag!("EC_PALSYN") { | 23481 | if crate::envflags::env_flag!("EC_PALSYN") { |
| @@ -23510,9 +23516,6 @@ fn decode_inter_block( | |||
| 23510 | let map = decode_color_index_map_wh(dec, cdfs, n, write_w, write_h, false); | 23516 | let map = decode_color_index_map_wh(dec, cdfs, n, write_w, write_h, false); |
| 23511 | PALETTE_HITS.with(|c| c.set(c.get() + 1)); | 23517 | PALETTE_HITS.with(|c| c.set(c.get() + 1)); |
| 23512 | INTRA_IN_INTER_PALETTE_Y_HITS.with(|c| c.set(c.get() + 1)); | 23518 | INTRA_IN_INTER_PALETTE_Y_HITS.with(|c| c.set(c.get() + 1)); |
| 23513 | - if crate::envflags::env_flag!("EC_PALII") { | ||
| 23514 | - eprintln!("EC_PALII y mi={rmi},{cmi} bw={write_w} bh={write_h} n={n} skip={skip}"); | ||
| 23515 | - } | ||
| 23516 | PaletteY { size: n, colors, map } | 23519 | PaletteY { size: n, colors, map } |
| 23517 | }); | 23520 | }); |
| 23518 | let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| { | 23521 | let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| { |
| @@ -27204,7 +27207,7 @@ fn decode_inter_block8( | |||
| 27204 | if allow_screen_content_tools { | 27207 | if allow_screen_content_tools { |
| 27205 | if mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[0][0]) != 0 { | 27208 | if mode == DC_PRED && dec.symbol(&mut cdfs.palette_y_mode[0][0]) != 0 { |
| 27206 | return Err(unsupported( | 27209 | return Err(unsupported( |
| 27207 | - "a block that actually uses a palette (Y@inter_block8) -- reconstruction is out of scope", | 27210 | + "a block that actually uses a palette (Y) -- reconstruction is out of scope", |
| 27208 | )); | 27211 | )); |
| 27209 | } | 27212 | } |
| 27210 | // lane-uv8 r1: `read_palette_mode_info` reads the UV symbol only | 27213 | // lane-uv8 r1: `read_palette_mode_info` reads the UV symbol only |
| @@ -27212,7 +27215,7 @@ fn decode_inter_block8( | |||
| 27212 | // while every non-DC uv_mode was refused a few lines above. | 27215 | // while every non-DC uv_mode was refused a few lines above. |
| 27213 | if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[0]) != 0 { | 27216 | if uv_mode == DC_PRED && dec.symbol(&mut cdfs.palette_uv_mode[0]) != 0 { |
| 27214 | return Err(unsupported( | 27217 | return Err(unsupported( |
| 27215 | - "a block that actually uses a palette (UV@inter_block8) -- reconstruction is out of scope", | 27218 | + "a block that actually uses a palette (UV) -- reconstruction is out of scope", |
| 27216 | )); | 27219 | )); |
| 27217 | } | 27220 | } |
| 27218 | } | 27221 | } |
crates/ec-av1/src/refusal_inventory.rsmodified+13 -3
| @@ -46,6 +46,12 @@ const REFUSALS: &[&str] = &[ | |||
| 46 | "CfL, filter intra or a palette on a 128-root HORZ/VERT intra block (every one of their size gates caps at 64x64 or below, so none of these symbols exists there)", | 46 | "CfL, filter intra or a palette on a 128-root HORZ/VERT intra block (every one of their size gates caps at 64x64 or below, so none of these symbols exists there)", |
| 47 | "intrabc under a 128x128 superblock (libaom's av1_is_dv_valid derives the block-vector delay from sb_size, which this decoder hardcodes to 64)", | 47 | "intrabc under a 128x128 superblock (libaom's av1_is_dv_valid derives the block-vector delay from sb_size, which this decoder hardcodes to 64)", |
| 48 | "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", | 48 | "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)", |
| 49 | + // lane-t900 r22: palette RECONSTRUCTION landed for the key-frame paths | ||
| 50 | + // (earlier lanes) and for the intra-in-inter square and rect paths (this | ||
| 51 | + // one). These two strings survive at exactly two kinds of site: the | ||
| 52 | + // `palette.is_none()` guards in `read_intra_mode`/`read_intra_mode_rect` | ||
| 53 | + // (defensive -- every caller now passes a real ctx/cache pair), and the | ||
| 54 | + // sub-8x8 `decode_inter_block8` leaf, which has no witness stream. | ||
| 49 | "a block that actually uses a palette (UV) -- reconstruction is out of scope", | 55 | "a block that actually uses a palette (UV) -- reconstruction is out of scope", |
| 50 | "a block that actually uses a palette (Y) -- reconstruction is out of scope", | 56 | "a block that actually uses a palette (Y) -- reconstruction is out of scope", |
| 51 | "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)", | 57 | "intra block copy on a HORZ/VERT/1:4 rect intra strip (reconstruction is not ported at this shape)", |
| @@ -111,9 +117,13 @@ const REFUSALS: &[&str] = &[ | |||
| 111 | // both arms of gate | 117 | // both arms of gate |
| 112 | // `a_real_aomenc_screen_inter_sequence_codes_palette_syntax_on_rect_intra_strips` | 118 | // `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 | 119 | // 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 | 120 | + // lane-t900 r22 NARROWED it again: the 16x4/4x16 arm is LIFTED (that arm |
| 115 | - // palette-eligible (`palette_bsize_ctx_wh` wants `8 <= min`, `max <= 64`) | 121 | + // routes through `decode_rect4_16_strip`, which reads the palette syntax |
| 116 | - // and neither of which has a witness stream yet. | 122 | + // itself -- the premise was stale), gated by |
| 123 | + // `a_screen_stream_with_16x4_intra_strips_in_inter_frames_decodes_pixel_exact`. | ||
| 124 | + // What still refuses is the 128-root half of a screen-content frame, whose | ||
| 125 | + // body (`decode_block_128rect`) reads no palette syntax and for which no | ||
| 126 | + // `--sb-size=128` screen witness exists yet. | ||
| 117 | "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", | 127 | "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", |
| 118 | "warp prediction with a scaled reference (superres, unimplemented)", | 128 | "warp prediction with a scaled reference (superres, unimplemented)", |
| 119 | "an 8x8 partition leaf under a scaled reference (superres, unimplemented)", | 129 | "an 8x8 partition leaf under a scaled reference (superres, unimplemented)", |
crates/ec-av1/src/stream.rsmodified+124 -0
| @@ -119,6 +119,13 @@ pub fn rect_intrabc_reads() -> usize { | |||
| 119 | crate::decode::rect_intrabc_reads() | 119 | crate::decode::rect_intrabc_reads() |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | +/// `(y, uv)` palette blocks RECONSTRUCTED inside an inter frame (lane-t900 | ||
| 123 | +/// r22) -- the counter a screen-content witness gate reads to prove it | ||
| 124 | +/// exercises the inter-frame palette path, not the key frame's. | ||
| 125 | +pub fn intra_in_inter_palette_hits() -> (usize, usize) { | ||
| 126 | + crate::decode::intra_in_inter_palette_hits() | ||
| 127 | +} | ||
| 128 | + | ||
| 122 | /// lane-rect64port r1: coded 64-level HORZ/VERT intra strips whose luma | 129 | /// lane-rect64port r1: coded 64-level HORZ/VERT intra strips whose luma |
| 123 | /// transform unit is the un-split TX_64X32 (orient 0) / TX_32X64 (orient 1). | 130 | /// transform unit is the un-split TX_64X32 (orient 0) / TX_32X64 (orient 1). |
| 124 | pub fn rect64_corner_tu_hits(orient: usize) -> usize { | 131 | pub fn rect64_corner_tu_hits(orient: usize) -> usize { |
| @@ -30922,6 +30929,123 @@ mod tests { | |||
| 30922 | ); | 30929 | ); |
| 30923 | } | 30930 | } |
| 30924 | 30931 | ||
| 30932 | + /// lane-t900 r22 GATE: a real `aomenc --tune-content=screen | ||
| 30933 | + /// --enable-palette=1` stream whose INTER frames reconstruct palette | ||
| 30934 | + /// blocks (Y and UV), at both bit depths. | ||
| 30935 | + /// | ||
| 30936 | + /// Recipe (both fixtures, 15 frames, key + 14 inter, 256x192, one tile): | ||
| 30937 | + /// `aomenc --codec=av1 --passes=1 --end-usage=q --cq-level=20 --cpu-used=1 | ||
| 30938 | + /// --threads=1 --row-mt=0 --lag-in-frames=0 --kf-max-dist=9999 | ||
| 30939 | + /// --sb-size=64 --tune-content=screen --enable-palette=1 | ||
| 30940 | + /// --enable-intrabc=0 --obu` (plus `--bit-depth=10 --profile=0` for the | ||
| 30941 | + /// twin) over a synthetic screen-like source: two luma levels on a 16x16 | ||
| 30942 | + /// grid, four chroma levels on an 8x8 one, both re-keyed per frame so the | ||
| 30943 | + /// encoder cannot predict the new blocks and codes them INTRA inside the | ||
| 30944 | + /// inter frames. `--enable-palette=0` on the same source is 13% larger, | ||
| 30945 | + /// which is what says the tool is really used. | ||
| 30946 | + /// | ||
| 30947 | + /// What this pins that no key-frame palette gate can: the palette | ||
| 30948 | + /// colour-index CDFs are this decoder's only VARIABLE-ALPHABET tables (the | ||
| 30949 | + /// reader takes `[..=n]` of a `[u16; 9]` row, so `update_cdf`'s counter | ||
| 30950 | + /// lives at index `n`), and `Cdfs::reset_counts` zeroed slot 8 instead -- | ||
| 30951 | + /// so every colour-index row crossed a frame boundary with a SATURATED | ||
| 30952 | + /// count and adapted at rate 6 where libaom, counting from 0, adapts at 4. | ||
| 30953 | + /// The first inter-frame palette block's map desynced at its THIRD | ||
| 30954 | + /// colour-index symbol (decode-order frame 3, mi(40,0), map cell (0,2): | ||
| 30955 | + /// ours cdf0 = 32768-1071, aomdec's = 32768-971, same ctx, same value, | ||
| 30956 | + /// different range). | ||
| 30957 | + #[test] | ||
| 30958 | + fn a_real_aomenc_screen_stream_with_palette_blocks_decodes_pixel_exact() { | ||
| 30959 | + const NAME: &str = | ||
| 30960 | + "a_real_aomenc_screen_stream_with_palette_blocks_decodes_pixel_exact"; | ||
| 30961 | + if !have_ffmpeg() { | ||
| 30962 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 30963 | + return; | ||
| 30964 | + } | ||
| 30965 | + for (fixture, ten_bit) in [ | ||
| 30966 | + ("fixtures/palette_screen_witness.obu", false), | ||
| 30967 | + ("fixtures/palette_screen_witness_10bit.obu", true), | ||
| 30968 | + ] { | ||
| 30969 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join(fixture); | ||
| 30970 | + let stream = std::fs::read(&path) | ||
| 30971 | + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); | ||
| 30972 | + let (width, height) = (256usize, 192usize); | ||
| 30973 | + let before = intra_in_inter_palette_hits(); | ||
| 30974 | + let frames = match decode_stream(&stream) { | ||
| 30975 | + Ok(frames) => frames, | ||
| 30976 | + Err(e) => panic!("{NAME} [{fixture}]: decode_stream refused: {e}"), | ||
| 30977 | + }; | ||
| 30978 | + let after = intra_in_inter_palette_hits(); | ||
| 30979 | + let (fired_y, fired_uv) = (after.0 - before.0, after.1 - before.1); | ||
| 30980 | + assert!( | ||
| 30981 | + fired_y > 0 && fired_uv > 0, | ||
| 30982 | + "{NAME} [{fixture}]: inter-frame palette fired y={fired_y} uv={fired_uv} \ | ||
| 30983 | + -- both planes must fire or the gate is vacuous for the one that did not" | ||
| 30984 | + ); | ||
| 30985 | + assert_eq!(frames.len(), 15, "{NAME} [{fixture}]: 15 shown frames"); | ||
| 30986 | + let ffmpeg_frames = if ten_bit { | ||
| 30987 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len()) | ||
| 30988 | + } else { | ||
| 30989 | + ffmpeg_decode_sequence(&stream, width, height, frames.len()) | ||
| 30990 | + }; | ||
| 30991 | + assert_eq!( | ||
| 30992 | + ffmpeg_frames.len(), | ||
| 30993 | + frames.len(), | ||
| 30994 | + "{NAME} [{fixture}]: frame count" | ||
| 30995 | + ); | ||
| 30996 | + for (i, (ours, theirs)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 30997 | + assert_eq!(ours.y, theirs.y, "{NAME} [{fixture}]: frame {i} luma vs ffmpeg"); | ||
| 30998 | + assert_eq!(ours.u, theirs.u, "{NAME} [{fixture}]: frame {i} U vs ffmpeg"); | ||
| 30999 | + assert_eq!(ours.v, theirs.v, "{NAME} [{fixture}]: frame {i} V vs ffmpeg"); | ||
| 31000 | + } | ||
| 31001 | + eprintln!( | ||
| 31002 | + "{NAME} [{fixture}]: 15 frames pixel-exact on every plane; \ | ||
| 31003 | + inter-frame palette y={fired_y} uv={fired_uv}" | ||
| 31004 | + ); | ||
| 31005 | + } | ||
| 31006 | + } | ||
| 31007 | + | ||
| 31008 | + /// lane-t900 r22 GATE for the LIFTED refusal `"a HORZ/VERT intra strip in | ||
| 31009 | + /// a screen-content frame (palette syntax is consumed for square blocks | ||
| 31010 | + /// only)"` on its 16x4/4x16 arm: that arm routes through | ||
| 31011 | + /// `decode_rect4_16_strip`, which takes `allow_screen_content_tools` and | ||
| 31012 | + /// reads the whole palette syntax itself, so the refusal was a stale | ||
| 31013 | + /// premise (the key-frame path proves that body). This 10-bit | ||
| 31014 | + /// `--tune-content=screen` stream reached that exact refusal before the | ||
| 31015 | + /// lift and now decodes all 15 frames pixel-exact while 8 inter-frame | ||
| 31016 | + /// palette blocks reconstruct. | ||
| 31017 | + #[test] | ||
| 31018 | + fn a_screen_stream_with_16x4_intra_strips_in_inter_frames_decodes_pixel_exact() { | ||
| 31019 | + const NAME: &str = | ||
| 31020 | + "a_screen_stream_with_16x4_intra_strips_in_inter_frames_decodes_pixel_exact"; | ||
| 31021 | + if !have_ffmpeg() { | ||
| 31022 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 31023 | + return; | ||
| 31024 | + } | ||
| 31025 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 31026 | + .join("fixtures/palette_screen_strip16_witness_10bit.obu"); | ||
| 31027 | + let stream = std::fs::read(&path) | ||
| 31028 | + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); | ||
| 31029 | + let before = intra_in_inter_palette_hits(); | ||
| 31030 | + let frames = match decode_stream(&stream) { | ||
| 31031 | + Ok(frames) => frames, | ||
| 31032 | + Err(e) => panic!("{NAME}: decode_stream refused: {e}"), | ||
| 31033 | + }; | ||
| 31034 | + let fired_y = intra_in_inter_palette_hits().0 - before.0; | ||
| 31035 | + assert!( | ||
| 31036 | + fired_y > 0, | ||
| 31037 | + "{NAME}: no inter-frame palette block -- gate is vacuous" | ||
| 31038 | + ); | ||
| 31039 | + assert_eq!(frames.len(), 15, "{NAME}: 15 shown frames"); | ||
| 31040 | + let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, 256, 192, frames.len()); | ||
| 31041 | + for (i, (ours, theirs)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 31042 | + assert_eq!(ours.y, theirs.y, "{NAME}: frame {i} luma vs ffmpeg"); | ||
| 31043 | + assert_eq!(ours.u, theirs.u, "{NAME}: frame {i} U vs ffmpeg"); | ||
| 31044 | + assert_eq!(ours.v, theirs.v, "{NAME}: frame {i} V vs ffmpeg"); | ||
| 31045 | + } | ||
| 31046 | + eprintln!("{NAME}: 15 frames pixel-exact; inter-frame palette y={fired_y}"); | ||
| 31047 | + } | ||
| 31048 | + | ||
| 30925 | /// lane-t900 r20 GATE, refusal A -- `"a non-skip rectangular | 31049 | /// lane-t900 r20 GATE, refusal A -- `"a non-skip rectangular |
| 30926 | /// (HORZ/VERT/HORZ_B) strip needs rectangular residual coding"`. | 31050 | /// (HORZ/VERT/HORZ_B) strip needs rectangular residual coding"`. |
| 30927 | /// | 31051 | /// |