diff --git a/crates/ec-vp9/src/decode.rs b/crates/ec-vp9/src/decode.rs index 0600c4cb..a4aa0105 100644 --- a/crates/ec-vp9/src/decode.rs +++ b/crates/ec-vp9/src/decode.rs @@ -197,8 +197,7 @@ pub struct Decoder { prev_mvs: Vec, prev_seg: Vec, last: LastFrameFacts, - /// Live only while an inter frame is being parsed. - iw: Option, + iw: InterWalk, /// `twd->extend_and_predict_buf`: the per-prediction bordered reference /// window built when a block's read leaves the reference frame. mc_scratch: Vec, @@ -247,6 +246,7 @@ struct LastFrameFacts { } /// State of one inter-syntax frame walk. +#[derive(Default)] struct InterWalk { ifs: crate::inter::InterFrameState, sign_bias: [bool; 4], @@ -274,7 +274,7 @@ impl Decoder { prev_mvs: Vec::new(), prev_seg: Vec::new(), last: LastFrameFacts::default(), - iw: None, + iw: InterWalk::default(), mc_scratch: Vec::new(), mc_temp: vec![0; 64 * 135 + 64 * 64], threads: default_threads(), @@ -507,7 +507,7 @@ impl Decoder { if hdr.error_resilient_mode || self.prev_seg.len() != mi_cols * mi_rows { self.prev_seg.clear(); } - self.iw = Some(InterWalk { + self.iw = InterWalk { ifs, sign_bias, use_prev, @@ -516,7 +516,7 @@ impl Decoder { prev_seg: std::mem::take(&mut self.prev_seg), prev_mvs: std::mem::take(&mut self.prev_mvs), tile_col_end: mi_cols, - }); + }; let data: &[u8] = frame .get(hdr_start + hdr.header_size_in_bytes as usize..) @@ -555,7 +555,7 @@ impl Decoder { adapt_mv_probs(&mut self.ctx, &pre, &counts, hdr.allow_high_precision_mv); } - let w = self.iw.take().expect("inter walk state"); + let w = std::mem::take(&mut self.iw); self.prev_mvs = w.mvs; if hdr.segmentation.enabled { self.prev_seg = w.seg_map; @@ -649,7 +649,7 @@ impl Decoder { 2 => 1u8, _ => 0u8, }; - let w = self.iw.as_mut().expect("inter walk state"); + let w = &mut self.iw; let prev_seg = std::mem::take(&mut w.prev_seg); let prev_mvs = std::mem::take(&mut w.prev_mvs); let ctx = crate::inter::InterBlockCtx { @@ -2127,9 +2127,9 @@ impl Decoder { copy_mi_cols(&mut grids.otx, &g.otx, mi_cols, mi_rows, lo, hi); copy_mi_cols(&mut grids.skip_inter, &g.skip_inter, mi_cols, mi_rows, lo, hi); copy_mi_cols(&mut grids.seg, &g.seg, mi_cols, mi_rows, lo, hi); - if let (Some(dst), Some(src)) = (self.iw.as_mut(), wk.iw.as_ref()) { - copy_mi_cols(&mut dst.mvs, &src.mvs, mi_cols, mi_rows, lo, hi); - copy_mi_cols(&mut dst.seg_map, &src.seg_map, mi_cols, mi_rows, lo, hi); + if !self.iw.mvs.is_empty() { + copy_mi_cols(&mut self.iw.mvs, &wk.iw.mvs, mi_cols, mi_rows, lo, hi); + copy_mi_cols(&mut self.iw.seg_map, &wk.iw.seg_map, mi_cols, mi_rows, lo, hi); } if let (Some(dst), Some(src)) = (self.planes.as_mut(), wk.planes.as_ref()) { copy_plane_cols(dst, src, lo, hi, hi == mi_cols); @@ -2170,9 +2170,7 @@ impl Decoder { mi.above_seg.fill(0); for &tc in cols { let (col_lo, col_hi) = tile_col_span(hdr, tc); - if let Some(w) = self.iw.as_mut() { - w.tile_col_end = col_hi; - } + self.iw.tile_col_end = col_hi; for tr in 0..tile_rows { let sb64_rows = mi_rows.div_ceil(SB_MI); let row_lo = ((sb64_rows * tr) >> hdr.tile_info.rows_log2) * SB_MI; @@ -2225,16 +2223,16 @@ impl Decoder { prev_mvs: Vec::new(), prev_seg: Vec::new(), last: self.last, - iw: self.iw.as_ref().map(|w| InterWalk { - ifs: w.ifs, - sign_bias: w.sign_bias, - use_prev: w.use_prev, + iw: InterWalk { + ifs: self.iw.ifs, + sign_bias: self.iw.sign_bias, + use_prev: self.iw.use_prev, seg_map: vec![0; n], mvs: vec![crate::inter::MvRef::default(); n], - prev_seg: w.prev_seg.clone(), - prev_mvs: w.prev_mvs.clone(), - tile_col_end: w.tile_col_end, - }), + prev_seg: self.iw.prev_seg.clone(), + prev_mvs: self.iw.prev_mvs.clone(), + tile_col_end: self.iw.tile_col_end, + }, mc_scratch: Vec::new(), mc_temp: vec![0; 64 * 135 + 64 * 64], threads: 1,