Bug 881512 - Make sure any released decoders are destroyed on the main thread. r=cajbir
authorMatthew Gregan <kinetik@flim.org>
Thu, 24 Apr 2014 00:44:00 +1200
changeset 198898 44ad5896ff61977428dae0db3f61917d47ddb0c6
parent 198897 15fe0db2ff8d995651c3c13f23938843d4901152
child 198899 826e982173dda5d25b5a33f377c892af9871f941
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscajbir
bugs881512
milestone31.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 881512 - Make sure any released decoders are destroyed on the main thread. r=cajbir
content/media/mediasource/MediaSourceDecoder.cpp
--- a/content/media/mediasource/MediaSourceDecoder.cpp
+++ b/content/media/mediasource/MediaSourceDecoder.cpp
@@ -335,16 +335,32 @@ MediaSourceReader::EnqueueDecoderInitial
   if (!EnsureWorkQueueInitialized()) {
     return NS_ERROR_FAILURE;
   }
   return mWorkQueue->Dispatch(NS_NewRunnableMethod(static_cast<MediaSourceDecoder*>(mDecoder),
                                                    &MediaSourceDecoder::CallDecoderInitialization),
                               NS_DISPATCH_NORMAL);
 }
 
+class ReleaseDecodersTask : public nsRunnable {
+public:
+  ReleaseDecodersTask(nsTArray<nsRefPtr<SubBufferDecoder>>& aDecoders)
+  {
+    mDecoders.SwapElements(aDecoders);
+  }
+
+  NS_IMETHOD Run() MOZ_OVERRIDE MOZ_FINAL {
+    mDecoders.Clear();
+    return NS_OK;
+  }
+
+private:
+  nsTArray<nsRefPtr<SubBufferDecoder>> mDecoders;
+};
+
 void
 MediaSourceReader::CallDecoderInitialization()
 {
   ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
   for (uint32_t i = 0; i < mPendingDecoders.Length(); ++i) {
     nsRefPtr<SubBufferDecoder> decoder = mPendingDecoders[i];
     MediaDecoderReader* reader = decoder->GetReader();
     MSE_DEBUG("%p: Initializating subdecoder %p reader %p", this, decoder.get(), reader);
@@ -371,17 +387,18 @@ MediaSourceReader::CallDecoderInitializa
     }
 
     if (active) {
       mDecoders.AppendElement(decoder);
     } else {
       MSE_DEBUG("%p: Reader %p not activated", this, reader);
     }
   }
-  mPendingDecoders.Clear();
+  NS_DispatchToMainThread(new ReleaseDecodersTask(mPendingDecoders));
+  MOZ_ASSERT(mPendingDecoders.IsEmpty());
   mDecoder->NotifyWaitingForResourcesStatusChanged();
   mon.NotifyAll();
 }
 
 void
 MediaSourceReader::WaitForPendingDecoders()
 {
   ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());