Bug 1329098. Part 4 - move DispatchDecodeTasksIfNeeded into DecodingState. r=kaku
authorJW Wang <jwwang@mozilla.com>
Fri, 06 Jan 2017 15:43:31 +0800
changeset 328494 8f579fb33b2574df84cd832d96fffa9cdfa2a80e
parent 328493 e675289447f5f45b59333a07cd4eefba25391670
child 328495 c00b89907a83d023448bffe7ad48e65dbc2a900a
push id35790
push userjwwang@mozilla.com
push dateMon, 09 Jan 2017 07:22:01 +0000
treeherderautoland@c00b89907a83 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskaku
bugs1329098
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1329098. Part 4 - move DispatchDecodeTasksIfNeeded into DecodingState. r=kaku MozReview-Commit-ID: LT9xNdTAtOW
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -587,24 +587,24 @@ public:
   State GetState() const override
   {
     return DECODER_STATE_DECODING;
   }
 
   void HandleAudioDecoded(MediaData* aAudio) override
   {
     mMaster->PushAudio(aAudio);
-    mMaster->DispatchDecodeTasksIfNeeded();
+    DispatchDecodeTasksIfNeeded();
     MaybeStopPrerolling();
   }
 
   void HandleVideoDecoded(MediaData* aVideo, TimeStamp aDecodeStart) override
   {
     mMaster->PushVideo(aVideo);
-    mMaster->DispatchDecodeTasksIfNeeded();
+    DispatchDecodeTasksIfNeeded();
     MaybeStopPrerolling();
     CheckSlowDecoding(aDecodeStart);
   }
 
   void HandleEndOfStream() override;
 
   void HandleWaitingForData() override
   {
@@ -628,32 +628,33 @@ public:
   }
 
   void HandlePlayStateChanged(MediaDecoder::PlayState aPlayState) override
   {
     if (aPlayState == MediaDecoder::PLAY_STATE_PLAYING) {
       // Schedule Step() to check if we can start playback.
       mMaster->ScheduleStateMachine();
       // Try to dispatch decoding tasks for mMinimizePreroll might be reset.
-      mMaster->DispatchDecodeTasksIfNeeded();
+      DispatchDecodeTasksIfNeeded();
     }
 
     if (aPlayState == MediaDecoder::PLAY_STATE_PAUSED) {
       StartDormantTimer();
     } else {
       mDormantTimer.Reset();
     }
   }
 
   void DumpDebugInfo() override
   {
     SDUMP("mIsPrerolling=%d", mIsPrerolling);
   }
 
 private:
+  void DispatchDecodeTasksIfNeeded();
   void MaybeStartBuffering();
 
   void CheckSlowDecoding(TimeStamp aDecodeStart)
   {
     // For non async readers, if the requested video sample was slow to
     // arrive, increase the amount of audio we buffer to ensure that we
     // don't run out of audio. This is unnecessary for async readers,
     // since they decode audio and video on different threads so they
@@ -2015,17 +2016,17 @@ DecodingState::Enter()
 
   mMaster->UpdateNextFrameStatus(MediaDecoderOwner::NEXT_FRAME_AVAILABLE);
 
   mDecodeStartTime = TimeStamp::Now();
 
   MaybeStopPrerolling();
 
   // Ensure that we've got tasks enqueued to decode data if we need to.
-  mMaster->DispatchDecodeTasksIfNeeded();
+  DispatchDecodeTasksIfNeeded();
 
   mMaster->ScheduleStateMachine();
 
   // Will enter dormant when playback is paused for a while.
   if (mMaster->mPlayState == MediaDecoder::PLAY_STATE_PAUSED) {
     StartDormantTimer();
   }
 }
@@ -2038,16 +2039,39 @@ DecodingState::HandleEndOfStream()
     SetState<CompletedState>();
   } else {
     MaybeStopPrerolling();
   }
 }
 
 void
 MediaDecoderStateMachine::
+DecodingState::DispatchDecodeTasksIfNeeded()
+{
+  const bool needToDecodeAudio =
+    mMaster->IsAudioDecoding() &&
+    ((!mMaster->mSentFirstFrameLoadedEvent && AudioQueue().GetSize() == 0) ||
+     (!mMaster->mMinimizePreroll && !mMaster->HaveEnoughDecodedAudio()));
+
+  const bool needToDecodeVideo =
+    mMaster->IsVideoDecoding() &&
+    ((!mMaster->mSentFirstFrameLoadedEvent && VideoQueue().GetSize() == 0) ||
+     (!mMaster->mMinimizePreroll && !mMaster->HaveEnoughDecodedVideo()));
+
+  if (needToDecodeAudio) {
+    mMaster->EnsureAudioDecodeTaskQueued();
+  }
+
+  if (needToDecodeVideo) {
+    mMaster->EnsureVideoDecodeTaskQueued();
+  }
+}
+
+void
+MediaDecoderStateMachine::
 DecodingState::MaybeStartBuffering()
 {
   // Buffering makes senses only after decoding first frames.
   MOZ_ASSERT(mMaster->mSentFirstFrameLoadedEvent);
 
   // Don't enter buffering when MediaDecoder is not playing.
   if (mMaster->mPlayState != MediaDecoder::PLAY_STATE_PLAYING) {
     return;
@@ -2941,49 +2965,16 @@ void MediaDecoderStateMachine::StopMedia
 
     mMediaSink->Stop();
     mMediaSinkAudioPromise.DisconnectIfExists();
     mMediaSinkVideoPromise.DisconnectIfExists();
   }
 }
 
 void
-MediaDecoderStateMachine::DispatchDecodeTasksIfNeeded()
-{
-  MOZ_ASSERT(OnTaskQueue());
-
-  if (mState != DECODER_STATE_DECODING &&
-      mState != DECODER_STATE_DECODING_FIRSTFRAME &&
-      mState != DECODER_STATE_BUFFERING) {
-    return;
-  }
-
-  const bool needToDecodeAudio =
-    IsAudioDecoding() &&
-    ((!mSentFirstFrameLoadedEvent && AudioQueue().GetSize() == 0) ||
-     (!mMinimizePreroll && !HaveEnoughDecodedAudio()));
-
-  const bool needToDecodeVideo =
-    IsVideoDecoding() &&
-    ((!mSentFirstFrameLoadedEvent && VideoQueue().GetSize() == 0) ||
-     (!mMinimizePreroll && !HaveEnoughDecodedVideo()));
-
-  SAMPLE_LOG("DispatchDecodeTasksIfNeeded needAudio=%d audioStatus=%s needVideo=%d videoStatus=%s",
-             needToDecodeAudio, AudioRequestStatus(),
-             needToDecodeVideo, VideoRequestStatus());
-
-  if (needToDecodeAudio) {
-    EnsureAudioDecodeTaskQueued();
-  }
-  if (needToDecodeVideo) {
-    EnsureVideoDecodeTaskQueued();
-  }
-}
-
-void
 MediaDecoderStateMachine::EnsureAudioDecodeTaskQueued()
 {
   MOZ_ASSERT(OnTaskQueue());
   MOZ_ASSERT(mState != DECODER_STATE_SEEKING);
   MOZ_ASSERT(mState != DECODER_STATE_DECODING_FIRSTFRAME);
 
   SAMPLE_LOG("EnsureAudioDecodeTaskQueued isDecoding=%d status=%s",
               IsAudioDecoding(), AudioRequestStatus());
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -423,22 +423,16 @@ protected:
 
   void WaitForData(MediaData::Type aType);
 
   bool IsRequestingAudioData() const { return mAudioDataRequest.Exists(); }
   bool IsRequestingVideoData() const { return mVideoDataRequest.Exists(); }
   bool IsWaitingAudioData() const { return mAudioWaitRequest.Exists(); }
   bool IsWaitingVideoData() const { return mVideoWaitRequest.Exists(); }
 
-  // Re-evaluates the state and determines whether we need to dispatch
-  // events to run the decode, or if not whether we should set the reader
-  // to idle mode. This is threadsafe, and can be called from any thread.
-  // The decoder monitor must be held.
-  void DispatchDecodeTasksIfNeeded();
-
   // Returns the "media time". This is the absolute time which the media
   // playback has reached. i.e. this returns values in the range
   // [mStartTime, mEndTime], and mStartTime will not be 0 if the media does
   // not start at 0. Note this is different than the "current playback position",
   // which is in the range [0,duration].
   int64_t GetMediaTime() const {
     MOZ_ASSERT(OnTaskQueue());
     return mCurrentPosition;