Backed out changesets a68c9d18ffa5 and 750e7aaf09cb (bug 1067414) for causing bug 1068658. a=me
authorRyan VanderMeulen <ryanvm@gmail.com>
Wed, 17 Sep 2014 14:39:17 -0400
changeset 205836 d2c01d77b9d0bf344d3a570dd224c4c543f47bba
parent 205835 db4cb2e87d11cf33a1e8053c7771b69b274bd55b
child 205837 4f2cac8d72da0dbf8ab097728ea5d788fa0e906d
child 205840 7d23d9d9d887556bf3d431f6f91a6639545a5c50
child 205851 37ce48b22993c26110d75785224d9900edb0a375
child 205897 0c796a435ec069935cfb4ab980f4e83c7cbd264e
push id27503
push userryanvm@gmail.com
push dateWed, 17 Sep 2014 18:42:22 +0000
treeherdermozilla-central@d2c01d77b9d0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs1067414, 1068658
milestone35.0a1
backs outa68c9d18ffa5a540c8b91e4ed77c094fe636ed8d
750e7aaf09cbe56f7bee01d1890774e03ffa0938
first release with
nightly linux32
d2c01d77b9d0 / 35.0a1 / 20140917114326 / files
nightly linux64
d2c01d77b9d0 / 35.0a1 / 20140917114326 / files
nightly mac
d2c01d77b9d0 / 35.0a1 / 20140917114326 / files
nightly win32
d2c01d77b9d0 / 35.0a1 / 20140917114326 / files
nightly win64
d2c01d77b9d0 / 35.0a1 / 20140917114326 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changesets a68c9d18ffa5 and 750e7aaf09cb (bug 1067414) for causing bug 1068658. a=me
content/media/CubebUtils.cpp
content/media/CubebUtils.h
content/media/GraphDriver.h
--- a/content/media/CubebUtils.cpp
+++ b/content/media/CubebUtils.cpp
@@ -1,50 +1,37 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <stdint.h>
 #include <algorithm>
-#include "mozilla/Atomics.h"
 #include "mozilla/Preferences.h"
-#include "mozilla/StaticMutex.h"
 #include "CubebUtils.h"
-#include "nsAutoRef.h"
 #include "prdtoa.h"
 
 #define PREF_VOLUME_SCALE "media.volume_scale"
 #define PREF_CUBEB_LATENCY "media.cubeb_latency_ms"
 
 namespace mozilla {
 
-namespace {
-
-// Prefered samplerate, in Hz (characteristic of the
-// hardware/mixer/platform/API used).
-Atomic<uint32_t> sPreferredSampleRate;
-
-// This mutex protects the variables below.
-StaticMutex sMutex;
-cubeb* sCubebContext;
-double sVolumeScale;
-uint32_t sCubebLatency;
-bool sCubebLatencyPrefSet;
-
-} // anonymous namespace
-
 extern PRLogModuleInfo* gAudioStreamLog;
 
 static const uint32_t CUBEB_NORMAL_LATENCY_MS = 100;
 
-namespace CubebUtils {
+StaticMutex CubebUtils::sMutex;
+cubeb* CubebUtils::sCubebContext;
+uint32_t CubebUtils::sPreferredSampleRate;
+double CubebUtils::sVolumeScale;
+uint32_t CubebUtils::sCubebLatency;
+bool CubebUtils::sCubebLatencyPrefSet;
 
-void PrefChanged(const char* aPref, void* aClosure)
+/*static*/ void CubebUtils::PrefChanged(const char* aPref, void* aClosure)
 {
   if (strcmp(aPref, PREF_VOLUME_SCALE) == 0) {
     nsAdoptingString value = Preferences::GetString(aPref);
     StaticMutexAutoLock lock(sMutex);
     if (value.IsEmpty()) {
       sVolumeScale = 1.0;
     } else {
       NS_ConvertUTF16toUTF8 utf8(value);
@@ -56,123 +43,116 @@ void PrefChanged(const char* aPref, void
     // audible.
     sCubebLatencyPrefSet = Preferences::HasUserValue(aPref);
     uint32_t value = Preferences::GetUint(aPref, CUBEB_NORMAL_LATENCY_MS);
     StaticMutexAutoLock lock(sMutex);
     sCubebLatency = std::min<uint32_t>(std::max<uint32_t>(value, 1), 1000);
   }
 }
 
-bool GetFirstStream()
+/*static*/ bool CubebUtils::GetFirstStream()
 {
   static bool sFirstStream = true;
 
   StaticMutexAutoLock lock(sMutex);
   bool result = sFirstStream;
   sFirstStream = false;
   return result;
 }
 
-double GetVolumeScale()
+/*static*/ double CubebUtils::GetVolumeScale()
 {
   StaticMutexAutoLock lock(sMutex);
   return sVolumeScale;
 }
 
-cubeb* GetCubebContext()
+/*static*/ cubeb* CubebUtils::GetCubebContext()
 {
   StaticMutexAutoLock lock(sMutex);
   return GetCubebContextUnlocked();
 }
 
-void InitPreferredSampleRate()
+/*static*/ void CubebUtils::InitPreferredSampleRate()
 {
-  // The mutex is used here to prohibit concurrent initialization calls, but
-  // sPreferredSampleRate itself is safe to access without the mutex because
-  // it is using atomic storage.
   StaticMutexAutoLock lock(sMutex);
-  uint32_t preferredSampleRate = 0;
   if (sPreferredSampleRate == 0 &&
       cubeb_get_preferred_sample_rate(GetCubebContextUnlocked(),
-                                      &preferredSampleRate) == CUBEB_OK) {
-    sPreferredSampleRate = preferredSampleRate;
-  } else {
-    // Query failed, use a sensible default.
+                                      &sPreferredSampleRate) != CUBEB_OK) {
     sPreferredSampleRate = 44100;
   }
 }
 
-cubeb* GetCubebContextUnlocked()
+/*static*/ cubeb* CubebUtils::GetCubebContextUnlocked()
 {
   sMutex.AssertCurrentThreadOwns();
   if (sCubebContext ||
       cubeb_init(&sCubebContext, "CubebUtils") == CUBEB_OK) {
     return sCubebContext;
   }
   NS_WARNING("cubeb_init failed");
   return nullptr;
 }
 
-uint32_t GetCubebLatency()
+/*static*/ uint32_t CubebUtils::GetCubebLatency()
 {
   StaticMutexAutoLock lock(sMutex);
   return sCubebLatency;
 }
 
-bool CubebLatencyPrefSet()
+/*static*/ bool CubebUtils::CubebLatencyPrefSet()
 {
   StaticMutexAutoLock lock(sMutex);
   return sCubebLatencyPrefSet;
 }
 
-void InitLibrary()
+/*static*/ void CubebUtils::InitLibrary()
 {
 #ifdef PR_LOGGING
   gAudioStreamLog = PR_NewLogModule("AudioStream");
 #endif
   PrefChanged(PREF_VOLUME_SCALE, nullptr);
   Preferences::RegisterCallback(PrefChanged, PREF_VOLUME_SCALE);
   PrefChanged(PREF_CUBEB_LATENCY, nullptr);
   Preferences::RegisterCallback(PrefChanged, PREF_CUBEB_LATENCY);
 }
 
-void ShutdownLibrary()
+/*static*/ void CubebUtils::ShutdownLibrary()
 {
   Preferences::UnregisterCallback(PrefChanged, PREF_VOLUME_SCALE);
   Preferences::UnregisterCallback(PrefChanged, PREF_CUBEB_LATENCY);
 
   StaticMutexAutoLock lock(sMutex);
   if (sCubebContext) {
     cubeb_destroy(sCubebContext);
     sCubebContext = nullptr;
   }
 }
 
-uint32_t MaxNumberOfChannels()
+/*static*/ int CubebUtils::MaxNumberOfChannels()
 {
-  cubeb* cubebContext = GetCubebContext();
+  cubeb* cubebContext = CubebUtils::GetCubebContext();
   uint32_t maxNumberOfChannels;
   if (cubebContext &&
       cubeb_get_max_channel_count(cubebContext,
                                   &maxNumberOfChannels) == CUBEB_OK) {
-    return maxNumberOfChannels;
+    return static_cast<int>(maxNumberOfChannels);
   }
 
   return 0;
 }
 
-uint32_t PreferredSampleRate()
+/*static*/ int CubebUtils::PreferredSampleRate()
 {
   MOZ_ASSERT(sPreferredSampleRate,
              "sPreferredSampleRate has not been initialized!");
   return sPreferredSampleRate;
 }
 
 #if defined(__ANDROID__) && defined(MOZ_B2G)
-cubeb_stream_type ConvertChannelToCubebType(dom::AudioChannel aChannel)
+/*static*/ cubeb_stream_type CubebUtils::ConvertChannelToCubebType(dom::AudioChannel aChannel)
 {
   switch(aChannel) {
     case dom::AudioChannel::Normal:
       return CUBEB_STREAM_TYPE_SYSTEM;
     case dom::AudioChannel::Content:
       return CUBEB_STREAM_TYPE_MUSIC;
     case dom::AudioChannel::Notification:
       return CUBEB_STREAM_TYPE_NOTIFICATION;
@@ -186,10 +166,9 @@ cubeb_stream_type ConvertChannelToCubebT
       return CUBEB_STREAM_TYPE_SYSTEM_ENFORCED;
     default:
       NS_ERROR("The value of AudioChannel is invalid");
       return CUBEB_STREAM_TYPE_MAX;
   }
 }
 #endif
 
-} // namespace CubebUtils
-} // namespace mozilla
+}
--- a/content/media/CubebUtils.h
+++ b/content/media/CubebUtils.h
@@ -3,47 +3,70 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #if !defined(CubebUtils_h_)
 #define CubebUtils_h_
 
 #include "cubeb/cubeb.h"
+#include "nsAutoRef.h"
+#include "mozilla/StaticMutex.h"
 #include "mozilla/dom/AudioChannelBinding.h"
 
+template <>
+class nsAutoRefTraits<cubeb_stream> : public nsPointerRefTraits<cubeb_stream>
+{
+public:
+  static void Release(cubeb_stream* aStream) { cubeb_stream_destroy(aStream); }
+};
+
 namespace mozilla {
-namespace CubebUtils {
 
-// Initialize Audio Library. Some Audio backends require initializing the
-// library before using it.
-void InitLibrary();
+class CubebUtils {
+public:
+  // Initialize Audio Library. Some Audio backends require initializing the
+  // library before using it.
+  static void InitLibrary();
 
-// Shutdown Audio Library. Some Audio backends require shutting down the
-// library after using it.
-void ShutdownLibrary();
+  // Shutdown Audio Library. Some Audio backends require shutting down the
+  // library after using it.
+  static void ShutdownLibrary();
 
-// Returns the maximum number of channels supported by the audio hardware.
-uint32_t MaxNumberOfChannels();
+  // Returns the maximum number of channels supported by the audio hardware.
+  static int MaxNumberOfChannels();
 
-// Queries the samplerate the hardware/mixer runs at, and stores it.
-// Can be called on any thread. When this returns, it is safe to call
-// PreferredSampleRate.
-void InitPreferredSampleRate();
-
-// Get the aforementioned sample rate. Thread safe.
-uint32_t PreferredSampleRate();
+  // Queries the samplerate the hardware/mixer runs at, and stores it.
+  // Can be called on any thread. When this returns, it is safe to call
+  // PreferredSampleRate without locking.
+  static void InitPreferredSampleRate();
+  // Get the aformentionned sample rate. Does not lock.
+  static int PreferredSampleRate();
 
-void PrefChanged(const char* aPref, void* aClosure);
-double GetVolumeScale();
-bool GetFirstStream();
-cubeb* GetCubebContext();
-cubeb* GetCubebContextUnlocked();
-uint32_t GetCubebLatency();
-bool CubebLatencyPrefSet();
+  static void PrefChanged(const char* aPref, void* aClosure);
+  static double GetVolumeScale();
+  static bool GetFirstStream();
+  static cubeb* GetCubebContext();
+  static cubeb* GetCubebContextUnlocked();
+  static uint32_t GetCubebLatency();
+  static bool CubebLatencyPrefSet();
 #if defined(__ANDROID__) && defined(MOZ_B2G)
-cubeb_stream_type ConvertChannelToCubebType(dom::AudioChannel aChannel);
+  static cubeb_stream_type ConvertChannelToCubebType(dom::AudioChannel aChannel);
 #endif
 
-} // namespace CubebUtils
-} // namespace mozilla
+private:
+  // This mutex protects the static members below.
+  static StaticMutex sMutex;
+  static cubeb* sCubebContext;
+
+  // Prefered samplerate, in Hz (characteristic of the
+  // hardware/mixer/platform/API used).
+  static uint32_t sPreferredSampleRate;
+
+  static double sVolumeScale;
+  static uint32_t sCubebLatency;
+  static bool sCubebLatencyPrefSet;
+};
+}
+
+
 
 #endif // CubebUtils_h_
--- a/content/media/GraphDriver.h
+++ b/content/media/GraphDriver.h
@@ -9,24 +9,18 @@
 #include "nsAutoPtr.h"
 #include "nsAutoRef.h"
 #include "AudioBufferUtils.h"
 #include "AudioMixer.h"
 #include "AudioSegment.h"
 
 struct cubeb_stream;
 
-template <>
-class nsAutoRefTraits<cubeb_stream> : public nsPointerRefTraits<cubeb_stream>
-{
-public:
-  static void Release(cubeb_stream* aStream) { cubeb_stream_destroy(aStream); }
-};
+namespace mozilla {
 
-namespace mozilla {
 
 /**
  * Assume we can run an iteration of the MediaStreamGraph loop in this much time
  * or less.
  * We try to run the control loop at this rate.
  */
 static const int MEDIA_GRAPH_TARGET_PERIOD_MS = 10;