The encoder's filter-search re-decode ignored ref_frame_sign_bias
Browse files at this commit28f2d424c8f3b1a2920d66ea0378725d6a4c3cbeParent: a802372- fix
- the encoder's filter-search re-decode ignored ref_frame_sign_bias
3 changed files +31 -4
- crates/ec-av1/src/decode.rs +14 -2
- crates/ec-av1/src/encode.rs +1 -0
- crates/ec-av1/src/encoder.rs +16 -2
crates/ec-av1/src/decode.rsmodified+14 -2
| @@ -32874,7 +32874,7 @@ pub(crate) fn decode_inter_frame_tile( | |||
| 32874 | data, mi_cols, mi_rows, base_q_idx, frame_width, frame_height, refpix, cdef, | 32874 | data, mi_cols, mi_rows, base_q_idx, frame_width, frame_height, refpix, cdef, |
| 32875 | loop_filter, allow_high_precision_mv, force_integer_mv, interp_fixed, | 32875 | loop_filter, allow_high_precision_mv, force_integer_mv, interp_fixed, |
| 32876 | enable_dual_filter, reference_select, tx_select, | 32876 | enable_dual_filter, reference_select, tx_select, |
| 32877 | - &LoopRestorationParams::default(), initial_cdfs, fctx, | 32877 | + &LoopRestorationParams::default(), initial_cdfs, NO_SIGN_BIAS, fctx, |
| 32878 | ) | 32878 | ) |
| 32879 | } | 32879 | } |
| 32880 | 32880 | ||
| @@ -32899,6 +32899,16 @@ pub(crate) fn decode_inter_frame_tile_lr( | |||
| 32899 | tx_select: bool, | 32899 | tx_select: bool, |
| 32900 | lr: &LoopRestorationParams, | 32900 | lr: &LoopRestorationParams, |
| 32901 | initial_cdfs: Option<Cdfs>, | 32901 | 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, | ||
| 32902 | fctx: &crate::decode::FrameCtx, | 32912 | fctx: &crate::decode::FrameCtx, |
| 32903 | ) -> Result<Picture> { | 32913 | ) -> Result<Picture> { |
| 32904 | let single_tile = TileInfo { | 32914 | let single_tile = TileInfo { |
| @@ -32922,7 +32932,7 @@ pub(crate) fn decode_inter_frame_tile_lr( | |||
| 32922 | initial_cdfs, | 32932 | initial_cdfs, |
| 32923 | allow_high_precision_mv, | 32933 | allow_high_precision_mv, |
| 32924 | force_integer_mv, | 32934 | force_integer_mv, |
| 32925 | - NO_SIGN_BIAS, | 32935 | + sign_bias, |
| 32926 | [ec_av1_syntax::WarpParams::default(); 7], | 32936 | [ec_av1_syntax::WarpParams::default(); 7], |
| 32927 | interp_fixed, | 32937 | interp_fixed, |
| 32928 | enable_dual_filter, | 32938 | enable_dual_filter, |
| @@ -37478,6 +37488,7 @@ mod tests { | |||
| 37478 | frame.tx_select, | 37488 | frame.tx_select, |
| 37479 | &frame.loop_restoration, | 37489 | &frame.loop_restoration, |
| 37480 | Some(frame.start_cdfs.0.clone()), | 37490 | Some(frame.start_cdfs.0.clone()), |
| 37491 | + NO_SIGN_BIAS, | ||
| 37481 | fctx, | 37492 | fctx, |
| 37482 | ) | 37493 | ) |
| 37483 | .unwrap(); | 37494 | .unwrap(); |
| @@ -37796,6 +37807,7 @@ mod tests { | |||
| 37796 | frame.tx_select, | 37807 | frame.tx_select, |
| 37797 | &frame.loop_restoration, | 37808 | &frame.loop_restoration, |
| 37798 | Some(frame.start_cdfs.0.clone()), | 37809 | Some(frame.start_cdfs.0.clone()), |
| 37810 | + NO_SIGN_BIAS, | ||
| 37799 | fctx, | 37811 | fctx, |
| 37800 | ) | 37812 | ) |
| 37801 | .unwrap(); | 37813 | .unwrap(); |
crates/ec-av1/src/encode.rsmodified+1 -0
| @@ -4840,6 +4840,7 @@ pub(crate) fn encode_inter_frame( | |||
| 4840 | // so it starts from the same tables the writer did (this | 4840 | // so it starts from the same tables the writer did (this |
| 4841 | // frame's `start_cdfs`), not from the defaults. | 4841 | // frame's `start_cdfs`), not from the defaults. |
| 4842 | Some(start_cdfs.0.clone()), | 4842 | Some(start_cdfs.0.clone()), |
| 4843 | + sign_bias, | ||
| 4843 | fctx, | 4844 | fctx, |
| 4844 | ) | 4845 | ) |
| 4845 | }, | 4846 | }, |
crates/ec-av1/src/encoder.rsmodified+16 -2
| @@ -817,7 +817,7 @@ impl Av1Encoder { | |||
| 817 | .then(|| self.dpb[altref_slot as usize].as_ref().map(|s| s.picture.clone())) | 817 | .then(|| self.dpb[altref_slot as usize].as_ref().map(|s| s.picture.clone())) |
| 818 | .flatten(); | 818 | .flatten(); |
| 819 | let start_cdfs = self.dpb[last_slot as usize].as_ref().map(|s| s.cdfs.0.clone()); | 819 | 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( |
| 821 | &picture.padded_to(SUPERBLOCK), | 821 | &picture.padded_to(SUPERBLOCK), |
| 822 | &reference, | 822 | &reference, |
| 823 | base_q_idx, | 823 | base_q_idx, |
| @@ -835,7 +835,21 @@ impl Av1Encoder { | |||
| 835 | show_frame, | 835 | show_frame, |
| 836 | sign_bias, | 836 | sign_bias, |
| 837 | }), | 837 | }), |
| 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 | + })?; | ||
| 839 | self.refresh(&[self_slot], &encoded, order_hint); | 853 | self.refresh(&[self_slot], &encoded, order_hint); |
| 840 | let cropped = crop_encoded(&encoded, render.0, render.1); | 854 | let cropped = crop_encoded(&encoded, render.0, render.1); |
| 841 | if let Some(rate_loop) = self.rate_loop.as_mut() { | 855 | if let Some(rate_loop) = self.rate_loop.as_mut() { |