| Index: source/libvpx/vp9/encoder/vp9_firstpass.c
|
| ===================================================================
|
| --- source/libvpx/vp9/encoder/vp9_firstpass.c (revision 223100)
|
| +++ source/libvpx/vp9/encoder/vp9_firstpass.c (working copy)
|
| @@ -346,7 +346,7 @@
|
| // Set up pointers for this macro block recon buffer
|
| xd->plane[0].pre[0].buf = recon_buffer->y_buffer + recon_yoffset;
|
|
|
| - switch (xd->mode_info_context->mbmi.sb_type) {
|
| + switch (xd->this_mi->mbmi.sb_type) {
|
| case BLOCK_8X8:
|
| vp9_mse8x8(x->plane[0].src.buf, x->plane[0].src.stride,
|
| xd->plane[0].pre[0].buf, xd->plane[0].pre[0].stride,
|
| @@ -385,7 +385,7 @@
|
| int further_steps = (MAX_MVSEARCH_STEPS - 1) - step_param;
|
| int n;
|
| vp9_variance_fn_ptr_t v_fn_ptr =
|
| - cpi->fn_ptr[xd->mode_info_context->mbmi.sb_type];
|
| + cpi->fn_ptr[xd->this_mi->mbmi.sb_type];
|
| int new_mv_mode_penalty = 256;
|
|
|
| int sr = 0;
|
| @@ -402,7 +402,7 @@
|
| further_steps -= sr;
|
|
|
| // override the default variance function to use MSE
|
| - switch (xd->mode_info_context->mbmi.sb_type) {
|
| + switch (xd->this_mi->mbmi.sb_type) {
|
| case BLOCK_8X8:
|
| v_fn_ptr.vf = vp9_mse8x8;
|
| break;
|
| @@ -505,9 +505,12 @@
|
| setup_dst_planes(xd, new_yv12, 0, 0);
|
|
|
| x->partition_info = x->pi;
|
| + xd->mi_8x8 = cm->mi_grid_visible;
|
| + // required for vp9_frame_init_quantizer
|
| + xd->this_mi =
|
| + xd->mi_8x8[0] = cm->mi;
|
| + xd->mic_stream_ptr = cm->mi;
|
|
|
| - xd->mode_info_context = cm->mi;
|
| -
|
| setup_block_dptrs(&x->e_mbd, cm->subsampling_x, cm->subsampling_y);
|
|
|
| vp9_frame_init_quantizer(cpi);
|
| @@ -549,23 +552,23 @@
|
|
|
| if (mb_col * 2 + 1 < cm->mi_cols) {
|
| if (mb_row * 2 + 1 < cm->mi_rows) {
|
| - xd->mode_info_context->mbmi.sb_type = BLOCK_16X16;
|
| + xd->this_mi->mbmi.sb_type = BLOCK_16X16;
|
| } else {
|
| - xd->mode_info_context->mbmi.sb_type = BLOCK_16X8;
|
| + xd->this_mi->mbmi.sb_type = BLOCK_16X8;
|
| }
|
| } else {
|
| if (mb_row * 2 + 1 < cm->mi_rows) {
|
| - xd->mode_info_context->mbmi.sb_type = BLOCK_8X16;
|
| + xd->this_mi->mbmi.sb_type = BLOCK_8X16;
|
| } else {
|
| - xd->mode_info_context->mbmi.sb_type = BLOCK_8X8;
|
| + xd->this_mi->mbmi.sb_type = BLOCK_8X8;
|
| }
|
| }
|
| - xd->mode_info_context->mbmi.ref_frame[0] = INTRA_FRAME;
|
| + xd->this_mi->mbmi.ref_frame[0] = INTRA_FRAME;
|
| set_mi_row_col(cm, xd,
|
| mb_row << 1,
|
| - 1 << mi_height_log2(xd->mode_info_context->mbmi.sb_type),
|
| + 1 << mi_height_log2(xd->this_mi->mbmi.sb_type),
|
| mb_col << 1,
|
| - 1 << mi_height_log2(xd->mode_info_context->mbmi.sb_type));
|
| + 1 << mi_height_log2(xd->this_mi->mbmi.sb_type));
|
|
|
| // do intra 16x16 prediction
|
| this_error = vp9_encode_intra(x, use_dc_pred);
|
| @@ -661,13 +664,13 @@
|
| mv.as_mv.col <<= 3;
|
| this_error = motion_error;
|
| vp9_set_mbmode_and_mvs(x, NEWMV, &mv);
|
| - xd->mode_info_context->mbmi.txfm_size = TX_4X4;
|
| - xd->mode_info_context->mbmi.ref_frame[0] = LAST_FRAME;
|
| - xd->mode_info_context->mbmi.ref_frame[1] = NONE;
|
| + xd->this_mi->mbmi.tx_size = TX_4X4;
|
| + xd->this_mi->mbmi.ref_frame[0] = LAST_FRAME;
|
| + xd->this_mi->mbmi.ref_frame[1] = NONE;
|
| vp9_build_inter_predictors_sby(xd, mb_row << 1,
|
| mb_col << 1,
|
| - xd->mode_info_context->mbmi.sb_type);
|
| - vp9_encode_sby(x, xd->mode_info_context->mbmi.sb_type);
|
| + xd->this_mi->mbmi.sb_type);
|
| + vp9_encode_sby(x, xd->this_mi->mbmi.sb_type);
|
| sum_mvr += mv.as_mv.row;
|
| sum_mvr_abs += abs(mv.as_mv.row);
|
| sum_mvc += mv.as_mv.col;
|
| @@ -1092,7 +1095,6 @@
|
| return q;
|
| }
|
|
|
| -
|
| extern void vp9_new_framerate(VP9_COMP *cpi, double framerate);
|
|
|
| void vp9_init_second_pass(VP9_COMP *cpi) {
|
| @@ -1718,6 +1720,8 @@
|
| old_boost_score = boost_score;
|
| }
|
|
|
| + cpi->gf_zeromotion_pct = (int)(zero_motion_accumulator * 1000.0);
|
| +
|
| // Don't allow a gf too near the next kf
|
| if ((cpi->twopass.frames_to_key - i) < MIN_GF_INTERVAL) {
|
| while (i < cpi->twopass.frames_to_key) {
|
| @@ -2079,63 +2083,71 @@
|
|
|
| vp9_clear_system_state();
|
|
|
| - // Special case code for first frame.
|
| - if (cpi->common.current_video_frame == 0) {
|
| - cpi->twopass.est_max_qcorrection_factor = 1.0;
|
| + if (cpi->oxcf.end_usage == USAGE_CONSTANT_QUALITY) {
|
| + cpi->active_worst_quality = cpi->oxcf.cq_level;
|
| + } else {
|
| + // Special case code for first frame.
|
| + if (cpi->common.current_video_frame == 0) {
|
| + int section_target_bandwidth =
|
| + (int)(cpi->twopass.bits_left / frames_left);
|
| + cpi->twopass.est_max_qcorrection_factor = 1.0;
|
|
|
| - // Set a cq_level in constrained quality mode.
|
| - if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) {
|
| - int est_cq = estimate_cq(cpi, &cpi->twopass.total_left_stats,
|
| - (int)(cpi->twopass.bits_left / frames_left));
|
| + // Set a cq_level in constrained quality mode.
|
| + if (cpi->oxcf.end_usage == USAGE_CONSTRAINED_QUALITY) {
|
| + int est_cq = estimate_cq(cpi, &cpi->twopass.total_left_stats,
|
| + section_target_bandwidth);
|
|
|
| - cpi->cq_target_quality = cpi->oxcf.cq_level;
|
| - if (est_cq > cpi->cq_target_quality)
|
| - cpi->cq_target_quality = est_cq;
|
| - }
|
| + cpi->cq_target_quality = cpi->oxcf.cq_level;
|
| + if (est_cq > cpi->cq_target_quality)
|
| + cpi->cq_target_quality = est_cq;
|
| + }
|
|
|
| - // guess at maxq needed in 2nd pass
|
| - cpi->twopass.maxq_max_limit = cpi->worst_quality;
|
| - cpi->twopass.maxq_min_limit = cpi->best_quality;
|
| + // guess at maxq needed in 2nd pass
|
| + cpi->twopass.maxq_max_limit = cpi->worst_quality;
|
| + cpi->twopass.maxq_min_limit = cpi->best_quality;
|
|
|
| - tmp_q = estimate_max_q(cpi, &cpi->twopass.total_left_stats,
|
| - (int)(cpi->twopass.bits_left / frames_left));
|
| + tmp_q = estimate_max_q(cpi, &cpi->twopass.total_left_stats,
|
| + section_target_bandwidth);
|
|
|
| - cpi->active_worst_quality = tmp_q;
|
| - cpi->ni_av_qi = tmp_q;
|
| - cpi->avg_q = vp9_convert_qindex_to_q(tmp_q);
|
| + cpi->active_worst_quality = tmp_q;
|
| + cpi->ni_av_qi = tmp_q;
|
| + cpi->avg_q = vp9_convert_qindex_to_q(tmp_q);
|
|
|
| #ifndef ONE_SHOT_Q_ESTIMATE
|
| - // Limit the maxq value returned subsequently.
|
| - // This increases the risk of overspend or underspend if the initial
|
| - // estimate for the clip is bad, but helps prevent excessive
|
| - // variation in Q, especially near the end of a clip
|
| - // where for example a small overspend may cause Q to crash
|
| - adjust_maxq_qrange(cpi);
|
| + // Limit the maxq value returned subsequently.
|
| + // This increases the risk of overspend or underspend if the initial
|
| + // estimate for the clip is bad, but helps prevent excessive
|
| + // variation in Q, especially near the end of a clip
|
| + // where for example a small overspend may cause Q to crash
|
| + adjust_maxq_qrange(cpi);
|
| #endif
|
| - }
|
| + }
|
|
|
| #ifndef ONE_SHOT_Q_ESTIMATE
|
| - // The last few frames of a clip almost always have to few or too many
|
| - // bits and for the sake of over exact rate control we dont want to make
|
| - // radical adjustments to the allowed quantizer range just to use up a
|
| - // few surplus bits or get beneath the target rate.
|
| - else if ((cpi->common.current_video_frame <
|
| - (((unsigned int)cpi->twopass.total_stats.count * 255) >> 8)) &&
|
| - ((cpi->common.current_video_frame + cpi->baseline_gf_interval) <
|
| - (unsigned int)cpi->twopass.total_stats.count)) {
|
| - if (frames_left < 1)
|
| - frames_left = 1;
|
| + // The last few frames of a clip almost always have to few or too many
|
| + // bits and for the sake of over exact rate control we dont want to make
|
| + // radical adjustments to the allowed quantizer range just to use up a
|
| + // few surplus bits or get beneath the target rate.
|
| + else if ((cpi->common.current_video_frame <
|
| + (((unsigned int)cpi->twopass.total_stats.count * 255) >> 8)) &&
|
| + ((cpi->common.current_video_frame + cpi->baseline_gf_interval) <
|
| + (unsigned int)cpi->twopass.total_stats.count)) {
|
| + int section_target_bandwidth =
|
| + (int)(cpi->twopass.bits_left / frames_left);
|
| + if (frames_left < 1)
|
| + frames_left = 1;
|
|
|
| - tmp_q = estimate_max_q(
|
| - cpi,
|
| - &cpi->twopass.total_left_stats,
|
| - (int)(cpi->twopass.bits_left / frames_left));
|
| + tmp_q = estimate_max_q(
|
| + cpi,
|
| + &cpi->twopass.total_left_stats,
|
| + section_target_bandwidth);
|
|
|
| - // Make a damped adjustment to active max Q
|
| - cpi->active_worst_quality =
|
| - adjust_active_maxq(cpi->active_worst_quality, tmp_q);
|
| + // Make a damped adjustment to active max Q
|
| + cpi->active_worst_quality =
|
| + adjust_active_maxq(cpi->active_worst_quality, tmp_q);
|
| + }
|
| +#endif
|
| }
|
| -#endif
|
| vp9_zero(this_frame);
|
| if (EOF == input_stats(cpi, &this_frame))
|
| return;
|
| @@ -2155,6 +2167,8 @@
|
| // Define next gf group and assign bits to it
|
| this_frame_copy = this_frame;
|
|
|
| + cpi->gf_zeromotion_pct = 0;
|
| +
|
| #if CONFIG_MULTIPLE_ARF
|
| if (cpi->multi_arf_enabled) {
|
| define_fixed_arf_period(cpi);
|
| @@ -2165,6 +2179,15 @@
|
| }
|
| #endif
|
|
|
| + if (cpi->gf_zeromotion_pct > 995) {
|
| + // As long as max_thresh for encode breakout is small enough, it is ok
|
| + // to enable it for no-show frame, i.e. set enable_encode_breakout to 2.
|
| + if (!cpi->common.show_frame)
|
| + cpi->enable_encode_breakout = 0;
|
| + else
|
| + cpi->enable_encode_breakout = 2;
|
| + }
|
| +
|
| // If we are going to code an altref frame at the end of the group
|
| // and the current frame is not a key frame....
|
| // If the previous group used an arf this frame has already benefited
|
|
|