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 825395 f990ce0881a5ec6c168b998817255cbaee8b583f
parent 825394 3967e717d24bb55e1a0af7aad6eaa0e628928569
child 825396 dc1952972a9d104180865901b8ba8ea4ee5dea98
push id118097
push userpaul@paul.cx
push dateWed, 01 Aug 2018 17:03:19 +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_