Bug 1400674 - P1: fix the algorithm of filling audio gaps with silence. r=jya

MozReview-Commit-ID: Hjsboq6PdlN

--HG--
extra : rebase_source : 639e1f4fcb96b6080133fced25ed304152e515af
This commit is contained in:
JW Wang 2017-10-13 17:24:24 +08:00
Родитель 5668671730
Коммит 3705c2d6bb
1 изменённых файлов: 15 добавлений и 22 удалений

Просмотреть файл

@ -424,28 +424,21 @@ AudioSink::NotifyAudioNeeded()
missingFrames = std::min<int64_t>(INT32_MAX, missingFrames.value());
mFramesParsed += missingFrames.value();
// 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<AudioData> silence = CreateAudioFromBuffer(Move(silenceData), data);
PushProcessedAudio(silence);
RefPtr<AudioData> 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);
}
PushProcessedAudio(silenceData);
}
mLastEndTime = data->GetEndTime();
@ -486,7 +479,7 @@ AudioSink::PushProcessedAudio(AudioData* aData)
already_AddRefed<AudioData>
AudioSink::CreateAudioFromBuffer(AlignedAudioBuffer&& aBuffer,
AudioData* aReference)
AudioData* aReference)
{
uint32_t frames = aBuffer.Length() / mOutputChannels;
if (!frames) {