Bug 1394052 - Fix reading media.cubeb.sandbox pref. r=kamidphish
authorJed Davis <jld@mozilla.com>
Fri, 25 Aug 2017 19:08:32 -0600
changeset 377719 740a3f332d0b047e5317c004c0f4880ef0c8f6ca
parent 377718 41850a57de472f05cb0177466c8d1c382052bdcd
child 377720 9bfb38ac67b232cc22d8f6c5dcdd7dde90072d8e
push id94338
push userkwierso@gmail.com
push dateThu, 31 Aug 2017 02:58:58 +0000
treeherdermozilla-inbound@9ca18987dabb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskamidphish
bugs1394052
milestone57.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 1394052 - Fix reading media.cubeb.sandbox pref. r=kamidphish Previously this would always treat the pref as false, due to a slight mistake in how Preferences::GetBool is called, and it could try to read prefs off the main thread in some cases. MozReview-Commit-ID: CcnVevHvqye
dom/media/CubebUtils.cpp
--- a/dom/media/CubebUtils.cpp
+++ b/dom/media/CubebUtils.cpp
@@ -107,16 +107,19 @@ enum class CubebState {
 } sCubebState = CubebState::Uninitialized;
 cubeb* sCubebContext;
 double sVolumeScale;
 uint32_t sCubebPlaybackLatencyInMilliseconds;
 uint32_t sCubebMSGLatencyInFrames;
 bool sCubebPlaybackLatencyPrefSet;
 bool sCubebMSGLatencyPrefSet;
 bool sAudioStreamInitEverSucceeded = false;
+#ifdef MOZ_CUBEB_REMOTING
+bool sCubebSandbox;
+#endif
 StaticAutoPtr<char> sBrandName;
 StaticAutoPtr<char> sCubebBackendName;
 
 const char kBrandBundleURL[]      = "chrome://branding/locale/brand.properties";
 
 const char* AUDIOSTREAM_BACKEND_ID_STR[] = {
   "jack",
   "pulse",
@@ -244,21 +247,21 @@ void PrefChanged(const char* aPref, void
     } else {
       sCubebBackendName = new char[value.Length() + 1];
       PodCopy(sCubebBackendName.get(), value.get(), value.Length());
       sCubebBackendName[value.Length()] = 0;
     }
   }
 #ifdef MOZ_CUBEB_REMOTING
   else if (strcmp(aPref, PREF_CUBEB_SANDBOX) == 0) {
-    bool cubebSandbox = false;
-    Preferences::GetBool(aPref, cubebSandbox);
-    MOZ_LOG(gCubebLog, LogLevel::Verbose, ("%s: %s", PREF_CUBEB_SANDBOX, cubebSandbox ? "true" : "false"));
+    StaticMutexAutoLock lock(sMutex);
+    sCubebSandbox = Preferences::GetBool(aPref);
+    MOZ_LOG(gCubebLog, LogLevel::Verbose, ("%s: %s", PREF_CUBEB_SANDBOX, sCubebSandbox ? "true" : "false"));
 
-    if (cubebSandbox && !sServerHandle && XRE_IsParentProcess()) {
+    if (sCubebSandbox && !sServerHandle && XRE_IsParentProcess()) {
       MOZ_LOG(gCubebLog, LogLevel::Debug, ("Starting cubeb server..."));
       StartSoundServer();
     }
   }
 #endif
 }
 
 bool GetFirstStream()
@@ -385,21 +388,19 @@ cubeb* GetCubebContextUnlocked()
   if (!sBrandName && NS_IsMainThread()) {
     InitBrandName();
   } else {
     NS_WARNING_ASSERTION(
       sBrandName, "Did not initialize sbrandName, and not on the main thread?");
   }
 
 #ifdef MOZ_CUBEB_REMOTING
-  bool cubebSandbox = false;
-  Preferences::GetBool(PREF_CUBEB_SANDBOX, cubebSandbox);
-  MOZ_LOG(gCubebLog, LogLevel::Info, ("%s: %s", PREF_CUBEB_SANDBOX, cubebSandbox ? "true" : "false"));
+  MOZ_LOG(gCubebLog, LogLevel::Info, ("%s: %s", PREF_CUBEB_SANDBOX, sCubebSandbox ? "true" : "false"));
 
-  int rv = cubebSandbox
+  int rv = sCubebSandbox
     ? audioipc_client_init(&sCubebContext, sBrandName)
     : cubeb_init(&sCubebContext, sBrandName, sCubebBackendName.get());
 #else // !MOZ_CUBEB_REMOTING
   int rv = cubeb_init(&sCubebContext, sBrandName, sCubebBackendName.get());
 #endif // MOZ_CUBEB_REMOTING
   NS_WARNING_ASSERTION(rv == CUBEB_OK, "Could not get a cubeb context.");
   sCubebState = (rv == CUBEB_OK) ? CubebState::Initialized : CubebState::Uninitialized;