diff --git a/crates/ec-av1/fixtures/reelb_head_key_frame.obu b/crates/ec-av1/fixtures/reelb_head_key_frame.obu new file mode 100644 index 0000000000000000000000000000000000000000..ecc409b000d6550743e1c768e075b23186e41c08 GIT binary patch literal 147 zcmV;E0Brvf016KP003g^zw$Zv^PwUEDS#>l0R!g%dVne#0_gYEq$Xw$Tu=>E zIRFFb000000)R4F5CDe&fB*mh03grHo2NmWeoqO5rDriCF8GQw;s}Qn { - dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE)); + if dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], VERT_ALIKE)) == 1 { + PARTITION_SPLIT + } else { + PARTITION_HORZ + } } (false, true) => { - dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE)); + if dec.symbol_fixed(&gather(&cdfs.partition_w64[ctx], HORZ_ALIKE)) == 1 { + PARTITION_SPLIT + } else { + PARTITION_VERT + } } - _ => {} + _ => PARTITION_SPLIT, } - PARTITION_SPLIT }; match part { PARTITION_NONE => { @@ -10279,20 +10294,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( } else { match (has_cols32, has_rows32) { (true, false) => { - dec.symbol_fixed(&gather( - &cdfs.partition_w32[ctx32], - VERT_ALIKE, - )); + // lane-golomb r1 (class `parsed-then-discarded`): the gathered + // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT + // (libaom `ec_read_partition_impl`). + if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE)) == 1 { + PARTITION_SPLIT + } else { + PARTITION_HORZ + } } (false, true) => { - dec.symbol_fixed(&gather( - &cdfs.partition_w32[ctx32], - HORZ_ALIKE, - )); + // lane-golomb r1 (class `parsed-then-discarded`): the gathered + // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT + // (libaom `ec_read_partition_impl`). + if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], HORZ_ALIKE)) == 1 { + PARTITION_SPLIT + } else { + PARTITION_VERT + } } - _ => {} + _ => PARTITION_SPLIT, } - PARTITION_SPLIT }; match part32 { PARTITION_NONE => { @@ -10710,15 +10732,29 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( does not code yet", )); } - if has_cols16 { + // lane-golomb r1 (class + // `parsed-then-discarded`): the gathered + // bit IS the partition -- 0 names + // PARTITION_HORZ (resp. VERT), only 1 is + // SPLIT (libaom `ec_read_partition_impl`). + // This path can only walk the four SPLIT + // leaves, so a 0 refuses by name instead + // of desyncing. + let edge_split = if has_cols16 { dec.symbol_fixed(&gather( &cdfs.partition_w16[ctx16], VERT_ALIKE, - )); + )) } else { dec.symbol_fixed(&gather( &cdfs.partition_w16[ctx16], HORZ_ALIKE, + )) + }; + if edge_split == 0 { + return Err(unsupported( + "a 16x16 block at the true frame edge coded as a \ + rect strip rather than SPLIT", )); } let (mi_row0, mi_col0) = @@ -11269,22 +11305,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( tx_select, reduced_tx_set, )?; - decode_block_rect64( - &mut dec, - &mut cdfs, - &mut neighbours, - (at.0 + 2, at.1), - 64, - 32, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - reduced_tx_set, - )?; + // lane-golomb r1: at the frame edge only the first half of the + // strip is coded (libaom `decode_partition` guards the second + // with the same has_rows test that made this partition non-square). + if has_rows { + decode_block_rect64( + &mut dec, + &mut cdfs, + &mut neighbours, + (at.0 + 2, at.1), + 64, + 32, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + reduced_tx_set, + )?; + } } PARTITION_VERT => { // lane-sbpart r2: mirror of PARTITION_HORZ above with @@ -11305,22 +11346,27 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( tx_select, reduced_tx_set, )?; - decode_block_rect64( - &mut dec, - &mut cdfs, - &mut neighbours, - (at.0, at.1 + 2), - 32, - 64, - &mut y, - &mut u, - &mut v, - enable_filter_intra, - allow_screen_content_tools, - base_q_idx, - tx_select, - reduced_tx_set, - )?; + // lane-golomb r1: at the frame edge only the first half of the + // strip is coded (libaom `decode_partition` guards the second + // with the same has_cols test that made this partition non-square). + if has_cols { + decode_block_rect64( + &mut dec, + &mut cdfs, + &mut neighbours, + (at.0, at.1 + 2), + 32, + 64, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + reduced_tx_set, + )?; + } } PARTITION_HORZ_A | PARTITION_HORZ_B | PARTITION_VERT_A | PARTITION_VERT_B => { // lane-part32 r4: the four superblock-level AB arms, each @@ -17161,12 +17207,24 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( p } (true, false) => { - dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)); - PARTITION_SPLIT + // lane-golomb r1 (class `parsed-then-discarded`): the gathered + // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT + // (libaom `ec_read_partition_impl`). + if dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)) == 1 { + PARTITION_SPLIT + } else { + PARTITION_HORZ + } } (false, true) => { - dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE)); - PARTITION_SPLIT + // lane-golomb r1 (class `parsed-then-discarded`): the gathered + // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT + // (libaom `ec_read_partition_impl`). + if dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], HORZ_ALIKE)) == 1 { + PARTITION_SPLIT + } else { + PARTITION_VERT + } } (false, false) => PARTITION_SPLIT, }; @@ -17271,14 +17329,27 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( } else { match (has_cols32, has_rows32) { (true, false) => { - dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE)); + // lane-golomb r1 (class `parsed-then-discarded`): the gathered + // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT + // (libaom `ec_read_partition_impl`). + if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE)) == 1 { + PARTITION_SPLIT + } else { + PARTITION_HORZ + } } (false, true) => { - dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], HORZ_ALIKE)); + // lane-golomb r1 (class `parsed-then-discarded`): the gathered + // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT + // (libaom `ec_read_partition_impl`). + if dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], HORZ_ALIKE)) == 1 { + PARTITION_SPLIT + } else { + PARTITION_VERT + } } - _ => {} + _ => PARTITION_SPLIT, } - PARTITION_SPLIT }; match part32 { PARTITION_NONE => { @@ -17370,17 +17441,24 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( p } else { if has_cols16 { - dec.symbol_fixed(&gather( - &cdfs.partition_w16[ctx16], - VERT_ALIKE, - )); + // lane-golomb r1 (class `parsed-then-discarded`): the gathered + // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT + // (libaom `ec_read_partition_impl`). + if dec.symbol_fixed(&gather(&cdfs.partition_w16[ctx16], VERT_ALIKE)) == 1 { + PARTITION_SPLIT + } else { + PARTITION_HORZ + } } else { - dec.symbol_fixed(&gather( - &cdfs.partition_w16[ctx16], - HORZ_ALIKE, - )); + // lane-golomb r1 (class `parsed-then-discarded`): the gathered + // bit IS the partition -- 0 means PARTITION_VERT, only 1 means SPLIT + // (libaom `ec_read_partition_impl`). + if dec.symbol_fixed(&gather(&cdfs.partition_w16[ctx16], HORZ_ALIKE)) == 1 { + PARTITION_SPLIT + } else { + PARTITION_VERT + } } - PARTITION_SPLIT }; if part16 == PARTITION_NONE { decode_inter_block( diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 3386c1b4..8fa47620 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -37,6 +37,7 @@ const REFUSALS: &[&str] = &[ "a HORZ_A/HORZ_B/VERT_A partition below 16x16 (this decoder codes only the square arms, HORZ, VERT, VERT_B, and a clean split below 16x16)", "an inter partition below 8x8 (this decoder codes no inter leaf smaller than 8x8; lane-sub8 scoped to intra)", "a 16x16 block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", + "a 16x16 block at the true frame edge coded as a rect strip rather than SPLIT", "a 16x16 inter block whose true edge cuts through both axes needs a rectangular transform this decoder does not code yet", "a 32x32 partition type this decoder does not code (value={part32})", "a 32x32-level 1:4 strip with a split transform (per-unit 4:1 prediction is not ported, depth={depth})", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 8facc864..c673d91a 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -2671,6 +2671,41 @@ mod tests { eprintln!("{NAME}: pixel-exact, grain_hits={}", crate::film_grain::grain_hits()); } + /// lane-golomb r1: THE FILM ITSELF. `crates/ec-av1/fixtures/reelb_head_key_frame.obu` + /// is the first frame of the user's ReelB AV1 release (3840x1608 + /// yuv420p10le, `ffmpeg -i -c copy -frames:v 1 -f obu`, 147 bytes) -- + /// a real 10-bit key frame whose height is NOT a multiple of the 64-pixel + /// superblock, so its last superblock row (mi_row=400 of 402) carries the + /// edge partition symbol this lane fixed: libaom's `ec_read_partition_impl` + /// returns `PARTITION_HORZ` when the gathered `split_or_horz` bit is 0, and + /// this decoder used to READ that bit and throw it away, forcing SPLIT + /// (class `parsed-then-discarded`). The desync surfaced two rows later as + /// "a Golomb tail longer than this decoder reads" -- a refusal naming the + /// symptom, never the cause. + #[test] + fn the_reelb_head_key_frame_decodes_pixel_exact() { + const NAME: &str = "the_reelb_head_key_frame_decodes_pixel_exact"; + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) + .join("fixtures/reelb_head_key_frame.obu"); + let stream = std::fs::read(&path) + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); + let (width, height) = (3840usize, 1608usize); + let frames = match decode_stream(&stream) { + Ok(frames) => frames, + Err(e) => panic!("{NAME}: decode_stream refused: {e}"), + }; + assert_eq!(frames.len(), 1, "{NAME}: one key frame"); + assert_eq!((frames[0].width, frames[0].height), (width, height)); + let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, width, height, 1); + assert_eq!(frames[0].y, ffmpeg_frames[0].y, "{NAME}: luma vs ffmpeg"); + assert_eq!(frames[0].u, ffmpeg_frames[0].u, "{NAME}: U vs ffmpeg"); + assert_eq!(frames[0].v, ffmpeg_frames[0].v, "{NAME}: V vs ffmpeg"); + } + /// lane-hbd10 r1: a real `aomenc --bit-depth=10 --superres-mode=1 /// --superres-denominator=12` key frame, decoded pixel-exact against /// ffmpeg's own 10-bit decode. Proves `superres::upscale_row`'s diff --git a/lanes/golomb-r1.report.md b/lanes/golomb-r1.report.md new file mode 100644 index 00000000..484257cb --- /dev/null +++ b/lanes/golomb-r1.report.md @@ -0,0 +1,47 @@ +# lane-golomb r1 — the edge partition bit was read and thrown away + +## Verdict +The "a Golomb tail longer than this decoder reads" refusal on the ReelB head was, as +suspected (`refusal-from-own-desync`), a symptom. Root cause: at a frame edge the partition +symbol is a single *gathered* bit, and this decoder read it and **discarded** it, always +inferring `PARTITION_SPLIT`. libaom `ec_read_partition_impl` (decodeframe.c:1255): +`!has_rows && has_cols` → `read ? PARTITION_SPLIT : PARTITION_HORZ`; the mirror case → +`PARTITION_VERT`. Class: `parsed-then-discarded`. + +Charter STEP-2 fallback ("libaom read_golomb caps at 32 bits, extend the reader") is FALSE: +`~/.cache/aom-oracle/src/av1/decoder/decodetxb.c:22` aborts the frame at `length > 20`, exactly +our cap. The cap was never the bug and is unchanged. + +## First divergent element (EVIDENCE) +EVIDENCE: /tmp/.../scratchpad/{ao-all.txt,ours-all.txt} | instrumented aomdec vs decode_probe, +EC_TRACE_MODE+EC_TRACE_MODE_STEP+EC_TRACE_COEFF on the 2-frame extract f2.obu, ladders aligned +element by element on msac RANGE | first diff at element 12053: key frame, **mi_row=400 +mi_col=0** (last, 8-pixel-tall superblock row of a 1608-tall frame), `name=skip` +oracle rng=34753 vs ours rng=43258. Oracle codes that superblock as one `BLOCK_64X32` +(`EC_IMODE ... bsize=11`, PARTITION_HORZ); we forced SPLIT and descended to 16x16. +After the fix the range ladder is element-exact for all 13712 shared elements of the key frame +(EVIDENCE: /tmp/.../scratchpad/{a4.n,o4.n} | awk first-diff | idx 13713, inside a later INTER +frame, i.e. past the whole key frame). + +## Fix +`crates/ec-av1/src/decode.rs` — every edge-partition site, both tile paths, all three levels +(64/32/16, intra and inter): the gathered bit now names HORZ/VERT vs SPLIT. The 64-level +HORZ/VERT arms only decode the second half when it is inside the frame (`has_rows`/`has_cols`), +mirroring libaom `decode_partition`. The intra 16x16 edge site can only walk four SPLIT leaves, +so a 0 bit refuses by name there (new string, listed in `refusal_inventory.rs`) instead of +desyncing. + +## Gates +- NEW `stream::tests::the_reelb_head_key_frame_decodes_pixel_exact` — the film itself: + `crates/ec-av1/fixtures/reelb_head_key_frame.obu` (147 B, first frame of his 3840x1608 + yuv420p10le release) decodes and matches `ffmpeg -pix_fmt yuv420p10le` on Y, U and V. + EVIDENCE: cargo test -p ec-av1 --lib -- the_reelb_head_key_frame | 1 passed | + Y/U/V all equal to ffmpeg's decode, 3840x1608. +- Full lib suite: `$HOME/.cache/golomb-suite.log` — **337 passed / 0 failed / 31 ignored**. + +## Film probes after the fix +- `hg-head.obu` (18 frames): key frame + first inter frames now entropy-exact; stops at + "an inter SB-level partition type other than NONE or SPLIT" — the same edge partition, now + correctly decoded as HORZ, on an INTER superblock row the inter path cannot code (rect inter + residual coding does not exist here). Next lane. +- `reelb5.obu`: "a 32x32-level 1:4 strip with a split transform (depth=2)" (unchanged by this lane).