Bug 1341200. Part 5 - move the definition to .cpp as they will access ShutdownPromisePool in next patches. r=jya
authorJW Wang <jwwang@mozilla.com>
Fri, 24 Feb 2017 17:27:42 +0800
changeset 493322 fb30eeb72b852d51693cefcb5ab899540327fff3
parent 493321 e353098c37d208361b46fd8cb9fb32be87c0d6d6
child 493323 5abf28d4768311d99305a74a29212f6dfe7efd1f
push id47743
push userbzbarsky@mozilla.com
push dateFri, 03 Mar 2017 21:15:16 +0000
reviewersjya
bugs1341200
milestone54.0a1
Bug 1341200. Part 5 - move the definition to .cpp as they will access ShutdownPromisePool in next patches. r=jya MozReview-Commit-ID: 5Tvh1t4KyoV
dom/media/MediaFormatReader.cpp
dom/media/MediaFormatReader.h
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -369,16 +369,82 @@ MediaFormatReader::ShutdownPromisePool::
       MOZ_DIAGNOSTIC_ASSERT(mPromises.Contains(aPromise));
       mPromises.RemoveEntry(aPromise);
       if (mShutdown && mPromises.Count() == 0) {
         mOnShutdownComplete->Resolve(true, __func__);
       }
     });
 }
 
+void
+MediaFormatReader::DecoderData::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]() {
+               mShuttingDown = false;
+               mShutdownPromise.ResolveIfExists(true, __func__);
+               owner->ScheduleUpdate(type);
+             },
+             []() { MOZ_RELEASE_ASSERT(false, "Can't ever be here"); });
+  }
+  mDescription = "shutdown";
+  mDecoder = nullptr;
+}
+
+void
+MediaFormatReader::DecoderData::Flush()
+{
+  if (mFlushing || 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) {
+    RefPtr<MediaFormatReader> owner = mOwner;
+    TrackType type = mType == MediaData::AUDIO_DATA
+                     ? TrackType::kAudioTrack
+                     : TrackType::kVideoTrack;
+    mFlushing = true;
+    mDecoder->Flush()
+      ->Then(mOwner->OwnerThread(), __func__,
+             [owner, type, this]() {
+               mFlushing = false;
+               if (!mShutdownPromise.IsEmpty()) {
+                 ShutdownDecoder();
+                 return;
+               }
+               owner->ScheduleUpdate(type);
+             },
+             [owner, type, this](const MediaResult& aError) {
+               mFlushing = false;
+               if (!mShutdownPromise.IsEmpty()) {
+                 ShutdownDecoder();
+                 return;
+               }
+               owner->NotifyError(type, aError);
+             });
+  }
+  mFlushed = true;
+}
+
 class MediaFormatReader::DecoderFactory
 {
   using InitPromise = MediaDataDecoder::InitPromise;
   using TokenPromise = GlobalAllocPolicy::Promise;
   using Token = GlobalAllocPolicy::Token;
 
 public:
   explicit DecoderFactory(MediaFormatReader* aOwner)
--- a/dom/media/MediaFormatReader.h
+++ b/dom/media/MediaFormatReader.h
@@ -209,37 +209,17 @@ private:
     // Only non-null up until the decoder is created.
     RefPtr<TaskQueue> mTaskQueue;
 
     // Mutex protecting mDescription and mDecoder.
     Mutex mMutex;
     // The platform decoder.
     RefPtr<MediaDataDecoder> mDecoder;
     const char* mDescription;
-    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]() {
-                   mShuttingDown = false;
-                   mShutdownPromise.ResolveIfExists(true, __func__);
-                   owner->ScheduleUpdate(type);
-                 },
-                 []() { MOZ_RELEASE_ASSERT(false, "Can't ever be here"); });
-      }
-      mDescription = "shutdown";
-      mDecoder = nullptr;
-    }
+    void ShutdownDecoder();
 
     // Only accessed from reader's task queue.
     bool mUpdateScheduled;
     bool mDemuxEOS;
     bool mWaitingForData;
     bool mWaitingForKey;
     bool mReceivedNewData;
 
@@ -336,57 +316,17 @@ private:
       mDemuxRequest.DisconnectIfExists();
       mSeekRequest.DisconnectIfExists();
       mTrackDemuxer->Reset();
       mQueuedSamples.Clear();
     }
 
     // Flush the decoder if present and reset decoding related data.
     // Following a flush, the decoder is ready to accept any new data.
-    void Flush()
-    {
-      if (mFlushing || 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) {
-        RefPtr<MediaFormatReader> owner = mOwner;
-        TrackType type = mType == MediaData::AUDIO_DATA
-                         ? TrackType::kAudioTrack
-                         : TrackType::kVideoTrack;
-        mFlushing = true;
-        mDecoder->Flush()
-          ->Then(mOwner->OwnerThread(), __func__,
-                 [owner, type, this]() {
-                   mFlushing = false;
-                   if (!mShutdownPromise.IsEmpty()) {
-                     ShutdownDecoder();
-                     return;
-                   }
-                   owner->ScheduleUpdate(type);
-                 },
-                 [owner, type, this](const MediaResult& aError) {
-                   mFlushing = false;
-                   if (!mShutdownPromise.IsEmpty()) {
-                     ShutdownDecoder();
-                     return;
-                   }
-                   owner->NotifyError(type, aError);
-                 });
-      }
-      mFlushed = true;
-    }
+    void Flush();
 
     bool CancelWaitingForKey()
     {
       if (!mWaitingForKey) {
         return false;
       }
       mWaitingForKey = false;
       if (IsWaiting() || !HasWaitingPromise()) {