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

cleanup AudioPrivate

* rename mAudioMeter -> audioMeter
* move class declaration below other classes
This commit is contained in:
Nils Fenner 2015-12-05 15:04:32 +01:00
parent ace3662757
commit d8607324ce
No known key found for this signature in database
GPG Key ID: 9591A163FF9BE04C

View File

@ -58,48 +58,6 @@
Audio* Audio::instance{nullptr}; Audio* Audio::instance{nullptr};
class AudioPrivate
{
public:
AudioPrivate()
: alInDev(nullptr)
, alOutDev(nullptr)
, alContext(nullptr)
, inputVolume(1.f)
, outputVolume(1.f)
, audioThread(new QThread())
, inputInitialized(false)
, outputInitialized(false)
{
audioThread->setObjectName("qTox Audio");
QObject::connect(audioThread, &QThread::finished, audioThread, &QThread::deleteLater);
}
void initInput(const QString& inDevDescr);
bool initOutput(const QString& outDevDescr);
void cleanupInput();
void cleanupOutput();
public:
ALCdevice* alInDev;
ALCdevice* alOutDev;
ALCcontext* alContext;
ALuint alMainSource;
qreal inputVolume;
qreal outputVolume;
QThread* audioThread;
QMutex audioLock;
Audio::PtrList inputSubscriptions;
Audio::PtrList outputSubscriptions;
bool inputInitialized;
bool outputInitialized;
QPointer<AudioMeter> mAudioMeter;
};
/** /**
@class AudioPlayer @class AudioPlayer
@ -192,6 +150,58 @@ public:
qreal mNewMaxGain; qreal mNewMaxGain;
}; };
class AudioPrivate
{
public:
AudioPrivate()
: audioThread(new QThread)
, alInDev(nullptr)
, alOutDev(nullptr)
, alContext(nullptr)
, inputVolume(1.f)
, outputVolume(1.f)
, inputInitialized(false)
, outputInitialized(false)
{
audioThread->setObjectName("qTox Audio");
QObject::connect(audioThread, &QThread::finished, audioThread, &QThread::deleteLater);
}
~AudioPrivate()
{
if (audioMeter)
audioMeter->stop();
audioThread->exit();
audioThread->wait();
cleanupInput();
cleanupOutput();
}
void initInput(const QString& inDevDescr);
bool initOutput(const QString& outDevDescr);
void cleanupInput();
void cleanupOutput();
public:
QThread* audioThread;
QMutex audioLock;
ALCdevice* alInDev;
ALCdevice* alOutDev;
ALCcontext* alContext;
ALuint alMainSource;
qreal inputVolume;
qreal outputVolume;
bool inputInitialized;
bool outputInitialized;
Audio::PtrList inputSubscriptions;
Audio::PtrList outputSubscriptions;
QPointer<AudioMeter> audioMeter;
};
AudioMeterListener::AudioMeterListener(AudioMeter* measureThread) AudioMeterListener::AudioMeterListener(AudioMeter* measureThread)
: mActive(false) : mActive(false)
, mAudioMeter(measureThread) , mAudioMeter(measureThread)
@ -268,10 +278,10 @@ Audio& Audio::getInstance()
AudioMeterListener* Audio::createAudioMeterListener() const AudioMeterListener* Audio::createAudioMeterListener() const
{ {
if (!d->mAudioMeter) if (!d->audioMeter)
d->mAudioMeter = new AudioMeter; d->audioMeter = new AudioMeter;
return new AudioMeterListener(d->mAudioMeter); return new AudioMeterListener(d->audioMeter);
} }
Audio::Audio() Audio::Audio()
@ -281,12 +291,7 @@ Audio::Audio()
Audio::~Audio() Audio::~Audio()
{ {
if (d->mAudioMeter) delete d;
d->mAudioMeter->stop();
d->audioThread->exit();
d->audioThread->wait();
d->cleanupInput();
d->cleanupOutput();
} }
/** /**