Bug 1135170 - Stop doing sync dispatch for SeekingStarted. r=mattwoodrow
authorBobby Holley <bobbyholley@gmail.com>
Fri, 20 Feb 2015 14:53:06 -0800
changeset 232365 1f94498ba81cd767a584e975edc18f8b3f5d84e0
parent 232364 371ab272ec4b26bdec7dd5d89eb1ddaf7181db6a
child 232366 5f2bef7e0b6c58dc937110aa97b3c1e88906511e
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 - Stop doing sync dispatch for SeekingStarted. r=mattwoodrow I can't see any reason why this should be necessary, and cursory archaeology suggests that this too is a hand-me-down from previous threading models.
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -2440,50 +2440,35 @@ void MediaDecoderStateMachine::DecodeSee
     return;
   }
 
   mCurrentSeekTarget = mSeekTarget;
   mSeekTarget.Reset();
   mDropAudioUntilNextDiscontinuity = HasAudio();
   mDropVideoUntilNextDiscontinuity = HasVideo();
 
-  // During the seek, don't have a lock on the decoder state,
-  // otherwise long seek operations can block the main thread.
-  // The events dispatched to the main thread are SYNC calls.
-  // These calls are made outside of the decode monitor lock so
-  // it is safe for the main thread to makes calls that acquire
-  // the lock since it won't deadlock. We check the state when
-  // acquiring the lock again in case shutdown has occurred
-  // during the time when we didn't have the lock.
   int64_t seekTime = mCurrentSeekTarget.mTime;
   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
   // mCurrentFrameTime that we've setting to seekTime here.
   StopPlayback();
   UpdatePlaybackPositionInternal(seekTime);
 
   // SeekingStarted will do a UpdateReadyStateForData which will
   // inform the element and its users that we have no frames
   // to display
-  {
-    ReentrantMonitorAutoExit exitMon(mDecoder->GetReentrantMonitor());
-    nsCOMPtr<nsIRunnable> startEvent =
-      NS_NewRunnableMethodWithArg<MediaDecoderEventVisibility>(
-        mDecoder,
-        &MediaDecoder::SeekingStarted,
-        mCurrentSeekTarget.mEventVisibility);
-    NS_DispatchToMainThread(startEvent, NS_DISPATCH_SYNC);
-  }
-  if (mState != DECODER_STATE_SEEKING) {
-    // May have shutdown while we released the monitor.
-    return;
-  }
+  nsCOMPtr<nsIRunnable> startEvent =
+    NS_NewRunnableMethodWithArg<MediaDecoderEventVisibility>(
+      mDecoder,
+      &MediaDecoder::SeekingStarted,
+      mCurrentSeekTarget.mEventVisibility);
+  NS_DispatchToMainThread(startEvent, NS_DISPATCH_NORMAL);
 
   mDecodeToSeekTarget = false;
 
   // The seek target is different than the current playback position,
   // we'll need to seek the playback position, so shutdown our decode
   // thread and audio sink.
   StopAudioThread();
   ResetPlayback();
@@ -2534,25 +2519,22 @@ MediaDecoderStateMachine::OnSeekFailed(n
   mCancelingSeek = false;
 
   if (NS_FAILED(aResult)) {
     DecodeError();
   } else if (wasCanceled && mSeekTarget.IsValid() && mState == DECODER_STATE_SEEKING) {
     // Try again.
     mCurrentSeekTarget = mSeekTarget;
     mSeekTarget.Reset();
-    {
-      ReentrantMonitorAutoExit exitMon(mDecoder->GetReentrantMonitor());
-      nsCOMPtr<nsIRunnable> startEvent =
-        NS_NewRunnableMethodWithArg<MediaDecoderEventVisibility>(
-          mDecoder,
-          &MediaDecoder::SeekingStarted,
-          mCurrentSeekTarget.mEventVisibility);
-      NS_DispatchToMainThread(startEvent, NS_DISPATCH_SYNC);
-    }
+    nsCOMPtr<nsIRunnable> startEvent =
+      NS_NewRunnableMethodWithArg<MediaDecoderEventVisibility>(
+        mDecoder,
+        &MediaDecoder::SeekingStarted,
+        mCurrentSeekTarget.mEventVisibility);
+    NS_DispatchToMainThread(startEvent, NS_DISPATCH_NORMAL);
     mReader->Seek(mCurrentSeekTarget.mTime, mEndTime)
            ->Then(DecodeTaskQueue(), __func__, this,
                   &MediaDecoderStateMachine::OnSeekCompleted,
                   &MediaDecoderStateMachine::OnSeekFailed);
     mWaitingForDecoderSeek = true;
   }
 }