From caa3760fb4d51dc883529912505f8fef3b7ad652 Mon Sep 17 00:00:00 2001 From: Sebastian Hengst Date: Mon, 16 Oct 2017 10:18:06 +0200 Subject: [PATCH] Backed out changeset 0442a3ecb494 (bug 1400674) for failing mda tests dom/media/mediasource/test/test_BufferingWait_mp4.html and test_WaitingOnMissingData_mp4.html. r=backout --HG-- extra : amend_source : 260df77d213debe033fef9a110fe665f180e50cc --- dom/media/mediasink/AudioSink.cpp | 37 ++++++++++++++++++------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/dom/media/mediasink/AudioSink.cpp b/dom/media/mediasink/AudioSink.cpp index 8986fc82e30c..12e657a8df81 100644 --- a/dom/media/mediasink/AudioSink.cpp +++ b/dom/media/mediasink/AudioSink.cpp @@ -424,21 +424,28 @@ AudioSink::NotifyAudioNeeded() missingFrames = std::min(INT32_MAX, missingFrames.value()); mFramesParsed += missingFrames.value(); - RefPtr silenceData; - AlignedAudioBuffer silenceBuffer(missingFrames.value() * data->mChannels); - if (!silenceBuffer) { - NS_WARNING("OOM in AudioSink"); - mErrored = true; - return; - } - if (mConverter->InputConfig() != mConverter->OutputConfig()) { - AlignedAudioBuffer convertedData = - mConverter->Process(AudioSampleBuffer(Move(silenceBuffer))).Forget(); - silenceData = CreateAudioFromBuffer(Move(convertedData), data); - } else { - silenceData = CreateAudioFromBuffer(Move(silenceBuffer), data); + // We need to calculate how many frames are missing at the output rate. + missingFrames = + SaferMultDiv(missingFrames.value(), mOutputRate, data->mRate); + if (!missingFrames.isValid()) { + NS_WARNING("Int overflow in AudioSink"); + mErrored = true; + return; + } + + // We need to insert silence, first use drained frames if any. + missingFrames -= DrainConverter(missingFrames.value()); + // Insert silence if still needed. + if (missingFrames.value()) { + AlignedAudioBuffer silenceData(missingFrames.value() * mOutputChannels); + if (!silenceData) { + NS_WARNING("OOM in AudioSink"); + mErrored = true; + return; + } + RefPtr silence = CreateAudioFromBuffer(Move(silenceData), data); + PushProcessedAudio(silence); } - PushProcessedAudio(silenceData); } mLastEndTime = data->GetEndTime(); @@ -479,7 +486,7 @@ AudioSink::PushProcessedAudio(AudioData* aData) already_AddRefed AudioSink::CreateAudioFromBuffer(AlignedAudioBuffer&& aBuffer, - AudioData* aReference) + AudioData* aReference) { uint32_t frames = aBuffer.Length() / mOutputChannels; if (!frames) {