From c2d4dcad38abd041f003ed9153d1c66e9da2a08f Mon Sep 17 00:00:00 2001 From: Bryce Seager van Dyk Date: Mon, 11 Jan 2021 20:24:03 +0000 Subject: [PATCH] Bug 1673525 - Don't try and process audio with no frames in DecodedStream. r=pehrsons Differential Revision: https://phabricator.services.mozilla.com/D100400 --- dom/media/mediasink/DecodedStream.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dom/media/mediasink/DecodedStream.cpp b/dom/media/mediasink/DecodedStream.cpp index a533940ab3e8..84b48addf9fb 100644 --- a/dom/media/mediasink/DecodedStream.cpp +++ b/dom/media/mediasink/DecodedStream.cpp @@ -608,6 +608,11 @@ static void SendStreamAudio(DecodedStreamData* aStream, MOZ_ASSERT(aData); AudioData* audio = aData; + + if (!audio->Frames()) { + // Ignore elements with 0 frames. + return; + } // This logic has to mimic AudioSink closely to make sure we write // the exact same silences CheckedInt64 audioWrittenOffset = @@ -621,8 +626,9 @@ static void SendStreamAudio(DecodedStreamData* aStream, } if (audioWrittenOffset.value() + AUDIO_FUZZ_FRAMES < frameOffset.value()) { + // We've written less audio than our frame offset, write silence so we have + // enough audio to be at the correct offset for our current frames. int64_t silentFrames = frameOffset.value() - audioWrittenOffset.value(); - // Write silence to catch up AudioSegment silence; silence.InsertNullDataAtStart(silentFrames); aStream->mAudioFramesWritten += silentFrames;