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
--- 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_