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

privatized open/close audio devices

This commit is contained in:
Nils Fenner 2015-11-11 01:30:41 +01:00
parent f6c09104e4
commit 68e7aef916
No known key found for this signature in database
GPG Key ID: 9591A163FF9BE04C
2 changed files with 26 additions and 50 deletions

View File

@ -75,12 +75,12 @@ Audio::Audio()
Audio::~Audio() Audio::~Audio()
{ {
closeInput();
closeOutput();
audioThread->exit(); audioThread->exit();
audioThread->wait(); audioThread->wait();
if (audioThread->isRunning()) if (audioThread->isRunning())
audioThread->terminate(); audioThread->terminate();
cleanupInput();
cleanupOutput();
} }
/** /**
@ -171,7 +171,11 @@ void Audio::unsubscribeInput()
void Audio::subscribeOutput() void Audio::subscribeOutput()
{ {
QMutexLocker locker(&audioOutLock); QMutexLocker locker(&audioOutLock);
internalSubscribeOutput();
}
void Audio::internalSubscribeOutput()
{
if (!alOutDev) if (!alOutDev)
initOutput(Settings::getInstance().getOutDev()); initOutput(Settings::getInstance().getOutDev());
@ -191,15 +195,6 @@ void Audio::unsubscribeOutput()
cleanupOutput(); cleanupOutput();
} }
/**
Open an input device, use before suscribing
*/
void Audio::openInput(const QString& inDevDescr)
{
QMutexLocker lock(&audioInLock);
initInput(inDevDescr);
}
void Audio::initInput(const QString& inDevDescr) void Audio::initInput(const QString& inDevDescr)
{ {
qDebug() << "Opening audio input" << inDevDescr; qDebug() << "Opening audio input" << inDevDescr;
@ -264,14 +259,10 @@ void Audio::initInput(const QString& inDevDescr)
} }
/** /**
Open an output device @internal
*/
bool Audio::openOutput(const QString &outDevDescr)
{
QMutexLocker lock(&audioOutLock);
return initOutput(outDevDescr);
}
Open an audio output device
*/
bool Audio::initOutput(const QString& outDevDescr) bool Audio::initOutput(const QString& outDevDescr)
{ {
qDebug() << "Opening audio output" << outDevDescr; qDebug() << "Opening audio output" << outDevDescr;
@ -335,24 +326,6 @@ bool Audio::initOutput(const QString& outDevDescr)
return false; return false;
} }
/**
Close an input device, please don't use unless everyone's unsuscribed
*/
void Audio::closeInput()
{
QMutexLocker locker(&audioInLock);
cleanupInput();
}
/**
Close an output device
*/
void Audio::closeOutput()
{
QMutexLocker locker(&audioOutLock);
cleanupOutput();
}
/** /**
Play a 44100Hz mono 16bit PCM sound Play a 44100Hz mono 16bit PCM sound
*/ */
@ -360,11 +333,7 @@ void Audio::playMono16Sound(const QByteArray& data)
{ {
QMutexLocker lock(&audioOutLock); QMutexLocker lock(&audioOutLock);
if (!alOutDev) internalSubscribeOutput();
{
if (!initOutput(Settings::getInstance().getOutDev()))
return;
}
ALuint buffer; ALuint buffer;
alGenBuffers(1, &buffer); alGenBuffers(1, &buffer);
@ -484,6 +453,11 @@ void Audio::playAudioBuffer(ALuint alSource, const int16_t *data, int samples, u
alSourcePlay(alSource); alSourcePlay(alSource);
} }
/**
@internal
Close active audio input device.
*/
void Audio::cleanupInput() void Audio::cleanupInput()
{ {
mInputInitialized = false; mInputInitialized = false;
@ -503,6 +477,11 @@ void Audio::cleanupInput()
} }
} }
/**
@internal
Close active audio output device
*/
void Audio::cleanupOutput() void Audio::cleanupOutput()
{ {
mOutputInitialized = false; mOutputInitialized = false;

View File

@ -60,13 +60,6 @@ public:
void setInputVolume(qreal volume); void setInputVolume(qreal volume);
void subscribeInput();
void unsubscribeInput();
void subscribeOutput();
void unsubscribeOutput();
void openInput(const QString& inDevDescr);
bool openOutput(const QString& outDevDescr);
inline void reinitInput(const QString& inDevDesc) inline void reinitInput(const QString& inDevDesc)
{ {
QMutexLocker locker(&audioInLock); QMutexLocker locker(&audioInLock);
@ -103,8 +96,10 @@ public:
#endif #endif
public slots: public slots:
void closeInput(); void subscribeInput();
void closeOutput(); void subscribeOutput();
void unsubscribeInput();
void unsubscribeOutput();
void playGroupAudio(int group, int peer, const int16_t* data, void playGroupAudio(int group, int peer, const int16_t* data,
unsigned samples, uint8_t channels, unsigned sample_rate); unsigned samples, uint8_t channels, unsigned sample_rate);
@ -115,6 +110,8 @@ private:
Audio(); Audio();
~Audio(); ~Audio();
void internalSubscribeOutput();
void initInput(const QString& inDevDescr); void initInput(const QString& inDevDescr);
bool initOutput(const QString& outDevDescr); bool initOutput(const QString& outDevDescr);
void cleanupInput(); void cleanupInput();