forge
Explore
Log in

Don't you dare go Hollow

debug(av1): r8 clears tile-offset and mode_info as the pinned CfL stream's bug

Browse files at this commit

fc77857b528702167c06a8933627f3c64c5bc9ebAhmet Kaan GümüşParent: 222de20
Independent from-spec OBU/frame-header parse in Python derives the tile
group's start at byte 23 (obu_header -> leb128 -> full sequence_header ->
full uncompressed_header bit-by-bit); EC_AV1_TRACE's new key_tile_bytes
line proves decode_stream's obu_offset + tile.offset feeds decode_key_frame_tile
that same byte 23, and r7's python literal agrees -- three-way match.

Extended EC_AV1_TRACE to partition/skip/y_mode/uv_mode (decode.rs
read_intra_mode + both partition sites) and cross-checked against an
independent Python MSAC decoder whose partition_w32/kf_y_mode/uv_mode_cfl
CDF literals this round re-verified byte-for-byte against
/tmp/libaom-src/av1/common/entropymode.c (not inherited from a prior
round): partition=NONE, skip=0, y_mode=DC_PRED, uv_mode=DC_PRED, matching
ours exactly. Both r8 hypotheses from r7's handoff are falsified -- the
bitstream genuinely codes DC_PRED with a near-zero residual for this
block, and our decode of that is bit-exact. ffmpeg's real output (a
smooth diagonal gradient) cannot come from that symbol sequence under any
correct DC_PRED reconstruction, so the desync is downstream of symbol
decode entirely: intra prediction or the inverse-transform/dequant path.
Traces kept (not fixed yet); ignore reason on the pinned CFL test points
r9 at crate::intra::predict and dequant_and_inverse_typed.
crates/ec-av1/src/decode.rsmodified+33 -4
@@ -564,11 +564,22 @@ fn read_intra_mode(
564 left_mode: usize,564 left_mode: usize,
565 cfl: bool,565 cfl: bool,
566 ) -> Result<(bool, usize, Option<(i32, i32)>)> {566 ) -> Result<(bool, usize, Option<(i32, i32)>)> {
567+ let trace = std::env::var_os("EC_AV1_TRACE").is_some();
567 let skip = dec.symbol(&mut cdfs.skip[0]) != 0;568 let skip = dec.symbol(&mut cdfs.skip[0]) != 0;
568- let mode =569+ if trace {
569- dec.symbol(&mut cdfs.kf_y_mode[INTRA_MODE_CTX[above_mode]][INTRA_MODE_CTX[left_mode]]);570+ eprintln!("TRACE skip value={}", skip as i32);
571+ }
572+ let above_ctx = INTRA_MODE_CTX[above_mode];
573+ let left_ctx = INTRA_MODE_CTX[left_mode];
574+ let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]);
575+ if trace {
576+ eprintln!("TRACE y_mode ctx=({above_ctx},{left_ctx}) value={mode}");
577+ }
570 if (V_PRED..=D67_PRED).contains(&mode) {578 if (V_PRED..=D67_PRED).contains(&mode) {
571 let angle = dec.symbol(&mut cdfs.angle_delta[mode - V_PRED]);579 let angle = dec.symbol(&mut cdfs.angle_delta[mode - V_PRED]);
580+ if trace {
581+ eprintln!("TRACE angle_delta value={angle}");
582+ }
572 if angle != ANGLE_DELTA_ZERO {583 if angle != ANGLE_DELTA_ZERO {
573 return Err(unsupported(584 return Err(unsupported(
574 "a nonzero angle delta (this encoder never writes one)",585 "a nonzero angle delta (this encoder never writes one)",
@@ -580,6 +591,9 @@ fn read_intra_mode(
580 } else {591 } else {
581 dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])592 dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])
582 };593 };
594+ if trace {
595+ eprintln!("TRACE uv_mode cfl={cfl} y_mode={mode} value={uv_mode}");
596+ }
583 let alpha = if uv_mode == DC_PRED {597 let alpha = if uv_mode == DC_PRED {
584 None598 None
585 } else if cfl && uv_mode == UV_CFL_PRED {599 } else if cfl && uv_mode == UV_CFL_PRED {
@@ -1119,6 +1133,13 @@ pub fn decode_key_frame_tile(
1119 let scan4 = default_scan(TX4);1133 let scan4 = default_scan(TX4);
1120 1134
1121 let mut cdfs = Cdfs::new(q_ctx_of(base_q_idx));1135 let mut cdfs = Cdfs::new(q_ctx_of(base_q_idx));
1136+ if std::env::var_os("EC_AV1_TRACE").is_some() {
1137+ eprintln!(
1138+ "TRACE key_tile_bytes len={} first8={:02x?} base_q_idx={base_q_idx} mi_cols={mi_cols} mi_rows={mi_rows}",
1139+ data.len(),
1140+ &data[..data.len().min(8)]
1141+ );
1142+ }
1122 let mut dec = SymbolDecoder::new(data);1143 let mut dec = SymbolDecoder::new(data);
1123 let mut neighbours = Neighbours::new(1144 let mut neighbours = Neighbours::new(
1124 cols32 as usize * 2,1145 cols32 as usize * 2,
@@ -1144,7 +1165,11 @@ pub fn decode_key_frame_tile(
1144 // mirroring [`crate::tile::sb_coeff_key_frame_tile`]'s own1165 // mirroring [`crate::tile::sb_coeff_key_frame_tile`]'s own
1145 // three-way write exactly.1166 // three-way write exactly.
1146 let part = if has_cols && has_rows {1167 let part = if has_cols && has_rows {
1147- dec.symbol(&mut cdfs.partition_w64[ctx])1168+ let p = dec.symbol(&mut cdfs.partition_w64[ctx]);
1169+ if std::env::var_os("EC_AV1_TRACE").is_some() {
1170+ eprintln!("TRACE partition_w64 ctx={ctx} value={p}");
1171+ }
1172+ p
1148 } else {1173 } else {
1149 match (has_cols, has_rows) {1174 match (has_cols, has_rows) {
1150 (true, false) => {1175 (true, false) => {
@@ -1190,7 +1215,11 @@ pub fn decode_key_frame_tile(
1190 has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows),1215 has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows),
1191 );1216 );
1192 let part32 = if has_cols32 && has_rows32 {1217 let part32 = if has_cols32 && has_rows32 {
1193- dec.symbol(&mut cdfs.partition_w32[ctx32])1218+ let p = dec.symbol(&mut cdfs.partition_w32[ctx32]);
1219+ if std::env::var_os("EC_AV1_TRACE").is_some() {
1220+ eprintln!("TRACE partition_w32 ctx={ctx32} value={p}");
1221+ }
1222+ p
1194 } else {1223 } else {
1195 match (has_cols32, has_rows32) {1224 match (has_cols32, has_rows32) {
1196 (true, false) => {1225 (true, false) => {
crates/ec-av1/src/stream.rsmodified+1 -1
@@ -513,7 +513,7 @@ mod tests {
513 /// decode: pixel-exact against ffmpeg's own decode, not just "decoded".513 /// decode: pixel-exact against ffmpeg's own decode, not just "decoded".
514 ///514 ///
515 #[test]515 #[test]
516- #[ignore = "r7: the symbol-level cross-check this note asked for is done and CLEARS the coefficient decode. An EC_AV1_TRACE-gated trace (decode.rs read_coeffs/read_eob) was diffed against an independent Python MSAC decoder (real libaom default CDFs pulled from token_cdfs.h, context arithmetic ported from txb_common.h's get_nz_mag/get_nz_map_ctx_from_stats/get_br_ctx -- not from this crate). Every symbol matches ours bit-for-bit through the full Luma32 base loop: eob_pt=5, eob_extra(ctx=2)=1, eob=15, base_eob(ctx=1)=1, then base ctx/value pairs 21/0,21/0,21/0,21/0,6/0,6/0,6/0,7/0,7/2,6/0,6/0,1/0,2/2,0/2, dc_sign(ctx=0)=negative -- three nonzero levels (magnitude 2 each) at raster positions 0/1/2. The scan table, CDF tables, and every context function are proven correct for this stream; r6's transposition hypothesis stays reverted and should not be revisited. Feeding those exact levels through dequant_and_inverse_typed (base_q_idx=60) gives a near-flat residual (row 0 barely varies, rows 1-31 replicate it -- correct behaviour for energy confined to row 0) landing luma at a uniform ~126 against ffmpeg's real ~50-and-varying output: three magnitude-2 coefficients cannot close a gap that size even transformed exactly right, so the desync is BEFORE this trace starts -- mode_info (partition/skip/y_mode/uv_mode) or the tile-group byte offset itself. r8: extend EC_AV1_TRACE (already added, off by default) to mode_info's own symbols and cross-check them the same way, and separately confirm the tile data's starting byte offset against the OBU/frame-header parse (ec-av1-syntax) rather than trusting a byte slice pulled from a prior round's own decoder run."]516+ #[ignore = "r8: BOTH remaining hypotheses from r7 are now falsified. (1) Tile-data byte offset: an independent from-spec OBU parse in Python (obu_header/leb128/full sequence_header/full uncompressed_header bit-by-bit) derives the tile group starting at absolute byte 23 in the pinned stream; `EC_AV1_TRACE`'s new `key_tile_bytes` line shows our own `decode_stream` (stream.rs `obu_offset + tile.offset`) feeds `decode_key_frame_tile` that exact same byte 23 (first8 04 c8 d9 35 3d a6 de 5e); the r7 python scripts' hardcoded literal agrees too -- three-way match, offset is not the bug. (2) mode_info symbols: `EC_AV1_TRACE` extended to partition/skip/y_mode/uv_mode (decode.rs read_intra_mode + the two partition sites); an independent Python MSAC decoder over the SAME CDF literals -- this round re-verified partition_w32_cdf[0], kf_y_mode_cdf[0][0] and uv_mode_cdf[cfl=1][DC_PRED] byte-for-byte against /tmp/libaom-src/av1/common/entropymode.c source, not trusted from a prior round -- reads partition=NONE, skip=0, y_mode=DC_PRED(0), uv_mode=DC_PRED(0), matching our decoder exactly. So the bitstream genuinely codes DC_PRED with a near-zero residual (three magnitude-2 AC coefficients) for this block, and our decode of that is bit-exact; ffmpeg's real output (a smooth 46..61 diagonal gradient) cannot come from that symbol sequence under any correct DC_PRED reconstruction. The desync is downstream of symbol decode entirely -- intra prediction (`crate::intra::predict`) or the inverse-transform/dequant path (`dequant_and_inverse_typed`) miscomputing the reconstructed pixels from a genuinely-correct DC_PRED + tiny-residual decode, not a wrong symbol. r9: trace/diff `crate::intra::predict`'s DC output and the post-dequant residual grid against an independent implementation of both, the same way r6-r8 did for the entropy layer."]
517 fn a_real_libaom_cfl_stream_decodes_pixel_exact() {517 fn a_real_libaom_cfl_stream_decodes_pixel_exact() {
518 if !have_ffmpeg() {518 if !have_ffmpeg() {
519 eprintln!("SKIP a_real_libaom_cfl_stream_decodes_pixel_exact: no ffmpeg");519 eprintln!("SKIP a_real_libaom_cfl_stream_decodes_pixel_exact: no ffmpeg");