Commit 8f684689 authored by Yaowu Xu's avatar Yaowu Xu Committed by Gerrit Code Review
Browse files

Merge "Replace imprecise 32 bits calculations by 64 bits calculations"

parents 2914bcfd 0ec5919d
...@@ -917,9 +917,7 @@ int vp9_twopass_worst_quality(VP9_COMP *cpi, FIRSTPASS_STATS *fpstats, ...@@ -917,9 +917,7 @@ int vp9_twopass_worst_quality(VP9_COMP *cpi, FIRSTPASS_STATS *fpstats,
return rc->worst_quality; // Highest value allowed return rc->worst_quality; // Highest value allowed
target_norm_bits_per_mb = target_norm_bits_per_mb =
section_target_bandwitdh < (1 << 20) ((uint64_t)section_target_bandwitdh << BPER_MB_NORMBITS) / num_mbs;
? (section_target_bandwitdh << BPER_MB_NORMBITS) / num_mbs
: (section_target_bandwitdh / num_mbs) << BPER_MB_NORMBITS;
// Try and pick a max Q that will be high enough to encode the // Try and pick a max Q that will be high enough to encode the
// content at the given rate. // content at the given rate.
......
...@@ -107,11 +107,7 @@ static int estimate_bits_at_q(int frame_kind, int q, int mbs, ...@@ -107,11 +107,7 @@ static int estimate_bits_at_q(int frame_kind, int q, int mbs,
double correction_factor) { double correction_factor) {
const int bpm = (int)(vp9_rc_bits_per_mb(frame_kind, q, correction_factor)); const int bpm = (int)(vp9_rc_bits_per_mb(frame_kind, q, correction_factor));
// Attempt to retain reasonable accuracy without overflow. The cutoff is return ((uint64_t)bpm * mbs) >> BPER_MB_NORMBITS;
// chosen such that the maximum product of Bpm and MBs fits 31 bits. The
// largest Bpm takes 20 bits.
return (mbs > (1 << 11)) ? (bpm >> BPER_MB_NORMBITS) * mbs
: (bpm * mbs) >> BPER_MB_NORMBITS;
} }
int vp9_rc_clamp_pframe_target_size(const VP9_COMP *const cpi, int target) { int vp9_rc_clamp_pframe_target_size(const VP9_COMP *const cpi, int target) {
...@@ -323,11 +319,8 @@ int vp9_rc_regulate_q(const VP9_COMP *cpi, int target_bits_per_frame, ...@@ -323,11 +319,8 @@ int vp9_rc_regulate_q(const VP9_COMP *cpi, int target_bits_per_frame,
// Calculate required scaling factor based on target frame size and size of // Calculate required scaling factor based on target frame size and size of
// frame produced using previous Q. // frame produced using previous Q.
if (target_bits_per_frame >= (INT_MAX >> BPER_MB_NORMBITS)) target_bits_per_mb =
// Case where we would overflow int ((uint64_t)target_bits_per_frame << BPER_MB_NORMBITS) / cm->MBs;
target_bits_per_mb = (target_bits_per_frame / cm->MBs) << BPER_MB_NORMBITS;
else
target_bits_per_mb = (target_bits_per_frame << BPER_MB_NORMBITS) / cm->MBs;
i = active_best_quality; i = active_best_quality;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment