diff options
Diffstat (limited to 'vp9/encoder/vp9_ratectrl.c')
-rw-r--r-- | vp9/encoder/vp9_ratectrl.c | 75 |
1 files changed, 38 insertions, 37 deletions
diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c index ae7713570..2e35e5fbc 100644 --- a/vp9/encoder/vp9_ratectrl.c +++ b/vp9/encoder/vp9_ratectrl.c @@ -85,7 +85,7 @@ void vp9_rc_init_minq_luts() { gf_high_motion_minq[i] = get_minq_index(maxq, 0.0000021, -0.00125, 0.50); afq_low_motion_minq[i] = get_minq_index(maxq, 0.0000015, -0.0009, 0.33); afq_high_motion_minq[i] = get_minq_index(maxq, 0.0000021, -0.00125, 0.55); - inter_minq[i] = get_minq_index(maxq, 0.00000271, -0.00113, 0.55); + inter_minq[i] = get_minq_index(maxq, 0.00000271, -0.00113, 0.75); } } @@ -134,7 +134,7 @@ int vp9_rc_clamp_pframe_target_size(const VP9_COMP *const cpi, int target) { int vp9_rc_clamp_iframe_target_size(const VP9_COMP *const cpi, int target) { const RATE_CONTROL *rc = &cpi->rc; - const VP9_CONFIG *oxcf = &cpi->oxcf; + const VP9EncoderConfig *oxcf = &cpi->oxcf; if (oxcf->rc_max_intra_bitrate_pct) { const int max_rate = rc->avg_frame_bandwidth * oxcf->rc_max_intra_bitrate_pct / 100; @@ -167,7 +167,7 @@ static void update_layer_buffer_level(SVC *svc, int encoded_frame_size) { // 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 VP9_CONFIG *oxcf = &cpi->oxcf; + const VP9EncoderConfig *oxcf = &cpi->oxcf; RATE_CONTROL *const rc = &cpi->rc; // Non-viewable frames are a special case and are treated as pure overhead. @@ -181,13 +181,13 @@ static void update_buffer_level(VP9_COMP *cpi, int encoded_frame_size) { rc->bits_off_target = MIN(rc->bits_off_target, oxcf->maximum_buffer_size); rc->buffer_level = rc->bits_off_target; - if (cpi->use_svc && cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { + if (cpi->use_svc && cpi->oxcf.rc_mode == RC_MODE_CBR) { update_layer_buffer_level(&cpi->svc, encoded_frame_size); } } -void vp9_rc_init(const VP9_CONFIG *oxcf, int pass, RATE_CONTROL *rc) { - if (pass == 0 && oxcf->end_usage == USAGE_STREAM_FROM_SERVER) { +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; @@ -237,7 +237,7 @@ void vp9_rc_init(const VP9_CONFIG *oxcf, int pass, RATE_CONTROL *rc) { } int vp9_rc_drop_frame(VP9_COMP *cpi) { - const VP9_CONFIG *oxcf = &cpi->oxcf; + const VP9EncoderConfig *oxcf = &cpi->oxcf; RATE_CONTROL *const rc = &cpi->rc; if (!oxcf->drop_frames_water_mark) { @@ -280,7 +280,7 @@ static double get_rate_correction_factor(const VP9_COMP *cpi) { } else { if ((cpi->refresh_alt_ref_frame || cpi->refresh_golden_frame) && !cpi->rc.is_src_frame_alt_ref && - !(cpi->use_svc && cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)) + !(cpi->use_svc && cpi->oxcf.rc_mode == RC_MODE_CBR)) return cpi->rc.gf_rate_correction_factor; else return cpi->rc.rate_correction_factor; @@ -293,7 +293,7 @@ static void set_rate_correction_factor(VP9_COMP *cpi, double factor) { } else { if ((cpi->refresh_alt_ref_frame || cpi->refresh_golden_frame) && !cpi->rc.is_src_frame_alt_ref && - !(cpi->use_svc && cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER)) + !(cpi->use_svc && cpi->oxcf.rc_mode == RC_MODE_CBR)) cpi->rc.gf_rate_correction_factor = factor; else cpi->rc.rate_correction_factor = factor; @@ -444,7 +444,7 @@ static int calc_active_worst_quality_one_pass_cbr(const VP9_COMP *cpi) { // ambient Q (at buffer = optimal level) to worst_quality level // (at buffer = critical level). const VP9_COMMON *const cm = &cpi->common; - const VP9_CONFIG *oxcf = &cpi->oxcf; + 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; @@ -612,7 +612,7 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi, int *top_index) { const VP9_COMMON *const cm = &cpi->common; const RATE_CONTROL *const rc = &cpi->rc; - const VP9_CONFIG *const oxcf = &cpi->oxcf; + const VP9EncoderConfig *const oxcf = &cpi->oxcf; const int cq_level = oxcf->cq_level; int active_best_quality; int active_worst_quality = calc_active_worst_quality_one_pass_vbr(cpi); @@ -671,7 +671,7 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi, q = rc->avg_frame_qindex[KEY_FRAME]; } // For constrained quality dont allow Q less than the cq level - if (oxcf->end_usage == USAGE_CONSTRAINED_QUALITY) { + if (oxcf->rc_mode == RC_MODE_CONSTRAINED_QUALITY) { if (q < cq_level) q = cq_level; if (rc->frames_since_key > 1) { @@ -688,7 +688,7 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi, // Constrained quality use slightly lower active best. active_best_quality = active_best_quality * 15 / 16; - } else if (oxcf->end_usage == USAGE_CONSTANT_QUALITY) { + } else if (oxcf->rc_mode == RC_MODE_CONSTANT_QUALITY) { if (!cpi->refresh_alt_ref_frame) { active_best_quality = cq_level; } else { @@ -708,7 +708,7 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi, gf_low_motion_minq, gf_high_motion_minq); } } else { - if (oxcf->end_usage == USAGE_CONSTANT_QUALITY) { + if (oxcf->rc_mode == RC_MODE_CONSTANT_QUALITY) { active_best_quality = cq_level; } else { // Use the lower of active_worst_quality and recent/average Q. @@ -718,7 +718,7 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi, 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->end_usage == USAGE_CONSTRAINED_QUALITY) && + if ((oxcf->rc_mode == RC_MODE_CONSTRAINED_QUALITY) && (active_best_quality < cq_level)) { active_best_quality = cq_level; } @@ -755,7 +755,7 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi, } #endif - if (oxcf->end_usage == USAGE_CONSTANT_QUALITY) { + if (oxcf->rc_mode == RC_MODE_CONSTANT_QUALITY) { 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) { @@ -774,7 +774,7 @@ static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi, #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.end_usage != USAGE_CONSTANT_QUALITY) { + cpi->oxcf.rc_mode != RC_MODE_CONSTANT_QUALITY) { double new_q; double current_q = vp9_convert_qindex_to_q(active_worst_quality); int level = cpi->this_frame_weight; @@ -801,7 +801,7 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi, int *top_index) { const VP9_COMMON *const cm = &cpi->common; const RATE_CONTROL *const rc = &cpi->rc; - const VP9_CONFIG *const oxcf = &cpi->oxcf; + const VP9EncoderConfig *const oxcf = &cpi->oxcf; const int cq_level = oxcf->cq_level; int active_best_quality; int active_worst_quality = cpi->twopass.active_worst_quality; @@ -862,7 +862,7 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi, q = active_worst_quality; } // For constrained quality dont allow Q less than the cq level - if (oxcf->end_usage == USAGE_CONSTRAINED_QUALITY) { + if (oxcf->rc_mode == RC_MODE_CONSTRAINED_QUALITY) { if (q < cq_level) q = cq_level; if (rc->frames_since_key > 1) { @@ -879,7 +879,7 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi, // Constrained quality use slightly lower active best. active_best_quality = active_best_quality * 15 / 16; - } else if (oxcf->end_usage == USAGE_CONSTANT_QUALITY) { + } else if (oxcf->rc_mode == RC_MODE_CONSTANT_QUALITY) { if (!cpi->refresh_alt_ref_frame) { active_best_quality = cq_level; } else { @@ -899,14 +899,14 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi, gf_low_motion_minq, gf_high_motion_minq); } } else { - if (oxcf->end_usage == USAGE_CONSTANT_QUALITY) { + if (oxcf->rc_mode == RC_MODE_CONSTANT_QUALITY) { 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->end_usage == USAGE_CONSTRAINED_QUALITY) && + if ((oxcf->rc_mode == RC_MODE_CONSTRAINED_QUALITY) && (active_best_quality < cq_level)) { active_best_quality = cq_level; } @@ -932,7 +932,7 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi, 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->end_usage != USAGE_STREAM_FROM_SERVER) && + (oxcf->rc_mode != RC_MODE_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); @@ -942,7 +942,7 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi, } #endif - if (oxcf->end_usage == USAGE_CONSTANT_QUALITY) { + if (oxcf->rc_mode == RC_MODE_CONSTANT_QUALITY) { 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) { @@ -961,7 +961,7 @@ static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi, #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.end_usage != USAGE_CONSTANT_QUALITY) { + cpi->oxcf.rc_mode != RC_MODE_CONSTANT_QUALITY) { double new_q; double current_q = vp9_convert_qindex_to_q(active_worst_quality); int level = cpi->this_frame_weight; @@ -987,7 +987,7 @@ int vp9_rc_pick_q_and_bounds(const VP9_COMP *cpi, int *bottom_index, int *top_index) { int q; if (cpi->pass == 0) { - if (cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) + if (cpi->oxcf.rc_mode == RC_MODE_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); @@ -1015,7 +1015,7 @@ void vp9_rc_compute_frame_size_bounds(const VP9_COMP *cpi, int frame_target, int *frame_under_shoot_limit, int *frame_over_shoot_limit) { - if (cpi->oxcf.end_usage == USAGE_CONSTANT_QUALITY) { + if (cpi->oxcf.rc_mode == RC_MODE_CONSTANT_QUALITY) { *frame_under_shoot_limit = 0; *frame_over_shoot_limit = INT_MAX; } else { @@ -1033,6 +1033,7 @@ void vp9_rc_set_frame_target(VP9_COMP *cpi, int target) { RATE_CONTROL *const rc = &cpi->rc; rc->this_frame_target = target; + // Target rate per SB64 (including partial SB64s. rc->sb64_target_rate = ((int64_t)rc->this_frame_target * 64 * 64) / (cm->width * cm->height); @@ -1079,7 +1080,7 @@ static void update_golden_frame_stats(VP9_COMP *cpi) { void vp9_rc_postencode_update(VP9_COMP *cpi, uint64_t bytes_used) { const VP9_COMMON *const cm = &cpi->common; - const VP9_CONFIG *const oxcf = &cpi->oxcf; + const VP9EncoderConfig *const oxcf = &cpi->oxcf; RATE_CONTROL *const rc = &cpi->rc; const int qindex = cm->base_qindex; @@ -1089,7 +1090,7 @@ void vp9_rc_postencode_update(VP9_COMP *cpi, uint64_t bytes_used) { // Post encode loop adjustment of Q prediction. vp9_rc_update_rate_correction_factors( cpi, (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF || - oxcf->end_usage == USAGE_STREAM_FROM_SERVER) ? 2 : 0); + oxcf->rc_mode == RC_MODE_CBR) ? 2 : 0); // Keep a record of last Q and ambient average Q. if (cm->frame_type == KEY_FRAME) { @@ -1098,7 +1099,7 @@ void vp9_rc_postencode_update(VP9_COMP *cpi, uint64_t bytes_used) { 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->end_usage == USAGE_STREAM_FROM_SERVER)) { + !(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); @@ -1238,7 +1239,7 @@ void vp9_rc_get_one_pass_vbr_params(VP9_COMP *cpi) { } static int calc_pframe_target_size_one_pass_cbr(const VP9_COMP *cpi) { - const VP9_CONFIG *oxcf = &cpi->oxcf; + 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; @@ -1246,7 +1247,7 @@ static int calc_pframe_target_size_one_pass_cbr(const VP9_COMP *cpi) { 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->end_usage == USAGE_STREAM_FROM_SERVER) { + oxcf->rc_mode == RC_MODE_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). @@ -1269,7 +1270,7 @@ static int calc_pframe_target_size_one_pass_cbr(const VP9_COMP *cpi) { static int calc_iframe_target_size_one_pass_cbr(const VP9_COMP *cpi) { const RATE_CONTROL *rc = &cpi->rc; - const VP9_CONFIG *oxcf = &cpi->oxcf; + const VP9EncoderConfig *oxcf = &cpi->oxcf; const SVC *const svc = &cpi->svc; int target; if (cpi->common.current_video_frame == 0) { @@ -1279,7 +1280,7 @@ static int calc_iframe_target_size_one_pass_cbr(const VP9_COMP *cpi) { int kf_boost = 32; double framerate = oxcf->framerate; if (svc->number_temporal_layers > 1 && - oxcf->end_usage == USAGE_STREAM_FROM_SERVER) { + oxcf->rc_mode == RC_MODE_CBR) { // Use the layer framerate for temporal layers CBR mode. const LAYER_CONTEXT *lc = &svc->layer_context[svc->temporal_layer_id]; framerate = lc->framerate; @@ -1304,12 +1305,12 @@ void vp9_rc_get_svc_params(VP9_COMP *cpi) { cpi->key_frame_frequency == 0))) { cm->frame_type = KEY_FRAME; rc->source_alt_ref_active = 0; - if (cpi->pass == 0 && cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { + if (cpi->pass == 0 && cpi->oxcf.rc_mode == RC_MODE_CBR) { target = calc_iframe_target_size_one_pass_cbr(cpi); } } else { cm->frame_type = INTER_FRAME; - if (cpi->pass == 0 && cpi->oxcf.end_usage == USAGE_STREAM_FROM_SERVER) { + if (cpi->pass == 0 && cpi->oxcf.rc_mode == RC_MODE_CBR) { target = calc_pframe_target_size_one_pass_cbr(cpi); } } @@ -1388,7 +1389,7 @@ int vp9_compute_qdelta_by_rate(const RATE_CONTROL *rc, FRAME_TYPE frame_type, void vp9_rc_update_framerate(VP9_COMP *cpi) { const VP9_COMMON *const cm = &cpi->common; - const VP9_CONFIG *const oxcf = &cpi->oxcf; + const VP9EncoderConfig *const oxcf = &cpi->oxcf; RATE_CONTROL *const rc = &cpi->rc; int vbr_max_bits; |