Bug 1295893 - Add entry/exit actions to state transitions of MDSM. draft
authorJW Wang <jwwang@mozilla.com>
Fri, 12 Aug 2016 16:06:30 +0800
changeset 401588 5aef4514cf5916a6405b20886a26ba5e1f03a476
parent 401565 8e5a81f6de5a1b3a371eb5cca55809bdaf39b1e2
child 401598 a5dbcdcf3fcfc28902fa09df093dd235fd0b133c
child 401663 b641358c0d7e9d7974330d8035aa7c13dc232950
push id26501
push userjwwang@mozilla.com
push dateWed, 17 Aug 2016 06:38:59 +0000
bugs1295893
milestone51.0a1
Bug 1295893 - Add entry/exit actions to state transitions of MDSM. MozReview-Commit-ID: Ak17K7kEigC
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1056,31 +1056,56 @@ MediaDecoderStateMachine::ToStateStr(Sta
 
 const char*
 MediaDecoderStateMachine::ToStateStr()
 {
   MOZ_ASSERT(OnTaskQueue());
   return ToStateStr(mState);
 }
 
-void MediaDecoderStateMachine::SetState(State aState)
+void
+MediaDecoderStateMachine::SetState(State aState)
 {
   MOZ_ASSERT(OnTaskQueue());
   if (mState == aState) {
     return;
   }
-  DECODER_LOG("Change machine state from %s to %s",
-              ToStateStr(), ToStateStr(aState));
-
+
+  DECODER_LOG("MDSM state: %s -> %s", ToStateStr(), ToStateStr(aState));
+
+  ExitState(mState);
   mState = aState;
-
-  mIsShutdown = mState == DECODER_STATE_ERROR || mState == DECODER_STATE_SHUTDOWN;
-
-  // Clear state-scoped state.
-  mSentPlaybackEndedEvent = false;
+  EnterState(mState);
+}
+
+void
+MediaDecoderStateMachine::ExitState(State aState)
+{
+  MOZ_ASSERT(OnTaskQueue());
+  switch (aState) {
+    case DECODER_STATE_COMPLETED:
+      mSentPlaybackEndedEvent = false;
+      break;
+    default:
+      break;
+  }
+}
+
+void
+MediaDecoderStateMachine::EnterState(State aState)
+{
+  MOZ_ASSERT(OnTaskQueue());
+  switch (aState) {
+    case DECODER_STATE_ERROR:
+    case DECODER_STATE_SHUTDOWN:
+      mIsShutdown = true;
+      break;
+    default:
+      break;
+  }
 }
 
 void MediaDecoderStateMachine::VolumeChanged()
 {
   MOZ_ASSERT(OnTaskQueue());
   mMediaSink->SetVolume(mVolume);
 }
 
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -363,16 +363,18 @@ private:
   // 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 ExitState(State aState);
+  void EnterState(State aState);
 
   void BufferedRangeUpdated();
 
   void ReaderSuspendedChanged();
 
   // Inserts MediaData* samples into their respective MediaQueues.
   // aSample must not be null.