• Home
  • Raw
  • Download

Lines Matching refs:rc

216   const RATE_CONTROL *rc = &cpi->rc;  in vp9_rc_clamp_pframe_target_size()  local
219 VPXMAX(rc->min_frame_bandwidth, rc->avg_frame_bandwidth >> 5); in vp9_rc_clamp_pframe_target_size()
221 if (cpi->refresh_golden_frame && rc->is_src_frame_alt_ref) { in vp9_rc_clamp_pframe_target_size()
229 if (target > rc->max_frame_bandwidth) target = rc->max_frame_bandwidth; in vp9_rc_clamp_pframe_target_size()
232 rc->avg_frame_bandwidth * oxcf->rc_max_inter_bitrate_pct / 100; in vp9_rc_clamp_pframe_target_size()
239 const RATE_CONTROL *rc = &cpi->rc; in vp9_rc_clamp_iframe_target_size() local
243 rc->avg_frame_bandwidth * oxcf->rc_max_intra_bitrate_pct / 100; in vp9_rc_clamp_iframe_target_size()
246 if (target > rc->max_frame_bandwidth) target = rc->max_frame_bandwidth; in vp9_rc_clamp_iframe_target_size()
259 RATE_CONTROL *lrc = &lc->rc; in update_layer_buffer_level()
274 RATE_CONTROL *const rc = &cpi->rc; in update_buffer_level() local
278 rc->bits_off_target -= encoded_frame_size; in update_buffer_level()
280 rc->bits_off_target += rc->avg_frame_bandwidth - encoded_frame_size; in update_buffer_level()
284 rc->bits_off_target = VPXMIN(rc->bits_off_target, rc->maximum_buffer_size); in update_buffer_level()
290 rc->bits_off_target = VPXMAX(rc->bits_off_target, -rc->maximum_buffer_size); in update_buffer_level()
292 rc->buffer_level = rc->bits_off_target; in update_buffer_level()
324 void vp9_rc_init(const VP9EncoderConfig *oxcf, int pass, RATE_CONTROL *rc) { in vp9_rc_init() argument
328 rc->avg_frame_qindex[KEY_FRAME] = oxcf->worst_allowed_q; in vp9_rc_init()
329 rc->avg_frame_qindex[INTER_FRAME] = oxcf->worst_allowed_q; in vp9_rc_init()
331 rc->avg_frame_qindex[KEY_FRAME] = in vp9_rc_init()
333 rc->avg_frame_qindex[INTER_FRAME] = in vp9_rc_init()
337 rc->last_q[KEY_FRAME] = oxcf->best_allowed_q; in vp9_rc_init()
338 rc->last_q[INTER_FRAME] = oxcf->worst_allowed_q; in vp9_rc_init()
340 rc->buffer_level = rc->starting_buffer_level; in vp9_rc_init()
341 rc->bits_off_target = rc->starting_buffer_level; in vp9_rc_init()
343 rc->rolling_target_bits = rc->avg_frame_bandwidth; in vp9_rc_init()
344 rc->rolling_actual_bits = rc->avg_frame_bandwidth; in vp9_rc_init()
345 rc->long_rolling_target_bits = rc->avg_frame_bandwidth; in vp9_rc_init()
346 rc->long_rolling_actual_bits = rc->avg_frame_bandwidth; in vp9_rc_init()
348 rc->total_actual_bits = 0; in vp9_rc_init()
349 rc->total_target_bits = 0; in vp9_rc_init()
350 rc->total_target_vs_actual = 0; in vp9_rc_init()
351 rc->avg_frame_low_motion = 0; in vp9_rc_init()
352 rc->count_last_scene_change = 0; in vp9_rc_init()
353 rc->af_ratio_onepass_vbr = 10; in vp9_rc_init()
354 rc->prev_avg_source_sad_lag = 0; in vp9_rc_init()
355 rc->high_source_sad = 0; in vp9_rc_init()
356 rc->high_source_sad_lagindex = -1; in vp9_rc_init()
357 rc->alt_ref_gf_group = 0; in vp9_rc_init()
358 rc->fac_active_worst_inter = 150; in vp9_rc_init()
359 rc->fac_active_worst_gf = 100; in vp9_rc_init()
360 rc->force_qpmin = 0; in vp9_rc_init()
361 for (i = 0; i < MAX_LAG_BUFFERS; ++i) rc->avg_source_sad[i] = 0; in vp9_rc_init()
362 rc->frames_since_key = 8; // Sensible default for first frame. in vp9_rc_init()
363 rc->this_key_frame_forced = 0; in vp9_rc_init()
364 rc->next_key_frame_forced = 0; in vp9_rc_init()
365 rc->source_alt_ref_pending = 0; in vp9_rc_init()
366 rc->source_alt_ref_active = 0; in vp9_rc_init()
368 rc->frames_till_gf_update_due = 0; in vp9_rc_init()
369 rc->ni_av_qi = oxcf->worst_allowed_q; in vp9_rc_init()
370 rc->ni_tot_qi = 0; in vp9_rc_init()
371 rc->ni_frames = 0; in vp9_rc_init()
373 rc->tot_q = 0.0; in vp9_rc_init()
374 rc->avg_q = vp9_convert_qindex_to_q(oxcf->worst_allowed_q, oxcf->bit_depth); in vp9_rc_init()
377 rc->rate_correction_factors[i] = 1.0; in vp9_rc_init()
380 rc->min_gf_interval = oxcf->min_gf_interval; in vp9_rc_init()
381 rc->max_gf_interval = oxcf->max_gf_interval; in vp9_rc_init()
382 if (rc->min_gf_interval == 0) in vp9_rc_init()
383 rc->min_gf_interval = vp9_rc_get_default_min_gf_interval( in vp9_rc_init()
385 if (rc->max_gf_interval == 0) in vp9_rc_init()
386 rc->max_gf_interval = vp9_rc_get_default_max_gf_interval( in vp9_rc_init()
387 oxcf->init_framerate, rc->min_gf_interval); in vp9_rc_init()
388 rc->baseline_gf_interval = (rc->min_gf_interval + rc->max_gf_interval) / 2; in vp9_rc_init()
393 RATE_CONTROL *const rc = &cpi->rc; in vp9_rc_drop_frame() local
399 if (rc->buffer_level < 0) { in vp9_rc_drop_frame()
406 (int)(oxcf->drop_frames_water_mark * rc->optimal_buffer_level / 100); in vp9_rc_drop_frame()
407 if ((rc->buffer_level > drop_mark) && (rc->decimation_factor > 0)) { in vp9_rc_drop_frame()
408 --rc->decimation_factor; in vp9_rc_drop_frame()
409 } else if (rc->buffer_level <= drop_mark && rc->decimation_factor == 0) { in vp9_rc_drop_frame()
410 rc->decimation_factor = 1; in vp9_rc_drop_frame()
412 if (rc->decimation_factor > 0) { in vp9_rc_drop_frame()
413 if (rc->decimation_count > 0) { in vp9_rc_drop_frame()
414 --rc->decimation_count; in vp9_rc_drop_frame()
417 rc->decimation_count = rc->decimation_factor; in vp9_rc_drop_frame()
421 rc->decimation_count = 0; in vp9_rc_drop_frame()
429 const RATE_CONTROL *const rc = &cpi->rc; in get_rate_correction_factor() local
433 rcf = rc->rate_correction_factors[KF_STD]; in get_rate_correction_factor()
437 rcf = rc->rate_correction_factors[rf_lvl]; in get_rate_correction_factor()
440 !rc->is_src_frame_alt_ref && !cpi->use_svc && in get_rate_correction_factor()
442 rcf = rc->rate_correction_factors[GF_ARF_STD]; in get_rate_correction_factor()
444 rcf = rc->rate_correction_factors[INTER_NORMAL]; in get_rate_correction_factor()
446 rcf *= rcf_mult[rc->frame_size_selector]; in get_rate_correction_factor()
451 RATE_CONTROL *const rc = &cpi->rc; in set_rate_correction_factor() local
454 factor /= rcf_mult[cpi->rc.frame_size_selector]; in set_rate_correction_factor()
459 rc->rate_correction_factors[KF_STD] = factor; in set_rate_correction_factor()
463 rc->rate_correction_factors[rf_lvl] = factor; in set_rate_correction_factor()
466 !rc->is_src_frame_alt_ref && !cpi->use_svc && in set_rate_correction_factor()
468 rc->rate_correction_factors[GF_ARF_STD] = factor; in set_rate_correction_factor()
470 rc->rate_correction_factors[INTER_NORMAL] = factor; in set_rate_correction_factor()
483 if (cpi->rc.is_src_frame_alt_ref) return; in vp9_rc_update_rate_correction_factors()
501 correction_factor = (int)((100 * (int64_t)cpi->rc.projected_frame_size) / in vp9_rc_update_rate_correction_factors()
509 cpi->rc.q_2_frame = cpi->rc.q_1_frame; in vp9_rc_update_rate_correction_factors()
510 cpi->rc.q_1_frame = cm->base_qindex; in vp9_rc_update_rate_correction_factors()
511 cpi->rc.rc_2_frame = cpi->rc.rc_1_frame; in vp9_rc_update_rate_correction_factors()
513 cpi->rc.rc_1_frame = -1; in vp9_rc_update_rate_correction_factors()
515 cpi->rc.rc_1_frame = 1; in vp9_rc_update_rate_correction_factors()
517 cpi->rc.rc_1_frame = 0; in vp9_rc_update_rate_correction_factors()
520 if (cpi->rc.rc_1_frame == -1 && cpi->rc.rc_2_frame == 1 && in vp9_rc_update_rate_correction_factors()
522 cpi->rc.rc_2_frame = 0; in vp9_rc_update_rate_correction_factors()
591 (cpi->rc.rc_1_frame * cpi->rc.rc_2_frame == -1) && in vp9_rc_regulate_q()
592 cpi->rc.q_1_frame != cpi->rc.q_2_frame) { in vp9_rc_regulate_q()
593 q = clamp(q, VPXMIN(cpi->rc.q_1_frame, cpi->rc.q_2_frame), in vp9_rc_regulate_q()
594 VPXMAX(cpi->rc.q_1_frame, cpi->rc.q_2_frame)); in vp9_rc_regulate_q()
599 cpi->rc.is_src_frame_alt_ref && !cpi->rc.alt_ref_gf_group) { in vp9_rc_regulate_q()
600 q = VPXMIN(q, (q + cpi->rc.last_boosted_qindex) >> 1); in vp9_rc_regulate_q()
621 static int get_kf_active_quality(const RATE_CONTROL *const rc, int q, in get_kf_active_quality() argument
627 return get_active_quality(q, rc->kf_boost, kf_low, kf_high, in get_kf_active_quality()
631 static int get_gf_active_quality(const RATE_CONTROL *const rc, int q, in get_gf_active_quality() argument
637 return get_active_quality(q, rc->gfu_boost, gf_low, gf_high, in get_gf_active_quality()
642 const RATE_CONTROL *const rc = &cpi->rc; in calc_active_worst_quality_one_pass_vbr() local
648 curr_frame == 0 ? rc->worst_quality : rc->last_q[KEY_FRAME] << 1; in calc_active_worst_quality_one_pass_vbr()
650 if (!rc->is_src_frame_alt_ref && in calc_active_worst_quality_one_pass_vbr()
654 ? rc->last_q[KEY_FRAME] * 5 >> 2 in calc_active_worst_quality_one_pass_vbr()
655 : rc->last_q[INTER_FRAME] * rc->fac_active_worst_gf / 100; in calc_active_worst_quality_one_pass_vbr()
658 ? rc->last_q[KEY_FRAME] << 1 in calc_active_worst_quality_one_pass_vbr()
659 : rc->avg_frame_qindex[INTER_FRAME] * in calc_active_worst_quality_one_pass_vbr()
660 rc->fac_active_worst_inter / 100; in calc_active_worst_quality_one_pass_vbr()
663 return VPXMIN(active_worst_quality, rc->worst_quality); in calc_active_worst_quality_one_pass_vbr()
674 const RATE_CONTROL *rc = &cpi->rc; in calc_active_worst_quality_one_pass_cbr() local
676 int64_t critical_level = rc->optimal_buffer_level >> 3; in calc_active_worst_quality_one_pass_cbr()
682 if (cm->frame_type == KEY_FRAME) return rc->worst_quality; in calc_active_worst_quality_one_pass_cbr()
689 ? VPXMIN(rc->avg_frame_qindex[INTER_FRAME], in calc_active_worst_quality_one_pass_cbr()
690 rc->avg_frame_qindex[KEY_FRAME]) in calc_active_worst_quality_one_pass_cbr()
691 : rc->avg_frame_qindex[INTER_FRAME]; in calc_active_worst_quality_one_pass_cbr()
699 const RATE_CONTROL *lrc = &lc->rc; in calc_active_worst_quality_one_pass_cbr()
703 active_worst_quality = VPXMIN(rc->worst_quality, ambient_qp * 5 >> 2); in calc_active_worst_quality_one_pass_cbr()
704 if (rc->buffer_level > rc->optimal_buffer_level) { in calc_active_worst_quality_one_pass_cbr()
709 buff_lvl_step = ((rc->maximum_buffer_size - rc->optimal_buffer_level) / in calc_active_worst_quality_one_pass_cbr()
712 adjustment = (int)((rc->buffer_level - rc->optimal_buffer_level) / in calc_active_worst_quality_one_pass_cbr()
716 } else if (rc->buffer_level > critical_level) { in calc_active_worst_quality_one_pass_cbr()
719 buff_lvl_step = (rc->optimal_buffer_level - critical_level); in calc_active_worst_quality_one_pass_cbr()
721 adjustment = (int)((rc->worst_quality - ambient_qp) * in calc_active_worst_quality_one_pass_cbr()
722 (rc->optimal_buffer_level - rc->buffer_level) / in calc_active_worst_quality_one_pass_cbr()
729 active_worst_quality = rc->worst_quality; in calc_active_worst_quality_one_pass_cbr()
738 const RATE_CONTROL *const rc = &cpi->rc; in rc_pick_q_and_bounds_one_pass_cbr() local
746 active_best_quality = rc->best_quality; in rc_pick_q_and_bounds_one_pass_cbr()
750 if (rc->this_key_frame_forced) { in rc_pick_q_and_bounds_one_pass_cbr()
751 int qindex = rc->last_boosted_qindex; in rc_pick_q_and_bounds_one_pass_cbr()
754 rc, last_boosted_q, (last_boosted_q * 0.75), cm->bit_depth); in rc_pick_q_and_bounds_one_pass_cbr()
755 active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality); in rc_pick_q_and_bounds_one_pass_cbr()
762 rc, rc->avg_frame_qindex[KEY_FRAME], cm->bit_depth); in rc_pick_q_and_bounds_one_pass_cbr()
773 vp9_compute_qdelta(rc, q_val, q_val * q_adj_factor, cm->bit_depth); in rc_pick_q_and_bounds_one_pass_cbr()
775 } else if (!rc->is_src_frame_alt_ref && !cpi->use_svc && in rc_pick_q_and_bounds_one_pass_cbr()
780 if (rc->frames_since_key > 1 && in rc_pick_q_and_bounds_one_pass_cbr()
781 rc->avg_frame_qindex[INTER_FRAME] < active_worst_quality) { in rc_pick_q_and_bounds_one_pass_cbr()
782 q = rc->avg_frame_qindex[INTER_FRAME]; in rc_pick_q_and_bounds_one_pass_cbr()
786 active_best_quality = get_gf_active_quality(rc, q, cm->bit_depth); in rc_pick_q_and_bounds_one_pass_cbr()
790 if (rc->avg_frame_qindex[INTER_FRAME] < active_worst_quality) in rc_pick_q_and_bounds_one_pass_cbr()
791 active_best_quality = rtc_minq[rc->avg_frame_qindex[INTER_FRAME]]; in rc_pick_q_and_bounds_one_pass_cbr()
795 if (rc->avg_frame_qindex[KEY_FRAME] < active_worst_quality) in rc_pick_q_and_bounds_one_pass_cbr()
796 active_best_quality = rtc_minq[rc->avg_frame_qindex[KEY_FRAME]]; in rc_pick_q_and_bounds_one_pass_cbr()
804 clamp(active_best_quality, rc->best_quality, rc->worst_quality); in rc_pick_q_and_bounds_one_pass_cbr()
806 clamp(active_worst_quality, active_best_quality, rc->worst_quality); in rc_pick_q_and_bounds_one_pass_cbr()
813 if (cm->frame_type == KEY_FRAME && !rc->this_key_frame_forced && in rc_pick_q_and_bounds_one_pass_cbr()
818 &cpi->rc, cm->frame_type, active_worst_quality, 2.0, cm->bit_depth); in rc_pick_q_and_bounds_one_pass_cbr()
825 if (cm->frame_type == KEY_FRAME && rc->this_key_frame_forced) { in rc_pick_q_and_bounds_one_pass_cbr()
826 q = rc->last_boosted_qindex; in rc_pick_q_and_bounds_one_pass_cbr()
828 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, active_best_quality, in rc_pick_q_and_bounds_one_pass_cbr()
832 if (rc->this_frame_target >= rc->max_frame_bandwidth) in rc_pick_q_and_bounds_one_pass_cbr()
838 assert(*top_index <= rc->worst_quality && *top_index >= rc->best_quality); in rc_pick_q_and_bounds_one_pass_cbr()
839 assert(*bottom_index <= rc->worst_quality && in rc_pick_q_and_bounds_one_pass_cbr()
840 *bottom_index >= rc->best_quality); in rc_pick_q_and_bounds_one_pass_cbr()
841 assert(q <= rc->worst_quality && q >= rc->best_quality); in rc_pick_q_and_bounds_one_pass_cbr()
845 static int get_active_cq_level_one_pass(const RATE_CONTROL *rc, in get_active_cq_level_one_pass() argument
849 if (oxcf->rc_mode == VPX_CQ && rc->total_target_bits > 0) { in get_active_cq_level_one_pass()
850 const double x = (double)rc->total_actual_bits / rc->total_target_bits; in get_active_cq_level_one_pass()
861 const RATE_CONTROL *rc, in get_active_cq_level_two_pass() argument
871 if (rc->total_target_bits > 0) { in get_active_cq_level_two_pass()
872 const double x = (double)rc->total_actual_bits / rc->total_target_bits; in get_active_cq_level_two_pass()
885 const RATE_CONTROL *const rc = &cpi->rc; in rc_pick_q_and_bounds_one_pass_vbr() local
887 const int cq_level = get_active_cq_level_one_pass(rc, oxcf); in rc_pick_q_and_bounds_one_pass_vbr()
898 int delta_qindex = vp9_compute_qdelta(rc, q, q * 0.25, cm->bit_depth); in rc_pick_q_and_bounds_one_pass_vbr()
899 active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality); in rc_pick_q_and_bounds_one_pass_vbr()
900 } else if (rc->this_key_frame_forced) { in rc_pick_q_and_bounds_one_pass_vbr()
904 int qindex = rc->last_boosted_qindex; in rc_pick_q_and_bounds_one_pass_vbr()
907 rc, last_boosted_q, last_boosted_q * 0.75, cm->bit_depth); in rc_pick_q_and_bounds_one_pass_vbr()
908 active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality); in rc_pick_q_and_bounds_one_pass_vbr()
915 rc, rc->avg_frame_qindex[KEY_FRAME], cm->bit_depth); in rc_pick_q_and_bounds_one_pass_vbr()
926 vp9_compute_qdelta(rc, q_val, q_val * q_adj_factor, cm->bit_depth); in rc_pick_q_and_bounds_one_pass_vbr()
928 } else if (!rc->is_src_frame_alt_ref && in rc_pick_q_and_bounds_one_pass_vbr()
933 if (rc->frames_since_key > 1) { in rc_pick_q_and_bounds_one_pass_vbr()
934 if (rc->avg_frame_qindex[INTER_FRAME] < active_worst_quality) { in rc_pick_q_and_bounds_one_pass_vbr()
935 q = rc->avg_frame_qindex[INTER_FRAME]; in rc_pick_q_and_bounds_one_pass_vbr()
940 q = rc->avg_frame_qindex[KEY_FRAME]; in rc_pick_q_and_bounds_one_pass_vbr()
946 active_best_quality = get_gf_active_quality(rc, q, cm->bit_depth); in rc_pick_q_and_bounds_one_pass_vbr()
956 delta_qindex = vp9_compute_qdelta(rc, q, q * 0.40, cm->bit_depth); in rc_pick_q_and_bounds_one_pass_vbr()
958 delta_qindex = vp9_compute_qdelta(rc, q, q * 0.50, cm->bit_depth); in rc_pick_q_and_bounds_one_pass_vbr()
959 active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality); in rc_pick_q_and_bounds_one_pass_vbr()
961 active_best_quality = get_gf_active_quality(rc, q, cm->bit_depth); in rc_pick_q_and_bounds_one_pass_vbr()
970 rc, q, q * delta_rate[cm->current_video_frame % FIXED_GF_INTERVAL], in rc_pick_q_and_bounds_one_pass_vbr()
972 active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality); in rc_pick_q_and_bounds_one_pass_vbr()
977 q = VPXMIN(rc->avg_frame_qindex[INTER_FRAME], active_worst_quality); in rc_pick_q_and_bounds_one_pass_vbr()
980 active_best_quality = inter_minq[rc->avg_frame_qindex[KEY_FRAME]]; in rc_pick_q_and_bounds_one_pass_vbr()
992 clamp(active_best_quality, rc->best_quality, rc->worst_quality); in rc_pick_q_and_bounds_one_pass_vbr()
994 clamp(active_worst_quality, active_best_quality, rc->worst_quality); in rc_pick_q_and_bounds_one_pass_vbr()
1005 if (cm->frame_type == KEY_FRAME && !rc->this_key_frame_forced && in rc_pick_q_and_bounds_one_pass_vbr()
1008 &cpi->rc, cm->frame_type, active_worst_quality, 2.0, cm->bit_depth); in rc_pick_q_and_bounds_one_pass_vbr()
1009 } else if (!rc->is_src_frame_alt_ref && in rc_pick_q_and_bounds_one_pass_vbr()
1012 &cpi->rc, cm->frame_type, active_worst_quality, 1.75, cm->bit_depth); in rc_pick_q_and_bounds_one_pass_vbr()
1022 } else if ((cm->frame_type == KEY_FRAME) && rc->this_key_frame_forced) { in rc_pick_q_and_bounds_one_pass_vbr()
1023 q = rc->last_boosted_qindex; in rc_pick_q_and_bounds_one_pass_vbr()
1025 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, active_best_quality, in rc_pick_q_and_bounds_one_pass_vbr()
1029 if (rc->this_frame_target >= rc->max_frame_bandwidth) in rc_pick_q_and_bounds_one_pass_vbr()
1036 assert(*top_index <= rc->worst_quality && *top_index >= rc->best_quality); in rc_pick_q_and_bounds_one_pass_vbr()
1037 assert(*bottom_index <= rc->worst_quality && in rc_pick_q_and_bounds_one_pass_vbr()
1038 *bottom_index >= rc->best_quality); in rc_pick_q_and_bounds_one_pass_vbr()
1039 assert(q <= rc->worst_quality && q >= rc->best_quality); in rc_pick_q_and_bounds_one_pass_vbr()
1056 vp9_compute_qdelta_by_rate(&cpi->rc, frame_type[rf_level], q, in vp9_frame_type_qdelta()
1065 const RATE_CONTROL *const rc = &cpi->rc; in rc_pick_q_and_bounds_two_pass() local
1068 const int cq_level = get_active_cq_level_two_pass(&cpi->twopass, rc, oxcf); in rc_pick_q_and_bounds_two_pass()
1079 if (rc->this_key_frame_forced) { in rc_pick_q_and_bounds_two_pass()
1085 qindex = VPXMIN(rc->last_kf_qindex, rc->last_boosted_qindex); in rc_pick_q_and_bounds_two_pass()
1088 delta_qindex = vp9_compute_qdelta(rc, last_boosted_q, in rc_pick_q_and_bounds_two_pass()
1093 qindex = rc->last_boosted_qindex; in rc_pick_q_and_bounds_two_pass()
1095 delta_qindex = vp9_compute_qdelta(rc, last_boosted_q, in rc_pick_q_and_bounds_two_pass()
1097 active_best_quality = VPXMAX(qindex + delta_qindex, rc->best_quality); in rc_pick_q_and_bounds_two_pass()
1105 get_kf_active_quality(rc, active_worst_quality, cm->bit_depth); in rc_pick_q_and_bounds_two_pass()
1119 vp9_compute_qdelta(rc, q_val, q_val * q_adj_factor, cm->bit_depth); in rc_pick_q_and_bounds_two_pass()
1121 } else if (!rc->is_src_frame_alt_ref && in rc_pick_q_and_bounds_two_pass()
1126 if (rc->frames_since_key > 1 && in rc_pick_q_and_bounds_two_pass()
1127 rc->avg_frame_qindex[INTER_FRAME] < active_worst_quality) { in rc_pick_q_and_bounds_two_pass()
1128 q = rc->avg_frame_qindex[INTER_FRAME]; in rc_pick_q_and_bounds_two_pass()
1136 active_best_quality = get_gf_active_quality(rc, q, cm->bit_depth); in rc_pick_q_and_bounds_two_pass()
1145 active_best_quality = get_gf_active_quality(rc, q, cm->bit_depth); in rc_pick_q_and_bounds_two_pass()
1153 active_best_quality = get_gf_active_quality(rc, q, cm->bit_depth); in rc_pick_q_and_bounds_two_pass()
1173 (!rc->is_src_frame_alt_ref && in rc_pick_q_and_bounds_two_pass()
1189 !rc->this_key_frame_forced || in rc_pick_q_and_bounds_two_pass()
1199 if (rc->frame_size_selector != UNSCALED && !frame_is_kf_gf_arf(cpi)) { in rc_pick_q_and_bounds_two_pass()
1201 rc, cm->frame_type, active_best_quality, 2.0, cm->bit_depth); in rc_pick_q_and_bounds_two_pass()
1203 VPXMAX(active_best_quality + qdelta, rc->best_quality); in rc_pick_q_and_bounds_two_pass()
1207 clamp(active_best_quality, rc->best_quality, rc->worst_quality); in rc_pick_q_and_bounds_two_pass()
1209 clamp(active_worst_quality, active_best_quality, rc->worst_quality); in rc_pick_q_and_bounds_two_pass()
1215 rc->this_key_frame_forced) { in rc_pick_q_and_bounds_two_pass()
1218 q = VPXMIN(rc->last_kf_qindex, rc->last_boosted_qindex); in rc_pick_q_and_bounds_two_pass()
1220 q = rc->last_boosted_qindex; in rc_pick_q_and_bounds_two_pass()
1223 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, active_best_quality, in rc_pick_q_and_bounds_two_pass()
1227 if (rc->this_frame_target >= rc->max_frame_bandwidth) in rc_pick_q_and_bounds_two_pass()
1238 assert(*top_index <= rc->worst_quality && *top_index >= rc->best_quality); in rc_pick_q_and_bounds_two_pass()
1239 assert(*bottom_index <= rc->worst_quality && in rc_pick_q_and_bounds_two_pass()
1240 *bottom_index >= rc->best_quality); in rc_pick_q_and_bounds_two_pass()
1241 assert(q <= rc->worst_quality && q >= rc->best_quality); in rc_pick_q_and_bounds_two_pass()
1280 VPXMIN(frame_target + tol_high + 100, cpi->rc.max_frame_bandwidth); in vp9_rc_compute_frame_size_bounds()
1286 RATE_CONTROL *const rc = &cpi->rc; in vp9_rc_set_frame_target() local
1288 rc->this_frame_target = target; in vp9_rc_set_frame_target()
1292 rc->frame_size_selector != UNSCALED) in vp9_rc_set_frame_target()
1293 rc->this_frame_target = (int)(rc->this_frame_target * in vp9_rc_set_frame_target()
1294 rate_thresh_mult[rc->frame_size_selector]); in vp9_rc_set_frame_target()
1297 rc->sb64_target_rate = (int)(((int64_t)rc->this_frame_target * 64 * 64) / in vp9_rc_set_frame_target()
1303 RATE_CONTROL *const rc = &cpi->rc; in update_alt_ref_frame_stats() local
1304 rc->frames_since_golden = 0; in update_alt_ref_frame_stats()
1307 rc->source_alt_ref_pending = 0; in update_alt_ref_frame_stats()
1310 rc->source_alt_ref_active = 1; in update_alt_ref_frame_stats()
1314 RATE_CONTROL *const rc = &cpi->rc; in update_golden_frame_stats() local
1319 rc->frames_since_golden = 0; in update_golden_frame_stats()
1325 if (!rc->source_alt_ref_pending && (cpi->twopass.gf_group.index == 0)) in update_golden_frame_stats()
1326 rc->source_alt_ref_active = 0; in update_golden_frame_stats()
1327 } else if (!rc->source_alt_ref_pending) { in update_golden_frame_stats()
1328 rc->source_alt_ref_active = 0; in update_golden_frame_stats()
1332 if (rc->frames_till_gf_update_due > 0) rc->frames_till_gf_update_due--; in update_golden_frame_stats()
1336 if (rc->frames_till_gf_update_due > 0) rc->frames_till_gf_update_due--; in update_golden_frame_stats()
1338 rc->frames_since_golden++; in update_golden_frame_stats()
1346 RATE_CONTROL *const rc = &cpi->rc; in compute_frame_low_motion() local
1358 rc->avg_frame_low_motion = (3 * rc->avg_frame_low_motion + cnt_zeromv) >> 2; in compute_frame_low_motion()
1364 RATE_CONTROL *const rc = &cpi->rc; in vp9_rc_postencode_update() local
1368 rc->projected_frame_size = (int)(bytes_used << 3); in vp9_rc_postencode_update()
1375 rc->last_q[KEY_FRAME] = qindex; in vp9_rc_postencode_update()
1376 rc->avg_frame_qindex[KEY_FRAME] = in vp9_rc_postencode_update()
1377 ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[KEY_FRAME] + qindex, 2); in vp9_rc_postencode_update()
1385 RATE_CONTROL *lrc = &lc->rc; in vp9_rc_postencode_update()
1386 lrc->last_q[KEY_FRAME] = rc->last_q[KEY_FRAME]; in vp9_rc_postencode_update()
1387 lrc->avg_frame_qindex[KEY_FRAME] = rc->avg_frame_qindex[KEY_FRAME]; in vp9_rc_postencode_update()
1392 (!rc->is_src_frame_alt_ref && in vp9_rc_postencode_update()
1394 rc->last_q[INTER_FRAME] = qindex; in vp9_rc_postencode_update()
1395 rc->avg_frame_qindex[INTER_FRAME] = in vp9_rc_postencode_update()
1396 ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[INTER_FRAME] + qindex, 2); in vp9_rc_postencode_update()
1397 rc->ni_frames++; in vp9_rc_postencode_update()
1398 rc->tot_q += vp9_convert_qindex_to_q(qindex, cm->bit_depth); in vp9_rc_postencode_update()
1399 rc->avg_q = rc->tot_q / rc->ni_frames; in vp9_rc_postencode_update()
1402 rc->ni_tot_qi += qindex; in vp9_rc_postencode_update()
1403 rc->ni_av_qi = rc->ni_tot_qi / rc->ni_frames; in vp9_rc_postencode_update()
1412 if ((qindex < rc->last_boosted_qindex) || (cm->frame_type == KEY_FRAME) || in vp9_rc_postencode_update()
1413 (!rc->constrained_gf_group && in vp9_rc_postencode_update()
1415 (cpi->refresh_golden_frame && !rc->is_src_frame_alt_ref)))) { in vp9_rc_postencode_update()
1416 rc->last_boosted_qindex = qindex; in vp9_rc_postencode_update()
1418 if (cm->frame_type == KEY_FRAME) rc->last_kf_qindex = qindex; in vp9_rc_postencode_update()
1420 update_buffer_level(cpi, rc->projected_frame_size); in vp9_rc_postencode_update()
1425 rc->rolling_target_bits = ROUND_POWER_OF_TWO( in vp9_rc_postencode_update()
1426 rc->rolling_target_bits * 3 + rc->this_frame_target, 2); in vp9_rc_postencode_update()
1427 rc->rolling_actual_bits = ROUND_POWER_OF_TWO( in vp9_rc_postencode_update()
1428 rc->rolling_actual_bits * 3 + rc->projected_frame_size, 2); in vp9_rc_postencode_update()
1429 rc->long_rolling_target_bits = ROUND_POWER_OF_TWO( in vp9_rc_postencode_update()
1430 rc->long_rolling_target_bits * 31 + rc->this_frame_target, 5); in vp9_rc_postencode_update()
1431 rc->long_rolling_actual_bits = ROUND_POWER_OF_TWO( in vp9_rc_postencode_update()
1432 rc->long_rolling_actual_bits * 31 + rc->projected_frame_size, 5); in vp9_rc_postencode_update()
1436 rc->total_actual_bits += rc->projected_frame_size; in vp9_rc_postencode_update()
1437 rc->total_target_bits += cm->show_frame ? rc->avg_frame_bandwidth : 0; in vp9_rc_postencode_update()
1439 rc->total_target_vs_actual = rc->total_actual_bits - rc->total_target_bits; in vp9_rc_postencode_update()
1451 if (cm->frame_type == KEY_FRAME) rc->frames_since_key = 0; in vp9_rc_postencode_update()
1453 rc->frames_since_key++; in vp9_rc_postencode_update()
1454 rc->frames_to_key--; in vp9_rc_postencode_update()
1460 rc->next_frame_size_selector != rc->frame_size_selector; in vp9_rc_postencode_update()
1461 rc->frame_size_selector = rc->next_frame_size_selector; in vp9_rc_postencode_update()
1472 cpi->rc.frames_since_key++; in vp9_rc_postencode_update_drop_frame()
1473 cpi->rc.frames_to_key--; in vp9_rc_postencode_update_drop_frame()
1474 cpi->rc.rc_2_frame = 0; in vp9_rc_postencode_update_drop_frame()
1475 cpi->rc.rc_1_frame = 0; in vp9_rc_postencode_update_drop_frame()
1479 const RATE_CONTROL *const rc = &cpi->rc; in calc_pframe_target_size_one_pass_vbr() local
1480 const int af_ratio = rc->af_ratio_onepass_vbr; in calc_pframe_target_size_one_pass_vbr()
1482 (!rc->is_src_frame_alt_ref && in calc_pframe_target_size_one_pass_vbr()
1484 ? (rc->avg_frame_bandwidth * rc->baseline_gf_interval * af_ratio) / in calc_pframe_target_size_one_pass_vbr()
1485 (rc->baseline_gf_interval + af_ratio - 1) in calc_pframe_target_size_one_pass_vbr()
1486 : (rc->avg_frame_bandwidth * rc->baseline_gf_interval) / in calc_pframe_target_size_one_pass_vbr()
1487 (rc->baseline_gf_interval + af_ratio - 1); in calc_pframe_target_size_one_pass_vbr()
1493 const RATE_CONTROL *rc = &cpi->rc; in calc_iframe_target_size_one_pass_vbr() local
1494 const int target = rc->avg_frame_bandwidth * kf_ratio; in calc_iframe_target_size_one_pass_vbr()
1499 RATE_CONTROL *const rc = &cpi->rc; in adjust_gfint_frame_constraint() local
1500 rc->constrained_gf_group = 0; in adjust_gfint_frame_constraint()
1502 if ((frame_constraint <= 7 * rc->baseline_gf_interval >> 2) && in adjust_gfint_frame_constraint()
1503 (frame_constraint > rc->baseline_gf_interval)) { in adjust_gfint_frame_constraint()
1504 rc->baseline_gf_interval = frame_constraint >> 1; in adjust_gfint_frame_constraint()
1505 if (rc->baseline_gf_interval < 5) in adjust_gfint_frame_constraint()
1506 rc->baseline_gf_interval = frame_constraint; in adjust_gfint_frame_constraint()
1507 rc->constrained_gf_group = 1; in adjust_gfint_frame_constraint()
1510 if (rc->baseline_gf_interval > frame_constraint) { in adjust_gfint_frame_constraint()
1511 rc->baseline_gf_interval = frame_constraint; in adjust_gfint_frame_constraint()
1512 rc->constrained_gf_group = 1; in adjust_gfint_frame_constraint()
1519 RATE_CONTROL *const rc = &cpi->rc; in vp9_rc_get_one_pass_vbr_params() local
1524 rc->frames_to_key == 0 || (cpi->oxcf.auto_key && 0))) { in vp9_rc_get_one_pass_vbr_params()
1526 rc->this_key_frame_forced = in vp9_rc_get_one_pass_vbr_params()
1527 cm->current_video_frame != 0 && rc->frames_to_key == 0; in vp9_rc_get_one_pass_vbr_params()
1528 rc->frames_to_key = cpi->oxcf.key_freq; in vp9_rc_get_one_pass_vbr_params()
1529 rc->kf_boost = DEFAULT_KF_BOOST; in vp9_rc_get_one_pass_vbr_params()
1530 rc->source_alt_ref_active = 0; in vp9_rc_get_one_pass_vbr_params()
1534 if (rc->frames_till_gf_update_due == 0) { in vp9_rc_get_one_pass_vbr_params()
1536 rc->gfu_boost = DEFAULT_GF_BOOST; in vp9_rc_get_one_pass_vbr_params()
1540 rc->baseline_gf_interval = VPXMIN( in vp9_rc_get_one_pass_vbr_params()
1541 20, VPXMAX(10, (rc->min_gf_interval + rc->max_gf_interval) / 2)); in vp9_rc_get_one_pass_vbr_params()
1543 rc->af_ratio_onepass_vbr = 10; in vp9_rc_get_one_pass_vbr_params()
1544 if (rc->rolling_target_bits > 0) in vp9_rc_get_one_pass_vbr_params()
1546 (double)rc->rolling_actual_bits / (double)rc->rolling_target_bits; in vp9_rc_get_one_pass_vbr_params()
1548 if (rc->avg_frame_qindex[INTER_FRAME] > (7 * rc->worst_quality) >> 3 && in vp9_rc_get_one_pass_vbr_params()
1550 rc->baseline_gf_interval = in vp9_rc_get_one_pass_vbr_params()
1551 VPXMIN(15, (3 * rc->baseline_gf_interval) >> 1); in vp9_rc_get_one_pass_vbr_params()
1552 } else if (rc->avg_frame_low_motion < 20) { in vp9_rc_get_one_pass_vbr_params()
1554 rc->baseline_gf_interval = VPXMAX(6, rc->baseline_gf_interval >> 1); in vp9_rc_get_one_pass_vbr_params()
1558 rc->gfu_boost = in vp9_rc_get_one_pass_vbr_params()
1559 VPXMAX(500, DEFAULT_GF_BOOST * (rc->avg_frame_low_motion << 1) / in vp9_rc_get_one_pass_vbr_params()
1560 (rc->avg_frame_low_motion + 100)); in vp9_rc_get_one_pass_vbr_params()
1561 rc->af_ratio_onepass_vbr = VPXMIN(15, VPXMAX(5, 3 * rc->gfu_boost / 400)); in vp9_rc_get_one_pass_vbr_params()
1563 adjust_gfint_frame_constraint(cpi, rc->frames_to_key); in vp9_rc_get_one_pass_vbr_params()
1564 rc->frames_till_gf_update_due = rc->baseline_gf_interval; in vp9_rc_get_one_pass_vbr_params()
1566 rc->source_alt_ref_pending = 0; in vp9_rc_get_one_pass_vbr_params()
1567 rc->alt_ref_gf_group = 0; in vp9_rc_get_one_pass_vbr_params()
1570 rc->source_alt_ref_pending = 1; in vp9_rc_get_one_pass_vbr_params()
1571 rc->alt_ref_gf_group = 1; in vp9_rc_get_one_pass_vbr_params()
1586 const RATE_CONTROL *rc = &cpi->rc; in calc_pframe_target_size_one_pass_cbr() local
1588 const int64_t diff = rc->optimal_buffer_level - rc->buffer_level; in calc_pframe_target_size_one_pass_cbr()
1589 const int64_t one_pct_bits = 1 + rc->optimal_buffer_level / 100; in calc_pframe_target_size_one_pass_cbr()
1591 VPXMAX(rc->avg_frame_bandwidth >> 4, FRAME_OVERHEAD_BITS); in calc_pframe_target_size_one_pass_cbr()
1597 ? (rc->avg_frame_bandwidth * rc->baseline_gf_interval * in calc_pframe_target_size_one_pass_cbr()
1599 (rc->baseline_gf_interval * 100 + af_ratio_pct - 100) in calc_pframe_target_size_one_pass_cbr()
1600 : (rc->avg_frame_bandwidth * rc->baseline_gf_interval * 100) / in calc_pframe_target_size_one_pass_cbr()
1601 (rc->baseline_gf_interval * 100 + af_ratio_pct - 100); in calc_pframe_target_size_one_pass_cbr()
1603 target = rc->avg_frame_bandwidth; in calc_pframe_target_size_one_pass_cbr()
1627 rc->avg_frame_bandwidth * oxcf->rc_max_inter_bitrate_pct / 100; in calc_pframe_target_size_one_pass_cbr()
1634 const RATE_CONTROL *rc = &cpi->rc; in calc_iframe_target_size_one_pass_cbr() local
1639 target = ((rc->starting_buffer_level / 2) > INT_MAX) in calc_iframe_target_size_one_pass_cbr()
1641 : (int)(rc->starting_buffer_level / 2); in calc_iframe_target_size_one_pass_cbr()
1654 if (rc->frames_since_key < framerate / 2) { in calc_iframe_target_size_one_pass_cbr()
1655 kf_boost = (int)(kf_boost * rc->frames_since_key / (framerate / 2)); in calc_iframe_target_size_one_pass_cbr()
1657 target = ((16 + kf_boost) * rc->avg_frame_bandwidth) >> 4; in calc_iframe_target_size_one_pass_cbr()
1664 RATE_CONTROL *const rc = &cpi->rc; in vp9_rc_get_svc_params() local
1665 int target = rc->avg_frame_bandwidth; in vp9_rc_get_svc_params()
1676 rc->source_alt_ref_active = 0; in vp9_rc_get_svc_params()
1721 rc->frames_till_gf_update_due = INT_MAX; in vp9_rc_get_svc_params()
1722 rc->baseline_gf_interval = INT_MAX; in vp9_rc_get_svc_params()
1727 RATE_CONTROL *const rc = &cpi->rc; in vp9_rc_get_one_pass_cbr_params() local
1731 rc->frames_to_key == 0 || (cpi->oxcf.auto_key && 0))) { in vp9_rc_get_one_pass_cbr_params()
1733 rc->this_key_frame_forced = in vp9_rc_get_one_pass_cbr_params()
1734 cm->current_video_frame != 0 && rc->frames_to_key == 0; in vp9_rc_get_one_pass_cbr_params()
1735 rc->frames_to_key = cpi->oxcf.key_freq; in vp9_rc_get_one_pass_cbr_params()
1736 rc->kf_boost = DEFAULT_KF_BOOST; in vp9_rc_get_one_pass_cbr_params()
1737 rc->source_alt_ref_active = 0; in vp9_rc_get_one_pass_cbr_params()
1741 if (rc->frames_till_gf_update_due == 0) { in vp9_rc_get_one_pass_cbr_params()
1745 rc->baseline_gf_interval = in vp9_rc_get_one_pass_cbr_params()
1746 (rc->min_gf_interval + rc->max_gf_interval) / 2; in vp9_rc_get_one_pass_cbr_params()
1747 rc->frames_till_gf_update_due = rc->baseline_gf_interval; in vp9_rc_get_one_pass_cbr_params()
1749 if (rc->frames_till_gf_update_due > rc->frames_to_key) in vp9_rc_get_one_pass_cbr_params()
1750 rc->frames_till_gf_update_due = rc->frames_to_key; in vp9_rc_get_one_pass_cbr_params()
1752 rc->gfu_boost = DEFAULT_GF_BOOST; in vp9_rc_get_one_pass_cbr_params()
1772 int vp9_compute_qdelta(const RATE_CONTROL *rc, double qstart, double qtarget, in vp9_compute_qdelta() argument
1774 int start_index = rc->worst_quality; in vp9_compute_qdelta()
1775 int target_index = rc->worst_quality; in vp9_compute_qdelta()
1779 for (i = rc->best_quality; i < rc->worst_quality; ++i) { in vp9_compute_qdelta()
1785 for (i = rc->best_quality; i < rc->worst_quality; ++i) { in vp9_compute_qdelta()
1793 int vp9_compute_qdelta_by_rate(const RATE_CONTROL *rc, FRAME_TYPE frame_type, in vp9_compute_qdelta_by_rate() argument
1796 int target_index = rc->worst_quality; in vp9_compute_qdelta_by_rate()
1807 for (i = rc->best_quality; i < rc->worst_quality; ++i) { in vp9_compute_qdelta_by_rate()
1818 RATE_CONTROL *const rc) { in vp9_rc_set_gf_interval_range() argument
1823 rc->max_gf_interval = FIXED_GF_INTERVAL; in vp9_rc_set_gf_interval_range()
1824 rc->min_gf_interval = FIXED_GF_INTERVAL; in vp9_rc_set_gf_interval_range()
1825 rc->static_scene_max_gf_interval = FIXED_GF_INTERVAL; in vp9_rc_set_gf_interval_range()
1828 rc->max_gf_interval = oxcf->max_gf_interval; in vp9_rc_set_gf_interval_range()
1829 rc->min_gf_interval = oxcf->min_gf_interval; in vp9_rc_set_gf_interval_range()
1830 if (rc->min_gf_interval == 0) in vp9_rc_set_gf_interval_range()
1831 rc->min_gf_interval = vp9_rc_get_default_min_gf_interval( in vp9_rc_set_gf_interval_range()
1833 if (rc->max_gf_interval == 0) in vp9_rc_set_gf_interval_range()
1834 rc->max_gf_interval = vp9_rc_get_default_max_gf_interval( in vp9_rc_set_gf_interval_range()
1835 cpi->framerate, rc->min_gf_interval); in vp9_rc_set_gf_interval_range()
1838 rc->static_scene_max_gf_interval = MAX_LAG_BUFFERS * 2; in vp9_rc_set_gf_interval_range()
1841 if (rc->static_scene_max_gf_interval > oxcf->lag_in_frames - 1) in vp9_rc_set_gf_interval_range()
1842 rc->static_scene_max_gf_interval = oxcf->lag_in_frames - 1; in vp9_rc_set_gf_interval_range()
1845 if (rc->max_gf_interval > rc->static_scene_max_gf_interval) in vp9_rc_set_gf_interval_range()
1846 rc->max_gf_interval = rc->static_scene_max_gf_interval; in vp9_rc_set_gf_interval_range()
1849 rc->min_gf_interval = VPXMIN(rc->min_gf_interval, rc->max_gf_interval); in vp9_rc_set_gf_interval_range()
1856 RATE_CONTROL *const rc = &cpi->rc; in vp9_rc_update_framerate() local
1859 rc->avg_frame_bandwidth = (int)(oxcf->target_bandwidth / cpi->framerate); in vp9_rc_update_framerate()
1860 rc->min_frame_bandwidth = in vp9_rc_update_framerate()
1861 (int)(rc->avg_frame_bandwidth * oxcf->two_pass_vbrmin_section / 100); in vp9_rc_update_framerate()
1863 rc->min_frame_bandwidth = in vp9_rc_update_framerate()
1864 VPXMAX(rc->min_frame_bandwidth, FRAME_OVERHEAD_BITS); in vp9_rc_update_framerate()
1874 (int)(((int64_t)rc->avg_frame_bandwidth * oxcf->two_pass_vbrmax_section) / in vp9_rc_update_framerate()
1876 rc->max_frame_bandwidth = in vp9_rc_update_framerate()
1879 vp9_rc_set_gf_interval_range(cpi, rc); in vp9_rc_update_framerate()
1885 RATE_CONTROL *const rc = &cpi->rc; in vbr_rate_correction() local
1886 int64_t vbr_bits_off_target = rc->vbr_bits_off_target; in vbr_rate_correction()
1914 if (!frame_is_kf_gf_arf(cpi) && !rc->is_src_frame_alt_ref && in vbr_rate_correction()
1915 rc->vbr_bits_off_target_fast) { in vbr_rate_correction()
1916 int one_frame_bits = VPXMAX(rc->avg_frame_bandwidth, *this_frame_target); in vbr_rate_correction()
1918 fast_extra_bits = (int)VPXMIN(rc->vbr_bits_off_target_fast, one_frame_bits); in vbr_rate_correction()
1921 VPXMAX(one_frame_bits / 8, rc->vbr_bits_off_target_fast / 8)); in vbr_rate_correction()
1923 rc->vbr_bits_off_target_fast -= fast_extra_bits; in vbr_rate_correction()
1928 RATE_CONTROL *const rc = &cpi->rc; in vp9_set_target_rate() local
1929 int target_rate = rc->base_frame_target; in vp9_set_target_rate()
1946 RATE_CONTROL *const rc = &cpi->rc; in vp9_resize_one_pass_cbr() local
1986 if (cpi->rc.frames_since_key > 2 * cpi->framerate) { in vp9_resize_one_pass_cbr()
1989 if (cpi->rc.buffer_level < (int)(30 * rc->optimal_buffer_level / 100)) in vp9_resize_one_pass_cbr()
2009 avg_qp < avg_qp_thr1 * cpi->rc.worst_quality / 100) { in vp9_resize_one_pass_cbr()
2011 avg_qp < avg_qp_thr2 * cpi->rc.worst_quality / 100 || in vp9_resize_one_pass_cbr()
2046 rc->buffer_level = rc->optimal_buffer_level; in vp9_resize_one_pass_cbr()
2047 rc->bits_off_target = rc->optimal_buffer_level; in vp9_resize_one_pass_cbr()
2048 rc->this_frame_target = calc_pframe_target_size_one_pass_cbr(cpi); in vp9_resize_one_pass_cbr()
2052 ? rc->this_frame_target * tot_scale_change in vp9_resize_one_pass_cbr()
2053 : rc->this_frame_target / tot_scale_change; in vp9_resize_one_pass_cbr()
2055 qindex = vp9_rc_regulate_q(cpi, target_bits_per_frame, rc->best_quality, in vp9_resize_one_pass_cbr()
2060 if (resize_action > 0 && qindex > 90 * cpi->rc.worst_quality / 100) { in vp9_resize_one_pass_cbr()
2061 rc->rate_correction_factors[INTER_NORMAL] *= 0.85; in vp9_resize_one_pass_cbr()
2067 rc->rate_correction_factors[INTER_NORMAL] *= 0.9; in vp9_resize_one_pass_cbr()
2075 RATE_CONTROL *const rc = &cpi->rc; in adjust_gf_boost_lag_one_pass_vbr() local
2094 uint64_t reference_sad = rc->avg_source_sad[0]; in adjust_gf_boost_lag_one_pass_vbr()
2096 if (rc->avg_source_sad[i] > 0) in adjust_gf_boost_lag_one_pass_vbr()
2097 reference_sad = (3 * reference_sad + rc->avg_source_sad[i]) >> 2; in adjust_gf_boost_lag_one_pass_vbr()
2101 (rc->avg_source_sad[lagframe_idx] > in adjust_gf_boost_lag_one_pass_vbr()
2103 rc->avg_source_sad[lagframe_idx] > in adjust_gf_boost_lag_one_pass_vbr()
2111 rc->avg_source_sad[lagframe_idx - 1] > (sad_thresh1 >> 2)) { in adjust_gf_boost_lag_one_pass_vbr()
2114 if (!(rc->avg_source_sad[i] > 0 && in adjust_gf_boost_lag_one_pass_vbr()
2115 rc->avg_source_sad[i] < (sad_thresh1 >> 2) && in adjust_gf_boost_lag_one_pass_vbr()
2116 rc->avg_source_sad[i] < in adjust_gf_boost_lag_one_pass_vbr()
2117 (rc->avg_source_sad[lagframe_idx - 1] >> 1))) { in adjust_gf_boost_lag_one_pass_vbr()
2124 avg_source_sad_lag += rc->avg_source_sad[lagframe_idx]; in adjust_gf_boost_lag_one_pass_vbr()
2129 high_source_sad_lagindex != rc->high_source_sad_lagindex - 1 && in adjust_gf_boost_lag_one_pass_vbr()
2130 abs(high_source_sad_lagindex - rc->high_source_sad_lagindex) < 4) in adjust_gf_boost_lag_one_pass_vbr()
2131 rc->high_source_sad_lagindex = -1; in adjust_gf_boost_lag_one_pass_vbr()
2133 rc->high_source_sad_lagindex = high_source_sad_lagindex; in adjust_gf_boost_lag_one_pass_vbr()
2139 if (rc->rolling_target_bits > 0) in adjust_gf_boost_lag_one_pass_vbr()
2141 (double)rc->rolling_actual_bits / (double)rc->rolling_target_bits; in adjust_gf_boost_lag_one_pass_vbr()
2143 avg_source_sad_lag > (rc->prev_avg_source_sad_lag << 1) || in adjust_gf_boost_lag_one_pass_vbr()
2146 ((avg_source_sad_lag < (rc->prev_avg_source_sad_lag >> 1)) || in adjust_gf_boost_lag_one_pass_vbr()
2149 rc->gfu_boost = DEFAULT_GF_BOOST; in adjust_gf_boost_lag_one_pass_vbr()
2150 rc->baseline_gf_interval = in adjust_gf_boost_lag_one_pass_vbr()
2151 VPXMIN(15, (3 * rc->baseline_gf_interval) >> 1); in adjust_gf_boost_lag_one_pass_vbr()
2153 rc->gfu_boost = DEFAULT_GF_BOOST >> 1; in adjust_gf_boost_lag_one_pass_vbr()
2154 rc->baseline_gf_interval = (rate_err > 3.0) in adjust_gf_boost_lag_one_pass_vbr()
2155 ? VPXMAX(10, rc->baseline_gf_interval >> 1) in adjust_gf_boost_lag_one_pass_vbr()
2156 : VPXMAX(6, rc->baseline_gf_interval >> 1); in adjust_gf_boost_lag_one_pass_vbr()
2158 if (rc->baseline_gf_interval > cpi->oxcf.lag_in_frames - 1) in adjust_gf_boost_lag_one_pass_vbr()
2159 rc->baseline_gf_interval = cpi->oxcf.lag_in_frames - 1; in adjust_gf_boost_lag_one_pass_vbr()
2162 frame_constraint = rc->frames_to_key; in adjust_gf_boost_lag_one_pass_vbr()
2163 if (rc->high_source_sad_lagindex > 0 && in adjust_gf_boost_lag_one_pass_vbr()
2164 frame_constraint > rc->high_source_sad_lagindex) in adjust_gf_boost_lag_one_pass_vbr()
2165 frame_constraint = rc->high_source_sad_lagindex; in adjust_gf_boost_lag_one_pass_vbr()
2169 rc->frames_till_gf_update_due = rc->baseline_gf_interval; in adjust_gf_boost_lag_one_pass_vbr()
2171 rc->fac_active_worst_inter = 150; // corresponds to 3/2 (= 150 /100). in adjust_gf_boost_lag_one_pass_vbr()
2172 rc->fac_active_worst_gf = 100; in adjust_gf_boost_lag_one_pass_vbr()
2174 rc->fac_active_worst_inter = 120; in adjust_gf_boost_lag_one_pass_vbr()
2175 rc->fac_active_worst_gf = 90; in adjust_gf_boost_lag_one_pass_vbr()
2176 } else if (rate_err > 8.0 && rc->avg_frame_qindex[INTER_FRAME] < 16) { in adjust_gf_boost_lag_one_pass_vbr()
2178 rc->fac_active_worst_inter = 200; in adjust_gf_boost_lag_one_pass_vbr()
2179 if (rc->avg_frame_qindex[INTER_FRAME] < 8) in adjust_gf_boost_lag_one_pass_vbr()
2180 rc->fac_active_worst_inter = 400; in adjust_gf_boost_lag_one_pass_vbr()
2182 if (low_content && rc->avg_frame_low_motion > 80) { in adjust_gf_boost_lag_one_pass_vbr()
2183 rc->af_ratio_onepass_vbr = 15; in adjust_gf_boost_lag_one_pass_vbr()
2184 } else if (high_content || rc->avg_frame_low_motion < 30) { in adjust_gf_boost_lag_one_pass_vbr()
2185 rc->af_ratio_onepass_vbr = 5; in adjust_gf_boost_lag_one_pass_vbr()
2186 rc->gfu_boost = DEFAULT_GF_BOOST >> 2; in adjust_gf_boost_lag_one_pass_vbr()
2192 if ((rc->high_source_sad_lagindex > 0 && in adjust_gf_boost_lag_one_pass_vbr()
2193 rc->high_source_sad_lagindex <= rc->frames_till_gf_update_due) || in adjust_gf_boost_lag_one_pass_vbr()
2195 rc->source_alt_ref_pending = 0; in adjust_gf_boost_lag_one_pass_vbr()
2196 rc->alt_ref_gf_group = 0; in adjust_gf_boost_lag_one_pass_vbr()
2198 rc->source_alt_ref_pending = 1; in adjust_gf_boost_lag_one_pass_vbr()
2199 rc->alt_ref_gf_group = 1; in adjust_gf_boost_lag_one_pass_vbr()
2201 if (rc->baseline_gf_interval > 10 && in adjust_gf_boost_lag_one_pass_vbr()
2202 rc->baseline_gf_interval < rc->frames_to_key) in adjust_gf_boost_lag_one_pass_vbr()
2203 rc->baseline_gf_interval = 10; in adjust_gf_boost_lag_one_pass_vbr()
2210 rc->prev_avg_source_sad_lag = avg_source_sad_lag; in adjust_gf_boost_lag_one_pass_vbr()
2220 RATE_CONTROL *const rc = &cpi->rc; in vp9_scene_detection_onepass() local
2224 rc->high_source_sad = 0; in vp9_scene_detection_onepass()
2258 avg_sad_current = rc->avg_source_sad[1]; in vp9_scene_detection_onepass()
2261 (unsigned int)(rc->avg_source_sad[0] * thresh)) && in vp9_scene_detection_onepass()
2263 rc->high_source_sad = 1; in vp9_scene_detection_onepass()
2265 rc->high_source_sad = 0; in vp9_scene_detection_onepass()
2268 rc->avg_source_sad[0] = in vp9_scene_detection_onepass()
2269 (3 * rc->avg_source_sad[0] + avg_sad_current) >> 2; in vp9_scene_detection_onepass()
2272 rc->avg_source_sad[frame] = rc->avg_source_sad[frame + 1]; in vp9_scene_detection_onepass()
2321 (unsigned int)(rc->avg_source_sad[0] * thresh)) && in vp9_scene_detection_onepass()
2322 rc->frames_since_key > 1) in vp9_scene_detection_onepass()
2323 rc->high_source_sad = 1; in vp9_scene_detection_onepass()
2325 rc->high_source_sad = 0; in vp9_scene_detection_onepass()
2327 rc->avg_source_sad[0] = (3 * rc->avg_source_sad[0] + avg_sad) >> 2; in vp9_scene_detection_onepass()
2329 rc->avg_source_sad[lagframe_idx] = avg_sad; in vp9_scene_detection_onepass()
2335 rc->high_source_sad && rc->frames_to_key > 3 && in vp9_scene_detection_onepass()
2336 rc->count_last_scene_change > 4 && in vp9_scene_detection_onepass()
2340 rc->source_alt_ref_pending = 0; in vp9_scene_detection_onepass()
2342 if (cpi->oxcf.enable_auto_arf) rc->source_alt_ref_pending = 1; in vp9_scene_detection_onepass()
2344 rc->gfu_boost = DEFAULT_GF_BOOST >> 1; in vp9_scene_detection_onepass()
2345 rc->baseline_gf_interval = in vp9_scene_detection_onepass()
2346 VPXMIN(20, VPXMAX(10, rc->baseline_gf_interval)); in vp9_scene_detection_onepass()
2347 adjust_gfint_frame_constraint(cpi, rc->frames_to_key); in vp9_scene_detection_onepass()
2348 rc->frames_till_gf_update_due = rc->baseline_gf_interval; in vp9_scene_detection_onepass()
2351 rc->count_last_scene_change = 0; in vp9_scene_detection_onepass()
2353 rc->count_last_scene_change++; in vp9_scene_detection_onepass()
2365 RATE_CONTROL *const rc = &cpi->rc; in vp9_encodedframe_overshoot() local
2366 int thresh_qp = 3 * (rc->worst_quality >> 2); in vp9_encodedframe_overshoot()
2367 int thresh_rate = rc->avg_frame_bandwidth * 10; in vp9_encodedframe_overshoot()
2370 cpi->rc.rate_correction_factors[INTER_NORMAL]; in vp9_encodedframe_overshoot()
2371 const int target_size = cpi->rc.avg_frame_bandwidth; in vp9_encodedframe_overshoot()
2377 *q = cpi->rc.worst_quality; in vp9_encodedframe_overshoot()
2382 cpi->rc.avg_frame_qindex[INTER_FRAME] = *q; in vp9_encodedframe_overshoot()
2383 rc->buffer_level = rc->optimal_buffer_level; in vp9_encodedframe_overshoot()
2384 rc->bits_off_target = rc->optimal_buffer_level; in vp9_encodedframe_overshoot()
2386 cpi->rc.rc_1_frame = 0; in vp9_encodedframe_overshoot()
2387 cpi->rc.rc_2_frame = 0; in vp9_encodedframe_overshoot()
2402 cpi->rc.rate_correction_factors[INTER_NORMAL] = rate_correction_factor; in vp9_encodedframe_overshoot()
2413 RATE_CONTROL *lrc = &lc->rc; in vp9_encodedframe_overshoot()
2415 lrc->buffer_level = rc->optimal_buffer_level; in vp9_encodedframe_overshoot()
2416 lrc->bits_off_target = rc->optimal_buffer_level; in vp9_encodedframe_overshoot()