Commit 221912d8 authored by Michael Bebenita's avatar Michael Bebenita Committed by Thomas Daede

Clean up config parameter passing, and fix bench.

parent 45a86b53
......@@ -377,9 +377,11 @@ fn write_b_bench(b: &mut Bencher, tx_size: TxSize, qindex: usize) {
av1_rtcd();
aom_dsp_rtcd();
}
let mut fi = FrameInvariants::new(1024, 1024, qindex, 10);
let config =
EncoderConfig { quantizer: qindex, speed: 10, ..Default::default() };
let mut fi = FrameInvariants::new(1024, 1024, config);
let w = ec::Writer::new();
let fc = CDFContext::new(fi.qindex as u8);
let fc = CDFContext::new(fi.config.quantizer as u8);
let bc = BlockContext::new(fi.sb_width * 16, fi.sb_height * 16);
let mut fs = FrameState::new(&fi);
let mut cw = ContextWriter::new(w, fc, bc);
......@@ -392,7 +394,7 @@ fn write_b_bench(b: &mut Bencher, tx_size: TxSize, qindex: usize) {
b.iter(|| {
for &mode in RAV1E_INTRA_MODES {
let sbo = SuperBlockOffset { x: sbx, y: sby };
fs.qc.update(fi.qindex, tx_size);
fs.qc.update(fi.config.quantizer, tx_size);
for p in 1..3 {
for by in 0..8 {
for bx in 0..8 {
......
......@@ -24,8 +24,7 @@ fn main() {
None => None
};
let mut fi =
FrameInvariants::new(width, height, config.quantizer, config.speed);
let mut fi = FrameInvariants::new(width, height, config);
let mut sequence = Sequence::new(width, height);
write_ivf_header(
&mut io.output,
......
......@@ -27,8 +27,7 @@ fn main() {
Some(y4m::encode(width, height, framerate).write_header(rec).unwrap()),
None => None
};
let mut fi =
FrameInvariants::new(width, height, config.quantizer, config.speed);
let mut fi = FrameInvariants::new(width, height, &config);
let mut sequence = Sequence::new(width, height);
write_ivf_header(
&mut io.output,
......
......@@ -978,8 +978,8 @@ pub struct CDFContext {
}
impl CDFContext {
pub fn new(qindex: u8) -> CDFContext {
let qctx = match qindex {
pub fn new(quantizer: u8) -> CDFContext {
let qctx = match quantizer {
0...20 => 0,
21...60 => 1,
61...120 => 2,
......
......@@ -76,11 +76,18 @@ const PRIMARY_REF_NONE: u32 = 7;
const PRIMARY_REF_BITS: u32 = 3;
arg_enum!{
#[derive(Copy, Clone, Debug)]
pub enum Tune {
Psnr
}
}
impl Default for Tune {
fn default() -> Self {
Tune::Psnr
}
}
#[derive(Copy,Clone)]
pub struct Sequence {
// OBU Sequence header of AV1
......@@ -240,8 +247,6 @@ impl Fixed for usize {
// Frame Invariants are invariant inside a frame
#[allow(dead_code)]
pub struct FrameInvariants {
pub qindex: usize,
pub speed: usize,
pub width: usize,
pub height: usize,
pub padded_w: usize,
......@@ -278,22 +283,21 @@ pub struct FrameInvariants {
pub is_motion_mode_switchable: bool,
pub disable_frame_end_update_cdf: bool,
pub allow_warped_motion: bool,
pub config: EncoderConfig,
}
impl FrameInvariants {
pub fn new(width: usize, height: usize, qindex: usize, speed: usize) -> FrameInvariants {
pub fn new(width: usize, height: usize, config: EncoderConfig) -> FrameInvariants {
// Speed level decides the minimum partition size, i.e. higher speed --> larger min partition size,
// with exception that SBs on right or bottom frame borders split down to BLOCK_4X4.
// At speed = 0, RDO search is exhaustive.
let min_partition_size = if speed <= 1 { BlockSize::BLOCK_4X4 }
else if speed <= 2 { BlockSize::BLOCK_8X8 }
else if speed <= 3 { BlockSize::BLOCK_16X16 }
let min_partition_size = if config.speed <= 1 { BlockSize::BLOCK_4X4 }
else if config.speed <= 2 { BlockSize::BLOCK_8X8 }
else if config.speed <= 3 { BlockSize::BLOCK_16X16 }
else { BlockSize::BLOCK_32X32 };
let use_reduced_tx_set = speed > 1;
let use_reduced_tx_set = config.speed > 1;
FrameInvariants {
qindex,
speed,
width,
height,
padded_w: width.align_power_of_two(3),
......@@ -328,6 +332,7 @@ impl FrameInvariants {
is_motion_mode_switchable: false, // 0: only the SIMPLE motion mode will be used.
disable_frame_end_update_cdf: true,
allow_warped_motion: true,
config,
}
}
}
......@@ -400,6 +405,7 @@ pub struct EncoderIO {
pub rec: Option<Box<Write>>,
}
#[derive(Copy, Clone, Debug)]
pub struct EncoderConfig {
pub limit: u64,
pub quantizer: usize,
......@@ -407,6 +413,17 @@ pub struct EncoderConfig {
pub tune: Tune
}
impl Default for EncoderConfig {
fn default() -> Self {
EncoderConfig {
limit: 0,
quantizer: 0,
speed: 0,
tune: Tune::Psnr,
}
}
}
impl EncoderConfig {
pub fn from_cli() -> (EncoderIO, EncoderConfig) {
let matches = App::new("rav1e")
......@@ -912,8 +929,8 @@ impl<'a> UncompressedHeader for BitWriter<'a, BE> {
// write context_update_tile_id and tile_size_bytes_minus_1 }
// quantization
assert!(fi.qindex > 0);
self.write(8,fi.qindex as u8)?; // base_q_idx
assert!(fi.config.quantizer > 0);
self.write(8,fi.config.quantizer as u8)?; // base_q_idx
self.write_bit(false)?; // y dc delta q
self.write_bit(false)?; // uv dc delta q
self.write_bit(false)?; // uv ac delta q
......@@ -1265,7 +1282,7 @@ fn write_uncompressed_header(packet: &mut Write,
bw.write(3,0x0)?; // frame context
bw.write_loop_filter()?;
bw.write(8,fi.qindex as u8)?; // qindex
bw.write(8,fi.config.quantizer as u8)?; // qindex
bw.write_bit(false)?; // y dc delta q
bw.write_bit(false)?; // uv dc delta q
bw.write_bit(false)?; // uv ac delta q
......@@ -1376,7 +1393,7 @@ pub fn encode_tx_block(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut Conte
fi.use_reduced_tx_set);
// Reconstruct
dequantize(fi.qindex, &coeffs, &mut rcoeffs.array, tx_size);
dequantize(fi.config.quantizer, &coeffs, &mut rcoeffs.array, tx_size);
inverse_transform_add(&rcoeffs.array, &mut rec.mut_slice(po).as_mut_slice(), stride, tx_size, tx_type);
}
......@@ -1433,7 +1450,7 @@ fn encode_block(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut ContextWrite
// Luma plane transform type decision
let tx_set_type = get_ext_tx_set_type(tx_size, is_inter, fi.use_reduced_tx_set);
let tx_type = if tx_set_type > TxSetType::EXT_TX_SET_DCTONLY && fi.speed <= 3 {
let tx_type = if tx_set_type > TxSetType::EXT_TX_SET_DCTONLY && fi.config.speed <= 3 {
// FIXME: there is one redundant transform type decision per encoded block
rdo_tx_type_decision(fi, fs, cw, luma_mode, bsize, bo, tx_size, tx_set_type)
} else {
......@@ -1451,7 +1468,7 @@ pub fn write_tx_blocks(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut Conte
let PlaneConfig { xdec, ydec, .. } = fs.input.planes[1].cfg;
fs.qc.update(fi.qindex, tx_size);
fs.qc.update(fi.config.quantizer, tx_size);
for by in 0..bh {
for bx in 0..bw {
......@@ -1491,7 +1508,7 @@ pub fn write_tx_blocks(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut Conte
let partition_x = (bo.x & LOCAL_BLOCK_MASK) >> xdec << MI_SIZE_LOG2;
let partition_y = (bo.y & LOCAL_BLOCK_MASK) >> ydec << MI_SIZE_LOG2;
fs.qc.update(fi.qindex, uv_tx_size);
fs.qc.update(fi.config.quantizer, uv_tx_size);
for p in 1..3 {
let sb_offset = bo.sb_offset().plane_offset(&fs.input.planes[p].cfg);
......@@ -1708,7 +1725,7 @@ fn encode_partition_topdown(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut
fn encode_tile(fi: &FrameInvariants, fs: &mut FrameState) -> Vec<u8> {
let w = ec::Writer::new();
let fc = CDFContext::new(fi.qindex as u8);
let fc = CDFContext::new(fi.config.quantizer as u8);
let bc = BlockContext::new(fi.w_in_b, fi.h_in_b);
let mut cw = ContextWriter::new(w, fc, bc);
......@@ -1720,7 +1737,7 @@ fn encode_tile(fi: &FrameInvariants, fs: &mut FrameState) -> Vec<u8> {
let bo = sbo.block_offset(0, 0);
// Encode SuperBlock
if fi.speed == 0 {
if fi.config.speed == 0 {
encode_partition_bottomup(fi, fs, &mut cw, BlockSize::BLOCK_64X64, &bo);
}
else {
......
......@@ -106,7 +106,7 @@ fn compute_rd_cost(
h_uv: usize, partition_start_x: usize, partition_start_y: usize,
bo: &BlockOffset, bit_cost: u32
) -> f64 {
let q = dc_q(fi.qindex) as f64;
let q = dc_q(fi.config.quantizer) as f64;
// Convert q into Q0 precision, given that libaom quantizers are Q3
let q0 = q / 8.0_f64;
......@@ -180,14 +180,14 @@ pub fn rdo_mode_decision(
for &skip in &[false, true] {
// Don't test skipped blocks at higher speed levels
if fi.speed > 1 && skip {
if fi.config.speed > 1 && skip {
continue;
}
let checkpoint = cw.checkpoint();
// Exclude complex prediction modes at higher speed levels
let mode_set = if fi.speed <= 3 {
let mode_set = if fi.config.speed <= 3 {
RAV1E_INTRA_MODES
} else {
RAV1E_INTRA_MODES_MINIMAL
......@@ -200,7 +200,7 @@ pub fn rdo_mode_decision(
break;
}
if is_chroma_block && fi.speed <= 3 {
if is_chroma_block && fi.config.speed <= 3 {
// Find the best chroma prediction mode for the current luma prediction mode
for &chroma_mode in RAV1E_INTRA_MODES {
encode_block(fi, fs, cw, luma_mode, chroma_mode, bsize, bo, skip);
......
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