Bug 1540746 - TimeUnitToFrames() should handle the case where the input TimeUnit is overflow. r=jya
☠☠ backed out by 50efd1672ffb ☠ ☠
authorAlastor Wu <alwu@mozilla.com>
Tue, 16 Apr 2019 17:19:13 +0000
changeset 469718 6ecaea77b9d5
parent 469717 8c63b67c8273
child 469719 50efd1672ffb
push id35879
push usernerli@mozilla.com
push dateTue, 16 Apr 2019 22:01:48 +0000
treeherdermozilla-central@12a60898fdc1 [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,17 @@ 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) : aTime;
 }
 
 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