forge
Explore
Log in

Don't you dare go Hollow

gate(av1): real-aomenc delta_q/delta_lf gate, both halves proven live

Browse files at this commit

93b89f55ea39d5de34fc629b91387861f85bc0daAhmet Kaan GümüşParent: a0f5562
r5 ported maybe_read_delta_q/maybe_read_delta_lf and removed the
whole-frame refusal on nothing but code-vs-spec review -- no fixture
anywhere set delta_lf_present, so the removal was an unproven claim.

a_real_aomenc_stream_with_delta_q_and_delta_lf_decodes_pixel_exact:
--deltaq-mode=2 (DELTA_Q_PERCEPTUAL) sets delta_q_present_flag
unconditionally once base_qindex>0, sidestepping the default
--deltaq-mode=1 (DELTA_Q_OBJECTIVE)'s extra alt-ref-eligibility/RD
gating (checked against libaom encodeframe.c:2192-2225, not assumed);
--delta-lf-mode=1 ANDs delta_lf_present_flag on top
(av1_cx_iface.c:1269-1270). 128x64 (2 SBs) gives the per-superblock
symbol somewhere to differ; --cpu-used=4 sidesteps the multi-SB
HORZ_4/VERT_B-at-part64 gap the cdef gate's comment already documents.
40/40 attempts: pixel-exact vs ffmpeg, delta_q_hits=1920,
delta_lf_hits=1920, both hard-asserted >0.

Noted but not gate-provable: libaom hardcodes delta_lf_multi =
DEFAULT_DELTA_LF_MULTI == 0 (enums.h:73) with no CLI flag to set it,
so this gate cannot and does not claim to exercise the decoder's
delta_lf_multi (4-plane) branch -- only the single-plane path is
gate-proven by a real stream.

cargo test -p ec-av1 --lib: 243 passed, 0 failed, 17 ignored.
crates/ec-av1/src/stream.rsmodified+202 -0
@@ -6358,4 +6358,206 @@ mod tests {
6358 "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20"6358 "{NAME}: {matched} pixel-exact matches, {named_refusals} named refusals out of 20"
6359 );6359 );
6360 }6360 }
6361+
6362+ /// lane-realworld r6: r5 ported `maybe_read_delta_q`/`maybe_read_delta_lf`
6363+ /// and removed the whole-frame refusal, but no fixture anywhere set
6364+ /// `delta_lf_present` -- the removal was unproven. `--deltaq-mode=2`
6365+ /// (`DELTA_Q_PERCEPTUAL`, checked against libaom's own
6366+ /// `encodeframe.c:2192-2225`) sets `delta_q_present_flag` unconditionally
6367+ /// once `base_qindex > 0` (unlike the default `--deltaq-mode=1`
6368+ /// `DELTA_Q_OBJECTIVE`, which additionally requires an alt-ref-eligible
6369+ /// frame and `allow_deltaq_mode`'s own RD search); `--delta-lf-mode=1`
6370+ /// then ANDs `delta_lf_present_flag` on top
6371+ /// (`tool_cfg->enable_deltalf_mode`, `av1_cx_iface.c:1269-1270`). 128x64
6372+ /// (2 SBs; this decoder hardcodes 64px SBs) is the charter's minimum for
6373+ /// a per-superblock symbol to have somewhere to differ; `--cpu-used=4`
6374+ /// (not the other gates' `=0`) sidesteps the multi-SB
6375+ /// HORZ_4/VERT_B-at-part64 gap the cdef gate's own comment documents
6376+ /// (lane-realworld r2 dead-end, part64 only covers NONE/SPLIT). Note:
6377+ /// libaom hardcodes `delta_lf_multi = DEFAULT_DELTA_LF_MULTI == 0`
6378+ /// (`enums.h:73`) with no CLI flag to set it -- this gate cannot and
6379+ /// does not claim to exercise this decoder's `delta_lf_multi` branch;
6380+ /// only the single-plane path is gate-proven.
6381+ #[test]
6382+ fn a_real_aomenc_stream_with_delta_q_and_delta_lf_decodes_pixel_exact() {
6383+ const NAME: &str = "a_real_aomenc_stream_with_delta_q_and_delta_lf_decodes_pixel_exact";
6384+ let _gate_lock = lock_gate_counters();
6385+ if !have_ffmpeg() {
6386+ eprintln!("SKIP {NAME}: no ffmpeg");
6387+ return;
6388+ }
6389+ if !have_aomenc() {
6390+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
6391+ return;
6392+ }
6393+ let (width, height, frame_count) = (128usize, 64usize, 24usize);
6394+ let mut named_refusals = 0u32;
6395+ let mut matched = 0u32;
6396+ let n_attempts: u32 = std::env::var("EC_DELTAQ_GATE_ATTEMPTS")
6397+ .ok()
6398+ .and_then(|s| s.parse().ok())
6399+ .unwrap_or(40);
6400+ for attempt in 0..n_attempts {
6401+ let seed = 42 + attempt;
6402+ let duration = frame_count as f64 / 25.0;
6403+ // Mandelbrot's varying local contrast is what gives
6404+ // DELTA_Q_PERCEPTUAL's per-superblock RD something to
6405+ // differentiate; flat gradients risk every superblock
6406+ // resolving the same delta.
6407+ let source = format!(
6408+ "mandelbrot=size={width}x{height}:rate=25:start_x={sx}:start_y={sy}",
6409+ sx = -0.6 + 0.005 * (attempt as f64),
6410+ sy = -0.4 + 0.005 * (attempt as f64)
6411+ );
6412+ let y4m = Command::new("ffmpeg")
6413+ .args([
6414+ "-v",
6415+ "error",
6416+ "-f",
6417+ "lavfi",
6418+ "-i",
6419+ &source,
6420+ "-t",
6421+ &duration.to_string(),
6422+ "-pix_fmt",
6423+ "yuv420p",
6424+ "-f",
6425+ "yuv4mpegpipe",
6426+ "-",
6427+ ])
6428+ .stdin(Stdio::null())
6429+ .stdout(Stdio::piped())
6430+ .stderr(Stdio::piped())
6431+ .output()
6432+ .expect("ffmpeg failed to run");
6433+ assert!(
6434+ y4m.status.success(),
6435+ "ffmpeg fixture: {}",
6436+ String::from_utf8_lossy(&y4m.stderr)
6437+ );
6438+ let args: Vec<&str> = vec![
6439+ "--codec=av1",
6440+ "--passes=1",
6441+ "--end-usage=q",
6442+ "--cq-level=45",
6443+ "--cpu-used=4",
6444+ "--aq-mode=0",
6445+ "--deltaq-mode=2",
6446+ "--delta-lf-mode=1",
6447+ "--kf-max-dist=1000",
6448+ "--threads=1",
6449+ "--row-mt=0",
6450+ "--sb-size=64",
6451+ "--auto-alt-ref=1",
6452+ "--lag-in-frames=16",
6453+ "--enable-fwd-kf=0",
6454+ "--enable-order-hint=1",
6455+ "--enable-warped-motion=1",
6456+ "--enable-global-motion=0",
6457+ "--enable-obmc=1",
6458+ "--tune-content=default",
6459+ "--enable-masked-comp=1",
6460+ "--enable-dist-wtd-comp=0",
6461+ "--enable-interintra-comp=1",
6462+ "--enable-onesided-comp=0",
6463+ "--enable-interintra-wedge=0",
6464+ "--enable-smooth-interintra=1",
6465+ "--enable-rect-partitions=0",
6466+ "--enable-ab-partitions=0",
6467+ "--enable-1to4-partitions=0",
6468+ "--enable-filter-intra=0",
6469+ "--enable-smooth-intra=0",
6470+ "--enable-paeth-intra=0",
6471+ "--enable-directional-intra=0",
6472+ "--enable-angle-delta=0",
6473+ "--enable-tx-size-search=0",
6474+ "--enable-cdef=1",
6475+ "--enable-restoration=0",
6476+ "--max-partition-size=32",
6477+ "--min-partition-size=32",
6478+ "--enable-palette=0",
6479+ "--enable-intrabc=0",
6480+ "--enable-cfl-intra=0",
6481+ "--enable-ref-frame-mvs=0",
6482+ "--obu",
6483+ "-o",
6484+ "-",
6485+ "-",
6486+ ];
6487+ let mut child = Command::new(aomenc_path())
6488+ .args(&args)
6489+ .stdin(Stdio::piped())
6490+ .stdout(Stdio::piped())
6491+ .stderr(Stdio::piped())
6492+ .spawn()
6493+ .expect("aomenc failed to start");
6494+ child
6495+ .stdin
6496+ .take()
6497+ .expect("aomenc stdin")
6498+ .write_all(&y4m.stdout)
6499+ .expect("writing y4m to aomenc");
6500+ let out = child.wait_with_output().expect("aomenc failed to run");
6501+ assert!(
6502+ out.status.success(),
6503+ "aomenc refused the fixture: {}",
6504+ String::from_utf8_lossy(&out.stderr)
6505+ );
6506+ let stream = out.stdout;
6507+ let frames = match decode_stream(&stream) {
6508+ Err(e) => {
6509+ let msg = e.to_string();
6510+ assert!(
6511+ msg.contains("unsupported"),
6512+ "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
6513+ );
6514+ assert!(
6515+ !msg.contains("delta_q") && !msg.contains("delta_lf"),
6516+ "{NAME} refused on delta_q/delta_lf (seed {seed}) -- that read is ported: {msg}"
6517+ );
6518+ named_refusals += 1;
6519+ eprintln!("seed {seed} refusal: {msg}");
6520+ continue;
6521+ }
6522+ Ok(frames) => frames,
6523+ };
6524+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
6525+ assert_eq!(frames.len(), frame_count);
6526+ let mismatched = frames
6527+ .iter()
6528+ .zip(&ffmpeg_frames)
6529+ .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
6530+ if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
6531+ std::fs::write(&path, &stream).expect("writing pinned stream");
6532+ eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
6533+ }
6534+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
6535+ assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})");
6536+ assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
6537+ assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
6538+ }
6539+ matched += 1;
6540+ }
6541+ assert!(
6542+ matched > 0,
6543+ "{NAME}: every attempt refused on other capabilities ({named_refusals} refusals); \
6544+ the gate never exercised delta_q/delta_lf"
6545+ );
6546+ assert!(
6547+ crate::decode::delta_q_hits() > 0,
6548+ "{NAME}: {matched} pixel-exact matches but zero delta_q symbol groups fired -- \
6549+ the reader is unexercised"
6550+ );
6551+ assert!(
6552+ crate::decode::delta_lf_hits() > 0,
6553+ "{NAME}: {matched} pixel-exact matches but zero delta_lf symbol groups fired -- \
6554+ the reader is unexercised"
6555+ );
6556+ eprintln!(
6557+ "{NAME}: {named_refusals} other-capability refusals, {matched} pixel-exact matches \
6558+ out of {n_attempts}, delta_q_hits={}, delta_lf_hits={}",
6559+ crate::decode::delta_q_hits(),
6560+ crate::decode::delta_lf_hits()
6561+ );
6562+ }
6361 }6563 }