Backed out changeset 66be4716e86e (bug 944707) for regressing lazy libcubeb initialization, startup time, and causing bug 946037.
authorMatthew Gregan <kinetik@flim.org>
Mon, 09 Dec 2013 11:49:25 +1300
changeset 174155 66b2067150566c6a3d63f1f950d0740045a4fec3
parent 174154 ebc291b18b352496d8a565baa2fc577f5688608c
child 174156 052685e62b342c87522a53665cf2e0080f7e93ec
push id3224
push userlsblakk@mozilla.com
push dateTue, 04 Feb 2014 01:06:49 +0000
treeherdermozilla-beta@60c04d0987f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs944707, 946037
milestone28.0a1
backs out66be4716e86e33ebc37d324313b622d9193498a5
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
Backed out changeset 66be4716e86e (bug 944707) for regressing lazy libcubeb initialization, startup time, and causing bug 946037.
content/media/AudioStream.cpp
content/media/AudioStream.h
--- a/content/media/AudioStream.cpp
+++ b/content/media/AudioStream.cpp
@@ -156,18 +156,16 @@ AudioStream::~AudioStream()
 {
 #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);
-
-  InitPreferredSampleRate();
 }
 
 /*static*/ void AudioStream::ShutdownLibrary()
 {
   Preferences::UnregisterCallback(PrefChanged, PREF_VOLUME_SCALE);
   Preferences::UnregisterCallback(PrefChanged, PREF_CUBEB_LATENCY);
 
   StaticMutexAutoLock lock(sMutex);
@@ -262,26 +260,38 @@ int64_t AudioStream::GetWritten()
       cubeb_get_max_channel_count(cubebContext,
                                   &maxNumberOfChannels) == CUBEB_OK) {
     return static_cast<int>(maxNumberOfChannels);
   }
 
   return 0;
 }
 
-/*static */ void AudioStream::InitPreferredSampleRate()
+/*static*/ int AudioStream::PreferredSampleRate()
 {
+  const int fallbackSampleRate = 44100;
+  StaticMutexAutoLock lock(sMutex);
+  if (sPreferredSampleRate != 0) {
+    return sPreferredSampleRate;
+  }
+
+  cubeb* cubebContext = GetCubebContextUnlocked();
+  if (!cubebContext) {
+    sPreferredSampleRate = fallbackSampleRate;
+  }
   // Get the preferred samplerate for this platform, or fallback to something
   // sensible if we fail. We cache the value, because this might be accessed
   // often, and the complexity of the function call below depends on the
   // backend used.
-  if (cubeb_get_preferred_sample_rate(GetCubebContext(),
+  if (cubeb_get_preferred_sample_rate(cubebContext,
                                       &sPreferredSampleRate) != CUBEB_OK) {
-    sPreferredSampleRate = 44100;
+    sPreferredSampleRate = fallbackSampleRate;
   }
+
+  return sPreferredSampleRate;
 }
 
 static void SetUint16LE(uint8_t* aDest, uint16_t aValue)
 {
   aDest[0] = aValue & 0xFF;
   aDest[1] = aValue >> 8;
 }
 
--- a/content/media/AudioStream.h
+++ b/content/media/AudioStream.h
@@ -174,23 +174,19 @@ public:
 
   // 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.
   static int MaxNumberOfChannels();
 
-  static void InitPreferredSampleRate();
   // Returns the samplerate the systems prefer, because it is the
   // samplerate the hardware/mixer supports.
-  static int PreferredSampleRate() {
-    MOZ_ASSERT(sPreferredSampleRate);
-    return sPreferredSampleRate;
-  }
+  static int PreferredSampleRate();
 
   AudioStream();
   ~AudioStream();
 
   enum LatencyRequest {
     HighLatency,
     LowLatency
   };
@@ -372,24 +368,24 @@ private:
                  // cubeb, after which StateCallback will indicate drain
                  // completion.
     DRAINED,     // StateCallback has indicated that the drain is complete.
     ERRORED      // Stream disabled due to an internal error.
   };
 
   StreamState mState;
 
+  // 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;
 
-  // This mutex protects the static members below
-  static StaticMutex sMutex;
-  static cubeb* sCubebContext;
-
   static double sVolumeScale;
   static uint32_t sCubebLatency;
   static bool sCubebLatencyPrefSet;
 };
 
 } // namespace mozilla
 
 #endif