From 0a24d80291a0c80b6b5be41980c5f0c76b97d7c5 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sun, 13 Oct 2019 01:42:00 +0200 Subject: [PATCH] [AFV], Ref T730 only startAudio and stopAudio * start audio restarts if devices change * restart no longer needed * stop normally is only needed at the end of the lifetime of CAfvClient * signal: startAudio --- src/blackcore/afv/clients/afvclient.cpp | 41 ++++++++++++------------- src/blackcore/afv/clients/afvclient.h | 6 ++-- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/blackcore/afv/clients/afvclient.cpp b/src/blackcore/afv/clients/afvclient.cpp index 8a954ea26..e924fd23d 100644 --- a/src/blackcore/afv/clients/afvclient.cpp +++ b/src/blackcore/afv/clients/afvclient.cpp @@ -187,38 +187,33 @@ namespace BlackCore this->setNormalizedOutputVolume(mute ? 0 : 50); } - void CAfvClient::restartWithNewDevices(const CAudioDeviceInfo &inputDevice, const CAudioDeviceInfo &outputDevice) + void CAfvClient::startAudio(const CAudioDeviceInfo &inputDevice, const CAudioDeviceInfo &outputDevice) { if (QThread::currentThread() != this->thread()) { // Method needs to be executed in the object thread since it will create new QObject children - QPointer myself(this); - QMetaObject::invokeMethod(this, [ = ]() { if (myself) restartWithNewDevices(inputDevice, outputDevice); }); - } - - this->stopAudio(); - this->startAudio(inputDevice, outputDevice, allTransceiverIds()); - } - - void CAfvClient::startAudio(const CAudioDeviceInfo &inputDevice, const CAudioDeviceInfo &outputDevice, const QVector &transceiverIDs) - { - 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, transceiverIDs); }); + QMetaObject::invokeMethod(this, [ = ]() { startAudio(inputDevice, outputDevice); }); return; } if (m_isStarted) { - CLogMessage(this).info(u"Client already started"); - return; + if (this->usesSameDevices(inputDevice, outputDevice)) + { + CLogMessage(this).info(u"Client already started for '%1'/'%2'") << inputDevice.getName() << outputDevice.getName(); + return; + } + this->stopAudio(); } this->initTransceivers(); - if (m_soundcardSampleProvider) { m_soundcardSampleProvider->deleteLater(); } - m_soundcardSampleProvider = new CSoundcardSampleProvider(SampleRate, transceiverIDs, this); + if (m_soundcardSampleProvider) + { + m_soundcardSampleProvider->disconnect(); + m_soundcardSampleProvider->deleteLater(); + } + m_soundcardSampleProvider = new CSoundcardSampleProvider(SampleRate, allTransceiverIds(), this); connect(m_soundcardSampleProvider, &CSoundcardSampleProvider::receivingCallsignsChanged, this, &CAfvClient::receivingCallsignsChanged); if (m_outputSampleProvider) { m_outputSampleProvider->deleteLater(); } @@ -237,13 +232,15 @@ namespace BlackCore CLogMessage(this).info(u"Started [Input: %1] [Output: %2]") << inputDevice.getName() << outputDevice.getName(); this->onPositionUpdateTimer(); // update values + + emit this->startedAudio(inputDevice, outputDevice); } void CAfvClient::startAudio(const QString &inputDeviceName, const QString &outputDeviceName) { - const CAudioDeviceInfo i(CAudioDeviceInfo::InputDevice, inputDeviceName); - const CAudioDeviceInfo o(CAudioDeviceInfo::OutputDevice, outputDeviceName); - this->startAudio(i, o, allTransceiverIds()); + const CAudioDeviceInfo i = CAudioDeviceInfoList::allInputDevices().findByName(inputDeviceName); + const CAudioDeviceInfo o = CAudioDeviceInfoList::allOutputDevices().findByName(outputDeviceName); + this->startAudio(i, o); } void CAfvClient::stopAudio() diff --git a/src/blackcore/afv/clients/afvclient.h b/src/blackcore/afv/clients/afvclient.h index 9a5c99fdb..014601a3a 100644 --- a/src/blackcore/afv/clients/afvclient.h +++ b/src/blackcore/afv/clients/afvclient.h @@ -107,8 +107,7 @@ namespace BlackCore //! @} //! Start/stop client @{ - void restartWithNewDevices(const BlackMisc::Audio::CAudioDeviceInfo &inputDevice, const BlackMisc::Audio::CAudioDeviceInfo &outputDevice); - void startAudio(const BlackMisc::Audio::CAudioDeviceInfo &inputDevice, const BlackMisc::Audio::CAudioDeviceInfo &outputDevice, const QVector &transceiverIDs); + void startAudio(const BlackMisc::Audio::CAudioDeviceInfo &inputDevice, const BlackMisc::Audio::CAudioDeviceInfo &outputDevice); Q_INVOKABLE void startAudio(const QString &inputDeviceName, const QString &outputDeviceName); void stopAudio(); //! @} @@ -244,6 +243,9 @@ namespace BlackCore void outputVolumePeakVU(double value); //! @} + //! Started audio with devices + void startedAudio(const BlackMisc::Audio::CAudioDeviceInfo &inputDevice, const BlackMisc::Audio::CAudioDeviceInfo &outputDevice); + protected: //! \copydoc BlackMisc::CContinuousWorker::initialize virtual void initialize() override;