ref: 9a7b92ebe748423432b92d8ad4d25d8a8a879391
parent: 757a45f3ebcb62ae1262c80f68eee447d6788de5
parent: b082790c7d1e16dde329f1baea153c0fe86112d5
author: John Koleszar <jkoleszar@google.com>
date: Thu Jan 13 19:05:08 EST 2011
Merge remote branch 'origin/master' into experimental Change-Id: I229048ab797a4087437c265e6bb96db5c32e7b3d
--- a/vp8/encoder/onyx_if.c
+++ b/vp8/encoder/onyx_if.c
@@ -3793,49 +3793,56 @@
}
// Set an active best quality and if necessary active worst quality
- if (cpi->pass == 2 || (cm->current_video_frame > 150))
+ // There is some odd behaviour for one pass here that needs attention.
+ if ( (cpi->pass == 2) || (cpi->ni_frames > 150))
{
- int Q;
- //int tmp;
-
vp8_clear_system_state();
Q = cpi->active_worst_quality;
- if ((cm->frame_type == KEY_FRAME) || cm->refresh_golden_frame || cpi->common.refresh_alt_ref_frame)
+ if ( cm->frame_type == KEY_FRAME )
{
- if (cm->frame_type != KEY_FRAME)
+ // Special case for key frames forced because we have reached
+ // the maximum key frame interval. Here force the Q to a range
+ // close to but just below the ambient Q to minimize the risk
+ // of popping
+ if ( cpi->this_key_frame_forced )
{
- if (cpi->avg_frame_qindex < cpi->active_worst_quality)
- Q = cpi->avg_frame_qindex;
+ cpi->active_worst_quality = cpi->avg_frame_qindex * 7/8;
+ cpi->active_best_quality = cpi->avg_frame_qindex * 2/3;
+ }
+ else
+ {
+ if ( cpi->pass == 2 )
+ {
+ if (cpi->gfu_boost > 600)
+ cpi->active_best_quality = kf_low_motion_minq[Q];
+ else
+ cpi->active_best_quality = kf_high_motion_minq[Q];
+ }
+ // One pass more conservative
+ else
+ cpi->active_best_quality = kf_high_motion_minq[Q];
+ }
+ }
- if ( cpi->gfu_boost > 1000 )
+ else if (cm->refresh_golden_frame || cpi->common.refresh_alt_ref_frame)
+ {
+ if (cpi->avg_frame_qindex < cpi->active_worst_quality)
+ Q = cpi->avg_frame_qindex;
+
+ if ( cpi->pass == 2 )
+ {
+ if ( cpi->gfu_boost > 1000 )
cpi->active_best_quality = gf_low_motion_minq[Q];
else if ( cpi->gfu_boost < 400 )
cpi->active_best_quality = gf_high_motion_minq[Q];
else
cpi->active_best_quality = gf_mid_motion_minq[Q];
- }
- // KEY FRAMES
- else
- {
- // Special case for key frames forced because we have reached
- // the maximum key frame interval. Here force the Q to a range
- // close to but just below the ambient Q to reduce the risk
- // of popping
- if ( cpi->this_key_frame_forced )
- {
- cpi->active_worst_quality = cpi->avg_frame_qindex * 7/8;
- cpi->active_best_quality = cpi->avg_frame_qindex * 2/3;
- }
- else
- {
- if (cpi->gfu_boost > 600)
- cpi->active_best_quality = kf_low_motion_minq[Q];
- else
- cpi->active_best_quality = kf_high_motion_minq[Q];
- }
- }
+ }
+ // One pass more conservative
+ else
+ cpi->active_best_quality = gf_high_motion_minq[Q];
}
else
{
@@ -3865,7 +3872,6 @@
cpi->active_best_quality -= min_qadjustment;
}
-
}
}
--- a/vp8/encoder/rdopt.c
+++ b/vp8/encoder/rdopt.c
@@ -1729,10 +1729,60 @@
int saddone=0;
int sr=0; //search range got from mv_pred(). It uses step_param levels. (0-7)
- *returnintra = INT_MAX;
+ MV frame_nearest_mv[4];
+ MV frame_near_mv[4];
+ MV frame_best_ref_mv[4];
+ int frame_mdcounts[4][4];
+ int frame_lf_or_gf[4];
+ unsigned char *y_buffer[4];
+ unsigned char *u_buffer[4];
+ unsigned char *v_buffer[4];
- vpx_memset(&best_mbmode, 0, sizeof(best_mbmode)); // clean
+ vpx_memset(&best_mbmode, 0, sizeof(best_mbmode));
+ if (cpi->ref_frame_flags & VP8_LAST_FLAG)
+ {
+ YV12_BUFFER_CONFIG *lst_yv12 = &cpi->common.yv12_fb[cpi->common.lst_fb_idx];
+
+ vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context, &frame_nearest_mv[LAST_FRAME], &frame_near_mv[LAST_FRAME],
+ &frame_best_ref_mv[LAST_FRAME], frame_mdcounts[LAST_FRAME], LAST_FRAME, cpi->common.ref_frame_sign_bias);
+
+ y_buffer[LAST_FRAME] = lst_yv12->y_buffer + recon_yoffset;
+ u_buffer[LAST_FRAME] = lst_yv12->u_buffer + recon_uvoffset;
+ v_buffer[LAST_FRAME] = lst_yv12->v_buffer + recon_uvoffset;
+
+ frame_lf_or_gf[LAST_FRAME] = 0;
+ }
+
+ if (cpi->ref_frame_flags & VP8_GOLD_FLAG)
+ {
+ YV12_BUFFER_CONFIG *gld_yv12 = &cpi->common.yv12_fb[cpi->common.gld_fb_idx];
+
+ vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context, &frame_nearest_mv[GOLDEN_FRAME], &frame_near_mv[GOLDEN_FRAME],
+ &frame_best_ref_mv[GOLDEN_FRAME], frame_mdcounts[GOLDEN_FRAME], GOLDEN_FRAME, cpi->common.ref_frame_sign_bias);
+
+ y_buffer[GOLDEN_FRAME] = gld_yv12->y_buffer + recon_yoffset;
+ u_buffer[GOLDEN_FRAME] = gld_yv12->u_buffer + recon_uvoffset;
+ v_buffer[GOLDEN_FRAME] = gld_yv12->v_buffer + recon_uvoffset;
+
+ frame_lf_or_gf[GOLDEN_FRAME] = 1;
+ }
+
+ if (cpi->ref_frame_flags & VP8_ALT_FLAG)
+ {
+ YV12_BUFFER_CONFIG *alt_yv12 = &cpi->common.yv12_fb[cpi->common.alt_fb_idx];
+
+ vp8_find_near_mvs(&x->e_mbd, x->e_mbd.mode_info_context, &frame_nearest_mv[ALTREF_FRAME], &frame_near_mv[ALTREF_FRAME],
+ &frame_best_ref_mv[ALTREF_FRAME], frame_mdcounts[ALTREF_FRAME], ALTREF_FRAME, cpi->common.ref_frame_sign_bias);
+
+ y_buffer[ALTREF_FRAME] = alt_yv12->y_buffer + recon_yoffset;
+ u_buffer[ALTREF_FRAME] = alt_yv12->u_buffer + recon_uvoffset;
+ v_buffer[ALTREF_FRAME] = alt_yv12->v_buffer + recon_uvoffset;
+
+ frame_lf_or_gf[ALTREF_FRAME] = 1;
+ }
+
+ *returnintra = INT_MAX;
cpi->mbs_tested_so_far++; // Count of the number of MBs tested so far this frame
x->skip = 0;
@@ -1789,8 +1839,6 @@
if (best_rd <= cpi->rd_threshes[mode_index])
continue;
-
-
// These variables hold are rolling total cost and distortion for this mode
rate2 = 0;
distortion2 = 0;
@@ -1808,58 +1856,19 @@
continue;
}
- if (x->e_mbd.mode_info_context->mbmi.ref_frame == LAST_FRAME)
+ /* everything but intra */
+ if (x->e_mbd.mode_info_context->mbmi.ref_frame)
{
- YV12_BUFFER_CONFIG *lst_yv12 = &cpi->common.yv12_fb[cpi->common.lst_fb_idx];
-
- if (!(cpi->ref_frame_flags & VP8_LAST_FLAG))
- continue;
-
- lf_or_gf = 0; // Local last frame vs Golden frame flag
-
- // Set up pointers for this macro block into the previous frame recon buffer
- x->e_mbd.pre.y_buffer = lst_yv12->y_buffer + recon_yoffset;
- x->e_mbd.pre.u_buffer = lst_yv12->u_buffer + recon_uvoffset;
- x->e_mbd.pre.v_buffer = lst_yv12->v_buffer + recon_uvoffset;
+ x->e_mbd.pre.y_buffer = y_buffer[x->e_mbd.mode_info_context->mbmi.ref_frame];
+ x->e_mbd.pre.u_buffer = u_buffer[x->e_mbd.mode_info_context->mbmi.ref_frame];
+ x->e_mbd.pre.v_buffer = v_buffer[x->e_mbd.mode_info_context->mbmi.ref_frame];
+ mode_mv[NEARESTMV] = frame_nearest_mv[x->e_mbd.mode_info_context->mbmi.ref_frame];
+ mode_mv[NEARMV] = frame_near_mv[x->e_mbd.mode_info_context->mbmi.ref_frame];
+ best_ref_mv = frame_best_ref_mv[x->e_mbd.mode_info_context->mbmi.ref_frame];
+ vpx_memcpy(mdcounts, frame_mdcounts[x->e_mbd.mode_info_context->mbmi.ref_frame], sizeof(mdcounts));
+ lf_or_gf = frame_lf_or_gf[x->e_mbd.mode_info_context->mbmi.ref_frame];
}
- else if (x->e_mbd.mode_info_context->mbmi.ref_frame == GOLDEN_FRAME)
- {
- YV12_BUFFER_CONFIG *gld_yv12 = &cpi->common.yv12_fb[cpi->common.gld_fb_idx];
- // not supposed to reference gold frame
- if (!(cpi->ref_frame_flags & VP8_GOLD_FLAG))
- continue;
-
- lf_or_gf = 1; // Local last frame vs Golden frame flag
-
- // Set up pointers for this macro block into the previous frame recon buffer
- x->e_mbd.pre.y_buffer = gld_yv12->y_buffer + recon_yoffset;
- x->e_mbd.pre.u_buffer = gld_yv12->u_buffer + recon_uvoffset;
- x->e_mbd.pre.v_buffer = gld_yv12->v_buffer + recon_uvoffset;
- }
- else if (x->e_mbd.mode_info_context->mbmi.ref_frame == ALTREF_FRAME)
- {
- YV12_BUFFER_CONFIG *alt_yv12 = &cpi->common.yv12_fb[cpi->common.alt_fb_idx];
-
- // not supposed to reference alt ref frame
- if (!(cpi->ref_frame_flags & VP8_ALT_FLAG))
- continue;
-
- //if ( !cpi->source_alt_ref_active )
- // continue;
-
- lf_or_gf = 1; // Local last frame vs Golden frame flag
-
- // Set up pointers for this macro block into the previous frame recon buffer
- x->e_mbd.pre.y_buffer = alt_yv12->y_buffer + recon_yoffset;
- x->e_mbd.pre.u_buffer = alt_yv12->u_buffer + recon_uvoffset;
- x->e_mbd.pre.v_buffer = alt_yv12->v_buffer + recon_uvoffset;
- }
-
- vp8_find_near_mvs(&x->e_mbd,
- x->e_mbd.mode_info_context,
- &mode_mv[NEARESTMV], &mode_mv[NEARMV], &best_ref_mv,
- mdcounts, x->e_mbd.mode_info_context->mbmi.ref_frame, cpi->common.ref_frame_sign_bias);
if(x->e_mbd.mode_info_context->mbmi.mode == NEWMV)
{