diff --git a/src/blackcore/afv/audio/callsignsampleprovider.cpp b/src/blackcore/afv/audio/callsignsampleprovider.cpp index 1a406d62a..eee8664d5 100644 --- a/src/blackcore/afv/audio/callsignsampleprovider.cpp +++ b/src/blackcore/afv/audio/callsignsampleprovider.cpp @@ -18,6 +18,8 @@ #include #include +#include +#include using namespace BlackMisc; using namespace BlackSound::SampleProvider; @@ -105,7 +107,7 @@ namespace BlackCore { m_callsign = callsign; CallsignDelayCache::instance().initialise(callsign); - m_type = aircraftType; + m_aircraftType = aircraftType; m_decoder.resetState(); m_inUse = true; setEffects(); @@ -125,7 +127,7 @@ namespace BlackCore { m_callsign = callsign; CallsignDelayCache::instance().initialise(callsign); - m_type = aircraftType; + m_aircraftType = aircraftType; m_decoder.resetState(); m_inUse = true; setEffects(true); @@ -169,7 +171,7 @@ namespace BlackCore m_inUse = false; setEffects(); m_callsign.clear(); - m_type.clear(); + m_aircraftType.clear(); } QVector CCallsignSampleProvider::decodeOpus(const QByteArray &opusData) @@ -230,6 +232,13 @@ namespace BlackCore setEffects(); } + QString CCallsignSampleProvider::toQString() const + { + return QStringLiteral("In use: ") % boolToYesNo(m_inUse) % + QStringLiteral(" cs: ") % m_callsign % + QStringLiteral(" type: ") % m_aircraftType; + } + } // ns } // ns } // ns diff --git a/src/blackcore/afv/audio/callsignsampleprovider.h b/src/blackcore/afv/audio/callsignsampleprovider.h index 8deeb99ae..7c37a7e1c 100644 --- a/src/blackcore/afv/audio/callsignsampleprovider.h +++ b/src/blackcore/afv/audio/callsignsampleprovider.h @@ -51,7 +51,7 @@ namespace BlackCore const QString &callsign() const { return m_callsign; } //! Type - const QString &type() const { return m_type; } + const QString &type() const { return m_aircraftType; } //! Is active? //! @{ @@ -73,6 +73,9 @@ namespace BlackCore //! Bypass effects void setBypassEffects(bool bypassEffects); + //! Info + QString toQString() const; + private: void timerElapsed(); void idle(); @@ -88,7 +91,7 @@ namespace BlackCore const int m_idleTimeoutMs = 500; QString m_callsign; - QString m_type; + QString m_aircraftType; bool m_inUse = false; bool m_bypassEffects = false; diff --git a/src/blackcore/afv/audio/receiversampleprovider.cpp b/src/blackcore/afv/audio/receiversampleprovider.cpp index 7cb28a652..7296f4a42 100644 --- a/src/blackcore/afv/audio/receiversampleprovider.cpp +++ b/src/blackcore/afv/audio/receiversampleprovider.cpp @@ -15,6 +15,7 @@ #include "blacksound/sampleprovider/samples.h" #include +#include using namespace BlackMisc; using namespace BlackMisc::Audio; @@ -115,13 +116,14 @@ namespace BlackCore // CLogMessage(this).debug(u"AFV Click..."); } + //! \todo KB 2020-04 not entirely correct, as it can be the number is the same, but changed callsign if (numberOfInUseInputs != m_lastNumberOfInUseInputs) { QStringList receivingCallsigns; for (const CCallsignSampleProvider *voiceInput : m_voiceInputs) { const QString callsign = voiceInput->callsign(); - if (! callsign.isEmpty()) + if (!callsign.isEmpty()) { receivingCallsigns.push_back(callsign); } @@ -151,7 +153,7 @@ namespace BlackCore voiceInput = *it; } - if (! voiceInput) + if (!voiceInput) { it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(), [](const CCallsignSampleProvider * p) { return p->inUse() == false; }); if (it != m_voiceInputs.end()) @@ -208,6 +210,29 @@ namespace BlackCore return m_frequencyHz; } + void CReceiverSampleProvider::logVoiceInputs(const QString &prefix, qint64 timeCheckOffsetMs) + { + if (timeCheckOffsetMs > 100) + { + const qint64 now = QDateTime::currentMSecsSinceEpoch(); + if (m_lastLogMessage + timeCheckOffsetMs > now) { return; } + m_lastLogMessage = now; + } + + QString l; + int no = 0; + for (const CCallsignSampleProvider *sp : m_voiceInputs) + { + if (!sp || !sp->inUse()) { continue; } // only log the ones in use + l += (l.isEmpty() ? QStringLiteral("") : QStringLiteral("\n")) % + prefix % + QString::number(no++) % QStringLiteral(": ") % sp->toQString(); + } + + if (l.isEmpty()) { return; } + CLogMessage(this).debug(l); + } + } // ns } // ns } // ns diff --git a/src/blackcore/afv/audio/receiversampleprovider.h b/src/blackcore/afv/audio/receiversampleprovider.h index 666b79849..0cfd2e949 100644 --- a/src/blackcore/afv/audio/receiversampleprovider.h +++ b/src/blackcore/afv/audio/receiversampleprovider.h @@ -87,6 +87,10 @@ namespace BlackCore //! Get frequency in Hz uint getFrequencyHz() const; + //! Log all inputs + //! \private DEBUG only + void logVoiceInputs(const QString &prefix = {}, qint64 timeCheckOffsetMs = -1); + signals: //! Receving callsigns have changed void receivingCallsignsChanged(const TransceiverReceivingCallsignsChangedArgs &args); @@ -100,10 +104,11 @@ namespace BlackCore quint16 m_id; BlackMisc::CSettingReadOnly m_audioSettings { this }; - BlackSound::SampleProvider::CVolumeSampleProvider *m_volume = nullptr; - BlackSound::SampleProvider::CMixingSampleProvider *m_mixer = nullptr; + BlackSound::SampleProvider::CVolumeSampleProvider *m_volume = nullptr; + BlackSound::SampleProvider::CMixingSampleProvider *m_mixer = nullptr; BlackSound::SampleProvider::CSinusGenerator *m_blockTone = nullptr; QVector m_voiceInputs; + qint64 m_lastLogMessage = -1; QString m_receivingCallsignsString; BlackMisc::Aviation::CCallsignSet m_receivingCallsigns; diff --git a/src/blackcore/afv/audio/soundcardsampleprovider.cpp b/src/blackcore/afv/audio/soundcardsampleprovider.cpp index 63ad467ec..8451a1c7f 100644 --- a/src/blackcore/afv/audio/soundcardsampleprovider.cpp +++ b/src/blackcore/afv/audio/soundcardsampleprovider.cpp @@ -8,7 +8,9 @@ #include "soundcardsampleprovider.h" #include "blackmisc/metadatautils.h" +#include "blackconfig/buildconfig.h" +using namespace BlackConfig; using namespace BlackMisc; using namespace BlackSound::SampleProvider; @@ -143,9 +145,15 @@ namespace BlackCore { receiverInput->addSilentSamples(audioDto, rxTransceiver.frequency, rxTransceiver.distanceRatio); } + + // debug ONLY + if (CBuildConfig::isLocalDeveloperDebugBuild()) + { + receiverInput->logVoiceInputs(QStringLiteral("Transceiver %1 ").arg(rxTransceiver.id), 1500); + } } - } - } + } // each transceiver + } // filtered rx transceivers } void CSoundcardSampleProvider::updateRadioTransceivers(const QVector &radioTransceivers) diff --git a/src/blackcore/afv/clients/afvclient.cpp b/src/blackcore/afv/clients/afvclient.cpp index 5be2fe5e7..0ee8048f1 100644 --- a/src/blackcore/afv/clients/afvclient.cpp +++ b/src/blackcore/afv/clients/afvclient.cpp @@ -62,7 +62,7 @@ namespace BlackCore m_output(new COutput(this)), m_voiceServerTimer(new QTimer(this)) { - this->setObjectName("AFV client"); + this->setObjectName("AFV client: " + apiServer ); m_connection->setReceiveAudio(false); connect(m_input, &CInput::opusDataAvailable, this, &CAfvClient::opusDataAvailable); @@ -123,7 +123,7 @@ namespace BlackCore void CAfvClient::connectWithContexts() { if (m_connectedWithContext) { return; } - if (!hasContexts()) { return; } + if (!hasContexts()) { return; } this->disconnect(sApp->getIContextOwnAircraft()); sApp->getIContextOwnAircraft()->disconnect(this); connect(sApp->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CAfvClient::onUpdateTransceiversFromContext, Qt::QueuedConnection); @@ -169,14 +169,16 @@ namespace BlackCore // thread safe connect { + QPointer myself(this); QMutexLocker lock(&m_mutexConnection); // async connection m_connection->connectTo(cid, password, callsign, client, { + // this is the callback when the connection has been established this, [ = ](bool authenticated) { - // this is the callback when the connection has been established + if (!myself) { return; } // HF stations aliased const QVector aliasedStations = m_connection->getAllAliasedStations(); @@ -388,7 +390,7 @@ namespace BlackCore }); } - /* + /* disabled because NOT used double CAfvClient::getDeviceInputVolume() const { if (m_input) { return m_input->getDeviceInputVolume(); } diff --git a/src/blackcore/afv/connection/apiserverconnection.cpp b/src/blackcore/afv/connection/apiserverconnection.cpp index c02a609a3..e876011ad 100644 --- a/src/blackcore/afv/connection/apiserverconnection.cpp +++ b/src/blackcore/afv/connection/apiserverconnection.cpp @@ -51,8 +51,8 @@ namespace BlackCore m_username = username; m_password = password; + m_client = client; m_networkVersion = networkVersion; - m_client = client; m_isAuthenticated = false; QUrl url(m_addressUrl); @@ -254,7 +254,7 @@ namespace BlackCore // posted in QAM thread, reply is nullptr if called from another thread sApp->postToNetwork(request, CApplication::NoLogRequestId, json.toJson(), { - this, [ = ](QNetworkReply * nwReply) + this, [ = ](QNetworkReply *nwReply) { // called in "this" thread const QScopedPointer reply(nwReply); diff --git a/src/blacksound/sampleprovider/bufferedwaveprovider.cpp b/src/blacksound/sampleprovider/bufferedwaveprovider.cpp index 7176e2c99..428e94720 100644 --- a/src/blacksound/sampleprovider/bufferedwaveprovider.cpp +++ b/src/blacksound/sampleprovider/bufferedwaveprovider.cpp @@ -10,7 +10,7 @@ namespace BlackSound CBufferedWaveProvider::CBufferedWaveProvider(const QAudioFormat &format, QObject *parent) : ISampleProvider(parent) { - const QString on = QStringLiteral("%1 format: ").arg(this->metaObject()->className(), BlackSound::toQString(format)); + const QString on = QStringLiteral("%1 format: '%2'").arg(this->metaObject()->className(), BlackSound::toQString(format)); this->setObjectName(on); // Set buffer size to 10 secs