Commit 1e090559 authored by Raphaël Zumer's avatar Raphaël Zumer
Browse files

Move Sequence into FrameInvariants

parent 8969d150
......@@ -46,11 +46,12 @@ fn write_b_bench(b: &mut Bencher, tx_size: TxSize, qindex: usize) {
}
let config =
EncoderConfig { quantizer: qindex, speed_settings: SpeedSettings::from_preset(10), ..Default::default() };
let mut fi = FrameInvariants::new(1024, 1024, config);
let sequence = Sequence::new(&Default::default());
let mut fi = FrameInvariants::new(1024, 1024, config, sequence);
let mut w = ec::WriterEncoder::new();
let fc = CDFContext::new(fi.base_q_idx);
let bc = BlockContext::new(fi.sb_width * 16, fi.sb_height * 16);
let mut fs = FrameState::new(&fi, Default::default());
let mut fs = FrameState::new(&fi);
// For now, restoration unit size is locked to superblock size.
let mut cw = ContextWriter::new(fc, bc);
......@@ -89,7 +90,6 @@ fn write_b_bench(b: &mut Bencher, tx_size: TxSize, qindex: usize) {
tx_size.block_size(),
&po,
false,
8,
ac,
0,
false
......@@ -111,11 +111,12 @@ fn cdef_frame(c: &mut Criterion) {
fn cdef_frame_bench(b: &mut Bencher, w: usize, h: usize) {
let config =
EncoderConfig { quantizer: 100, speed_settings: SpeedSettings::from_preset(10), ..Default::default() };
let fi = FrameInvariants::new(w, h, config);
let sequence = Sequence::new(&Default::default());
let fi = FrameInvariants::new(w, h, config, sequence);
let mut bc = BlockContext::new(fi.sb_width * 16, fi.sb_height * 16);
let mut fs = FrameState::new(&fi, Default::default());
let mut fs = FrameState::new(&fi);
b.iter(|| cdef_filter_frame(&fi, &mut fs.rec, &mut bc, 8));
b.iter(|| cdef_filter_frame(&fi, &mut fs.rec, &mut bc));
}
fn cfl_rdo(c: &mut Criterion) {
......@@ -133,10 +134,11 @@ fn cfl_rdo(c: &mut Criterion) {
fn cfl_rdo_bench(b: &mut Bencher, bsize: BlockSize) {
let config =
EncoderConfig { quantizer: 100, speed_settings: SpeedSettings::from_preset(10), ..Default::default() };
let fi = FrameInvariants::new(1024, 1024, config);
let mut fs = FrameState::new(&fi, Default::default());
let sequence = Sequence::new(&Default::default());
let fi = FrameInvariants::new(1024, 1024, config, sequence );
let mut fs = FrameState::new(&fi);
let offset = BlockOffset { x: 1, y: 1 };
b.iter(|| rdo_cfl_alpha(&mut fs, &offset, bsize, 8, Default::default()))
b.iter(|| rdo_cfl_alpha(&mut fs, &offset, bsize, fi.sequence.bit_depth, fi.sequence.chroma_sampling))
}
criterion_group!(intra_prediction, predict::pred_bench,);
......
......@@ -291,12 +291,13 @@ impl Config {
}
pub fn new_context(&self) -> Context {
let seq = Sequence::new(&self.frame_info);
let fi = FrameInvariants::new(
self.frame_info.width,
self.frame_info.height,
self.enc
self.enc,
seq,
);
let seq = Sequence::new(&self.frame_info);
#[cfg(feature = "aom")]
unsafe {
......@@ -306,7 +307,6 @@ impl Config {
Context {
fi,
seq,
frame_count: 0,
frames_to_be_coded: 0,
idx: 0,
......@@ -322,7 +322,6 @@ impl Config {
pub struct Context {
fi: FrameInvariants,
seq: Sequence,
// timebase: Rational,
frame_count: u64,
frames_to_be_coded: u64,
......@@ -370,7 +369,7 @@ impl fmt::Display for Packet {
impl Context {
pub fn new_frame(&self) -> Arc<Frame> {
Arc::new(Frame::new(self.fi.padded_w, self.fi.padded_h, self.seq.chroma_sampling))
Arc::new(Frame::new(self.fi.padded_w, self.fi.padded_h, self.fi.sequence.chroma_sampling))
}
pub fn send_frame<F>(&mut self, frame: F) -> Result<(), EncoderStatus>
......@@ -423,7 +422,7 @@ impl Context {
Ok(buf)
}
sequence_header_inner(&self.seq).unwrap()
sequence_header_inner(&self.fi.sequence).unwrap()
}
fn next_keyframe(&self) -> u64 {
......@@ -503,15 +502,15 @@ impl Context {
if self.fi.show_existing_frame {
self.idx += 1;
let mut fs = FrameState::new(&self.fi, self.seq.chroma_sampling);
let mut fs = FrameState::new(&self.fi);
let data = encode_frame(&mut self.seq, &mut self.fi, &mut fs);
let data = encode_frame(&mut self.fi, &mut fs);
let rec = if self.fi.show_frame { Some(fs.rec) } else { None };
let mut psnr = None;
if self.fi.config.show_psnr {
if let Some(ref rec) = rec {
psnr = Some(calculate_frame_psnr(&*fs.input, rec, self.seq.bit_depth));
psnr = Some(calculate_frame_psnr(&*fs.input, rec, self.fi.sequence.bit_depth));
}
}
......@@ -521,10 +520,9 @@ impl Context {
self.idx += 1;
if let Some(frame) = f {
let mut fs = FrameState::new_with_frame(&self.fi, frame.clone(),
self.seq.chroma_sampling);
let mut fs = FrameState::new_with_frame(&self.fi, frame.clone());
let data = encode_frame(&mut self.seq, &mut self.fi, &mut fs);
let data = encode_frame(&mut self.fi, &mut fs);
self.packet_data.extend(data);
fs.rec.pad(self.fi.width, self.fi.height);
......@@ -541,7 +539,7 @@ impl Context {
let mut psnr = None;
if self.fi.config.show_psnr {
if let Some(ref rec) = rec {
psnr = Some(calculate_frame_psnr(&*frame, rec, self.seq.bit_depth));
psnr = Some(calculate_frame_psnr(&*frame, rec, self.fi.sequence.bit_depth));
}
}
......
......@@ -243,10 +243,9 @@ pub fn cdef_filter_superblock(fi: &FrameInvariants,
bc_global: &mut BlockContext,
sbo: &SuperBlockOffset,
sbo_global: &SuperBlockOffset,
bit_depth: usize,
cdef_index: u8,
cdef_dirs: &CdefDirections) {
let coeff_shift = bit_depth as i32 - 8;
let coeff_shift = fi.sequence.bit_depth as i32 - 8;
let cdef_damping = fi.cdef_damping as i32;
let cdef_y_strength = fi.cdef_y_strengths[cdef_index as usize];
let cdef_uv_strength = fi.cdef_uv_strengths[cdef_index as usize];
......@@ -324,7 +323,7 @@ pub fn cdef_filter_superblock(fi: &FrameInvariants,
// CDEF parameters are stored for each 64 by 64 block of pixels.
// The CDEF filter is applied on each 8 by 8 block of pixels.
// Reference: http://av1-spec.argondesign.com/av1-spec/av1-spec.html#cdef-process
pub fn cdef_filter_frame(fi: &FrameInvariants, rec: &mut Frame, bc: &mut BlockContext, bit_depth: usize) {
pub fn cdef_filter_frame(fi: &FrameInvariants, rec: &mut Frame, bc: &mut BlockContext) {
// Each filter block is 64x64, except right and/or bottom for non-multiple-of-64 sizes.
// FIXME: 128x128 SB support will break this, we need FilterBlockOffset etc.
......@@ -384,8 +383,8 @@ pub fn cdef_filter_frame(fi: &FrameInvariants, rec: &mut Frame, bc: &mut BlockCo
for fbx in 0..fb_width {
let sbo = SuperBlockOffset { x: fbx, y: fby };
let cdef_index = bc.at(&sbo.block_offset(0, 0)).cdef_index;
let cdef_dirs = cdef_analyze_superblock(&mut cdef_frame, bc, &sbo, &sbo, bit_depth);
cdef_filter_superblock(fi, &mut cdef_frame, rec, bc, &sbo, &sbo, bit_depth, cdef_index, &cdef_dirs);
let cdef_dirs = cdef_analyze_superblock(&mut cdef_frame, bc, &sbo, &sbo, fi.sequence.bit_depth);
cdef_filter_superblock(fi, &mut cdef_frame, rec, bc, &sbo, &sbo, cdef_index, &cdef_dirs);
}
}
}
......@@ -1339,13 +1339,11 @@ fn sse_optimize(fs: &mut FrameState, bc: &mut BlockContext, bit_depth: usize) {
}
pub fn deblock_filter_optimize(
fi: &FrameInvariants, fs: &mut FrameState, bc: &mut BlockContext,
bit_depth: usize
) {
fi: &FrameInvariants, fs: &mut FrameState, bc: &mut BlockContext) {
if fi.config.speed_settings.fast_deblock {
let q = ac_q(fi.base_q_idx, 0, bit_depth) as i32;
let q = ac_q(fi.base_q_idx, 0, fi.sequence.bit_depth) as i32;
let level = clamp(
match bit_depth {
match fi.sequence.bit_depth {
8 =>
if fi.frame_type == FrameType::KEY {
q * 17563 - 421574 + (1 << 18 >> 1) >> 18
......@@ -1378,6 +1376,6 @@ pub fn deblock_filter_optimize(
fs.deblock.levels[2] = level;
fs.deblock.levels[3] = level;
} else {
sse_optimize(fs, bc, bit_depth);
sse_optimize(fs, bc, fi.sequence.bit_depth);
}
}
This diff is collapsed.
......@@ -16,7 +16,6 @@ use context::ContextWriter;
use context::SuperBlockOffset;
use context::PLANES;
use context::MAX_SB_SIZE;
use encoder::Sequence;
use plane::Plane;
use plane::PlaneConfig;
use plane::PlaneOffset;
......@@ -403,7 +402,7 @@ pub struct RestorationState {
}
impl RestorationState {
pub fn new(seq: &Sequence, fi: &FrameInvariants, input: &Frame) -> Self {
pub fn new(fi: &FrameInvariants, input: &Frame) -> Self {
// unlike the other loop filters that operate over the padded
// frame dimensions, restoration filtering and source pixel
// accesses are clipped to the original frame dimensions
......@@ -421,7 +420,7 @@ impl RestorationState {
clipped_cfg[2].height = fi.height + (1 << ydec >> 1) >> ydec;
// Currrently opt for smallest possible restoration unit size
let lrf_y_shift = if seq.use_128x128_superblock {1} else {2};
let lrf_y_shift = if fi.sequence.use_128x128_superblock {1} else {2};
let lrf_uv_shift = lrf_y_shift + if xdec>0 && ydec>0 {1} else {0};
let lrf_type: [u8; PLANES] = [RESTORE_SWITCHABLE, RESTORE_SWITCHABLE, RESTORE_SWITCHABLE];
let unit_size: [usize; PLANES] = [RESTORATION_TILESIZE_MAX >> lrf_y_shift,
......@@ -448,9 +447,7 @@ impl RestorationState {
}
pub fn lrf_optimize_superblock(&mut self, _sbo: &SuperBlockOffset, _fi: &FrameInvariants,
_fs: &FrameState, _cw: &mut ContextWriter,
_bit_depth: usize) {
_fs: &FrameState, _cw: &mut ContextWriter) {
}
pub fn lrf_filter_frame(&mut self, fs: &mut FrameState, pre_cdef: &Frame,
......
......@@ -145,7 +145,7 @@ fn get_mv_range(fi: &FrameInvariants, bo: &BlockOffset, blk_w: usize, blk_h: usi
pub fn motion_estimation(
fi: &FrameInvariants, fs: &FrameState, bsize: BlockSize, bo: &BlockOffset,
ref_frame: usize, cmv: MotionVector, bit_depth: usize, pmv: &[MotionVector; 2]
ref_frame: usize, cmv: MotionVector, pmv: &[MotionVector; 2]
) -> MotionVector {
match fi.rec_buffer.frames[fi.ref_frames[ref_frame - LAST_FRAME] as usize] {
Some(ref rec) => {
......@@ -166,7 +166,7 @@ pub fn motion_estimation(
let mut best_mv = MotionVector { row: 0, col: 0 };
// 0.5 is a fudge factor
let lambda = (get_lambda_sqrt(fi, bit_depth) * 256.0 * 0.5) as u32;
let lambda = (get_lambda_sqrt(fi) * 256.0 * 0.5) as u32;
full_search(
x_lo,
......@@ -181,7 +181,7 @@ pub fn motion_estimation(
&mut lowest_cost,
&po,
2,
bit_depth,
fi.sequence.bit_depth,
lambda,
pmv,
fi.allow_high_precision_mv
......@@ -228,15 +228,14 @@ pub fn motion_estimation(
blk_w,
blk_h,
[ref_frame, NONE_FRAME],
[cand_mv, MotionVector { row: 0, col: 0 }],
bit_depth
[cand_mv, MotionVector { row: 0, col: 0 }]
);
}
let plane_org = fs.input.planes[0].slice(&po);
let plane_ref = tmp_plane.slice(&PlaneOffset { x: 0, y: 0 });
let sad = get_sad(&plane_org, &plane_ref, blk_h, blk_w, bit_depth);
let sad = get_sad(&plane_org, &plane_ref, blk_h, blk_w, fi.sequence.bit_depth);
let rate1 = get_mv_rate(cand_mv, pmv[0], fi.allow_high_precision_mv);
let rate2 = get_mv_rate(cand_mv, pmv[1], fi.allow_high_precision_mv);
......@@ -312,7 +311,7 @@ fn get_mv_rate(a: MotionVector, b: MotionVector, allow_high_precision_mv: bool)
pub fn estimate_motion_ss4(
fi: &FrameInvariants, fs: &FrameState, bsize: BlockSize, ref_idx: usize,
bo: &BlockOffset, bit_depth: usize
bo: &BlockOffset
) -> Option<MotionVector> {
if let Some(ref rec) = fi.rec_buffer.frames[ref_idx] {
let blk_w = bsize.width();
......@@ -334,7 +333,7 @@ pub fn estimate_motion_ss4(
let mut best_mv = MotionVector { row: 0, col: 0 };
// Divide by 16 to account for subsampling, 0.125 is a fudge factor
let lambda = (get_lambda_sqrt(fi, bit_depth) * 256.0 / 16.0 * 0.125) as u32;
let lambda = (get_lambda_sqrt(fi) * 256.0 / 16.0 * 0.125) as u32;
full_search(
x_lo,
......@@ -349,7 +348,7 @@ pub fn estimate_motion_ss4(
&mut lowest_cost,
&po,
1,
bit_depth,
fi.sequence.bit_depth,
lambda,
&[MotionVector { row: 0, col: 0 }; 2],
fi.allow_high_precision_mv
......@@ -363,7 +362,7 @@ pub fn estimate_motion_ss4(
pub fn estimate_motion_ss2(
fi: &FrameInvariants, fs: &FrameState, bsize: BlockSize, ref_idx: usize,
bo: &BlockOffset, pmvs: &[Option<MotionVector>; 3], bit_depth: usize
bo: &BlockOffset, pmvs: &[Option<MotionVector>; 3]
) -> Option<MotionVector> {
if let Some(ref rec) = fi.rec_buffer.frames[ref_idx] {
let blk_w = bsize.width();
......@@ -380,7 +379,7 @@ pub fn estimate_motion_ss2(
let mut best_mv = MotionVector { row: 0, col: 0 };
// Divide by 4 to account for subsampling, 0.125 is a fudge factor
let lambda = (get_lambda_sqrt(fi, bit_depth) * 256.0 / 4.0 * 0.125) as u32;
let lambda = (get_lambda_sqrt(fi) * 256.0 / 4.0 * 0.125) as u32;
for omv in pmvs.iter() {
if let Some(pmv) = omv {
......@@ -402,7 +401,7 @@ pub fn estimate_motion_ss2(
&mut lowest_cost,
&po,
1,
bit_depth,
fi.sequence.bit_depth,
lambda,
&[MotionVector { row: 0, col: 0 }; 2],
fi.allow_high_precision_mv
......
......@@ -1166,7 +1166,7 @@ impl PredictionMode {
pub fn predict_inter<'a>(
self, fi: &FrameInvariants, p: usize, po: &PlaneOffset,
dst: &'a mut PlaneMutSlice<'a>, width: usize, height: usize,
ref_frames: [usize; 2], mvs: [MotionVector; 2], bit_depth: usize
ref_frames: [usize; 2], mvs: [MotionVector; 2]
) {
assert!(!self.is_intra());
......@@ -1189,11 +1189,11 @@ impl PredictionMode {
(mvs[i].col as i32 - (col_offset << shift_col)) << (4 - shift_col);
let ref_stride = rec_cfg.stride;
let max_sample_val = ((1 << bit_depth) - 1) as i32;
let max_sample_val = ((1 << fi.sequence.bit_depth) - 1) as i32;
let y_filter_idx = if height <= 4 { 4 } else { 0 };
let x_filter_idx = if width <= 4 { 4 } else { 0 };
let shifts = {
let shift_offset = if bit_depth == 12 { 2 } else { 0 };
let shift_offset = if fi.sequence.bit_depth == 12 { 2 } else { 0 };
let inter_round0 = 3 + shift_offset;
let inter_round1 = if is_compound { 7 } else { 11 } - shift_offset;
(inter_round0, inter_round1, 14 - inter_round0 - inter_round1)
......
......@@ -13,7 +13,7 @@
use context::{INTRA_MODES, MAX_TX_SIZE};
use partition::*;
use util::*;
use util::Pixel;
#[cfg(all(target_arch = "x86_64", not(windows), feature = "nasm"))]
use libc;
......
......@@ -30,7 +30,6 @@ use partition::*;
use plane::*;
use predict::{RAV1E_INTRA_MODES, RAV1E_INTER_MODES_MINIMAL, RAV1E_INTER_COMPOUND_MODES};
use quantize::dc_q;
use Sequence;
use Tune;
use write_tx_blocks;
use write_tx_tree;
......@@ -139,8 +138,8 @@ pub fn sse_wxh(
sse
}
pub fn get_lambda(fi: &FrameInvariants, bit_depth: usize) -> f64 {
let q = dc_q(fi.base_q_idx, fi.dc_delta_q[0], bit_depth) as f64;
pub fn get_lambda(fi: &FrameInvariants) -> f64 {
let q = dc_q(fi.base_q_idx, fi.dc_delta_q[0], fi.sequence.bit_depth) as f64;
// Convert q into Q0 precision, given that libaom quantizers are Q3
let q0 = q / 8.0_f64;
......@@ -150,8 +149,8 @@ pub fn get_lambda(fi: &FrameInvariants, bit_depth: usize) -> f64 {
q0 * q0 * std::f64::consts::LN_2 / 6.0
}
pub fn get_lambda_sqrt(fi: &FrameInvariants, bit_depth: usize) -> f64 {
let q = dc_q(fi.base_q_idx, fi.dc_delta_q[0], bit_depth) as f64;
pub fn get_lambda_sqrt(fi: &FrameInvariants) -> f64 {
let q = dc_q(fi.base_q_idx, fi.dc_delta_q[0], fi.sequence.bit_depth) as f64;
// Convert q into Q0 precision, given that libaom quantizers are Q3
let q0 = q / 8.0_f64;
......@@ -164,10 +163,10 @@ pub fn get_lambda_sqrt(fi: &FrameInvariants, bit_depth: usize) -> f64 {
// Compute the rate-distortion cost for an encode
fn compute_rd_cost(
fi: &FrameInvariants, fs: &FrameState, w_y: usize, h_y: usize,
is_chroma_block: bool, bo: &BlockOffset, bit_cost: u32, bit_depth: usize,
is_chroma_block: bool, bo: &BlockOffset, bit_cost: u32,
luma_only: bool
) -> f64 {
let lambda = get_lambda(fi, bit_depth);
let lambda = get_lambda(fi);
// Compute distortion
let po = bo.plane_offset(&fs.input.planes[0].cfg);
......@@ -184,7 +183,7 @@ fn compute_rd_cost(
&fs.rec.planes[0].slice(&po),
w_y,
h_y,
bit_depth
fi.sequence.bit_depth
)
} else {
unimplemented!();
......@@ -226,12 +225,11 @@ fn compute_rd_cost(
fn compute_tx_rd_cost(
fi: &FrameInvariants, fs: &FrameState, w_y: usize, h_y: usize,
is_chroma_block: bool, bo: &BlockOffset, bit_cost: u32, tx_dist: i64,
bit_depth: usize,
skip: bool, luma_only: bool
) -> f64 {
assert!(fi.config.tune == Tune::Psnr);
let lambda = get_lambda(fi, bit_depth);
let lambda = get_lambda(fi);
// Compute distortion
let mut distortion = if skip {
......@@ -281,7 +279,7 @@ fn compute_tx_rd_cost(
}
pub fn rdo_tx_size_type(
seq: &Sequence, fi: &FrameInvariants, fs: &mut FrameState,
fi: &FrameInvariants, fs: &mut FrameState,
cw: &mut ContextWriter, bsize: BlockSize, bo: &BlockOffset,
luma_mode: PredictionMode, ref_frames: [usize; 2], mvs: [MotionVector; 2], skip: bool
) -> (TxSize, TxType) {
......@@ -322,8 +320,6 @@ pub fn rdo_tx_size_type(
bo,
tx_size,
tx_set,
seq.bit_depth,
seq.chroma_sampling
)
} else {
TxType::DCT_DCT
......@@ -362,8 +358,7 @@ impl Default for EncodingSettings {
}
}
// RDO-based mode decision
pub fn rdo_mode_decision(
seq: &Sequence, fi: &FrameInvariants, fs: &mut FrameState,
pub fn rdo_mode_decision(fi: &FrameInvariants, fs: &mut FrameState,
cw: &mut ContextWriter, bsize: BlockSize, bo: &BlockOffset,
pmvs: &[Option<MotionVector>], needs_rec: bool
) -> RDOOutput {
......@@ -417,7 +412,7 @@ pub fn rdo_mode_decision(
if mv_stack.len() > 1 { pmv[1] = mv_stack[1].this_mv; }
let cmv = pmvs[ref_slot_set[i] as usize].unwrap();
mvs_from_me.push([
motion_estimation(fi, fs, bsize, bo, ref_frames[0], cmv, seq.bit_depth, &pmv),
motion_estimation(fi, fs, bsize, bo, ref_frames[0], cmv, &pmv),
MotionVector { row: 0, col: 0 }
]);
......@@ -473,7 +468,7 @@ pub fn rdo_mode_decision(
mvs: [MotionVector; 2], ref_frames: [usize; 2], mode_set_chroma: &[PredictionMode], luma_mode_is_intra: bool,
mode_context: usize, mv_stack: &Vec<CandidateMV>| {
let (tx_size, mut tx_type) = rdo_tx_size_type(
seq, fi, fs, cw, bsize, bo, luma_mode, ref_frames, mvs, false,
fi, fs, cw, bsize, bo, luma_mode, ref_frames, mvs, false,
);
// Find the best chroma prediction mode for the current luma prediction mode
......@@ -488,10 +483,9 @@ pub fn rdo_mode_decision(
cw.write_partition(wr, bo, PartitionType::PARTITION_NONE, bsize);
}
encode_block_a(seq, fs, cw, wr, bsize, bo, skip);
encode_block_a(&fi.sequence, fs, cw, wr, bsize, bo, skip);
let tx_dist =
encode_block_b(
seq,
fi,
fs,
cw,
......@@ -503,7 +497,6 @@ pub fn rdo_mode_decision(
bsize,
bo,
skip,
seq.bit_depth,
CFLParams::new(),
tx_size,
tx_type,
......@@ -523,7 +516,6 @@ pub fn rdo_mode_decision(
bo,
cost,
tx_dist,
seq.bit_depth,
skip,
false
)
......@@ -536,7 +528,6 @@ pub fn rdo_mode_decision(
is_chroma_block,
bo,
cost,
seq.bit_depth,
false
)
};
......@@ -610,12 +601,12 @@ pub fn rdo_mode_decision(
let mut sads = intra_mode_set.iter().map(|&luma_mode| {
let rec = &mut fs.rec.planes[0];
let po = bo.plane_offset(&rec.cfg);
luma_mode.predict_intra(&mut rec.mut_slice(&po), tx_size, seq.bit_depth, &[0i16; 2], 0, 0, fi.w_in_b, fi.h_in_b);
luma_mode.predict_intra(&mut rec.mut_slice(&po), tx_size, fi.sequence.bit_depth, &[0i16; 2], 0, 0, fi.w_in_b, fi.h_in_b);
let plane_org = fs.input.planes[0].slice(&po);
let plane_ref = rec.slice(&po);
(luma_mode, get_sad(&plane_org, &plane_ref, tx_size.height(), tx_size.width(), seq.bit_depth))
(luma_mode, get_sad(&plane_org, &plane_ref, tx_size.height(), tx_size.width(), fi.sequence.bit_depth))
}).collect::<Vec<_>>();
sads.sort_by_key(|a| a.1);
......@@ -664,20 +655,17 @@ pub fn rdo_mode_decision(
best.tx_size,
best.tx_type,
false,
seq.bit_depth,
seq.chroma_sampling,
CFLParams::new(),
true,
false
);
cw.rollback(&cw_checkpoint);
if let Some(cfl) = rdo_cfl_alpha(fs, bo, bsize, seq.bit_depth, seq.chroma_sampling) {
if let Some(cfl) = rdo_cfl_alpha(fs, bo, bsize, fi.sequence.bit_depth, fi.sequence.chroma_sampling) {
let mut wr: &mut dyn Writer = &mut WriterCounter::new();
let tell = wr.tell_frac();
encode_block_a(seq, fs, cw, wr, bsize, bo, best.skip);
encode_block_a(&fi.sequence, fs, cw, wr, bsize, bo, best.skip);
encode_block_b(
seq,
fi,
fs,
cw,
......@@ -689,7 +677,6 @@ pub fn rdo_mode_decision(
bsize,
bo,
best.skip,
seq.bit_depth,
cfl,
best.tx_size,
best.tx_type,
......@@ -710,7 +697,6 @@ pub fn rdo_mode_decision(
is_chroma_block,
bo,
cost,
seq.bit_depth,
false
);
......@@ -793,8 +779,7 @@ pub fn rdo_cfl_alpha(
pub fn rdo_tx_type_decision(
fi: &FrameInvariants, fs: &mut FrameState, cw: &mut ContextWriter,
mode: PredictionMode, ref_frames: [usize; 2], mvs: [MotionVector; 2], bsize: BlockSize, bo: &BlockOffset, tx_size: TxSize,
tx_set: TxSet, bit_depth: usize, chroma_sampling: ChromaSampling
) -> TxType {
tx_set: TxSet) -> TxType {
let mut best_type = TxType::DCT_DCT;
let mut best_rd = std::f64::MAX;
......@@ -816,19 +801,19 @@ pub fn rdo_tx_type_decision(
}
if is_inter {
motion_compensate(fi, fs, cw, mode, ref_frames, mvs, bsize, bo, bit_depth, true);
motion_compensate(fi, fs, cw, mode, ref_frames, mvs, bsize, bo, true);
}
let mut wr: &mut dyn Writer = &mut WriterCounter::new();
let tell = wr.tell_frac();
let tx_dist = if is_inter {
write_tx_tree(
fi, fs, cw, wr, mode, bo, bsize, tx_size, tx_type, false, bit_depth, chroma_sampling, true, true
fi, fs, cw, wr, mode, bo, bsize, tx_size, tx_type, false, true, true
)
} else {
let cfl = CFLParams::new(); // Unused
write_tx_blocks(
fi, fs, cw, wr, mode, mode, bo, bsize, tx_size, tx_type, false, bit_depth, chroma_sampling, cfl, true, true
fi, fs, cw, wr, mode, mode, bo, bsize, tx_size, tx_type, false, cfl, true, true
)
};
......@@ -843,7 +828,6 @@ pub fn rdo_tx_type_decision(
bo,
cost,
tx_dist,
bit_depth,
false,
true
)
......@@ -856,7 +840,6 @@ pub fn rdo_tx_type_decision(
is_chroma_block,
bo,
cost,
bit_depth,
true
)
};
......@@ -924,7 +907,7 @@ pub fn get_sub_partitions_with_border_check<'a>(four_partitions: &[&'a BlockOffs
// RDO-based single level partitioning decision
pub fn rdo_partition_decision(
seq: &Sequence, fi: &FrameInvariants, fs: &mut FrameState,
fi: &FrameInvariants, fs: &mut FrameState,
cw: &mut ContextWriter, w_pre_cdef: &mut dyn Writer, w_post_cdef: &mut dyn Writer,
bsize: BlockSize, bo: &BlockOffset,