1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix: don't subscribe to in/out device when initialization failed

This commit is contained in:
Nils Fenner 2015-12-13 23:02:48 +01:00
parent 0615c7c3c6
commit e73fd27d8b
No known key found for this signature in database
GPG Key ID: 9591A163FF9BE04C

View File

@ -181,7 +181,7 @@ public:
cleanupOutput(); cleanupOutput();
} }
void initInput(const QString& inDevDescr); bool initInput(const QString& inDevDescr);
bool initOutput(const QString& outDevDescr); bool initOutput(const QString& outDevDescr);
void cleanupInput(); void cleanupInput();
void cleanupOutput(); void cleanupOutput();
@ -377,8 +377,12 @@ void Audio::subscribeInput()
{ {
QMutexLocker locker(&d->audioLock); QMutexLocker locker(&d->audioLock);
if (!d->alInDev) if (!d->alInDev) {
d->initInput(Settings::getInstance().getInDev()); if (!d->initInput(Settings::getInstance().getInDev())) {
qWarning("Failed to subscribe to audio input device.");
return;
}
}
d->inSubscriptions++; d->inSubscriptions++;
qDebug() << "Subscribed to audio input device [" << d->inSubscriptions << "subscriptions ]"; qDebug() << "Subscribed to audio input device [" << d->inSubscriptions << "subscriptions ]";
@ -402,13 +406,13 @@ void Audio::unsubscribeInput()
d->cleanupInput(); d->cleanupInput();
} }
void AudioPrivate::initInput(const QString& inDevDescr) bool AudioPrivate::initInput(const QString& inDevDescr)
{ {
qDebug() << "Opening audio input" << inDevDescr; qDebug() << "Opening audio input" << inDevDescr;
inputInitialized = false; inputInitialized = false;
if (inDevDescr == "none") if (inDevDescr == "none")
return; return true;
assert(!alInDev); assert(!alInDev);
@ -447,18 +451,15 @@ void AudioPrivate::initInput(const QString& inDevDescr)
qWarning() << "Cannot open input audio device" << inDevDescr; qWarning() << "Cannot open input audio device" << inDevDescr;
// Restart the capture if necessary // Restart the capture if necessary
if (alInDev) if (alInDev) {
{
alcCaptureStart(alInDev); alcCaptureStart(alInDev);
} } else {
else qCritical() << "Failed to initialize audio input device:" << inDevDescr;
{ return false;
#if (FIX_SND_PCM_PREPARE_BUG)
alcCaptureStart(alInDev);
#endif
} }
inputInitialized = true; inputInitialized = true;
return true;
} }
/** /**
@ -744,8 +745,12 @@ void Audio::subscribeOutput(SID& sid)
{ {
QMutexLocker locker(&d->audioLock); QMutexLocker locker(&d->audioLock);
if (!d->alOutDev) if (!d->alOutDev) {
d->initOutput(Settings::getInstance().getOutDev()); if (!d->initOutput(Settings::getInstance().getOutDev())) {
qWarning("Failed to subscribe to audio input device.");
return;
}
}
alGenSources(1, &sid); alGenSources(1, &sid);
assert(sid); assert(sid);