Bug 1135785 - Make DecodeError safe to run on any thread. r=cpearce
authorBobby Holley <bobbyholley@gmail.com>
Sun, 22 Feb 2015 14:16:28 -0800
changeset 261586 2a077477b16c970ce100f41fbba2dde13fc9919d
parent 261585 e637962ba64b4a6dc25965d9179af92c30200815
child 261587 ede75f0e87f0e907ae0977e2fc8599a7a6bed8f2
push id830
push userraliiev@mozilla.com
push dateFri, 19 Jun 2015 19:24:37 +0000
treeherdermozilla-release@932614382a68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs1135785
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 1135785 - Make DecodeError safe to run on any thread. r=cpearce This is necessary so that we can make On{Audio,Video}{,Not}Decoded run on the state machine thread in the next patch.
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -2149,23 +2149,34 @@ bool MediaDecoderStateMachine::HasLowUnd
          !buffered->Contains(static_cast<double>(endOfDecodedData) / USECS_PER_S,
                              static_cast<double>(std::min(endOfDecodedData + aUsecs, GetDuration())) / USECS_PER_S);
 }
 
 void
 MediaDecoderStateMachine::DecodeError()
 {
   AssertCurrentThreadInMonitor();
-  NS_ASSERTION(OnDecodeThread(), "Should be on decode thread.");
-
   if (mState == DECODER_STATE_SHUTDOWN) {
     // Already shutdown.
     return;
   }
 
+  // DecodeError should probably be redesigned so that it doesn't need to run
+  // on the Decode Task Queue, but this does the trick for now.
+  if (!OnDecodeThread()) {
+    RefPtr<nsIRunnable> task(
+      NS_NewRunnableMethod(this, &MediaDecoderStateMachine::AcquireMonitorAndInvokeDecodeError));
+    nsresult rv = DecodeTaskQueue()->Dispatch(task);
+
+    if (NS_FAILED(rv)) {
+      DECODER_WARN("Failed to dispatch AcquireMonitorAndInvokeDecodeError");
+    }
+    return;
+  }
+
   // Change state to shutdown before sending error report to MediaDecoder
   // and the HTMLMediaElement, so that our pipeline can start exiting
   // cleanly during the sync dispatch below.
   DECODER_WARN("Decode error, changed state to SHUTDOWN due to error");
   SetState(DECODER_STATE_SHUTDOWN);
   mScheduler->ScheduleAndShutdown();
   mDecoder->GetReentrantMonitor().NotifyAll();
 
@@ -3638,22 +3649,17 @@ void MediaDecoderStateMachine::OnAudioSi
 
   // Make the best effort to continue playback when there is video.
   if (HasVideo()) {
     return;
   }
 
   // Otherwise notify media decoder/element about this error for it makes
   // no sense to play an audio-only file without sound output.
-  RefPtr<nsIRunnable> task(
-    NS_NewRunnableMethod(this, &MediaDecoderStateMachine::AcquireMonitorAndInvokeDecodeError));
-  nsresult rv = DecodeTaskQueue()->Dispatch(task);
-  if (NS_FAILED(rv)) {
-    DECODER_WARN("Failed to dispatch AcquireMonitorAndInvokeDecodeError");
-  }
+  DecodeError();
 }
 
 } // namespace mozilla
 
 // avoid redefined macro in unified build
 #undef DECODER_LOG
 #undef VERBOSE_LOG
 #undef DECODER_WARN