diff options
Diffstat (limited to 'dom')
-rw-r--r-- | dom/media/CubebUtils.cpp | 31 | ||||
-rw-r--r-- | dom/media/CubebUtils.h | 2 | ||||
-rw-r--r-- | dom/media/GraphDriver.cpp | 10 |
3 files changed, 22 insertions, 21 deletions
diff --git a/dom/media/CubebUtils.cpp b/dom/media/CubebUtils.cpp index aa611973db..5ec8363355 100644 --- a/dom/media/CubebUtils.cpp +++ b/dom/media/CubebUtils.cpp @@ -50,11 +50,11 @@ enum class CubebState { Shutdown } sCubebState = CubebState::Uninitialized; cubeb* sCubebContext; -double sVolumeScale; -uint32_t sCubebPlaybackLatencyInMilliseconds; -uint32_t sCubebMSGLatencyInFrames; -bool sCubebPlaybackLatencyPrefSet; -bool sCubebMSGLatencyPrefSet; +double sVolumeScale = 1.0; +uint32_t sCubebPlaybackLatencyInMilliseconds = 100; +uint32_t sCubebMSGLatencyInFrames = 512; +bool sCubebPlaybackLatencyPrefSet = false; +bool sCubebMSGLatencyPrefSet = false; bool sAudioStreamInitEverSucceeded = false; StaticAutoPtr<char> sBrandName; @@ -227,7 +227,7 @@ cubeb* GetCubebContextUnlocked() sBrandName, "Did not initialize sbrandName, and not on the main thread?"); } - int rv = cubeb_init(&sCubebContext, sBrandName); + int rv = cubeb_init(&sCubebContext, sBrandName, nullptr); NS_WARNING_ASSERTION(rv == CUBEB_OK, "Could not get a cubeb context."); sCubebState = (rv == CUBEB_OK) ? CubebState::Initialized : CubebState::Uninitialized; @@ -258,14 +258,23 @@ bool CubebMSGLatencyPrefSet() return sCubebMSGLatencyPrefSet; } -Maybe<uint32_t> GetCubebMSGLatencyInFrames() +uint32_t GetCubebMSGLatencyInFrames(cubeb_stream_params * params) { StaticMutexAutoLock lock(sMutex); - if (!sCubebMSGLatencyPrefSet) { - return Maybe<uint32_t>(); + if (sCubebMSGLatencyPrefSet) { + MOZ_ASSERT(sCubebMSGLatencyInFrames > 0); + return sCubebMSGLatencyInFrames; } - MOZ_ASSERT(sCubebMSGLatencyInFrames > 0); - return Some(sCubebMSGLatencyInFrames); + cubeb* context = GetCubebContextUnlocked(); + if (!context) { + return sCubebMSGLatencyInFrames; // default 512 + } + uint32_t latency_frames = 0; + if (cubeb_get_min_latency(context, params, &latency_frames) != CUBEB_OK) { + NS_WARNING("Could not get minimal latency from cubeb."); + return sCubebMSGLatencyInFrames; // default 512 + } + return latency_frames; } void InitLibrary() diff --git a/dom/media/CubebUtils.h b/dom/media/CubebUtils.h index f434923747..8ebd1af214 100644 --- a/dom/media/CubebUtils.h +++ b/dom/media/CubebUtils.h @@ -36,7 +36,7 @@ bool GetFirstStream(); cubeb* GetCubebContext(); cubeb* GetCubebContextUnlocked(); uint32_t GetCubebPlaybackLatencyInMilliseconds(); -Maybe<uint32_t> GetCubebMSGLatencyInFrames(); +uint32_t GetCubebMSGLatencyInFrames(cubeb_stream_params * params); bool CubebLatencyPrefSet(); void GetCurrentBackend(nsAString& aBackend); diff --git a/dom/media/GraphDriver.cpp b/dom/media/GraphDriver.cpp index 90680d8c69..70b59c61f1 100644 --- a/dom/media/GraphDriver.cpp +++ b/dom/media/GraphDriver.cpp @@ -593,7 +593,6 @@ AudioCallbackDriver::Init() cubeb_stream_params output; cubeb_stream_params input; - uint32_t latency_frames; MOZ_ASSERT(!NS_IsMainThread(), "This is blocking and should never run on the main thread."); @@ -609,14 +608,7 @@ AudioCallbackDriver::Init() output.format = CUBEB_SAMPLE_FLOAT32NE; } - Maybe<uint32_t> latencyPref = CubebUtils::GetCubebMSGLatencyInFrames(); - if (latencyPref) { - latency_frames = latencyPref.value(); - } else { - if (cubeb_get_min_latency(cubebContext, output, &latency_frames) != CUBEB_OK) { - NS_WARNING("Could not get minimal latency from cubeb."); - } - } + uint32_t latency_frames = CubebUtils::GetCubebMSGLatencyInFrames(&output); input = output; input.channels = mInputChannels; // change to support optional stereo capture |