Bug 1341200. Part 2 - replace mFlushRequest with a bool for mFlushRequest.Disconnect() is never used and a bool is sufficient to do the job. draft
authorJW Wang <jwwang@mozilla.com>
Fri, 24 Feb 2017 17:04:32 +0800
changeset 493134 94c493b76c067f249cab5507cb1e6758d3c21bf5
parent 493133 8f6180ff7cf68210bf5e3d5ae708fe4a65d3f8d4
child 493135 1b4303b2ac289f6ab1d86f3ce9dd0d00caf672dc
push id47651
push userjwwang@mozilla.com
push dateFri, 03 Mar 2017 09:41:12 +0000
bugs1341200
milestone54.0a1
Bug 1341200. Part 2 - replace mFlushRequest with a bool for mFlushRequest.Disconnect() is never used and a bool is sufficient to do the job. MozReview-Commit-ID: GFnSvunqtGq
dom/media/MediaFormatReader.cpp
dom/media/MediaFormatReader.h
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -1080,17 +1080,17 @@ MediaFormatReader::ShutdownDecoderWithPr
   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__);
   }
 
-  if (decoder.mFlushRequest.Exists() || decoder.mShutdownRequest.Exists()) {
+  if (decoder.mFlushing || decoder.mShutdownRequest.Exists()) {
     // 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__);
   }
 
   if (!decoder.mDecoder) {
     // Shutdown any decoders that may be in the process of being initialized
     // in the Decoder Factory.
@@ -1887,17 +1887,17 @@ MediaFormatReader::DecodeDemuxedSamples(
 void
 MediaFormatReader::HandleDemuxedSamples(
   TrackType aTrack, AbstractMediaDecoder::AutoNotifyDecoded& aA)
 {
   MOZ_ASSERT(OnTaskQueue());
 
   auto& decoder = GetDecoderData(aTrack);
 
-  if (decoder.mFlushRequest.Exists() || decoder.mShutdownRequest.Exists()) {
+  if (decoder.mFlushing || decoder.mShutdownRequest.Exists()) {
     LOGV("Decoder operation in progress, let it complete.");
     return;
   }
 
   if (decoder.mQueuedSamples.IsEmpty()) {
     return;
   }
 
@@ -2269,17 +2269,17 @@ MediaFormatReader::Update(TrackType aTra
     " qs=%u decoding:%d flushing:%d shutdown:%d pending:%u waiting:%d sid:%u",
     TrackTypeToStr(aTrack),
     needInput,
     needOutput,
     decoder.mNumSamplesInput,
     decoder.mNumSamplesOutput,
     uint32_t(size_t(decoder.mSizeOfQueue)),
     decoder.mDecodeRequest.Exists(),
-    decoder.mFlushRequest.Exists(),
+    decoder.mFlushing,
     decoder.mShutdownRequest.Exists(),
     uint32_t(decoder.mOutput.Length()),
     decoder.mWaitingForData,
     decoder.mLastStreamSourceID);
 
   if ((decoder.mWaitingForData
        && (!decoder.mTimeThreshold || decoder.mTimeThreshold.ref().mWaiting))
       || (decoder.mWaitingForKey && decoder.mDecodeRequest.Exists())) {
--- a/dom/media/MediaFormatReader.h
+++ b/dom/media/MediaFormatReader.h
@@ -180,16 +180,17 @@ private:
       , mType(aType)
       , mMutex("DecoderData")
       , mDescription("shutdown")
       , mUpdateScheduled(false)
       , mDemuxEOS(false)
       , mWaitingForData(false)
       , mWaitingForKey(false)
       , mReceivedNewData(false)
+      , mFlushing(false)
       , mFlushed(true)
       , mDrainState(DrainState::None)
       , mNumOfConsecutiveError(0)
       , mMaxConsecutiveError(aNumOfMaxError)
       , mNumSamplesInput(0)
       , mNumSamplesOutput(0)
       , mNumSamplesOutputTotal(0)
       , mNumSamplesSkippedTotal(0)
@@ -259,17 +260,17 @@ private:
     bool IsWaiting() const
     {
       MOZ_ASSERT(mOwner->OnTaskQueue());
       return mWaitingForData || mWaitingForKey;
     }
 
     // MediaDataDecoder handler's variables.
     MozPromiseRequestHolder<MediaDataDecoder::DecodePromise> mDecodeRequest;
-    MozPromiseRequestHolder<MediaDataDecoder::FlushPromise> mFlushRequest;
+    bool mFlushing; // True if flush is in action.
     // Set to true if the last operation run on the decoder was a flush.
     bool mFlushed;
     MozPromiseHolder<ShutdownPromise> mShutdownPromise;
     MozPromiseRequestHolder<ShutdownPromise> mShutdownRequest;
 
     MozPromiseRequestHolder<MediaDataDecoder::DecodePromise> mDrainRequest;
     DrainState mDrainState;
     bool HasPendingDrain() const
@@ -337,52 +338,52 @@ private:
       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 (mFlushRequest.Exists() || mFlushed) {
+      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 && !mFlushed) {
         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]() {
-                   mFlushRequest.Complete();
+                   mFlushing = false;
                    if (!mShutdownPromise.IsEmpty()) {
                      ShutdownDecoder();
                      return;
                    }
                    owner->ScheduleUpdate(type);
                  },
                  [owner, type, this](const MediaResult& aError) {
-                   mFlushRequest.Complete();
+                   mFlushing = false;
                    if (!mShutdownPromise.IsEmpty()) {
                      ShutdownDecoder();
                      return;
                    }
                    owner->NotifyError(type, aError);
-                 })
-          ->Track(mFlushRequest);
+                 });
       }
       mFlushed = true;
     }
 
     bool CancelWaitingForKey()
     {
       if (!mWaitingForKey) {
         return false;