Bug 1309116. Part 4 - fix remaining calls to MDSM::SetState() and remove unused functions. draft
authorJW Wang <jwwang@mozilla.com>
Tue, 11 Oct 2016 14:58:29 +0800
changeset 425046 77c4344c0366d6e57d1a14d53e23e2ee4287bcde
parent 425045 5f32414bc1448b8dbb6586141117b65548118cdf
child 425086 12781511089734d4311c75d8797a85110d968d33
push id32322
push userjwwang@mozilla.com
push dateFri, 14 Oct 2016 02:59:40 +0000
bugs1309116
milestone52.0a1
Bug 1309116. Part 4 - fix remaining calls to MDSM::SetState() and remove unused functions. MozReview-Commit-ID: EytZ8qrQJRn
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1964,17 +1964,17 @@ MediaDecoderStateMachine::MaybeStartBuff
   if (mReader->UseBufferingHeuristics()) {
     shouldBuffer = HasLowDecodedData() && HasLowBufferedData();
   } else {
     MOZ_ASSERT(mReader->IsWaitForDataSupported());
     shouldBuffer = (OutOfDecodedAudio() && mReader->IsWaitingAudioData()) ||
                    (OutOfDecodedVideo() && mReader->IsWaitingVideoData());
   }
   if (shouldBuffer) {
-    SetState(DECODER_STATE_BUFFERING);
+    mStateObj->SetState<BufferingState>();
   }
 }
 
 void MediaDecoderStateMachine::UpdatePlaybackPositionInternal(int64_t aTime)
 {
   MOZ_ASSERT(OnTaskQueue());
   SAMPLE_LOG("UpdatePlaybackPositionInternal(%lld)", aTime);
 
@@ -2017,64 +2017,16 @@ MediaDecoderStateMachine::ToStateStr(Sta
 
 const char*
 MediaDecoderStateMachine::ToStateStr()
 {
   MOZ_ASSERT(OnTaskQueue());
   return ToStateStr(mState);
 }
 
-void
-MediaDecoderStateMachine::SetState(State aState)
-{
-  MOZ_ASSERT(OnTaskQueue());
-  if (mState == aState) {
-    return;
-  }
-
-  DECODER_LOG("MDSM state: %s -> %s", ToStateStr(), ToStateStr(aState));
-
-  MOZ_ASSERT(mState == mStateObj->GetState());
-  mStateObj->Exit();
-  mState = aState;
-
-  switch (mState) {
-    case DECODER_STATE_DECODING_METADATA:
-      mStateObj = MakeUnique<DecodeMetadataState>(this);
-      break;
-    case DECODER_STATE_WAIT_FOR_CDM:
-      mStateObj = MakeUnique<WaitForCDMState>(this);
-      break;
-    case DECODER_STATE_DORMANT:
-      mStateObj = MakeUnique<DormantState>(this);
-      break;
-    case DECODER_STATE_DECODING_FIRSTFRAME:
-      mStateObj = MakeUnique<DecodingFirstFrameState>(this);
-      break;
-    case DECODER_STATE_DECODING:
-      mStateObj = MakeUnique<DecodingState>(this);
-      break;
-    case DECODER_STATE_BUFFERING:
-      mStateObj = MakeUnique<BufferingState>(this);
-      break;
-    case DECODER_STATE_COMPLETED:
-      mStateObj = MakeUnique<CompletedState>(this);
-      break;
-    case DECODER_STATE_SHUTDOWN:
-      mStateObj = MakeUnique<ShutdownState>(this);
-      break;
-    default:
-      MOZ_ASSERT_UNREACHABLE("Invalid state.");
-      break;
-  }
-
-  MOZ_ASSERT(mState == mStateObj->GetState());
-  mStateObj->Enter();
-}
-
 void MediaDecoderStateMachine::VolumeChanged()
 {
   MOZ_ASSERT(OnTaskQueue());
   mMediaSink->SetVolume(mVolume);
 }
 
 void MediaDecoderStateMachine::RecomputeDuration()
 {
@@ -2127,17 +2079,17 @@ MediaDecoderStateMachine::SetDormant(boo
   mStateObj->HandleDormant(aDormant);
 }
 
 RefPtr<ShutdownPromise>
 MediaDecoderStateMachine::Shutdown()
 {
   MOZ_ASSERT(OnTaskQueue());
 
-  SetState(DECODER_STATE_SHUTDOWN);
+  mStateObj->SetState<ShutdownState>();
 
   mDelayedScheduler.Reset();
 
   mBufferedUpdateRequest.DisconnectIfExists();
 
   mQueuedSeek.RejectIfExists(__func__);
 
   // Shutdown happens will decode timer is active, we need to disconnect and
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -342,18 +342,16 @@ private:
   // Resets all state related to decoding and playback, emptying all buffers
   // and aborting all pending operations on the decode task queue.
   void Reset(TrackSet aTracks = TrackSet(TrackInfo::kAudioTrack,
                                          TrackInfo::kVideoTrack));
 
 protected:
   virtual ~MediaDecoderStateMachine();
 
-  void SetState(State aState);
-
   void BufferedRangeUpdated();
 
   void ReaderSuspendedChanged();
 
   // Inserts MediaData* samples into their respective MediaQueues.
   // aSample must not be null.
 
   void Push(MediaData* aSample, MediaData::Type aSampleType);