forge
Explore
Log in

Don't you dare go Hollow

WIP(av1): single-ref LAST2/LAST3/BWDREF/ALTREF2/ALTREF decode — agent capped mid-verification

Browse files at this commit

96e6529482bec19f8e9f7584b64ea821f61ced13Ahmet Kaan GümüşParent: 1ce9f54
crates/ec-av1/src/decode.rsmodified+87 -103
@@ -32,8 +32,9 @@ use crate::mc;
32 use crate::msac::SymbolDecoder;32 use crate::msac::SymbolDecoder;
33 use crate::mvstack::{33 use crate::mvstack::{
34 ALTREF_FRAME, ALTREF2_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST_FRAME, LAST2_FRAME, LAST3_FRAME,34 ALTREF_FRAME, ALTREF2_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST_FRAME, LAST2_FRAME, LAST3_FRAME,
35- MiGrid, MiInfo, find_mv_stack, single_ref_ctx, single_ref_p1_ctx, single_ref_p2_ctx,35+ MiGrid, MiInfo, NO_SIGN_BIAS, SignBiasTable, find_mv_stack, find_mv_stack_with_sign_bias,
36- single_ref_p3_ctx, single_ref_p4_ctx, single_ref_p5_ctx, single_ref_p6_ctx,36+ single_ref_ctx, single_ref_p1_ctx, single_ref_p2_ctx, single_ref_p3_ctx, single_ref_p4_ctx,
37+ single_ref_p5_ctx, single_ref_p6_ctx,
37 };38 };
38 use crate::tile::{INTRA_MODE_CTX, block_grid, has_half};39 use crate::tile::{INTRA_MODE_CTX, block_grid, has_half};
39 use crate::transform::{TxType, dequant_and_inverse_typed};40 use crate::transform::{TxType, dequant_and_inverse_typed};
@@ -1248,6 +1249,14 @@ struct PlaneBuf {
1248 true_height: usize,1249 true_height: usize,
1249 }1250 }
1250 1251
1252+/// One entry per `MV_REFERENCE_FRAME` (index 0/1 unused -- `NONE`/
1253+/// `INTRA_FRAME`/`LAST_FRAME` all resolve elsewhere), `Some` when this
1254+/// frame's own `ref_frame_idx` names a DPB slot that has a picture in it
1255+/// (lane-av1refs: the same "empty slot" case `GOLDEN_FRAME` already
1256+/// refused by name, now generic across `LAST2`/`LAST3`/`GOLDEN`/`BWDREF`/
1257+/// `ALTREF2`/`ALTREF`).
1258+type RefSlots<'a> = [Option<(&'a PlaneBuf, &'a PlaneBuf, &'a PlaneBuf)>; 8];
1259+
1251 impl PlaneBuf {1260 impl PlaneBuf {
1252 fn edges(1261 fn edges(
1253 &self,1262 &self,
@@ -3691,18 +3700,14 @@ fn decode_inter_block(
3691 ref_y: &PlaneBuf,3700 ref_y: &PlaneBuf,
3692 ref_u: &PlaneBuf,3701 ref_u: &PlaneBuf,
3693 ref_v: &PlaneBuf,3702 ref_v: &PlaneBuf,
3694- // corner-cut (lane-av1refs r1): only `LAST_FRAME` (`ref_y`/`u`/`v`) and3703+ // lane-av1refs: every non-`LAST_FRAME` reference this frame header's own
3695- // `GOLDEN_FRAME` (`golden_*`, when the frame header's own3704+ // `ref_frame_idx` names a live DPB slot for, indexed `[ref_frame]`
3696- // `ref_frame_idx` names a slot with a picture) are threaded down to MC.3705+ // (`LAST2_FRAME`=2 .. `ALTREF_FRAME`=7; index 0/1 unused, `LAST_FRAME`
3697- // Ceiling: `LAST2`/`LAST3`/`BWDREF`/`ALTREF2`/`ALTREF` still refuse by3706+ // stays on `ref_y`/`u`/`v` above) -- `None` at a live index means the
3698- // name -- real short low-lag streams overwhelmingly pick `LAST` or3707+ // slot's still empty (an error-resilient stream, or too early in the
3699- // `GOLDEN` (the ledger's cdffwd trace). Upgrade path: widen `golden_*`3708+ // GOP), matching `GOLDEN_FRAME`'s existing empty-slot refusal below.
3700- // into a `[Option<&PlaneBuf>; REFS_PER_FRAME]` addressed by the decoded3709+ other_refs: &RefSlots,
3701- // reference, same as the CDF/picture DPB slots `decode_stream` already3710+ sign_bias_table: &SignBiasTable,
3702- // keeps.
3703- golden_y: Option<&PlaneBuf>,
3704- golden_u: Option<&PlaneBuf>,
3705- golden_v: Option<&PlaneBuf>,
3706 base_q_idx: u8,3711 base_q_idx: u8,
3707 luma_set_intra: TxbSet,3712 luma_set_intra: TxbSet,
3708 luma_set_inter: TxbSet,3713 luma_set_inter: TxbSet,
@@ -3737,57 +3742,31 @@ fn decode_inter_block(
3737 if is_inter {3742 if is_inter {
3738 let ref_frame = read_single_ref(dec, cdfs, neighbours.above_ref[c], neighbours.left_ref[r]);3743 let ref_frame = read_single_ref(dec, cdfs, neighbours.above_ref[c], neighbours.left_ref[r]);
3739 ref_frame_for_lf = ref_frame;3744 ref_frame_for_lf = ref_frame;
3740- // round 4-8 (lane-av1golden through lane-av1golden6): repeatedly3745+ // round 4-9 (lane-av1golden..lane-av1golden7): GOLDEN_FRAME's own
3741- // un-masked and re-masked chasing what looked like a GOLDEN_FRAME MC3746+ // stacked defects (lf_level ref/mode-delta forwarding, the
3742- // bug -- lf_level `mode_deltas`/`ref_deltas` forwarding fixes3747+ // switchable_interp ref-frame ctx gate, and a film-grain synthesis
3743- // (rounds 5/6, both real and kept), and a switchable_interp ctx3748+ // gap that looked like a GOLDEN MC bug by survivor bias -- see the
3744- // ref-frame gate (round 8, real and kept). Every remaining3749+ // ledger) are all closed; GOLDEN_FRAME decodes live via `other_refs`
3745- // "GOLDEN_FRAME mismatch" chased past round 8 (including a frame-03750+ // below same as every other non-`LAST_FRAME` reference. lane-av1refs
3746- // *intra keyframe* luma mismatch that could not possibly depend on3751+ // widens this from GOLDEN alone to every reference `read_single_ref`
3747- // this arm at all) turned out to be a single unrelated cause: round3752+ // can name.
3748- // 9 (lane-av1golden7) traced `fixtures/golden6-mismatch.obu`'s3753+ let (py_ref, pu_ref, pv_ref) = if ref_frame == LAST_FRAME {
3749- // frame-0 mismatch down to `header.film_grain.apply_grain == true`3754+ (ref_y, ref_u, ref_v)
3750- // (aomenc's `--tune-content=film` denoises the coded picture and3755+ } else {
3751- // has the decoder re-synthesize grain per spec 7.18.3) -- this3756+ match other_refs[ref_frame as usize] {
3752- // decoder never implements grain synthesis at all, so it silently3757+ Some((ry, ru, rv)) => (ry, ru, rv),
3753- // returned the clean base picture while ffmpeg (dav1d) returned the3758+ None => {
3754- // grain-synthesized one. That bug fires on *any* frame, key or
3755- // inter, and is orthogonal to which reference a block selects --
3756- // the earlier "correlates with GOLDEN firing" pattern was survivor
3757- // bias: the golden gate only ever compared streams where
3758- // `non_last_ref_hits` fired, and `--tune-content=film` is part of
3759- // that same gate's own aomenc recipe. `decode_stream` now refuses
3760- // `apply_grain` streams by name instead of silently mismatching --
3761- // but unmasking `GOLDEN_FRAME` with that fix in still shows a real,
3762- // separate residual MC bug: round 9 (lane-av1golden7)'s forwarding
3763- // gate hit 1/20 real aomenc streams mismatching (frame 3 luma,
3764- // apply_grain=false, non_last_ref_hits delta=2), pinned in
3765- // `fixtures/golden7-forwarding-mismatch.obu` for round 10. `GOLDEN_FRAME`
3766- // stays refused by name until that's found.
3767- let (py_ref, pu_ref, pv_ref) = match ref_frame {
3768- LAST_FRAME => (ref_y, ref_u, ref_v),
3769- GOLDEN_FRAME => match (golden_y, golden_u, golden_v) {
3770- (Some(gy), Some(gu), Some(gv)) => (gy, gu, gv),
3771- _ => {
3772 return Err(unsupported(3759 return Err(unsupported(
3773- "GOLDEN_FRAME selected with no golden picture at this frame's \3760+ "a reference frame selected with no picture at this frame's own \
3774- ref_frame_idx[3] slot",3761+ ref_frame_idx slot for it",
3775 ));3762 ));
3776 }3763 }
3777- },
3778- _ => {
3779- return Err(unsupported(
3780- "a reference frame other than LAST_FRAME (LAST2/LAST3/GOLDEN/BWDREF/\
3781- ALTREF2/ALTREF still have no MC path -- GOLDEN's residual MC bug is \
3782- pinned in fixtures/golden7-forwarding-mismatch.obu, round 9 \
3783- lane-av1golden7)",
3784- ));
3785 }3764 }
3786 };3765 };
3787 3766
3788 let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize);3767 let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize);
3789 let bw4 = side / 4;3768 let bw4 = side / 4;
3790- let stack = find_mv_stack(3769+ let stack = find_mv_stack_with_sign_bias(
3791 grid,3770 grid,
3792 mi_row,3771 mi_row,
3793 mi_col,3772 mi_col,
@@ -3796,6 +3775,7 @@ fn decode_inter_block(
3796 ref_frame,3775 ref_frame,
3797 mi_cols as usize,3776 mi_cols as usize,
3798 mi_rows as usize,3777 mi_rows as usize,
3778+ sign_bias_table,
3799 );3779 );
3800 let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1;3780 let not_new = dec.symbol(&mut cdfs.new_mv[stack.new_mv_ctx]) == 1;
3801 let mut is_globalmv = false;3781 let mut is_globalmv = false;
@@ -4615,7 +4595,7 @@ pub fn decode_inter_frame_tile(
4615 frame_width: u32,4595 frame_width: u32,
4616 frame_height: u32,4596 frame_height: u32,
4617 reference: &Picture,4597 reference: &Picture,
4618- golden: Option<&Picture>,4598+ other_refs: [Option<&Picture>; 8],
4619 cdef: &CdefParams,4599 cdef: &CdefParams,
4620 loop_filter: &LoopFilterParams,4600 loop_filter: &LoopFilterParams,
4621 allow_high_precision_mv: bool,4601 allow_high_precision_mv: bool,
@@ -4630,11 +4610,12 @@ pub fn decode_inter_frame_tile(
4630 frame_width,4610 frame_width,
4631 frame_height,4611 frame_height,
4632 reference,4612 reference,
4633- golden,4613+ other_refs,
4634 cdef,4614 cdef,
4635 loop_filter,4615 loop_filter,
4636 None,4616 None,
4637 allow_high_precision_mv,4617 allow_high_precision_mv,
4618+ NO_SIGN_BIAS,
4638 interp_fixed,4619 interp_fixed,
4639 enable_dual_filter,4620 enable_dual_filter,
4640 )4621 )
@@ -4654,11 +4635,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
4654 frame_width: u32,4635 frame_width: u32,
4655 frame_height: u32,4636 frame_height: u32,
4656 reference: &Picture,4637 reference: &Picture,
4657- golden: Option<&Picture>,4638+ other_refs: [Option<&Picture>; 8],
4658 cdef: &CdefParams,4639 cdef: &CdefParams,
4659 loop_filter: &LoopFilterParams,4640 loop_filter: &LoopFilterParams,
4660 initial_cdfs: Option<Cdfs>,4641 initial_cdfs: Option<Cdfs>,
4661 allow_high_precision_mv: bool,4642 allow_high_precision_mv: bool,
4643+ sign_bias_table: SignBiasTable,
4662 interp_fixed: Option<mc::InterpFilterKind>,4644 interp_fixed: Option<mc::InterpFilterKind>,
4663 enable_dual_filter: bool,4645 enable_dual_filter: bool,
4664 ) -> Result<(Picture, Cdfs)> {4646 ) -> Result<(Picture, Cdfs)> {
@@ -4696,38 +4678,43 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
4696 true_width: reference.width / 2,4678 true_width: reference.width / 2,
4697 true_height: reference.height / 2,4679 true_height: reference.height / 2,
4698 };4680 };
4699- // `GOLDEN_FRAME`'s own picture, when the frame header's `ref_frame_idx`4681+ // Every non-`LAST_FRAME` reference this frame header's own `ref_frame_idx`
4700- // names a DPB slot holding one and it is this frame's own true size --4682+ // names a live DPB slot for (lane-av1refs: generalised from the old
4701- // `decode_inter_block`'s GOLDEN_FRAME arm refuses when it is `None` or a4683+ // GOLDEN_FRAME-only block -- same empty-slot/size-mismatch refusal,
4702- // mismatched size (spec 7.9 requires every active reference be a4684+ // now per-reference). `decode_inter_block` refuses by name when the
4703- // compatible size; this decoder's single-slot-per-frame update makes4685+ // block it is decoding selects an index that is still `None` here
4704- // that always true for a stream this crate's own encoder writes).4686+ // (spec 7.9 requires every *active* reference be a compatible size;
4705- let (golden_y, golden_u, golden_v) = match golden {4687+ // an inactive one this frame never selects is simply left `None`).
4706- Some(g) if g.width == reference.width && g.height == reference.height => (4688+ let owned_refs: [Option<(PlaneBuf, PlaneBuf, PlaneBuf)>; 8] = std::array::from_fn(|i| {
4707- Some(PlaneBuf {4689+ other_refs[i]
4708- data: g.y.clone(),4690+ .filter(|g| g.width == reference.width && g.height == reference.height)
4709- width: g.width,4691+ .map(|g| {
4710- height: g.height,4692+ (
4711- true_width: g.width,4693+ PlaneBuf {
4712- true_height: g.height,4694+ data: g.y.clone(),
4713- }),4695+ width: g.width,
4714- Some(PlaneBuf {4696+ height: g.height,
4715- data: g.u.clone(),4697+ true_width: g.width,
4716- width: g.width / 2,4698+ true_height: g.height,
4717- height: g.height / 2,4699+ },
4718- true_width: g.width / 2,4700+ PlaneBuf {
4719- true_height: g.height / 2,4701+ data: g.u.clone(),
4720- }),4702+ width: g.width / 2,
4721- Some(PlaneBuf {4703+ height: g.height / 2,
4722- data: g.v.clone(),4704+ true_width: g.width / 2,
4723- width: g.width / 2,4705+ true_height: g.height / 2,
4724- height: g.height / 2,4706+ },
4725- true_width: g.width / 2,4707+ PlaneBuf {
4726- true_height: g.height / 2,4708+ data: g.v.clone(),
4727- }),4709+ width: g.width / 2,
4728- ),4710+ height: g.height / 2,
4729- _ => (None, None, None),4711+ true_width: g.width / 2,
4730- };4712+ true_height: g.height / 2,
4713+ },
4714+ )
4715+ })
4716+ });
4717+ let ref_slots: RefSlots = std::array::from_fn(|i| owned_refs[i].as_ref().map(|(a, b, c)| (a, b, c)));
4731 4718
4732 let mut y = PlaneBuf {4719 let mut y = PlaneBuf {
4733 data: vec![0u8; width * height],4720 data: vec![0u8; width * height],
@@ -4830,9 +4817,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
4830 &ref_y,4817 &ref_y,
4831 &ref_u,4818 &ref_u,
4832 &ref_v,4819 &ref_v,
4833- golden_y.as_ref(),4820+ &ref_slots,
4834- golden_u.as_ref(),4821+ &sign_bias_table,
4835- golden_v.as_ref(),
4836 base_q_idx,4822 base_q_idx,
4837 TxbSet::Luma32,4823 TxbSet::Luma32,
4838 TxbSet::Luma32Inter,4824 TxbSet::Luma32Inter,
@@ -4888,9 +4874,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
4888 &ref_y,4874 &ref_y,
4889 &ref_u,4875 &ref_u,
4890 &ref_v,4876 &ref_v,
4891- golden_y.as_ref(),4877+ &ref_slots,
4892- golden_u.as_ref(),4878+ &sign_bias_table,
4893- golden_v.as_ref(),
4894 base_q_idx,4879 base_q_idx,
4895 TxbSet::Luma16,4880 TxbSet::Luma16,
4896 TxbSet::Luma16Inter,4881 TxbSet::Luma16Inter,
@@ -5457,7 +5442,7 @@ mod tests {
5457 width as u32,5442 width as u32,
5458 height as u32,5443 height as u32,
5459 &reference,5444 &reference,
5460- None,5445+ [None; 8],
5461 &CdefParams::default(),5446 &CdefParams::default(),
5462 &LoopFilterParams::default(),5447 &LoopFilterParams::default(),
5463 false,5448 false,
@@ -5627,9 +5612,8 @@ mod tests {
5627 &ref_y,5612 &ref_y,
5628 &ref_u,5613 &ref_u,
5629 &ref_v,5614 &ref_v,
5630- None,5615+ &[None; 8],
5631- None,5616+ &NO_SIGN_BIAS,
5632- None,
5633 100,5617 100,
5634 TxbSet::Luma16,5618 TxbSet::Luma16,
5635 TxbSet::Luma16Inter,5619 TxbSet::Luma16Inter,
@@ -5729,7 +5713,7 @@ mod tests {
5729 coded_w,5713 coded_w,
5730 coded_h,5714 coded_h,
5731 &reference,5715 &reference,
5732- None,5716+ [None; 8],
5733 &CdefParams::default(),5717 &CdefParams::default(),
5734 &LoopFilterParams::default(),5718 &LoopFilterParams::default(),
5735 false,5719 false,
crates/ec-av1/src/mvstack.rsmodified+56 -13
@@ -227,18 +227,30 @@ fn add_candidate(candidates: &mut Vec<StackEntry>, mv: (i32, i32), weight: u32)
227 }227 }
228 }228 }
229 229
230-/// Whether `ref_frame`'s prediction runs backward in display order230+/// `cm->ref_frame_sign_bias[ref_frame]`, looked up from the frame header's
231-/// (`cm->ref_frame_sign_bias`, libaom): flips a borrowed neighbour's MV231+/// own `ref_frame_sign_bias` (spec 5.9.2's `get_relative_dist(ref_order_hint,
232-/// sign in [`process_single_ref_mv_candidate`] when the neighbour's own232+/// OrderHint) > 0` per active reference, already computed by
233-/// reference disagrees. This decoder only ever threads forward references233+/// `ec_av1_syntax::frame::read_uncompressed_header` and indexed exactly like
234-/// (`LAST_FRAME`/`GOLDEN_FRAME`) to MC — never `BWDREF`/`ALTREF` — so every234+/// `ref_frame_idx`: `table[ref_frame - LAST_FRAME]`). `find_mv_stack`'s
235-/// call site compares `false != false` and the flip is always inert. Ported235+/// no-sign-bias callers (this crate's own encoder, which only ever writes
236-/// anyway (never proved away, per this round's own bounds): a real236+/// `LAST_FRAME`) pass an all-`false` table, matching this stub's old
237-/// backward reference would need this to be correct on day one.237+/// always-`false` behaviour exactly.
238-fn sign_bias(_ref_frame: i8) -> bool {238+fn sign_bias(table: &SignBiasTable, ref_frame: i8) -> bool {
239- false239+ table[(ref_frame - LAST_FRAME) as usize]
240 }240 }
241 241
242+/// One `bool` per `MV_REFERENCE_FRAME` past `INTRA_FRAME`/`NONE`
243+/// (`LAST_FRAME`..=`ALTREF_FRAME`), indexed `[ref_frame - LAST_FRAME]` --
244+/// spec `ec_av1_syntax::frame::FrameHeader::ref_frame_sign_bias`'s own
245+/// shape, threaded straight through.
246+pub type SignBiasTable = [bool; 7];
247+
248+/// The all-`false` table every no-sign-bias caller (this crate's own
249+/// encoder, and every test below) passes: correct as long as no candidate
250+/// or query ever names a backward reference, exactly this module's old
251+/// hardcoded `sign_bias` stub.
252+pub const NO_SIGN_BIAS: SignBiasTable = [false; 7];
253+
242 /// libaom's `process_single_ref_mv_candidate` (mvref_common.c): folds one254 /// libaom's `process_single_ref_mv_candidate` (mvref_common.c): folds one
243 /// already-coded neighbour into the stack as a low-weight (`2`, unboosted)255 /// already-coded neighbour into the stack as a low-weight (`2`, unboosted)
244 /// filler entry, used only by the single-reference extension pass below.256 /// filler entry, used only by the single-reference extension pass below.
@@ -257,13 +269,14 @@ fn sign_bias(_ref_frame: i8) -> bool {
257 fn process_single_ref_mv_candidate(269 fn process_single_ref_mv_candidate(
258 candidate: &MiInfo,270 candidate: &MiInfo,
259 ref_frame: i8,271 ref_frame: i8,
272+ sign_bias_table: &SignBiasTable,
260 candidates: &mut Vec<StackEntry>,273 candidates: &mut Vec<StackEntry>,
261 ) {274 ) {
262 if !candidate.is_inter {275 if !candidate.is_inter {
263 return;276 return;
264 }277 }
265 let mut this_mv = candidate.mv;278 let mut this_mv = candidate.mv;
266- if sign_bias(candidate.ref_frame) != sign_bias(ref_frame) {279+ if sign_bias(sign_bias_table, candidate.ref_frame) != sign_bias(sign_bias_table, ref_frame) {
267 this_mv = (-this_mv.0, -this_mv.1);280 this_mv = (-this_mv.0, -this_mv.1);
268 }281 }
269 if !candidates.iter().any(|e| e.mv == this_mv) {282 if !candidates.iter().any(|e| e.mv == this_mv) {
@@ -510,6 +523,36 @@ pub fn find_mv_stack(
510 ref_frame: i8,523 ref_frame: i8,
511 mi_cols: usize,524 mi_cols: usize,
512 mi_rows: usize,525 mi_rows: usize,
526+) -> MvStack {
527+ find_mv_stack_with_sign_bias(
528+ grid,
529+ mi_row,
530+ mi_col,
531+ bw4,
532+ bh4,
533+ ref_frame,
534+ mi_cols,
535+ mi_rows,
536+ &NO_SIGN_BIAS,
537+ )
538+}
539+
540+/// [`find_mv_stack`], with the frame header's real `ref_frame_sign_bias`
541+/// (lane-av1refs: `BWDREF_FRAME`/`ALTREF2_FRAME`/`ALTREF_FRAME` are forward
542+/// in display order, so the single-reference extension pass's borrowed-MV
543+/// flip is no longer always inert once one of them is live next to a
544+/// backward-biased neighbour).
545+#[allow(clippy::too_many_arguments)]
546+pub fn find_mv_stack_with_sign_bias(
547+ grid: &MiGrid,
548+ mi_row: usize,
549+ mi_col: usize,
550+ bw4: usize,
551+ bh4: usize,
552+ ref_frame: i8,
553+ mi_cols: usize,
554+ mi_rows: usize,
555+ sign_bias_table: &SignBiasTable,
513 ) -> MvStack {556 ) -> MvStack {
514 let mut candidates = Vec::new();557 let mut candidates = Vec::new();
515 let mut newmv_count = 0u32;558 let mut newmv_count = 0u32;
@@ -703,7 +746,7 @@ pub fn find_mv_stack(
703 let cand = grid.get(mi_row - 1, mi_col + idx);746 let cand = grid.get(mi_row - 1, mi_col + idx);
704 let step = cand.map_or(1, |c| c.size).max(1);747 let step = cand.map_or(1, |c| c.size).max(1);
705 if let Some(c) = cand {748 if let Some(c) = cand {
706- process_single_ref_mv_candidate(c, ref_frame, &mut candidates);749+ process_single_ref_mv_candidate(c, ref_frame, sign_bias_table, &mut candidates);
707 }750 }
708 idx += step;751 idx += step;
709 }752 }
@@ -714,7 +757,7 @@ pub fn find_mv_stack(
714 let cand = grid.get(mi_row + idx, mi_col - 1);757 let cand = grid.get(mi_row + idx, mi_col - 1);
715 let step = cand.map_or(1, |c| c.size).max(1);758 let step = cand.map_or(1, |c| c.size).max(1);
716 if let Some(c) = cand {759 if let Some(c) = cand {
717- process_single_ref_mv_candidate(c, ref_frame, &mut candidates);760+ process_single_ref_mv_candidate(c, ref_frame, sign_bias_table, &mut candidates);
718 }761 }
719 idx += step;762 idx += step;
720 }763 }
crates/ec-av1/src/stream.rsmodified+25 -15
@@ -157,16 +157,17 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
157 // model needs the full affine/translation MV derivation this157 // model needs the full affine/translation MV derivation this
158 // decoder does not carry. `global_motion` is indexed `ref_frame - 1`158 // decoder does not carry. `global_motion` is indexed `ref_frame - 1`
159 // (`read_global_motion_params`'s `i` loops from `LAST_FRAME`);159 // (`read_global_motion_params`'s `i` loops from `LAST_FRAME`);
160- // lane-av1refs widens this from `[0]` (LAST_FRAME) alone to every160+ // lane-av1refs widens this from `[0, 3]` (LAST_FRAME/GOLDEN_FRAME)
161- // reference `decode_inter_block` can now select -- LAST_FRAME (index161+ // to every one of the 7 single-reference slots `decode_inter_block`
162- // 0) and GOLDEN_FRAME (index 3).162+ // can now select.
163 if header.frame_type != FrameType::Key163 if header.frame_type != FrameType::Key
164- && (header.global_motion[0].model != WarpModel::Identity164+ && header.global_motion[..7]
165- || header.global_motion[3].model != WarpModel::Identity)165+ .iter()
166+ .any(|gm| gm.model != WarpModel::Identity)
166 {167 {
167 return Err(Error::unsupported(168 return Err(Error::unsupported(
168 "AV1 decode_stream",169 "AV1 decode_stream",
169- "an inter frame whose LAST_FRAME/GOLDEN_FRAME global motion is not IDENTITY (GLOBALMV needs the full warp derivation this decoder does not carry)",170+ "an inter frame whose global motion for a single-reference frame is not IDENTITY (GLOBALMV needs the full warp derivation this decoder does not carry)",
170 ));171 ));
171 }172 }
172 // `decode_inter_block`'s `single_ref_p*` chain codes only173 // `decode_inter_block`'s `single_ref_p*` chain codes only
@@ -255,14 +256,22 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
255 "an inter frame with no key frame before it",256 "an inter frame with no key frame before it",
256 )257 )
257 })?;258 })?;
258- // `ref_frame_idx[3]` names GOLDEN_FRAME's own DPB slot (spec259+ // `ref_frame_idx[i]` names the DPB slot for `LAST_FRAME + i`
259- // 7.8/7.20 -- `ref_frame_idx` is indexed `ref_frame - LAST_FRAME`).260+ // (spec 7.8/7.20). Any of them having no picture yet is not a
260- // Unlike LAST_FRAME, GOLDEN_FRAME having no picture yet is not a261+ // stream error on its own: `decode_inter_block` only needs a
261- // stream error on its own: `decode_inter_block` only needs it262+ // given slot when a block actually selects that reference, and
262- // when a block actually selects GOLDEN_FRAME, and refuses by263+ // refuses by name there if the slot is still empty -- widened
263- // name there if the slot is still empty.264+ // (lane-av1refs) from `GOLDEN_FRAME`'s own slot alone to every
264- let golden_slot = header.ref_frame_idx[3] as usize;265+ // one of the 7 single-reference slots.
265- let golden = ref_slots.get(golden_slot).and_then(Option::as_ref);266+ let other_refs: [Option<&Picture>; 8] = std::array::from_fn(|ref_frame| {
267+ if ref_frame == 0 {
268+ None
269+ } else {
270+ ref_slots
271+ .get(header.ref_frame_idx[ref_frame - 1] as usize)
272+ .and_then(Option::as_ref)
273+ }
274+ });
266 decode_inter_frame_tile_with_cdfs(275 decode_inter_frame_tile_with_cdfs(
267 tile_bytes,276 tile_bytes,
268 header.mi_cols,277 header.mi_cols,
@@ -271,11 +280,12 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
271 header.frame_width,280 header.frame_width,
272 header.frame_height,281 header.frame_height,
273 reference,282 reference,
274- golden,283+ other_refs,
275 &header.cdef,284 &header.cdef,
276 &header.loop_filter,285 &header.loop_filter,
277 initial_cdfs,286 initial_cdfs,
278 header.allow_high_precision_mv,287 header.allow_high_precision_mv,
288+ header.ref_frame_sign_bias,
279 interp_fixed,289 interp_fixed,
280 enable_dual_filter,290 enable_dual_filter,
281 )?291 )?