Bug 1298217. Part 5 - Move the call to |SetState(DECODER_STATE_COMPLETED)| out of CheckIfDecodeComplete() to make it easier to move more code to entry actions. draft
authorJW Wang <jwwang@mozilla.com>
Fri, 26 Aug 2016 06:18:53 +1200
changeset 406598 1402d7f069af0b835827563b6745af93ec9fe4df
parent 406597 cb0362f9ec8946289e12ba8238d6ee0c884e0ef2
child 406599 7d4ec09265558221cd8a4bfa14168fe8df965988
push id27772
push userjwwang@mozilla.com
push dateMon, 29 Aug 2016 06:35:00 +0000
bugs1298217
milestone51.0a1
Bug 1298217. Part 5 - Move the call to |SetState(DECODER_STATE_COMPLETED)| out of CheckIfDecodeComplete() to make it easier to move more code to entry actions. MozReview-Commit-ID: 7nJTIGwPyCs
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -709,18 +709,21 @@ MediaDecoderStateMachine::OnNotDecoded(M
     StopPrerollingVideo();
   }
   switch (mState) {
     case DECODER_STATE_BUFFERING:
     case DECODER_STATE_DECODING: {
       if (MaybeFinishDecodeFirstFrame()) {
         return;
       }
-      CheckIfDecodeComplete();
-
+      if (CheckIfDecodeComplete()) {
+        SetState(DECODER_STATE_COMPLETED);
+        ScheduleStateMachine();
+        return;
+      }
       // Schedule next cycle to see if we can leave buffering state.
       if (mState == DECODER_STATE_BUFFERING) {
         ScheduleStateMachine();
       }
       return;
     }
     default: {
       return;
@@ -819,31 +822,23 @@ MediaDecoderStateMachine::IsAudioDecodin
 
 bool
 MediaDecoderStateMachine::IsVideoDecoding()
 {
   MOZ_ASSERT(OnTaskQueue());
   return HasVideo() && !VideoQueue().IsFinished();
 }
 
-void
+bool
 MediaDecoderStateMachine::CheckIfDecodeComplete()
 {
   MOZ_ASSERT(OnTaskQueue());
   MOZ_ASSERT(mState == DECODER_STATE_DECODING ||
              mState == DECODER_STATE_BUFFERING);
-
-  if (!IsVideoDecoding() && !IsAudioDecoding()) {
-    // We've finished decoding all active streams,
-    // so move to COMPLETED state.
-    SetState(DECODER_STATE_COMPLETED);
-    ScheduleStateMachine();
-  }
-  DECODER_LOG("CheckIfDecodeComplete %scompleted",
-              ((mState == DECODER_STATE_COMPLETED) ? "" : "NOT "));
+  return !IsVideoDecoding() && !IsAudioDecoding();
 }
 
 bool MediaDecoderStateMachine::IsPlaying() const
 {
   MOZ_ASSERT(OnTaskQueue());
   return mMediaSink->IsPlaying();
 }
 
@@ -1277,23 +1272,24 @@ void MediaDecoderStateMachine::StartDeco
                "Return from dormant must have queued seek");
 
     if (mQueuedSeek.Exists()) {
       InitiateSeek(Move(mQueuedSeek));
       return;
     }
   }
 
-  mDecodeStartTime = TimeStamp::Now();
-
-  CheckIfDecodeComplete();
-  if (mState == DECODER_STATE_COMPLETED) {
+  if (CheckIfDecodeComplete()) {
+    SetState(DECODER_STATE_COMPLETED);
+    ScheduleStateMachine();
     return;
   }
 
+  mDecodeStartTime = TimeStamp::Now();
+
   // Reset other state to pristine values before starting decode.
   mIsAudioPrerolling = !DonePrerollingAudio() && !mReader->IsWaitingAudioData();
   mIsVideoPrerolling = !DonePrerollingVideo() && !mReader->IsWaitingVideoData();
 
   // Ensure that we've got tasks enqueued to decode data if we need to.
   DispatchDecodeTasksIfNeeded();
 
   ScheduleStateMachine();
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -571,20 +571,17 @@ protected:
   // Return true if we are currently decoding the first frames.
   bool IsDecodingFirstFrame();
   void FinishDecodeFirstFrame();
 
   // Completes the seek operation, moves onto the next appropriate state.
   void SeekCompleted();
 
   // Queries our state to see whether the decode has finished for all streams.
-  // If so, we move into DECODER_STATE_COMPLETED and schedule the state machine
-  // to run.
-  // The decoder monitor must be held.
-  void CheckIfDecodeComplete();
+  bool CheckIfDecodeComplete();
 
   // Performs one "cycle" of the state machine. Polls the state, and may send
   // a video frame to be displayed, and generally manages the decode. Called
   // periodically via timer to ensure the video stays in sync.
   nsresult RunStateMachine();
 
   bool IsStateMachineScheduled() const;