Bug 1307724 - Cherry-pick cubeb revision 50d92c. r?kinetik draft
authorPaul Adenot <paul@paul.cx>
Wed, 05 Oct 2016 10:54:03 +0200
changeset 421102 52cf1ade92d26af4946bb1e504f4c22e7ee1c913
parent 420198 1858c9bbbc83b8c00b030e8111284f8074a400bf
child 532974 8646535ef69d506945a9f525054293fd6550d0e9
push id31382
push userpaul@paul.cx
push dateWed, 05 Oct 2016 08:54:27 +0000
reviewerskinetik
bugs1307724
milestone52.0a1
Bug 1307724 - Cherry-pick cubeb revision 50d92c. r?kinetik MozReview-Commit-ID: 2R5QrRB1hjH
media/libcubeb/src/cubeb_wasapi.cpp
media/libcubeb/update.sh
media/libcubeb/wasapi-stereo-mic.patch
--- a/media/libcubeb/src/cubeb_wasapi.cpp
+++ b/media/libcubeb/src/cubeb_wasapi.cpp
@@ -504,16 +504,17 @@ refill(cubeb_stream * stm, float * input
     LOG("start draining.\n");
     stm->draining = true;
   }
 
   /* If this is not true, there will be glitches.
      It is alright to have produced less frames if we are draining, though. */
   XASSERT(out_frames == output_frames_needed || stm->draining || !has_output(stm));
 
+
   if (has_output(stm)) {
     if (should_upmix(stm->output_stream_params, stm->output_mix_params)) {
       upmix(dest, out_frames, output_buffer,
             stm->output_stream_params.channels, stm->output_mix_params.channels);
     } else if (should_downmix(stm->output_stream_params, stm->output_mix_params)) {
       downmix(dest, out_frames, output_buffer,
               stm->output_stream_params.channels, stm->output_mix_params.channels);
     }
@@ -682,17 +683,17 @@ refill_callback_duplex(cubeb_stream * st
   /* This can only happen when debugging, and having breakpoints set in the
    * callback in a way that it makes the stream underrun. */
   if (output_frames == 0) {
     return true;
   }
 
   // When WASAPI has not filled the input buffer yet, send silence.
   double output_duration = double(output_frames) / stm->output_mix_params.rate;
-  double input_duration = double(stm->linear_input_buffer.length() / stm->input_mix_params.channels) / stm->input_mix_params.rate;
+  double input_duration = double(stm->linear_input_buffer.length() / stm->input_stream_params.channels) / stm->input_mix_params.rate;
   if (input_duration < output_duration) {
     size_t padding = size_t(round((output_duration - input_duration) * stm->input_mix_params.rate));
     LOG("padding silence: out=%f in=%f pad=%u\n", output_duration, input_duration, padding);
     stm->linear_input_buffer.push_front_silence(padding * stm->input_stream_params.channels);
   }
 
   refill(stm,
          stm->linear_input_buffer.data(),
--- a/media/libcubeb/update.sh
+++ b/media/libcubeb/update.sh
@@ -54,8 +54,10 @@ if [ -n "$rev" ]; then
   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 < ./wasapi-drift.patch
+echo "Applying another patch on top of $version"
+patch -p1 < ./wasapi-stereo-mic.patch
new file mode 100644
--- /dev/null
+++ b/media/libcubeb/wasapi-stereo-mic.patch
@@ -0,0 +1,28 @@
+From 50d92c0eaa05a93f4dd8ff5072e983c6c84d0369 Mon Sep 17 00:00:00 2001
+From: Paul Adenot <paul@paul.cx>
+Date: Tue, 4 Oct 2016 07:18:04 -0700
+Subject: [PATCH] Divide by the number of channel of the stream to compute the
+ duratio of the buffer.
+
+We downmix right before, so this is in frames in with the channel count of the
+stream, not the mix.
+---
+ src/cubeb_wasapi.cpp | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/cubeb_wasapi.cpp b/src/cubeb_wasapi.cpp
+index bd2cbed..87aa305 100644
+--- a/src/cubeb_wasapi.cpp
++++ b/src/cubeb_wasapi.cpp
+@@ -687,7 +687,7 @@ refill_callback_duplex(cubeb_stream * stm)
+ 
+   // When WASAPI has not filled the input buffer yet, send silence.
+   double output_duration = double(output_frames) / stm->output_mix_params.rate;
+-  double input_duration = double(stm->linear_input_buffer.length() / stm->input_mix_params.channels) / stm->input_mix_params.rate;
++  double input_duration = double(stm->linear_input_buffer.length() / stm->input_stream_params.channels) / stm->input_mix_params.rate;
+   if (input_duration < output_duration) {
+     size_t padding = size_t(round((output_duration - input_duration) * stm->input_mix_params.rate));
+     LOG("padding silence: out=%f in=%f pad=%u\n", output_duration, input_duration, padding);
+-- 
+2.7.4
+