Bug 1307677. Part 3 - move |mCurrentSeek.mPromise.Ensure| out of InitiateSeek(). This makes it easier to move more code into SeekingState. draft
authorJW Wang <jwwang@mozilla.com>
Tue, 04 Oct 2016 16:55:59 +0800
changeset 421049 ad2212940c6cd0627ccd784516345b8463b9372e
parent 421048 baac81f5fae2bba25154d82719cbafbe3e07d9b8
child 421050 900361c6eee21f595d156e5283ee42fef2f730d4
push id31369
push userjwwang@mozilla.com
push dateWed, 05 Oct 2016 07:51:53 +0000
bugs1307677
milestone52.0a1
Bug 1307677. Part 3 - move |mCurrentSeek.mPromise.Ensure| out of InitiateSeek(). This makes it easier to move more code into SeekingState. MozReview-Commit-ID: Id4PprPtJdX
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -497,17 +497,18 @@ public:
 
     // Since ForceZeroStartTime() is true, we should've transitioned to SEEKING
     // in Enter() if there is any queued seek.
     MOZ_ASSERT(!mMaster->mQueuedSeek.Exists());
 
     SLOG("Changed state to SEEKING (to %lld)", aTarget.GetTime().ToMicroseconds());
     SeekJob seekJob;
     seekJob.mTarget = aTarget;
-    return mMaster->InitiateSeek(Move(seekJob));
+    mMaster->InitiateSeek(Move(seekJob));
+    return mMaster->mCurrentSeek.mPromise.Ensure(__func__);
   }
 
 private:
   // Notify FirstFrameLoaded if having decoded first frames and
   // transition to SEEKING if there is any pending seek, or DECODING otherwise.
   void MaybeFinishDecodeFirstFrame()
   {
     MOZ_ASSERT(!mMaster->mSentFirstFrameLoadedEvent);
@@ -607,17 +608,18 @@ public:
   }
 
   RefPtr<MediaDecoder::SeekPromise> HandleSeek(SeekTarget aTarget) override
   {
     mMaster->mQueuedSeek.RejectIfExists(__func__);
     SLOG("Changed state to SEEKING (to %lld)", aTarget.GetTime().ToMicroseconds());
     SeekJob seekJob;
     seekJob.mTarget = aTarget;
-    return mMaster->InitiateSeek(Move(seekJob));
+    mMaster->InitiateSeek(Move(seekJob));
+    return mMaster->mCurrentSeek.mPromise.Ensure(__func__);
   }
 
 private:
   void CheckSlowDecoding(TimeStamp aDecodeStart)
   {
     // For non async readers, if the requested video sample was slow to
     // arrive, increase the amount of audio we buffer to ensure that we
     // don't run out of audio. This is unnecessary for async readers,
@@ -703,17 +705,18 @@ public:
   }
 
   RefPtr<MediaDecoder::SeekPromise> HandleSeek(SeekTarget aTarget) override
   {
     mMaster->mQueuedSeek.RejectIfExists(__func__);
     SLOG("Changed state to SEEKING (to %lld)", aTarget.GetTime().ToMicroseconds());
     SeekJob seekJob;
     seekJob.mTarget = aTarget;
-    return mMaster->InitiateSeek(Move(seekJob));
+    mMaster->InitiateSeek(Move(seekJob));
+    return mMaster->mCurrentSeek.mPromise.Ensure(__func__);
   }
 };
 
 class MediaDecoderStateMachine::BufferingState
   : public MediaDecoderStateMachine::StateObject
 {
 public:
   explicit BufferingState(Master* aPtr) : StateObject(aPtr) {}
@@ -812,17 +815,18 @@ public:
   }
 
   RefPtr<MediaDecoder::SeekPromise> HandleSeek(SeekTarget aTarget) override
   {
     mMaster->mQueuedSeek.RejectIfExists(__func__);
     SLOG("Changed state to SEEKING (to %lld)", aTarget.GetTime().ToMicroseconds());
     SeekJob seekJob;
     seekJob.mTarget = aTarget;
-    return mMaster->InitiateSeek(Move(seekJob));
+    mMaster->InitiateSeek(Move(seekJob));
+    return mMaster->mCurrentSeek.mPromise.Ensure(__func__);
   }
 
 private:
   TimeStamp mBufferingStart;
 };
 
 class MediaDecoderStateMachine::CompletedState
   : public MediaDecoderStateMachine::StateObject
@@ -889,17 +893,18 @@ public:
   }
 
   RefPtr<MediaDecoder::SeekPromise> HandleSeek(SeekTarget aTarget) override
   {
     mMaster->mQueuedSeek.RejectIfExists(__func__);
     SLOG("Changed state to SEEKING (to %lld)", aTarget.GetTime().ToMicroseconds());
     SeekJob seekJob;
     seekJob.mTarget = aTarget;
-    return mMaster->InitiateSeek(Move(seekJob));
+    mMaster->InitiateSeek(Move(seekJob));
+    return mMaster->mCurrentSeek.mPromise.Ensure(__func__);
   }
 
 private:
   bool mSentPlaybackEndedEvent = false;
 };
 
 class MediaDecoderStateMachine::ShutdownState
   : public MediaDecoderStateMachine::StateObject
@@ -1964,20 +1969,21 @@ void MediaDecoderStateMachine::Visibilit
                                   ? SeekTarget::Type::Accurate
                                   : SeekTarget::Type::PrevSyncPoint;
 
     seekJob.mTarget = SeekTarget(GetMediaTime(),
                                  type,
                                  MediaDecoderEventVisibility::Suppressed,
                                  true /* aVideoOnly */);
 
-    InitiateSeek(Move(seekJob))
-      ->Then(AbstractThread::MainThread(), __func__,
-             [start, info, hw](){ ReportRecoveryTelemetry(start, info, hw); },
-             [](){});
+    InitiateSeek(Move(seekJob));
+    RefPtr<MediaDecoder::SeekPromise> p = mCurrentSeek.mPromise.Ensure(__func__);
+    p->Then(AbstractThread::MainThread(), __func__,
+            [start, info, hw](){ ReportRecoveryTelemetry(start, info, hw); },
+            [](){});
   }
 }
 
 void MediaDecoderStateMachine::BufferedRangeUpdated()
 {
   MOZ_ASSERT(OnTaskQueue());
 
   // While playing an unseekable stream of unknown duration, mObservedDuration
@@ -2099,17 +2105,17 @@ MediaDecoderStateMachine::DispatchDecode
   if (needIdle) {
     DECODER_LOG("Dispatching SetIdle() audioQueue=%lld videoQueue=%lld",
                 GetDecodedAudioDuration(),
                 VideoQueue().Duration());
     mReader->SetIdle();
   }
 }
 
-RefPtr<MediaDecoder::SeekPromise>
+void
 MediaDecoderStateMachine::InitiateSeek(SeekJob aSeekJob)
 {
   MOZ_ASSERT(OnTaskQueue());
 
   SetState(DECODER_STATE_SEEKING);
 
   // Discard the existing seek task.
   DiscardSeekTaskIfExist();
@@ -2161,17 +2167,16 @@ MediaDecoderStateMachine::InitiateSeek(S
   mSeekTaskRequest.Begin(mSeekTask->Seek(Duration())
     ->Then(OwnerThread(), __func__, this,
            &MediaDecoderStateMachine::OnSeekTaskResolved,
            &MediaDecoderStateMachine::OnSeekTaskRejected));
 
   MOZ_ASSERT(!mQueuedSeek.Exists());
   MOZ_ASSERT(!mCurrentSeek.Exists());
   mCurrentSeek = Move(aSeekJob);
-  return mCurrentSeek.mPromise.Ensure(__func__);
 }
 
 void
 MediaDecoderStateMachine::OnSeekTaskResolved(SeekTaskResolveValue aValue)
 {
   MOZ_ASSERT(OnTaskQueue());
   MOZ_ASSERT(mState == DECODER_STATE_SEEKING);
 
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -481,17 +481,17 @@ protected:
   // Dispatches a LoadedMetadataEvent.
   // This is threadsafe and can be called on any thread.
   // The decoder monitor must be held.
   void EnqueueLoadedMetadataEvent();
 
   void EnqueueFirstFrameLoadedEvent();
 
   // Clears any previous seeking state and initiates a new seek on the decoder.
-  RefPtr<MediaDecoder::SeekPromise> InitiateSeek(SeekJob aSeekJob);
+  void InitiateSeek(SeekJob aSeekJob);
 
   void DispatchAudioDecodeTaskIfNeeded();
   void DispatchVideoDecodeTaskIfNeeded();
 
   // Dispatch a task to decode audio if there is not.
   void EnsureAudioDecodeTaskQueued();
 
   // Dispatch a task to decode video if there is not.