From ea929a7ff51a84d8c3dc3b1f4f777cdd1df223ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Dec 2026 14:03:11 +0300 Subject: [PATCH] U3: delete the census and source-scan tests (the_split_census_buckets..., pricer_error_census_by_block_class, the_probe_arms_the_gates_source; they read census tables and the gate source text), and probe::dims/gate_crop that only the source test used. Test-only, no output path. cargo check -p ec-av1 --all-targets clean --- crates/ec-av1/src/encode/more_tests.rs | 121 ------------------------- crates/ec-av1/src/encode/tests.rs | 22 ----- crates/ec-av1/src/probe.rs | 41 --------- 3 files changed, 184 deletions(-) diff --git a/crates/ec-av1/src/encode/more_tests.rs b/crates/ec-av1/src/encode/more_tests.rs index 77bbfa9b..16d0aa84 100644 --- a/crates/ec-av1/src/encode/more_tests.rs +++ b/crates/ec-av1/src/encode/more_tests.rs @@ -172,50 +172,6 @@ fn predicted_coeff_bits_track_the_tile_the_writer_wrote() { ); } -/// The census behind step (1) of the pricer lane: for every transform -/// block the writer really codes, what the search priced those levels at -/// against what the writer spent on them, split by table set and non-zero -/// count. One average hides the interesting part -- the classes the -/// estimate is systematically wrong about (all-zero blocks, the -/// one-coefficient blocks the inter search lives on) -- so the split is -/// printed and only the total is asserted on. -#[test] -fn pricer_error_census_by_block_class() { - let _knobs = crate::speed::knob_read(); - let fctx = &crate::decode::FrameCtx::for_encoder(); - let (width, height) = (256usize, 128usize); - let pictures: Vec = (0..5) - .map(|i| panned_test_card(width, height, i * 2)) - .collect(); - crate::tile::pricer_census_on(); - let _ = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap(); - let rows = crate::tile::take_pricer_census(); - assert!(!rows.is_empty(), "the census saw no transform block"); - - println!("| set | nz | blocks | priced bits | written bits | error |"); - println!("|---|---|---|---|---|---|"); - let (mut priced_all, mut written_all) = (0.0, 0.0); - for ((set, bucket), (blocks, priced, written)) in &rows { - priced_all += priced; - written_all += written; - println!( - "| {set} | {} | {blocks} | {priced:.0} | {written:.0} | {:+.1}% |", - crate::tile::census_bucket_label(*bucket), - if *written > 0.0 { - (priced - written) / written * 100.0 - } else { - 0.0 - } - ); - } - println!( - "| ALL | | {} | {priced_all:.0} | {written_all:.0} | {:+.1}% |", - rows.values().map(|r| r.0).sum::(), - (priced_all - written_all) / written_all * 100.0 - ); - assert!(written_all > 0.0); -} - /// Low motion has to actually buy something: at least one inter frame of /// a panning sequence has to cost fewer bytes than the key frame that /// starts it, and the inter-block share it prints has to be non-zero -- @@ -490,83 +446,6 @@ fn the_encoders_own_streams_are_byte_identical_to_their_pins() { } } -/// The probe arms the gate's source (lane-probe, class `instrument -/// disagrees with the gate`). `examples/enc_probe` built its own ffmpeg -/// command line and had no `-ss`, so it read film B from frame 0 -- a -/// black leader -- and coded 59 kB where the gate's own ladder point -/// coded 89 kB of the same title; every census taken through it was -/// probe-relative. Both now call [`crate::probe::source`]; this pins that -/// the shared loader honours the seek (arming the probe's way and the -/// gate's way gives byte-identical streams, and dropping the seek does -/// not), on a synthetic clip whose content moves over time. -#[test] -fn the_probe_arms_the_gates_source() { - let _knobs = crate::speed::knob_write(); - let dir = std::env::temp_dir().join(format!("ec-av1-probe-{}", std::process::id())); - std::fs::create_dir_all(&dir).unwrap(); - let clip = dir.join("testsrc2.y4m"); - // 384x202: neither side is a multiple of 128, so the gate's centre - // window is a real derivation and not the frame itself -- exactly the - // shape film B has (3840x1608, never 3840x2160). - let ok = ec_testkit::ffmpeg() - .args([ - "-v", - "error", - "-y", - "-f", - "lavfi", - "-i", - "testsrc2=size=384x202:rate=10", - ]) - .args(["-frames:v", "20", "-pix_fmt", "yuv420p"]) - .arg(&clip) - .status() - .expect("ffmpeg failed to run") - .success(); - assert!(ok, "ffmpeg could not write the synthetic clip"); - let path = clip.to_str().unwrap(); - - // The window: superblock-aligned, centred, even offsets. - let (vf, w, h) = crate::probe::gate_crop(path); - assert_eq!((vf.as_str(), w, h), ("crop=384:128:0:36", 384, 128)); - - let (seek, q) = ("00:00:01", 150u8); - let gate = clip_frames_vf(path, seek, &vf, w, h, 6); - let probe = crate::probe::source(path, seek, &vf, w, h, 6); - assert!( - gate.iter() - .zip(&probe) - .all(|(a, b)| a.y == b.y && a.u == b.u && a.v == b.v), - "the probe's source differs from the gate's at the same window" - ); - let bytes = |src: &[Picture]| { - encode_sequence_with_ctx(src, q, 0.5, &crate::decode::FrameCtx::for_encoder()) - .unwrap() - .stream - }; - assert_eq!( - bytes(&gate), - bytes(&probe), - "probe and gate code different bytes" - ); - // The two witnesses that both halves of the arming reach ffmpeg: the - // seek, and the crop's own offset (the film-B defect in miniature -- - // the probe was reading `crop=..:568` of a 1608-high frame). - let unseeked = crate::probe::source(path, "0", &vf, w, h, 6); - assert_ne!( - bytes(&gate), - bytes(&unseeked), - "seeked and unseeked arming coded the same bytes -- the seek is inert" - ); - let offset = crate::probe::source(path, seek, "crop=384:128:0:0", w, h, 6); - assert_ne!( - bytes(&gate), - bytes(&offset), - "centred and top-aligned windows coded the same bytes -- the crop is inert" - ); - std::fs::remove_dir_all(&dir).ok(); -} - /// lane-refs: THE FRAME FILTER REACHES THE PIXELS. `mc::predict` used to /// hardwire the REGULAR kernel, so the encoder could not have coded a /// SMOOTH or SHARP frame even if the header had said so -- the search, diff --git a/crates/ec-av1/src/encode/tests.rs b/crates/ec-av1/src/encode/tests.rs index 9e7249e2..c11e69c9 100644 --- a/crates/ec-av1/src/encode/tests.rs +++ b/crates/ec-av1/src/encode/tests.rs @@ -1,26 +1,4 @@ -/// Every (site, frame type, block side) the census can be called with -/// lands in its own ten-counter bucket, inside the array (class -/// `enumerate-table-domain`: an off-by-one here would silently add two -/// sites' trials together). -#[test] -fn the_split_census_buckets_are_distinct_and_in_bounds() { - let mut seen = std::collections::BTreeSet::new(); - for site in 0..2 { - for key in [true, false] { - for side in [8usize, 16, 32, 64] { - let base = super::split_census_base(site, key, side); - assert!( - base + 10 <= super::SPLIT_CENSUS.len(), - "{site} {key} {side}" - ); - assert!(seen.insert(base), "{site} {key} {side} collides"); - } - } - } - assert_eq!(seen.len(), 16); -} - /// An [`crate::mvstack::MvStack`] with every context at zero and no /// neighbours, for the pricer tests below to fill the one band each of /// them is about. diff --git a/crates/ec-av1/src/probe.rs b/crates/ec-av1/src/probe.rs index 9cd42902..4fc2a6ec 100644 --- a/crates/ec-av1/src/probe.rs +++ b/crates/ec-av1/src/probe.rs @@ -12,47 +12,6 @@ use crate::encode::Picture; #[cfg(test)] use std::process::Command; -/// The video stream's coded size, from ffprobe. -#[must_use] -pub fn dims(clip: &str) -> Option<(usize, usize)> { - let out = ec_testkit::ffprobe() - .args(["-v", "error", "-select_streams", "v:0"]) - .args(["-show_entries", "stream=width,height", "-of", "csv=p=0"]) - .arg(clip) - .output() - .ok()?; - let text = String::from_utf8_lossy(&out.stdout); - let mut f = text.trim().split(','); - Some(( - f.next()?.trim().parse().ok()?, - f.next()?.trim().parse().ok()?, - )) -} - -/// The native BD gate's window on `clip`: a whole number of 128-wide -/// superblocks, at most 1920x1024, out of the MIDDLE of the coded frame, with -/// even offsets for 4:2:0 -- as an ffmpeg `crop` filter plus its size. -/// -/// This lives here because the probe used to be handed the crop by hand, and -/// a hand-written `crop=1920:1024:960:568` (a 2160-high frame that film B, -/// coded 3840x1608, is not) put the instrument on different pixels than the -/// gate: 60 kB where the gate's own q=150 point coded 90 kB. -/// -/// # Panics -/// When ffprobe cannot read the size, or the frame is under one superblock. -#[must_use] -pub fn gate_crop(clip: &str) -> (String, usize, usize) { - let (nw, nh) = dims(clip).expect("ffprobe gave no size"); - let cw = nw.min(1920) / 128 * 128; - let ch = nh.min(1024) / 128 * 128; - assert!( - cw >= 128 && ch >= 128, - "{nw}x{nh} is smaller than a superblock" - ); - let (x, y) = (((nw - cw) / 2) & !1, ((nh - ch) / 2) & !1); - (format!("crop={cw}:{ch}:{x}:{y}"), cw, ch) -} - /// `frames` pictures of `clip` from `skip` through the filter chain `vf`, as /// planar 8-bit 4:2:0 at `width`x`height` -- the BD gate's loader recipe. ///