ref: bd3088fd5664e00ceb6a22fd2b3ad06357cbcda4
parent: db2056f341e86218d3f7387023dc3b2d57258e8d
author: Marco <[email protected]>
date: Mon Sep 28 04:31:06 EDT 2015
VP8: Update rate correction factor for drop_overshoot feature. Update rate correction factor when we drop the frame due to overshoot. Only affects when the drop_overshoot feature is on: screen_content_mode = 2. Change-Id: I67e24de979b4c74744151d2ceb3cd75fec2a1e7a
--- a/vp8/encoder/ratectrl.c
+++ b/vp8/encoder/ratectrl.c
@@ -1593,15 +1593,38 @@
if (Q < thresh_qp &&
cpi->projected_frame_size > thresh_rate &&
pred_err_mb > thresh_pred_err_mb) {
+ double new_correction_factor = cpi->rate_correction_factor;
+ const int target_size = cpi->av_per_frame_bandwidth;
+ int target_bits_per_mb;
// Drop this frame: advance frame counters, and set force_maxqp flag.
cpi->common.current_video_frame++;
cpi->frames_since_key++;
- // Adjust rate correction factor upwards.
- cpi->rate_correction_factor *= 2.0;
- if (cpi->rate_correction_factor > MAX_BPB_FACTOR)
- cpi->rate_correction_factor = MAX_BPB_FACTOR;
// Flag to indicate we will force next frame to be encoded at max QP.
cpi->force_maxqp = 1;
+ // Reset the buffer levels.
+ cpi->buffer_level = cpi->oxcf.optimal_buffer_level;
+ cpi->bits_off_target = cpi->oxcf.optimal_buffer_level;
+ // Compute a new rate correction factor, corresponding to the current
+ // target frame size and max_QP, and adjust the rate correction factor
+ // upwards, if needed.
+ // This is to prevent a bad state where the re-encoded frame at max_QP
+ // undershoots significantly, and then we end up dropping every other
+ // frame because the QP/rate_correction_factor may have been too low
+ // before the drop and then takes too long to come up.
+ if (target_size >= (INT_MAX >> BPER_MB_NORMBITS))
+ target_bits_per_mb =
+ (target_size / cpi->common.MBs) << BPER_MB_NORMBITS;
+ else
+ target_bits_per_mb =
+ (target_size << BPER_MB_NORMBITS) / cpi->common.MBs;
+ // Rate correction factor based on target_size_per_mb and max_QP.
+ new_correction_factor = (double)target_bits_per_mb /
+ (double)vp8_bits_per_mb[INTER_FRAME][cpi->worst_quality];
+ if (new_correction_factor > cpi->rate_correction_factor)
+ cpi->rate_correction_factor =
+ VPXMIN(2.0 * cpi->rate_correction_factor, new_correction_factor);
+ if (cpi->rate_correction_factor > MAX_BPB_FACTOR)
+ cpi->rate_correction_factor = MAX_BPB_FACTOR;
return 1;
} else {
cpi->force_maxqp = 0;