Bug 1307699. Part 4 - move DiscardSeekTaskIfExist() into the exit action of SeekingState. draft
authorJW Wang <jwwang@mozilla.com>
Wed, 05 Oct 2016 14:47:13 +0800
changeset 421416 7f6379a6d3eb5084bd8802c4814768820cf2e323
parent 421415 df02e79b13ac2b90b604b32da6fbc043bcc36cbe
child 421417 fb650453c4e5ef9fe8db28668efd90ff9a681c26
push id31488
push userjwwang@mozilla.com
push dateThu, 06 Oct 2016 02:31:05 +0000
bugs1307699
milestone52.0a1
Bug 1307699. Part 4 - move DiscardSeekTaskIfExist() into the exit action of SeekingState. MozReview-Commit-ID: 9FDgZLHg8Wj
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -395,17 +395,16 @@ public:
 class MediaDecoderStateMachine::DormantState
   : public MediaDecoderStateMachine::StateObject
 {
 public:
   explicit DormantState(Master* aPtr) : StateObject(aPtr) {}
 
   void Enter() override
   {
-    mMaster->DiscardSeekTaskIfExist();
     if (mMaster->IsPlaying()) {
       mMaster->StopPlayback();
     }
     mMaster->Reset();
     mMaster->mReader->ReleaseResources();
   }
 
   State GetState() const override
@@ -667,19 +666,16 @@ class MediaDecoderStateMachine::SeekingS
   : public MediaDecoderStateMachine::StateObject
 {
 public:
   explicit SeekingState(Master* aPtr, SeekJob aSeekJob)
     : StateObject(aPtr), mSeekJob(Move(aSeekJob)) {}
 
   void Enter() override
   {
-    // Discard the existing seek task.
-    mMaster->DiscardSeekTaskIfExist();
-
     // SeekTask will register its callbacks to MediaDecoderReaderWrapper.
     mMaster->CancelMediaDecoderReaderWrapperCallback();
 
     // Create a new SeekTask instance for the incoming seek task.
     if (mSeekJob.mTarget.IsAccurate() ||
         mSeekJob.mTarget.IsFast()) {
       mMaster->mSeekTask = new AccurateSeekTask(
         mMaster->mDecoderID, OwnerThread(), Reader(), mSeekJob.mTarget,
@@ -732,16 +728,25 @@ public:
     MOZ_ASSERT(!mMaster->mQueuedSeek.Exists());
     MOZ_ASSERT(!mMaster->mCurrentSeek.Exists());
     mMaster->mCurrentSeek = Move(mSeekJob);
   }
 
   void Exit() override
   {
     mSeekTaskRequest.DisconnectIfExists();
+
+    if (mMaster->mSeekTask) {
+      mMaster->mCurrentSeek.RejectIfExists(__func__);
+      mMaster->mSeekTask->Discard();
+      mMaster->mSeekTask = nullptr;
+
+      // Reset the MediaDecoderReaderWrapper's callbask.
+      mMaster->SetMediaDecoderReaderWrapperCallback();
+    }
   }
 
   State GetState() const override
   {
     return DECODER_STATE_SEEKING;
   }
 
   bool HandleDormant(bool aDormant) override
@@ -823,18 +828,16 @@ private:
       mMaster->AudioQueue().Finish();
     }
 
     if (aValue.mIsVideoQueueFinished) {
       mMaster->VideoQueue().Finish();
     }
 
     mMaster->DecodeError(aValue.mError);
-
-    mMaster->DiscardSeekTaskIfExist();
   }
 
   void SeekCompleted()
   {
     int64_t seekTime = mMaster->mSeekTask->GetSeekTarget().GetTime().ToMicroseconds();
     int64_t newCurrentTime = seekTime;
 
     // Setup timestamp state.
@@ -874,20 +877,16 @@ private:
     } else {
       nextState = DECODER_STATE_DECODING;
     }
 
     // We want to resolve the seek request prior finishing the first frame
     // to ensure that the seeked event is fired prior loadeded.
     mMaster->mCurrentSeek.Resolve(nextState == DECODER_STATE_COMPLETED, __func__);
 
-    // Discard and nullify the seek task.
-    // Reset the MediaDecoderReaderWrapper's callbask.
-    mMaster->DiscardSeekTaskIfExist();
-
     // NOTE: Discarding the mSeekTask must be done before here. The following code
     // might ask the MediaDecoderReaderWrapper to request media data, however, the
     // SeekTask::Discard() will ask MediaDecoderReaderWrapper to discard media
     // data requests.
 
     // Notify FirstFrameLoaded now if we haven't since we've decoded some data
     // for readyState to transition to HAVE_CURRENT_DATA and fire 'loadeddata'.
     if (!mMaster->mSentFirstFrameLoadedEvent) {
@@ -1962,18 +1961,16 @@ MediaDecoderStateMachine::Shutdown()
   SetState(DECODER_STATE_SHUTDOWN);
 
   mDelayedScheduler.Reset();
 
   mBufferedUpdateRequest.DisconnectIfExists();
 
   mQueuedSeek.RejectIfExists(__func__);
 
-  DiscardSeekTaskIfExist();
-
   // Shutdown happens will decode timer is active, we need to disconnect and
   // dispose of the timer.
   mVideoDecodeSuspendTimer.Reset();
 
   mCDMProxyPromise.DisconnectIfExists();
 
   if (IsPlaying()) {
     StopPlayback();
@@ -2312,29 +2309,16 @@ MediaDecoderStateMachine::InitiateSeek(S
   // if we are already in the SEEKING state.
   mStateObj->Exit();
   mState = DECODER_STATE_SEEKING;
   mStateObj = MakeUnique<SeekingState>(this, Move(aSeekJob));
   mStateObj->Enter();
 }
 
 void
-MediaDecoderStateMachine::DiscardSeekTaskIfExist()
-{
-  if (mSeekTask) {
-    mCurrentSeek.RejectIfExists(__func__);
-    mSeekTask->Discard();
-    mSeekTask = nullptr;
-
-    // Reset the MediaDecoderReaderWrapper's callbask.
-    SetMediaDecoderReaderWrapperCallback();
-  }
-}
-
-void
 MediaDecoderStateMachine::DispatchAudioDecodeTaskIfNeeded()
 {
   MOZ_ASSERT(OnTaskQueue());
   if (!IsShutdown() && NeedToDecodeAudio()) {
     EnsureAudioDecodeTaskQueued();
   }
 }
 
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -617,20 +617,16 @@ private:
 
   // Queued seek - moves to mCurrentSeek when DecodeFirstFrame completes.
   SeekJob mQueuedSeek;
   SeekJob mCurrentSeek;
 
   // mSeekTask is responsible for executing the current seek request.
   RefPtr<SeekTask> mSeekTask;
 
-  // This method discards the seek task and then get the ownership of
-  // MedaiDecoderReaderWarpper back via registering MDSM's callback into it.
-  void DiscardSeekTaskIfExist();
-
   // Media Fragment end time in microseconds. Access controlled by decoder monitor.
   int64_t mFragmentEndTime;
 
   // The media sink resource.  Used on the state machine thread.
   RefPtr<media::MediaSink> mMediaSink;
 
   const RefPtr<MediaDecoderReaderWrapper> mReader;