ref: 21a0dade42c4eef9398c6312c14d60f3cbf14431
parent: 940db8fc4e3c9cca983acf2d7c920e8dbc34b267
author: Marco <[email protected]>
date: Thu Aug 14 05:18:38 EDT 2014
vp8: Modify to use closest reference in zero_mv bias. Modify zero_mv bias condition to include check that "closest" reference is last_frame. This is needed for temporal layers, where the last_frame is not always the closest reference. Also, constain zeromv_count to be for last_frame reference. Change-Id: I7af54a809ebf01ef43b9933c9d4095b6cb189390
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -3150,10 +3150,8 @@
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 */
{
@@ -3165,9 +3163,7 @@
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)
{
@@ -3181,10 +3177,8 @@
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) */
@@ -3195,10 +3189,8 @@
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
}
}
}
@@ -3211,9 +3203,7 @@
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)
{
@@ -3227,10 +3217,8 @@
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) */
@@ -3241,10 +3229,8 @@
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
}
}
}
@@ -3256,9 +3242,7 @@
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
@@ -3494,6 +3478,31 @@
}
#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)
{
@@ -4420,7 +4429,8 @@
{
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++;
}
--- a/vp8/encoder/onyx_int.h
+++ b/vp8/encoder/onyx_int.h
@@ -684,9 +684,10 @@
int mr_low_res_mb_cols;
/* Indicate if lower-res mv info is available */
unsigned char mr_low_res_mv_avail;
+#endif
/* The frame number of each reference frames */
unsigned int current_ref_frames[MAX_REF_FRAMES];
-#endif
+ MV_REFERENCE_FRAME closest_reference_frame;
struct rd_costs_struct
{
--- a/vp8/encoder/pickinter.c
+++ b/vp8/encoder/pickinter.c
@@ -505,16 +505,11 @@
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;
}