Bug 1264199: P7. Reduce likelihood of integer overflow. r?gerald
If frame start time was very high (like seen with some BBC videos) it could easily overflow. Now we can only overflow after playing 2^63 / sampling_rate microseconds of audio (~6 years @ 48kHz)
MozReview-Commit-ID: 14uQuAZheeq
--- a/dom/media/mediasink/DecodedAudioDataSink.cpp
+++ b/dom/media/mediasink/DecodedAudioDataSink.cpp
@@ -245,21 +245,21 @@ DecodedAudioDataSink::PopFrames(uint32_t
if (!mProcessedQueue.GetSize()) {
return MakeUnique<Chunk>();
}
// See if there's a gap in the audio. If there is, push silence into the
// audio hardware, so we can play across the gap.
// Calculate the timestamp of the next chunk of audio in numbers of
// samples.
- CheckedInt64 sampleTime = UsecsToFrames(mProcessedQueue.PeekFront()->mTime,
- mOutputRate);
+
+ CheckedInt64 sampleTime =
+ UsecsToFrames(mProcessedQueue.PeekFront()->mTime - mStartTime, mOutputRate);
// Calculate the number of frames that have been pushed onto the audio hardware.
- CheckedInt64 playedFrames = UsecsToFrames(mStartTime, mOutputRate) +
- static_cast<int64_t>(mWritten);
+ CheckedInt64 playedFrames = UsecsToFrames(mWritten, mOutputRate);
CheckedInt64 missingFrames = sampleTime - playedFrames;
if (!missingFrames.isValid() || !sampleTime.isValid()) {
NS_WARNING("Int overflow in DecodedAudioDataSink");
mErrored = true;
return MakeUnique<Chunk>();
}