Bug 1404977 - Part 14 - Add a way to set the global cubeb* singleton at runtime, from a test. r?pehrsons draft
authorPaul Adenot <paul@paul.cx>
Fri, 22 Jun 2018 11:45:31 +0200
changeset 824655 1ac501f559943478dcbd76f94b4d678cceb792bc
parent 824654 ddd7e48418cacf212492ece3c64c0872b9be27e6
child 824656 9cab933a4ba12b7c5f8f92af77a757d1fe92acc1
push id117965
push userpaul@paul.cx
push dateTue, 31 Jul 2018 14:52:35 +0000
reviewerspehrsons
bugs1404977
milestone63.0a1
Bug 1404977 - Part 14 - Add a way to set the global cubeb* singleton at runtime, from a test. r?pehrsons This is for testing purposes only. Defining ENABLE_SET_CUBEB_BACKEND before including CubebUtils.h will expose the function. This is not to be set outside of test files. MozReview-Commit-ID: D0V8oLj9xo6
dom/media/CubebUtils.cpp
dom/media/CubebUtils.h
--- a/dom/media/CubebUtils.cpp
+++ b/dom/media/CubebUtils.cpp
@@ -296,16 +296,25 @@ double GetVolumeScale()
 }
 
 cubeb* GetCubebContext()
 {
   StaticMutexAutoLock lock(sMutex);
   return GetCubebContextUnlocked();
 }
 
+// This is only exported when running tests.
+void
+ForceSetCubebContext(cubeb* aCubebContext)
+{
+  StaticMutexAutoLock lock(sMutex);
+  sCubebContext = aCubebContext;
+  sCubebState = CubebState::Initialized;
+}
+
 bool InitPreferredSampleRate()
 {
   StaticMutexAutoLock lock(sMutex);
   if (sPreferredSampleRate != 0) {
     return true;
   }
 #ifdef MOZ_WIDGET_ANDROID
   sPreferredSampleRate = AndroidGetAudioOutputSampleRate();
--- a/dom/media/CubebUtils.h
+++ b/dom/media/CubebUtils.h
@@ -49,12 +49,17 @@ void GetCurrentBackend(nsAString& aBacke
 void GetDeviceCollection(nsTArray<RefPtr<AudioDeviceInfo>>& aDeviceInfos,
                          Side aSide);
 cubeb_stream_prefs GetDefaultStreamPrefs();
 
 #ifdef MOZ_WIDGET_ANDROID
 uint32_t AndroidGetAudioOutputSampleRate();
 uint32_t AndroidGetAudioOutputFramesPerBuffer();
 #endif
+
+#ifdef ENABLE_SET_CUBEB_BACKEND
+void
+ForceSetCubebContext(cubeb* aCubebContext);
+#endif
 } // namespace CubebUtils
 } // namespace mozilla
 
 #endif // CubebUtils_h_