diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index fed75396..3dffb14e 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -5892,6 +5892,46 @@ mod tests { } } + /// The same sequence through OUR OWN decoder, sample-exact against the + /// encoder's reconstruction. ffmpeg stays the bitstream oracle + /// ([[shared-oracle-blindness]]) -- but a stream ffmpeg REFUSES yields no + /// divergence point at all, while our decoder can be traced symbol by + /// symbol (`EC_TRACE_MODE_STEP`) on the very stream that broke. This is + /// the instrument the inter `TxMode::Select` hunt lacked; on failure it + /// names the first differing frame, plane and position. + #[test] + fn every_frame_of_a_sequence_decodes_through_our_own_decoder() { + let fctx = &crate::decode::FrameCtx::new(); + let (width, height) = (128usize, 64usize); + let pictures: Vec = + (0..5).map(|i| panned_test_card(width, height, i * 3)).collect(); + let encoded = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap(); + let decoded = crate::stream::decode_stream(&encoded.stream).expect("our decoder"); + assert_eq!(decoded.len(), encoded.frames.len(), "frame count"); + for (i, (frame, dec)) in encoded.frames.iter().zip(&decoded).enumerate() { + let recon = &frame.reconstruction; + for (plane, got, want, stride) in [ + ("luma", &dec.y, &recon.y, width), + ("U", &dec.u, &recon.u, width / 2), + ("V", &dec.v, &recon.v, width / 2), + ] { + assert_eq!(got.len(), want.len(), "frame {i}: {plane} size"); + if let Some(at) = got.iter().zip(want).position(|(a, b)| a != b) { + panic!( + "frame {i}: {plane} differs first at ({}, {}): decoded {} vs \ + reconstruction {} ({} of {} samples differ)", + at % stride, + at / stride, + got[at], + want[at], + got.iter().zip(want).filter(|(a, b)| a != b).count(), + got.len(), + ); + } + } + } + } + /// The rate term the mode search ranks every decision by has to be the /// rate the writer then spends. The search prices a block's coefficients /// through `tile::coeff_bits` -- the writer's own symbol chain, but diff --git a/crates/ec-av1/src/tile.rs b/crates/ec-av1/src/tile.rs index 6e0dbd15..8fd63395 100644 --- a/crates/ec-av1/src/tile.rs +++ b/crates/ec-av1/src/tile.rs @@ -759,16 +759,25 @@ impl Neighbours { /// `get_tx_size_context` as libaom writes it for a block inside an INTER /// frame (decode.rs `tx_size_context_txfm_rect`): the `TXFM_CONTEXT` /// bands, except that an *inter* neighbour contributes its own BLOCK size. + /// + /// lane-av1tx2 r1: a neighbour OUTSIDE the tile contributes nothing at all + /// -- the decoder's `tx_size_context_txfm` drops the whole term when + /// `has_above`/`has_left` is false, where this counted the band's + /// [`TXFM_CTX_INIT`] (64, the widest transform) as a real neighbour. Every + /// intra block on a tile's top row or left column then took its `tx_depth` + /// off a CDF row one higher than the decoder's, which is the first + /// divergence of the inter `TxMode::Select` stream. fn tx_size_ctx_txfm(&self, (mi_r, mi_c): (usize, usize), own_side: usize) -> usize { + let (has_above, has_left) = (mi_r > 0, mi_c > 0); let mut above = usize::from(self.above_txfm[mi_c]) >= own_side; let mut left = usize::from(self.left_txfm[mi_r]) >= own_side; - if mi_r > 0 && self.above_inter[mi_c] { + if has_above && self.above_inter[mi_c] { above = self.above_side_mi[mi_c] >= own_side; } - if mi_c > 0 && self.left_inter[mi_r] { + if has_left && self.left_inter[mi_r] { left = self.left_side_mi[mi_r] >= own_side; } - usize::from(above) + usize::from(left) + usize::from(has_above && above) + usize::from(has_left && left) } /// `get_tx_size_context` (decode.rs [`crate::decode::tx_size_context`]):