Bug 1135170 - Move the RenderVideoFrame call to the end of SeekCompleted. r=mattwoodrow
authorBobby Holley <bobbyholley@gmail.com>
Tue, 03 Mar 2015 10:34:44 -0800
changeset 232371 537948bc60078543196f98bce042c6dba34cb199
parent 232370 c4346f7588e63e736e201f1c84c94f4e53d4292b
child 232372 f256c4348bacfed6e8ff4f8740c8b5b981e2a09c
push id56528
push userbobbyholley@gmail.com
push dateSat, 07 Mar 2015 03:18:56 +0000
treeherdermozilla-inbound@cb5ec48a3391 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1135170
milestone39.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 1135170 - Move the RenderVideoFrame call to the end of SeekCompleted. r=mattwoodrow This means that we can get rid of the code to recheck state after dropping the monitor. We'll remove the other monitor drop from this method in a subsequent patch.
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -2465,17 +2465,17 @@ MediaDecoderStateMachine::SeekCompleted(
   if (mState != DECODER_STATE_SEEKING) {
     return;
   }
 
   int64_t seekTime = mCurrentSeekTarget.mTime;
   int64_t newCurrentTime = mCurrentSeekTarget.mTime;
 
   // Setup timestamp state.
-  VideoData* video = VideoQueue().PeekFront();
+  nsRefPtr<VideoData> video = VideoQueue().PeekFront();
   if (seekTime == mEndTime) {
     newCurrentTime = mAudioStartTime = seekTime;
   } else if (HasAudio()) {
     AudioData* audio = AudioQueue().PeekFront();
     // Though we adjust the newCurrentTime in audio-based, and supplemented
     // by video. For better UX, should NOT bind the slide position to
     // the first audio data timestamp directly.
     // While seeking to a position where there's only either audio or video, or
@@ -2485,37 +2485,17 @@ MediaDecoderStateMachine::SeekCompleted(
     int64_t audioStart = audio ? audio->mTime : seekTime;
     newCurrentTime = mAudioStartTime =
         std::min(std::min(audioStart, videoStart), seekTime);
   } else {
     newCurrentTime = video ? video->mTime : seekTime;
   }
   mPlayDuration = newCurrentTime - mStartTime;
 
-  if (HasVideo()) {
-    if (video) {
-      {
-        ReentrantMonitorAutoExit exitMon(mDecoder->GetReentrantMonitor());
-        RenderVideoFrame(video, TimeStamp::Now());
-      }
-      nsCOMPtr<nsIRunnable> event =
-        NS_NewRunnableMethod(mDecoder, &MediaDecoder::Invalidate);
-      NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
-    }
-  }
-
-  MOZ_ASSERT(mState != DECODER_STATE_DECODING_NONE);
-
   mDecoder->StartProgressUpdates();
-  if (mState == DECODER_STATE_DECODING_METADATA ||
-      mState == DECODER_STATE_DECODING_FIRSTFRAME ||
-      mState == DECODER_STATE_DORMANT ||
-      mState == DECODER_STATE_SHUTDOWN) {
-    return;
-  }
 
   // Change state to DECODING or COMPLETED now. SeekingStopped will
   // call MediaDecoderStateMachine::Seek to reset our state to SEEKING
   // if we need to seek again.
 
   nsCOMPtr<nsIRunnable> stopEvent;
   bool isLiveStream = mDecoder->GetResource()->GetLength() == -1;
   if (mSeekTarget.IsValid()) {
@@ -2561,16 +2541,24 @@ MediaDecoderStateMachine::SeekCompleted(
   mScheduler->FreezeScheduling();
   {
     ReentrantMonitorAutoExit exitMon(mDecoder->GetReentrantMonitor());
     NS_DispatchToMainThread(stopEvent, NS_DISPATCH_SYNC);
   }
 
   ScheduleStateMachine();
   mScheduler->ThawScheduling();
+
+  if (video) {
+    ReentrantMonitorAutoExit exitMon(mDecoder->GetReentrantMonitor());
+    RenderVideoFrame(video, TimeStamp::Now());
+    nsCOMPtr<nsIRunnable> event =
+      NS_NewRunnableMethod(mDecoder, &MediaDecoder::Invalidate);
+    NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
+  }
 }
 
 // Runnable to dispose of the decoder and state machine on the main thread.
 class nsDecoderDisposeEvent : public nsRunnable {
 public:
   nsDecoderDisposeEvent(already_AddRefed<MediaDecoder> aDecoder,
                         already_AddRefed<MediaDecoderStateMachine> aStateMachine)
     : mDecoder(aDecoder), mStateMachine(aStateMachine) {}