Fix underrun handler

merge-requests/9/merge
Phil Taylor 2022-04-06 22:02:43 +01:00
rodzic f00051ecd4
commit 0f7a5566fc
2 zmienionych plików z 11 dodań i 7 usunięć

Wyświetl plik

@ -166,7 +166,12 @@ bool audioHandler::init(audioSetup setupIn)
qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "thread id" << QThread::currentThreadId(); qInfo(logAudio()) << (setup.isinput ? "Input" : "Output") << "thread id" << QThread::currentThreadId();
underTimer = new QTimer();
underTimer->setSingleShot(true);
connect(underTimer, &QTimer::timeout, this, &audioHandler::clearUnderrun);
this->start(); this->start();
return true; return true;
} }
@ -571,15 +576,15 @@ void audioHandler::stateChanged(QAudio::State state)
case QAudio::IdleState: case QAudio::IdleState:
{ {
isUnderrun = true; isUnderrun = true;
if (underTimer->isActive()) {
underTimer->stop();
}
break; break;
} }
case QAudio::ActiveState: case QAudio::ActiveState:
{ {
//qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Audio started!"; //qDebug(logAudio()) << (setup.isinput ? "Input" : "Output") << "Audio started!";
if (underTimer == Q_NULLPTR) { if (!underTimer->isActive()) {
underTimer = new QTimer();
underTimer->setSingleShot(true);
connect(underTimer, &QTimer::timeout, this, &audioHandler::clearUnderrun);
underTimer->start(500); underTimer->start(500);
} }
break; break;
@ -601,6 +606,5 @@ void audioHandler::stateChanged(QAudio::State state)
void audioHandler::clearUnderrun() void audioHandler::clearUnderrun()
{ {
isUnderrun = false; isUnderrun = false;
delete underTimer; underTimer->stop();
underTimer = Q_NULLPTR;
} }

Wyświetl plik

@ -142,7 +142,7 @@ private:
OpusEncoder* encoder=Q_NULLPTR; OpusEncoder* encoder=Q_NULLPTR;
OpusDecoder* decoder=Q_NULLPTR; OpusDecoder* decoder=Q_NULLPTR;
QTimer * underTimer=Q_NULLPTR; QTimer* underTimer;
}; };