Bug 1135170 - Move some work from MDSM::Seek to MDSM::InitiateSeek. r=mattwoodrow
authorBobby Holley <bobbyholley@gmail.com>
Mon, 02 Mar 2015 16:05:54 -0800
changeset 232370 c4346f7588e63e736e201f1c84c94f4e53d4292b
parent 232369 602445fadacd62f1ce91767e73e007897c940839
child 232371 537948bc60078543196f98bce042c6dba34cb199
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 some work from MDSM::Seek to MDSM::InitiateSeek. r=mattwoodrow This has two implications: * We no longer need to pipe mQueuedSeekTarget through MDSM::Seek to get the appropriate clamping. * MDSM::Seek doesn't _need_ to be called on the main thread anymore.
dom/media/MediaDecoder.cpp
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -478,17 +478,17 @@ void MediaDecoder::UpdateStreamBlockingF
       NS_DispatchToMainThread(runnable);
     }
   }
 }
 
 void MediaDecoder::RecreateDecodedStream(int64_t aStartTimeUSecs)
 {
   MOZ_ASSERT(NS_IsMainThread());
-  GetReentrantMonitor().AssertCurrentThreadIn();
+  ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
   DECODER_LOG("RecreateDecodedStream aStartTimeUSecs=%lld!", aStartTimeUSecs);
 
   DestroyDecodedStream();
 
   mDecodedStream = new DecodedStreamData(this, aStartTimeUSecs,
     MediaStreamGraph::GetInstance()->CreateSourceStream(nullptr));
 
   // Note that the delay between removing ports in DestroyDecodedStream
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1696,39 +1696,20 @@ void MediaDecoderStateMachine::Seek(cons
                "We should have got duration already");
 
   if (mState < DECODER_STATE_DECODING) {
     DECODER_LOG("Seek() Not Enough Data to continue at this stage, queuing seek");
     mQueuedSeekTarget = aTarget;
     return;
   }
   mQueuedSeekTarget.Reset();
-
-  // Bound the seek time to be inside the media range.
-  int64_t end = GetEndTime();
-  NS_ASSERTION(mStartTime != -1, "Should know start time by now");
-  NS_ASSERTION(end != -1, "Should know end time by now");
-  int64_t seekTime = aTarget.mTime + mStartTime;
-  seekTime = std::min(seekTime, end);
-  seekTime = std::max(mStartTime, seekTime);
-  NS_ASSERTION(seekTime >= mStartTime && seekTime <= end,
-               "Can only seek in range [0,duration]");
-  mSeekTarget = SeekTarget(seekTime, aTarget.mType, aTarget.mEventVisibility);
+  mSeekTarget = aTarget;
 
   DECODER_LOG("Changed state to SEEKING (to %lld)", mSeekTarget.mTime);
   SetState(DECODER_STATE_SEEKING);
-
-  // TODO: We should re-create the decoded stream after seek completed as we do
-  // for audio thread since it is until then we know which position we seek to
-  // as far as fast-seek is concerned. It also fix the problem where stream
-  // clock seems to go backwards during seeking.
-  if (mAudioCaptured) {
-    mDecoder->RecreateDecodedStream(seekTime - mStartTime);
-  }
-
   ScheduleStateMachine();
 }
 
 void
 MediaDecoderStateMachine::EnqueueStartQueuedSeekTask()
 {
   MOZ_ASSERT(mQueuedSeekTarget.IsValid());
   MOZ_ASSERT(mState >= DECODER_STATE_DECODING, "MDSM::Seek will requeue this seek!");
@@ -1872,16 +1853,39 @@ MediaDecoderStateMachine::DispatchDecode
 void
 MediaDecoderStateMachine::InitiateSeek()
 {
   MOZ_ASSERT(OnStateMachineThread());
   AssertCurrentThreadInMonitor();
 
   mCurrentSeekTarget = mSeekTarget;
   mSeekTarget.Reset();
+
+  // Bound the seek time to be inside the media range.
+  int64_t end = GetEndTime();
+  NS_ASSERTION(mStartTime != -1, "Should know start time by now");
+  NS_ASSERTION(end != -1, "Should know end time by now");
+  int64_t seekTime = mCurrentSeekTarget.mTime + mStartTime;
+  seekTime = std::min(seekTime, end);
+  seekTime = std::max(mStartTime, seekTime);
+  NS_ASSERTION(seekTime >= mStartTime && seekTime <= end,
+               "Can only seek in range [0,duration]");
+  mCurrentSeekTarget.mTime = seekTime;
+
+  if (mAudioCaptured) {
+    // TODO: We should re-create the decoded stream after seek completed as we do
+    // for audio thread since it is until then we know which position we seek to
+    // as far as fast-seek is concerned. It also fix the problem where stream
+    // clock seems to go backwards during seeking.
+    nsCOMPtr<nsIRunnable> event =
+      NS_NewRunnableMethodWithArg<int64_t>(mDecoder, &MediaDecoder::RecreateDecodedStream,
+                                           seekTime - mStartTime);
+    NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
+  }
+
   mDropAudioUntilNextDiscontinuity = HasAudio();
   mDropVideoUntilNextDiscontinuity = HasVideo();
 
   mDecoder->StopProgressUpdates();
   mCurrentTimeBeforeSeek = GetMediaTime();
 
   // Stop playback now to ensure that while we're outside the monitor
   // dispatching SeekingStarted, playback doesn't advance and mess with