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

make use of QThread::requestInterruption

This commit is contained in:
Nils Fenner 2015-11-29 23:37:42 +01:00
parent 02f5f0a391
commit 535bb212f5
No known key found for this signature in database
GPG Key ID: 9591A163FF9BE04C

View File

@ -151,19 +151,13 @@ class AudioMeter : public QThread
{ {
public: public:
AudioMeter() AudioMeter()
: mActive(false)
{ {
connect(this, &AudioMeter::finished, this, &AudioMeter::deleteLater); connect(this, &AudioMeter::finished, this, &AudioMeter::deleteLater);
} }
void waitForData(QMutex* condition) inline void stop()
{ {
mCheckGainChanged.wait(condition); requestInterruption();
}
void monitorFrame()
{
mDoMonitoring.wakeAll();
} }
private: private:
@ -174,9 +168,8 @@ private:
Audio& audio = Audio::getInstance(); Audio& audio = Audio::getInstance();
mNewMaxGain = 0.f; mNewMaxGain = 0.f;
mActive = true;
while (mActive) { while (!isInterruptionRequested()) {
int16_t buff[framesize] = {0}; int16_t buff[framesize] = {0};
if (audio.tryCaptureSamples(buff, AUDIO_FRAME_SAMPLE_COUNT)) { if (audio.tryCaptureSamples(buff, AUDIO_FRAME_SAMPLE_COUNT)) {
mMeterLock.lock(); mMeterLock.lock();
@ -200,7 +193,6 @@ public:
QMutex mMeterLock; QMutex mMeterLock;
QWaitCondition mDoMonitoring; QWaitCondition mDoMonitoring;
QWaitCondition mCheckGainChanged; QWaitCondition mCheckGainChanged;
bool mActive;
qreal mNewMaxGain; qreal mNewMaxGain;
}; };
@ -253,7 +245,7 @@ void AudioMeterListener::doListen()
mAudioMeter->monitorFrame(); mAudioMeter->monitorFrame();
} }
mAudioMeter->mActive = false; mAudioMeter->requestInterruption();
} }
@ -285,6 +277,8 @@ Audio::Audio()
Audio::~Audio() Audio::~Audio()
{ {
if (d->mAudioMeter)
d->mAudioMeter->stop();
d->audioThread->exit(); d->audioThread->exit();
d->audioThread->wait(); d->audioThread->wait();
d->cleanupInput(); d->cleanupInput();