mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 18:13:05 +02:00
rather than do checkDevices to find new audio devices every 2 seconds, do each check 2 seconds after the previous one has completed. This is done to avoid swamping the thread pool when the check takes a long time
This commit is contained in:
parent
5729d35c48
commit
4d34b12f06
1 changed files with 11 additions and 4 deletions
|
@ -244,13 +244,20 @@ AudioClient::AudioClient() :
|
||||||
// initialize wasapi; if getAvailableDevices is called from the CheckDevicesThread before this, it will crash
|
// initialize wasapi; if getAvailableDevices is called from the CheckDevicesThread before this, it will crash
|
||||||
getAvailableDevices(QAudio::AudioInput);
|
getAvailableDevices(QAudio::AudioInput);
|
||||||
getAvailableDevices(QAudio::AudioOutput);
|
getAvailableDevices(QAudio::AudioOutput);
|
||||||
|
|
||||||
// start a thread to detect any device changes
|
// start a thread to detect any device changes
|
||||||
_checkDevicesTimer = new QTimer(this);
|
_checkDevicesTimer = new QTimer(this);
|
||||||
connect(_checkDevicesTimer, &QTimer::timeout, this, [this] {
|
|
||||||
QtConcurrent::run(QThreadPool::globalInstance(), [this] { checkDevices(); });
|
|
||||||
});
|
|
||||||
const unsigned long DEVICE_CHECK_INTERVAL_MSECS = 2 * 1000;
|
const unsigned long DEVICE_CHECK_INTERVAL_MSECS = 2 * 1000;
|
||||||
|
connect(_checkDevicesTimer, &QTimer::timeout, this, [=] {
|
||||||
|
QtConcurrent::run(QThreadPool::globalInstance(), [=] {
|
||||||
|
checkDevices();
|
||||||
|
// On some systems (Ubuntu) checking all the audio devices can take more than 2 seconds. To
|
||||||
|
// avoid consuming all of the thread pool, don't start the check interval until the previous
|
||||||
|
// check has completed.
|
||||||
|
QMetaObject::invokeMethod(_checkDevicesTimer, "start", Q_ARG(int, DEVICE_CHECK_INTERVAL_MSECS));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
_checkDevicesTimer->setSingleShot(true);
|
||||||
_checkDevicesTimer->start(DEVICE_CHECK_INTERVAL_MSECS);
|
_checkDevicesTimer->start(DEVICE_CHECK_INTERVAL_MSECS);
|
||||||
|
|
||||||
// start a thread to detect peak value changes
|
// start a thread to detect peak value changes
|
||||||
|
|
Loading…
Reference in a new issue