Bug 1313548: P1. Always resolve waiting promise, when clearing waitforkey. r=gerald
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 23 Feb 2017 14:10:12 +0100
changeset 374717 86489d8bd8825b707af8dfc77f0a2511a2626e46
parent 374716 a2ec65fced217970ecad5b839493f2b335923773
child 374718 24ee5cc96d2af8b9f3e16186809f11bd09ccaf3c
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1313548
milestone54.0a1
Bug 1313548: P1. Always resolve waiting promise, when clearing waitforkey. r=gerald MozReview-Commit-ID: 6xu8Rcn9WMO
dom/media/MediaFormatReader.cpp
dom/media/MediaFormatReader.h
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -2274,23 +2274,19 @@ MediaFormatReader::Update(TrackType aTra
   if ((decoder.mWaitingForData
        && (!decoder.mTimeThreshold || decoder.mTimeThreshold.ref().mWaiting))
       || (decoder.mWaitingForKey && decoder.mDecodeRequest.Exists())) {
     // Nothing more we can do at present.
     LOGV("Still waiting for data or key.");
     return;
   }
 
-  if (decoder.mWaitingForKey) {
-    decoder.mWaitingForKey = false;
-    if (decoder.HasWaitingPromise() && !decoder.IsWaiting()) {
-      LOGV("No longer waiting for key. Resolving waiting promise");
-      decoder.mWaitingPromise.Resolve(decoder.mType, __func__);
-      return;
-    }
+  if (decoder.CancelWaitingForKey()) {
+    LOGV("No longer waiting for key. Resolving waiting promise");
+    return;
   }
 
   if (!needInput) {
     LOGV("No need for additional input (pending:%u)",
          uint32_t(decoder.mOutput.Length()));
     return;
   }
 
--- a/dom/media/MediaFormatReader.h
+++ b/dom/media/MediaFormatReader.h
@@ -344,16 +344,17 @@ private:
     {
       if (mFlushRequest.Exists() || mFlushed) {
         // Flush still pending or already flushed, nothing more to do.
         return;
       }
       mDecodeRequest.DisconnectIfExists();
       mDrainRequest.DisconnectIfExists();
       mDrainState = DrainState::None;
+      CancelWaitingForKey();
       mOutput.Clear();
       mNumSamplesInput = 0;
       mNumSamplesOutput = 0;
       mSizeOfQueue = 0;
       if (mDecoder && !mFlushed) {
         RefPtr<MediaFormatReader> owner = mOwner;
         TrackType type = mType == MediaData::AUDIO_DATA
                          ? TrackType::kAudioTrack
@@ -376,29 +377,42 @@ private:
                    }
                    owner->NotifyError(type, aError);
                  })
           ->Track(mFlushRequest);
       }
       mFlushed = true;
     }
 
+    bool CancelWaitingForKey()
+    {
+      if (!mWaitingForKey) {
+        return false;
+      }
+      mWaitingForKey = false;
+      if (IsWaiting() || mWaitingPromise.IsEmpty()) {
+        return false;
+      }
+      mWaitingPromise.Resolve(mType, __func__);
+      return true;
+    }
+
     // Reset the state of the DecoderData, clearing all queued frames
     // (pending demuxed and decoded).
     // The track demuxer is *not* reset.
     void ResetState()
     {
       MOZ_ASSERT(mOwner->OnTaskQueue());
       mDemuxEOS = false;
       mWaitingForData = false;
-      mWaitingForKey = false;
       mQueuedSamples.Clear();
       mDecodeRequest.DisconnectIfExists();
       mDrainRequest.DisconnectIfExists();
       mDrainState = DrainState::None;
+      CancelWaitingForKey();
       mTimeThreshold.reset();
       mLastSampleTime.reset();
       mOutput.Clear();
       mNumSamplesInput = 0;
       mNumSamplesOutput = 0;
       mSizeOfQueue = 0;
       mNextStreamSourceID.reset();
       if (!HasFatalError()) {