Bug 1341200. Part 6 - let ShutdownDecoderWithPromise() return void by tracking the shutdown promise. draft
authorJW Wang <jwwang@mozilla.com>
Sat, 25 Feb 2017 07:49:29 +0800
changeset 493138 fde4ca7bfd6f07f364efd0dbbdfbbb182fd5490d
parent 493137 6506584e81ed12abe96c56a79448e4c2fecc266b
child 493139 7eb24cfdaad873f9335ca3ca90e38947ea3ad085
push id47651
push userjwwang@mozilla.com
push dateFri, 03 Mar 2017 09:41:12 +0000
bugs1341200
milestone54.0a1
Bug 1341200. Part 6 - let ShutdownDecoderWithPromise() return void by tracking the shutdown promise. MozReview-Commit-ID: GIYdLXZYEyk
dom/media/MediaFormatReader.cpp
dom/media/MediaFormatReader.h
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -1108,88 +1108,90 @@ MediaFormatReader::Shutdown()
     mVideo.RejectPromise(NS_ERROR_DOM_MEDIA_CANCELED, __func__);
   }
 
   if (HasAudio()) {
     mAudio.ResetDemuxer();
     mAudio.mTrackDemuxer->BreakCycles();
     mAudio.mTrackDemuxer = nullptr;
     mAudio.ResetState();
-    mShutdownPromisePool->Track(ShutdownDecoderWithPromise(TrackInfo::kAudioTrack));
+    ShutdownDecoderWithPromise(TrackInfo::kAudioTrack);
   }
 
   if (HasVideo()) {
     mVideo.ResetDemuxer();
     mVideo.mTrackDemuxer->BreakCycles();
     mVideo.mTrackDemuxer = nullptr;
     mVideo.ResetState();
-    mShutdownPromisePool->Track(ShutdownDecoderWithPromise(TrackInfo::kVideoTrack));
+    ShutdownDecoderWithPromise(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);
 }
 
-RefPtr<ShutdownPromise>
+void
 MediaFormatReader::ShutdownDecoderWithPromise(TrackType aTrack)
 {
   LOGV("%s", TrackTypeToStr(aTrack));
 
   auto& decoder = GetDecoderData(aTrack);
   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__);
+    mShutdownPromisePool->Track(decoder.mShutdownPromise.Ensure(__func__));
+    return;
   }
 
   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__);
+    mShutdownPromisePool->Track(decoder.mShutdownPromise.Ensure(__func__));
+    return;
   }
 
   if (!decoder.mDecoder) {
     // Shutdown any decoders that may be in the process of being initialized
     // in the Decoder Factory.
     // This will be a no-op until we're processing the final decoder shutdown
     // prior to the MediaFormatReader being shutdown.
     mDecoderFactory->ShutdownDecoder(aTrack);
-    return ShutdownPromise::CreateAndResolve(true, __func__);
+    return;
   }
 
   // Finally, let's just shut down the currently active decoder.
   decoder.ShutdownDecoder();
-  return decoder.mShutdownPromise.Ensure(__func__);
+  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;
   }
-  Unused << ShutdownDecoderWithPromise(aTrack);
+  ShutdownDecoderWithPromise(aTrack);
 }
 
 RefPtr<ShutdownPromise>
 MediaFormatReader::TearDownDecoders()
 {
   if (mAudio.mTaskQueue) {
     mAudio.mTaskQueue->BeginShutdown();
     mAudio.mTaskQueue->AwaitShutdownAndIdle();
--- a/dom/media/MediaFormatReader.h
+++ b/dom/media/MediaFormatReader.h
@@ -544,15 +544,15 @@ private:
   void MaybeResolveMetadataPromise();
 
   UniquePtr<MetadataTags> mTags;
 
   // A flag indicating if the start time is known or not.
   bool mHasStartTime = false;
 
   void ShutdownDecoder(TrackType aTrack);
-  RefPtr<ShutdownPromise> ShutdownDecoderWithPromise(TrackType aTrack);
+  void ShutdownDecoderWithPromise(TrackType aTrack);
   RefPtr<ShutdownPromise> TearDownDecoders();
 };
 
 } // namespace mozilla
 
 #endif