Bug 1298217. Part 8 - Move some code to the entry action of DECODER_STATE_DECODING. draft
authorJW Wang <jwwang@mozilla.com>
Mon, 29 Aug 2016 11:46:08 +0800
changeset 406601 7b6afa7870103e2a2b47132edc363b1e465a7ba4
parent 406600 7ffcbf4ca19705722bacfa2a534094463c240818
child 406602 daf935dd80cfdbe95cd18cfb3d402c62d695a701
push id27772
push userjwwang@mozilla.com
push dateMon, 29 Aug 2016 06:35:00 +0000
bugs1298217
milestone51.0a1
Bug 1298217. Part 8 - Move some code to the entry action of DECODER_STATE_DECODING. MozReview-Commit-ID: 1gzwIX566i
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1090,16 +1090,19 @@ MediaDecoderStateMachine::EnterState(Sta
     case DECODER_STATE_DORMANT:
       DiscardSeekTaskIfExist();
       if (IsPlaying()) {
         StopPlayback();
       }
       Reset();
       mReader->ReleaseResources();
       break;
+    case DECODER_STATE_DECODING:
+      StartDecoding();
+      break;
     case DECODER_STATE_COMPLETED:
       ScheduleStateMachine();
       break;
     case DECODER_STATE_ERROR:
     case DECODER_STATE_SHUTDOWN:
       mIsShutdown = true;
       break;
     default:
@@ -1251,21 +1254,21 @@ MediaDecoderStateMachine::Shutdown()
   // the queue to spin down.
   return mReader->Shutdown()
     ->Then(OwnerThread(), __func__, this,
            &MediaDecoderStateMachine::FinishShutdown,
            &MediaDecoderStateMachine::FinishShutdown)
     ->CompletionPromise();
 }
 
-void MediaDecoderStateMachine::StartDecoding()
+void
+MediaDecoderStateMachine::StartDecoding()
 {
   MOZ_ASSERT(OnTaskQueue());
-  MOZ_ASSERT(mState != DECODER_STATE_DECODING);
-  SetState(DECODER_STATE_DECODING);
+  MOZ_ASSERT(mState == DECODER_STATE_DECODING);
 
   if (mDecodingFirstFrame && mSentFirstFrameLoadedEvent) {
     // We're resuming from dormant state, so we don't need to request
     // the first samples in order to determine the media start time,
     // we have the start time from last time we loaded.
     // FinishDecodeFirstFrame will be launched upon completion of the seek when
     // we have data ready to play.
     MOZ_ASSERT(mQueuedSeek.Exists() && mSentFirstFrameLoadedEvent,
@@ -1324,17 +1327,17 @@ void MediaDecoderStateMachine::PlayState
     DECODER_LOG("Unexpected state - Bailing out of PlayInternal()");
     return;
   }
 
   // When asked to play, switch to decoding state only if
   // we are currently buffering. In other cases, we'll start playing anyway
   // when the state machine notices the decoder's state change to PLAYING.
   if (mState == DECODER_STATE_BUFFERING) {
-    StartDecoding();
+    SetState(DECODER_STATE_DECODING);
   }
 
   ScheduleStateMachine();
 }
 
 static void
 ReportRecoveryTelemetry(const TimeStamp& aRecoveryStart,
                         const MediaInfo& aMediaInfo,
@@ -2023,17 +2026,17 @@ MediaDecoderStateMachine::OnMetadataRead
 
   if (waitingForCDM) {
     // Metadata parsing was successful but we're still waiting for CDM caps
     // to become available so that we can build the correct decryptor/decoder.
     SetState(DECODER_STATE_WAIT_FOR_CDM);
     return;
   }
 
-  StartDecoding();
+  SetState(DECODER_STATE_DECODING);
 
   ScheduleStateMachine();
 }
 
 void
 MediaDecoderStateMachine::OnMetadataNotRead(ReadMetadataFailureReason aReason)
 {
   MOZ_ASSERT(OnTaskQueue());
@@ -2182,17 +2185,17 @@ MediaDecoderStateMachine::SeekCompleted(
 
   if (mDecodingFirstFrame) {
     // We were resuming from dormant, or initiated a seek early.
     // We can fire loadeddata now.
     FinishDecodeFirstFrame();
   }
 
   if (nextState == DECODER_STATE_DECODING) {
-    StartDecoding();
+    SetState(DECODER_STATE_DECODING);
   } else {
     SetState(nextState);
   }
 
   // Ensure timestamps are up to date.
   UpdatePlaybackPositionInternal(newCurrentTime);
 
   // Try to decode another frame to detect if we're at the end...
@@ -2341,17 +2344,17 @@ nsresult MediaDecoderStateMachine::RunSt
                     "mAudioStatus: %s, outOfVideo: %d, mVideoStatus: %s",
                     OutOfDecodedAudio(), AudioRequestStatus(),
                     OutOfDecodedVideo(), VideoRequestStatus());
         return NS_OK;
       }
 
       DECODER_LOG("Changed state from BUFFERING to DECODING");
       DECODER_LOG("Buffered for %.3lfs", (now - mBufferingStart).ToSeconds());
-      StartDecoding();
+      SetState(DECODER_STATE_DECODING);
 
       NS_ASSERTION(IsStateMachineScheduled(), "Must have timer scheduled");
       return NS_OK;
     }
 
     case DECODER_STATE_SEEKING: {
       return NS_OK;
     }
@@ -2759,17 +2762,17 @@ void MediaDecoderStateMachine::OnMediaSi
 void
 MediaDecoderStateMachine::OnCDMProxyReady(RefPtr<CDMProxy> aProxy)
 {
   MOZ_ASSERT(OnTaskQueue());
   mCDMProxyPromise.Complete();
   mCDMProxy = aProxy;
   mReader->SetCDMProxy(aProxy);
   if (mState == DECODER_STATE_WAIT_FOR_CDM) {
-    StartDecoding();
+    SetState(DECODER_STATE_DECODING);
   }
 }
 
 void
 MediaDecoderStateMachine::OnCDMProxyNotReady()
 {
   MOZ_ASSERT(OnTaskQueue());
   mCDMProxyPromise.Complete();