forge
Explore
Log in

Don't you dare go Hollow

Compile the r1 UV-palette WIP + gate it against a real aomenc stream

Browse files at this commit

03d0151c7932d0c4baaf3ee080e0cad7e1beef41Ahmet Kaan GümüşParent: 168c232
  • fix
    • compile the r1 UV-palette WIP + gate it against a real aomenc stream
Show full message
fix(av1): compile the r1 UV-palette WIP + gate it against a real aomenc stream

read_intra_mode's 8x8-leaf call site was still on the pre-UV 8-arg tuple/
13-arg signature after r1's mid-edit commit -- fixed by threading the same
None-palette-uv/&[] corner-cut that call site already used for palette_y.
Everything else r1 wrote (read_palette_colors_uv, PaletteUv reconstruction
into both chroma planes, record_palette_uv neighbour tracking) was already
correct once it compiled.

Added a_real_aomenc_stream_with_palette_uv_decodes_pixel_exact: testsrc2
at the same square-only recipe as the palette-Y gate, hard-asserting
palette_uv_hits moved before checking pixel-exactness against ffmpeg
(2 UV palette blocks fire; both frames match luma/U/V exactly).

refusal_inventory.rs needed no edit -- "a block that actually uses a
palette (UV)" is still genuinely present at two other call sites (the
HORZ/VERT rect-strip and inter-frame 8x8-leaf paths), which stay refused
and are out of this round's scope (steps 2/3).
crates/ec-av1/src/decode.rsmodified+2 -1
@@ -4391,7 +4391,7 @@ fn decode_leaf8(
43914391 // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec
43924392 // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF, like every other
43934393 // `decode_block` caller at 16x16 and up.
4394- let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, _palette_y) =
4394+ let (skip, mode, angle_delta_y, uv_mode, angle_delta_uv, alpha, filter_intra, _palette_y, _palette_uv) =
43954395 read_intra_mode(
43964396 dec,
43974397 cdfs,
@@ -4404,6 +4404,7 @@ fn decode_leaf8(
44044404 allow_screen_content_tools,
44054405 allow_intrabc,
44064406 None,
4407+ &[],
44074408 leaf_mi.0,
44084409 leaf_mi.1,
44094410 )?;
crates/ec-av1/src/stream.rsmodified+118 -0
@@ -1707,6 +1707,124 @@ mod tests {
17071707 assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg");
17081708 }
17091709
1710+ /// A real `aomenc` palette-**UV** fixture (lane-palette2 r2): `testsrc2`
1711+ /// (the multicoloured AV1 test pattern -- flat, few-colour, repetitive
1712+ /// per-region colour *and* chroma, unlike `smptebars=hue=s=0` above,
1713+ /// which flattened chroma to a single value specifically to avoid
1714+ /// exercising this path). Same square-only recipe as the palette-Y gate
1715+ /// (`--enable-rect-partitions=0`/`-ab-`/`-1to4-`, fixed 32x32 partition)
1716+ /// so a UV palette block never lands inside the still-refused HORZ/VERT
1717+ /// screen-content strip. HARD-asserts [`decode::palette_uv_hits`] moved
1718+ /// -- a stream that never reads a real UV palette block would decode (or
1719+ /// not) by construction without proving this milestone at all
1720+ /// ([[gate-blind-to-feature]]).
1721+ #[test]
1722+ fn a_real_aomenc_stream_with_palette_uv_decodes_pixel_exact() {
1723+ const NAME: &str = "a_real_aomenc_stream_with_palette_uv_decodes_pixel_exact";
1724+ if !have_ffmpeg() {
1725+ eprintln!("SKIP {NAME}: no ffmpeg");
1726+ return;
1727+ }
1728+ if !have_aomenc() {
1729+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
1730+ return;
1731+ }
1732+ let source = "testsrc2=size=64x64:rate=25";
1733+ fn render(source: &str) -> Vec<u8> {
1734+ Command::new("ffmpeg")
1735+ .args([
1736+ "-v",
1737+ "error",
1738+ "-f",
1739+ "lavfi",
1740+ "-i",
1741+ source,
1742+ "-pix_fmt",
1743+ "yuv420p",
1744+ "-t",
1745+ "0.16",
1746+ "-f",
1747+ "yuv4mpegpipe",
1748+ "-",
1749+ ])
1750+ .stdin(Stdio::null())
1751+ .stdout(Stdio::piped())
1752+ .stderr(Stdio::piped())
1753+ .output()
1754+ .expect("ffmpeg failed to run")
1755+ .stdout
1756+ }
1757+ let y4m_a = render(source);
1758+ let y4m_b = render(source);
1759+ assert_eq!(
1760+ y4m_a, y4m_b,
1761+ "testsrc2 must render byte-identical across two runs"
1762+ );
1763+ let y4m = y4m_a;
1764+ let mut child = Command::new(aomenc_path())
1765+ .args([
1766+ "--codec=av1",
1767+ "--passes=1",
1768+ "--end-usage=q",
1769+ "--cq-level=30",
1770+ "--cpu-used=0",
1771+ "--threads=1",
1772+ "--row-mt=0",
1773+ "--sb-size=64",
1774+ "--tune-content=screen",
1775+ "--enable-palette=1",
1776+ "--enable-intrabc=0",
1777+ "--enable-rect-partitions=0",
1778+ "--enable-ab-partitions=0",
1779+ "--enable-1to4-partitions=0",
1780+ "--min-partition-size=32",
1781+ "--max-partition-size=32",
1782+ "--enable-filter-intra=0",
1783+ "--enable-cdef=0",
1784+ "--enable-restoration=0",
1785+ "--enable-tx-size-search=0",
1786+ "--loopfilter-control=0",
1787+ "--obu",
1788+ "-o",
1789+ "-",
1790+ "-",
1791+ ])
1792+ .stdin(Stdio::piped())
1793+ .stdout(Stdio::piped())
1794+ .stderr(Stdio::piped())
1795+ .spawn()
1796+ .expect("aomenc failed to start");
1797+ child
1798+ .stdin
1799+ .take()
1800+ .expect("aomenc stdin")
1801+ .write_all(&y4m)
1802+ .expect("writing y4m to aomenc");
1803+ let out = child.wait_with_output().expect("aomenc failed to run");
1804+ assert!(
1805+ out.status.success(),
1806+ "aomenc refused the fixture: {}",
1807+ String::from_utf8_lossy(&out.stderr)
1808+ );
1809+ let stream = out.stdout;
1810+ let before = decode::palette_uv_hits();
1811+ let frames = match decode_stream(&stream) {
1812+ Ok(frames) => frames,
1813+ Err(e) => panic!("{NAME}: decode_stream refused: {e}"),
1814+ };
1815+ assert!(
1816+ decode::palette_uv_hits() > before,
1817+ "palette_uv_mode never fired decoding this stream -- gate is vacuous"
1818+ );
1819+ let frame_count = frames.len();
1820+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, 64, 64, frame_count);
1821+ for i in 0..frame_count {
1822+ assert_eq!(frames[i].y, ffmpeg_frames[i].y, "luma vs ffmpeg, frame {i}");
1823+ assert_eq!(frames[i].u, ffmpeg_frames[i].u, "U vs ffmpeg, frame {i}");
1824+ assert_eq!(frames[i].v, ffmpeg_frames[i].v, "V vs ffmpeg, frame {i}");
1825+ }
1826+ }
1827+
17101828 /// As [`a_real_aomenc_filter_intra_stream_decodes_pixel_exact`]'s
17111829 /// harness, but with the deblocking filter left *on* (no
17121830 /// `--loopfilter-control=0`) at a crf high enough that libaom actually