Pin the libaom screen stream whose sub-8x8 groups sit beside palette blocks
Browse files at this commit8d023ec17fae809f3371066da50e6840bbe3437aParent: 2fe9a36- test
- pin the libaom screen stream whose sub-8x8 groups sit beside palette blocks
1 changed file +95 -0
- crates/ec-av1/src/stream.rs +95 -0
crates/ec-av1/src/stream.rsmodified+95 -0
| @@ -3867,6 +3867,101 @@ pub(crate) mod tests { | |||
| 3867 | } | 3867 | } |
| 3868 | } | 3868 | } |
| 3869 | 3869 | ||
| 3870 | + /// lane-dkey: the palette-neighbour-band gate. A palette-Y block's size and | ||
| 3871 | + /// colours used to stay standing in the mi-granular above/left bands after a | ||
| 3872 | + /// sub-8x8 group was decoded next to it -- the sub-8x8 readers published | ||
| 3873 | + /// skip/lf/mode state but no palette state, while libaom's mi grid carries | ||
| 3874 | + /// `palette_size == 0` in exactly those cells (`av1_allow_palette` needs | ||
| 3875 | + /// BLOCK_8X8 and up). The next intra block then read `palette_y_mode` off | ||
| 3876 | + /// CDF row 1 where libaom reads row 0 (class `cdf-row-held-constant`), | ||
| 3877 | + /// decoded a palette libaom never coded, and skipped the `use_filter_intra` | ||
| 3878 | + /// symbol a palette block has none of: one symbol short, tile desynced. | ||
| 3879 | + /// | ||
| 3880 | + /// Measured on the instrumented aomdec at KEY-frame block mi(76,88) of this | ||
| 3881 | + /// very stream (`EC_PALSYN_AOM ... ctx=0 y=0` against our `mode_ctx=1`). | ||
| 3882 | + /// Without the fix every one of the 12 frames differs from ffmpeg's decode | ||
| 3883 | + /// from luma sample 491904 on. | ||
| 3884 | + /// | ||
| 3885 | + /// The source is SYNTHETIC (no film sample lives in `fixtures`): the dark, | ||
| 3886 | + /// near-flat background libaom's own screen-content detector counts as | ||
| 3887 | + /// screen content (2..=4 distinct luma values per 16x16 block), which is | ||
| 3888 | + /// what turns palette on, plus one textured patch at a HALF-PEL position on | ||
| 3889 | + /// half the frames so the encoder splits that region down to 4x4 groups | ||
| 3890 | + /// beside its palette blocks. | ||
| 3891 | + #[test] | ||
| 3892 | + fn a_libaom_screen_stream_with_sub8_groups_beside_palette_blocks_decodes_exact() { | ||
| 3893 | + const NAME: &str = | ||
| 3894 | + "a_libaom_screen_stream_with_sub8_groups_beside_palette_blocks_decodes_exact"; | ||
| 3895 | + if !have_ffmpeg() { | ||
| 3896 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 3897 | + return; | ||
| 3898 | + } | ||
| 3899 | + let (w, h, frames) = (1920usize, 1024usize, 12usize); | ||
| 3900 | + let mut raw = Vec::with_capacity(frames * w * h * 3 / 2); | ||
| 3901 | + for f in 0..frames { | ||
| 3902 | + let mut y = vec![0u8; w * h]; | ||
| 3903 | + for row in 0..h { | ||
| 3904 | + for col in 0..w { | ||
| 3905 | + y[row * w + col] = | ||
| 3906 | + 16 + ((col / 32 + row / 32) % 5) as u8 + ((col / 4 + row / 4) % 3) as u8; | ||
| 3907 | + } | ||
| 3908 | + } | ||
| 3909 | + // 2.5 px per pair of frames: integer on one pair, half a pixel off | ||
| 3910 | + // on the next (linear interpolation), so the patch's edges land | ||
| 3911 | + // mid-sample and the encoder splits there. | ||
| 3912 | + let x0 = 200.0 + 2.5 * (f / 2) as f64; | ||
| 3913 | + let (fx, ix) = (x0.fract(), x0.floor() as usize); | ||
| 3914 | + for row in 300..428 { | ||
| 3915 | + for col in 0..192 { | ||
| 3916 | + let tex = |u: f64| -> f64 { | ||
| 3917 | + let v = (row - 300) as f64; | ||
| 3918 | + 30.0 + 100.0 * (0.5 + 0.5 * ((u * 0.35).sin() * (v * 0.21).cos())) | ||
| 3919 | + }; | ||
| 3920 | + let s = tex(col as f64) * (1.0 - fx) + tex(col as f64 - 1.0) * fx; | ||
| 3921 | + y[row * w + ix + col] = s.round().clamp(0.0, 255.0) as u8; | ||
| 3922 | + } | ||
| 3923 | + } | ||
| 3924 | + raw.extend_from_slice(&y); | ||
| 3925 | + raw.extend(std::iter::repeat_n(128u8, w * h / 2)); | ||
| 3926 | + } | ||
| 3927 | + // [[pid-keyed-temp-path]]: parallel test binaries must not share a name. | ||
| 3928 | + let src = std::env::temp_dir().join(format!("ec-av1-palsub8-{}.yuv", std::process::id())); | ||
| 3929 | + std::fs::write(&src, &raw).expect("raw source"); | ||
| 3930 | + let out = Command::new("ffmpeg") | ||
| 3931 | + .args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "yuv420p"]) | ||
| 3932 | + .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"]) | ||
| 3933 | + .arg(&src) | ||
| 3934 | + .args(["-an", "-threads", "1", "-g", "12", "-c:v", "libaom-av1"]) | ||
| 3935 | + .args(["-cpu-used", "6", "-b:v", "0", "-crf", "35", "-f", "obu", "-"]) | ||
| 3936 | + .stdin(Stdio::null()) | ||
| 3937 | + .stdout(Stdio::piped()) | ||
| 3938 | + .stderr(Stdio::piped()) | ||
| 3939 | + .output() | ||
| 3940 | + .expect("ffmpeg failed to run"); | ||
| 3941 | + let _ = std::fs::remove_file(&src); | ||
| 3942 | + if !out.status.success() { | ||
| 3943 | + eprintln!( | ||
| 3944 | + "SKIP {NAME}: ffmpeg has no libaom-av1 encoder ({})", | ||
| 3945 | + String::from_utf8_lossy(&out.stderr) | ||
| 3946 | + ); | ||
| 3947 | + return; | ||
| 3948 | + } | ||
| 3949 | + let stream = out.stdout; | ||
| 3950 | + let ours = decode_stream(&stream).expect("libaom screen-content stream decodes"); | ||
| 3951 | + let theirs = ffmpeg_decode_sequence(&stream, w, h, frames); | ||
| 3952 | + assert_eq!(ours.len(), frames, "{NAME}: shown frame count"); | ||
| 3953 | + for (i, (a, b)) in ours.iter().zip(theirs.iter()).enumerate() { | ||
| 3954 | + for (plane, l, r) in [("Y", &a.y, &b.y), ("U", &a.u, &b.u), ("V", &a.v, &b.v)] { | ||
| 3955 | + let first = l.iter().zip(r.iter()).position(|(x, y)| x != y); | ||
| 3956 | + assert!( | ||
| 3957 | + first.is_none(), | ||
| 3958 | + "{NAME}: frame {i} plane {plane} differs from ffmpeg at sample {}", | ||
| 3959 | + first.unwrap() | ||
| 3960 | + ); | ||
| 3961 | + } | ||
| 3962 | + } | ||
| 3963 | + } | ||
| 3964 | + | ||
| 3870 | /// Hardened past the report-only test above: a real libaom-av1 gradients | 3965 | /// Hardened past the report-only test above: a real libaom-av1 gradients |
| 3871 | /// stream, pinned deterministic (`gradients`' own `seed=`, plus | 3966 | /// stream, pinned deterministic (`gradients`' own `seed=`, plus |
| 3872 | /// `-threads 1`/`-row-mt 0`/no tiling so libaom's `cpu-used 8` RD search | 3967 | /// `-threads 1`/`-row-mt 0`/no tiling so libaom's `cpu-used 8` RD search |