summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Andrews <athenian200@outlook.com>2021-08-24 13:42:09 -0500
committerJeremy Andrews <athenian200@outlook.com>2021-08-24 13:42:09 -0500
commit41b1b3947c99d5f9478e0d3bd60a95b781c69431 (patch)
tree525d337ef90e17467b431acfd36fb1af6255050b
parentc23dab7adc7228838dc3bc271f864316ff1347ae (diff)
downloaduxp-41b1b3947c99d5f9478e0d3bd60a95b781c69431.tar.gz
Issue #1806 - Part 3: Allow forcing a particular libcubeb backend.
This streamlines troubleshooting in situations where multiple audio backends are compiled into the binary. Now testing different audio backends is as simple as restarting the browser and changing a pref rather than requiring a full recompile.
-rw-r--r--dom/media/CubebUtils.cpp20
-rw-r--r--modules/libpref/init/all.js3
2 files changed, 22 insertions, 1 deletions
diff --git a/dom/media/CubebUtils.cpp b/dom/media/CubebUtils.cpp
index 5ec8363355..12f4b03f03 100644
--- a/dom/media/CubebUtils.cpp
+++ b/dom/media/CubebUtils.cpp
@@ -22,6 +22,7 @@
#include "prdtoa.h"
#define PREF_VOLUME_SCALE "media.volume_scale"
+#define PREF_CUBEB_BACKEND "media.cubeb.backend"
#define PREF_CUBEB_LATENCY_PLAYBACK "media.cubeb_latency_playback_ms"
#define PREF_CUBEB_LATENCY_MSG "media.cubeb_latency_msg_frames"
@@ -57,6 +58,7 @@ bool sCubebPlaybackLatencyPrefSet = false;
bool sCubebMSGLatencyPrefSet = false;
bool sAudioStreamInitEverSucceeded = false;
StaticAutoPtr<char> sBrandName;
+StaticAutoPtr<char> sCubebBackendName;
const char kBrandBundleURL[] = "chrome://branding/locale/brand.properties";
@@ -133,9 +135,21 @@ void PrefChanged(const char* aPref, void* aClosure)
// We don't want to limit the upper limit too much, so that people can
// experiment.
sCubebMSGLatencyInFrames = std::min<uint32_t>(std::max<uint32_t>(value, 128), 1e6);
+ } else if (strcmp(aPref, PREF_CUBEB_BACKEND) == 0) {
+ nsAdoptingString value = Preferences::GetString(aPref);
+ if (value.IsEmpty()) {
+ sCubebBackendName = nullptr;
+ } else {
+ NS_LossyConvertUTF16toASCII ascii(value);
+ sCubebBackendName = new char[ascii.Length() + 1];
+ PodCopy(sCubebBackendName.get(), ascii.get(), ascii.Length());
+ sCubebBackendName[ascii.Length()] = 0;
+ }
}
}
+
+
bool GetFirstStream()
{
static bool sFirstStream = true;
@@ -227,7 +241,7 @@ cubeb* GetCubebContextUnlocked()
sBrandName, "Did not initialize sbrandName, and not on the main thread?");
}
- int rv = cubeb_init(&sCubebContext, sBrandName, nullptr);
+ int rv = cubeb_init(&sCubebContext, sBrandName, sCubebBackendName.get());
NS_WARNING_ASSERTION(rv == CUBEB_OK, "Could not get a cubeb context.");
sCubebState = (rv == CUBEB_OK) ? CubebState::Initialized : CubebState::Uninitialized;
@@ -283,6 +297,8 @@ void InitLibrary()
Preferences::RegisterCallback(PrefChanged, PREF_VOLUME_SCALE);
PrefChanged(PREF_CUBEB_LATENCY_PLAYBACK, nullptr);
PrefChanged(PREF_CUBEB_LATENCY_MSG, nullptr);
+ PrefChanged(PREF_CUBEB_BACKEND, nullptr);
+ Preferences::RegisterCallback(PrefChanged, PREF_CUBEB_BACKEND);
Preferences::RegisterCallback(PrefChanged, PREF_CUBEB_LATENCY_PLAYBACK);
Preferences::RegisterCallback(PrefChanged, PREF_CUBEB_LATENCY_MSG);
NS_DispatchToMainThread(NS_NewRunnableFunction(&InitBrandName));
@@ -291,6 +307,7 @@ void InitLibrary()
void ShutdownLibrary()
{
Preferences::UnregisterCallback(PrefChanged, PREF_VOLUME_SCALE);
+ Preferences::UnregisterCallback(PrefChanged, PREF_CUBEB_BACKEND);
Preferences::UnregisterCallback(PrefChanged, PREF_CUBEB_LATENCY_PLAYBACK);
Preferences::UnregisterCallback(PrefChanged, PREF_CUBEB_LATENCY_MSG);
@@ -300,6 +317,7 @@ void ShutdownLibrary()
sCubebContext = nullptr;
}
sBrandName = nullptr;
+ sCubebBackendName = nullptr;
// This will ensure we don't try to re-create a context.
sCubebState = CubebState::Shutdown;
}
diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js
index b16e58d714..47cd95eeaa 100644
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -353,6 +353,9 @@ pref("media.dormant-on-pause-timeout-ms", 5000);
pref("media.dormant-on-pause-timeout-ms", -1);
#endif
+// Audio backend override
+pref("media.cubeb.backend", "");
+
// Media cache size in kilobytes
pref("media.cache_size", 512000);
// When a network connection is suspended, don't resume it until the