Bug 1341200. Part 7 - merge ShutdownDecoderWithPromise() and ShutdownDecoder(). r=jya
authorJW Wang <jwwang@mozilla.com>
Sat, 25 Feb 2017 07:59:53 +0800
changeset 493324 4acb3ce34d942b50697a0b62eddca5b7882b37b3
parent 493323 5abf28d4768311d99305a74a29212f6dfe7efd1f
child 493325 161f4237b402880a0b66cf1981c51e28014f3a3e
push id47743
push userbzbarsky@mozilla.com
push dateFri, 03 Mar 2017 21:15:16 +0000
reviewersjya
bugs1341200
milestone54.0a1
Bug 1341200. Part 7 - merge ShutdownDecoderWithPromise() and ShutdownDecoder(). r=jya MozReview-Commit-ID: 9YRwPJGqrhq
dom/media/MediaFormatReader.cpp
dom/media/MediaFormatReader.h
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -1108,46 +1108,55 @@ MediaFormatReader::Shutdown()
     mVideo.RejectPromise(NS_ERROR_DOM_MEDIA_CANCELED, __func__);
   }
 
   if (HasAudio()) {
     mAudio.ResetDemuxer();
     mAudio.mTrackDemuxer->BreakCycles();
     mAudio.mTrackDemuxer = nullptr;
     mAudio.ResetState();
-    ShutdownDecoderWithPromise(TrackInfo::kAudioTrack);
+    ShutdownDecoder(TrackInfo::kAudioTrack);
   }
 
   if (HasVideo()) {
     mVideo.ResetDemuxer();
     mVideo.mTrackDemuxer->BreakCycles();
     mVideo.mTrackDemuxer = nullptr;
     mVideo.ResetState();
-    ShutdownDecoderWithPromise(TrackInfo::kVideoTrack);
+    ShutdownDecoder(TrackInfo::kVideoTrack);
   }
 
   mShutdownPromisePool->Track(mDemuxer->Shutdown());
   mDemuxer = nullptr;
 
   mCompositorUpdatedListener.DisconnectIfExists();
   mOnTrackWaitingForKeyListener.Disconnect();
 
   mShutdown = true;
   return mShutdownPromisePool->Shutdown()
     ->Then(OwnerThread(), __func__, this,
            &MediaFormatReader::TearDownDecoders,
            &MediaFormatReader::TearDownDecoders);
 }
 
 void
-MediaFormatReader::ShutdownDecoderWithPromise(TrackType aTrack)
+MediaFormatReader::ShutdownDecoder(TrackType aTrack)
 {
   LOGV("%s", TrackTypeToStr(aTrack));
 
   auto& decoder = GetDecoderData(aTrack);
+  if (!decoder.mDecoder) {
+    LOGV("Already shut down");
+    return;
+  }
+  if (!decoder.mShutdownPromise.IsEmpty()) {
+    LOGV("Shutdown already in progress");
+    return;
+  }
+
   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();
     mShutdownPromisePool->Track(decoder.mShutdownPromise.Ensure(__func__));
     return;
   }
@@ -1168,32 +1177,16 @@ MediaFormatReader::ShutdownDecoderWithPr
     return;
   }
 
   // Finally, let's just shut down the currently active decoder.
   decoder.ShutdownDecoder();
   mShutdownPromisePool->Track(decoder.mShutdownPromise.Ensure(__func__));
 }
 
-void
-MediaFormatReader::ShutdownDecoder(TrackType aTrack)
-{
-  LOG("%s", TrackTypeToStr(aTrack));
-  auto& decoder = GetDecoderData(aTrack);
-  if (!decoder.mDecoder) {
-    LOGV("Already shut down");
-    return;
-  }
-  if (!decoder.mShutdownPromise.IsEmpty()) {
-    LOGV("Shutdown already in progress");
-    return;
-  }
-  ShutdownDecoderWithPromise(aTrack);
-}
-
 RefPtr<ShutdownPromise>
 MediaFormatReader::TearDownDecoders()
 {
   if (mAudio.mTaskQueue) {
     mAudio.mTaskQueue->BeginShutdown();
     mAudio.mTaskQueue->AwaitShutdownAndIdle();
     mAudio.mTaskQueue = nullptr;
   }
--- a/dom/media/MediaFormatReader.h
+++ b/dom/media/MediaFormatReader.h
@@ -544,15 +544,14 @@ private:
   void MaybeResolveMetadataPromise();
 
   UniquePtr<MetadataTags> mTags;
 
   // A flag indicating if the start time is known or not.
   bool mHasStartTime = false;
 
   void ShutdownDecoder(TrackType aTrack);
-  void ShutdownDecoderWithPromise(TrackType aTrack);
   RefPtr<ShutdownPromise> TearDownDecoders();
 };
 
 } // namespace mozilla
 
 #endif