A witness that builds an SVT-AV1 screen stream whose palette map is cut by the frame edge
Browse files at this commit7fc807b2a08fe5cf967e2a6ed0a735bba1389172Parent: 2461f80- test
- a witness that builds an SVT-AV1 screen stream whose palette map is cut by the frame edge
2 changed files +156 -0
- crates/ec-av1/src/stream.rs +62 -0
- lanes/svtinter.report.md +94 -0
crates/ec-av1/src/stream.rsmodified+62 -0
| @@ -3344,6 +3344,68 @@ pub(crate) mod tests { | |||
| 3344 | .collect() | 3344 | .collect() |
| 3345 | } | 3345 | } |
| 3346 | 3346 | ||
| 3347 | + /// lane-svtinter: an SVT-AV1 screen stream whose frame height is not a | ||
| 3348 | + /// multiple of the superblock size codes PALETTE blocks in the bottom | ||
| 3349 | + /// (and right) superblock row that hang off the mi grid. Spec 5.11.50 | ||
| 3350 | + /// `palette_tokens` reads the colour-index map only over the block's | ||
| 3351 | + /// `onscreenWidth x onscreenHeight` corner and replicates it outward; | ||
| 3352 | + /// this decoder read the full block grid, so it consumed colour-index | ||
| 3353 | + /// symbols libaom never wrote and desynced the rest of the tile -- either | ||
| 3354 | + /// a wrong bottom superblock row (1599 luma samples in this stream's | ||
| 3355 | + /// frame 0, ~80k per inter frame after) or, further along the same tile, | ||
| 3356 | + /// a bogus "a Golomb tail longer than this decoder reads" refusal. | ||
| 3357 | + /// | ||
| 3358 | + /// Unlike its lane-svt1 sibling above this one BUILDS its stream: the | ||
| 3359 | + /// recipe is synthetic (`smptebars,drawgrid` through `libsvtav1 -preset 8 | ||
| 3360 | + /// -svtav1-params screen-content-mode=1`), and 384x152 puts a 32x32 | ||
| 3361 | + /// palette block at mi row 32 of a 38-mi-tall frame, 24 of its 32 rows | ||
| 3362 | + /// on screen. `palette_onscreen_cut_hits` is asserted non-zero so the row | ||
| 3363 | + /// cannot pass on a stream that never cuts a palette map (class | ||
| 3364 | + /// gate-blind-to-feature). | ||
| 3365 | + #[test] | ||
| 3366 | + fn an_svt_screen_palette_map_cut_by_the_frame_edge_decodes_exactly() { | ||
| 3367 | + const NAME: &str = "an_svt_screen_palette_map_cut_by_the_frame_edge_decodes_exactly"; | ||
| 3368 | + if !have_ffmpeg() { | ||
| 3369 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 3370 | + return; | ||
| 3371 | + } | ||
| 3372 | + let (width, height) = (384usize, 152usize); | ||
| 3373 | + let out = Command::new("ffmpeg") | ||
| 3374 | + .args([ | ||
| 3375 | + "-v", "error", "-f", "lavfi", "-i", | ||
| 3376 | + "smptebars=s=384x152:r=12,drawgrid=w=8:h=8:t=1:c=black", | ||
| 3377 | + "-frames:v", "4", "-c:v", "libsvtav1", "-preset", "8", "-crf", "30", | ||
| 3378 | + "-svtav1-params", "lp=1:screen-content-mode=1", "-g", "12", "-f", "obu", "-", | ||
| 3379 | + ]) | ||
| 3380 | + .stdin(Stdio::null()) | ||
| 3381 | + .stdout(Stdio::piped()) | ||
| 3382 | + .stderr(Stdio::piped()) | ||
| 3383 | + .output() | ||
| 3384 | + .expect("ffmpeg failed to run"); | ||
| 3385 | + if !out.status.success() || out.stdout.is_empty() { | ||
| 3386 | + eprintln!( | ||
| 3387 | + "SKIP {NAME}: no libsvtav1 in this ffmpeg: {}", | ||
| 3388 | + String::from_utf8_lossy(&out.stderr) | ||
| 3389 | + ); | ||
| 3390 | + return; | ||
| 3391 | + } | ||
| 3392 | + let stream = out.stdout; | ||
| 3393 | + crate::decode::reset_palette_onscreen_cut_hits(); | ||
| 3394 | + let decoded = decode_stream(&stream).expect("the SVT-AV1 screen stream decodes"); | ||
| 3395 | + assert_eq!(decoded.len(), 4, "{NAME}: frame count"); | ||
| 3396 | + assert!( | ||
| 3397 | + crate::decode::palette_onscreen_cut_hits() > 0, | ||
| 3398 | + "{NAME}: no palette map is cut by the frame edge here -- the gate would pass blind" | ||
| 3399 | + ); | ||
| 3400 | + let want = ffmpeg_decode_sequence(&stream, width, height, decoded.len()); | ||
| 3401 | + assert_eq!(want.len(), decoded.len(), "{NAME}: ffmpeg frame count"); | ||
| 3402 | + for (i, (got, want)) in decoded.iter().zip(&want).enumerate() { | ||
| 3403 | + assert_eq!(got.y, want.y, "{NAME}: frame {i} luma vs ffmpeg"); | ||
| 3404 | + assert_eq!(got.u, want.u, "{NAME}: frame {i} U vs ffmpeg"); | ||
| 3405 | + assert_eq!(got.v, want.v, "{NAME}: frame {i} V vs ffmpeg"); | ||
| 3406 | + } | ||
| 3407 | + } | ||
| 3408 | + | ||
| 3347 | /// lane-svt1: an SVT-AV1 (v3.1.2, `-preset 8 -crf 35`) screen key frame | 3409 | /// lane-svt1: an SVT-AV1 (v3.1.2, `-preset 8 -crf 35`) screen key frame |
| 3348 | /// codes 16x16 PALETTE blocks with `skip == 1` whose `tx_depth` split the | 3410 | /// codes 16x16 PALETTE blocks with `skip == 1` whose `tx_depth` split the |
| 3349 | /// luma transform. [`crate::decode::decode_block`] armed the palette | 3411 | /// luma transform. [`crate::decode::decode_block`] armed the palette |
lanes/svtinter.report.mdadded+94 -0
| @@ -0,0 +1,94 @@ | |||
| 1 | +# lane-svtinter — the palette colour-index map read past the frame edge | ||
| 2 | + | ||
| 3 | +Class: **map-read-past-frame-edge** — a syntax loop whose extent the spec | ||
| 4 | +clamps to the block's ON-SCREEN part, read at the full block size, so the | ||
| 5 | +decoder consumes symbols the encoder never wrote. | ||
| 6 | + | ||
| 7 | +## First divergent symbol | ||
| 8 | + | ||
| 9 | +Stream `smptebars=s=384x152:r=12,drawgrid=w=8:h=8:t=1:c=black` through | ||
| 10 | +`libsvtav1 -preset 8 -crf 30 -svtav1-params lp=1:screen-content-mode=1`, | ||
| 11 | +frame 0 (the KEY frame — the defect is not inter-only; lane-svt1's | ||
| 12 | +"key frames are exact" held only for its own kept stream). | ||
| 13 | + | ||
| 14 | +* Pixels: first wrong luma sample at row 128, col 296; everything after it in | ||
| 15 | + the raster diverges (1599 luma + 28 chroma in frame 0, ~80k per inter | ||
| 16 | + frame). | ||
| 17 | +* Partitions agree with an instrumented aomdec (`EC_TRACE`) through the whole | ||
| 18 | + frame up to `mi_row=32 mi_col=72 bsize=BLOCK_32X32 PARTITION_NONE`, which is | ||
| 19 | + exactly the block covering pixel (128, 288). | ||
| 20 | +* Mode ladder agrees symbol for symbol into that block (`EC_TRACE_MODE_STEP`, | ||
| 21 | + `EC_PALSYN`): `skip=1`, `y_mode=DC`, `uv_mode=DC`, `palette_y_mode=1`, | ||
| 22 | + `palette_y_size=3`, colours `[7,16,24]`, `rng=39432` on both sides. | ||
| 23 | +* **First divergent symbol**: the colour-index map's wavefront, diagonal | ||
| 24 | + `i = 24`. aomdec's last symbol on that diagonal is `row=23 col=1` and it | ||
| 25 | + moves on to `row=0 col=25`; ours reads one more, `row=24 col=0`, and every | ||
| 26 | + symbol after that is one position out of step (`rng` 42060 vs 42068 from | ||
| 27 | + there on). | ||
| 28 | + | ||
| 29 | +## Root cause | ||
| 30 | + | ||
| 31 | +The block is 32x32 at mi row 32 of a 38-mi-tall frame: only 24 of its 32 rows | ||
| 32 | +are inside the mi grid. Spec 5.11.50 `palette_tokens` / | ||
| 33 | +`av1_get_block_dimensions` (blockd.h:1512) read the colour-index map over | ||
| 34 | +`onscreenWidth x onscreenHeight` only and REPLICATE the last on-screen column | ||
| 35 | +and row over the rest (detokenize.c:71). `decode_color_index_map_wh` walked | ||
| 36 | +the full `bw x bh` grid — its own doc comment asserted the clamp was | ||
| 37 | +unnecessary ("palette blocks ... never straddle the frame's true edge"). | ||
| 38 | + | ||
| 39 | +Both reported failure kinds are this one defect: the extra symbols either | ||
| 40 | +shift the rest of the tile (~200k-sample misses) or eventually make a coeff | ||
| 41 | +Golomb tail read as absurdly long ("a Golomb tail longer than this decoder | ||
| 42 | +reads" — a desync symptom, never a reader bound, as the standing class says). | ||
| 43 | + | ||
| 44 | +## Fix | ||
| 45 | + | ||
| 46 | +`crates/ec-av1/src/decode.rs`: | ||
| 47 | + | ||
| 48 | +* `palette_onscreen(mi_r, mi_c, bw, bh, fctx)` — the on-screen extent in luma | ||
| 49 | + pixels, from `fctx.seg_mi_dims` (set once per frame for every frame). | ||
| 50 | +* `palette_onscreen_uv(luma, on, chroma)` — the same carried into chroma, | ||
| 51 | + keeping the `is_chroma_sub8` +2 bump in step with the caller's own | ||
| 52 | + `(bw / 2).max(4)`. | ||
| 53 | +* `decode_color_index_map{,_wh}` take `(onscreenWidth, onscreenHeight)`, read | ||
| 54 | + the wavefront over that corner at the full-block stride, then replicate the | ||
| 55 | + last on-screen column and row (libaom's own two extension loops). | ||
| 56 | + | ||
| 57 | +Same-shape sweep — all five reader call sites take the clamp: key-frame square | ||
| 58 | +(`read_intra_mode`), rect strip (`read_intra_mode_rect`), intra-in-inter rect | ||
| 59 | +(`decode_intra_rect_in_inter`), inter block intra (`decode_inter_block`), 8x8 | ||
| 60 | +inter leaf (`decode_inter_block8`), luma and chroma each. | ||
| 61 | + | ||
| 62 | +## Pass table | ||
| 63 | + | ||
| 64 | +Every decode compares EVERY plane of EVERY frame against `ffmpeg -pix_fmt | ||
| 65 | +yuv420p` (harness asserts our decode exited 0 and produced N frames first). | ||
| 66 | + | ||
| 67 | +| streams | before | after | | ||
| 68 | +|---|---|---| | ||
| 69 | +| fresh sweep: `smptebars,drawgrid` x {384x152, 320x184, 640x366} x crf {20,30,35,45}, 4 frames | 8 exact, 2 DIFF (22397/1599 samples in frame 0 alone), 3 REFUSED (Golomb tail) — 12 total | **12/12 exact** | | ||
| 70 | +| kept `$HOME/.cache/svt1-keep/w3/*.obu` (180 streams) | (lane-svt1: 2 refusals + 6 x ~200k-sample misses among the 8 that reach its arm) | **180/180 exact** | | ||
| 71 | + | ||
| 72 | +No refusal string survives on any stream in either set. | ||
| 73 | + | ||
| 74 | +## Witness | ||
| 75 | + | ||
| 76 | +`stream::tests::an_svt_screen_palette_map_cut_by_the_frame_edge_decodes_exactly` | ||
| 77 | +BUILDS its stream in-test (the recipe above at crf 30), SKIPs with a printed | ||
| 78 | +reason when ffmpeg/libsvtav1 is missing, asserts the new | ||
| 79 | +`decode::palette_onscreen_cut_hits()` counter is non-zero (so it cannot pass | ||
| 80 | +on a stream that never cuts a palette map) and compares all three planes of | ||
| 81 | +all four frames against ffmpeg. | ||
| 82 | + | ||
| 83 | +* RED (reader reverted to the full-grid walk, counter kept): `test result: | ||
| 84 | + FAILED. 0 passed; 1 failed`, panic `frame 0 luma vs ffmpeg`. | ||
| 85 | +* GREEN: `test result: ok. 1 passed`. | ||
| 86 | + | ||
| 87 | +## Open | ||
| 88 | + | ||
| 89 | +* `open|` The WRITE side has the same shape: `tile.rs:3457 | ||
| 90 | + write_color_index_map` walks `side x side` with no on-screen clamp | ||
| 91 | + (callers at 3498 / 3908 / 3913). Reachable only when our own encoder codes | ||
| 92 | + a palette block straddling the mi grid (screen-content mode at a frame size | ||
| 93 | + whose bottom/right block is cut) — not fixed here because a writer change | ||
| 94 | + moves the encoder pins, which this lane must leave byte-identical. | ||