Bug 1329098. Part 1 - copy DispatchDecodeTasksIfNeeded() into BufferingState. r=kaku
authorJW Wang <jwwang@mozilla.com>
Fri, 06 Jan 2017 15:00:36 +0800
changeset 328524 c6bd3e871b126bbaf4319a1bb02f32ebdb03e0d8
parent 328523 7ec0bc99f5cf170d3cd0b39a9ce42f4f6c7c4bab
child 328525 17d0086ac024660fd2a9de21eefd3261d2366a2c
push id31178
push userkwierso@gmail.com
push dateTue, 10 Jan 2017 00:30:08 +0000
treeherdermozilla-central@6bcc24319ba5 [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 1 - copy DispatchDecodeTasksIfNeeded() into BufferingState. r=kaku MozReview-Commit-ID: 2q8FhTFTJ6g
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1498,16 +1498,18 @@ public:
     if (mMaster->HasVideo()) {
       mMaster->mVideoDecodeSuspended = true;
       mMaster->mOnPlaybackEvent.Notify(MediaEventType::EnterVideoSuspend);
       Reader()->SetVideoBlankDecode(true);
     }
   }
 
 private:
+  void DispatchDecodeTasksIfNeeded();
+
   TimeStamp mBufferingStart;
 
   // The maximum number of second we spend buffering when we are short on
   // unbuffered data.
   const uint32_t mBufferingWait = 15;
 };
 
 /**
@@ -2209,16 +2211,39 @@ NextFrameSeekingState::HandleVideoNotDec
     default:
       // Raise an error since we can't finish video seek anyway.
       mMaster->DecodeError(aError);
   }
 }
 
 void
 MediaDecoderStateMachine::
+BufferingState::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::
 BufferingState::Step()
 {
   TimeStamp now = TimeStamp::Now();
   MOZ_ASSERT(!mBufferingStart.IsNull(), "Must know buffering start time.");
 
   // With buffering heuristics we will remain in the buffering state if
   // we've not decoded enough data to begin playback, or if we've not
   // downloaded a reasonable amount of data inside our buffering time.
@@ -2227,21 +2252,21 @@ BufferingState::Step()
     bool isLiveStream = Resource()->IsLiveStream();
     if ((isLiveStream || !mMaster->CanPlayThrough()) &&
         elapsed < TimeDuration::FromSeconds(mBufferingWait * mMaster->mPlaybackRate) &&
         mMaster->HasLowBufferedData(mBufferingWait * USECS_PER_S) &&
         IsExpectingMoreData()) {
       SLOG("Buffering: wait %ds, timeout in %.3lfs",
            mBufferingWait, mBufferingWait - elapsed.ToSeconds());
       mMaster->ScheduleStateMachineIn(USECS_PER_S);
-      mMaster->DispatchDecodeTasksIfNeeded();
+      DispatchDecodeTasksIfNeeded();
       return;
     }
   } else if (mMaster->OutOfDecodedAudio() || mMaster->OutOfDecodedVideo()) {
-    mMaster->DispatchDecodeTasksIfNeeded();
+    DispatchDecodeTasksIfNeeded();
     MOZ_ASSERT(!mMaster->OutOfDecodedAudio() ||
                mMaster->IsRequestingAudioData() ||
                mMaster->IsWaitingAudioData());
     MOZ_ASSERT(!mMaster->OutOfDecodedVideo() ||
                mMaster->IsRequestingVideoData() ||
                mMaster->IsWaitingVideoData());
     SLOG("In buffering mode, waiting to be notified: outOfAudio: %d, "
          "mAudioStatus: %s, outOfVideo: %d, mVideoStatus: %s",