| Index: source/libvpx/vp9/encoder/vp9_ratectrl.c
|
| ===================================================================
|
| --- source/libvpx/vp9/encoder/vp9_ratectrl.c (revision 278778)
|
| +++ source/libvpx/vp9/encoder/vp9_ratectrl.c (working copy)
|
| @@ -159,7 +159,7 @@
|
| lrc->bits_off_target += bits_off_for_this_layer;
|
|
|
| // Clip buffer level to maximum buffer size for the layer.
|
| - lrc->bits_off_target = MIN(lrc->bits_off_target, lc->maximum_buffer_size);
|
| + lrc->bits_off_target = MIN(lrc->bits_off_target, lrc->maximum_buffer_size);
|
| lrc->buffer_level = lrc->bits_off_target;
|
| }
|
| }
|
| @@ -167,7 +167,6 @@
|
| // Update the buffer level: leaky bucket model.
|
| static void update_buffer_level(VP9_COMP *cpi, int encoded_frame_size) {
|
| const VP9_COMMON *const cm = &cpi->common;
|
| - const VP9EncoderConfig *oxcf = &cpi->oxcf;
|
| RATE_CONTROL *const rc = &cpi->rc;
|
|
|
| // Non-viewable frames are a special case and are treated as pure overhead.
|
| @@ -178,34 +177,30 @@
|
| }
|
|
|
| // Clip the buffer level to the maximum specified buffer size.
|
| - rc->bits_off_target = MIN(rc->bits_off_target, oxcf->maximum_buffer_size);
|
| + rc->bits_off_target = MIN(rc->bits_off_target, rc->maximum_buffer_size);
|
| rc->buffer_level = rc->bits_off_target;
|
|
|
| - if (cpi->use_svc && cpi->oxcf.rc_mode == RC_MODE_CBR) {
|
| + if (cpi->use_svc && cpi->oxcf.rc_mode == VPX_CBR) {
|
| update_layer_buffer_level(&cpi->svc, encoded_frame_size);
|
| }
|
| }
|
|
|
| void vp9_rc_init(const VP9EncoderConfig *oxcf, int pass, RATE_CONTROL *rc) {
|
| - if (pass == 0 && oxcf->rc_mode == RC_MODE_CBR) {
|
| - rc->avg_frame_qindex[0] = oxcf->worst_allowed_q;
|
| - rc->avg_frame_qindex[1] = oxcf->worst_allowed_q;
|
| - rc->avg_frame_qindex[2] = oxcf->worst_allowed_q;
|
| + if (pass == 0 && oxcf->rc_mode == VPX_CBR) {
|
| + rc->avg_frame_qindex[KEY_FRAME] = oxcf->worst_allowed_q;
|
| + rc->avg_frame_qindex[INTER_FRAME] = oxcf->worst_allowed_q;
|
| } else {
|
| - rc->avg_frame_qindex[0] = (oxcf->worst_allowed_q +
|
| - oxcf->best_allowed_q) / 2;
|
| - rc->avg_frame_qindex[1] = (oxcf->worst_allowed_q +
|
| - oxcf->best_allowed_q) / 2;
|
| - rc->avg_frame_qindex[2] = (oxcf->worst_allowed_q +
|
| - oxcf->best_allowed_q) / 2;
|
| + rc->avg_frame_qindex[KEY_FRAME] = (oxcf->worst_allowed_q +
|
| + oxcf->best_allowed_q) / 2;
|
| + rc->avg_frame_qindex[INTER_FRAME] = (oxcf->worst_allowed_q +
|
| + oxcf->best_allowed_q) / 2;
|
| }
|
|
|
| - rc->last_q[0] = oxcf->best_allowed_q;
|
| - rc->last_q[1] = oxcf->best_allowed_q;
|
| - rc->last_q[2] = oxcf->best_allowed_q;
|
| + rc->last_q[KEY_FRAME] = oxcf->best_allowed_q;
|
| + rc->last_q[INTER_FRAME] = oxcf->best_allowed_q;
|
|
|
| - rc->buffer_level = oxcf->starting_buffer_level;
|
| - rc->bits_off_target = oxcf->starting_buffer_level;
|
| + rc->buffer_level = rc->starting_buffer_level;
|
| + rc->bits_off_target = rc->starting_buffer_level;
|
|
|
| rc->rolling_target_bits = rc->avg_frame_bandwidth;
|
| rc->rolling_actual_bits = rc->avg_frame_bandwidth;
|
| @@ -213,6 +208,7 @@
|
| rc->long_rolling_actual_bits = rc->avg_frame_bandwidth;
|
|
|
| rc->total_actual_bits = 0;
|
| + rc->total_target_bits = 0;
|
| rc->total_target_vs_actual = 0;
|
|
|
| rc->baseline_gf_interval = DEFAULT_GF_INTERVAL;
|
| @@ -250,7 +246,7 @@
|
| // If buffer is below drop_mark, for now just drop every other frame
|
| // (starting with the next frame) until it increases back over drop_mark.
|
| int drop_mark = (int)(oxcf->drop_frames_water_mark *
|
| - oxcf->optimal_buffer_level / 100);
|
| + rc->optimal_buffer_level / 100);
|
| if ((rc->buffer_level > drop_mark) &&
|
| (rc->decimation_factor > 0)) {
|
| --rc->decimation_factor;
|
| @@ -280,7 +276,7 @@
|
| } else {
|
| if ((cpi->refresh_alt_ref_frame || cpi->refresh_golden_frame) &&
|
| !cpi->rc.is_src_frame_alt_ref &&
|
| - !(cpi->use_svc && cpi->oxcf.rc_mode == RC_MODE_CBR))
|
| + !(cpi->use_svc && cpi->oxcf.rc_mode == VPX_CBR))
|
| return cpi->rc.gf_rate_correction_factor;
|
| else
|
| return cpi->rc.rate_correction_factor;
|
| @@ -293,7 +289,7 @@
|
| } else {
|
| if ((cpi->refresh_alt_ref_frame || cpi->refresh_golden_frame) &&
|
| !cpi->rc.is_src_frame_alt_ref &&
|
| - !(cpi->use_svc && cpi->oxcf.rc_mode == RC_MODE_CBR))
|
| + !(cpi->use_svc && cpi->oxcf.rc_mode == VPX_CBR))
|
| cpi->rc.gf_rate_correction_factor = factor;
|
| else
|
| cpi->rc.rate_correction_factor = factor;
|
| @@ -432,7 +428,6 @@
|
| : rc->last_q[INTER_FRAME] * 2;
|
| }
|
| }
|
| -
|
| return MIN(active_worst_quality, rc->worst_quality);
|
| }
|
|
|
| @@ -444,10 +439,9 @@
|
| // ambient Q (at buffer = optimal level) to worst_quality level
|
| // (at buffer = critical level).
|
| const VP9_COMMON *const cm = &cpi->common;
|
| - const VP9EncoderConfig *oxcf = &cpi->oxcf;
|
| const RATE_CONTROL *rc = &cpi->rc;
|
| // Buffer level below which we push active_worst to worst_quality.
|
| - int64_t critical_level = oxcf->optimal_buffer_level >> 2;
|
| + int64_t critical_level = rc->optimal_buffer_level >> 2;
|
| int64_t buff_lvl_step = 0;
|
| int adjustment = 0;
|
| int active_worst_quality;
|
| @@ -459,26 +453,26 @@
|
| else
|
| active_worst_quality = MIN(rc->worst_quality,
|
| rc->avg_frame_qindex[KEY_FRAME] * 3 / 2);
|
| - if (rc->buffer_level > oxcf->optimal_buffer_level) {
|
| + if (rc->buffer_level > rc->optimal_buffer_level) {
|
| // Adjust down.
|
| // Maximum limit for down adjustment, ~30%.
|
| int max_adjustment_down = active_worst_quality / 3;
|
| if (max_adjustment_down) {
|
| - buff_lvl_step = ((oxcf->maximum_buffer_size -
|
| - oxcf->optimal_buffer_level) / max_adjustment_down);
|
| + buff_lvl_step = ((rc->maximum_buffer_size -
|
| + rc->optimal_buffer_level) / max_adjustment_down);
|
| if (buff_lvl_step)
|
| - adjustment = (int)((rc->buffer_level - oxcf->optimal_buffer_level) /
|
| + adjustment = (int)((rc->buffer_level - rc->optimal_buffer_level) /
|
| buff_lvl_step);
|
| active_worst_quality -= adjustment;
|
| }
|
| } else if (rc->buffer_level > critical_level) {
|
| // Adjust up from ambient Q.
|
| if (critical_level) {
|
| - buff_lvl_step = (oxcf->optimal_buffer_level - critical_level);
|
| + buff_lvl_step = (rc->optimal_buffer_level - critical_level);
|
| if (buff_lvl_step) {
|
| adjustment =
|
| (int)((rc->worst_quality - rc->avg_frame_qindex[INTER_FRAME]) *
|
| - (oxcf->optimal_buffer_level - rc->buffer_level) /
|
| + (rc->optimal_buffer_level - rc->buffer_level) /
|
| buff_lvl_step);
|
| }
|
| active_worst_quality = rc->avg_frame_qindex[INTER_FRAME] + adjustment;
|
| @@ -607,13 +601,27 @@
|
| return q;
|
| }
|
|
|
| +static int get_active_cq_level(const RATE_CONTROL *rc,
|
| + const VP9EncoderConfig *const oxcf) {
|
| + static const double cq_adjust_threshold = 0.5;
|
| + int active_cq_level = oxcf->cq_level;
|
| + if (oxcf->rc_mode == VPX_CQ &&
|
| + rc->total_target_bits > 0) {
|
| + const double x = (double)rc->total_actual_bits / rc->total_target_bits;
|
| + if (x < cq_adjust_threshold) {
|
| + active_cq_level = (int)(active_cq_level * x / cq_adjust_threshold);
|
| + }
|
| + }
|
| + return active_cq_level;
|
| +}
|
| +
|
| static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi,
|
| int *bottom_index,
|
| int *top_index) {
|
| const VP9_COMMON *const cm = &cpi->common;
|
| const RATE_CONTROL *const rc = &cpi->rc;
|
| const VP9EncoderConfig *const oxcf = &cpi->oxcf;
|
| - const int cq_level = oxcf->cq_level;
|
| + const int cq_level = get_active_cq_level(rc, oxcf);
|
| int active_best_quality;
|
| int active_worst_quality = calc_active_worst_quality_one_pass_vbr(cpi);
|
| int q;
|
| @@ -630,7 +638,7 @@
|
| int delta_qindex = vp9_compute_qdelta(rc, last_boosted_q,
|
| last_boosted_q * 0.75);
|
| active_best_quality = MAX(qindex + delta_qindex, rc->best_quality);
|
| - } else if (cm->current_video_frame > 0) {
|
| + } else {
|
| // not first frame of one pass and kf_boost is set
|
| double q_adj_factor = 1.0;
|
| double q_val;
|
| @@ -671,7 +679,7 @@
|
| q = rc->avg_frame_qindex[KEY_FRAME];
|
| }
|
| // For constrained quality dont allow Q less than the cq level
|
| - if (oxcf->rc_mode == RC_MODE_CONSTRAINED_QUALITY) {
|
| + if (oxcf->rc_mode == VPX_CQ) {
|
| if (q < cq_level)
|
| q = cq_level;
|
|
|
| @@ -683,7 +691,7 @@
|
| // Constrained quality use slightly lower active best.
|
| active_best_quality = active_best_quality * 15 / 16;
|
|
|
| - } else if (oxcf->rc_mode == RC_MODE_CONSTANT_QUALITY) {
|
| + } else if (oxcf->rc_mode == VPX_Q) {
|
| if (!cpi->refresh_alt_ref_frame) {
|
| active_best_quality = cq_level;
|
| } else {
|
| @@ -697,7 +705,7 @@
|
| arfgf_low_motion_minq, arfgf_high_motion_minq);
|
| }
|
| } else {
|
| - if (oxcf->rc_mode == RC_MODE_CONSTANT_QUALITY) {
|
| + if (oxcf->rc_mode == VPX_Q) {
|
| active_best_quality = cq_level;
|
| } else {
|
| // Use the lower of active_worst_quality and recent/average Q.
|
| @@ -707,7 +715,7 @@
|
| active_best_quality = inter_minq[rc->avg_frame_qindex[KEY_FRAME]];
|
| // For the constrained quality mode we don't want
|
| // q to fall below the cq level.
|
| - if ((oxcf->rc_mode == RC_MODE_CONSTRAINED_QUALITY) &&
|
| + if ((oxcf->rc_mode == VPX_CQ) &&
|
| (active_best_quality < cq_level)) {
|
| active_best_quality = cq_level;
|
| }
|
| @@ -744,7 +752,7 @@
|
| }
|
| #endif
|
|
|
| - if (oxcf->rc_mode == RC_MODE_CONSTANT_QUALITY) {
|
| + if (oxcf->rc_mode == VPX_Q) {
|
| q = active_best_quality;
|
| // Special case code to try and match quality with forced key frames
|
| } else if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced) {
|
| @@ -763,7 +771,7 @@
|
| #if CONFIG_MULTIPLE_ARF
|
| // Force the quantizer determined by the coding order pattern.
|
| if (cpi->multi_arf_enabled && (cm->frame_type != KEY_FRAME) &&
|
| - cpi->oxcf.rc_mode != RC_MODE_CONSTANT_QUALITY) {
|
| + cpi->oxcf.rc_mode != VPX_Q) {
|
| double new_q;
|
| double current_q = vp9_convert_qindex_to_q(active_worst_quality);
|
| int level = cpi->this_frame_weight;
|
| @@ -791,7 +799,7 @@
|
| const VP9_COMMON *const cm = &cpi->common;
|
| const RATE_CONTROL *const rc = &cpi->rc;
|
| const VP9EncoderConfig *const oxcf = &cpi->oxcf;
|
| - const int cq_level = oxcf->cq_level;
|
| + const int cq_level = get_active_cq_level(rc, oxcf);
|
| int active_best_quality;
|
| int active_worst_quality = cpi->twopass.active_worst_quality;
|
| int q;
|
| @@ -851,7 +859,7 @@
|
| q = active_worst_quality;
|
| }
|
| // For constrained quality dont allow Q less than the cq level
|
| - if (oxcf->rc_mode == RC_MODE_CONSTRAINED_QUALITY) {
|
| + if (oxcf->rc_mode == VPX_CQ) {
|
| if (q < cq_level)
|
| q = cq_level;
|
|
|
| @@ -863,7 +871,7 @@
|
| // Constrained quality use slightly lower active best.
|
| active_best_quality = active_best_quality * 15 / 16;
|
|
|
| - } else if (oxcf->rc_mode == RC_MODE_CONSTANT_QUALITY) {
|
| + } else if (oxcf->rc_mode == VPX_Q) {
|
| if (!cpi->refresh_alt_ref_frame) {
|
| active_best_quality = cq_level;
|
| } else {
|
| @@ -877,14 +885,14 @@
|
| arfgf_low_motion_minq, arfgf_high_motion_minq);
|
| }
|
| } else {
|
| - if (oxcf->rc_mode == RC_MODE_CONSTANT_QUALITY) {
|
| + if (oxcf->rc_mode == VPX_Q) {
|
| active_best_quality = cq_level;
|
| } else {
|
| active_best_quality = inter_minq[active_worst_quality];
|
|
|
| // For the constrained quality mode we don't want
|
| // q to fall below the cq level.
|
| - if ((oxcf->rc_mode == RC_MODE_CONSTRAINED_QUALITY) &&
|
| + if ((oxcf->rc_mode == VPX_CQ) &&
|
| (active_best_quality < cq_level)) {
|
| active_best_quality = cq_level;
|
| }
|
| @@ -911,7 +919,7 @@
|
| qdelta = vp9_compute_qdelta_by_rate(&cpi->rc, cm->frame_type,
|
| active_worst_quality, 2.0);
|
| } else if (!rc->is_src_frame_alt_ref &&
|
| - (oxcf->rc_mode != RC_MODE_CBR) &&
|
| + (oxcf->rc_mode != VPX_CBR) &&
|
| (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
|
| qdelta = vp9_compute_qdelta_by_rate(&cpi->rc, cm->frame_type,
|
| active_worst_quality, 1.75);
|
| @@ -921,7 +929,7 @@
|
| }
|
| #endif
|
|
|
| - if (oxcf->rc_mode == RC_MODE_CONSTANT_QUALITY) {
|
| + if (oxcf->rc_mode == VPX_Q) {
|
| q = active_best_quality;
|
| // Special case code to try and match quality with forced key frames.
|
| } else if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced) {
|
| @@ -940,7 +948,7 @@
|
| #if CONFIG_MULTIPLE_ARF
|
| // Force the quantizer determined by the coding order pattern.
|
| if (cpi->multi_arf_enabled && (cm->frame_type != KEY_FRAME) &&
|
| - cpi->oxcf.rc_mode != RC_MODE_CONSTANT_QUALITY) {
|
| + cpi->oxcf.rc_mode != VPX_Q) {
|
| double new_q;
|
| double current_q = vp9_convert_qindex_to_q(active_worst_quality);
|
| int level = cpi->this_frame_weight;
|
| @@ -966,14 +974,13 @@
|
| int *bottom_index, int *top_index) {
|
| int q;
|
| if (cpi->pass == 0) {
|
| - if (cpi->oxcf.rc_mode == RC_MODE_CBR)
|
| + if (cpi->oxcf.rc_mode == VPX_CBR)
|
| q = rc_pick_q_and_bounds_one_pass_cbr(cpi, bottom_index, top_index);
|
| else
|
| q = rc_pick_q_and_bounds_one_pass_vbr(cpi, bottom_index, top_index);
|
| } else {
|
| q = rc_pick_q_and_bounds_two_pass(cpi, bottom_index, top_index);
|
| }
|
| -
|
| if (cpi->sf.use_nonrd_pick_mode) {
|
| if (cpi->sf.force_frame_boost == 1)
|
| q -= cpi->sf.max_delta_qindex;
|
| @@ -990,7 +997,7 @@
|
| int frame_target,
|
| int *frame_under_shoot_limit,
|
| int *frame_over_shoot_limit) {
|
| - if (cpi->oxcf.rc_mode == RC_MODE_CONSTANT_QUALITY) {
|
| + if (cpi->oxcf.rc_mode == VPX_Q) {
|
| *frame_under_shoot_limit = 0;
|
| *frame_over_shoot_limit = INT_MAX;
|
| } else {
|
| @@ -1065,29 +1072,28 @@
|
| // Post encode loop adjustment of Q prediction.
|
| vp9_rc_update_rate_correction_factors(
|
| cpi, (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF ||
|
| - oxcf->rc_mode == RC_MODE_CBR) ? 2 : 0);
|
| + oxcf->rc_mode == VPX_CBR) ? 2 : 0);
|
|
|
| // Keep a record of last Q and ambient average Q.
|
| if (cm->frame_type == KEY_FRAME) {
|
| rc->last_q[KEY_FRAME] = qindex;
|
| rc->avg_frame_qindex[KEY_FRAME] =
|
| ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[KEY_FRAME] + qindex, 2);
|
| - } else if (!rc->is_src_frame_alt_ref &&
|
| - (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) &&
|
| - !(cpi->use_svc && oxcf->rc_mode == RC_MODE_CBR)) {
|
| - rc->last_q[2] = qindex;
|
| - rc->avg_frame_qindex[2] =
|
| - ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[2] + qindex, 2);
|
| } else {
|
| - rc->last_q[INTER_FRAME] = qindex;
|
| - rc->avg_frame_qindex[INTER_FRAME] =
|
| + if (rc->is_src_frame_alt_ref ||
|
| + !(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) ||
|
| + (cpi->use_svc && oxcf->rc_mode == VPX_CBR)) {
|
| + rc->last_q[INTER_FRAME] = qindex;
|
| + rc->avg_frame_qindex[INTER_FRAME] =
|
| ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[INTER_FRAME] + qindex, 2);
|
| - rc->ni_frames++;
|
| - rc->tot_q += vp9_convert_qindex_to_q(qindex);
|
| - rc->avg_q = rc->tot_q / rc->ni_frames;
|
| - // Calculate the average Q for normal inter frames (not key or GFU frames).
|
| - rc->ni_tot_qi += qindex;
|
| - rc->ni_av_qi = rc->ni_tot_qi / rc->ni_frames;
|
| + rc->ni_frames++;
|
| + rc->tot_q += vp9_convert_qindex_to_q(qindex);
|
| + rc->avg_q = rc->tot_q / rc->ni_frames;
|
| + // Calculate the average Q for normal inter frames (not key or GFU
|
| + // frames).
|
| + rc->ni_tot_qi += qindex;
|
| + rc->ni_av_qi = rc->ni_tot_qi / rc->ni_frames;
|
| + }
|
| }
|
|
|
| // Keep record of last boosted (KF/KF/ARF) Q value.
|
| @@ -1123,7 +1129,7 @@
|
|
|
| rc->total_target_vs_actual = rc->total_actual_bits - rc->total_target_bits;
|
|
|
| - if (oxcf->play_alternate && cpi->refresh_alt_ref_frame &&
|
| + if (is_altref_enabled(oxcf) && cpi->refresh_alt_ref_frame &&
|
| (cm->frame_type != KEY_FRAME))
|
| // Update the alternate reference frame stats as appropriate.
|
| update_alt_ref_frame_stats(cpi);
|
| @@ -1214,12 +1220,12 @@
|
| const VP9EncoderConfig *oxcf = &cpi->oxcf;
|
| const RATE_CONTROL *rc = &cpi->rc;
|
| const SVC *const svc = &cpi->svc;
|
| - const int64_t diff = oxcf->optimal_buffer_level - rc->buffer_level;
|
| - const int64_t one_pct_bits = 1 + oxcf->optimal_buffer_level / 100;
|
| + const int64_t diff = rc->optimal_buffer_level - rc->buffer_level;
|
| + const int64_t one_pct_bits = 1 + rc->optimal_buffer_level / 100;
|
| int min_frame_target = MAX(rc->avg_frame_bandwidth >> 4, FRAME_OVERHEAD_BITS);
|
| int target = rc->avg_frame_bandwidth;
|
| if (svc->number_temporal_layers > 1 &&
|
| - oxcf->rc_mode == RC_MODE_CBR) {
|
| + oxcf->rc_mode == VPX_CBR) {
|
| // Note that for layers, avg_frame_bandwidth is the cumulative
|
| // per-frame-bandwidth. For the target size of this frame, use the
|
| // layer average frame size (i.e., non-cumulative per-frame-bw).
|
| @@ -1246,13 +1252,13 @@
|
| const SVC *const svc = &cpi->svc;
|
| int target;
|
| if (cpi->common.current_video_frame == 0) {
|
| - target = ((cpi->oxcf.starting_buffer_level / 2) > INT_MAX)
|
| - ? INT_MAX : (int)(cpi->oxcf.starting_buffer_level / 2);
|
| + target = ((rc->starting_buffer_level / 2) > INT_MAX)
|
| + ? INT_MAX : (int)(rc->starting_buffer_level / 2);
|
| } else {
|
| int kf_boost = 32;
|
| double framerate = oxcf->framerate;
|
| if (svc->number_temporal_layers > 1 &&
|
| - oxcf->rc_mode == RC_MODE_CBR) {
|
| + oxcf->rc_mode == VPX_CBR) {
|
| // Use the layer framerate for temporal layers CBR mode.
|
| const LAYER_CONTEXT *lc = &svc->layer_context[svc->temporal_layer_id];
|
| framerate = lc->framerate;
|
| @@ -1282,7 +1288,7 @@
|
| cpi->svc.layer_context[cpi->svc.spatial_layer_id].is_key_frame = 1;
|
| }
|
|
|
| - if (cpi->pass == 0 && cpi->oxcf.rc_mode == RC_MODE_CBR) {
|
| + if (cpi->pass == 0 && cpi->oxcf.rc_mode == VPX_CBR) {
|
| target = calc_iframe_target_size_one_pass_cbr(cpi);
|
| }
|
| } else {
|
| @@ -1297,7 +1303,7 @@
|
| }
|
| }
|
|
|
| - if (cpi->pass == 0 && cpi->oxcf.rc_mode == RC_MODE_CBR) {
|
| + if (cpi->pass == 0 && cpi->oxcf.rc_mode == VPX_CBR) {
|
| target = calc_pframe_target_size_one_pass_cbr(cpi);
|
| }
|
| }
|
| @@ -1375,6 +1381,23 @@
|
| return target_index - qindex;
|
| }
|
|
|
| +void vp9_rc_set_gf_max_interval(const VP9EncoderConfig *const oxcf,
|
| + RATE_CONTROL *const rc) {
|
| + // Set Maximum gf/arf interval
|
| + rc->max_gf_interval = 16;
|
| +
|
| + // Extended interval for genuinely static scenes
|
| + rc->static_scene_max_gf_interval = oxcf->key_freq >> 1;
|
| +
|
| + if (is_altref_enabled(oxcf)) {
|
| + if (rc->static_scene_max_gf_interval > oxcf->lag_in_frames - 1)
|
| + rc->static_scene_max_gf_interval = oxcf->lag_in_frames - 1;
|
| + }
|
| +
|
| + if (rc->max_gf_interval > rc->static_scene_max_gf_interval)
|
| + rc->max_gf_interval = rc->static_scene_max_gf_interval;
|
| +}
|
| +
|
| void vp9_rc_update_framerate(VP9_COMP *cpi) {
|
| const VP9_COMMON *const cm = &cpi->common;
|
| const VP9EncoderConfig *const oxcf = &cpi->oxcf;
|
| @@ -1399,21 +1422,5 @@
|
| rc->max_frame_bandwidth = MAX(MAX((cm->MBs * MAX_MB_RATE), MAXRATE_1080P),
|
| vbr_max_bits);
|
|
|
| - // Set Maximum gf/arf interval
|
| - rc->max_gf_interval = 16;
|
| -
|
| - // Extended interval for genuinely static scenes
|
| - rc->static_scene_max_gf_interval = cpi->oxcf.key_freq >> 1;
|
| -
|
| - // Special conditions when alt ref frame enabled in lagged compress mode
|
| - if (oxcf->play_alternate && oxcf->lag_in_frames) {
|
| - if (rc->max_gf_interval > oxcf->lag_in_frames - 1)
|
| - rc->max_gf_interval = oxcf->lag_in_frames - 1;
|
| -
|
| - if (rc->static_scene_max_gf_interval > oxcf->lag_in_frames - 1)
|
| - rc->static_scene_max_gf_interval = oxcf->lag_in_frames - 1;
|
| - }
|
| -
|
| - if (rc->max_gf_interval > rc->static_scene_max_gf_interval)
|
| - rc->max_gf_interval = rc->static_scene_max_gf_interval;
|
| + vp9_rc_set_gf_max_interval(oxcf, rc);
|
| }
|
|
|