diff --git a/crates/ec-av1/src/decode/mod.rs b/crates/ec-av1/src/decode/mod.rs index a17b5e63..6656567f 100644 --- a/crates/ec-av1/src/decode/mod.rs +++ b/crates/ec-av1/src/decode/mod.rs @@ -100,9 +100,6 @@ pub use key_tile::*; mod inter_ctx; pub(crate) use inter_ctx::*; -#[cfg(test)] -mod obmc_skip_chroma_tests; - mod sub8_inter; pub(crate) use frame_tile::*; use sub8_inter::*; @@ -3793,5 +3790,3 @@ pub(crate) fn decode_key_frame_tile( #[cfg(test)] mod tests; -#[cfg(test)] -mod tx4x8_table_tests; diff --git a/crates/ec-av1/src/decode/obmc_skip_chroma_tests.rs b/crates/ec-av1/src/decode/obmc_skip_chroma_tests.rs deleted file mode 100644 index 6bfce4c0..00000000 --- a/crates/ec-av1/src/decode/obmc_skip_chroma_tests.rs +++ /dev/null @@ -1,27 +0,0 @@ -use super::obmc_skip_chroma_above; - -/// lane-av1-llpred2: the above-chroma skip keys off the PLANE block -/// under the frame's own ss pair. At 4:2:0 a 16x8/8x16 rect strip's -/// plane block is 8x4/4x8 and MUST still skip (the old `chroma_side` -/// ratio read ss=(1,0) off a 16x8 strip and made it blend); at 4:4:4 -/// the plane block is the luma block, so only true 4-wide/high shapes -/// skip and the shift never leaves `usize` range (the old ratio's -/// `trailing_zeros(0)` = 64 panicked a debug build). -#[test] -fn rect_strips_skip_above_chroma_at_420_and_shift_never_overflows() { - // 4:2:0 (ss 1,1): 8x8 -> 4x4, 16x8 -> 8x4, 8x16 -> 4x8 all skip. - assert!(obmc_skip_chroma_above(8, 8, 1, 1)); - assert!(obmc_skip_chroma_above(16, 8, 1, 1)); - assert!(obmc_skip_chroma_above(8, 16, 1, 1)); - // ... larger plane blocks blend, exactly libaom's own list. - assert!(!obmc_skip_chroma_above(16, 16, 1, 1)); - assert!(!obmc_skip_chroma_above(32, 16, 1, 1)); - assert!(!obmc_skip_chroma_above(16, 32, 1, 1)); - // 4:4:4 (ss 0,0): the plane block is the luma block itself. - assert!(obmc_skip_chroma_above(4, 4, 0, 0)); - assert!(obmc_skip_chroma_above(8, 4, 0, 0)); - assert!(obmc_skip_chroma_above(4, 8, 0, 0)); - assert!(!obmc_skip_chroma_above(8, 8, 0, 0)); - assert!(!obmc_skip_chroma_above(16, 8, 0, 0)); - assert!(!obmc_skip_chroma_above(8, 16, 0, 0)); -} diff --git a/crates/ec-av1/src/decode/tx4x8_table_tests.rs b/crates/ec-av1/src/decode/tx4x8_table_tests.rs deleted file mode 100644 index e3492876..00000000 --- a/crates/ec-av1/src/decode/tx4x8_table_tests.rs +++ /dev/null @@ -1,89 +0,0 @@ -use super::*; - -/// Asymmetric gate on the two new scan tables (class -/// `reference-layout-not-spec`): a transposed pair of tables passes any -/// "is a permutation" check, so this pins the pair AGAINST each other -- -/// `SCAN_8X4[k]` must be `SCAN_4X8[k]` reflected across the diagonal, and -/// both must be bijections of `0..32` in our own row-major indexing. -#[test] -fn the_rect_4x8_scans_are_each_other_transposed() { - let mut seen_a = [false; 32]; - let mut seen_b = [false; 32]; - for k in 0..32usize { - let a = SCAN_4X8[k] as usize; - let b = SCAN_8X4[k] as usize; - assert!(!seen_a[a] && !seen_b[b], "scan position {k} repeats"); - seen_a[a] = true; - seen_b[b] = true; - let (row, col) = (a / 4, a % 4); - assert_eq!( - b, - col * 8 + row, - "SCAN_8X4[{k}] is not SCAN_4X8[{k}] transposed" - ); - } - assert!(seen_a.iter().all(|&s| s) && seen_b.iter().all(|&s| s)); -} - -/// `mrow_scan_4x8`/`mcol_scan_4x8`/`mrow_scan_8x4`/`mcol_scan_8x4` -/// (libaom `scan.c`), converted out of their column-major encoding by -/// `(p % h) * w + p / h` -- the head of each, pinned so the rect -/// `V_DCT`/`H_DCT` walk cannot silently transpose. -#[test] -fn the_rect_class1_scans_match_libaom() { - assert_eq!( - class_scan_table_wh(4, 8, TxClass::Vert), - (0..32u16).collect::>() - ); - assert_eq!( - &class_scan_table_wh(4, 8, TxClass::Horiz)[..8], - &[0u16, 4, 8, 12, 16, 20, 24, 28] - ); - assert_eq!( - class_scan_table_wh(8, 4, TxClass::Vert), - (0..32u16).collect::>() - ); - assert_eq!( - &class_scan_table_wh(8, 4, TxClass::Horiz)[..8], - &[0u16, 8, 16, 24, 1, 9, 17, 25] - ); -} - -/// The 32-position `eob_pt` alphabet: six symbols (one more than the -/// 16-position table, one fewer than the 64-position one), strictly -/// increasing, terminated at 32768 with the adaptation counter after it. -#[test] -fn the_32_position_eob_tables_are_well_formed() { - for table in [ - &cdf::EOB_PT_32_LUMA_Q0, - &cdf::EOB_PT_32_LUMA_Q1, - &cdf::EOB_PT_32_LUMA, - &cdf::EOB_PT_32_LUMA_Q3, - &cdf::EOB_PT_32_LUMA_CLASS1_Q0, - &cdf::EOB_PT_32_LUMA_CLASS1_Q1, - &cdf::EOB_PT_32_LUMA_CLASS1, - &cdf::EOB_PT_32_LUMA_CLASS1_Q3, - ] { - assert_eq!(table.len(), 7); - assert_eq!(table[5], 32768); - assert_eq!(table[6], 0); - for w in table[..6].windows(2) { - assert!(w[0] < w[1], "{table:?} is not increasing"); - } - } -} - -/// `Reach::of_rect` must read libaom's own `has_tr_4x8`/`has_tr_8x4` -/// rows, not the 32x16 pair the two existing rect strips use: the two -/// shapes disagree at a position inside the superblock, which is what -/// makes this an asymmetric check rather than a tautology. -#[test] -fn the_sub8_rect_reach_tables_are_shape_specific() { - let fctx = &crate::decode::FrameCtx::new(); - let a = Reach::of_rect(4, 8, 4, 8, 64, 64, fctx); - let b = Reach::of_rect(8, 4, 8, 4, 64, 64, fctx); - assert!( - a.above_right != b.above_right || a.below_left != b.below_left, - "4x8 and 8x4 reach identically at mirrored positions -- one table is unused" - ); -} diff --git a/crates/ec-av1/tests/real_library.rs b/crates/ec-av1/tests/real_library.rs deleted file mode 100644 index d474843c..00000000 --- a/crates/ec-av1/tests/real_library.rs +++ /dev/null @@ -1,287 +0,0 @@ -use std::io::Read; -use std::path::{Path, PathBuf}; -use std::process::{Child, ChildStdout, Stdio}; - -use ec_av1::encode::Picture; - -const FRAMES: usize = 300; - -const IN_SCOPE_PIX_FMTS: [&str; 2] = ["yuv420p", "yuv420p10le"]; - -fn scratch(tag: &str) -> PathBuf { - let base = std::env::var_os("TMPDIR").map_or_else(std::env::temp_dir, PathBuf::from); - let dir = base.join(format!("ec-av1-{tag}-{}", std::process::id())); - std::fs::create_dir_all(&dir).expect("scratch dir"); - dir -} - -struct Entry { - path: PathBuf, - container: String, - width: String, - height: String, - pix_fmt: String, -} - -fn open_entries() -> Vec { - vec![Entry { - path: ec_testkit::fixture("derived/sintel720-svtav1.ivf"), - container: "ivf".to_string(), - width: "1280".to_string(), - height: "720".to_string(), - pix_fmt: "yuv420p".to_string(), - }] -} - -fn frame_bytes(pic: &Picture, bps: usize) -> Vec { - let mut out = Vec::with_capacity((pic.y.len() + pic.u.len() + pic.v.len()) * bps); - for plane in [&pic.y, &pic.u, &pic.v] { - for &s in plane.iter() { - if bps == 1 { - out.push(s as u8); - } else { - out.extend_from_slice(&s.to_le_bytes()); - } - } - } - out -} - -fn locate(offset: usize, bps: usize, pic: &Picture) -> (&'static str, usize, usize) { - let s = offset / bps; - let (w, cw) = (pic.width, pic.u.len() / pic.height.div_ceil(2).max(1)); - let luma = pic.y.len(); - if s < luma { - ("Y", s % w, s / w) - } else if s < luma + pic.u.len() { - let c = s - luma; - ("U", c % cw.max(1), c / cw.max(1)) - } else { - let c = s - luma - pic.u.len(); - ("V", c % cw.max(1), c / cw.max(1)) - } -} - -struct Sweep { - out: ChildStdout, - child: Child, - open: bool, - compared: usize, - differing_frames: usize, - first_diff: Option, - oracle_short: bool, - index: usize, - frame_len: usize, - bps: usize, - max_sample: u16, -} - -impl Sweep { - fn take(&mut self, pic: &Picture) { - let index = self.index; - self.index += 1; - if !self.open || self.index > FRAMES { - return; - } - if let Some(&s) = pic.y.iter().chain(&pic.u).chain(&pic.v).max() - && s > self.max_sample - { - self.differing_frames += 1; - self.first_diff.get_or_insert(format!( - "frame {index}: sample {s} above the maximum {}", - self.max_sample - )); - } - let want = frame_bytes(pic, self.bps); - self.frame_len = want.len(); - let mut oracle = vec![0u8; want.len()]; - if self.out.read_exact(&mut oracle).is_err() { - self.open = false; - self.oracle_short = true; - return; - } - self.compared += 1; - if want != oracle { - self.differing_frames += 1; - if self.first_diff.is_none() { - let at = want - .iter() - .zip(&oracle) - .position(|(a, b)| a != b) - .unwrap_or(0); - let (plane, x, y) = locate(at, self.bps, pic); - self.first_diff = Some(format!("frame {index} plane {plane} x={x} y={y}")); - } - } - } - - fn finish(mut self) -> Sweep { - if self.open && self.frame_len > 0 { - let mut probe = vec![0u8; self.frame_len]; - if self.out.read_exact(&mut probe).is_ok() { - self.first_diff.get_or_insert(format!( - "decoder produced {} frames, ffmpeg produced more", - self.index - )); - self.differing_frames += 1; - } - } - let _ = self.child.kill(); - let _ = self.child.wait(); - self - } -} - -fn short_name(path: &Path) -> String { - path.file_name() - .map(|n| n.to_string_lossy().chars().take(38).collect()) - .unwrap_or_default() -} - -fn extract(src: &Path, dst: &Path) -> bool { - ec_testkit::ffmpeg() - .args(["-v", "error", "-y", "-i"]) - .arg(src) - .args([ - "-map", - "0:v:0", - "-c", - "copy", - "-frames:v", - &FRAMES.to_string(), - "-f", - "obu", - ]) - .arg(dst) - .status() - .is_ok_and(|s| s.success()) -} - -fn sweep_file(es: &Path, pix_fmt: &str, bit_depth: u32) -> Result { - let bps = if bit_depth > 8 { 2 } else { 1 }; - let mut child = ec_testkit::ffmpeg() - .args(["-v", "error", "-c:v", "libdav1d", "-i"]) - .arg(es) - .args([ - "-frames:v", - &FRAMES.to_string(), - "-f", - "rawvideo", - "-pix_fmt", - pix_fmt, - "-", - ]) - .stdout(Stdio::piped()) - .stderr(Stdio::null()) - .spawn() - .map_err(|e| e.to_string())?; - let out = child.stdout.take().expect("piped stdout"); - let mut sweep = Sweep { - out, - child, - open: true, - compared: 0, - differing_frames: 0, - first_diff: None, - oracle_short: false, - index: 0, - frame_len: 0, - bps, - max_sample: ((1u32 << bit_depth) - 1) as u16, - }; - let data = std::fs::read(es).map_err(|e| e.to_string())?; - let result = ec_av1::stream::decode_stream_with(&data, |pic, _decode_index, shown| { - if shown { - sweep.take(pic); - } - Ok(()) - }); - let sweep = sweep.finish(); - if let Err(e) = result { - return Err(format!("{e}")); - } - Ok(sweep) -} - -#[test] -fn sintel_av1_stream_matches_ffmpeg() { - let entries = open_entries(); - let dir = scratch("real-library-av1"); - let mut table = String::new(); - let mut decoded = 0usize; - let mut refused = 0usize; - let mut failures = Vec::new(); - - for entry in &entries { - let name = short_name(&entry.path); - let res = format!("{}x{}", entry.width, entry.height); - let bit_depth: u32 = if entry.pix_fmt == "yuv420p10le" { - 10 - } else { - 8 - }; - if !IN_SCOPE_PIX_FMTS.contains(&entry.pix_fmt.as_str()) { - refused += 1; - table.push_str(&format!( - "{name:<38} {:<12} {res:>10} {bit_depth:>2}-bit {:>4} refused: pixel format {} is outside 4:2:0 8/10-bit\n", - entry.container, "-", entry.pix_fmt - )); - continue; - } - let es = dir.join("stream.obu"); - if !extract(&entry.path, &es) { - failures.push(format!("{name}: extraction failed")); - table.push_str(&format!( - "{name:<38} {:<12} {res:>10} {bit_depth:>2}-bit {:>4} ERROR extraction\n", - entry.container, "-" - )); - continue; - } - match sweep_file(&es, &entry.pix_fmt, bit_depth) { - Ok(s) if s.differing_frames > 0 => { - failures.push(format!("{name}: {} frames differ", s.differing_frames)); - table.push_str(&format!( - "{name:<38} {:<12} {res:>10} {bit_depth:>2}-bit {:>4} MISMATCH {} of {} frames; first: {}\n", - entry.container, s.compared, s.differing_frames, s.compared, - s.first_diff.clone().unwrap_or_default() - )); - } - Ok(s) => { - decoded += 1; - table.push_str(&format!( - "{name:<38} {:<12} {res:>10} {bit_depth:>2}-bit {:>4} bit-exact{}\n", - entry.container, - s.compared, - if s.oracle_short { - " (ffmpeg stopped early)" - } else { - "" - } - )); - } - Err(e) if e.contains("unsupported") => { - refused += 1; - table.push_str(&format!( - "{name:<38} {:<12} {res:>10} {bit_depth:>2}-bit {:>4} refused: {e}\n", - entry.container, "-" - )); - } - Err(e) => { - failures.push(format!("{name}: {e}")); - table.push_str(&format!( - "{name:<38} {:<12} {res:>10} {bit_depth:>2}-bit {:>4} ERROR {e}\n", - entry.container, "-" - )); - } - } - let _ = std::fs::remove_file(&es); - } - let _ = std::fs::remove_dir_all(&dir); - eprintln!("{table}"); - eprintln!( - "real library av1: {decoded} bit-exact, {refused} refused by name, {} failed", - failures.len() - ); - assert!(failures.is_empty(), "{failures:#?}"); - assert!(decoded >= 1, "no real AV1 file was swept end to end"); -}