Bug 1136360 - Report actual number of frames written to ReleaseBuffer. r=jesup, a=ritu
authorMatthew Gregan <kinetik@flim.org>
Fri, 21 Aug 2015 18:09:34 +1200
changeset 288898 951ac09d3d3a4871da1f5f1c9955871c1cc0fabd
parent 288897 a524e8ce1debeed49614072256e6057205baea3d
child 288899 affe675fc3c62b88073aeaaf7ccb195a422b0411
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup, ritu
bugs1136360
milestone42.0a2
Bug 1136360 - Report actual number of frames written to ReleaseBuffer. r=jesup, a=ritu
media/libcubeb/src/cubeb_wasapi.cpp
--- a/media/libcubeb/src/cubeb_wasapi.cpp
+++ b/media/libcubeb/src/cubeb_wasapi.cpp
@@ -435,40 +435,37 @@ downmix(T * in, long inframes, T * out, 
  * before the eventual upmix occurs. */
 static size_t
 frames_to_bytes_before_mix(cubeb_stream * stm, size_t frames)
 {
   size_t stream_frame_size = stm->stream_params.channels * sizeof(float);
   return stream_frame_size * frames;
 }
 
-void
+long
 refill(cubeb_stream * stm, float * data, long frames_needed)
 {
   /* If we need to upmix after resampling, resample into the mix buffer to
    * avoid a copy. */
   float * dest;
   if (should_upmix(stm) || should_downmix(stm)) {
     dest = stm->mix_buffer;
   } else {
     dest = data;
   }
 
   long out_frames = cubeb_resampler_fill(stm->resampler, dest, frames_needed);
+  /* TODO: Report out_frames < 0 as an error via the API. */
+  XASSERT(out_frames >= 0);
 
   {
     auto_lock lock(stm->stream_reset_lock);
     stm->frames_written += out_frames;
   }
 
-  /* XXX: Handle this error. */
-  if (out_frames < 0) {
-    XASSERT(false);
-  }
-
   /* Go in draining mode if we got fewer frames than requested. */
   if (out_frames < frames_needed) {
     LOG("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. */
@@ -476,16 +473,18 @@ refill(cubeb_stream * stm, float * data,
 
   if (should_upmix(stm)) {
     upmix(dest, out_frames, data,
           stm->stream_params.channels, stm->mix_params.channels);
   } else if (should_downmix(stm)) {
     downmix(dest, out_frames, data,
             stm->stream_params.channels, stm->mix_params.channels);
   }
+
+  return out_frames;
 }
 
 static unsigned int __stdcall
 wasapi_stream_render_loop(LPVOID stream)
 {
   cubeb_stream * stm = static_cast<cubeb_stream *>(stream);
 
   bool is_playing = true;
@@ -577,19 +576,20 @@ wasapi_stream_render_loop(LPVOID stream)
 
       if (available == 0) {
         continue;
       }
 
       BYTE * data;
       hr = stm->render_client->GetBuffer(available, &data);
       if (SUCCEEDED(hr)) {
-        refill(stm, reinterpret_cast<float *>(data), available);
+        long wrote = refill(stm, reinterpret_cast<float *>(data), available);
+        XASSERT(wrote == available || stm->draining);
 
-        hr = stm->render_client->ReleaseBuffer(available, 0);
+        hr = stm->render_client->ReleaseBuffer(wrote, 0);
         if (FAILED(hr)) {
           LOG("failed to release buffer.\n");
           is_playing = false;
         }
       } else {
         LOG("failed to get buffer.\n");
         is_playing = false;
       }