Bug 1337805 - Avoid deadlock in AudioStream::DataCallback. r=padenot
authorAlex Chronopoulos <achronop@gmail.com>
Fri, 10 Feb 2017 16:14:36 +0200
changeset 342244 7bdff2fe50521570fb21e374958c138f8bd5c2b3
parent 342243 2c6b2fd2235ea391c772e3cdb70c4e908bbb0503
child 342245 c67282da235f86ec8c739142541c2cce9162c177
push id31346
push userkwierso@gmail.com
push dateFri, 10 Feb 2017 22:33:24 +0000
treeherdermozilla-central@7b9d9e4a82a6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1337805
milestone54.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 1337805 - Avoid deadlock in AudioStream::DataCallback. r=padenot MozReview-Commit-ID: IPCjepQ4dKt
dom/media/CubebUtils.cpp
--- a/dom/media/CubebUtils.cpp
+++ b/dom/media/CubebUtils.cpp
@@ -218,27 +218,37 @@ uint32_t PreferredSampleRate()
     return 44100;
   }
   MOZ_ASSERT(sPreferredSampleRate);
   return sPreferredSampleRate;
 }
 
 bool InitPreferredChannelLayout()
 {
-  StaticMutexAutoLock lock(sMutex);
-  if (sPreferredChannelLayout != 0) {
-    return true;
+  {
+    StaticMutexAutoLock lock(sMutex);
+    if (sPreferredChannelLayout != 0) {
+      return true;
+    }
   }
-  cubeb* context = GetCubebContextUnlocked();
+
+  cubeb* context = GetCubebContext();
   if (!context) {
     return false;
   }
-  return cubeb_get_preferred_channel_layout(context,
-                                            &sPreferredChannelLayout) == CUBEB_OK
-         ? true : false;
+
+  // Favor calling cubeb api with the mutex unlock, potential deadlock.
+  cubeb_channel_layout layout;
+  if (cubeb_get_preferred_channel_layout(context, &layout) != CUBEB_OK) {
+    return false;
+  }
+
+  StaticMutexAutoLock lock(sMutex);
+  sPreferredChannelLayout = layout;
+  return true;
 }
 
 uint32_t PreferredChannelMap(uint32_t aChannels)
 {
   // The first element of the following mapping table is channel counts,
   // and the second one is its bit mask. It will be used in many times,
   // so we shoule avoid to allocate it in stack, or it will be created
   // and removed repeatedly. Use static to allocate this local variable