b=938450 process all input samples in decodeAudioData r=padenot
authorKarl Tomlinson <karlt+@karlt.net>
Tue, 03 Dec 2013 12:09:01 +1300
changeset 174185 9ba0897b47f9d2e6e72c24137053db242175e7dd
parent 174184 c995ea111b8bfd474d28210a76f9fc9fcaf446f4
child 174186 8a57fd3a56a978930c41474673674ef1dede75db
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs938450
milestone28.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=938450 process all input samples in decodeAudioData r=padenot
content/media/webaudio/MediaBufferDecoder.cpp
--- a/content/media/webaudio/MediaBufferDecoder.cpp
+++ b/content/media/webaudio/MediaBufferDecoder.cpp
@@ -341,64 +341,62 @@ MediaDecodeTask::Decode()
 
   nsAutoPtr<AudioData> audioData;
   while ((audioData = audioQueue.PopFront())) {
     audioData->EnsureAudioBuffer(); // could lead to a copy :(
     AudioDataValue* bufferData = static_cast<AudioDataValue*>
       (audioData->mAudioBuffer->Data());
 
     if (sampleRate != destSampleRate) {
-      const uint32_t expectedOutSamples = static_cast<uint32_t>(
-          static_cast<uint64_t>(destSampleRate) *
-          static_cast<uint64_t>(audioData->mFrames) /
-          static_cast<uint64_t>(sampleRate)
-        );
+      const uint32_t maxOutSamples = resampledFrames - mDecodeJob.mWriteIndex;
 
       for (uint32_t i = 0; i < audioData->mChannels; ++i) {
         uint32_t inSamples = audioData->mFrames;
-        uint32_t outSamples = expectedOutSamples;
+        uint32_t outSamples = maxOutSamples;
 
         WebAudioUtils::SpeexResamplerProcess(
             resampler, i, &bufferData[i * audioData->mFrames], &inSamples,
             mDecodeJob.mChannelBuffers[i] + mDecodeJob.mWriteIndex,
             &outSamples);
 
         if (i == audioData->mChannels - 1) {
           mDecodeJob.mWriteIndex += outSamples;
           MOZ_ASSERT(mDecodeJob.mWriteIndex <= resampledFrames);
+          MOZ_ASSERT(inSamples == audioData->mFrames);
         }
       }
     } else {
       for (uint32_t i = 0; i < audioData->mChannels; ++i) {
         ConvertAudioSamples(&bufferData[i * audioData->mFrames],
                             mDecodeJob.mChannelBuffers[i] + mDecodeJob.mWriteIndex,
                             audioData->mFrames);
 
         if (i == audioData->mChannels - 1) {
           mDecodeJob.mWriteIndex += audioData->mFrames;
         }
       }
     }
   }
 
   if (sampleRate != destSampleRate) {
-    int inputLatency = speex_resampler_get_input_latency(resampler);
-    int outputLatency = speex_resampler_get_output_latency(resampler);
+    uint32_t inputLatency = speex_resampler_get_input_latency(resampler);
+    const uint32_t maxOutSamples = resampledFrames - mDecodeJob.mWriteIndex;
     for (uint32_t i = 0; i < channelCount; ++i) {
       uint32_t inSamples = inputLatency;
-      uint32_t outSamples = outputLatency;
+      uint32_t outSamples = maxOutSamples;
 
       WebAudioUtils::SpeexResamplerProcess(
           resampler, i, (AudioDataValue*)nullptr, &inSamples,
           mDecodeJob.mChannelBuffers[i] + mDecodeJob.mWriteIndex,
           &outSamples);
 
       if (i == channelCount - 1) {
         mDecodeJob.mWriteIndex += outSamples;
         MOZ_ASSERT(mDecodeJob.mWriteIndex <= resampledFrames);
+        MOZ_ASSERT(inSamples == inputLatency);
       }
     }
   }
 
   mPhase = PhaseEnum::AllocateBuffer;
   RunNextPhase();
 }