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

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;
......
This diff is collapsed.
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