Bug 1162861: Don't disconnect promise outside target thread. r=bholley
authorJean-Yves Avenard <jyavenard@mozilla.com>
Mon, 11 May 2015 20:52:11 +1000
changeset 243351 210b76b5343e81cb40cf91f8f3745b6ef0baf4c3
parent 243350 be45c1aa635d0b7c1491a59512185f9d46be25f1
child 243352 785c11ff43933339e2b5db444430aa9fdf3b1c55
push id28738
push usercbook@mozilla.com
push dateTue, 12 May 2015 14:11:31 +0000
treeherderautoland@bedce1b405a3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbholley
bugs1162861
milestone40.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 1162861: Don't disconnect promise outside target thread. r=bholley
dom/media/mediasource/TrackBuffer.cpp
--- a/dom/media/mediasource/TrackBuffer.cpp
+++ b/dom/media/mediasource/TrackBuffer.cpp
@@ -680,16 +680,25 @@ TrackBuffer::OnMetadataRead(MetadataHold
 {
   MOZ_ASSERT(aDecoder->GetReader()->GetTaskQueue()->IsCurrentThreadIn());
 
   mParentDecoder->GetReentrantMonitor().AssertNotCurrentThreadIn();
   ReentrantMonitorAutoEnter mon(mParentDecoder->GetReentrantMonitor());
 
   mMetadataRequest.Complete();
 
+  if (mShutdown) {
+    MSE_DEBUG("was shut down while reading metadata. Aborting initialization.");
+    return;
+  }
+  if (mCurrentDecoder != aDecoder) {
+    MSE_DEBUG("append was cancelled. Aborting initialization.");
+    return;
+  }
+
   // Adding an empty buffer will reopen the SourceBufferResource
   if (!aWasEnded) {
     nsRefPtr<MediaLargeByteBuffer> emptyBuffer = new MediaLargeByteBuffer;
     aDecoder->GetResource()->AppendData(emptyBuffer);
   }
   // HACK END.
 
   MediaDecoderReader* reader = aDecoder->GetReader();
@@ -731,16 +740,25 @@ TrackBuffer::OnMetadataNotRead(ReadMetad
 {
   MOZ_ASSERT(aDecoder->GetReader()->GetTaskQueue()->IsCurrentThreadIn());
 
   mParentDecoder->GetReentrantMonitor().AssertNotCurrentThreadIn();
   ReentrantMonitorAutoEnter mon(mParentDecoder->GetReentrantMonitor());
 
   mMetadataRequest.Complete();
 
+  if (mShutdown) {
+    MSE_DEBUG("was shut down while reading metadata. Aborting initialization.");
+    return;
+  }
+  if (mCurrentDecoder != aDecoder) {
+    MSE_DEBUG("append was cancelled. Aborting initialization.");
+    return;
+  }
+
   MediaDecoderReader* reader = aDecoder->GetReader();
   reader->SetIdle();
 
   aDecoder->SetTaskQueue(nullptr);
 
   MSE_DEBUG("Reader %p failed to initialize", reader);
 
   RemoveDecoder(aDecoder);
@@ -932,17 +950,16 @@ TrackBuffer::AbortAppendData()
 
   nsRefPtr<SourceBufferDecoder> current = mCurrentDecoder;
   DiscardCurrentDecoder();
 
   if (mMetadataRequest.Exists() || !mInitializationPromise.IsEmpty()) {
     MOZ_ASSERT(current);
     RemoveDecoder(current);
   }
-  mMetadataRequest.DisconnectIfExists();
   // The SourceBuffer would have disconnected its promise.
   // However we must ensure that the MediaPromiseHolder handle all pending
   // promises.
   mInitializationPromise.RejectIfExists(NS_ERROR_ABORT, __func__);
 }
 
 const nsTArray<nsRefPtr<SourceBufferDecoder>>&
 TrackBuffer::Decoders()