Bug 1310224 - Cherry-pick 46d12e9a from cubeb. r=kinetik, a=jcristau
authorPaul Adenot <paul@paul.cx>
Thu, 17 Nov 2016 12:07:59 +0100
changeset 358937 ea95da0bb7ab5f8f9f9be6ce1920f56aa9dd3bf9
parent 358936 d2a50c565d374e36a219984c44081a528d4e26bd
child 358938 0d8d75042332b977ceebf846ed5edc1a1ed2d696
push id1324
push usermtabara@mozilla.com
push dateMon, 16 Jan 2017 13:07:44 +0000
treeherdermozilla-release@a01c49833940 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik, jcristau
bugs1310224
milestone51.0
Bug 1310224 - Cherry-pick 46d12e9a from cubeb. r=kinetik, a=jcristau MozReview-Commit-ID: D6wpucS71qh
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
@@ -69,9 +69,12 @@ echo "Applying another patch on top of $
 patch -p3 < ./bug1314496_allocator.patch
 echo "Applying another patch on top of $version"
 patch -p1 < ./bug1315495_wasapi_leak.patch
 echo "Applying another patch on top of $version"
 patch -p1 < ./bug1311911_logitech_delay.patch
 echo "Applying another patch on top of $version"
 patch -p1 < ./bug1306247_crash_fix.patch
 echo "Applying another patch on top of $version"
+patch -p1 < ./unresampled-frames.patch
+
+echo "Applying another patch on top of $version"
 patch -p1 < ./bug1302231_emergency_bailout.patch