forge
Explore
Log in

Don't you dare go Hollow

The encoder's filter-search re-decode ignored ref_frame_sign_bias

Browse files at this commit

28f2d424c8f3b1a2920d66ea0378725d6a4c3cbeAhmet Kaan GümüşParent: a802372
  • fix
    • the encoder's filter-search re-decode ignored ref_frame_sign_bias
Show full message
fix(av1): the encoder's filter-search re-decode ignored ref_frame_sign_bias

decode_inter_frame_tile_lr hard-coded NO_SIGN_BIAS, so the trial decode of a
pyramid leaf reading its group's backward hidden ALTREF built different MV
stacks than the writer and desynced into 'a reference frame selected with no
picture at this frame's own ref_frame_idx slot'.
crates/ec-av1/src/decode.rsmodified+14 -2
@@ -32874,7 +32874,7 @@ pub(crate) fn decode_inter_frame_tile(
3287432874 data, mi_cols, mi_rows, base_q_idx, frame_width, frame_height, refpix, cdef,
3287532875 loop_filter, allow_high_precision_mv, force_integer_mv, interp_fixed,
3287632876 enable_dual_filter, reference_select, tx_select,
32877- &LoopRestorationParams::default(), initial_cdfs, fctx,
32877+ &LoopRestorationParams::default(), initial_cdfs, NO_SIGN_BIAS, fctx,
3287832878 )
3287932879 }
3288032880
@@ -32899,6 +32899,16 @@ pub(crate) fn decode_inter_frame_tile_lr(
3289932899 tx_select: bool,
3290032900 lr: &LoopRestorationParams,
3290132901 initial_cdfs: Option<Cdfs>,
32902+ // spec 5.9.2's `ref_frame_sign_bias`, derived by a real decoder from the
32903+ // order hints its DPB slots hold. A raw tile decode cannot derive it (it
32904+ // is handed planes, not slots), and hard-coding `NO_SIGN_BIAS` here
32905+ // desyncs the encoder's own filter-search re-decode of any frame with a
32906+ // BACKWARD reference -- a pyramid leaf reading its group's hidden
32907+ // `ALTREF_FRAME` -- since the writer's MV-stack scans flip borrowed
32908+ // candidates across the bias boundary and this one's did not. Same class
32909+ // as `tx_select`/`initial_cdfs` above: a header-derived value a raw tile
32910+ // decode has to be told.
32911+ sign_bias: crate::mvstack::SignBiasTable,
3290232912 fctx: &crate::decode::FrameCtx,
3290332913 ) -> Result<Picture> {
3290432914 let single_tile = TileInfo {
@@ -32922,7 +32932,7 @@ pub(crate) fn decode_inter_frame_tile_lr(
3292232932 initial_cdfs,
3292332933 allow_high_precision_mv,
3292432934 force_integer_mv,
32925- NO_SIGN_BIAS,
32935+ sign_bias,
3292632936 [ec_av1_syntax::WarpParams::default(); 7],
3292732937 interp_fixed,
3292832938 enable_dual_filter,
@@ -37478,6 +37488,7 @@ mod tests {
3747837488 frame.tx_select,
3747937489 &frame.loop_restoration,
3748037490 Some(frame.start_cdfs.0.clone()),
37491+ NO_SIGN_BIAS,
3748137492 fctx,
3748237493 )
3748337494 .unwrap();
@@ -37796,6 +37807,7 @@ mod tests {
3779637807 frame.tx_select,
3779737808 &frame.loop_restoration,
3779837809 Some(frame.start_cdfs.0.clone()),
37810+ NO_SIGN_BIAS,
3779937811 fctx,
3780037812 )
3780137813 .unwrap();
crates/ec-av1/src/encode.rsmodified+1 -0
@@ -4840,6 +4840,7 @@ pub(crate) fn encode_inter_frame(
48404840 // so it starts from the same tables the writer did (this
48414841 // frame's `start_cdfs`), not from the defaults.
48424842 Some(start_cdfs.0.clone()),
4843+ sign_bias,
48434844 fctx,
48444845 )
48454846 },
crates/ec-av1/src/encoder.rsmodified+16 -2
@@ -817,7 +817,7 @@ impl Av1Encoder {
817817 .then(|| self.dpb[altref_slot as usize].as_ref().map(|s| s.picture.clone()))
818818 .flatten();
819819 let start_cdfs = self.dpb[last_slot as usize].as_ref().map(|s| s.cdfs.0.clone());
820- let encoded = encode_inter_frame(
820+ let encoded = || -> Result<Encoded> { encode_inter_frame(
821821 &picture.padded_to(SUPERBLOCK),
822822 &reference,
823823 base_q_idx,
@@ -835,7 +835,21 @@ impl Av1Encoder {
835835 show_frame,
836836 sign_bias,
837837 }),
838- )?;
838+ ) }();
839+ // Name the pyramid position in any failure: an error out of the tile
840+ // writer or the filter search is otherwise indistinguishable between
841+ // the hidden frame and the leaves that read it.
842+ let encoded = encoded.map_err(|e| {
843+ Error::unsupported(
844+ "AV1 encode",
845+ format!(
846+ "{level:?} frame at order {order} (last slot {last_slot}, self {self_slot}, \
847+ altref {altref_slot}, shown {show_frame}, golden {}, altref pic {}): {e}",
848+ golden.is_some(),
849+ altref.is_some(),
850+ ),
851+ )
852+ })?;
839853 self.refresh(&[self_slot], &encoded, order_hint);
840854 let cropped = crop_encoded(&encoded, render.0, render.1);
841855 if let Some(rate_loop) = self.rate_loop.as_mut() {