cm->alt_fb_idx = cm->gld_fb_idx = cm->new_fb_idx;
-#if CONFIG_MULTI_RES_ENCODING
cpi->current_ref_frames[GOLDEN_FRAME] = cm->current_video_frame;
cpi->current_ref_frames[ALTREF_FRAME] = cm->current_video_frame;
-#endif
}
else /* For non key frames */
{
cm->yv12_fb[cm->alt_fb_idx].flags &= ~VP8_ALTR_FRAME;
cm->alt_fb_idx = cm->new_fb_idx;
-#if CONFIG_MULTI_RES_ENCODING
cpi->current_ref_frames[ALTREF_FRAME] = cm->current_video_frame;
-#endif
}
else if (cm->copy_buffer_to_arf)
{
yv12_fb[cm->alt_fb_idx].flags &= ~VP8_ALTR_FRAME;
cm->alt_fb_idx = cm->lst_fb_idx;
-#if CONFIG_MULTI_RES_ENCODING
cpi->current_ref_frames[ALTREF_FRAME] =
cpi->current_ref_frames[LAST_FRAME];
-#endif
}
}
else /* if (cm->copy_buffer_to_arf == 2) */
yv12_fb[cm->alt_fb_idx].flags &= ~VP8_ALTR_FRAME;
cm->alt_fb_idx = cm->gld_fb_idx;
-#if CONFIG_MULTI_RES_ENCODING
cpi->current_ref_frames[ALTREF_FRAME] =
cpi->current_ref_frames[GOLDEN_FRAME];
-#endif
}
}
}
cm->yv12_fb[cm->gld_fb_idx].flags &= ~VP8_GOLD_FRAME;
cm->gld_fb_idx = cm->new_fb_idx;
-#if CONFIG_MULTI_RES_ENCODING
cpi->current_ref_frames[GOLDEN_FRAME] = cm->current_video_frame;
-#endif
}
else if (cm->copy_buffer_to_gf)
{
yv12_fb[cm->gld_fb_idx].flags &= ~VP8_GOLD_FRAME;
cm->gld_fb_idx = cm->lst_fb_idx;
-#if CONFIG_MULTI_RES_ENCODING
cpi->current_ref_frames[GOLDEN_FRAME] =
cpi->current_ref_frames[LAST_FRAME];
-#endif
}
}
else /* if (cm->copy_buffer_to_gf == 2) */
yv12_fb[cm->gld_fb_idx].flags &= ~VP8_GOLD_FRAME;
cm->gld_fb_idx = cm->alt_fb_idx;
-#if CONFIG_MULTI_RES_ENCODING
cpi->current_ref_frames[GOLDEN_FRAME] =
cpi->current_ref_frames[ALTREF_FRAME];
-#endif
}
}
}
cm->yv12_fb[cm->lst_fb_idx].flags &= ~VP8_LAST_FRAME;
cm->lst_fb_idx = cm->new_fb_idx;
-#if CONFIG_MULTI_RES_ENCODING
cpi->current_ref_frames[LAST_FRAME] = cm->current_video_frame;
-#endif
}
#if CONFIG_TEMPORAL_DENOISING
}
#endif
+ // Find the reference frame closest to the current frame.
+ cpi->closest_reference_frame = LAST_FRAME;
+ if (cm->frame_type != KEY_FRAME) {
+ int i;
+ MV_REFERENCE_FRAME closest_ref = INTRA_FRAME;
+ if (cpi->ref_frame_flags & VP8_LAST_FRAME) {
+ closest_ref = LAST_FRAME;
+ } else if (cpi->ref_frame_flags & VP8_GOLD_FRAME) {
+ closest_ref = GOLDEN_FRAME;
+ } else if (cpi->ref_frame_flags & VP8_ALTR_FRAME) {
+ closest_ref = ALTREF_FRAME;
+ }
+ for (i = 1; i <= 3; i++) {
+ vpx_ref_frame_type_t ref_frame_type = (vpx_ref_frame_type_t)
+ ((i == 3) ? 4 : i);
+ if (cpi->ref_frame_flags & ref_frame_type) {
+ if ((cm->current_video_frame - cpi->current_ref_frames[i]) <
+ (cm->current_video_frame - cpi->current_ref_frames[closest_ref])) {
+ closest_ref = i;
+ }
+ }
+ }
+ cpi->closest_reference_frame = closest_ref;
+ }
+
/* Set various flags etc to special state if it is a key frame */
if (cm->frame_type == KEY_FRAME)
{
{
for (mb_col = 0; mb_col < cm->mb_cols; mb_col ++)
{
- if(tmp->mbmi.mode == ZEROMV)
+ if (tmp->mbmi.mode == ZEROMV &&
+ tmp->mbmi.ref_frame == LAST_FRAME)
cpi->zeromv_count++;
tmp++;
}
this_rd = RDCOST(x->rdmult, x->rddiv, rate2, *distortion2);
- /* Adjust rd to bias to ZEROMV */
- if(this_mode == ZEROMV)
+ // Adjust rd for ZEROMV and LAST, if LAST is the closest reference frame.
+ if (this_mode == ZEROMV &&
+ x->e_mbd.mode_info_context->mbmi.ref_frame == LAST_FRAME &&
+ cpi->closest_reference_frame == LAST_FRAME)
{
- /* Bias to ZEROMV on LAST_FRAME reference when it is available. */
- if ((cpi->ref_frame_flags & VP8_LAST_FRAME &
- cpi->common.refresh_last_frame)
- && x->e_mbd.mode_info_context->mbmi.ref_frame != LAST_FRAME)
- rd_adj = 100;
-
- // rd_adj <= 100
this_rd = ((int64_t)this_rd) * rd_adj / 100;
}