Bug 1310206 - Uplift a few cubeb one-liners to beta. r=jesup a=ritu
☠☠ backed out by d025e0641d9e ☠ ☠
authorPaul Adenot <paul@paul.cx>
Tue, 18 Oct 2016 14:18:27 +0200
changeset 350710 3c7b927f4b0bc5fad60390b4fa7d27a05f9f2f1e
parent 350709 42362b3185baaa3c0d82c481f5facd031c7ee993
child 350711 fa324ad9a0cb9bc27a2509aef5d220ae46338b8d
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup, ritu
bugs1310206
milestone50.0
Bug 1310206 - Uplift a few cubeb one-liners to beta. r=jesup a=ritu MozReview-Commit-ID: AqWuE5jW5rD
media/libcubeb/src/cubeb_resampler.cpp
media/libcubeb/src/cubeb_resampler_internal.h
media/libcubeb/src/cubeb_wasapi.cpp
--- a/media/libcubeb/src/cubeb_resampler.cpp
+++ b/media/libcubeb/src/cubeb_resampler.cpp
@@ -1,14 +1,19 @@
 /*
  * Copyright © 2014 Mozilla Foundation
  *
  * This program is made available under an ISC-style license.  See the
  * accompanying file LICENSE for details.
  */
+
+#ifndef NOMINMAX
+#define NOMINMAX
+#endif // NOMINMAX
+
 #include <algorithm>
 #include <cmath>
 #include <cassert>
 #include <cstring>
 #include <cstddef>
 #include <cstdio>
 #if defined(HAVE_CONFIG_H)
 #include "config.h"
--- a/media/libcubeb/src/cubeb_resampler_internal.h
+++ b/media/libcubeb/src/cubeb_resampler_internal.h
@@ -258,17 +258,17 @@ 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()))
+    return (uint32_t)roundf((output_frame_count - samples_to_frames(resampling_out_buffer.length()))
                           * resampling_ratio);
 
   }
 
   /** 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.
--- a/media/libcubeb/src/cubeb_wasapi.cpp
+++ b/media/libcubeb/src/cubeb_wasapi.cpp
@@ -608,17 +608,17 @@ bool get_input_buffer(cubeb_stream * stm
   assert(stm->linear_input_buffer.length() >= total_available_input &&
          offset == total_available_input);
 
   return true;
 }
 
 /* Get an output buffer from the render_client. It has to be released before
  * exiting the callback. */
-bool get_output_buffer(cubeb_stream * stm, size_t max_frames, float *& buffer, size_t & frame_count)
+bool get_output_buffer(cubeb_stream * stm, float *& buffer, size_t & frame_count)
 {
   UINT32 padding_out;
   HRESULT hr;
 
   XASSERT(has_output(stm));
 
   hr = stm->output_client->GetCurrentPadding(&padding_out);
   if (FAILED(hr)) {
@@ -630,17 +630,17 @@ bool get_output_buffer(cubeb_stream * st
   if (stm->draining) {
     if (padding_out == 0) {
       stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_DRAINED);
       return false;
     }
     return true;
   }
 
-  frame_count = std::min<size_t>(max_frames, stm->output_buffer_frame_count - padding_out);
+  frame_count = stm->output_buffer_frame_count - padding_out;
   BYTE * output_buffer;
 
   hr = stm->render_client->GetBuffer(frame_count, &output_buffer);
   if (FAILED(hr)) {
     LOG("cannot get render buffer\n");
     return false;
   }
 
@@ -668,31 +668,31 @@ refill_callback_duplex(cubeb_stream * st
     return rv;
   }
 
   input_frames = stm->linear_input_buffer.length() / stm->input_stream_params.channels;
   if (!input_frames) {
     return true;
   }
 
-  rv = get_output_buffer(stm, input_frames, output_buffer, output_frames);
+  rv = get_output_buffer(stm, output_buffer, output_frames);
   if (!rv) {
     hr = stm->render_client->ReleaseBuffer(output_frames, 0);
     return rv;
   }
 
   /* 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(input_frames) / 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(),
@@ -740,18 +740,17 @@ refill_callback_output(cubeb_stream * st
 {
   bool rv;
   HRESULT hr;
   float * output_buffer = nullptr;
   size_t output_frames = 0;
 
   XASSERT(!has_input(stm) && has_output(stm));
 
-  rv = get_output_buffer(stm, std::numeric_limits<size_t>::max(),
-                         output_buffer, output_frames);
+  rv = get_output_buffer(stm, output_buffer, output_frames);
   if (!rv) {
     return rv;
   }
 
   if (stm->draining || output_frames == 0) {
     return true;
   }