forge
Explore
Log in

Don't you dare go Hollow

ALTREF as the frame two back, on an alternating slot

Browse files at this commit

931098164d723070530a397176eddb5ff3e1a290Ahmet Kaan GümüşParent: 2f069ae
  • feat
    • ALTREF as the frame two back, on an alternating slot
Show full message
feat(av1): ALTREF as the frame two back, on an alternating slot

Frame n refreshes slot 0 for odd n and slot 2 for even n, so the frame
two back is still intact in the very slot this one is about to overwrite
(read before write): ref_frame_idx names it as ALTREF_FRAME, LAST names
the other slot, GOLDEN stays on slot 1. inter_frame_headers_slots is the
header builder that takes the three slots apart; the five-argument
inter_frame_headers keeps its old read-and-write-one-slot meaning for the
hand-built fixtures. The RD prices each extra reference's two
search-free modes from a slice, so LAST/GOLDEN/ALTREF share one code path.

ALTREF is picked for 337/405/1793 blocks per ladder. BD-rate vs libaom
127.3/153.4/83.0 -> 126.5/152.9/80.9, vs rav1e 78.6/105.7/18.3 ->
77.9/105.5/17.6; wall 7.8/7.1/7.8 -> 8.0/7.2/7.7 s. ffmpeg decodes every
stream sample-exact.
crates/ec-av1/src/decode.rsmodified+21 -2
@@ -35642,9 +35642,20 @@ mod tests {
35642 /// `ref_frame_idx[3]` names the slot the key frame left behind and its35642 /// `ref_frame_idx[3]` names the slot the key frame left behind and its
35643 /// blocks may code `single_ref` out to it.35643 /// blocks may code `single_ref` out to it.
35644 fn last_and_golden<'a>(last: &'a Picture, golden: &'a Picture) -> RefPix<'a> {35644 fn last_and_golden<'a>(last: &'a Picture, golden: &'a Picture) -> RefPix<'a> {
35645+ last_golden_altref(last, golden, None)
35646+ }
35647+
35648+ /// [`last_and_golden`] plus `ALTREF_FRAME` (index 7): the frame two back,
35649+ /// which the encoder keeps in the slot the current frame refreshes.
35650+ fn last_golden_altref<'a>(
35651+ last: &'a Picture,
35652+ golden: &'a Picture,
35653+ altref: Option<&'a Picture>,
35654+ ) -> RefPix<'a> {
35645 let mut refs: [Option<&Picture>; 8] = [None; 8];35655 let mut refs: [Option<&Picture>; 8] = [None; 8];
35646 refs[1] = Some(last);35656 refs[1] = Some(last);
35647 refs[4] = Some(golden);35657 refs[4] = Some(golden);
35658+ refs[7] = altref;
35648 RefPix::ready(refs)35659 RefPix::ready(refs)
35649 }35660 }
35650 35661
@@ -37175,7 +37186,11 @@ mod tests {
37175 frame.base_q_idx,37186 frame.base_q_idx,
37176 width as u32,37187 width as u32,
37177 height as u32,37188 height as u32,
37178- &last_and_golden(&reference, &encoded.frames[0].reconstruction),37189+ &last_golden_altref(
37190+ &reference,
37191+ &encoded.frames[0].reconstruction,
37192+ (i >= 2).then(|| &encoded.frames[i - 2].reconstruction),
37193+ ),
37179 &frame.cdef,37194 &frame.cdef,
37180 &frame.loop_filter,37195 &frame.loop_filter,
37181 false,37196 false,
@@ -37487,7 +37502,11 @@ mod tests {
37487 frame.base_q_idx,37502 frame.base_q_idx,
37488 coded_w,37503 coded_w,
37489 coded_h,37504 coded_h,
37490- &last_and_golden(&reference, &encoded.frames[0].reconstruction),37505+ &last_golden_altref(
37506+ &reference,
37507+ &encoded.frames[0].reconstruction,
37508+ (i >= 2).then(|| &encoded.frames[i - 2].reconstruction),
37509+ ),
37491 &frame.cdef,37510 &frame.cdef,
37492 &frame.loop_filter,37511 &frame.loop_filter,
37493 false,37512 false,
crates/ec-av1/src/encode.rsmodified+106 -31
@@ -731,6 +731,26 @@ pub fn inter_frame_headers(
731 base_q_idx: u8,731 base_q_idx: u8,
732 order_hint: u32,732 order_hint: u32,
733 last_slot: u8,733 last_slot: u8,
734+) -> Result<(SequenceHeader, FrameHeader)> {
735+ inter_frame_headers_slots(width, height, base_q_idx, order_hint, last_slot, last_slot, last_slot)
736+}
737+
738+/// [`inter_frame_headers`] with the three slots named apart: the one read as
739+/// `LAST_FRAME`, the one this frame refreshes, and the one read as
740+/// `ALTREF_FRAME`. The encoder alternates the refreshed slot between 0 and 2
741+/// so that the frame two back is still intact in the slot this one is about
742+/// to overwrite -- read before write, spec 7.20's decode order.
743+///
744+/// # Errors
745+/// As [`inter_frame_headers`].
746+pub fn inter_frame_headers_slots(
747+ width: usize,
748+ height: usize,
749+ base_q_idx: u8,
750+ order_hint: u32,
751+ last_slot: u8,
752+ self_slot: u8,
753+ altref_slot: u8,
734 ) -> Result<(SequenceHeader, FrameHeader)> {754 ) -> Result<(SequenceHeader, FrameHeader)> {
735 let (seq, key) = key_frame_headers(width, height, base_q_idx)?;755 let (seq, key) = key_frame_headers(width, height, base_q_idx)?;
736 let header = FrameHeader {756 let header = FrameHeader {
@@ -746,7 +766,7 @@ pub fn inter_frame_headers(
746 force_integer_mv: false,766 force_integer_mv: false,
747 order_hint,767 order_hint,
748 primary_ref_frame: 0,768 primary_ref_frame: 0,
749- refresh_frame_flags: 1 << last_slot,769+ refresh_frame_flags: 1 << self_slot,
750 // Every reference but `GOLDEN_FRAME` (index 3 of `ref_frame_idx`)770 // Every reference but `GOLDEN_FRAME` (index 3 of `ref_frame_idx`)
751 // names the slot this frame both predicts from and refreshes;771 // names the slot this frame both predicts from and refreshes;
752 // GOLDEN names slot 1, which the key frame wrote when it refreshed772 // GOLDEN names slot 1, which the key frame wrote when it refreshed
@@ -755,6 +775,7 @@ pub fn inter_frame_headers(
755 ref_frame_idx: {775 ref_frame_idx: {
756 let mut idx = [last_slot; ec_av1_syntax::REFS_PER_FRAME];776 let mut idx = [last_slot; ec_av1_syntax::REFS_PER_FRAME];
757 idx[3] = GOLDEN_SLOT;777 idx[3] = GOLDEN_SLOT;
778+ idx[6] = altref_slot;
758 idx779 idx
759 },780 },
760 allow_high_precision_mv: false,781 allow_high_precision_mv: false,
@@ -3408,7 +3429,7 @@ fn search_inter_block(
3408 // its two search-free modes are priced (`NEARESTMV`, `GLOBALMV`) -- a3429 // its two search-free modes are priced (`NEARESTMV`, `GLOBALMV`) -- a
3409 // second motion search would double the wall of the stage that already3430 // second motion search would double the wall of the stage that already
3410 // owns most of it.3431 // owns most of it.
3411- golden: Option<(&Picture, &MvStack)>, fctx: &crate::decode::FrameCtx,3432+ extra: &[(i8, &Picture, &MvStack)], fctx: &crate::decode::FrameCtx,
3412 ) -> (BlockCoeffs, f64) {3433 ) -> (BlockCoeffs, f64) {
3413 // `luma_set` is the INTRA candidates' table; the two inter candidates3434 // `luma_set` is the INTRA candidates' table; the two inter candidates
3414 // below price their coefficients through `TxbSet::Luma32Inter`, which is3435 // below price their coefficients through `TxbSet::Luma32Inter`, which is
@@ -3680,8 +3701,8 @@ fn search_inter_block(
3680 ));3701 ));
3681 }3702 }
3682 3703
3683- if let Some((_, gstack)) = golden {3704+ for &(ref_frame, _, gstack) in extra {
3684- let g_ref_bits = single_ref_bits(crate::mvstack::GOLDEN_FRAME);3705+ let g_ref_bits = single_ref_bits(ref_frame);
3685 let g_not_new = symbol_bits(&cdf::NEW_MV[gstack.new_mv_ctx], 1);3706 let g_not_new = symbol_bits(&cdf::NEW_MV[gstack.new_mv_ctx], 1);
3686 cands.push((3707 cands.push((
3687 gstack.nearest_mv,3708 gstack.nearest_mv,
@@ -3690,7 +3711,7 @@ fn search_inter_block(
3690 + symbol_bits(&cdf::ZERO_MV[gstack.zero_mv_ctx], 1)3711 + symbol_bits(&cdf::ZERO_MV[gstack.zero_mv_ctx], 1)
3691 + symbol_bits(&cdf::REF_MV[gstack.ref_mv_ctx], 0),3712 + symbol_bits(&cdf::REF_MV[gstack.ref_mv_ctx], 0),
3692 InterInfo {3713 InterInfo {
3693- ref_frame: crate::mvstack::GOLDEN_FRAME,3714+ ref_frame,
3694 mode: InterMode::NearestMv,3715 mode: InterMode::NearestMv,
3695 mv: gstack.nearest_mv,3716 mv: gstack.nearest_mv,
3696 ref_mv_idx: 0,3717 ref_mv_idx: 0,
@@ -3700,7 +3721,7 @@ fn search_inter_block(
3700 (0, 0),3721 (0, 0),
3701 g_ref_bits + g_not_new + symbol_bits(&cdf::ZERO_MV[gstack.zero_mv_ctx], 0),3722 g_ref_bits + g_not_new + symbol_bits(&cdf::ZERO_MV[gstack.zero_mv_ctx], 0),
3702 InterInfo {3723 InterInfo {
3703- ref_frame: crate::mvstack::GOLDEN_FRAME,3724+ ref_frame,
3704 mode: InterMode::GlobalMv,3725 mode: InterMode::GlobalMv,
3705 mv: (0, 0),3726 mv: (0, 0),
3706 ref_mv_idx: 0,3727 ref_mv_idx: 0,
@@ -3718,13 +3739,16 @@ fn search_inter_block(
3718 cands.dedup_by_key(|c| (c.2.ref_frame, c.0));3739 cands.dedup_by_key(|c| (c.2.ref_frame, c.0));
3719 {3740 {
3720 for (mv, mode_bits_inter, info) in cands {3741 for (mv, mode_bits_inter, info) in cands {
3721- let (ref_luma, ref_u, ref_v) = match golden {3742+ let (ref_luma, ref_u, ref_v) = match extra
3722- Some((g, _)) if info.ref_frame == crate::mvstack::GOLDEN_FRAME => (3743+ .iter()
3744+ .find(|(r, _, _)| *r == info.ref_frame)
3745+ {
3746+ Some(&(_, g, _)) => (
3723 (&g.y, g.width, luma.true_width, luma.true_height),3747 (&g.y, g.width, luma.true_width, luma.true_height),
3724 (&g.u, g.width / 2, chroma[0].true_width, chroma[0].true_height),3748 (&g.u, g.width / 2, chroma[0].true_width, chroma[0].true_height),
3725 (&g.v, g.width / 2, chroma[1].true_width, chroma[1].true_height),3749 (&g.v, g.width / 2, chroma[1].true_width, chroma[1].true_height),
3726 ),3750 ),
3727- _ => (ref_luma, ref_u, ref_v),3751+ None => (ref_luma, ref_u, ref_v),
3728 };3752 };
3729 let luma_trial = mc_trial(3753 let luma_trial = mc_trial(
3730 luma,3754 luma,
@@ -3839,7 +3863,11 @@ pub(crate) fn encode_inter_frame(
3839 // The key frame's own (padded) reconstruction, which every frame of the3863 // The key frame's own (padded) reconstruction, which every frame of the
3840 // GOP still holds in DPB slot 1 -- `GOLDEN_FRAME`. `None` codes the frame3864 // GOP still holds in DPB slot 1 -- `GOLDEN_FRAME`. `None` codes the frame
3841 // with `LAST_FRAME` alone, exactly as before.3865 // with `LAST_FRAME` alone, exactly as before.
3842- golden: Option<&Picture>, fctx: &crate::decode::FrameCtx,3866+ golden: Option<&Picture>,
3867+ // The frame two back, held in the slot this frame is about to refresh
3868+ // (the encoder alternates 0/2): `ALTREF_FRAME`. `None` for the first two
3869+ // inter frames of a GOP, where the frame two back IS the key frame.
3870+ altref: Option<&Picture>, fctx: &crate::decode::FrameCtx,
3843 ) -> Result<Encoded> {3871 ) -> Result<Encoded> {
3844 picture.check()?;3872 picture.check()?;
3845 if !picture.width.is_multiple_of(SUPERBLOCK) || !picture.height.is_multiple_of(SUPERBLOCK) {3873 if !picture.width.is_multiple_of(SUPERBLOCK) || !picture.height.is_multiple_of(SUPERBLOCK) {
@@ -3862,14 +3890,33 @@ pub(crate) fn encode_inter_frame(
3862 // overwrites slot 0, so the frame just coded is always what the next one3890 // overwrites slot 0, so the frame just coded is always what the next one
3863 // predicts against.3891 // predicts against.
3864 const LAST_SLOT: u8 = 0;3892 const LAST_SLOT: u8 = 0;
3893+ // Slot 0 and slot 2 alternate so the frame two back survives one more
3894+ // frame: frame n writes A(n) = 0 for odd n, 2 for even, so A(n) = A(n-2)
3895+ // and the picture this frame names as `ALTREF_FRAME` is the one sitting
3896+ // in the very slot it will overwrite.
3897+ let self_slot = if order_hint % 2 == 1 { 0 } else { 2 };
3898+ let last_slot = if order_hint <= 1 {
3899+ LAST_SLOT
3900+ } else if (order_hint - 1) % 2 == 1 {
3901+ 0
3902+ } else {
3903+ 2
3904+ };
3865 // `render`, not `picture.width`/`picture.height`: `picture` here is3905 // `render`, not `picture.width`/`picture.height`: `picture` here is
3866 // already padded to a whole number of superblocks (`encode_sequence`'s3906 // already padded to a whole number of superblocks (`encode_sequence`'s
3867 // `padded_to(SUPERBLOCK)`), and the header's `mi_cols`/`mi_rows` (and so3907 // `padded_to(SUPERBLOCK)`), and the header's `mi_cols`/`mi_rows` (and so
3868 // every true-edge clamp downstream) must come from the frame's real,3908 // every true-edge clamp downstream) must come from the frame's real,
3869 // unpadded size, same as `key_frame_headers_colour` takes `render` and3909 // unpadded size, same as `key_frame_headers_colour` takes `render` and
3870 // not the padded picture in `encode_key_frame_inner`.3910 // not the padded picture in `encode_key_frame_inner`.
3871- let (seq, mut header) =3911+ let (seq, mut header) = inter_frame_headers_slots(
3872- inter_frame_headers(render.0, render.1, base_q_idx, order_hint, LAST_SLOT)?;3912+ render.0,
3913+ render.1,
3914+ base_q_idx,
3915+ order_hint,
3916+ last_slot,
3917+ self_slot,
3918+ if altref.is_some() { self_slot } else { GOLDEN_SLOT },
3919+ )?;
3873 header.render_width = render.0 as u32;3920 header.render_width = render.0 as u32;
3874 header.render_height = render.1 as u32;3921 header.render_height = render.1 as u32;
3875 // `TxMode::Select` here too: an inter block then codes one `txfm_split`3922 // `TxMode::Select` here too: an inter block then codes one `txfm_split`
@@ -3974,18 +4021,25 @@ pub(crate) fn encode_inter_frame(
3974 let (mi_row, mi_col) = (r32 * 8, c32 * 8);4021 let (mi_row, mi_col) = (r32 * 8, c32 * 8);
3975 let stack =4022 let stack =
3976 find_mv_stack(&grid, mi_row, mi_col, 8, 8, LAST_FRAME, mi_cols, mi_rows);4023 find_mv_stack(&grid, mi_row, mi_col, 8, 8, LAST_FRAME, mi_cols, mi_rows);
3977- let golden_stack = golden.map(|_| {4024+ let extra_stacks: Vec<(i8, &Picture, MvStack)> = [
3978- find_mv_stack(4025+ (crate::mvstack::GOLDEN_FRAME, golden),
3979- &grid,4026+ (crate::mvstack::ALTREF_FRAME, altref),
3980- mi_row,4027+ ]
3981- mi_col,4028+ .into_iter()
3982- 8,4029+ .filter_map(|(r, pic)| {
3983- 8,4030+ pic.map(|p| {
3984- crate::mvstack::GOLDEN_FRAME,4031+ (
3985- mi_cols,4032+ r,
3986- mi_rows,4033+ p,
3987- )4034+ find_mv_stack(&grid, mi_row, mi_col, 8, 8, r, mi_cols, mi_rows),
3988- });4035+ )
4036+ })
4037+ })
4038+ .collect();
4039+ let extra: Vec<(i8, &Picture, &MvStack)> = extra_stacks
4040+ .iter()
4041+ .map(|(r, p, st)| (*r, *p, st))
4042+ .collect();
3989 4043
3990 let base = snapshot(&luma, &chroma, (x, y), BLOCK);4044 let base = snapshot(&luma, &chroma, (x, y), BLOCK);
3991 let (block, mut cost_whole) = search_inter_block(4045 let (block, mut cost_whole) = search_inter_block(
@@ -3996,7 +4050,7 @@ pub(crate) fn encode_inter_frame(
3996 &mode_bits_table,4050 &mode_bits_table,
3997 reference,4051 reference,
3998 &stack,4052 &stack,
3999- golden.zip(golden_stack.as_ref()), fctx,4053+ &extra, fctx,
4000 );4054 );
4001 cost_whole += search.lambda * partition_bits(BLOCK, false);4055 cost_whole += search.lambda * partition_bits(BLOCK, false);
4002 let after_whole = snapshot(&luma, &chroma, (x, y), BLOCK);4056 let after_whole = snapshot(&luma, &chroma, (x, y), BLOCK);
@@ -4368,9 +4422,23 @@ pub(crate) fn encode_inter_frame(
4368 }4422 }
4369 }4423 }
4370 });4424 });
4425+ let trial_altref = altref.map(|a| {
4426+ if (a.width, a.height) == (fw, fh) {
4427+ a.clone()
4428+ } else {
4429+ Picture {
4430+ width: fw,
4431+ height: fh,
4432+ y: crop_plane(&a.y, a.width, fw, fh),
4433+ u: crop_plane(&a.u, a.width / 2, fw / 2, fh / 2),
4434+ v: crop_plane(&a.v, a.width / 2, fw / 2, fh / 2),
4435+ }
4436+ }
4437+ });
4371 let mut refs: [Option<&Picture>; 8] = [None; 8];4438 let mut refs: [Option<&Picture>; 8] = [None; 8];
4372 refs[1] = Some(&trial_ref);4439 refs[1] = Some(&trial_ref);
4373 refs[4] = trial_golden.as_ref();4440 refs[4] = trial_golden.as_ref();
4441+ refs[7] = trial_altref.as_ref();
4374 let refpix = crate::decode::RefPix::ready(refs);4442 let refpix = crate::decode::RefPix::ready(refs);
4375 pick_and_apply_filters(4443 pick_and_apply_filters(
4376 &mut header,4444 &mut header,
@@ -4495,6 +4563,9 @@ pub(crate) fn encode_sequence_with_ctx(
4495 // key frame refreshes every slot, each inter frame only slot 0), which is4563 // key frame refreshes every slot, each inter frame only slot 0), which is
4496 // what `GOLDEN_FRAME` names.4564 // what `GOLDEN_FRAME` names.
4497 let golden = key.reconstruction.clone();4565 let golden = key.reconstruction.clone();
4566+ // The frame two back, once there is one that is not the key frame
4567+ // itself (which `GOLDEN_FRAME` already names).
4568+ let mut prev2: Option<Picture> = None;
4498 let mut carried = key.next_cdfs.clone();4569 let mut carried = key.next_cdfs.clone();
4499 let mut reference = key.reconstruction.clone();4570 let mut reference = key.reconstruction.clone();
4500 let mut frames = vec![crop_encoded(&key, render.0, render.1)];4571 let mut frames = vec![crop_encoded(&key, render.0, render.1)];
@@ -4515,11 +4586,15 @@ pub(crate) fn encode_sequence_with_ctx(
4515 order_hint,4586 order_hint,
4516 render,4587 render,
4517 Some(&carried.0),4588 Some(&carried.0),
4518- Some(&golden), fctx,4589+ Some(&golden),
4590+ prev2.as_ref(), fctx,
4519 )?;4591 )?;
4520 stream.extend_from_slice(&inter.stream);4592 stream.extend_from_slice(&inter.stream);
4521 carried = inter.next_cdfs.clone();4593 carried = inter.next_cdfs.clone();
4522- reference = inter.reconstruction.clone();4594+ prev2 = Some(std::mem::replace(
4595+ &mut reference,
4596+ inter.reconstruction.clone(),
4597+ ));
4523 frames.push(crop_encoded(&inter, render.0, render.1));4598 frames.push(crop_encoded(&inter, render.0, render.1));
4524 }4599 }
4525 Ok(EncodedSequence { stream, frames })4600 Ok(EncodedSequence { stream, frames })
@@ -6552,7 +6627,7 @@ mod tests {
6552 let padded_pic = picture.padded_to(SUPERBLOCK);6627 let padded_pic = picture.padded_to(SUPERBLOCK);
6553 let t = Instant::now();6628 let t = Instant::now();
6554 let inter =6629 let inter =
6555- encode_inter_frame(&padded_pic, &padded_ref, 100, 0.5, 1, (width, height), None, None, fctx).unwrap();6630+ encode_inter_frame(&padded_pic, &padded_ref, 100, 0.5, 1, (width, height), None, None, None, fctx).unwrap();
6556 let inter_t = t.elapsed();6631 let inter_t = t.elapsed();
6557 eprintln!(6632 eprintln!(
6558 "inter frame vs its own key frame: {inter_t:>9.2?} ({} bytes, inter share \6633 "inter frame vs its own key frame: {inter_t:>9.2?} ({} bytes, inter share \
@@ -6650,7 +6725,7 @@ mod tests {
6650 stage_reset();6725 stage_reset();
6651 let t = Instant::now();6726 let t = Instant::now();
6652 let inter =6727 let inter =
6653- encode_inter_frame(&padded_pic, &padded_ref, 100, 0.5, 1, (width, height), None, None, fctx).unwrap();6728+ encode_inter_frame(&padded_pic, &padded_ref, 100, 0.5, 1, (width, height), None, None, None, fctx).unwrap();
6654 let total_t = t.elapsed();6729 let total_t = t.elapsed();
6655 let [motion_search, interpolation, transform_quant, entropy] = stage_read();6730 let [motion_search, interpolation, transform_quant, entropy] = stage_read();
6656 let accounted = motion_search + transform_quant + entropy;6731 let accounted = motion_search + transform_quant + entropy;
@@ -6827,7 +6902,7 @@ mod tests {
6827 q,6902 q,
6828 0.5,6903 0.5,
6829 1,6904 1,
6830- (width, height), None, None, fctx,6905+ (width, height), None, None, None, fctx,
6831 )6906 )
6832 .unwrap();6907 .unwrap();
6833 let baseline_psnr = psnr(&baseline.reconstruction.y, &inter_source.y);6908 let baseline_psnr = psnr(&baseline.reconstruction.y, &inter_source.y);
@@ -6844,7 +6919,7 @@ mod tests {
6844 q,6919 q,
6845 0.5,6920 0.5,
6846 1,6921 1,
6847- (width, height), None, None, fctx,6922+ (width, height), None, None, None, fctx,
6848 )6923 )
6849 .unwrap();6924 .unwrap();
6850 let pruned_psnr = psnr(&pruned.reconstruction.y, &inter_source.y);6925 let pruned_psnr = psnr(&pruned.reconstruction.y, &inter_source.y);
crates/ec-av1/src/encoder.rsmodified+8 -0
@@ -234,6 +234,9 @@ pub struct Av1Encoder {
234 /// The last key frame's own (padded) reconstruction: `GOLDEN_FRAME`,234 /// The last key frame's own (padded) reconstruction: `GOLDEN_FRAME`,
235 /// which stays in DPB slot 1 until the next key frame refreshes it.235 /// which stays in DPB slot 1 until the next key frame refreshes it.
236 golden: Option<Picture>,236 golden: Option<Picture>,
237+ /// The frame two back: `ALTREF_FRAME`, in the slot the next frame is
238+ /// about to refresh (`encode_inter_frame`'s 0/2 alternation).
239+ prev2: Option<Picture>,
237 }240 }
238 241
239 /// The encoder stays `Send` now that it owns a `FrameCtx` (whose cells are242 /// The encoder stays `Send` now that it owns a `FrameCtx` (whose cells are
@@ -261,6 +264,7 @@ impl Av1Encoder {
261 Ok(Self {264 Ok(Self {
262 carried_cdfs: None,265 carried_cdfs: None,
263 golden: None,266 golden: None,
267+ prev2: None,
264 color_config: config.colour.color_config(),268 color_config: config.colour.color_config(),
265 config,269 config,
266 reference: None,270 reference: None,
@@ -367,6 +371,7 @@ impl Av1Encoder {
367 render,371 render,
368 self.carried_cdfs.as_ref().map(|c| &c.0),372 self.carried_cdfs.as_ref().map(|c| &c.0),
369 self.golden.as_ref(),373 self.golden.as_ref(),
374+ self.prev2.as_ref(),
370 &self.fctx,375 &self.fctx,
371 )?376 )?
372 };377 };
@@ -374,6 +379,9 @@ impl Av1Encoder {
374 self.carried_cdfs = Some(encoded.next_cdfs.clone());379 self.carried_cdfs = Some(encoded.next_cdfs.clone());
375 if is_key {380 if is_key {
376 self.golden = Some(encoded.reconstruction.clone());381 self.golden = Some(encoded.reconstruction.clone());
382+ self.prev2 = None;
383+ } else {
384+ self.prev2 = self.reference.take();
377 }385 }
378 self.reference = Some(encoded.reconstruction.clone());386 self.reference = Some(encoded.reconstruction.clone());
379 self.next_index += 1;387 self.next_index += 1;