diff --git a/src/blackcore/afv/clients/afvclient.cpp b/src/blackcore/afv/clients/afvclient.cpp index a288b4cba..e3cc9ac14 100644 --- a/src/blackcore/afv/clients/afvclient.cpp +++ b/src/blackcore/afv/clients/afvclient.cpp @@ -203,7 +203,7 @@ namespace BlackCore { // Method needs to be executed in the object thread since it will create new QObject children QPointer myself(this); - QMetaObject::invokeMethod(this, [ = ]() { if (myself) disconnectFrom(stop); }); + QMetaObject::invokeMethod(this, [ = ]() { if (myself) { disconnectFrom(stop); }}); return; } @@ -260,7 +260,8 @@ namespace BlackCore if (QThread::currentThread() != this->thread()) { // Method needs to be executed in the object thread since it will create new QObject children - QMetaObject::invokeMethod(this, [ = ]() { startAudio(inputDevice, outputDevice); }); + QPointer myself(this); + QMetaObject::invokeMethod(this, [ = ]() { if (myself) { startAudio(inputDevice, outputDevice); }}); return; } @@ -364,6 +365,23 @@ namespace BlackCore emit this->stoppedAudio(); } + void CAfvClient::restartAudio() + { + if (!m_isStarted) + { + // just need to start + this->startAudio(); + return; + } + + this->stopAudio(); + QPointer myself(this); + QTimer::singleShot(1000, this, [ = ] + { + if (myself) { myself->startAudio(); } + }); + } + double CAfvClient::getDeviceInputVolume() const { if (m_input) { return m_input->getDeviceInputVolume(); } diff --git a/src/blackcore/afv/clients/afvclient.h b/src/blackcore/afv/clients/afvclient.h index 579997956..6d1deebb9 100644 --- a/src/blackcore/afv/clients/afvclient.h +++ b/src/blackcore/afv/clients/afvclient.h @@ -126,6 +126,7 @@ namespace BlackCore void startAudio(const BlackMisc::Audio::CAudioDeviceInfo &inputDevice, const BlackMisc::Audio::CAudioDeviceInfo &outputDevice); Q_INVOKABLE void startAudio(const QString &inputDeviceName, const QString &outputDeviceName); void stopAudio(); + void restartAudio(); //! @} //! The device's volume 0..1 @{