Bug 1540746 - TimeUnitToFrames() should handle the case where the input TimeUnit is overflow. r=jya
authorAlastor Wu <alwu@mozilla.com>
Tue, 16 Apr 2019 18:22:51 +0000
changeset 469761 473513f68366
parent 469760 bdd3825511f3
child 469762 f5e5b65b6600
push id35882
push usercbrindusan@mozilla.com
push dateWed, 17 Apr 2019 15:54:01 +0000
treeherdermozilla-central@37185c0ae520 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1540746
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1540746 - TimeUnitToFrames() should handle the case where the input TimeUnit is overflow. r=jya If the input has been overflow, we don't need to calculate frames and will directly return invalid result to let caller handle the error. Differential Revision: https://phabricator.services.mozilla.com/D27010
dom/media/VideoUtils.cpp
dom/media/mediasink/AudioSink.cpp
--- a/dom/media/VideoUtils.cpp
+++ b/dom/media/VideoUtils.cpp
@@ -61,17 +61,19 @@ TimeUnit FramesToTimeUnit(int64_t aFrame
 // Converts from microseconds to number of audio frames, given the specified
 // audio rate.
 CheckedInt64 UsecsToFrames(int64_t aUsecs, uint32_t aRate) {
   return SaferMultDiv(aUsecs, aRate, USECS_PER_S);
 }
 
 // Format TimeUnit as number of frames at given rate.
 CheckedInt64 TimeUnitToFrames(const TimeUnit& aTime, uint32_t aRate) {
-  return UsecsToFrames(aTime.ToMicroseconds(), aRate);
+  return aTime.IsValid() ?
+      UsecsToFrames(aTime.ToMicroseconds(), aRate) :
+      CheckedInt64(INT64_MAX) + 1;
 }
 
 nsresult SecondsToUsecs(double aSeconds, int64_t& aOutUsecs) {
   if (aSeconds * double(USECS_PER_S) > INT64_MAX) {
     return NS_ERROR_FAILURE;
   }
   aOutUsecs = int64_t(aSeconds * double(USECS_PER_S));
   return NS_OK;
--- a/dom/media/mediasink/AudioSink.cpp
+++ b/dom/media/mediasink/AudioSink.cpp
@@ -380,17 +380,17 @@ void AudioSink::NotifyAudioNeeded() {
     // Calculate the timestamp of the next chunk of audio in numbers of
     // samples.
     CheckedInt64 sampleTime =
         TimeUnitToFrames(data->mTime - mStartTime, data->mRate);
     // Calculate the number of frames that have been pushed onto the audio
     // hardware.
     CheckedInt64 missingFrames = sampleTime - mFramesParsed;
 
-    if (!missingFrames.isValid()) {
+    if (!missingFrames.isValid() || !sampleTime.isValid()) {
       NS_WARNING("Int overflow in AudioSink");
       mErrored = true;
       return;
     }
 
     if (missingFrames.value() > AUDIO_FUZZ_FRAMES) {
       // The next audio packet begins some time after the end of the last packet
       // we pushed to the audio hardware. We must push silence into the audio