Bug 1139380 - Ensure all queued tasks are aborted when shutting down. r=cpearce a=lmandel
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 06 Mar 2015 16:49:00 +1100
changeset 250382 1604edfb5a6c
parent 250381 247c345e5f23
child 250383 3aa618647813
push id4570
push userryanvm@gmail.com
push date2015-03-16 16:03 +0000
treeherdermozilla-beta@ad1f181d8593 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, lmandel
bugs1139380
milestone37.0
Bug 1139380 - Ensure all queued tasks are aborted when shutting down. r=cpearce a=lmandel
dom/media/MediaDecoderStateMachine.cpp
dom/media/mediasource/MediaSourceReader.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -828,16 +828,20 @@ MediaDecoderStateMachine::OnNotDecoded(M
   bool isAudio = aType == MediaData::AUDIO_DATA;
   MOZ_ASSERT_IF(!isAudio, aType == MediaData::VIDEO_DATA);
 
   if (isAudio) {
     mAudioDataRequest.Complete();
   } else {
     mVideoDataRequest.Complete();
   }
+  if (IsShutdown()) {
+    // Already shutdown;
+    return;
+  }
 
   // If this is a decode error, delegate to the generic error path.
   if (aReason == MediaDecoderReader::DECODE_ERROR) {
     DecodeError();
     return;
   }
 
   // If the decoder is waiting for data, we tell it to call us back when the
@@ -1907,16 +1911,20 @@ MediaDecoderStateMachine::EnqueueDecodeS
 
 nsresult
 MediaDecoderStateMachine::DispatchAudioDecodeTaskIfNeeded()
 {
   ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
   NS_ASSERTION(OnStateMachineThread() || OnDecodeThread(),
                "Should be on state machine or decode thread.");
 
+  if (IsShutdown()) {
+    return NS_ERROR_FAILURE;
+  }
+
   if (NeedToDecodeAudio()) {
     return EnsureAudioDecodeTaskQueued();
   }
 
   return NS_OK;
 }
 
 nsresult
@@ -1955,16 +1963,20 @@ MediaDecoderStateMachine::EnsureAudioDec
 
 nsresult
 MediaDecoderStateMachine::DispatchVideoDecodeTaskIfNeeded()
 {
   ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
   NS_ASSERTION(OnStateMachineThread() || OnDecodeThread(),
                "Should be on state machine or decode thread.");
 
+  if (IsShutdown()) {
+    return NS_ERROR_FAILURE;
+  }
+
   if (NeedToDecodeVideo()) {
     return EnsureVideoDecodeTaskQueued();
   }
 
   return NS_OK;
 }
 
 nsresult
--- a/dom/media/mediasource/MediaSourceReader.cpp
+++ b/dom/media/mediasource/MediaSourceReader.cpp
@@ -401,16 +401,24 @@ MediaSourceReader::CheckForWaitOrEndOfSt
     mVideoPromise.Reject(WAITING_FOR_DATA, __func__);
   }
 }
 
 nsRefPtr<ShutdownPromise>
 MediaSourceReader::Shutdown()
 {
   mSeekPromise.RejectIfExists(NS_ERROR_FAILURE, __func__);
+  // Any previous requests we've been waiting on are now unwanted.
+  mAudioRequest.DisconnectIfExists();
+  mVideoRequest.DisconnectIfExists();
+
+  // Additionally, reject any outstanding promises _we_ made that we might have
+  // been waiting on the above to fulfill.
+  mAudioPromise.RejectIfExists(CANCELED, __func__);
+  mVideoPromise.RejectIfExists(CANCELED, __func__);
 
   MOZ_ASSERT(mMediaSourceShutdownPromise.IsEmpty());
   nsRefPtr<ShutdownPromise> p = mMediaSourceShutdownPromise.Ensure(__func__);
 
   ContinueShutdown();
   return p;
 }