Bug 1277037 - Make AudioCallbackDriver::StartStream fallible. r=jesup

Avoid crashing in the case that cubeb stream start fails and report
an error instead.

MozReview-Commit-ID: 75M392POyHo

--HG--
extra : rebase_source : 2c083cf129f12ad1e18d9065152cfee13987b071
This commit is contained in:
Ralph Giles 2017-01-11 11:51:23 -08:00
parent 526e90ef9f
commit d5608e0a47
2 changed files with 19 additions and 11 deletions

View File

@ -515,7 +515,9 @@ AsyncCubebTask::Run()
switch(mOperation) {
case AsyncCubebOperation::INIT: {
LIFECYCLE_LOG("AsyncCubebOperation::INIT driver=%p\n", mDriver.get());
mDriver->Init();
if (!mDriver->Init()) {
return NS_ERROR_FAILURE;
}
mDriver->CompleteAudioContextOperations(mOperation);
break;
}
@ -594,7 +596,7 @@ bool IsMacbookOrMacbookAir()
return false;
}
void
bool
AudioCallbackDriver::Init()
{
cubeb* cubebContext = CubebUtils::GetCubebContext();
@ -603,7 +605,7 @@ AudioCallbackDriver::Init()
if (!mFromFallback) {
CubebUtils::ReportCubebStreamInitFailure(true);
}
return;
return false;
}
cubeb_stream_params output;
@ -624,7 +626,7 @@ AudioCallbackDriver::Init()
#endif
if (output.stream_type == CUBEB_STREAM_TYPE_MAX) {
NS_WARNING("Bad stream type");
return;
return false;
}
#else
(void)mAudioChannel;
@ -643,7 +645,7 @@ AudioCallbackDriver::Init()
} else {
if (cubeb_get_min_latency(cubebContext, output, &latency_frames) != CUBEB_OK) {
NS_WARNING("Could not get minimal latency from cubeb.");
return;
return false;
}
}
@ -712,7 +714,7 @@ AudioCallbackDriver::Init()
nextDriver->SetGraphTime(this, mIterationStart, mIterationEnd);
mGraphImpl->SetCurrentDriver(nextDriver);
nextDriver->Start();
return;
return true;
}
}
bool aec;
@ -722,9 +724,13 @@ AudioCallbackDriver::Init()
cubeb_stream_register_device_changed_callback(mAudioStream,
AudioCallbackDriver::DeviceChangedCallback_s);
StartStream();
if (!StartStream()) {
STREAM_LOG(LogLevel::Warning, ("AudioCallbackDriver couldn't start stream."));
return false;
}
STREAM_LOG(LogLevel::Debug, ("AudioCallbackDriver started."));
return true;
}
@ -771,11 +777,12 @@ AudioCallbackDriver::Start()
initEvent->Dispatch();
}
void
bool
AudioCallbackDriver::StartStream()
{
if (cubeb_stream_start(mAudioStream) != CUBEB_OK) {
MOZ_CRASH("Could not start cubeb stream for MSG.");
NS_WARNING("Could not start cubeb stream for MSG.");
return false;
}
{
@ -783,6 +790,7 @@ AudioCallbackDriver::StartStream()
mStarted = true;
mWaitState = WAITSTATE_RUNNING;
}
return true;
}
void

View File

@ -467,9 +467,9 @@ private:
* This is called when the output device used by the cubeb stream changes. */
void DeviceChangedCallback();
/* Start the cubeb stream */
void StartStream();
bool StartStream();
friend class AsyncCubebTask;
void Init();
bool Init();
/* MediaStreamGraphs are always down/up mixed to stereo for now. */
static const uint32_t ChannelCount = 2;
/* The size of this buffer comes from the fact that some audio backends can