forge
Explore
Log in

Don't you dare go Hollow

An intra block on a tile edge read its tx_depth context off a phantom neighbour

Browse files at this commit

b8e3b16d4fc425d6b545e1077f0816b990e845feAhmet Kaan GümüşParent: 96d82d0
  • fix
    • an intra block on a tile edge read its tx_depth context off a phantom neighbour
Show full message
fix(av1): an intra block on a tile edge read its tx_depth context off a phantom neighbour

The inter-frame TxMode::Select writer counted the TXFM_CONTEXT band value
of a neighbour that does not exist -- the bands initialise to 64 pixels
(the widest transform), so every intra block on a tile top row or left
column took its tx_depth symbol off a CDF row one higher than the
decoder, whose tx_size_context_txfm drops the term entirely when
has_above/has_left is false. First divergence of every inter Select
stream.

Found with the new encode.rs round trip through our OWN decoder: the
ffmpeg gates could only report "Invalid data found", while our decoder
names the first differing frame/plane/position and can be traced symbol
by symbol.
crates/ec-av1/src/encode.rsmodified+40 -0
@@ -5892,6 +5892,46 @@ mod tests {
5892 }5892 }
5893 }5893 }
5894 5894
5895+ /// The same sequence through OUR OWN decoder, sample-exact against the
5896+ /// encoder's reconstruction. ffmpeg stays the bitstream oracle
5897+ /// ([[shared-oracle-blindness]]) -- but a stream ffmpeg REFUSES yields no
5898+ /// divergence point at all, while our decoder can be traced symbol by
5899+ /// symbol (`EC_TRACE_MODE_STEP`) on the very stream that broke. This is
5900+ /// the instrument the inter `TxMode::Select` hunt lacked; on failure it
5901+ /// names the first differing frame, plane and position.
5902+ #[test]
5903+ fn every_frame_of_a_sequence_decodes_through_our_own_decoder() {
5904+ let fctx = &crate::decode::FrameCtx::new();
5905+ let (width, height) = (128usize, 64usize);
5906+ let pictures: Vec<Picture> =
5907+ (0..5).map(|i| panned_test_card(width, height, i * 3)).collect();
5908+ let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap();
5909+ let decoded = crate::stream::decode_stream(&encoded.stream).expect("our decoder");
5910+ assert_eq!(decoded.len(), encoded.frames.len(), "frame count");
5911+ for (i, (frame, dec)) in encoded.frames.iter().zip(&decoded).enumerate() {
5912+ let recon = &frame.reconstruction;
5913+ for (plane, got, want, stride) in [
5914+ ("luma", &dec.y, &recon.y, width),
5915+ ("U", &dec.u, &recon.u, width / 2),
5916+ ("V", &dec.v, &recon.v, width / 2),
5917+ ] {
5918+ assert_eq!(got.len(), want.len(), "frame {i}: {plane} size");
5919+ if let Some(at) = got.iter().zip(want).position(|(a, b)| a != b) {
5920+ panic!(
5921+ "frame {i}: {plane} differs first at ({}, {}): decoded {} vs \
5922+ reconstruction {} ({} of {} samples differ)",
5923+ at % stride,
5924+ at / stride,
5925+ got[at],
5926+ want[at],
5927+ got.iter().zip(want).filter(|(a, b)| a != b).count(),
5928+ got.len(),
5929+ );
5930+ }
5931+ }
5932+ }
5933+ }
5934+
5895 /// The rate term the mode search ranks every decision by has to be the5935 /// The rate term the mode search ranks every decision by has to be the
5896 /// rate the writer then spends. The search prices a block's coefficients5936 /// rate the writer then spends. The search prices a block's coefficients
5897 /// through `tile::coeff_bits` -- the writer's own symbol chain, but5937 /// through `tile::coeff_bits` -- the writer's own symbol chain, but
crates/ec-av1/src/tile.rsmodified+12 -3
@@ -759,16 +759,25 @@ impl Neighbours {
759 /// `get_tx_size_context` as libaom writes it for a block inside an INTER759 /// `get_tx_size_context` as libaom writes it for a block inside an INTER
760 /// frame (decode.rs `tx_size_context_txfm_rect`): the `TXFM_CONTEXT`760 /// frame (decode.rs `tx_size_context_txfm_rect`): the `TXFM_CONTEXT`
761 /// bands, except that an *inter* neighbour contributes its own BLOCK size.761 /// bands, except that an *inter* neighbour contributes its own BLOCK size.
762+ ///
763+ /// lane-av1tx2 r1: a neighbour OUTSIDE the tile contributes nothing at all
764+ /// -- the decoder's `tx_size_context_txfm` drops the whole term when
765+ /// `has_above`/`has_left` is false, where this counted the band's
766+ /// [`TXFM_CTX_INIT`] (64, the widest transform) as a real neighbour. Every
767+ /// intra block on a tile's top row or left column then took its `tx_depth`
768+ /// off a CDF row one higher than the decoder's, which is the first
769+ /// divergence of the inter `TxMode::Select` stream.
762 fn tx_size_ctx_txfm(&self, (mi_r, mi_c): (usize, usize), own_side: usize) -> usize {770 fn tx_size_ctx_txfm(&self, (mi_r, mi_c): (usize, usize), own_side: usize) -> usize {
771+ let (has_above, has_left) = (mi_r > 0, mi_c > 0);
763 let mut above = usize::from(self.above_txfm[mi_c]) >= own_side;772 let mut above = usize::from(self.above_txfm[mi_c]) >= own_side;
764 let mut left = usize::from(self.left_txfm[mi_r]) >= own_side;773 let mut left = usize::from(self.left_txfm[mi_r]) >= own_side;
765- if mi_r > 0 && self.above_inter[mi_c] {774+ if has_above && self.above_inter[mi_c] {
766 above = self.above_side_mi[mi_c] >= own_side;775 above = self.above_side_mi[mi_c] >= own_side;
767 }776 }
768- if mi_c > 0 && self.left_inter[mi_r] {777+ if has_left && self.left_inter[mi_r] {
769 left = self.left_side_mi[mi_r] >= own_side;778 left = self.left_side_mi[mi_r] >= own_side;
770 }779 }
771- usize::from(above) + usize::from(left)780+ usize::from(has_above && above) + usize::from(has_left && left)
772 }781 }
773 782
774 /// `get_tx_size_context` (decode.rs [`crate::decode::tx_size_context`]):783 /// `get_tx_size_context` (decode.rs [`crate::decode::tx_size_context`]):