Bug 1319706. Part 1 - remove DecodingFirstFrameState::mPendingSeek since it can handle seek requests immediately. r=kaku
authorJW Wang <jwwang@mozilla.com>
Wed, 23 Nov 2016 17:48:48 +0800
changeset 324617 8aaa89d73c3fe8540a6b6d20693a9447951690e9
parent 324616 5bb030f09be53e66f8cf397e3a51e1eabee8d7a6
child 324618 03144421b4a60da0fa4cbaf0548252bb2af3dc5a
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +0000
reviewerskaku
bugs1319706
milestone53.0a1
Bug 1319706. Part 1 - remove DecodingFirstFrameState::mPendingSeek since it can handle seek requests immediately. r=kaku MozReview-Commit-ID: I2lI63s46GQ
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -457,34 +457,27 @@ private:
   SeekJob mPendingSeek;
 };
 
 /**
  * Purpose: decode the 1st audio and video frames to fire the 'loadeddata' event.
  *
  * Transition to:
  *   SHUTDOWN if any decode error.
- *   SEEKING if any pending seek and seek is possible.
+ *   SEEKING if any seek request.
  *   DECODING when the 'loadeddata' event is fired.
  */
 class MediaDecoderStateMachine::DecodingFirstFrameState
   : public MediaDecoderStateMachine::StateObject
 {
 public:
   explicit DecodingFirstFrameState(Master* aPtr) : StateObject(aPtr) {}
 
   void Enter(SeekJob aPendingSeek);
 
-  void Exit() override
-  {
-    // mPendingSeek is either moved before transition to SEEKING,
-    // or should be rejected here before transition to SHUTDOWN.
-    mPendingSeek.RejectIfExists(__func__);
-  }
-
   State GetState() const override
   {
     return DECODER_STATE_DECODING_FIRSTFRAME;
   }
 
   void HandleAudioDecoded(MediaData* aAudio) override
   {
     mMaster->Push(aAudio);
@@ -497,35 +490,31 @@ public:
     MaybeFinishDecodeFirstFrame();
   }
 
   void HandleEndOfStream() override
   {
     MaybeFinishDecodeFirstFrame();
   }
 
-  RefPtr<MediaDecoder::SeekPromise> HandleSeek(SeekTarget aTarget) override;
-
   void HandleVideoSuspendTimeout() override
   {
     // Do nothing for we need to decode the 1st video frame to get the dimensions.
   }
 
   void HandleResumeVideoDecoding() override
   {
     // We never suspend video decoding in this state.
     MOZ_ASSERT(false, "Shouldn't have suspended video decoding.");
   }
 
 private:
   // Notify FirstFrameLoaded if having decoded first frames and
   // transition to SEEKING if there is any pending seek, or DECODING otherwise.
   void MaybeFinishDecodeFirstFrame();
-
-  SeekJob mPendingSeek;
 };
 
 /**
  * Purpose: decode audio/video data for playback.
  *
  * Transition to:
  *   DORMANT if playback is paused for a while.
  *   SEEKING if any seek request.
@@ -1305,77 +1294,46 @@ WaitForCDMState::HandleCDMProxyReady()
   SetState<DecodingFirstFrameState>(Move(mPendingSeek));
 }
 
 void
 MediaDecoderStateMachine::
 DecodingFirstFrameState::Enter(SeekJob aPendingSeek)
 {
   // Handle pending seek.
-  if (aPendingSeek.Exists() &&
-      (mMaster->mSentFirstFrameLoadedEvent ||
-       Reader()->ForceZeroStartTime())) {
+  if (aPendingSeek.Exists()) {
     SetState<SeekingState>(Move(aPendingSeek), EventVisibility::Observable);
     return;
   }
 
   // Transition to DECODING if we've decoded first frames.
   if (mMaster->mSentFirstFrameLoadedEvent) {
     SetState<DecodingState>();
     return;
   }
 
   MOZ_ASSERT(!mMaster->mVideoDecodeSuspended);
 
-  mPendingSeek = Move(aPendingSeek);
-
   // Dispatch tasks to decode first frames.
   mMaster->DispatchDecodeTasksIfNeeded();
 }
 
-RefPtr<MediaDecoder::SeekPromise>
-MediaDecoderStateMachine::
-DecodingFirstFrameState::HandleSeek(SeekTarget aTarget)
-{
-  // Should've transitioned to DECODING in Enter()
-  // if mSentFirstFrameLoadedEvent is true.
-  MOZ_ASSERT(!mMaster->mSentFirstFrameLoadedEvent);
-
-  if (!Reader()->ForceZeroStartTime()) {
-    SLOG("Not Enough Data to seek at this stage, queuing seek");
-    mPendingSeek.RejectIfExists(__func__);
-    mPendingSeek.mTarget = aTarget;
-    return mPendingSeek.mPromise.Ensure(__func__);
-  }
-
-  // Since ForceZeroStartTime() is true, we should've transitioned to SEEKING
-  // in Enter() if there is any pending seek.
-  MOZ_ASSERT(!mPendingSeek.Exists());
-
-  return StateObject::HandleSeek(aTarget);
-}
-
 void
 MediaDecoderStateMachine::
 DecodingFirstFrameState::MaybeFinishDecodeFirstFrame()
 {
   MOZ_ASSERT(!mMaster->mSentFirstFrameLoadedEvent);
 
   if ((mMaster->IsAudioDecoding() && AudioQueue().GetSize() == 0) ||
       (mMaster->IsVideoDecoding() && VideoQueue().GetSize() == 0)) {
     return;
   }
 
   mMaster->FinishDecodeFirstFrame();
-
-  if (mPendingSeek.Exists()) {
-    SetState<SeekingState>(Move(mPendingSeek), EventVisibility::Observable);
-  } else {
-    SetState<DecodingState>();
-  }
+  SetState<DecodingState>();
 }
 
 void
 MediaDecoderStateMachine::
 DecodingState::Enter()
 {
   MOZ_ASSERT(mMaster->mSentFirstFrameLoadedEvent);