From c84128d318c027606b53a6a7baf7724e88ee36a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Mon, 7 Sep 2026 16:23:30 +0300 Subject: [PATCH] test(av1): the lossless inter gate gets two tune-content=screen key rows The palette path is what caught the whole-block palette prediction being handed to a 4x4 chroma unit, and nothing in the gate coded a palette block. Screen rows are KEY-only: a screen INTER frame still desyncs (lane report). --- crates/ec-av1/src/stream.rs | 68 +++++++++++++++++++++++++++---------- lanes/lossless2.report.md | 5 ++- 2 files changed, 54 insertions(+), 19 deletions(-) diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index c259aa2b..63f4d801 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -4114,15 +4114,25 @@ pub(crate) mod tests { eprintln!("SKIP {NAME}: no ffmpeg"); return; } - // (w, h, frames, gop, bit depth, 128-superblock) - let cases: [(usize, usize, usize, &str, u32, bool); 4] = [ - (256, 128, 8, "4", 8, false), - (192, 96, 6, "3", 10, false), - (320, 192, 6, "3", 8, false), - (256, 256, 4, "2", 8, true), + // (w, h, frames, gop, bit depth, 128-superblock, screen content) + // lane-lossless2: the SCREEN rows carry palette blocks, which is what + // caught the whole-block palette prediction being handed to a 4x4 + // chroma unit; they are KEY-only, see the lane report's deferred + // screen-inter desync. + let cases: [(usize, usize, usize, &str, u32, bool, bool); 6] = [ + (256, 128, 8, "4", 8, false, false), + (192, 96, 6, "3", 10, false, false), + (320, 192, 6, "3", 8, false, false), + (256, 256, 4, "2", 8, true, false), + (320, 192, 2, "1", 8, false, true), + (640, 384, 2, "1", 8, false, true), ]; - for &(w, h, frames, gop, depth, sb128) in &cases { - let tag = format!("{w}x{h} {depth}-bit gop {gop}{}", if sb128 { " sb128" } else { "" }); + for &(w, h, frames, gop, depth, sb128, screen) in &cases { + let tag = format!( + "{w}x{h} {depth}-bit gop {gop}{}{}", + if sb128 { " sb128" } else { "" }, + if screen { " screen" } else { "" } + ); let mut raw: Vec = Vec::new(); let put = |v: u32, raw: &mut Vec| { if depth == 10 { @@ -4131,20 +4141,36 @@ pub(crate) mod tests { raw.push(v as u8); } }; + // A screen source is a few flat colours in 16x16 tiles plus + // 1-px text-like rows -- what makes libaom code palette blocks. + const PAL: [u32; 8] = [16, 60, 110, 145, 180, 210, 235, 128]; for f in 0..frames { for row in 0..h { for col in 0..w { - put((((col + 2 * f) * 7 + row * 13) % 251) as u32, &mut raw); - } - } - for row in 0..h / 2 { - for col in 0..w / 2 { - put((((col + f) * 11 + row * 5) % 251) as u32, &mut raw); + let v = if screen { + if row % 7 == 0 && col % 3 == 0 { + if (col / 3 + row + f) % 2 == 1 { 16 } else { 235 } + } else { + PAL[((col + 4 * f) / 16 + row / 16) % PAL.len()] + } + } else { + (((col + 2 * f) * 7 + row * 13) % 251) as u32 + }; + put(v, &mut raw); } } - for row in 0..h / 2 { - for col in 0..w / 2 { - put(((col * 3 + (row + f) * 17) % 251) as u32, &mut raw); + for plane in 0..2usize { + for row in 0..h / 2 { + for col in 0..w / 2 { + let v = if screen { + PAL[((col + 2 * f) / 8 + row / 8 + plane) % PAL.len()] + } else if plane == 0 { + (((col + f) * 11 + row * 5) % 251) as u32 + } else { + ((col * 3 + (row + f) * 17) % 251) as u32 + }; + put(v, &mut raw); + } } } } @@ -4162,6 +4188,9 @@ pub(crate) mod tests { if sb128 { cmd.args(["-aom-params", "sb-size=128"]); } + if screen { + cmd.args(["-aom-params", "tune-content=screen"]); + } let out = cmd .args(["-f", "obu", "-"]) .stdin(Stdio::null()) @@ -4197,7 +4226,10 @@ pub(crate) mod tests { } } assert!(lossless >= frames, "{NAME} [{tag}] went blind: {lossless} lossless frames"); - assert!(inters > 0, "{NAME} [{tag}] went blind: no inter frame at gop {gop}"); + assert!( + screen || inters > 0, + "{NAME} [{tag}] went blind: no inter frame at gop {gop}" + ); let ours = decode_stream(&stream) .unwrap_or_else(|e| panic!("{NAME} [{tag}]: a lossless inter stream decodes: {e}")); let refs = if depth == 10 { diff --git a/lanes/lossless2.report.md b/lanes/lossless2.report.md index 05c09c74..baf3dcd7 100644 --- a/lanes/lossless2.report.md +++ b/lanes/lossless2.report.md @@ -51,6 +51,8 @@ TEXTURED luma AND chroma and per-frame motion. | 192x96, 6 frames `-g 3`, 10-bit | same gate | EXACT | | 320x192, 6 frames `-g 3`, 8-bit | same gate | EXACT | | 256x256, 4 frames `-g 2`, `-aom-params sb-size=128` | same gate | EXACT | +| 320x192, 2 key frames, `tune-content=screen` (palette) | same gate | EXACT | +| 640x384, 2 key frames, `tune-content=screen` (palette) | same gate | EXACT | ## Screen content (palette) — three more defects, found by a `tune-content=screen` stream | defect | libaom | fix | @@ -65,6 +67,8 @@ TEXTURED luma AND chroma and per-frame motion. ## Gate results - `a_lossless_libaom_key_frame_decodes_sample_exact` + `a_lossless_libaom_inter_frame_decodes_sample_exact`: PASS (2 passed). - `cargo check --workspace --all-targets -j4`: RC=0, 0 errors, 0 ec-av1 warnings (the 21 warnings are pre-existing `ec-opus`). +- crate suite `cargo test -p ec-av1 --release --lib -- --test-threads=1`: **557 passed / 0 failed / 44 ignored** (959.9 s), pins green (`the_encoders_own_streams_are_byte_identical_to_their_pins`). That run predates the two screen KEY rows added to the inter gate afterwards; those two were run on their own (2 passed). +- The screen rows really do code palette: the same recipe at 320x192 decoded 9600/15360 chroma samples wrong before `palette_window` and 0 after. - DECIDING GATE `bd_rate_screen_native`: **RED**, one reference point: `LADDER DECODE FAILURE: libaom-av1 ["-cpu-used","6","-b:v","0","-crf","5"] frame 0 plane Y sample 625: our decoder decoded 41, ffmpeg 40`. That point used to be refused; it now decodes, and frame 0 (a KEY frame) is @@ -74,5 +78,4 @@ TEXTURED luma AND chroma and per-frame motion. ## Deferred - `deferred: the bd_rate_screen_native crf-5 screen point — ONE luma sample (625, row 0) of frame 0, a lossless KEY frame, decodes 41 where ffmpeg decodes 40; every other sample of every other point is exact. Not reproduced by a synthetic 1920x1024 tune-content=screen -crf 5 key frame (0 samples differ), so it needs the gate's own stream — unblocks: dump the ladder stream (EC_ENC_OUT / the external_ladder recipe) and diff EC_TRACE_COEFF against aomdec around that block.` - `deferred: lossless INTER frames of SCREEN content desync — reproduced at 640x384 tune-content=screen -crf 0 -g 3: key frames 0 and 3 are sample-exact, inter frames 1/2/4/5 are not. Localised with the aomdec oracle to all_zero unit #23422 of the stream: the first LUMA unit of a block right after a sub-8x8 group reads txb_skip_ctx 3 where libaom reads 1 (one neighbour magnitude > 3 where libaom sees 0) — unblocks: that one block's above-band luma level; the synthetic non-screen inter fixtures in the gate are all exact, so it is screen/sub-8x8 specific.` -- `deferred: a screen-content KEY-frame fixture is not yet IN the gate — verified by hand with dump_yuv this round; adding it to a_lossless_libaom_inter_frame_decodes_sample_exact is a one-case edit but the crate suite for this report was already running — unblocks: one suite re-run.` - `deferred: a frame mixing lossless and lossy segments — still refused by name ("a frame mixing lossless and lossy segments (the TX_4X4/WHT rules are per segment there)"): every rule above keys off a frame-wide `lossless_flag`, so per-segment support means threading `segment_id` through `lossless()`, `lossless_tx()`, the WHT switch and the filter gates — unblocks: a libaom recipe that emits one. Four tried this round at -crf 0 (aom-params aq-mode=1, aq-mode=2, aq-mode=3, deltaq-mode=1): none produced a frame whose segments disagree — the refusal never fired, i.e. every segment stayed at qindex 0.`