Bug 1306186. Part 3 - remove StopPrerolling{Audio,Video}. draft
authorJW Wang <jwwang@mozilla.com>
Thu, 29 Sep 2016 11:55:34 +0800
changeset 419972 08f9f4bd1b0644cbe540019b55ae087ec3670088
parent 419971 03aa59e75347cdafb33792bc8fe08c5824dfaede
child 419973 6ade0a74ae34f01819b4714fcfcf599eb392fdba
push id31057
push userjwwang@mozilla.com
push dateMon, 03 Oct 2016 02:44:04 +0000
bugs1306186
milestone52.0a1
Bug 1306186. Part 3 - remove StopPrerolling{Audio,Video}. Note we remove the calls from OnSeekTask{Resolved,Rejected} because DecodingState will decide whether to reset those flags. MozReview-Commit-ID: GjWvbxTqXMP
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1128,23 +1128,20 @@ MediaDecoderStateMachine::OnNotDecoded(M
 
   // If the decoder is waiting for data, we tell it to call us back when the
   // data arrives.
   if (aError == NS_ERROR_DOM_MEDIA_WAITING_FOR_DATA) {
     MOZ_ASSERT(mReader->IsWaitForDataSupported(),
                "Readers that send WAITING_FOR_DATA need to implement WaitForData");
     mReader->WaitForData(aType);
 
-    // We are out of data to decode and will enter buffering mode soon.
-    // We want to play the frames we have already decoded, so we stop pre-rolling
-    // and ensure that loadeddata is fired as required.
-    if (isAudio) {
-      StopPrerollingAudio();
-    } else {
-      StopPrerollingVideo();
+    if ((isAudio && mIsAudioPrerolling) || (!isAudio && mIsVideoPrerolling)) {
+      // Schedule next cycle to stop prerolling so we can play the frames we've
+      // decoded so far.
+      ScheduleStateMachine();
     }
     return;
   }
 
   if (aError == NS_ERROR_DOM_MEDIA_CANCELED) {
     if (isAudio) {
       EnsureAudioDecodeTaskQueued();
     } else {
@@ -1158,21 +1155,26 @@ MediaDecoderStateMachine::OnNotDecoded(M
     DecodeError(aError);
     return;
   }
 
   // This is an EOS. Finish off the queue, and then handle things based on our
   // state.
   if (isAudio) {
     AudioQueue().Finish();
-    StopPrerollingAudio();
   } else {
     VideoQueue().Finish();
-    StopPrerollingVideo();
   }
+
+  if ((isAudio && mIsAudioPrerolling) || (!isAudio && mIsVideoPrerolling)) {
+    // No more data to decode. Schedule next cycle to stop prerolling
+    // and start playback.
+    ScheduleStateMachine();
+  }
+
   switch (mState) {
     case DECODER_STATE_DECODING_FIRSTFRAME:
       MaybeFinishDecodeFirstFrame();
       return;
     case DECODER_STATE_BUFFERING:
     case DECODER_STATE_DECODING: {
       if (CheckIfDecodeComplete()) {
         SetState(DECODER_STATE_COMPLETED);
@@ -2124,43 +2126,39 @@ MediaDecoderStateMachine::OnSeekTaskReso
   if (aValue.mSeekedVideoData) {
     Push(aValue.mSeekedVideoData.get(), MediaData::VIDEO_DATA);
     mDecodedVideoEndTime =
       std::max(aValue.mSeekedVideoData->GetEndTime(), mDecodedVideoEndTime);
   }
 
   if (aValue.mIsAudioQueueFinished) {
     AudioQueue().Finish();
-    StopPrerollingAudio();
   }
 
   if (aValue.mIsVideoQueueFinished) {
     VideoQueue().Finish();
-    StopPrerollingVideo();
   }
 
   SeekCompleted();
 }
 
 void
 MediaDecoderStateMachine::OnSeekTaskRejected(SeekTaskRejectValue aValue)
 {
   MOZ_ASSERT(OnTaskQueue());
   MOZ_ASSERT(mState == DECODER_STATE_SEEKING);
 
   mSeekTaskRequest.Complete();
 
   if (aValue.mIsAudioQueueFinished) {
     AudioQueue().Finish();
-    StopPrerollingAudio();
   }
 
   if (aValue.mIsVideoQueueFinished) {
     VideoQueue().Finish();
-    StopPrerollingVideo();
   }
 
   DecodeError(aValue.mError);
 
   DiscardSeekTaskIfExist();
 }
 
 void
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -725,34 +725,16 @@ private:
   {
     MOZ_ASSERT(OnTaskQueue());
     return !mIsVisible ||
         !IsVideoDecoding() ||
         static_cast<uint32_t>(VideoQueue().GetSize()) >=
             VideoPrerollFrames() * mPlaybackRate + 1;
   }
 
-  void StopPrerollingAudio()
-  {
-    MOZ_ASSERT(OnTaskQueue());
-    if (mIsAudioPrerolling) {
-      mIsAudioPrerolling = false;
-      ScheduleStateMachine();
-    }
-  }
-
-  void StopPrerollingVideo()
-  {
-    MOZ_ASSERT(OnTaskQueue());
-    if (mIsVideoPrerolling) {
-      mIsVideoPrerolling = false;
-      ScheduleStateMachine();
-    }
-  }
-
   // When we start decoding (either for the first time, or after a pause)
   // we may be low on decoded data. We don't want our "low data" logic to
   // kick in and decide that we're low on decoded data because the download
   // can't keep up with the decode, and cause us to pause playback. So we
   // have a "preroll" stage, where we ignore the results of our "low data"
   // logic during the first few frames of our decode. This occurs during
   // playback. The flags below are true when the corresponding stream is
   // being "prerolled".