forge
Explore
Log in

Don't you dare go Hollow

debug(av1): r9 falsifies hypothesis A and rules out qmatrix/delta_q/segmentation

Browse files at this commit

120854a398c719ca7b7e08da4e4d9deb925e7375Ahmet Kaan GümüşParent: fc77857
Task 1 (frame inventory): manual byte-level OBU parse of pin_cfl.obu (77
bytes total) shows exactly TD(size 0) + SEQUENCE_HEADER(size 10) +
one OBU_FRAME(type 6, size 61) to EOF -- no second frame OBU, no
show_existing_frame, nothing hidden. ffprobe/ffmpeg (libdav1d) also read
exactly 1 frame from the file. decode_stream returns 1 Picture; the test
compares frames[0] against ffmpeg_frames[0], the same single frame both
decoders parsed. Hypothesis A (ffmpeg showing a different frame) is
FALSIFIED for this fixture -- three independent confirmations (manual OBU
byte parse, ffprobe frame count, our own frame count) agree on
single-frame-single-shown.

Task 2 (reconstruction diff), new evidence this round: added
EC_AV1_TRACE prints for quantization/segmentation/delta params to
scratch_isolate_pinned_mismatch (stream.rs) and confirmed for pin_cfl.obu:
using_qmatrix=false, delta_q_y_dc=0 and delta.q_present=false,
segmentation.enabled=false, coded_lossless=false, tx_mode=Largest -- so
none of those alternate-quantization paths (which decode.rs does not
implement) are actually exercised by this stream; ruling them out removes
several live hypotheses for the amplitude gap rather than leaving them
open.

Independently verified the transform math itself: for the block's proven
levels ((0,0)=-2,(0,1)=-2,(0,2)=-2, dc_sign negative), dequant at
base_q_idx=60 gives [-57,-67,-67], and BOTH a from-scratch scipy
`idctn(norm='ortho')` computation and this crate's own
`dequant_and_inverse` agree the resulting residual is [-2,-2,-2,-2,-2,-1,
-1,-1,-1,-1,0,...,0] across the row -- i.e. our transform pipeline is
mathematically self-consistent and correct *given* those coefficients.
That residual added to DC_PRED=128 reconstructs to ~126, which is what
this decoder outputs; ffmpeg's real decode of the identical bytes is a
smooth 41-82 diagonal gradient that cannot come from this residual under
any correct reconstruction. So the remaining gap is neither hypothesis A
(ruled out above) nor a transform/dequant bug (ruled out here) -- it must
be a symbol read upstream of the proven-clean coefficient values
(partition_w32, most likely: a single 32x32 PARTITION_NONE forces the
whole frame through one DC_PRED block, while a wrong partition context
table could silently produce the same "coefficients bit-exact for the
symbols we read" result while reading the wrong symbol in the first
place). r10: re-derive partition_w32's CDF/context table from
entropymode.c independently of both this crate's and r8's prior Python
cross-check (which may share the same transcription error), and try
forcing a SPLIT decode of this exact stream to see whether a 4-subblock
reconstruction (each with its own propagated DC neighbour) produces
ffmpeg's smooth gradient shape.

Left the EC_AV1_TRACE prints (quantization/delta/segmentation/lossless)
in scratch_isolate_pinned_mismatch and a new #[ignore]d
scratch_probe_32x32_dequant in transform.rs documenting the independent
math check -- both scratch/debug-only, gated behind #[ignore] or env
vars, no behavior change. cargo test -p ec-av1 --release: 164 passed, 0
failed, 13 ignored.
crates/ec-av1/src/stream.rsmodified+7 -0
@@ -560,6 +560,13 @@ mod tests {
560560 pos += obu.total_size;
561561 if let ObuKind::Frame(header, _) = obu.kind {
562562 eprintln!("cdef: {:?}", header.cdef);
563+ eprintln!("quantization: {:?}", header.quantization);
564+ eprintln!(
565+ "coded_lossless: {:?} tx_mode: {:?}",
566+ header.coded_lossless, header.tx_mode
567+ );
568+ eprintln!("delta: {:?}", header.delta);
569+ eprintln!("segmentation: {:?}", header.segmentation);
563570 }
564571 }
565572 }
crates/ec-av1/src/transform.rsmodified+35 -0
@@ -1050,6 +1050,41 @@ mod tests {
10501050 .collect()
10511051 }
10521052
1053+ #[test]
1054+ #[ignore]
1055+ fn scratch_probe_32x32_dequant() {
1056+ let mut levels = vec![0i32; 32 * 32];
1057+ levels[0] = -2;
1058+ levels[1] = -2;
1059+ levels[2] = -2;
1060+ let dq = crate::quant::dequant(&levels, 32, 8, 60);
1061+ eprintln!("dq[0..4]={:?}", &dq[0..4]);
1062+ let residual = dequant_and_inverse(&levels, 32, 8, 60);
1063+ eprintln!("row0: {:?}", &residual[0..32]);
1064+ eprintln!("row1: {:?}", &residual[32..64]);
1065+
1066+ // superposition probe: does inverse_transform_2d at side=32 sum
1067+ // three simultaneous low-frequency coefficients the same as it
1068+ // reconstructs each alone?
1069+ let side = 32usize;
1070+ let mut single_sum = vec![0i32; side * side];
1071+ for &(pos, val) in &[(0usize, -57i32), (1, -67), (2, -67)] {
1072+ let mut c = vec![0i32; side * side];
1073+ c[pos] = val;
1074+ let got = inverse_transform_2d(&c, side, 8);
1075+ for i in 0..side * side {
1076+ single_sum[i] += got[i];
1077+ }
1078+ }
1079+ let mut combined = vec![0i32; side * side];
1080+ combined[0] = -57;
1081+ combined[1] = -67;
1082+ combined[2] = -67;
1083+ let got_combined = inverse_transform_2d(&combined, side, 8);
1084+ eprintln!("single_sum row0: {:?}", &single_sum[0..8]);
1085+ eprintln!("combined row0: {:?}", &got_combined[0..8]);
1086+ }
1087+
10531088 fn rmse(a: &[i32], b: &[i32]) -> f64 {
10541089 let sum: f64 = a
10551090 .iter()