Bug 1329098. Part 1 - copy DispatchDecodeTasksIfNeeded() into BufferingState. draft
authorJW Wang <jwwang@mozilla.com>
Fri, 06 Jan 2017 15:00:36 +0800
changeset 457495 cdc7a1f3941465745814d1807f6faec15e9d09b9
parent 457494 dd70f490ed45e3eb5b92f2ceb89fceaefc4aa304
child 457496 ce248528ce1b28c6d64bed9e0c824850837b6be8
push id40791
push userjwwang@mozilla.com
push dateMon, 09 Jan 2017 03:31:36 +0000
bugs1329098
milestone53.0a1
Bug 1329098. Part 1 - copy DispatchDecodeTasksIfNeeded() into BufferingState. 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",