Bug 1310224 - Cherry-pick 46d12e9a from cubeb. r=kinetik, a=gchang
authorPaul Adenot <paul@paul.cx>
Thu, 17 Nov 2016 12:06:47 +0100
changeset 352606 ffba3e01b09120519e3f4b9011d9e8f9456c4024
parent 352605 7b1a218bce5c9f89407575886cc84e1c62d3cdf3
child 352607 7a0a906b9680cd0717436c74d5ed3d33e68745d0
push id6795
push userjlund@mozilla.com
push dateMon, 23 Jan 2017 14:19:46 +0000
treeherdermozilla-esr52@76101b503191 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik, gchang
bugs1310224
milestone52.0a2
Bug 1310224 - Cherry-pick 46d12e9a from cubeb. r=kinetik, a=gchang
media/libcubeb/src/cubeb_resampler_internal.h
media/libcubeb/unresampled-frames.patch
media/libcubeb/update.sh
--- a/media/libcubeb/src/cubeb_resampler_internal.h
+++ b/media/libcubeb/src/cubeb_resampler_internal.h
@@ -258,19 +258,25 @@ public:
   }
 
   /** Returns the number of frames to pass in the input of the resampler to have
    * exactly `output_frame_count` resampled frames. This can return a number
    * slightly bigger than what is strictly necessary, but it guaranteed that the
    * number of output frames will be exactly equal. */
   uint32_t input_needed_for_output(uint32_t output_frame_count)
   {
-    return (uint32_t)ceilf((output_frame_count - samples_to_frames(resampling_out_buffer.length()))
-                           * resampling_ratio);
-
+    int32_t unresampled_frames_left = samples_to_frames(resampling_in_buffer.length());
+    int32_t resampled_frames_left = samples_to_frames(resampling_out_buffer.length());
+    float input_frames_needed =
+      (output_frame_count - unresampled_frames_left) * resampling_ratio
+        - resampled_frames_left;
+    if (input_frames_needed < 0) {
+      return 0;
+    }
+    return (uint32_t)ceilf(input_frames_needed);
   }
 
   /** Returns a pointer to the input buffer, that contains empty space for at
    * least `frame_count` elements. This is useful so that consumer can directly
    * write into the input buffer of the resampler. The pointer returned is
    * adjusted so that leftover data are not overwritten.
    */
   T * input_buffer(size_t frame_count)
new file mode 100644
--- /dev/null
+++ b/media/libcubeb/unresampled-frames.patch
@@ -0,0 +1,36 @@
+From 46d12e9ae6fa9c233bc32812b13185ee7df8d3fd Mon Sep 17 00:00:00 2001
+From: Paul Adenot <paul@paul.cx>
+Date: Thu, 10 Nov 2016 06:20:16 +0100
+Subject: [PATCH] Prevent underflowing the number of input frames needed in
+ input when resampling. (#188)
+
+---
+ src/cubeb_resampler_internal.h | 12 +++++++++---
+ 1 file changed, 9 insertions(+), 3 deletions(-)
+
+diff --git a/src/cubeb_resampler_internal.h b/src/cubeb_resampler_internal.h
+index e165cc2..3c37a04 100644
+--- a/src/cubeb_resampler_internal.h
++++ b/src/cubeb_resampler_internal.h
+@@ -263,9 +263,15 @@ public:
+    * number of output frames will be exactly equal. */
+   uint32_t input_needed_for_output(uint32_t output_frame_count)
+   {
+-    return (uint32_t)ceilf((output_frame_count - samples_to_frames(resampling_out_buffer.length()))
+-                           * resampling_ratio);
+-
++    int32_t unresampled_frames_left = samples_to_frames(resampling_in_buffer.length());
++    int32_t resampled_frames_left = samples_to_frames(resampling_out_buffer.length());
++    float input_frames_needed =
++      (output_frame_count - unresampled_frames_left) * resampling_ratio
++        - resampled_frames_left;
++    if (input_frames_needed < 0) {
++      return 0;
++    }
++    return (uint32_t)ceilf(input_frames_needed);
+   }
+ 
+   /** Returns a pointer to the input buffer, that contains empty space for at
+-- 
+2.7.4
+
--- a/media/libcubeb/update.sh
+++ b/media/libcubeb/update.sh
@@ -54,9 +54,12 @@ if [ -n "$rev" ]; then
   fi
   sed -i.bak -e "/The git commit ID used was/ s/[0-9a-f]\{40\}\(-dirty\)\{0,1\}\./$version./" README_MOZILLA
   rm README_MOZILLA.bak
 else
   echo "Remember to update README_MOZILLA with the version details."
 fi
 
 echo "Applying a patch on top of $version"
+patch -p1 < ./unresampled-frames.patch
+
+echo "Applying a patch on top of $version"
 patch -p1 < ./bug1302231_emergency_bailout.patch