Bug 1341200. Part 6 - let ShutdownDecoderWithPromise() return void by tracking the shutdown promise. r=jya
authorJW Wang <jwwang@mozilla.com>
Sat, 25 Feb 2017 07:49:29 +0800
changeset 374858 5abf28d4768311d99305a74a29212f6dfe7efd1f
parent 374857 fb30eeb72b852d51693cefcb5ab899540327fff3
child 374859 4acb3ce34d942b50697a0b62eddca5b7882b37b3
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)
reviewersjya
bugs1341200
milestone54.0a1
Bug 1341200. Part 6 - let ShutdownDecoderWithPromise() return void by tracking the shutdown promise. r=jya 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