Bug 1300956. Part 5 - Implement DecodingState. draft
authorJW Wang <jwwang@mozilla.com>
Tue, 06 Sep 2016 11:14:09 +0800
changeset 411524 8eed1251dbbc32fbb0a9c15b12fb6bd25ec553d8
parent 411523 5bbc75a7205599022d978fb40e744a2ac50fc45c
child 411525 c615a4e5fadf579fba4fa2bec415a8adb4888577
push id28915
push userjwwang@mozilla.com
push dateThu, 08 Sep 2016 07:23:46 +0000
bugs1300956
milestone51.0a1
Bug 1300956. Part 5 - Implement DecodingState. MozReview-Commit-ID: Kx5oRrT8DD0
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -285,16 +285,38 @@ public:
   }
 
   State GetState() const override
   {
     return DECODER_STATE_DECODING_FIRSTFRAME;
   }
 };
 
+class MediaDecoderStateMachine::DecodingState
+  : public MediaDecoderStateMachine::StateObject
+{
+public:
+  explicit DecodingState(Master* aPtr) : StateObject(aPtr) {}
+
+  void Enter() override
+  {
+    mMaster->StartDecoding();
+  }
+
+  void Step() override
+  {
+    mMaster->StepDecoding();
+  }
+
+  State GetState() const override
+  {
+    return DECODER_STATE_DECODING;
+  }
+};
+
 #define INIT_WATCHABLE(name, val) \
   name(val, "MediaDecoderStateMachine::" #name)
 #define INIT_MIRROR(name, val) \
   name(mTaskQueue, val, "MediaDecoderStateMachine::" #name " (Mirror)")
 #define INIT_CANONICAL(name, val) \
   name(mTaskQueue, val, "MediaDecoderStateMachine::" #name " (Canonical)")
 
 MediaDecoderStateMachine::MediaDecoderStateMachine(MediaDecoder* aDecoder,
@@ -1161,16 +1183,19 @@ MediaDecoderStateMachine::SetState(State
       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;
     default:
       mStateObj = nullptr;
       break;
   }
 
   EnterState();
 }
 
@@ -1204,19 +1229,16 @@ MediaDecoderStateMachine::EnterState()
 
   if (mStateObj) {
     MOZ_ASSERT(mState == mStateObj->GetState());
     mStateObj->Enter();
     return;
   }
 
   switch (mState) {
-    case DECODER_STATE_DECODING:
-      StartDecoding();
-      break;
     case DECODER_STATE_BUFFERING:
       StartBuffering();
       break;
     case DECODER_STATE_COMPLETED:
       ScheduleStateMachine();
       break;
     case DECODER_STATE_SHUTDOWN:
       mIsShutdown = true;
@@ -2370,19 +2392,16 @@ MediaDecoderStateMachine::RunStateMachin
   mDispatchedStateMachine = false;
 
   if (mStateObj) {
     mStateObj->Step();
     return;
   }
 
   switch (mState) {
-    case DECODER_STATE_DECODING:
-      StepDecoding();
-      return;
     case DECODER_STATE_BUFFERING:
       StepBuffering();
       return;
     case DECODER_STATE_COMPLETED:
       StepCompleted();
       return;
     default:
       return;