shithub: libvpx

Download patch

ref: 8f68468917296320f2337bb8c8c4ae2de79e1817
parent: 2914bcfd9b95f04f51ac124316ccfdac2714b699
parent: 0ec5919d4202c6e99b31cf707c7125536498f1f4
author: Yaowu Xu <yaowu@google.com>
date: Tue Apr 8 03:14:21 EDT 2014

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

--- a/vp9/encoder/vp9_firstpass.c
+++ b/vp9/encoder/vp9_firstpass.c
@@ -917,9 +917,7 @@
     return rc->worst_quality;          // Highest value allowed
 
   target_norm_bits_per_mb =
-      section_target_bandwitdh < (1 << 20)
-      ? (section_target_bandwitdh << BPER_MB_NORMBITS) / num_mbs
-      : (section_target_bandwitdh / num_mbs) << BPER_MB_NORMBITS;
+      ((uint64_t)section_target_bandwitdh << BPER_MB_NORMBITS) / num_mbs;
 
   // Try and pick a max Q that will be high enough to encode the
   // content at the given rate.
--- a/vp9/encoder/vp9_ratectrl.c
+++ b/vp9/encoder/vp9_ratectrl.c
@@ -107,11 +107,7 @@
                               double 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
-  // 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;
+  return ((uint64_t)bpm * mbs) >> BPER_MB_NORMBITS;
 }
 
 int vp9_rc_clamp_pframe_target_size(const VP9_COMP *const cpi, int target) {
@@ -323,11 +319,8 @@
 
   // Calculate required scaling factor based on target frame size and size of
   // frame produced using previous Q.
-  if (target_bits_per_frame >= (INT_MAX >> BPER_MB_NORMBITS))
-    // Case where we would overflow int
-    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;
+    target_bits_per_mb =
+        ((uint64_t)target_bits_per_frame << BPER_MB_NORMBITS) / cm->MBs;
 
   i = active_best_quality;