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()
{
closeInput();
closeOutput();
audioThread->exit();
audioThread->wait();
if (audioThread->isRunning())
audioThread->terminate();
cleanupInput();
cleanupOutput();
}
/**
@ -171,7 +171,11 @@ void Audio::unsubscribeInput()
void Audio::subscribeOutput()
{
QMutexLocker locker(&audioOutLock);
internalSubscribeOutput();
}
void Audio::internalSubscribeOutput()
{
if (!alOutDev)
initOutput(Settings::getInstance().getOutDev());
@ -191,15 +195,6 @@ void Audio::unsubscribeOutput()
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)
{
qDebug() << "Opening audio input" << inDevDescr;
@ -264,14 +259,10 @@ void Audio::initInput(const QString& inDevDescr)
}
/**
Open an output device
*/
bool Audio::openOutput(const QString &outDevDescr)
{
QMutexLocker lock(&audioOutLock);
return initOutput(outDevDescr);
}
@internal
Open an audio output device
*/
bool Audio::initOutput(const QString& outDevDescr)
{
qDebug() << "Opening audio output" << outDevDescr;
@ -335,24 +326,6 @@ bool Audio::initOutput(const QString& outDevDescr)
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
*/
@ -360,11 +333,7 @@ void Audio::playMono16Sound(const QByteArray& data)
{
QMutexLocker lock(&audioOutLock);
if (!alOutDev)
{
if (!initOutput(Settings::getInstance().getOutDev()))
return;
}
internalSubscribeOutput();
ALuint buffer;
alGenBuffers(1, &buffer);
@ -484,6 +453,11 @@ void Audio::playAudioBuffer(ALuint alSource, const int16_t *data, int samples, u
alSourcePlay(alSource);
}
/**
@internal
Close active audio input device.
*/
void Audio::cleanupInput()
{
mInputInitialized = false;
@ -503,6 +477,11 @@ void Audio::cleanupInput()
}
}
/**
@internal
Close active audio output device
*/
void Audio::cleanupOutput()
{
mOutputInitialized = false;

View File

@ -60,13 +60,6 @@ public:
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)
{
QMutexLocker locker(&audioInLock);
@ -103,8 +96,10 @@ public:
#endif
public slots:
void closeInput();
void closeOutput();
void subscribeInput();
void subscribeOutput();
void unsubscribeInput();
void unsubscribeOutput();
void playGroupAudio(int group, int peer, const int16_t* data,
unsigned samples, uint8_t channels, unsigned sample_rate);
@ -115,6 +110,8 @@ private:
Audio();
~Audio();
void internalSubscribeOutput();
void initInput(const QString& inDevDescr);
bool initOutput(const QString& outDevDescr);
void cleanupInput();