diff options
author | Paul Wilkins <paulwilkins@google.com> | 2013-02-25 12:49:54 -0800 |
---|---|---|
committer | Gerrit Code Review <gerrit@gerrit.golo.chromium.org> | 2013-02-25 12:49:54 -0800 |
commit | 0e36158c7064db3410bf269df14d7bbd9f6d8492 (patch) | |
tree | f669eb0f10f847f8ac27797389f4431b26dfcdf2 /vp9/encoder/vp9_ratectrl.c | |
parent | 77a3becf92b6385ce7e2ffcf636c9cc373d8760c (diff) | |
parent | 97da8b8c3395ba3de5e13b8d77a8432b9a462b78 (diff) | |
download | libvpx-0e36158c7064db3410bf269df14d7bbd9f6d8492.tar libvpx-0e36158c7064db3410bf269df14d7bbd9f6d8492.tar.gz libvpx-0e36158c7064db3410bf269df14d7bbd9f6d8492.tar.bz2 libvpx-0e36158c7064db3410bf269df14d7bbd9f6d8492.zip |
Merge "Minor rate control refactoring and experiments." into experimental
Diffstat (limited to 'vp9/encoder/vp9_ratectrl.c')
-rw-r--r-- | vp9/encoder/vp9_ratectrl.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/vp9/encoder/vp9_ratectrl.c b/vp9/encoder/vp9_ratectrl.c index 53d931c9b..a2a79574d 100644 --- a/vp9/encoder/vp9_ratectrl.c +++ b/vp9/encoder/vp9_ratectrl.c @@ -114,13 +114,19 @@ static int kfboost_qadjust(int qindex) { return retval; } -int vp9_bits_per_mb(FRAME_TYPE frame_type, int qindex) { - if (frame_type == KEY_FRAME) - return (int)(4500000 / vp9_convert_qindex_to_q(qindex)); - else - return (int)(2850000 / vp9_convert_qindex_to_q(qindex)); -} +int vp9_bits_per_mb(FRAME_TYPE frame_type, int qindex, + double correction_factor) { + int enumerator; + double q = vp9_convert_qindex_to_q(qindex); + + if (frame_type == KEY_FRAME) { + enumerator = 4500000; + } else { + enumerator = 2850000; + } + return (int)(0.5 + (enumerator * correction_factor / q)); +} void vp9_save_coding_context(VP9_COMP *cpi) { CODING_CONTEXT *const cc = &cpi->coding_context; @@ -259,7 +265,7 @@ void vp9_setup_inter_frame(VP9_COMP *cpi) { static int estimate_bits_at_q(int frame_kind, int Q, int MBs, double correction_factor) { - int Bpm = (int)(.5 + correction_factor * vp9_bits_per_mb(frame_kind, Q)); + int Bpm = (int)(vp9_bits_per_mb(frame_kind, Q, correction_factor)); /* Attempt to retain reasonable accuracy without overflow. The cutoff is * chosen such that the maximum product of Bpm and MBs fits 31 bits. The @@ -397,12 +403,12 @@ void vp9_update_rate_correction_factors(VP9_COMP *cpi, int damp_var) { rate_correction_factor = cpi->rate_correction_factor; } - // Work out how big we would have expected the frame to be at this Q given the current correction factor. + // Work out how big we would have expected the frame to be at this Q given + // the current correction factor. // Stay in double to avoid int overflow when values are large projected_size_based_on_q = - (int)(((.5 + rate_correction_factor * - vp9_bits_per_mb(cpi->common.frame_type, Q)) * - cpi->common.MBs) / (1 << BPER_MB_NORMBITS)); + estimate_bits_at_q(cpi->common.frame_type, Q, + cpi->common.MBs, rate_correction_factor); // Work out a size correction factor. // if ( cpi->this_frame_target > 0 ) @@ -485,8 +491,7 @@ int vp9_regulate_q(VP9_COMP *cpi, int target_bits_per_frame) { do { bits_per_mb_at_this_q = - (int)(.5 + correction_factor * - vp9_bits_per_mb(cpi->common.frame_type, i)); + (int)(vp9_bits_per_mb(cpi->common.frame_type, i, correction_factor)); if (bits_per_mb_at_this_q <= target_bits_per_mb) { if ((target_bits_per_mb - bits_per_mb_at_this_q) <= last_error) |