Browse Source

use internal cleanup methods to close in-/output devices

pull/2509/head
Nils Fenner 10 years ago
parent
commit
26fc424986
No known key found for this signature in database
GPG Key ID: 9591A163FF9BE04C
  1. 105
      src/audio/audio.cpp
  2. 3
      src/audio/audio.h

105
src/audio/audio.cpp

@ -162,15 +162,13 @@ If the input device has no more subscriptions, it will be closed.
void Audio::unsubscribeInput() void Audio::unsubscribeInput()
{ {
qDebug() << "unsubscribing input" << inputSubscriptions; qDebug() << "unsubscribing input" << inputSubscriptions;
QMutexLocker locker(&audioInLock);
if (inputSubscriptions > 0) if (inputSubscriptions > 0)
inputSubscriptions--; inputSubscriptions--;
else if(inputSubscriptions < 0)
inputSubscriptions = 0;
if (!inputSubscriptions) { if (!inputSubscriptions) {
closeOutput(); cleanupInput();
closeInput();
}
} }
/** /**
@ -180,14 +178,7 @@ void Audio::openInput(const QString& inDevDescr)
{ {
QMutexLocker lock(&audioInLock); QMutexLocker lock(&audioInLock);
if (alInDev) { cleanupInput();
#if (!FIX_SND_PCM_PREPARE_BUG)
qDebug() << "stopping capture";
alcCaptureStop(alInDev);
#endif
alcCaptureCloseDevice(alInDev);
}
alInDev = nullptr;
if (inDevDescr == "none") if (inDevDescr == "none")
return; return;
@ -251,8 +242,8 @@ bool Audio::openOutput(const QString &outDevDescr)
qDebug() << "Opening audio output " + outDevDescr; qDebug() << "Opening audio output " + outDevDescr;
QMutexLocker lock(&audioOutLock); QMutexLocker lock(&audioOutLock);
auto* tmp = alOutDev; cleanupOutput();
alOutDev = nullptr;
if (outDevDescr != "none") if (outDevDescr != "none")
{ {
@ -285,12 +276,6 @@ bool Audio::openOutput(const QString &outDevDescr)
if (alOutDev) if (alOutDev)
{ {
if (alContext && alcMakeContextCurrent(nullptr) == ALC_TRUE)
alcDestroyContext(alContext);
if (tmp)
alcCloseDevice(tmp);
alContext = alcCreateContext(alOutDev, nullptr); alContext = alcCreateContext(alOutDev, nullptr);
if (alcMakeContextCurrent(alContext)) if (alcMakeContextCurrent(alContext))
{ {
@ -328,23 +313,7 @@ void Audio::closeInput()
{ {
qDebug() << "Closing input"; qDebug() << "Closing input";
QMutexLocker locker(&audioInLock); QMutexLocker locker(&audioInLock);
if (alInDev) cleanupInput();
{
#if (!FIX_SND_PCM_PREPARE_BUG)
qDebug() << "stopping capture";
alcCaptureStop(alInDev);
#endif
if (alcCaptureCloseDevice(alInDev) == ALC_TRUE)
{
alInDev = nullptr;
inputSubscriptions = 0;
}
else
{
qWarning() << "Failed to close input";
}
}
} }
/** /**
@ -354,20 +323,7 @@ void Audio::closeOutput()
{ {
qDebug() << "Closing output"; qDebug() << "Closing output";
QMutexLocker locker(&audioOutLock); QMutexLocker locker(&audioOutLock);
cleanupOutput();
if (alContext && alcMakeContextCurrent(nullptr) == ALC_TRUE)
{
alcDestroyContext(alContext);
alContext = nullptr;
}
if (alOutDev)
{
if (alcCloseDevice(alOutDev) == ALC_TRUE)
alOutDev = nullptr;
else
qWarning() << "Failed to close output";
}
} }
/** /**
@ -429,8 +385,6 @@ void Audio::playGroupAudioQueued(void*,int group, int peer, const int16_t* data,
emit static_cast<Core*>(core)->groupPeerAudioPlaying(group, peer); emit static_cast<Core*>(core)->groupPeerAudioPlaying(group, peer);
} }
/** /**
Must be called from the audio thread, plays a group call's received audio Must be called from the audio thread, plays a group call's received audio
*/ */
@ -503,6 +457,49 @@ void Audio::playAudioBuffer(ALuint alSource, const int16_t *data, int samples, u
alSourcePlay(alSource); alSourcePlay(alSource);
} }
void Audio::cleanupInput()
{
if (alInDev)
{
#if (!FIX_SND_PCM_PREPARE_BUG)
qDebug() << "stopping capture";
alcCaptureStop(alInDev);
#endif
if (alcCaptureCloseDevice(alInDev))
{
alInDev = nullptr;
inputSubscriptions = 0;
}
else
{
qWarning() << "Failed to close input";
}
}
}
void Audio::cleanupOutput()
{
if (inputSubscriptions)
cleanupInput();
if (alOutDev) {
alSourcei(alMainSource, AL_LOOPING, AL_FALSE);
alSourceStop(alMainSource);
alDeleteSources(1, &alMainSource);
ALCdevice* device = alcGetContextsDevice(alContext);
if (!alcMakeContextCurrent(nullptr))
qWarning("Failed to clear current audio context.");
alcDestroyContext(alContext);
alContext = nullptr;
if (!alcCloseDevice(device))
qWarning("Failed to close output.");
}
}
/** /**
Returns true if the input device is open and suscribed to Returns true if the input device is open and suscribed to
*/ */

3
src/audio/audio.h

@ -106,6 +106,9 @@ private:
Audio(); Audio();
~Audio(); ~Audio();
void cleanupInput();
void cleanupOutput();
private: private:
static Audio* instance; static Audio* instance;

Loading…
Cancel
Save