Bug 1341200. Part 5 - move the definition to .cpp as they will access ShutdownPromisePool in next patches. draft
authorJW Wang <jwwang@mozilla.com>
Fri, 24 Feb 2017 17:27:42 +0800
changeset 493137 6506584e81ed12abe96c56a79448e4c2fecc266b
parent 493136 b80c6442232caa0a2099219f923aba4003761c96
child 493138 fde4ca7bfd6f07f364efd0dbbdfbbb182fd5490d
push id47651
push userjwwang@mozilla.com
push dateFri, 03 Mar 2017 09:41:12 +0000
bugs1341200
milestone54.0a1
Bug 1341200. Part 5 - move the definition to .cpp as they will access ShutdownPromisePool in next patches. 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()) {