Bug 1172825 - MDSM playback should depend on IsPlaying() instead of |mPlayState|. r=cpearce.
authorJW Wang <jwwang@mozilla.com>
Thu, 11 Jun 2015 10:16:33 +0800
changeset 248260 4636a1c2b824a1d0f6e0b4d405778572df460678
parent 248259 9c4f6706db9a05d332c88befff1581cb1f2bc020
child 248261 bcaca4f837e80a7e28d0fa44cc0a1c5d335fd6a7
push id28893
push userkwierso@gmail.com
push dateFri, 12 Jun 2015 00:02:58 +0000
treeherderautoland@8cf9d3e497f9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1172825
milestone41.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 1172825 - MDSM playback should depend on IsPlaying() instead of |mPlayState|. r=cpearce.
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -2612,17 +2612,17 @@ nsresult MediaDecoderStateMachine::RunSt
         // playing!
         StopPlayback();
       }
 
       // Start playback if necessary so that the clock can be properly queried.
       MaybeStartPlayback();
 
       AdvanceFrame();
-      NS_ASSERTION(mPlayState != MediaDecoder::PLAY_STATE_PLAYING ||
+      NS_ASSERTION(!IsPlaying() ||
                    mLogicallySeeking ||
                    IsStateMachineScheduled() ||
                    mPlaybackRate == 0.0, "Must have timer scheduled");
       return NS_OK;
     }
 
     case DECODER_STATE_BUFFERING: {
       TimeStamp now = TimeStamp::Now();
@@ -2673,25 +2673,30 @@ nsresult MediaDecoderStateMachine::RunSt
     case DECODER_STATE_SEEKING: {
       if (mPendingSeek.Exists()) {
         InitiateSeek();
       }
       return NS_OK;
     }
 
     case DECODER_STATE_COMPLETED: {
+      if (mPlayState != MediaDecoder::PLAY_STATE_PLAYING && IsPlaying()) {
+        StopPlayback();
+      }
       // Play the remaining media. We want to run AdvanceFrame() at least
       // once to ensure the current playback position is advanced to the
       // end of the media, and so that we update the readyState.
       if (VideoQueue().GetSize() > 0 ||
           (HasAudio() && !mAudioCompleted) ||
           (mAudioCaptured && !GetDecodedStream()->IsFinished()))
       {
+        // Start playback if necessary to play the remaining media.
+        MaybeStartPlayback();
         AdvanceFrame();
-        NS_ASSERTION(mPlayState != MediaDecoder::PLAY_STATE_PLAYING ||
+        NS_ASSERTION(!IsPlaying() ||
                      mLogicallySeeking ||
                      mPlaybackRate == 0 || IsStateMachineScheduled(),
                      "Must have timer scheduled");
         return NS_OK;
       }
 
       // StopPlayback in order to reset the IsPlaying() state so audio
       // is restarted correctly.
@@ -2889,17 +2894,17 @@ int64_t MediaDecoderStateMachine::GetClo
 
 void MediaDecoderStateMachine::AdvanceFrame()
 {
   MOZ_ASSERT(OnTaskQueue());
   AssertCurrentThreadInMonitor();
   NS_ASSERTION(!HasAudio() || mAudioStartTime != -1,
                "Should know audio start time if we have audio.");
 
-  if (mPlayState != MediaDecoder::PLAY_STATE_PLAYING || mLogicallySeeking) {
+  if (!IsPlaying() || mLogicallySeeking) {
     return;
   }
 
   // If playbackRate is 0.0, we should stop the progress, but not be in paused
   // state, per spec.
   if (mPlaybackRate == 0.0) {
     return;
   }
@@ -2999,23 +3004,17 @@ void MediaDecoderStateMachine::AdvanceFr
     int64_t frameTime = currentFrame->mTime - mStartTime;
     if (frameTime > 0  || (frameTime == 0 && mPlayDuration == 0) ||
         IsRealTime()) {
       ReentrantMonitorAutoExit exitMon(mDecoder->GetReentrantMonitor());
       // If we have video, we want to increment the clock in steps of the frame
       // duration.
       RenderVideoFrame(currentFrame, presTime);
     }
-    // If we're no longer playing after dropping and reacquiring the lock,
-    // playback must've been stopped on the decode thread (by a seek, for
-    // example).  In that case, the current frame is probably out of date.
-    if (!IsPlaying()) {
-      ScheduleStateMachine();
-      return;
-    }
+    MOZ_ASSERT(IsPlaying());
     MediaDecoder::FrameStatistics& frameStats = mDecoder->GetFrameStatistics();
     frameStats.NotifyPresentedFrame();
     remainingTime = currentFrame->GetEndTime() - clock_time;
     currentFrame = nullptr;
   }
 
   // The remainingTime is negative (include zero):
   // 1. When the clock_time is larger than the latest video frame's endtime.