Bug 1264199: P7. Reduce likelihood of integer overflow. r?gerald draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 14 Apr 2016 17:49:47 +1000
changeset 350764 a7c3ee8f4d52ad4f6f696f3db71b16ec1277ae9d
parent 350763 2d442343b20960fa7d140b889f2c071b3c149d5a
child 350828 927a17c673f578e4337628012af0151279d4d0ee
push id15406
push userbmo:jyavenard@mozilla.com
push dateThu, 14 Apr 2016 07:50:31 +0000
reviewersgerald
bugs1264199
milestone48.0a1
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
dom/media/mediasink/DecodedAudioDataSink.cpp
--- 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>();
     }