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

Audio: Fix crash when no devices available

This commit is contained in:
TheSpiritXIII 2015-08-05 10:36:57 -04:00 committed by Nils Fenner
parent a311b96376
commit 61eb302ff7
No known key found for this signature in database
GPG Key ID: 9591A163FF9BE04C
2 changed files with 17 additions and 3 deletions

View File

@ -199,7 +199,7 @@ void Audio::openInput(const QString& inDevDescr)
} }
void Audio::openOutput(const QString& outDevDescr) bool Audio::openOutput(const QString& outDevDescr)
{ {
QMutexLocker lock(audioOutLock); QMutexLocker lock(audioOutLock);
auto* tmp = alOutDev; auto* tmp = alOutDev;
@ -212,6 +212,7 @@ void Audio::openOutput(const QString& outDevDescr)
if (!alOutDev) if (!alOutDev)
{ {
qWarning() << "Cannot open output audio device " + outDevDescr; qWarning() << "Cannot open output audio device " + outDevDescr;
return false;
} }
else else
{ {
@ -226,6 +227,7 @@ void Audio::openOutput(const QString& outDevDescr)
{ {
qWarning() << "Cannot create output audio context"; qWarning() << "Cannot create output audio context";
alcCloseDevice(alOutDev); alcCloseDevice(alOutDev);
return false;
} }
else else
{ {
@ -239,6 +241,8 @@ void Audio::openOutput(const QString& outDevDescr)
Core* core = Core::getInstance(); Core* core = Core::getInstance();
if (core) if (core)
core->resetCallSources(); // Force to regen each group call's sources core->resetCallSources(); // Force to regen each group call's sources
return true;
} }
void Audio::closeInput() void Audio::closeInput()
@ -278,8 +282,12 @@ void Audio::closeOutput()
void Audio::playMono16Sound(const QByteArray& data) void Audio::playMono16Sound(const QByteArray& data)
{ {
QMutexLocker lock(audioOutLock); QMutexLocker lock(audioOutLock);
if (!alOutDev) if (!alOutDev)
openOutput(Settings::getInstance().getOutDev()); {
if (!openOutput(Settings::getInstance().getOutDev()))
return;
}
ALuint buffer; ALuint buffer;
alGenBuffers(1, &buffer); alGenBuffers(1, &buffer);
@ -325,6 +333,9 @@ void Audio::playGroupAudio(int group, int peer, const int16_t* data,
QMutexLocker lock(audioOutLock); QMutexLocker lock(audioOutLock);
if (!alOutDev)
return;
ToxGroupCall& call = Core::groupCalls[group]; ToxGroupCall& call = Core::groupCalls[group];
if (!call.active || call.muteVol) if (!call.active || call.muteVol)
@ -352,6 +363,9 @@ void Audio::playAudioBuffer(ALuint alSource, const int16_t *data, int samples, u
QMutexLocker lock(audioOutLock); QMutexLocker lock(audioOutLock);
if (!alOutDev)
return;
ALuint bufid; ALuint bufid;
ALint processed = 0, queued = 16; ALint processed = 0, queued = 16;
alGetSourcei(alSource, AL_BUFFERS_PROCESSED, &processed); alGetSourcei(alSource, AL_BUFFERS_PROCESSED, &processed);

View File

@ -56,7 +56,7 @@ public:
static void unsuscribeInput(); ///< Call once you don't need to capture on the open input device anymore. static void unsuscribeInput(); ///< Call once you don't need to capture on the open input device anymore.
static void openInput(const QString& inDevDescr); ///< Open an input device, use before suscribing static void openInput(const QString& inDevDescr); ///< Open an input device, use before suscribing
static void openOutput(const QString& outDevDescr); ///< Open an output device static bool openOutput(const QString& outDevDescr); ///< Open an output device
static void closeInput(); ///< Close an input device, please don't use unless everyone's unsuscribed static void closeInput(); ///< Close an input device, please don't use unless everyone's unsuscribed
static void closeOutput(); ///< Close an output device static void closeOutput(); ///< Close an output device