Commit 265889fa authored by Romain Vimont's avatar Romain Vimont Committed by Romain Vimont

Pass CDFContext by reference in ContextWriter

With tiling, the lifetime of CDFContext will exceed that of
ContextWriter (which will exist only during tile encoding).

The resulting CDFContext must be read to be (possibly) copied into the
FrameState.

Therefore, make ContextWriter only reference it (instead of taking
ownership).
parent 8e063aaf
......@@ -43,12 +43,12 @@ fn write_b_bench(b: &mut Bencher, tx_size: TxSize, qindex: usize) {
let sequence = Sequence::new(&Default::default());
let mut fi = FrameInvariants::<u16>::new(config, sequence);
let mut w = ec::WriterEncoder::new();
let fc = CDFContext::new(fi.base_q_idx);
let mut fc = CDFContext::new(fi.base_q_idx);
let mut fb = FrameBlocks::new(fi.sb_width * 16, fi.sb_height * 16);
let bc = BlockContext::new(&mut fb);
let mut fs = FrameState::new(&fi);
// For now, restoration unit size is locked to superblock size.
let mut cw = ContextWriter::new(fc, bc);
let mut cw = ContextWriter::new(&mut fc, bc);
let tx_type = TxType::DCT_DCT;
......
......@@ -1909,14 +1909,14 @@ pub struct ContextWriterCheckpoint {
pub struct ContextWriter<'a> {
pub bc: BlockContext<'a>,
pub fc: CDFContext,
pub fc: &'a mut CDFContext,
#[cfg(debug)]
fc_map: Option<FieldMap> // For debugging purposes
}
impl<'a> ContextWriter<'a> {
#[allow(clippy::let_and_return)]
pub fn new(fc: CDFContext, bc: BlockContext<'a>) -> Self {
pub fn new(fc: &'a mut CDFContext, bc: BlockContext<'a>) -> Self {
#[allow(unused_mut)]
let mut cw = ContextWriter {
fc,
......@@ -3803,13 +3803,13 @@ impl<'a> ContextWriter<'a> {
pub fn checkpoint(&mut self) -> ContextWriterCheckpoint {
ContextWriterCheckpoint {
fc: self.fc,
fc: *self.fc,
bc: self.bc.checkpoint()
}
}
pub fn rollback(&mut self, checkpoint: &ContextWriterCheckpoint) {
self.fc = checkpoint.fc;
*self.fc = checkpoint.fc;
self.bc.rollback(&checkpoint.bc);
#[cfg(debug)] {
if self.fc_map.is_some() {
......
......@@ -2022,7 +2022,7 @@ fn encode_tile<T: Pixel>(fi: &FrameInvariants<T>, fs: &mut FrameState<T>) -> Vec
crate::me::FullSearch::estimate_motion_ss2
};
let fc = if fi.primary_ref_frame == PRIMARY_REF_NONE {
let mut fc = if fi.primary_ref_frame == PRIMARY_REF_NONE {
CDFContext::new(fi.base_q_idx)
} else {
match fi.rec_buffer.frames[fi.ref_frames[fi.primary_ref_frame as usize] as usize] {
......@@ -2034,7 +2034,7 @@ fn encode_tile<T: Pixel>(fi: &FrameInvariants<T>, fs: &mut FrameState<T>) -> Vec
let mut blocks = FrameBlocks::new(fi.w_in_b, fi.h_in_b);
let bc = BlockContext::new(&mut blocks);
// For now, restoration unit size is locked to superblock size.
let mut cw = ContextWriter::new(fc, bc);
let mut cw = ContextWriter::new(&mut fc, bc);
let frame_pmvs = build_coarse_pmvs(fi, fs);
// main loop
......@@ -2214,7 +2214,7 @@ fn encode_tile<T: Pixel>(fi: &FrameInvariants<T>, fs: &mut FrameState<T>) -> Vec
fs.t.print_code();
}
fs.cdfs = cw.fc;
fs.cdfs = fc;
fs.cdfs.reset_counts();
w.done()
......
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