Commit 00b17cac authored by Frank Bossen's avatar Frank Bossen Committed by Thomas Daede

Boost quantizer on key frames

parent c1b5dced
......@@ -44,7 +44,7 @@ fn write_b_bench(b: &mut Bencher, tx_size: TxSize, qindex: usize) {
EncoderConfig { quantizer: qindex, speed: 10, ..Default::default() };
let mut fi = FrameInvariants::new(1024, 1024, config);
let mut w = ec::WriterEncoder::new();
let fc = CDFContext::new(fi.config.quantizer as u8);
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);
let mut cw = ContextWriter::new(fc, bc);
......@@ -58,7 +58,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.config.quantizer, tx_size, mode.is_intra(), 8);
fs.qc.update(fi.base_q_idx, tx_size, mode.is_intra(), 8);
for p in 1..3 {
for by in 0..8 {
for bx in 0..8 {
......
......@@ -61,10 +61,17 @@ fn main() {
);
loop {
//fi.frame_type = FrameType::KEY;
fi.frame_type =
if fi.number % 30 == 0 { FrameType::KEY } else { FrameType::INTER };
fi.base_q_idx =
if fi.frame_type == FrameType::KEY {
let q_boost = 15;
fi.config.quantizer.max(1 + q_boost).min(255 + q_boost) - q_boost
} else {
fi.config.quantizer.max(1).min(255)
} as u8;
fi.refresh_frame_flags =
if fi.frame_type == FrameType::KEY { ALL_REF_FRAMES_MASK } else { 1 };
fi.intra_only = fi.frame_type == FrameType::KEY
......
......@@ -322,7 +322,8 @@ pub struct FrameInvariants {
pub config: EncoderConfig,
pub ref_frames: [usize; INTER_REFS_PER_FRAME],
pub rec_buffer: ReferenceFramesSet,
pub deblock: DeblockState
pub deblock: DeblockState,
pub base_q_idx: u8,
}
impl FrameInvariants {
......@@ -387,7 +388,8 @@ impl FrameInvariants {
config,
ref_frames: [0; INTER_REFS_PER_FRAME],
rec_buffer: ReferenceFramesSet::new(),
deblock: Default::default()
deblock: Default::default(),
base_q_idx: config.quantizer as u8,
}
}
......@@ -869,8 +871,8 @@ impl<'a> UncompressedHeader for BitWriter<'a, BE> {
// write context_update_tile_id and tile_size_bytes_minus_1 }
// quantization
assert!(fi.config.quantizer > 0);
self.write(8,fi.config.quantizer as u8)?; // base_q_idx
assert!(fi.base_q_idx > 0);
self.write(8, fi.base_q_idx)?; // 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
......@@ -1226,7 +1228,7 @@ pub fn encode_tx_block(
fi.use_reduced_tx_set);
// Reconstruct
dequantize(fi.config.quantizer, &coeffs, &mut rcoeffs.array, tx_size, bit_depth);
dequantize(fi.base_q_idx, &coeffs, &mut rcoeffs.array, tx_size, bit_depth);
inverse_transform_add(&rcoeffs.array, &mut rec.mut_slice(po).as_mut_slice(), stride, tx_size, tx_type, bit_depth);
has_coeff
......@@ -1448,7 +1450,7 @@ pub fn write_tx_blocks(fi: &FrameInvariants, fs: &mut FrameState,
let PlaneConfig { xdec, ydec, .. } = fs.input.planes[1].cfg;
let ac = &mut [0i16; 32 * 32];
fs.qc.update(fi.config.quantizer, tx_size, luma_mode.is_intra(), bit_depth);
fs.qc.update(fi.base_q_idx, tx_size, luma_mode.is_intra(), bit_depth);
for by in 0..bh {
for bx in 0..bw {
......@@ -1494,7 +1496,7 @@ pub fn write_tx_blocks(fi: &FrameInvariants, fs: &mut FrameState,
if bw_uv > 0 && bh_uv > 0 {
let uv_tx_type = uv_intra_mode_to_tx_type_context(chroma_mode);
fs.qc.update(fi.config.quantizer, uv_tx_size, true, bit_depth);
fs.qc.update(fi.base_q_idx, uv_tx_size, true, bit_depth);
for p in 1..3 {
let alpha = cfl.alpha(p - 1);
......@@ -1532,7 +1534,7 @@ pub fn write_tx_tree(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut Context
let PlaneConfig { xdec, ydec, .. } = fs.input.planes[1].cfg;
let ac = &[0i16; 32 * 32];
fs.qc.update(fi.config.quantizer, tx_size, luma_mode.is_intra(), bit_depth);
fs.qc.update(fi.base_q_idx, tx_size, luma_mode.is_intra(), bit_depth);
let po = bo.plane_offset(&fs.input.planes[0].cfg);
let has_coeff = encode_tx_block(
......@@ -1566,7 +1568,7 @@ pub fn write_tx_tree(fi: &FrameInvariants, fs: &mut FrameState, cw: &mut Context
if bw_uv > 0 && bh_uv > 0 {
let uv_tx_type = if has_coeff {tx_type} else {TxType::DCT_DCT}; // if inter mode, uv_tx_type == tx_type
fs.qc.update(fi.config.quantizer, uv_tx_size, false, bit_depth);
fs.qc.update(fi.base_q_idx, uv_tx_size, false, bit_depth);
for p in 1..3 {
let tx_bo = BlockOffset {
......@@ -1857,11 +1859,11 @@ fn encode_tile(sequence: &mut Sequence, fi: &FrameInvariants, fs: &mut FrameStat
let mut w = WriterEncoder::new();
let fc = if fi.primary_ref_frame == PRIMARY_REF_NONE {
CDFContext::new(fi.config.quantizer as u8)
CDFContext::new(fi.base_q_idx)
} else {
match fi.rec_buffer.frames[fi.ref_frames[fi.primary_ref_frame as usize]] {
Some(ref rec) => rec.cdfs.clone(),
None => CDFContext::new(fi.config.quantizer as u8)
None => CDFContext::new(fi.base_q_idx)
}
};
......
......@@ -30,7 +30,7 @@ fn get_log_tx_scale(tx_size: TxSize) -> i32 {
}
}
pub fn dc_q(qindex: usize, bit_depth: usize) -> i16 {
pub fn dc_q(qindex: u8, bit_depth: usize) -> i16 {
let &table = match bit_depth {
8 => &dc_qlookup_Q3,
10 => &dc_qlookup_10_Q3,
......@@ -38,10 +38,10 @@ pub fn dc_q(qindex: usize, bit_depth: usize) -> i16 {
_ => unimplemented!()
};
table[qindex]
table[qindex as usize]
}
pub fn ac_q(qindex: usize, bit_depth: usize) -> i16 {
pub fn ac_q(qindex: u8, bit_depth: usize) -> i16 {
let &table = match bit_depth {
8 => &ac_qlookup_Q3,
10 => &ac_qlookup_10_Q3,
......@@ -49,7 +49,7 @@ pub fn ac_q(qindex: usize, bit_depth: usize) -> i16 {
_ => unimplemented!()
};
table[qindex]
table[qindex as usize]
}
#[derive(Debug, Default, Clone, Copy)]
......@@ -119,7 +119,7 @@ mod test {
}
impl QuantizationContext {
pub fn update(&mut self, qindex: usize, tx_size: TxSize, is_intra: bool, bit_depth: usize) {
pub fn update(&mut self, qindex: u8, tx_size: TxSize, is_intra: bool, bit_depth: usize) {
self.log_tx_scale = get_log_tx_scale(tx_size);
self.dc_quant = dc_q(qindex, bit_depth) as u32;
......@@ -146,7 +146,7 @@ impl QuantizationContext {
}
}
pub fn quantize_in_place(qindex: usize, coeffs: &mut [i32], tx_size: TxSize, bit_depth: usize) {
pub fn quantize_in_place(qindex: u8, coeffs: &mut [i32], tx_size: TxSize, bit_depth: usize) {
let log_tx_scale = get_log_tx_scale(tx_size);
let dc_quant = dc_q(qindex, bit_depth) as i32;
......@@ -168,7 +168,7 @@ pub fn quantize_in_place(qindex: usize, coeffs: &mut [i32], tx_size: TxSize, bit
}
pub fn dequantize(
qindex: usize, coeffs: &[i32], rcoeffs: &mut [i32], tx_size: TxSize, bit_depth: usize
qindex: u8, coeffs: &[i32], rcoeffs: &mut [i32], tx_size: TxSize, bit_depth: usize
) {
let log_tx_scale = get_log_tx_scale(tx_size) as i32;
let offset = (1 << log_tx_scale) - 1;
......
......@@ -127,7 +127,7 @@ fn sse_wxh(src1: &PlaneSlice<'_>, src2: &PlaneSlice<'_>, w: usize, h: usize) ->
}
pub fn get_lambda(fi: &FrameInvariants, bit_depth: usize) -> f64 {
let q = dc_q(fi.config.quantizer, bit_depth) as f64;
let q = dc_q(fi.base_q_idx, bit_depth) as f64;
// Convert q into Q0 precision, given that libaom quantizers are Q3
let q0 = q / 8.0_f64;
......
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