Commit cf3efe55 authored by Thomas Daede's avatar Thomas Daede

Convert mv_stack to an ArrayVec.

parent 63f13f77
...@@ -32,6 +32,7 @@ use crate::util::{AlignedArray, clamp, msb, Pixel, UninitializedAlignedArray}; ...@@ -32,6 +32,7 @@ use crate::util::{AlignedArray, clamp, msb, Pixel, UninitializedAlignedArray};
use std::*; use std::*;
use std::ops::{Index, IndexMut}; use std::ops::{Index, IndexMut};
use arrayvec::*;
pub const PLANES: usize = 3; pub const PLANES: usize = 3;
...@@ -2135,7 +2136,7 @@ impl<'a> ContextWriter<'a> { ...@@ -2135,7 +2136,7 @@ impl<'a> ContextWriter<'a> {
cmp::min(cmp::max(col_offset, -(mi_col as isize)), (mi_cols - mi_col - 1) as isize) cmp::min(cmp::max(col_offset, -(mi_col as isize)), (mi_cols - mi_col - 1) as isize)
} }
fn find_matching_mv(&self, mv: MotionVector, mv_stack: &mut Vec<CandidateMV>) -> bool { fn find_matching_mv(&self, mv: MotionVector, mv_stack: &mut ArrayVec<[CandidateMV; 9]>) -> bool {
for mv_cand in mv_stack { for mv_cand in mv_stack {
if mv.row == mv_cand.this_mv.row && mv.col == mv_cand.this_mv.col { if mv.row == mv_cand.this_mv.row && mv.col == mv_cand.this_mv.col {
return true; return true;
...@@ -2144,7 +2145,7 @@ impl<'a> ContextWriter<'a> { ...@@ -2144,7 +2145,7 @@ impl<'a> ContextWriter<'a> {
false false
} }
fn find_matching_mv_and_update_weight(&self, mv: MotionVector, mv_stack: &mut Vec<CandidateMV>, weight: u32) -> bool { fn find_matching_mv_and_update_weight(&self, mv: MotionVector, mv_stack: &mut ArrayVec<[CandidateMV; 9]>, weight: u32) -> bool {
for mut mv_cand in mv_stack { for mut mv_cand in mv_stack {
if mv.row == mv_cand.this_mv.row && mv.col == mv_cand.this_mv.col { if mv.row == mv_cand.this_mv.row && mv.col == mv_cand.this_mv.col {
mv_cand.weight += weight; mv_cand.weight += weight;
...@@ -2154,8 +2155,8 @@ impl<'a> ContextWriter<'a> { ...@@ -2154,8 +2155,8 @@ impl<'a> ContextWriter<'a> {
false false
} }
fn find_matching_comp_mv_and_update_weight(&self, mvs: [MotionVector; 2], mv_stack: &mut Vec<CandidateMV>, weight: u32) -> bool { fn find_matching_comp_mv_and_update_weight(&self, mvs: [MotionVector; 2], mv_stack: &mut ArrayVec<[CandidateMV; 9]>, weight: u32) -> bool {
for mut mv_cand in mv_stack { for mv_cand in mv_stack {
if mvs[0].row == mv_cand.this_mv.row && mvs[0].col == mv_cand.this_mv.col && if mvs[0].row == mv_cand.this_mv.row && mvs[0].col == mv_cand.this_mv.col &&
mvs[1].row == mv_cand.comp_mv.row && mvs[1].col == mv_cand.comp_mv.col { mvs[1].row == mv_cand.comp_mv.row && mvs[1].col == mv_cand.comp_mv.col {
mv_cand.weight += weight; mv_cand.weight += weight;
...@@ -2165,7 +2166,7 @@ impl<'a> ContextWriter<'a> { ...@@ -2165,7 +2166,7 @@ impl<'a> ContextWriter<'a> {
false false
} }
fn add_ref_mv_candidate(&self, ref_frames: [RefType; 2], blk: &Block, mv_stack: &mut Vec<CandidateMV>, fn add_ref_mv_candidate(&self, ref_frames: [RefType; 2], blk: &Block, mv_stack: &mut ArrayVec<[CandidateMV; 9]>,
weight: u32, newmv_count: &mut usize, is_compound: bool) -> bool { weight: u32, newmv_count: &mut usize, is_compound: bool) -> bool {
if !blk.is_inter() { /* For intrabc */ if !blk.is_inter() { /* For intrabc */
false false
...@@ -2231,7 +2232,7 @@ impl<'a> ContextWriter<'a> { ...@@ -2231,7 +2232,7 @@ impl<'a> ContextWriter<'a> {
&self, &self,
blk: &Block, blk: &Block,
ref_frames: [RefType; 2], ref_frames: [RefType; 2],
mv_stack: &mut Vec<CandidateMV>, mv_stack: &mut ArrayVec<[CandidateMV; 9]>,
fi: &FrameInvariants<T>, fi: &FrameInvariants<T>,
is_compound: bool, is_compound: bool,
ref_id_count: &mut [usize; 2], ref_id_count: &mut [usize; 2],
...@@ -2286,7 +2287,7 @@ impl<'a> ContextWriter<'a> { ...@@ -2286,7 +2287,7 @@ impl<'a> ContextWriter<'a> {
fn scan_row_mbmi(&mut self, bo: BlockOffset, row_offset: isize, max_row_offs: isize, fn scan_row_mbmi(&mut self, bo: BlockOffset, row_offset: isize, max_row_offs: isize,
processed_rows: &mut isize, ref_frames: [RefType; 2], processed_rows: &mut isize, ref_frames: [RefType; 2],
mv_stack: &mut Vec<CandidateMV>, newmv_count: &mut usize, bsize: BlockSize, mv_stack: &mut ArrayVec<[CandidateMV; 9]>, newmv_count: &mut usize, bsize: BlockSize,
is_compound: bool) -> bool { is_compound: bool) -> bool {
let bc = &self.bc; let bc = &self.bc;
let target_n4_w = bsize.width_mi(); let target_n4_w = bsize.width_mi();
...@@ -2340,7 +2341,7 @@ impl<'a> ContextWriter<'a> { ...@@ -2340,7 +2341,7 @@ impl<'a> ContextWriter<'a> {
fn scan_col_mbmi(&mut self, bo: BlockOffset, col_offset: isize, max_col_offs: isize, fn scan_col_mbmi(&mut self, bo: BlockOffset, col_offset: isize, max_col_offs: isize,
processed_cols: &mut isize, ref_frames: [RefType; 2], processed_cols: &mut isize, ref_frames: [RefType; 2],
mv_stack: &mut Vec<CandidateMV>, newmv_count: &mut usize, bsize: BlockSize, mv_stack: &mut ArrayVec<[CandidateMV; 9]>, newmv_count: &mut usize, bsize: BlockSize,
is_compound: bool) -> bool { is_compound: bool) -> bool {
let bc = &self.bc; let bc = &self.bc;
...@@ -2393,7 +2394,7 @@ impl<'a> ContextWriter<'a> { ...@@ -2393,7 +2394,7 @@ impl<'a> ContextWriter<'a> {
} }
fn scan_blk_mbmi(&mut self, bo: BlockOffset, ref_frames: [RefType; 2], fn scan_blk_mbmi(&mut self, bo: BlockOffset, ref_frames: [RefType; 2],
mv_stack: &mut Vec<CandidateMV>, newmv_count: &mut usize, mv_stack: &mut ArrayVec<[CandidateMV; 9]>, newmv_count: &mut usize,
is_compound: bool) -> bool { is_compound: bool) -> bool {
if bo.x >= self.bc.blocks.cols() || bo.y >= self.bc.blocks.rows() { if bo.x >= self.bc.blocks.cols() || bo.y >= self.bc.blocks.rows() {
return false; return false;
...@@ -2404,14 +2405,14 @@ impl<'a> ContextWriter<'a> { ...@@ -2404,14 +2405,14 @@ impl<'a> ContextWriter<'a> {
self.add_ref_mv_candidate(ref_frames, &self.bc.blocks[bo], mv_stack, weight, newmv_count, is_compound) self.add_ref_mv_candidate(ref_frames, &self.bc.blocks[bo], mv_stack, weight, newmv_count, is_compound)
} }
fn add_offset(&mut self, mv_stack: &mut Vec<CandidateMV>) { fn add_offset(&mut self, mv_stack: &mut ArrayVec<[CandidateMV; 9]>) {
for mut cand_mv in mv_stack { for mut cand_mv in mv_stack {
cand_mv.weight += REF_CAT_LEVEL; cand_mv.weight += REF_CAT_LEVEL;
} }
} }
fn setup_mvref_list<T: Pixel>( fn setup_mvref_list<T: Pixel>(
&mut self, bo: BlockOffset, ref_frames: [RefType; 2], mv_stack: &mut Vec<CandidateMV>, &mut self, bo: BlockOffset, ref_frames: [RefType; 2], mv_stack: &mut ArrayVec<[CandidateMV; 9]>,
bsize: BlockSize, fi: &FrameInvariants<T>, is_compound: bool bsize: BlockSize, fi: &FrameInvariants<T>, is_compound: bool
) -> usize { ) -> usize {
let (_rf, _rf_num) = (INTRA_FRAME, 1); let (_rf, _rf_num) = (INTRA_FRAME, 1);
...@@ -2635,7 +2636,7 @@ impl<'a> ContextWriter<'a> { ...@@ -2635,7 +2636,7 @@ impl<'a> ContextWriter<'a> {
pub fn find_mvrefs<T: Pixel>( pub fn find_mvrefs<T: Pixel>(
&mut self, bo: BlockOffset, ref_frames: [RefType; 2], &mut self, bo: BlockOffset, ref_frames: [RefType; 2],
mv_stack: &mut Vec<CandidateMV>, bsize: BlockSize, mv_stack: &mut ArrayVec<[CandidateMV; 9]>, bsize: BlockSize,
fi: &FrameInvariants<T>, is_compound: bool fi: &FrameInvariants<T>, is_compound: bool
) -> usize { ) -> usize {
assert!(ref_frames[0] != NONE_FRAME); assert!(ref_frames[0] != NONE_FRAME);
......
...@@ -40,6 +40,7 @@ use std::io::Write; ...@@ -40,6 +40,7 @@ use std::io::Write;
use std::io::Read; use std::io::Read;
use std::sync::Arc; use std::sync::Arc;
use std::fs::File; use std::fs::File;
use arrayvec::*;
pub static TEMPORAL_DELIMITER: [u8; 2] = [0x12, 0x00]; pub static TEMPORAL_DELIMITER: [u8; 2] = [0x12, 0x00];
...@@ -1510,7 +1511,7 @@ pub fn encode_block_with_modes<T: Pixel>( ...@@ -1510,7 +1511,7 @@ pub fn encode_block_with_modes<T: Pixel>(
debug_assert!((tx_size, tx_type) == debug_assert!((tx_size, tx_type) ==
rdo_tx_size_type(fi, ts, cw, bsize, tile_bo, mode_luma, ref_frames, mvs, skip)); rdo_tx_size_type(fi, ts, cw, bsize, tile_bo, mode_luma, ref_frames, mvs, skip));
let mut mv_stack = Vec::new(); let mut mv_stack = ArrayVec::<[CandidateMV; 9]>::new();
let is_compound = ref_frames[1] != NONE_FRAME; let is_compound = ref_frames[1] != NONE_FRAME;
let mode_context = cw.find_mvrefs(tile_bo, ref_frames, &mut mv_stack, bsize, fi, is_compound); let mode_context = cw.find_mvrefs(tile_bo, ref_frames, &mut mv_stack, bsize, fi, is_compound);
...@@ -1838,7 +1839,7 @@ fn encode_partition_topdown<T: Pixel>( ...@@ -1838,7 +1839,7 @@ fn encode_partition_topdown<T: Pixel>(
let (tx_size, tx_type) = let (tx_size, tx_type) =
rdo_tx_size_type(fi, ts, cw, bsize, tile_bo, mode_luma, ref_frames, mvs, skip); rdo_tx_size_type(fi, ts, cw, bsize, tile_bo, mode_luma, ref_frames, mvs, skip);
let mut mv_stack = Vec::new(); let mut mv_stack = ArrayVec::<[CandidateMV; 9]>::new();
let is_compound = ref_frames[1] != NONE_FRAME; let is_compound = ref_frames[1] != NONE_FRAME;
let mode_context = cw.find_mvrefs(tile_bo, ref_frames, &mut mv_stack, bsize, fi, is_compound); let mode_context = cw.find_mvrefs(tile_bo, ref_frames, &mut mv_stack, bsize, fi, is_compound);
......
...@@ -511,7 +511,7 @@ pub fn rdo_mode_decision<T: Pixel>( ...@@ -511,7 +511,7 @@ pub fn rdo_mode_decision<T: Pixel>(
}; };
for (i, &ref_frames) in ref_frames_set.iter().enumerate() { for (i, &ref_frames) in ref_frames_set.iter().enumerate() {
let mut mv_stack: Vec<CandidateMV> = Vec::new(); let mut mv_stack = ArrayVec::<[CandidateMV; 9]>::new();
mode_contexts.push(cw.find_mvrefs(tile_bo, ref_frames, &mut mv_stack, bsize, fi, false)); mode_contexts.push(cw.find_mvrefs(tile_bo, ref_frames, &mut mv_stack, bsize, fi, false));
if fi.frame_type == FrameType::INTER { if fi.frame_type == FrameType::INTER {
...@@ -571,7 +571,7 @@ pub fn rdo_mode_decision<T: Pixel>( ...@@ -571,7 +571,7 @@ pub fn rdo_mode_decision<T: Pixel>(
let mv0 = mvs_from_me[r0][0]; let mv0 = mvs_from_me[r0][0];
let mv1 = mvs_from_me[r1][0]; let mv1 = mvs_from_me[r1][0];
mvs_from_me.push([mv0, mv1]); mvs_from_me.push([mv0, mv1]);
let mut mv_stack: Vec<CandidateMV> = Vec::new(); let mut mv_stack = ArrayVec::<[CandidateMV; 9]>::new();
mode_contexts.push(cw.find_mvrefs(tile_bo, ref_frames, &mut mv_stack, bsize, fi, true)); mode_contexts.push(cw.find_mvrefs(tile_bo, ref_frames, &mut mv_stack, bsize, fi, true));
for &x in RAV1E_INTER_COMPOUND_MODES { for &x in RAV1E_INTER_COMPOUND_MODES {
mode_set.push((x, ref_frames_set.len() - 1)); mode_set.push((x, ref_frames_set.len() - 1));
...@@ -590,7 +590,7 @@ pub fn rdo_mode_decision<T: Pixel>( ...@@ -590,7 +590,7 @@ pub fn rdo_mode_decision<T: Pixel>(
mode_set_chroma: &[PredictionMode], mode_set_chroma: &[PredictionMode],
luma_mode_is_intra: bool, luma_mode_is_intra: bool,
mode_context: usize, mode_context: usize,
mv_stack: &Vec<CandidateMV>| { mv_stack: &ArrayVec<[CandidateMV; 9]>| {
let (tx_size, mut tx_type) = rdo_tx_size_type( let (tx_size, mut tx_type) = rdo_tx_size_type(
fi, ts, cw, bsize, tile_bo, luma_mode, ref_frames, mvs, false, fi, ts, cw, bsize, tile_bo, luma_mode, ref_frames, mvs, false,
); );
...@@ -628,7 +628,7 @@ pub fn rdo_mode_decision<T: Pixel>( ...@@ -628,7 +628,7 @@ pub fn rdo_mode_decision<T: Pixel>(
tx_size, tx_size,
tx_type, tx_type,
mode_context, mode_context,
mv_stack, &mv_stack,
rdo_type, rdo_type,
!needs_rec !needs_rec
); );
...@@ -705,7 +705,7 @@ pub fn rdo_mode_decision<T: Pixel>( ...@@ -705,7 +705,7 @@ pub fn rdo_mode_decision<T: Pixel>(
PredictionMode::NEW_NEARESTMV => [mvs_from_me[i][0], mv_stacks[i][0].comp_mv], PredictionMode::NEW_NEARESTMV => [mvs_from_me[i][0], mv_stacks[i][0].comp_mv],
_ => [MotionVector::default(); 2] _ => [MotionVector::default(); 2]
}; };
let mode_set_chroma = vec![luma_mode]; let mode_set_chroma = ArrayVec::from([luma_mode]);
luma_chroma_mode_rdo(luma_mode, ts, cw, &mut best, mvs, ref_frames_set[i], &mode_set_chroma, false, luma_chroma_mode_rdo(luma_mode, ts, cw, &mut best, mvs, ref_frames_set[i], &mode_set_chroma, false,
mode_contexts[i], &mv_stacks[i]); mode_contexts[i], &mv_stacks[i]);
...@@ -800,7 +800,7 @@ pub fn rdo_mode_decision<T: Pixel>( ...@@ -800,7 +800,7 @@ pub fn rdo_mode_decision<T: Pixel>(
mode_set_chroma.push(PredictionMode::DC_PRED); mode_set_chroma.push(PredictionMode::DC_PRED);
} }
luma_chroma_mode_rdo(luma_mode, ts, cw, &mut best, mvs, ref_frames, &mode_set_chroma, true, luma_chroma_mode_rdo(luma_mode, ts, cw, &mut best, mvs, ref_frames, &mode_set_chroma, true,
0, &Vec::new()); 0, &ArrayVec::<[CandidateMV; 9]>::new());
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment