Lines Matching refs:cpi

215 int vp9_rc_clamp_pframe_target_size(const VP9_COMP *const cpi, int target) {
216 const RATE_CONTROL *rc = &cpi->rc;
217 const VP9EncoderConfig *oxcf = &cpi->oxcf;
221 if (cpi->refresh_golden_frame && rc->is_src_frame_alt_ref) {
238 int vp9_rc_clamp_iframe_target_size(const VP9_COMP *const cpi, int target) {
239 const RATE_CONTROL *rc = &cpi->rc;
240 const VP9EncoderConfig *oxcf = &cpi->oxcf;
272 static void update_buffer_level(VP9_COMP *cpi, int encoded_frame_size) {
273 const VP9_COMMON *const cm = &cpi->common;
274 RATE_CONTROL *const rc = &cpi->rc;
288 if (cpi->oxcf.content == VP9E_CONTENT_SCREEN &&
289 cpi->oxcf.drop_frames_water_mark == 0)
294 if (is_one_pass_cbr_svc(cpi)) {
295 update_layer_buffer_level(&cpi->svc, encoded_frame_size);
391 int vp9_rc_drop_frame(VP9_COMP *cpi) {
392 const VP9EncoderConfig *oxcf = &cpi->oxcf;
393 RATE_CONTROL *const rc = &cpi->rc;
395 (is_one_pass_cbr_svc(cpi) &&
396 cpi->svc.spatial_layer_id > cpi->svc.first_spatial_layer_to_encode)) {
428 static double get_rate_correction_factor(const VP9_COMP *cpi) {
429 const RATE_CONTROL *const rc = &cpi->rc;
432 if (cpi->common.frame_type == KEY_FRAME) {
434 } else if (cpi->oxcf.pass == 2) {
436 cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index];
439 if ((cpi->refresh_alt_ref_frame || cpi->refresh_golden_frame) &&
440 !rc->is_src_frame_alt_ref && !cpi->use_svc &&
441 (cpi->oxcf.rc_mode != VPX_CBR || cpi->oxcf.gf_cbr_boost_pct > 100))
450 static void set_rate_correction_factor(VP9_COMP *cpi, double factor) {
451 RATE_CONTROL *const rc = &cpi->rc;
454 factor /= rcf_mult[cpi->rc.frame_size_selector];
458 if (cpi->common.frame_type == KEY_FRAME) {
460 } else if (cpi->oxcf.pass == 2) {
462 cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index];
465 if ((cpi->refresh_alt_ref_frame || cpi->refresh_golden_frame) &&
466 !rc->is_src_frame_alt_ref && !cpi->use_svc &&
467 (cpi->oxcf.rc_mode != VPX_CBR || cpi->oxcf.gf_cbr_boost_pct > 100))
474 void vp9_rc_update_rate_correction_factors(VP9_COMP *cpi) {
475 const VP9_COMMON *const cm = &cpi->common;
477 double rate_correction_factor = get_rate_correction_factor(cpi);
483 if (cpi->rc.is_src_frame_alt_ref) return;
491 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cpi->common.seg.enabled) {
493 vp9_cyclic_refresh_estimate_bits_at_q(cpi, rate_correction_factor);
496 vp9_estimate_bits_at_q(cpi->common.frame_type, cm->base_qindex, cm->MBs,
501 correction_factor = (int)((100 * (int64_t)cpi->rc.projected_frame_size) /
509 cpi->rc.q_2_frame = cpi->rc.q_1_frame;
510 cpi->rc.q_1_frame = cm->base_qindex;
511 cpi->rc.rc_2_frame = cpi->rc.rc_1_frame;
513 cpi->rc.rc_1_frame = -1;
515 cpi->rc.rc_1_frame = 1;
517 cpi->rc.rc_1_frame = 0;
520 if (cpi->rc.rc_1_frame == -1 && cpi->rc.rc_2_frame == 1 &&
522 cpi->rc.rc_2_frame = 0;
544 set_rate_correction_factor(cpi, rate_correction_factor);
547 int vp9_rc_regulate_q(const VP9_COMP *cpi, int target_bits_per_frame,
549 const VP9_COMMON *const cm = &cpi->common;
550 CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
554 const double correction_factor = get_rate_correction_factor(cpi);
564 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled &&
566 (!cpi->oxcf.gf_cbr_boost_pct || !cpi->refresh_golden_frame)) {
568 (int)vp9_cyclic_refresh_rc_bits_per_mb(cpi, i, correction_factor);
588 if (cpi->oxcf.rc_mode == VPX_CBR &&
589 (!cpi->oxcf.gf_cbr_boost_pct ||
590 !(cpi->refresh_alt_ref_frame || cpi->refresh_golden_frame)) &&
591 (cpi->rc.rc_1_frame * cpi->rc.rc_2_frame == -1) &&
592 cpi->rc.q_1_frame != cpi->rc.q_2_frame) {
593 q = clamp(q, VPXMIN(cpi->rc.q_1_frame, cpi->rc.q_2_frame),
594 VPXMAX(cpi->rc.q_1_frame, cpi->rc.q_2_frame));
597 if (cpi->oxcf.enable_auto_arf && cpi->oxcf.pass == 0 &&
598 cpi->oxcf.rc_mode == VPX_VBR && cpi->oxcf.lag_in_frames > 0 &&
599 cpi->rc.is_src_frame_alt_ref && !cpi->rc.alt_ref_gf_group) {
600 q = VPXMIN(q, (q + cpi->rc.last_boosted_qindex) >> 1);
641 static int calc_active_worst_quality_one_pass_vbr(const VP9_COMP *cpi) {
642 const RATE_CONTROL *const rc = &cpi->rc;
643 const unsigned int curr_frame = cpi->common.current_video_frame;
646 if (cpi->common.frame_type == KEY_FRAME) {
651 (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
667 static int calc_active_worst_quality_one_pass_cbr(const VP9_COMP *cpi) {
673 const VP9_COMMON *const cm = &cpi->common;
674 const RATE_CONTROL *rc = &cpi->rc;
681 unsigned int num_frames_weight_key = 5 * cpi->svc.number_temporal_layers;
694 if (cpi->use_svc && cpi->svc.spatial_layer_id > 0) {
695 int layer = LAYER_IDS_TO_IDX(0, cpi->svc.temporal_layer_id,
696 cpi->svc.number_temporal_layers);
697 const LAYER_CONTEXT *lc = &cpi->svc.layer_context[layer];
734 static int rc_pick_q_and_bounds_one_pass_cbr(const VP9_COMP *cpi,
737 const VP9_COMMON *const cm = &cpi->common;
738 const RATE_CONTROL *const rc = &cpi->rc;
740 int active_worst_quality = calc_active_worst_quality_one_pass_cbr(cpi);
775 } else if (!rc->is_src_frame_alt_ref && !cpi->use_svc &&
776 (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
818 &cpi->rc, cm->frame_type, active_worst_quality, 2.0, cm->bit_depth);
828 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, active_best_quality,
881 static int rc_pick_q_and_bounds_one_pass_vbr(const VP9_COMP *cpi,
884 const VP9_COMMON *const cm = &cpi->common;
885 const RATE_CONTROL *const rc = &cpi->rc;
886 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
889 int active_worst_quality = calc_active_worst_quality_one_pass_vbr(cpi);
929 (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
955 if (cpi->refresh_alt_ref_frame)
1008 &cpi->rc, cm->frame_type, active_worst_quality, 2.0, cm->bit_depth);
1010 (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
1012 &cpi->rc, cm->frame_type, active_worst_quality, 1.75, cm->bit_depth);
1025 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, active_best_quality,
1043 int vp9_frame_type_qdelta(const VP9_COMP *cpi, int rf_level, int q) {
1054 const VP9_COMMON *const cm = &cpi->common;
1056 vp9_compute_qdelta_by_rate(&cpi->rc, frame_type[rf_level], q,
1062 static int rc_pick_q_and_bounds_two_pass(const VP9_COMP *cpi, int *bottom_index,
1064 const VP9_COMMON *const cm = &cpi->common;
1065 const RATE_CONTROL *const rc = &cpi->rc;
1066 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
1067 const GF_GROUP *gf_group = &cpi->twopass.gf_group;
1068 const int cq_level = get_active_cq_level_two_pass(&cpi->twopass, rc, oxcf);
1070 int active_worst_quality = cpi->twopass.active_worst_quality;
1075 if (frame_is_intra_only(cm) || vp9_is_upper_layer_key_frame(cpi)) {
1084 if (cpi->twopass.last_kfgroup_zeromotion_pct >= STATIC_MOTION_THRESH) {
1103 // Baseline value derived from cpi->active_worst_quality and kf boost.
1113 q_adj_factor += 0.05 - (0.001 * (double)cpi->twopass.kf_zeromotion_pct);
1122 (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame)) {
1142 if (!cpi->refresh_alt_ref_frame) {
1171 if (cpi->oxcf.rc_mode != VPX_Q) {
1174 (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame))) {
1176 (cpi->twopass.extend_minq + cpi->twopass.extend_minq_fast);
1177 active_worst_quality += (cpi->twopass.extend_maxq / 2);
1180 (cpi->twopass.extend_minq + cpi->twopass.extend_minq_fast) / 2;
1181 active_worst_quality += cpi->twopass.extend_maxq;
1188 if (!((frame_is_intra_only(cm) || vp9_is_upper_layer_key_frame(cpi))) ||
1190 (cpi->twopass.last_kfgroup_zeromotion_pct < STATIC_MOTION_THRESH)) {
1191 int qdelta = vp9_frame_type_qdelta(cpi, gf_group->rf_level[gf_group->index],
1199 if (rc->frame_size_selector != UNSCALED && !frame_is_kf_gf_arf(cpi)) {
1214 } else if ((frame_is_intra_only(cm) || vp9_is_upper_layer_key_frame(cpi)) &&
1217 if (cpi->twopass.last_kfgroup_zeromotion_pct >= STATIC_MOTION_THRESH) {
1223 q = vp9_rc_regulate_q(cpi, rc->this_frame_target, active_best_quality,
1245 int vp9_rc_pick_q_and_bounds(const VP9_COMP *cpi, int *bottom_index,
1248 if (cpi->oxcf.pass == 0) {
1249 if (cpi->oxcf.rc_mode == VPX_CBR)
1250 q = rc_pick_q_and_bounds_one_pass_cbr(cpi, bottom_index, top_index);
1252 q = rc_pick_q_and_bounds_one_pass_vbr(cpi, bottom_index, top_index);
1254 q = rc_pick_q_and_bounds_two_pass(cpi, bottom_index, top_index);
1256 if (cpi->sf.use_nonrd_pick_mode) {
1257 if (cpi->sf.force_frame_boost == 1) q -= cpi->sf.max_delta_qindex;
1267 void vp9_rc_compute_frame_size_bounds(const VP9_COMP *cpi, int frame_target,
1270 if (cpi->oxcf.rc_mode == VPX_Q) {
1276 const int tol_low = (cpi->sf.recode_tolerance_low * frame_target) / 100;
1277 const int tol_high = (cpi->sf.recode_tolerance_high * frame_target) / 100;
1280 VPXMIN(frame_target + tol_high + 100, cpi->rc.max_frame_bandwidth);
1284 void vp9_rc_set_frame_target(VP9_COMP *cpi, int target) {
1285 const VP9_COMMON *const cm = &cpi->common;
1286 RATE_CONTROL *const rc = &cpi->rc;
1291 if (cpi->oxcf.resize_mode == RESIZE_DYNAMIC &&
1301 static void update_alt_ref_frame_stats(VP9_COMP *cpi) {
1303 RATE_CONTROL *const rc = &cpi->rc;
1313 static void update_golden_frame_stats(VP9_COMP *cpi) {
1314 RATE_CONTROL *const rc = &cpi->rc;
1317 if (cpi->refresh_golden_frame) {
1324 if (cpi->oxcf.pass == 2) {
1325 if (!rc->source_alt_ref_pending && (cpi->twopass.gf_group.index == 0))
1334 } else if (!cpi->refresh_alt_ref_frame) {
1342 static void compute_frame_low_motion(VP9_COMP *const cpi) {
1343 VP9_COMMON *const cm = &cpi->common;
1346 RATE_CONTROL *const rc = &cpi->rc;
1361 void vp9_rc_postencode_update(VP9_COMP *cpi, uint64_t bytes_used) {
1362 const VP9_COMMON *const cm = &cpi->common;
1363 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
1364 RATE_CONTROL *const rc = &cpi->rc;
1371 vp9_rc_update_rate_correction_factors(cpi);
1378 if (cpi->use_svc) {
1380 SVC *svc = &cpi->svc;
1391 if ((cpi->use_svc && oxcf->rc_mode == VPX_CBR) ||
1393 !(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame))) {
1414 (cpi->refresh_alt_ref_frame ||
1415 (cpi->refresh_golden_frame && !rc->is_src_frame_alt_ref)))) {
1420 update_buffer_level(cpi, rc->projected_frame_size);
1441 if (!cpi->use_svc || is_two_pass_svc(cpi)) {
1442 if (is_altref_enabled(cpi) && cpi->refresh_alt_ref_frame &&
1445 update_alt_ref_frame_stats(cpi);
1448 update_golden_frame_stats(cpi);
1459 cpi->resize_pending =
1465 if (cm->frame_type != KEY_FRAME) compute_frame_low_motion(cpi);
1469 void vp9_rc_postencode_update_drop_frame(VP9_COMP *cpi) {
1471 update_buffer_level(cpi, 0);
1472 cpi->rc.frames_since_key++;
1473 cpi->rc.frames_to_key--;
1474 cpi->rc.rc_2_frame = 0;
1475 cpi->rc.rc_1_frame = 0;
1478 static int calc_pframe_target_size_one_pass_vbr(const VP9_COMP *const cpi) {
1479 const RATE_CONTROL *const rc = &cpi->rc;
1483 (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame))
1488 return vp9_rc_clamp_pframe_target_size(cpi, target);
1491 static int calc_iframe_target_size_one_pass_vbr(const VP9_COMP *const cpi) {
1493 const RATE_CONTROL *rc = &cpi->rc;
1495 return vp9_rc_clamp_iframe_target_size(cpi, target);
1498 static void adjust_gfint_frame_constraint(VP9_COMP *cpi, int frame_constraint) {
1499 RATE_CONTROL *const rc = &cpi->rc;
1517 void vp9_rc_get_one_pass_vbr_params(VP9_COMP *cpi) {
1518 VP9_COMMON *const cm = &cpi->common;
1519 RATE_CONTROL *const rc = &cpi->rc;
1522 if (!cpi->refresh_alt_ref_frame &&
1523 (cm->current_video_frame == 0 || (cpi->frame_flags & FRAMEFLAGS_KEY) ||
1524 rc->frames_to_key == 0 || (cpi->oxcf.auto_key && 0))) {
1528 rc->frames_to_key = cpi->oxcf.key_freq;
1537 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cpi->oxcf.pass == 0) {
1538 vp9_cyclic_refresh_set_golden_update(cpi);
1563 adjust_gfint_frame_constraint(cpi, rc->frames_to_key);
1565 cpi->refresh_golden_frame = 1;
1569 if (cpi->oxcf.enable_auto_arf) {
1576 target = calc_iframe_target_size_one_pass_vbr(cpi);
1578 target = calc_pframe_target_size_one_pass_vbr(cpi);
1579 vp9_rc_set_frame_target(cpi, target);
1580 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cpi->oxcf.pass == 0)
1581 vp9_cyclic_refresh_update_parameters(cpi);
1584 static int calc_pframe_target_size_one_pass_cbr(const VP9_COMP *cpi) {
1585 const VP9EncoderConfig *oxcf = &cpi->oxcf;
1586 const RATE_CONTROL *rc = &cpi->rc;
1587 const SVC *const svc = &cpi->svc;
1596 target = cpi->refresh_golden_frame
1605 if (is_one_pass_cbr_svc(cpi)) {
1633 static int calc_iframe_target_size_one_pass_cbr(const VP9_COMP *cpi) {
1634 const RATE_CONTROL *rc = &cpi->rc;
1635 const VP9EncoderConfig *oxcf = &cpi->oxcf;
1636 const SVC *const svc = &cpi->svc;
1638 if (cpi->common.current_video_frame == 0) {
1644 double framerate = cpi->framerate;
1659 return vp9_rc_clamp_iframe_target_size(cpi, target);
1662 void vp9_rc_get_svc_params(VP9_COMP *cpi) {
1663 VP9_COMMON *const cm = &cpi->common;
1664 RATE_CONTROL *const rc = &cpi->rc;
1667 LAYER_IDS_TO_IDX(cpi->svc.spatial_layer_id, cpi->svc.temporal_layer_id,
1668 cpi->svc.number_temporal_layers);
1671 if ((cm->current_video_frame == 0) || (cpi->frame_flags & FRAMEFLAGS_KEY) ||
1672 (cpi->oxcf.auto_key &&
1673 (cpi->svc.current_superframe % cpi->oxcf.key_freq == 0) &&
1674 cpi->svc.spatial_layer_id == 0)) {
1677 if (is_two_pass_svc(cpi)) {
1678 cpi->svc.layer_context[layer].is_key_frame = 1;
1679 cpi->ref_frame_flags &= (~VP9_LAST_FLAG & ~VP9_GOLD_FLAG & ~VP9_ALT_FLAG);
1680 } else if (is_one_pass_cbr_svc(cpi)) {
1681 if (cm->current_video_frame > 0) vp9_svc_reset_key_frame(cpi);
1682 layer = LAYER_IDS_TO_IDX(cpi->svc.spatial_layer_id,
1683 cpi->svc.temporal_layer_id,
1684 cpi->svc.number_temporal_layers);
1685 cpi->svc.layer_context[layer].is_key_frame = 1;
1686 cpi->ref_frame_flags &= (~VP9_LAST_FLAG & ~VP9_GOLD_FLAG & ~VP9_ALT_FLAG);
1689 target = calc_iframe_target_size_one_pass_cbr(cpi);
1693 if (is_two_pass_svc(cpi)) {
1694 LAYER_CONTEXT *lc = &cpi->svc.layer_context[layer];
1695 if (cpi->svc.spatial_layer_id == 0) {
1699 cpi->svc.layer_context[cpi->svc.temporal_layer_id].is_key_frame;
1700 if (lc->is_key_frame) cpi->ref_frame_flags &= (~VP9_LAST_FLAG);
1702 cpi->ref_frame_flags &= (~VP9_ALT_FLAG);
1703 } else if (is_one_pass_cbr_svc(cpi)) {
1704 LAYER_CONTEXT *lc = &cpi->svc.layer_context[layer];
1705 if (cpi->svc.spatial_layer_id == cpi->svc.first_spatial_layer_to_encode) {
1709 cpi->svc.layer_context[cpi->svc.temporal_layer_id].is_key_frame;
1711 target = calc_pframe_target_size_one_pass_cbr(cpi);
1717 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
1718 vp9_cyclic_refresh_update_parameters(cpi);
1720 vp9_rc_set_frame_target(cpi, target);
1725 void vp9_rc_get_one_pass_cbr_params(VP9_COMP *cpi) {
1726 VP9_COMMON *const cm = &cpi->common;
1727 RATE_CONTROL *const rc = &cpi->rc;
1730 if ((cm->current_video_frame == 0 || (cpi->frame_flags & FRAMEFLAGS_KEY) ||
1731 rc->frames_to_key == 0 || (cpi->oxcf.auto_key && 0))) {
1735 rc->frames_to_key = cpi->oxcf.key_freq;
1742 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
1743 vp9_cyclic_refresh_set_golden_update(cpi);
1751 cpi->refresh_golden_frame = 1;
1757 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ)
1758 vp9_cyclic_refresh_update_parameters(cpi);
1761 target = calc_iframe_target_size_one_pass_cbr(cpi);
1763 target = calc_pframe_target_size_one_pass_cbr(cpi);
1765 vp9_rc_set_frame_target(cpi, target);
1766 if (cpi->oxcf.resize_mode == RESIZE_DYNAMIC)
1767 cpi->resize_pending = vp9_resize_one_pass_cbr(cpi);
1769 cpi->resize_pending = 0;
1817 void vp9_rc_set_gf_interval_range(const VP9_COMP *const cpi,
1819 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
1832 oxcf->width, oxcf->height, cpi->framerate);
1835 cpi->framerate, rc->min_gf_interval);
1840 if (is_altref_enabled(cpi)) {
1853 void vp9_rc_update_framerate(VP9_COMP *cpi) {
1854 const VP9_COMMON *const cm = &cpi->common;
1855 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
1856 RATE_CONTROL *const rc = &cpi->rc;
1859 rc->avg_frame_bandwidth = (int)(oxcf->target_bandwidth / cpi->framerate);
1879 vp9_rc_set_gf_interval_range(cpi, rc);
1884 static void vbr_rate_correction(VP9_COMP *cpi, int *this_frame_target) {
1885 RATE_CONTROL *const rc = &cpi->rc;
1888 int frame_window = VPXMIN(16, ((int)cpi->twopass.total_stats.count -
1889 cpi->common.current_video_frame));
1914 if (!frame_is_kf_gf_arf(cpi) && !rc->is_src_frame_alt_ref &&
1927 void vp9_set_target_rate(VP9_COMP *cpi) {
1928 RATE_CONTROL *const rc = &cpi->rc;
1931 if (cpi->common.frame_type == KEY_FRAME)
1932 target_rate = vp9_rc_clamp_iframe_target_size(cpi, target_rate);
1934 target_rate = vp9_rc_clamp_pframe_target_size(cpi, target_rate);
1937 if (cpi->oxcf.rc_mode == VPX_VBR || cpi->oxcf.rc_mode == VPX_CQ)
1938 vbr_rate_correction(cpi, &target_rate);
1939 vp9_rc_set_frame_target(cpi, target_rate);
1944 int vp9_resize_one_pass_cbr(VP9_COMP *cpi) {
1945 const VP9_COMMON *const cm = &cpi->common;
1946 RATE_CONTROL *const rc = &cpi->rc;
1953 cpi->resize_scale_num = 1;
1954 cpi->resize_scale_den = 1;
1957 cpi->resize_avg_qp = 0;
1958 cpi->resize_count = 0;
1967 if (cpi->resize_state == ORIG &&
1970 else if (cpi->resize_state == THREE_QUARTER &&
1971 ((cpi->oxcf.width >> 1) < min_width ||
1972 (cpi->oxcf.height >> 1) < min_height))
1978 if (cpi->oxcf.noise_sensitivity > 0) {
1986 if (cpi->rc.frames_since_key > 2 * cpi->framerate) {
1987 const int window = (int)(4 * cpi->framerate);
1988 cpi->resize_avg_qp += cm->base_qindex;
1989 if (cpi->rc.buffer_level < (int)(30 * rc->optimal_buffer_level / 100))
1990 ++cpi->resize_buffer_underflow;
1991 ++cpi->resize_count;
1993 if (cpi->resize_count >= window) {
1994 int avg_qp = cpi->resize_avg_qp / cpi->resize_count;
2000 if (cpi->resize_buffer_underflow > (cpi->resize_count >> 2)) {
2001 if (cpi->resize_state == THREE_QUARTER && down_size_on) {
2003 cpi->resize_state = ONE_HALF;
2004 } else if (cpi->resize_state == ORIG) {
2006 cpi->resize_state = ONEHALFONLY_RESIZE ? ONE_HALF : THREE_QUARTER;
2008 } else if (cpi->resize_state != ORIG &&
2009 avg_qp < avg_qp_thr1 * cpi->rc.worst_quality / 100) {
2010 if (cpi->resize_state == THREE_QUARTER ||
2011 avg_qp < avg_qp_thr2 * cpi->rc.worst_quality / 100 ||
2014 cpi->resize_state = ORIG;
2015 } else if (cpi->resize_state == ONE_HALF) {
2017 cpi->resize_state = THREE_QUARTER;
2021 cpi->resize_avg_qp = 0;
2022 cpi->resize_count = 0;
2023 cpi->resize_buffer_underflow = 0;
2034 cpi->resize_scale_num = 3;
2035 cpi->resize_scale_den = 4;
2037 cpi->resize_scale_num = 1;
2038 cpi->resize_scale_den = 2;
2040 cpi->resize_scale_num = 1;
2041 cpi->resize_scale_den = 1;
2043 tot_scale_change = (cpi->resize_scale_den * cpi->resize_scale_den) /
2044 (cpi->resize_scale_num * cpi->resize_scale_num);
2048 rc->this_frame_target = calc_pframe_target_size_one_pass_cbr(cpi);
2054 active_worst_quality = calc_active_worst_quality_one_pass_cbr(cpi);
2055 qindex = vp9_rc_regulate_q(cpi, target_bits_per_frame, rc->best_quality,
2060 if (resize_action > 0 && qindex > 90 * cpi->rc.worst_quality / 100) {
2073 void adjust_gf_boost_lag_one_pass_vbr(VP9_COMP *cpi, uint64_t avg_sad_current) {
2074 VP9_COMMON *const cm = &cpi->common;
2075 RATE_CONTROL *const rc = &cpi->rc;
2091 int tot_frames = (int)vp9_lookahead_depth(cpi->lookahead) - 1;
2136 if (cpi->refresh_golden_frame == 1 && cm->current_video_frame > 30 &&
2137 cpi->oxcf.lag_in_frames > 8) {
2158 if (rc->baseline_gf_interval > cpi->oxcf.lag_in_frames - 1)
2159 rc->baseline_gf_interval = cpi->oxcf.lag_in_frames - 1;
2168 adjust_gfint_frame_constraint(cpi, frame_constraint);
2189 if (cpi->oxcf.enable_auto_arf) {
2207 target = calc_pframe_target_size_one_pass_vbr(cpi);
2208 vp9_rc_set_frame_target(cpi, target);
2218 void vp9_scene_detection_onepass(VP9_COMP *cpi) {
2219 VP9_COMMON *const cm = &cpi->common;
2220 RATE_CONTROL *const rc = &cpi->rc;
2225 if (cpi->Last_Source != NULL &&
2226 cpi->Last_Source->y_width == cpi->Source->y_width &&
2227 cpi->Last_Source->y_height == cpi->Source->y_height) {
2229 uint8_t *src_y = cpi->Source->y_buffer;
2230 int src_ystride = cpi->Source->y_stride;
2231 uint8_t *last_src_y = cpi->Last_Source->y_buffer;
2232 int last_src_ystride = cpi->Last_Source->y_stride;
2239 if (cpi->oxcf.rc_mode == VPX_VBR) {
2243 if (cpi->oxcf.lag_in_frames > 0) {
2245 ? (int)vp9_lookahead_depth(cpi->lookahead) - 1
2247 start_frame = (int)vp9_lookahead_depth(cpi->lookahead) - 1;
2252 vp9_lookahead_peek(cpi->lookahead, lagframe_idx);
2262 cm->current_video_frame > (unsigned int)cpi->oxcf.lag_in_frames)
2271 for (frame = 1; frame < cpi->oxcf.lag_in_frames - 1; ++frame)
2275 if (cpi->oxcf.lag_in_frames == 0 ||
2281 (cpi->oxcf.lag_in_frames == 0) ? 0 : start_frame - frame + 1;
2289 if (cpi->oxcf.lag_in_frames > 0) {
2302 tmp_sad = cpi->fn_ptr[bsize].sdf(src_y, src_ystride, last_src_y,
2326 if (avg_sad > 0 || cpi->oxcf.rc_mode == VPX_CBR)
2334 if (cpi->oxcf.rc_mode == VPX_VBR && cm->frame_type != KEY_FRAME &&
2337 cpi->ext_refresh_frame_flags_pending == 0) {
2339 cpi->refresh_golden_frame = 1;
2342 if (cpi->oxcf.enable_auto_arf) rc->source_alt_ref_pending = 1;
2347 adjust_gfint_frame_constraint(cpi, rc->frames_to_key);
2349 target = calc_pframe_target_size_one_pass_vbr(cpi);
2350 vp9_rc_set_frame_target(cpi, target);
2356 if (cpi->oxcf.lag_in_frames > 0)
2357 adjust_gf_boost_lag_one_pass_vbr(cpi, avg_sad_current);
2363 int vp9_encodedframe_overshoot(VP9_COMP *cpi, int frame_size, int *q) {
2364 VP9_COMMON *const cm = &cpi->common;
2365 RATE_CONTROL *const rc = &cpi->rc;
2370 cpi->rc.rate_correction_factors[INTER_NORMAL];
2371 const int target_size = cpi->rc.avg_frame_bandwidth;
2377 *q = cpi->rc.worst_quality;
2382 cpi->rc.avg_frame_qindex[INTER_FRAME] = *q;
2386 cpi->rc.rc_1_frame = 0;
2387 cpi->rc.rc_2_frame = 0;
2402 cpi->rc.rate_correction_factors[INTER_NORMAL] = rate_correction_factor;
2406 if (cpi->use_svc) {
2408 SVC *svc = &cpi->svc;