Bug 1303655. Part 3 - Move mDecodeStartTime into Decodingstate. draft
authorJW Wang <jwwang@mozilla.com>
Tue, 06 Sep 2016 16:59:02 +0800
changeset 415336 6b1e41f8a8e62beb94ff5d9809c36f0243956d24
parent 415335 105b38cf5763d4c4669071fb0135213a3f804b92
child 415772 956bc7baa3db23631675fcb27a6e3e1b8dcf1ab1
child 415896 ab63055bd65e37c0e1d3ce9672129eae85055a2e
push id29852
push userjwwang@mozilla.com
push dateTue, 20 Sep 2016 06:50:15 +0000
bugs1303655
milestone51.0a1
Bug 1303655. Part 3 - Move mDecodeStartTime into Decodingstate. MozReview-Commit-ID: ELUr9AHaE2P
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -435,39 +435,51 @@ public:
     // transitioning to DECODING.
     MOZ_ASSERT(!mMaster->mQueuedSeek.Exists());
 
     if (mMaster->CheckIfDecodeComplete()) {
       SetState(DECODER_STATE_COMPLETED);
       return;
     }
 
-    mMaster->mDecodeStartTime = TimeStamp::Now();
+    mDecodeStartTime = TimeStamp::Now();
 
     // Reset other state to pristine values before starting decode.
     mMaster->mIsAudioPrerolling = !mMaster->DonePrerollingAudio() &&
                                   !Reader()->IsWaitingAudioData();
     mMaster->mIsVideoPrerolling = !mMaster->DonePrerollingVideo() &&
                                   !Reader()->IsWaitingVideoData();
 
     // Ensure that we've got tasks enqueued to decode data if we need to.
     mMaster->DispatchDecodeTasksIfNeeded();
 
     mMaster->ScheduleStateMachine();
   }
 
+  void Exit() override
+  {
+    if (!mDecodeStartTime.IsNull()) {
+      TimeDuration decodeDuration = TimeStamp::Now() - mDecodeStartTime;
+      SLOG("Exiting DECODING, decoded for %.3lfs", decodeDuration.ToSeconds());
+    }
+  }
+
   void Step() override
   {
     mMaster->StepDecoding();
   }
 
   State GetState() const override
   {
     return DECODER_STATE_DECODING;
   }
+
+private:
+  // Time at which we started decoding.
+  TimeStamp mDecodeStartTime;
 };
 
 class MediaDecoderStateMachine::SeekingState
   : public MediaDecoderStateMachine::StateObject
 {
 public:
   explicit SeekingState(Master* aPtr) : StateObject(aPtr) {}
 
@@ -2729,21 +2741,18 @@ MediaDecoderStateMachine::StartBuffering
 {
   MOZ_ASSERT(OnTaskQueue());
   MOZ_ASSERT(mState == DECODER_STATE_BUFFERING);
 
   if (IsPlaying()) {
     StopPlayback();
   }
 
-  TimeDuration decodeDuration = TimeStamp::Now() - mDecodeStartTime;
   mBufferingStart = TimeStamp::Now();
 
-  DECODER_LOG("Changed state from DECODING to BUFFERING, decoded for %.3lfs",
-              decodeDuration.ToSeconds());
   MediaStatistics stats = GetStatistics();
   DECODER_LOG("Playback rate: %.1lfKB/s%s download rate: %.1lfKB/s%s",
               stats.mPlaybackRate/1024, stats.mPlaybackRateReliable ? "" : " (unreliable)",
               stats.mDownloadRate/1024, stats.mDownloadRateReliable ? "" : " (unreliable)");
 
   // Don't go straight back to the state machine loop since that might
   // cause us to start decoding again and we could flip-flop between
   // decoding and quick-buffering.
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -670,19 +670,16 @@ private:
 
   // The end time of the last decoded video frame. Used to check if we are low
   // on decoded video data.
   int64_t mDecodedVideoEndTime;
 
   // Playback rate. 1.0 : normal speed, 0.5 : two times slower.
   double mPlaybackRate;
 
-  // Time at which we started decoding. Synchronised via decoder monitor.
-  TimeStamp mDecodeStartTime;
-
   // The maximum number of second we spend buffering when we are short on
   // unbuffered data.
   uint32_t mBufferingWait;
   int64_t  mLowDataThresholdUsecs;
 
   // If we've got more than this number of decoded video frames waiting in
   // the video queue, we will not decode any more video frames until some have
   // been consumed by the play state machine thread.