diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index 92c83905..ce9a3d90 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -66,6 +66,18 @@ fn main() { } } println!("TILING: {frames_seen} frame headers parsed"); + // lane-sb128 r4: the superblock size decides the whole partition tree, so + // report it next to the tiling -- it is the first thing a film blocker + // triage needs. + if let Some(seq) = parser.sequence_header() { + println!( + "SEQ: use_128x128_superblock={} bit_depth={} max_frame={}x{}", + seq.use_128x128_superblock, + seq.color_config.bit_depth, + seq.max_frame_width, + seq.max_frame_height + ); + } for (cols, rows, uniform, ctx_id) in &seen { println!( "TILING: cols={cols} rows={rows} uniform_spacing={uniform} context_update_tile_id={ctx_id}" diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 990cdc73..16c188a1 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -88,6 +88,14 @@ pub(crate) fn sb_mi_cur() -> u32 { thread_local! { static PART128_SYMBOLS: std::cell::Cell = const { std::cell::Cell::new(0) }; static PART128_SPLIT_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + static PART128_GATHERED_SYMBOLS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of `PART128_GATHERED_SYMBOLS`: 128 roots that read the +/// half-out-of-frame gathered split_or_horz/split_or_vert symbol (spec +/// 5.11.4), which this decoder used to read and throw away. +pub(crate) fn part128_gathered_symbols() -> usize { + PART128_GATHERED_SYMBOLS.with(|c| c.get()) } /// Current value of [`PART128_SYMBOLS`]. @@ -11778,16 +11786,33 @@ fn read_sb128_root( } p } else { + // lane-sb128 r4: the gathered half-out-of-frame reads DECIDE the + // partition, they are not a forced split -- exactly the discarded-bit + // defect the 64 root carries a comment about at `partition_w64`'s + // gathered arm. Value 1 is SPLIT; 0 is HORZ (rows out of frame) or + // VERT (cols out of frame), which the refusal below then names + // instead of silently reconstructing a split. + PART128_GATHERED_SYMBOLS.with(|c| c.set(c.get() + 1)); match (has_cols128, has_rows128) { (true, false) => { - dec.symbol_fixed(&gather_of(&cdfs.partition_w128[ctx128], &VERT_ALIKE128)); + if dec.symbol_fixed(&gather_of(&cdfs.partition_w128[ctx128], &VERT_ALIKE128)) == 1 { + PARTITION_SPLIT + } else { + PARTITION_HORZ + } } (false, true) => { - dec.symbol_fixed(&gather_of(&cdfs.partition_w128[ctx128], &HORZ_ALIKE128)); + if dec.symbol_fixed(&gather_of(&cdfs.partition_w128[ctx128], &HORZ_ALIKE128)) == 1 { + PARTITION_SPLIT + } else { + PARTITION_VERT + } + } + _ => { + PART128_GATHERED_SYMBOLS.with(|c| c.set(c.get() - 1)); + PARTITION_SPLIT } - _ => {} } - PARTITION_SPLIT }; if part128 != PARTITION_SPLIT { return Err(unsupported( diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 7a094e68..0268ba13 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -1110,7 +1110,8 @@ mod tests { let mut child = Command::new(aomenc_path()) .args([ "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32", - "--cpu-used=0", "--sb-size=128", "--kf-max-dist=0", "--limit=1", + "--cpu-used=0", "--sb-size=128", "--min-partition-size=16", + "--kf-max-dist=0", "--limit=1", "--threads=1", "--row-mt=0", "--obu", "-o", "-", "-", ]) .stdin(Stdio::piped()) @@ -1141,12 +1142,25 @@ mod tests { assert!(sb128, "aomenc ignored --sb-size=128: this stream is 64x64-superblock"); let _guard = lock_gate_counters(); + let before = crate::decode::part128_symbols() + + crate::decode::part128_gathered_symbols(); let (frames, hidden) = decode_all_frames_vs_oracle(&stream, "sb128-oddh-64x72"); assert!(frames > 0, "no frames decoded for {width}x{height}"); + // The 128 root actually READ a partition symbol here: at mi_rows=18 + // `has_rows` is true, so BLOCK_128X128 is not a forced split. + let part128 = crate::decode::part128_symbols() + + crate::decode::part128_gathered_symbols() + - before; + assert!( + part128 > 0, + "{width}x{height} decoded without reading a single BLOCK_128X128 \ + partition symbol -- the gate proves nothing about the 128 root" + ); eprintln!( "a_real_aomenc_128x128_superblock_stream_decodes_pixel_exact: \ - {frames} frames pixel-exact ({hidden} hidden) at {width}x{height}" + {frames} frames pixel-exact ({hidden} hidden) at {width}x{height}, \ + part128_symbols={part128}" ); }