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

fix(audio): move audio timers to and start from audioThread

Fix #5053
This commit is contained in:
Anthony Bilinski 2018-04-10 20:01:46 -07:00
parent 97bc4a9b4a
commit 5d0f9509a8
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C

View File

@ -54,20 +54,28 @@ OpenAL::OpenAL()
alcGetError(nullptr);
audioThread->setObjectName("qTox Audio");
QObject::connect(audioThread, &QThread::finished, &voiceTimer, &QTimer::stop);
QObject::connect(audioThread, &QThread::finished, &captureTimer, &QTimer::stop);
QObject::connect(audioThread, &QThread::finished, &playMono16Timer, &QTimer::stop);
QObject::connect(audioThread, &QThread::finished, audioThread, &QThread::deleteLater);
moveToThread(audioThread);
voiceTimer.setSingleShot(true);
voiceTimer.moveToThread(audioThread);
connect(this, &Audio::startActive, &voiceTimer, static_cast<void (QTimer::*)(int)>(&QTimer::start));
connect(&voiceTimer, &QTimer::timeout, this, &Audio::stopActive);
connect(&captureTimer, &QTimer::timeout, this, &OpenAL::doAudio);
captureTimer.setInterval(AUDIO_FRAME_DURATION / 2);
captureTimer.setSingleShot(false);
captureTimer.start();
captureTimer.moveToThread(audioThread);
// TODO for Qt 5.6+: use qOverload
connect(audioThread, &QThread::started, &captureTimer, static_cast<void (QTimer::*)(void)>(&QTimer::start));
connect(&playMono16Timer, &QTimer::timeout, this, &OpenAL::playMono16SoundCleanup);
playMono16Timer.setSingleShot(true);
playMono16Timer.moveToThread(audioThread);
audioThread->start();
}
@ -413,7 +421,7 @@ void OpenAL::playMono16Sound(const QByteArray& data)
alSourcePlay(alMainSource);
int durationMs = data.size() * 1000 / 2 / 44100;
playMono16Timer.start(durationMs + 50);
QMetaObject::invokeMethod(&playMono16Timer, "start", Q_ARG(int, durationMs + 50));
}
void OpenAL::playAudioBuffer(uint sourceId, const int16_t* data, int samples, unsigned channels,