forge
Explore
Log in

Don't you dare go Hollow

U4: ec-vp9 InterWalk is a plain value on Decoder (Default, no Option); keyframes carry an empty walk, and the tile merge copies walk vectors only when the walk is sized

Browse files at this commit

7f0151d1c3c70555ec05240c328655c8f8f247c8Ahmet Kaan GümüşParent: 4288c92
crates/ec-vp9/src/decode.rsmodified+19 -21
@@ -197,8 +197,7 @@ pub struct Decoder {
197 prev_mvs: Vec<crate::inter::MvRef>,197 prev_mvs: Vec<crate::inter::MvRef>,
198 prev_seg: Vec<u8>,198 prev_seg: Vec<u8>,
199 last: LastFrameFacts,199 last: LastFrameFacts,
200- /// Live only while an inter frame is being parsed.200+ iw: InterWalk,
201- iw: Option<InterWalk>,
202 /// `twd->extend_and_predict_buf`: the per-prediction bordered reference201 /// `twd->extend_and_predict_buf`: the per-prediction bordered reference
203 /// window built when a block's read leaves the reference frame.202 /// window built when a block's read leaves the reference frame.
204 mc_scratch: Vec<Sample>,203 mc_scratch: Vec<Sample>,
@@ -247,6 +246,7 @@ struct LastFrameFacts {
247 }246 }
248 247
249 /// State of one inter-syntax frame walk.248 /// State of one inter-syntax frame walk.
249+#[derive(Default)]
250 struct InterWalk {250 struct InterWalk {
251 ifs: crate::inter::InterFrameState,251 ifs: crate::inter::InterFrameState,
252 sign_bias: [bool; 4],252 sign_bias: [bool; 4],
@@ -274,7 +274,7 @@ impl Decoder {
274 prev_mvs: Vec::new(),274 prev_mvs: Vec::new(),
275 prev_seg: Vec::new(),275 prev_seg: Vec::new(),
276 last: LastFrameFacts::default(),276 last: LastFrameFacts::default(),
277- iw: None,277+ iw: InterWalk::default(),
278 mc_scratch: Vec::new(),278 mc_scratch: Vec::new(),
279 mc_temp: vec![0; 64 * 135 + 64 * 64],279 mc_temp: vec![0; 64 * 135 + 64 * 64],
280 threads: default_threads(),280 threads: default_threads(),
@@ -507,7 +507,7 @@ impl Decoder {
507 if hdr.error_resilient_mode || self.prev_seg.len() != mi_cols * mi_rows {507 if hdr.error_resilient_mode || self.prev_seg.len() != mi_cols * mi_rows {
508 self.prev_seg.clear();508 self.prev_seg.clear();
509 }509 }
510- self.iw = Some(InterWalk {510+ self.iw = InterWalk {
511 ifs,511 ifs,
512 sign_bias,512 sign_bias,
513 use_prev,513 use_prev,
@@ -516,7 +516,7 @@ impl Decoder {
516 prev_seg: std::mem::take(&mut self.prev_seg),516 prev_seg: std::mem::take(&mut self.prev_seg),
517 prev_mvs: std::mem::take(&mut self.prev_mvs),517 prev_mvs: std::mem::take(&mut self.prev_mvs),
518 tile_col_end: mi_cols,518 tile_col_end: mi_cols,
519- });519+ };
520 520
521 let data: &[u8] = frame521 let data: &[u8] = frame
522 .get(hdr_start + hdr.header_size_in_bytes as usize..)522 .get(hdr_start + hdr.header_size_in_bytes as usize..)
@@ -555,7 +555,7 @@ impl Decoder {
555 adapt_mv_probs(&mut self.ctx, &pre, &counts, hdr.allow_high_precision_mv);555 adapt_mv_probs(&mut self.ctx, &pre, &counts, hdr.allow_high_precision_mv);
556 }556 }
557 557
558- let w = self.iw.take().expect("inter walk state");558+ let w = std::mem::take(&mut self.iw);
559 self.prev_mvs = w.mvs;559 self.prev_mvs = w.mvs;
560 if hdr.segmentation.enabled {560 if hdr.segmentation.enabled {
561 self.prev_seg = w.seg_map;561 self.prev_seg = w.seg_map;
@@ -649,7 +649,7 @@ impl Decoder {
649 2 => 1u8,649 2 => 1u8,
650 _ => 0u8,650 _ => 0u8,
651 };651 };
652- let w = self.iw.as_mut().expect("inter walk state");652+ let w = &mut self.iw;
653 let prev_seg = std::mem::take(&mut w.prev_seg);653 let prev_seg = std::mem::take(&mut w.prev_seg);
654 let prev_mvs = std::mem::take(&mut w.prev_mvs);654 let prev_mvs = std::mem::take(&mut w.prev_mvs);
655 let ctx = crate::inter::InterBlockCtx {655 let ctx = crate::inter::InterBlockCtx {
@@ -2127,9 +2127,9 @@ impl Decoder {
2127 copy_mi_cols(&mut grids.otx, &g.otx, mi_cols, mi_rows, lo, hi);2127 copy_mi_cols(&mut grids.otx, &g.otx, mi_cols, mi_rows, lo, hi);
2128 copy_mi_cols(&mut grids.skip_inter, &g.skip_inter, mi_cols, mi_rows, lo, hi);2128 copy_mi_cols(&mut grids.skip_inter, &g.skip_inter, mi_cols, mi_rows, lo, hi);
2129 copy_mi_cols(&mut grids.seg, &g.seg, mi_cols, mi_rows, lo, hi);2129 copy_mi_cols(&mut grids.seg, &g.seg, mi_cols, mi_rows, lo, hi);
2130- if let (Some(dst), Some(src)) = (self.iw.as_mut(), wk.iw.as_ref()) {2130+ if !self.iw.mvs.is_empty() {
2131- copy_mi_cols(&mut dst.mvs, &src.mvs, mi_cols, mi_rows, lo, hi);2131+ copy_mi_cols(&mut self.iw.mvs, &wk.iw.mvs, mi_cols, mi_rows, lo, hi);
2132- copy_mi_cols(&mut dst.seg_map, &src.seg_map, mi_cols, mi_rows, lo, hi);2132+ copy_mi_cols(&mut self.iw.seg_map, &wk.iw.seg_map, mi_cols, mi_rows, lo, hi);
2133 }2133 }
2134 if let (Some(dst), Some(src)) = (self.planes.as_mut(), wk.planes.as_ref()) {2134 if let (Some(dst), Some(src)) = (self.planes.as_mut(), wk.planes.as_ref()) {
2135 copy_plane_cols(dst, src, lo, hi, hi == mi_cols);2135 copy_plane_cols(dst, src, lo, hi, hi == mi_cols);
@@ -2170,9 +2170,7 @@ impl Decoder {
2170 mi.above_seg.fill(0);2170 mi.above_seg.fill(0);
2171 for &tc in cols {2171 for &tc in cols {
2172 let (col_lo, col_hi) = tile_col_span(hdr, tc);2172 let (col_lo, col_hi) = tile_col_span(hdr, tc);
2173- if let Some(w) = self.iw.as_mut() {2173+ self.iw.tile_col_end = col_hi;
2174- w.tile_col_end = col_hi;
2175- }
2176 for tr in 0..tile_rows {2174 for tr in 0..tile_rows {
2177 let sb64_rows = mi_rows.div_ceil(SB_MI);2175 let sb64_rows = mi_rows.div_ceil(SB_MI);
2178 let row_lo = ((sb64_rows * tr) >> hdr.tile_info.rows_log2) * SB_MI;2176 let row_lo = ((sb64_rows * tr) >> hdr.tile_info.rows_log2) * SB_MI;
@@ -2225,16 +2223,16 @@ impl Decoder {
2225 prev_mvs: Vec::new(),2223 prev_mvs: Vec::new(),
2226 prev_seg: Vec::new(),2224 prev_seg: Vec::new(),
2227 last: self.last,2225 last: self.last,
2228- iw: self.iw.as_ref().map(|w| InterWalk {2226+ iw: InterWalk {
2229- ifs: w.ifs,2227+ ifs: self.iw.ifs,
2230- sign_bias: w.sign_bias,2228+ sign_bias: self.iw.sign_bias,
2231- use_prev: w.use_prev,2229+ use_prev: self.iw.use_prev,
2232 seg_map: vec![0; n],2230 seg_map: vec![0; n],
2233 mvs: vec![crate::inter::MvRef::default(); n],2231 mvs: vec![crate::inter::MvRef::default(); n],
2234- prev_seg: w.prev_seg.clone(),2232+ prev_seg: self.iw.prev_seg.clone(),
2235- prev_mvs: w.prev_mvs.clone(),2233+ prev_mvs: self.iw.prev_mvs.clone(),
2236- tile_col_end: w.tile_col_end,2234+ tile_col_end: self.iw.tile_col_end,
2237- }),2235+ },
2238 mc_scratch: Vec::new(),2236 mc_scratch: Vec::new(),
2239 mc_temp: vec![0; 64 * 135 + 64 * 64],2237 mc_temp: vec![0; 64 * 135 + 64 * 64],
2240 threads: 1,2238 threads: 1,