Bug 1276849 - some AudioStream::OpenCubeb code cleanup. r=kinetik.
MozReview-Commit-ID: 1X1DXa8fEZN
--- a/dom/media/AudioStream.cpp
+++ b/dom/media/AudioStream.cpp
@@ -324,20 +324,16 @@ int AudioStream::InvokeCubeb(Function aF
nsresult
AudioStream::Init(uint32_t aNumChannels, uint32_t aRate,
const dom::AudioChannel aAudioChannel)
{
auto startTime = TimeStamp::Now();
mIsFirst = CubebUtils::GetFirstStream();
- if (!CubebUtils::GetCubebContext()) {
- return NS_ERROR_FAILURE;
- }
-
LOG("%s channels: %d, rate: %d", __FUNCTION__, aNumChannels, aRate);
mInRate = mOutRate = aRate;
mChannels = aNumChannels;
mOutChannels = aNumChannels;
mDumpFile = OpenDumpFile(this);
cubeb_stream_params params;
@@ -356,52 +352,36 @@ AudioStream::Init(uint32_t aNumChannels,
#endif
params.format = ToCubebFormat<AUDIO_OUTPUT_FORMAT>::value;
mAudioClock.Init();
return OpenCubeb(params, startTime);
}
-// This code used to live inside AudioStream::Init(), but on Mac (others?)
-// it has been known to take 300-800 (or even 8500) ms to execute(!)
nsresult
AudioStream::OpenCubeb(cubeb_stream_params &aParams, TimeStamp aStartTime)
{
cubeb* cubebContext = CubebUtils::GetCubebContext();
if (!cubebContext) {
NS_WARNING("Can't get cubeb context!");
- MonitorAutoLock mon(mMonitor);
- mState = AudioStream::ERRORED;
return NS_ERROR_FAILURE;
}
- // If the latency pref is set, use it. Otherwise, if this stream is intended
- // for low latency playback, try to get the lowest latency possible.
- // Otherwise, for normal streams, use 100ms.
- uint32_t latency = CubebUtils::GetCubebLatency();
-
- {
- cubeb_stream* stream;
- if (cubeb_stream_init(cubebContext, &stream, "AudioStream",
- nullptr, nullptr, nullptr, &aParams,
- latency, DataCallback_S, StateCallback_S, this) == CUBEB_OK) {
- MonitorAutoLock mon(mMonitor);
- MOZ_ASSERT(mState != SHUTDOWN);
- mCubebStream.reset(stream);
- } else {
- MonitorAutoLock mon(mMonitor);
- mState = ERRORED;
- NS_WARNING(nsPrintfCString("AudioStream::OpenCubeb() %p failed to init cubeb", this).get());
- return NS_ERROR_FAILURE;
- }
+ cubeb_stream* stream = nullptr;
+ if (cubeb_stream_init(cubebContext, &stream, "AudioStream",
+ nullptr, nullptr, nullptr, &aParams,
+ CubebUtils::GetCubebLatency(),
+ DataCallback_S, StateCallback_S, this) == CUBEB_OK) {
+ mCubebStream.reset(stream);
+ } else {
+ NS_WARNING(nsPrintfCString("AudioStream::OpenCubeb() %p failed to init cubeb", this).get());
+ return NS_ERROR_FAILURE;
}
- mState = INITIALIZED;
-
TimeDuration timeDelta = TimeStamp::Now() - aStartTime;
LOG("creation time %sfirst: %u ms", mIsFirst ? "" : "not ",
(uint32_t) timeDelta.ToMilliseconds());
Telemetry::Accumulate(mIsFirst ? Telemetry::AUDIOSTREAM_FIRST_OPEN_MS :
Telemetry::AUDIOSTREAM_LATER_OPEN_MS, timeDelta.ToMilliseconds());
return NS_OK;
}