forge
Explore
Log in

Don't you dare go Hollow

Derive the key-frame skip context

Browse files at this commit

0b6be1696580c16b8f1347c9784e2c0eca20e802Ahmet Kaan GümüşParent: ae78393
  • fix
    • derive the key-frame skip context
    • refuse a split-transform rect strip
Show full message
fix(av1): derive the key-frame skip context; refuse a split-transform rect strip

Two defects an adversarial source review found in the intra HORZ/VERT strip
merge, both confirmed against libaom.

The key-frame intra path read `skip` from `cdfs.skip[0]` unconditionally, while
av1_get_skip_txfm_context (pred_common.h:175-181) is above_skip + left_skip.
That was latent -- key frames rarely skip -- but the rect strips are skip-only,
so every strip this decoder accepts guarantees a skip=1 neighbour, and the
second strip of a HORZ pair would have read the wrong CDF row and desynced the
rest of the tile. Fixed at all three intra call sites, not just the rect one:
the defect is the class, and the pre-existing square site is now load-bearing.
The context comes off the mi skip grid, which every path already fills, with an
absent neighbour contributing 0 the way an absent above_mi/left_mi does.

Second, tx_depth was read and then ignored: the predictor ran over the whole
strip regardless, where libaom predicts per transform unit with each unit
taking its edges from the previous unit's reconstruction. That is a silent
pixel mismatch, and it violates this change's own skip-only contract, so a
split transform now refuses by name until the per-TU loop is ported.

Full lib suite 224 passed / 0 failed -- the skip-context fix is inert for every
existing stream, as it must be.
crates/ec-av1/src/decode.rsmodified+27 -7
@@ -1140,6 +1140,16 @@ impl Neighbours {
11401140 .unwrap_or(false)
11411141 }
11421142
1143+ /// The `skip_txfm` context of a block whose top-left mi cell is
1144+ /// `(mi_r, mi_c)`: libaom `av1_get_skip_txfm_context`
1145+ /// (`pred_common.h:175-181`) is `above_mi->skip_txfm + left_mi->skip_txfm`,
1146+ /// with an absent neighbour contributing 0. The mi grid is per tile, so
1147+ /// row/column 0 is a tile edge and has no neighbour on that axis.
1148+ fn skip_txfm_ctx(&self, mi_r: usize, mi_c: usize) -> usize {
1149+ usize::from(mi_r > 0 && self.skip_at(mi_r - 1, mi_c))
1150+ + usize::from(mi_c > 0 && self.skip_at(mi_r, mi_c - 1))
1151+ }
1152+
11431153 fn is_skip_txfm(&self, mi_r: usize, mi_c: usize) -> bool {
11441154 (0..2).all(|rr| {
11451155 (0..2).all(|cc| {
@@ -1562,6 +1572,7 @@ fn read_intra_mode_rect(
15621572 bw: usize,
15631573 bh: usize,
15641574 enable_filter_intra: bool,
1575+ skip_ctx: usize,
15651576 ) -> Result<(
15661577 bool,
15671578 usize,
@@ -1571,7 +1582,7 @@ fn read_intra_mode_rect(
15711582 Option<(i32, i32)>,
15721583 Option<usize>,
15731584 )> {
1574- let skip = dec.symbol(&mut cdfs.skip[0]) != 0;
1585+ let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;
15751586 let above_ctx = INTRA_MODE_CTX[above_mode];
15761587 let left_ctx = INTRA_MODE_CTX[left_mode];
15771588 let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]);
@@ -1696,6 +1707,7 @@ fn decode_block_rect(
16961707 bw,
16971708 bh,
16981709 enable_filter_intra,
1710+ neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)),
16991711 )?;
17001712 if filter_intra.is_some() {
17011713 // `predict_filter_intra` (spec 7.11.2.3) is square-only in this
@@ -1717,12 +1729,17 @@ fn decode_block_rect(
17171729 let depth = dec.symbol(&mut cdfs.tx_size_cat2[ctx]);
17181730 if depth != 0 {
17191731 TX_DEPTH_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
1732+ // A split transform is predicted per transform unit, each taking its
1733+ // edges from the previous unit's reconstruction (the square path's own
1734+ // per-TU loop does exactly that). Predicting the whole strip in one
1735+ // shot would silently produce different pixels, so refuse by name
1736+ // until that loop is ported for rect strips.
1737+ return Err(unsupported(
1738+ "a HORZ/VERT intra strip with a split transform (per-unit rect \
1739+ prediction is not ported)",
1740+ ));
17201741 }
1721- let (tx_w, tx_h) = match depth {
1722- 0 => (bw, bh),
1723- 1 => (16, 16),
1724- _ => (8, 8),
1725- };
1742+ let (tx_w, tx_h) = (bw, bh);
17261743 if !skip {
17271744 return Err(unsupported(
17281745 "a non-skip HORZ/VERT intra strip needs a rectangular transform \
@@ -1806,6 +1823,7 @@ fn read_intra_mode(
18061823 cfl: bool,
18071824 side: usize,
18081825 enable_filter_intra: bool,
1826+ skip_ctx: usize,
18091827 ) -> Result<(
18101828 bool,
18111829 usize,
@@ -1816,7 +1834,7 @@ fn read_intra_mode(
18161834 Option<usize>,
18171835 )> {
18181836 let trace = std::env::var_os("EC_AV1_TRACE").is_some();
1819- let skip = dec.symbol(&mut cdfs.skip[0]) != 0;
1837+ let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;
18201838 if trace {
18211839 eprintln!("TRACE skip value={}", skip as i32);
18221840 }
@@ -2354,6 +2372,7 @@ fn decode_block(
23542372 cfl,
23552373 side,
23562374 enable_filter_intra,
2375+ neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)),
23572376 )?;
23582377 // `predict` panics outside `DC_PRED..=PAETH_PRED` (0..=12); `UV_CFL_PRED`
23592378 // (13) predicts as `DC_PRED` with the [`cfl_scaled`] nudge carrying the
@@ -2667,6 +2686,7 @@ fn decode_leaf8(
26672686 true,
26682687 8,
26692688 enable_filter_intra,
2689+ neighbours.skip_txfm_ctx(leaf_mi.0, leaf_mi.1),
26702690 )?;
26712691 let uv_predict_mode = if uv_mode == UV_CFL_PRED {
26722692 DC_PRED