Bug 1305826: P3. Only process the number of frames, do not rely on allocated size. r?gerald draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Sat, 01 Oct 2016 19:34:42 +1000
changeset 419873 0df267cd57c51d3b438fe11fb774b9d9c634220f
parent 419872 f4d27bc7e19995d330ed453cf5115880bec2d802
child 532668 fbce0eebe97cc405ff616e8f3eae38a3f130e560
push id31032
push userbmo:jyavenard@mozilla.com
push dateSat, 01 Oct 2016 09:38:22 +0000
reviewersgerald
bugs1305826
milestone52.0a1
Bug 1305826: P3. Only process the number of frames, do not rely on allocated size. r?gerald This is only for safeguarding, in case an audio buffer was over allocated. There should be none. But better be safe than sorry MozReview-Commit-ID: JszA8CqycTr
dom/media/mediasink/DecodedAudioDataSink.cpp
--- a/dom/media/mediasink/DecodedAudioDataSink.cpp
+++ b/dom/media/mediasink/DecodedAudioDataSink.cpp
@@ -462,18 +462,23 @@ DecodedAudioDataSink::NotifyAudioNeeded(
         PushProcessedAudio(silence);
       }
     }
 
     mLastEndTime = data->GetEndTime();
     mFramesParsed += data->mFrames;
 
     if (mConverter->InputConfig() != mConverter->OutputConfig()) {
+      // We must ensure that the size in the buffer contains exactly the number
+      // of frames, in case one of the audio producer over allocated the buffer.
+      AlignedAudioBuffer buffer(Move(data->mAudioData));
+      buffer.SetLength(size_t(data->mFrames) * data->mChannels);
+
       AlignedAudioBuffer convertedData =
-        mConverter->Process(AudioSampleBuffer(Move(data->mAudioData))).Forget();
+        mConverter->Process(AudioSampleBuffer(Move(buffer))).Forget();
       data = CreateAudioFromBuffer(Move(convertedData), data);
     }
     if (PushProcessedAudio(data)) {
       mLastProcessedPacket = Some(data);
     }
   }
 
   if (AudioQueue().IsFinished()) {