Bug 936317 - Prevent MediaBufferDecoder threads from waiting after AudioContext shutdown(). r=ehsan, a=bajaj
authorKarl Tomlinson <karlt+@karlt.net>
Sat, 09 Nov 2013 14:07:45 +1300
changeset 167510 00232fdf3afb690a44a8be65108b9d5b22388203
parent 167509 b4b8a4057dac0492694b070a08437cceb42fff52
child 167511 5ec49fda7a689769e2188d547a8b410b8687e55a
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, bajaj
bugs936317
milestone27.0a2
Bug 936317 - Prevent MediaBufferDecoder threads from waiting after AudioContext shutdown(). r=ehsan, a=bajaj
content/media/webaudio/AudioContext.cpp
content/media/webaudio/MediaBufferDecoder.cpp
content/media/webaudio/MediaBufferDecoder.h
--- a/content/media/webaudio/AudioContext.cpp
+++ b/content/media/webaudio/AudioContext.cpp
@@ -530,16 +530,18 @@ AudioContext::CurrentTime() const
 
 void
 AudioContext::Shutdown()
 {
   mIsShutDown = true;
 
   Suspend();
 
+  mDecoder.Shutdown();
+
   // Release references to active nodes.
   // Active AudioNodes don't unregister in destructors, at which point the
   // Node is already unregistered.
   mActiveNodes.Clear();
 
   // For offline contexts, we can destroy the MediaStreamGraph at this point.
   if (mIsOffline && mDestination) {
     mDestination->OfflineShutdown();
--- a/content/media/webaudio/MediaBufferDecoder.cpp
+++ b/content/media/webaudio/MediaBufferDecoder.cpp
@@ -534,16 +534,27 @@ MediaBufferDecoder::EnsureThreadPoolInit
     if (!mThreadPool) {
       return false;
     }
     mThreadPool->SetName(NS_LITERAL_CSTRING("MediaBufferDecoder"));
   }
   return true;
 }
 
+void
+MediaBufferDecoder::Shutdown() {
+  if (mThreadPool) {
+    // Setting threadLimit to 0 causes threads to exit when all events have
+    // been run, like nsIThreadPool::Shutdown(), but doesn't run a nested event
+    // loop nor wait until this has happened.
+    mThreadPool->SetThreadLimit(0);
+    mThreadPool = nullptr;
+  }
+}
+
 WebAudioDecodeJob::WebAudioDecodeJob(const nsACString& aContentType,
                                      AudioContext* aContext,
                                      const ArrayBuffer& aBuffer,
                                      DecodeSuccessCallback* aSuccessCallback,
                                      DecodeErrorCallback* aFailureCallback)
   : mContentType(aContentType)
   , mWriteIndex(0)
   , mContext(aContext)
--- a/content/media/webaudio/MediaBufferDecoder.h
+++ b/content/media/webaudio/MediaBufferDecoder.h
@@ -75,16 +75,18 @@ class MediaBufferDecoder
 {
 public:
   void AsyncDecodeMedia(const char* aContentType, uint8_t* aBuffer,
                         uint32_t aLength, WebAudioDecodeJob& aDecodeJob);
 
   bool SyncDecodeMedia(const char* aContentType, uint8_t* aBuffer,
                        uint32_t aLength, WebAudioDecodeJob& aDecodeJob);
 
+  void Shutdown();
+
 private:
   bool EnsureThreadPoolInitialized();
 
 private:
   nsCOMPtr<nsIThreadPool> mThreadPool;
 };
 
 }