Bug 1341200. Part 3 - replace mShutdownRequest with a bool as P2. draft
authorJW Wang <jwwang@mozilla.com>
Fri, 24 Feb 2017 17:19:12 +0800
changeset 493135 1b4303b2ac289f6ab1d86f3ce9dd0d00caf672dc
parent 493134 94c493b76c067f249cab5507cb1e6758d3c21bf5
child 493136 b80c6442232caa0a2099219f923aba4003761c96
push id47651
push userjwwang@mozilla.com
push dateFri, 03 Mar 2017 09:41:12 +0000
bugs1341200
milestone54.0a1
Bug 1341200. Part 3 - replace mShutdownRequest with a bool as P2. MozReview-Commit-ID: ERERt0ZyvkC
dom/media/MediaFormatReader.cpp
dom/media/MediaFormatReader.h
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -1080,17 +1080,17 @@ MediaFormatReader::ShutdownDecoderWithPr
   if (!decoder.mFlushed && decoder.mDecoder) {
     // The decoder has yet to be flushed.
     // We always flush the decoder prior to a shutdown to ensure that all the
     // potentially pending operations on the decoder are completed.
     decoder.Flush();
     return decoder.mShutdownPromise.Ensure(__func__);
   }
 
-  if (decoder.mFlushing || decoder.mShutdownRequest.Exists()) {
+  if (decoder.mFlushing || decoder.mShuttingDown) {
     // Let the current flush or shutdown operation complete, Flush will continue
     // shutting down the current decoder now that the shutdown promise is set.
     return decoder.mShutdownPromise.Ensure(__func__);
   }
 
   if (!decoder.mDecoder) {
     // Shutdown any decoders that may be in the process of being initialized
     // in the Decoder Factory.
@@ -1887,17 +1887,17 @@ MediaFormatReader::DecodeDemuxedSamples(
 void
 MediaFormatReader::HandleDemuxedSamples(
   TrackType aTrack, AbstractMediaDecoder::AutoNotifyDecoded& aA)
 {
   MOZ_ASSERT(OnTaskQueue());
 
   auto& decoder = GetDecoderData(aTrack);
 
-  if (decoder.mFlushing || decoder.mShutdownRequest.Exists()) {
+  if (decoder.mFlushing || decoder.mShuttingDown) {
     LOGV("Decoder operation in progress, let it complete.");
     return;
   }
 
   if (decoder.mQueuedSamples.IsEmpty()) {
     return;
   }
 
@@ -2270,17 +2270,17 @@ MediaFormatReader::Update(TrackType aTra
     TrackTypeToStr(aTrack),
     needInput,
     needOutput,
     decoder.mNumSamplesInput,
     decoder.mNumSamplesOutput,
     uint32_t(size_t(decoder.mSizeOfQueue)),
     decoder.mDecodeRequest.Exists(),
     decoder.mFlushing,
-    decoder.mShutdownRequest.Exists(),
+    decoder.mShuttingDown,
     uint32_t(decoder.mOutput.Length()),
     decoder.mWaitingForData,
     decoder.mLastStreamSourceID);
 
   if ((decoder.mWaitingForData
        && (!decoder.mTimeThreshold || decoder.mTimeThreshold.ref().mWaiting))
       || (decoder.mWaitingForKey && decoder.mDecodeRequest.Exists())) {
     // Nothing more we can do at present.
--- a/dom/media/MediaFormatReader.h
+++ b/dom/media/MediaFormatReader.h
@@ -217,25 +217,25 @@ private:
     void ShutdownDecoder()
     {
       MutexAutoLock lock(mMutex);
       if (mDecoder) {
         RefPtr<MediaFormatReader> owner = mOwner;
         TrackType type = mType == MediaData::AUDIO_DATA
                          ? TrackType::kAudioTrack
                          : TrackType::kVideoTrack;
+        mShuttingDown = true;
         mDecoder->Shutdown()
           ->Then(mOwner->OwnerThread(), __func__,
                  [owner, this, type]() {
-                   mShutdownRequest.Complete();
+                   mShuttingDown = false;
                    mShutdownPromise.ResolveIfExists(true, __func__);
                    owner->ScheduleUpdate(type);
                  },
-                 []() { MOZ_RELEASE_ASSERT(false, "Can't ever be here"); })
-          ->Track(mShutdownRequest);
+                 []() { MOZ_RELEASE_ASSERT(false, "Can't ever be here"); });
       }
       mDescription = "shutdown";
       mDecoder = nullptr;
     }
 
     // Only accessed from reader's task queue.
     bool mUpdateScheduled;
     bool mDemuxEOS;
@@ -264,17 +264,17 @@ private:
     }
 
     // MediaDataDecoder handler's variables.
     MozPromiseRequestHolder<MediaDataDecoder::DecodePromise> mDecodeRequest;
     bool mFlushing; // True if flush is in action.
     // Set to true if the last operation run on the decoder was a flush.
     bool mFlushed;
     MozPromiseHolder<ShutdownPromise> mShutdownPromise;
-    MozPromiseRequestHolder<ShutdownPromise> mShutdownRequest;
+    bool mShuttingDown = false; // True if shutdown is in action.
 
     MozPromiseRequestHolder<MediaDataDecoder::DecodePromise> mDrainRequest;
     DrainState mDrainState;
     bool HasPendingDrain() const
     {
       return mDrainState != DrainState::None;
     }
     void RequestDrain()