b=999267 ensure AudioSegment::Resample() processes all frames of each chunk r=padenot
authorKarl Tomlinson <karlt+@karlt.net>
Mon, 09 Jun 2014 12:11:08 +1200
changeset 207824 bd5d24cb324684d758706eadc74ba1f2bf52dae9
parent 207823 9305a8ec77fe3efc902b73c26807558151e23cdb
child 207825 5181e577261ef5204e36db3438bf58efd7c85903
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs999267
milestone32.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
b=999267 ensure AudioSegment::Resample() processes all frames of each chunk r=padenot
content/media/AudioSegment.h
--- a/content/media/AudioSegment.h
+++ b/content/media/AudioSegment.h
@@ -187,34 +187,39 @@ public:
       if (c.IsNull()) {
         c.mDuration *= aOutRate / aInRate;
         mDuration += c.mDuration;
         continue;
       }
       uint32_t channels = c.mChannelData.Length();
       output.SetLength(channels);
       bufferPtrs.SetLength(channels);
-      uint32_t inFrames = c.mDuration,
-      outFrames = c.mDuration * aOutRate / aInRate;
+      uint32_t inFrames = c.mDuration;
+      // Round up to allocate; the last frame may not be used.
+      NS_ASSERTION((UINT32_MAX - aInRate + 1) / c.mDuration >= aOutRate,
+                   "Dropping samples");
+      uint32_t outSize = (c.mDuration * aOutRate + aInRate - 1) / aInRate;
       for (uint32_t i = 0; i < channels; i++) {
         const T* in = static_cast<const T*>(c.mChannelData[i]);
-        T* out = output[i].AppendElements(outFrames);
+        T* out = output[i].AppendElements(outSize);
+        uint32_t outFrames = outSize;
 
         dom::WebAudioUtils::SpeexResamplerProcess(aResampler, i,
                                                   in, &inFrames,
                                                   out, &outFrames);
-
+        MOZ_ASSERT(inFrames == c.mDuration);
         bufferPtrs[i] = out;
         output[i].SetLength(outFrames);
       }
+      MOZ_ASSERT(channels > 0);
+      c.mDuration = output[0].Length();
       c.mBuffer = new mozilla::SharedChannelArrayBuffer<T>(&output);
       for (uint32_t i = 0; i < channels; i++) {
         c.mChannelData[i] = bufferPtrs[i];
       }
-      c.mDuration = outFrames;
       mDuration += c.mDuration;
     }
   }
 
   void ResampleChunks(SpeexResamplerState* aResampler);
 
   void AppendFrames(already_AddRefed<ThreadSharedObject> aBuffer,
                     const nsTArray<const float*>& aChannelData,