From d3a1eb1d60a71b3a939dd2a359c78e66b3e475f5 Mon Sep 17 00:00:00 2001 From: Roland Rossgotterer Date: Sat, 5 Oct 2019 20:51:24 +0200 Subject: [PATCH] [AFV] First version of threaded CAfvClient --- samples/afvclient/afvclientbridge.cpp | 15 +++ samples/afvclient/afvclientbridge.h | 97 +++++++++++++++++++ samples/afvclient/main.cpp | 20 +++- src/blackcore/afv/clients/afvclient.cpp | 81 +++++++++++++--- src/blackcore/afv/clients/afvclient.h | 27 +++--- .../afv/connection/apiserverconnection.cpp | 6 +- .../afv/connection/apiserverconnection.h | 5 +- src/blackcore/context/contextaudio.cpp | 6 +- src/blackcore/registermetadata.cpp | 5 + .../sampleprovider/resourcesound.cpp | 35 +++---- 10 files changed, 238 insertions(+), 59 deletions(-) create mode 100644 samples/afvclient/afvclientbridge.cpp create mode 100644 samples/afvclient/afvclientbridge.h diff --git a/samples/afvclient/afvclientbridge.cpp b/samples/afvclient/afvclientbridge.cpp new file mode 100644 index 000000000..8ffc41012 --- /dev/null +++ b/samples/afvclient/afvclientbridge.cpp @@ -0,0 +1,15 @@ +#include "afvclientbridge.h" + +using namespace BlackCore::Afv::Clients; + +CAfvClientBridge::CAfvClientBridge(CAfvClient *afvClient, QObject *parent) : + QObject(parent), + m_afvClient(afvClient) +{ + connect(afvClient, &CAfvClient::receivingCallsignsChanged, this, &CAfvClientBridge::receivingCallsignsChanged); + connect(afvClient, &CAfvClient::connectionStatusChanged, this, &CAfvClientBridge::connectionStatusChanged); + connect(afvClient, &CAfvClient::updatedFromOwnAircraftCockpit, this, &CAfvClientBridge::updatedFromOwnAircraftCockpit); + connect(afvClient, &CAfvClient::ptt, this, &CAfvClientBridge::ptt); + connect(afvClient, &CAfvClient::inputVolumePeakVU, this, &CAfvClientBridge::inputVolumePeakVU); + connect(afvClient, &CAfvClient::outputVolumePeakVU, this, &CAfvClientBridge::outputVolumePeakVU); +} diff --git a/samples/afvclient/afvclientbridge.h b/samples/afvclient/afvclientbridge.h new file mode 100644 index 000000000..3a23dd977 --- /dev/null +++ b/samples/afvclient/afvclientbridge.h @@ -0,0 +1,97 @@ +#ifndef AFVCLIENTBRIDGE_H +#define AFVCLIENTBRIDGE_H + +#include "blackcore/afv/clients/afvclient.h" +#include + +class CAfvClientBridge : public QObject +{ + Q_OBJECT + Q_PROPERTY(double inputVolumePeakVU READ getInputVolumePeakVU NOTIFY inputVolumePeakVU) + Q_PROPERTY(double outputVolumePeakVU READ getOutputVolumePeakVU NOTIFY outputVolumePeakVU) + Q_PROPERTY(BlackCore::Afv::Clients::CAfvClient::ConnectionStatus connectionStatus READ getConnectionStatus NOTIFY connectionStatusChanged) + Q_PROPERTY(QString receivingCallsignsCom1 READ getReceivingCallsignsCom1 NOTIFY receivingCallsignsChanged) + Q_PROPERTY(QString receivingCallsignsCom2 READ getReceivingCallsignsCom2 NOTIFY receivingCallsignsChanged) + +public: + CAfvClientBridge(BlackCore::Afv::Clients::CAfvClient *afvClient, QObject *parent = nullptr); + + double getInputVolumePeakVU() const { return m_afvClient->getInputVolumePeakVU(); } + double getOutputVolumePeakVU() const { return m_afvClient->getOutputVolumePeakVU(); } + + BlackCore::Afv::Clients::CAfvClient::ConnectionStatus getConnectionStatus() const + { + return m_afvClient->getConnectionStatus(); + } + + QString getReceivingCallsignsCom1() { return m_afvClient->getReceivingCallsignsCom1(); } + QString getReceivingCallsignsCom2() { return m_afvClient->getReceivingCallsignsCom2(); } + + Q_INVOKABLE void connectTo(const QString &cid, const QString &password, const QString &callsign) + { + m_afvClient->connectTo(cid, password, callsign); + } + + Q_INVOKABLE void disconnectFrom() { m_afvClient->disconnectFrom(); } + + //! Audio devices @{ + Q_INVOKABLE QStringList availableInputDevices() const { return m_afvClient->availableInputDevices(); } + Q_INVOKABLE QStringList availableOutputDevices() const { return m_afvClient->availableOutputDevices(); } + //! @} + + //! Enable/disable VHF simulation, true means effects are NOT used + Q_INVOKABLE void setBypassEffects(bool value) { /*m_afvClient->setBypassEffects(value);*/ } + + Q_INVOKABLE void startAudio(const QString &inputDeviceName, const QString &outputDeviceName) { m_afvClient->startAudio(inputDeviceName, outputDeviceName); } + + Q_INVOKABLE void enableTransceiver(quint16 id, bool enable) { /*m_afvClient->enableTransceiver(id, enable);*/ } + + Q_INVOKABLE void updateComFrequency(quint16 id, quint32 frequencyHz) { m_afvClient->updateComFrequency(id, frequencyHz); } + + //! Update own aircraft position + Q_INVOKABLE void updatePosition(double latitudeDeg, double longitudeDeg, double heightMeters) + { + m_afvClient->updatePosition(latitudeDeg, longitudeDeg, heightMeters); + } + + //! Push to talk @{ + Q_INVOKABLE void setPtt(bool active) { m_afvClient->setPtt(active); } + //! @} + + //! Loopback @{ + Q_INVOKABLE void setLoopBack(bool on) { m_afvClient->setLoopBack(on); } + Q_INVOKABLE bool isLoopback() const { return false; m_afvClient->isLoopback(); } + //! @} + + //! Input volume in dB, +-18dB @{ + Q_INVOKABLE void setInputVolumeDb(double valueDb) { /*m_afvClient->setInputVolumeDb(valueDb);*/ } + //! @} + + //! Output volume in dB, +-18dB @{ + Q_INVOKABLE void setOutputVolumeDb(double valueDb) { /*m_afvClient->setOutputVolumeDb(valueDb);*/ } + //! @} + +signals: + //! Receiving callsigns have been changed + //! \remark callsigns I do receive + void receivingCallsignsChanged(const BlackCore::Afv::Audio::TransceiverReceivingCallsignsChangedArgs &args); + + //! Connection status has been changed + void connectionStatusChanged(BlackCore::Afv::Clients::CAfvClient::ConnectionStatus status); + + //! Client updated from own aicraft data + void updatedFromOwnAircraftCockpit(); + + //! PTT status in this particular AFV client + void ptt(bool active, BlackMisc::Audio::PTTCOM pttcom, const BlackMisc::CIdentifier &identifier); + + //! VU levels @{ + void inputVolumePeakVU(double value); + void outputVolumePeakVU(double value); + //! @} + +private: + BlackCore::Afv::Clients::CAfvClient *m_afvClient = nullptr; +}; + +#endif // CAFVCLIENTBRIDGE_H diff --git a/samples/afvclient/main.cpp b/samples/afvclient/main.cpp index 6f73b10b8..62d83f469 100644 --- a/samples/afvclient/main.cpp +++ b/samples/afvclient/main.cpp @@ -1,8 +1,9 @@ -// #include "voiceclientui.h" - +#include "afvclientbridge.h" #include "blackcore/afv/model/atcstationmodel.h" #include "blackcore/afv/model/afvmapreader.h" #include "blackcore/afv/clients/afvclient.h" +#include "blackcore/registermetadata.h" + #include "blackcore/application.h" #include "blackmisc/network/user.h" #include "blackmisc/obfuscation.h" @@ -27,12 +28,21 @@ int main(int argc, char *argv[]) QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication qa(argc, argv); - CApplication a("sampleafvclient", CApplicationInfo::Sample); + BlackCore::registerMetadata(); + + BlackCore::CApplication a("sampleafvclient", CApplicationInfo::Sample); CAfvMapReader *afvMapReader = new CAfvMapReader(&a); afvMapReader->updateFromMap(); - CAfvClient voiceClient("https://voice1.vatsim.uk"); + CAfvClient *voiceClient = new CAfvClient("https://voice1.vatsim.uk", &qa); + CAfvClientBridge *voiceClientBridge = new CAfvClientBridge(voiceClient, &qa); + voiceClient->start(QThread::TimeCriticalPriority); + + QObject::connect(&qa, &QCoreApplication::aboutToQuit, [voiceClient]() + { + voiceClient->quitAndWait(); + }); // default user name QString defaultUserName("1234567"); @@ -45,7 +55,7 @@ int main(int argc, char *argv[]) QQmlApplicationEngine engine; QQmlContext *ctxt = engine.rootContext(); ctxt->setContextProperty("afvMapReader", afvMapReader); - ctxt->setContextProperty("voiceClient", &voiceClient); + ctxt->setContextProperty("voiceClient", voiceClientBridge); ctxt->setContextProperty("userName", defaultUserName); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); diff --git a/src/blackcore/afv/clients/afvclient.cpp b/src/blackcore/afv/clients/afvclient.cpp index 4f1ba6518..f4a09941d 100644 --- a/src/blackcore/afv/clients/afvclient.cpp +++ b/src/blackcore/afv/clients/afvclient.cpp @@ -37,7 +37,7 @@ namespace BlackCore } CAfvClient::CAfvClient(const QString &apiServer, QObject *parent) : - QObject(parent), CIdentifiable(this), + CContinuousWorker(parent, "CAfvClient"), m_connection(new CClientConnection(apiServer, this)), m_input(new CInput(SampleRate, this)), m_output(new Output(this)), @@ -64,6 +64,7 @@ namespace BlackCore void CAfvClient::initTransceivers() { + QMutexLocker lock(&m_mutex); m_transceivers = { { 0, UniCom, 48.5, 11.5, 1000.0, 1000.0 }, @@ -87,6 +88,13 @@ namespace BlackCore void CAfvClient::connectTo(const QString &cid, const QString &password, const QString &callsign) { + if (QThread::currentThread() != thread()) + { + // Method needs to be executed in the object thread since it will create new QObject children + QMetaObject::invokeMethod(this, [ = ]() { connectTo(cid, password, callsign); }); + return; + } + this->initWithContext(); m_callsign = callsign; m_connection->connectTo(cid, password, callsign); @@ -100,6 +108,13 @@ namespace BlackCore void CAfvClient::disconnectFrom() { + if (QThread::currentThread() != thread()) + { + // Method needs to be executed in the object thread since it will create new QObject children + QMetaObject::invokeMethod(this, [ = ]() { disconnectFrom(); }); + return; + } + m_connection->disconnectFrom(); emit connectionStatusChanged(Disconnected); } @@ -116,6 +131,7 @@ namespace BlackCore void CAfvClient::setBypassEffects(bool value) { + QMutexLocker lock(&m_mutex); if (soundcardSampleProvider) { soundcardSampleProvider->setBypassEffects(value); @@ -134,12 +150,12 @@ namespace BlackCore bool CAfvClient::restartWithNewDevices(const CAudioDeviceInfo &inputDevice, const CAudioDeviceInfo &outputDevice) { - this->stop(); - this->start(inputDevice, outputDevice, allTransceiverIds()); + this->stopAudio(); + this->startAudio(inputDevice, outputDevice, allTransceiverIds()); return true; } - void CAfvClient::start(const CAudioDeviceInfo &inputDevice, const CAudioDeviceInfo &outputDevice, const QVector &transceiverIDs) + void CAfvClient::startAudio(const CAudioDeviceInfo &inputDevice, const CAudioDeviceInfo &outputDevice, const QVector &transceiverIDs) { if (m_isStarted) { @@ -147,6 +163,13 @@ namespace BlackCore return; } + 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); }); + return; + } + this->initTransceivers(); soundcardSampleProvider = new CSoundcardSampleProvider(SampleRate, transceiverIDs, this); @@ -165,21 +188,22 @@ namespace BlackCore CLogMessage(this).info(u"Started [Input: %1] [Output: %2]") << inputDevice.getName() << outputDevice.getName(); } - void CAfvClient::start(const QString &inputDeviceName, const QString &outputDeviceName) + 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()); + } + + void CAfvClient::stopAudio() { if (QThread::currentThread() != this->thread()) { - QMetaObject::invokeMethod(this, "start", Q_ARG(QString, inputDeviceName), Q_ARG(QString, outputDeviceName)); + // Method needs to be executed in the object thread since it will create new QObject children + QMetaObject::invokeMethod(this, [ = ]() { stopAudio(); }); return; } - const CAudioDeviceInfo i(CAudioDeviceInfo::InputDevice, inputDeviceName); - const CAudioDeviceInfo o(CAudioDeviceInfo::OutputDevice, outputDeviceName); - this->start(i, o, allTransceiverIds()); - } - - void CAfvClient::stop() - { if (!m_isStarted) { CLogMessage(this).info(u"Client NOT started"); @@ -199,6 +223,8 @@ namespace BlackCore void CAfvClient::enableTransceiver(quint16 id, bool enable) { + QMutexLocker lock(&m_mutex); + if (enable) { m_enabledTransceivers.insert(id); } else { m_enabledTransceivers.remove(id); } @@ -233,6 +259,7 @@ namespace BlackCore // Fix rounding issues like 128074999 Hz -> 128075000 Hz quint32 roundedFrequencyHz = static_cast(qRound(frequencyHz / 1000.0)) * 1000; + QMutexLocker lock(&m_mutex); auto it = std::find_if(m_aliasedStations.begin(), m_aliasedStations.end(), [roundedFrequencyHz](const StationDto & d) { return d.frequencyAlias == roundedFrequencyHz; @@ -267,6 +294,7 @@ namespace BlackCore void CAfvClient::updatePosition(double latitudeDeg, double longitudeDeg, double heightMeters) { + QMutexLocker lock(&m_mutex); for (TransceiverDto &transceiver : m_transceivers) { transceiver.LatDeg = latitudeDeg; @@ -322,11 +350,13 @@ namespace BlackCore void CAfvClient::setTransmittingTransceivers(const QVector &transceivers) { + QMutexLocker lock(&m_mutex); m_transmittingTransceivers = transceivers; } bool CAfvClient::isTransmittingTransceiver(quint16 id) const { + QMutexLocker lock(&m_mutex); for (const TxTransceiverDto &dto : m_transmittingTransceivers) { if (dto.id == id) { return true; } @@ -355,6 +385,8 @@ namespace BlackCore } if (m_transmit == active) { return; } + + QMutexLocker lock(&m_mutex); m_transmit = active; if (soundcardSampleProvider) @@ -380,6 +412,8 @@ namespace BlackCore { if (valueDb > MaxDbIn) { valueDb = MaxDbIn; } if (valueDb < MinDbIn) { valueDb = MinDbIn; } + + QMutexLocker lock(&m_mutex); m_inputVolumeDb = valueDb; if (m_input) { @@ -421,8 +455,22 @@ namespace BlackCore this->setOutputVolumeDb(dB); } + double CAfvClient::getInputVolumePeakVU() const + { + QMutexLocker lock(&m_mutex); + return m_inputVolumeStream.PeakVU; + } + + double CAfvClient::getOutputVolumePeakVU() const + { + QMutexLocker lock(&m_mutex); + return m_outputVolumeStream.PeakVU; + } + void CAfvClient::opusDataAvailable(const OpusDataAvailableArgs &args) { + QMutexLocker lock(&m_mutex); + if (m_loopbackOn && m_transmit) { IAudioDto audioData; @@ -431,6 +479,7 @@ namespace BlackCore audioData.lastPacket = false; audioData.sequenceCounter = 0; + RxTransceiverDto com1 = { 0, m_transceivers.size() > 0 ? m_transceivers[0].frequencyHz : UniCom, 1.0 }; RxTransceiverDto com2 = { 1, m_transceivers.size() > 1 ? m_transceivers[1].frequencyHz : UniCom, 1.0 }; @@ -483,18 +532,21 @@ namespace BlackCore void CAfvClient::inputVolumeStream(const InputVolumeStreamArgs &args) { + QMutexLocker lock(&m_mutex); m_inputVolumeStream = args; emit inputVolumePeakVU(m_inputVolumeStream.PeakVU); } void CAfvClient::outputVolumeStream(const OutputVolumeStreamArgs &args) { + QMutexLocker lock(&m_mutex); m_outputVolumeStream = args; emit outputVolumePeakVU(m_outputVolumeStream.PeakVU); } QString CAfvClient::getReceivingCallsignsCom1() { + QMutexLocker lock(&m_mutex); if (soundcardSampleProvider) { return soundcardSampleProvider->getReceivingCallsigns(0); @@ -504,6 +556,7 @@ namespace BlackCore QString CAfvClient::getReceivingCallsignsCom2() { + QMutexLocker lock(&m_mutex); if (soundcardSampleProvider) { return soundcardSampleProvider->getReceivingCallsigns(1); @@ -578,6 +631,8 @@ namespace BlackCore { if (valueDb > MaxDbOut) { valueDb = MaxDbOut; } if (valueDb < MinDbOut) { valueDb = MinDbOut; } + + QMutexLocker lock(&m_mutex); m_outputVolumeDb = valueDb; m_outputVolume = qPow(10, m_outputVolumeDb / 20.0); diff --git a/src/blackcore/afv/clients/afvclient.h b/src/blackcore/afv/clients/afvclient.h index b38ac57a5..937fa9630 100644 --- a/src/blackcore/afv/clients/afvclient.h +++ b/src/blackcore/afv/clients/afvclient.h @@ -27,6 +27,7 @@ #include "blackmisc/logcategorylist.h" #include "blackmisc/identifiable.h" #include "blackmisc/settingscache.h" +#include "blackmisc/worker.h" #include #include @@ -35,6 +36,8 @@ #include #include +#include + namespace BlackCore { namespace Afv @@ -42,12 +45,12 @@ namespace BlackCore namespace Clients { //! AFV client - class BLACKCORE_EXPORT CAfvClient final : public QObject, public BlackMisc::CIdentifiable + class BLACKCORE_EXPORT CAfvClient final : public BlackMisc::CContinuousWorker { Q_OBJECT Q_PROPERTY(double inputVolumePeakVU READ getInputVolumePeakVU NOTIFY inputVolumePeakVU) Q_PROPERTY(double outputVolumePeakVU READ getOutputVolumePeakVU NOTIFY outputVolumePeakVU) - Q_PROPERTY(ConnectionStatus connectionStatus READ getConnectionStatus NOTIFY connectionStatusChanged) + Q_PROPERTY(BlackCore::Afv::Clients::CAfvClient::ConnectionStatus connectionStatus READ getConnectionStatus NOTIFY connectionStatusChanged) Q_PROPERTY(QString receivingCallsignsCom1 READ getReceivingCallsignsCom1 NOTIFY receivingCallsignsChanged) Q_PROPERTY(QString receivingCallsignsCom2 READ getReceivingCallsignsCom2 NOTIFY receivingCallsignsChanged) @@ -63,7 +66,7 @@ namespace BlackCore CAfvClient(const QString &apiServer, QObject *parent = nullptr); //! Dtor - virtual ~CAfvClient() override { this->stop(); } + virtual ~CAfvClient() override { this->stopAudio(); } //! Corresponding callsign QString callsign() const { return m_callsign; } @@ -100,9 +103,9 @@ namespace BlackCore //! @} bool restartWithNewDevices(const BlackMisc::Audio::CAudioDeviceInfo &inputDevice, const BlackMisc::Audio::CAudioDeviceInfo &outputDevice); - void start(const BlackMisc::Audio::CAudioDeviceInfo &inputDevice, const BlackMisc::Audio::CAudioDeviceInfo &outputDevice, const QVector &transceiverIDs); - Q_INVOKABLE void start(const QString &inputDeviceName, const QString &outputDeviceName); - void stop(); + void startAudio(const BlackMisc::Audio::CAudioDeviceInfo &inputDevice, const BlackMisc::Audio::CAudioDeviceInfo &outputDevice, const QVector &transceiverIDs); + Q_INVOKABLE void startAudio(const QString &inputDeviceName, const QString &outputDeviceName); + void stopAudio(); //! Enable COM unit/transceiver @{ Q_INVOKABLE void enableTransceiver(quint16 id, bool enable); @@ -159,8 +162,8 @@ namespace BlackCore //! @} //! VU values, 0..1 @{ - double getInputVolumePeakVU() const { return m_inputVolumeStream.PeakVU; } - double getOutputVolumePeakVU() const { return m_outputVolumeStream.PeakVU; } + double getInputVolumePeakVU() const; + double getOutputVolumePeakVU() const; //! @} //! Recently used device @{ @@ -176,7 +179,7 @@ namespace BlackCore signals: //! Receiving callsigns have been changed //! \remark callsigns I do receive - void receivingCallsignsChanged(const Audio::TransceiverReceivingCallsignsChangedArgs &args); + void receivingCallsignsChanged(const BlackCore::Afv::Audio::TransceiverReceivingCallsignsChangedArgs &args); //! Connection status has been changed void connectionStatusChanged(ConnectionStatus status); @@ -228,13 +231,13 @@ namespace BlackCore Audio::CSoundcardSampleProvider *soundcardSampleProvider = nullptr; BlackSound::SampleProvider::CVolumeSampleProvider *outputSampleProvider = nullptr; - bool m_transmit = false; + std::atomic_bool m_transmit = { false }; bool m_transmitHistory = false; QVector m_transmittingTransceivers; static const QVector &allTransceiverIds() { static const QVector transceiverIds{0, 1}; return transceiverIds; } bool m_isStarted = false; - bool m_loopbackOn = false; + std::atomic_bool m_loopbackOn = { false }; QDateTime m_startDateTimeUtc; double m_inputVolumeDb; @@ -253,6 +256,8 @@ namespace BlackCore void initTransceivers(); void initWithContext(); static bool hasContext(); + + mutable QMutex m_mutex; }; } // ns } // ns diff --git a/src/blackcore/afv/connection/apiserverconnection.cpp b/src/blackcore/afv/connection/apiserverconnection.cpp index da43b8c55..3ad082e5a 100644 --- a/src/blackcore/afv/connection/apiserverconnection.cpp +++ b/src/blackcore/afv/connection/apiserverconnection.cpp @@ -63,7 +63,7 @@ namespace BlackCore QNetworkRequest request(url); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); - QEventLoop loop(sApp); + QEventLoop loop; // posted in QAM thread, reply is nullptr if called from another thread QNetworkReply *reply = sApp->postToNetwork(request, CApplication::NoLogRequestId, QJsonDocument(obj).toJson(), @@ -160,7 +160,7 @@ namespace BlackCore { if (isShuttingDown()) { return {}; } - QEventLoop loop(sApp); + QEventLoop loop; QByteArray receivedData; // posted in QAM thread, reply is nullptr if called from another thread @@ -196,7 +196,7 @@ namespace BlackCore { if (isShuttingDown()) { return {}; } - QEventLoop loop(sApp); + QEventLoop loop; QByteArray receivedData; // posted in QAM thread, reply is nullptr if called from another thread diff --git a/src/blackcore/afv/connection/apiserverconnection.h b/src/blackcore/afv/connection/apiserverconnection.h index 511ed2347..98b7f3ed3 100644 --- a/src/blackcore/afv/connection/apiserverconnection.h +++ b/src/blackcore/afv/connection/apiserverconnection.h @@ -14,6 +14,7 @@ #include "blackmisc/logcategorylist.h" #include "blackcore/afv/dto.h" #include "blackcore/application.h" +#include "blackmisc/logmessage.h" #include #include @@ -78,7 +79,7 @@ namespace BlackCore { if (!m_isAuthenticated) { - CLogMessage(this).debug(u"AFV not authenticated"); + BlackMisc::CLogMessage(this).debug(u"AFV not authenticated"); return {}; } @@ -101,7 +102,7 @@ namespace BlackCore { if (! m_isAuthenticated) { - CLogMessage(this).debug(u"AFV not authenticated"); + BlackMisc::CLogMessage(this).debug(u"AFV not authenticated"); return {}; } diff --git a/src/blackcore/context/contextaudio.cpp b/src/blackcore/context/contextaudio.cpp index 886ef440b..81d5dc035 100644 --- a/src/blackcore/context/contextaudio.cpp +++ b/src/blackcore/context/contextaudio.cpp @@ -94,7 +94,7 @@ namespace BlackCore IContextAudio::~IContextAudio() { - m_voiceClient.stop(); + m_voiceClient.stopAudio(); } const CIdentifier &IContextAudio::audioRunsWhere() const @@ -394,11 +394,11 @@ namespace BlackCore { const CUser connectedUser = this->getIContextNetwork()->getConnectedServer().getUser(); m_voiceClient.connectTo(connectedUser.getId(), connectedUser.getPassword(), connectedUser.getCallsign().asString()); - m_voiceClient.start(CAudioDeviceInfo::getDefaultInputDevice(), CAudioDeviceInfo::getDefaultOutputDevice(), {0, 1}); + m_voiceClient.startAudio(CAudioDeviceInfo::getDefaultInputDevice(), CAudioDeviceInfo::getDefaultOutputDevice(), {0, 1}); } else if (to.isDisconnected()) { - m_voiceClient.stop(); + m_voiceClient.stopAudio(); m_voiceClient.disconnectFrom(); } } diff --git a/src/blackcore/registermetadata.cpp b/src/blackcore/registermetadata.cpp index 33d4fd00a..acce6f0b3 100644 --- a/src/blackcore/registermetadata.cpp +++ b/src/blackcore/registermetadata.cpp @@ -16,6 +16,7 @@ #include "blackcore/fsd/fsdclient.h" #include "blackcore/webreaderflags.h" #include "blackcore/aircraftmatcher.h" +#include "blackcore/afv/clients/afvclient.h" #include "blackmisc/dbus.h" #include "blackmisc/network/network.h" #include "blackmisc/valueobject.h" @@ -33,6 +34,10 @@ namespace BlackCore // however, does not harm if it is redundant qRegisterMetaType(); qRegisterMetaType(); + qRegisterMetaType(); + qRegisterMetaType("ConnectionStatus"); + qRegisterMetaType(); + qRegisterMetaType("TransceiverReceivingCallsignsChangedArgs"); qDBusRegisterMetaType(); qDBusRegisterMetaType(); diff --git a/src/blacksound/sampleprovider/resourcesound.cpp b/src/blacksound/sampleprovider/resourcesound.cpp index 7a9d8fb7d..5c1ada11b 100644 --- a/src/blacksound/sampleprovider/resourcesound.cpp +++ b/src/blacksound/sampleprovider/resourcesound.cpp @@ -36,32 +36,23 @@ namespace BlackSound { if (m_data->fileName.isEmpty()) { return false; } - QObject *parent = QCoreApplication::instance(); - Q_ASSERT(parent); - CWorker *worker = CWorker::fromTask(parent, "loadResourceSound", [this]() + CWavFile wavFile; + m_data->samples.clear(); + if (wavFile.open(m_data->fileName)) { - CWavFile wavFile; - - m_data->samples.clear(); - if (wavFile.open(m_data->fileName)) + if (wavFile.fileFormat().sampleType() == QAudioFormat::Float) { - if (wavFile.fileFormat().sampleType() == QAudioFormat::Float) - { - // Not implemented - // m_samples = convertFloatBytesTo16BitPCM(wavFile.audioData()); - } - else - { - m_data->samples = convertBytesTo32BitFloatPCM(wavFile.audioData()); - } + // Not implemented + // m_samples = convertFloatBytesTo16BitPCM(wavFile.audioData()); } - }); - worker->then([this]() - { - m_data->isLoaded = true; - }); + else + { + m_data->samples = convertBytesTo32BitFloatPCM(wavFile.audioData()); + } + } - return worker ? true : false; + m_data->isLoaded = true; + return true; } bool CResourceSound::isSameFileName(const QString &fn) const