refactor(afv): Fix some clang-tidy warnings

This commit is contained in:
Lars Toenning
2024-11-19 08:20:42 +01:00
parent d89af5316e
commit 9e615778ee
28 changed files with 61 additions and 98 deletions

View File

@@ -3,33 +3,35 @@
#include "core/afv/audio/callsigndelaycache.h"
#include <algorithm>
namespace swift::core::afv::audio
{
void CallsignDelayCache::initialise(const QString &callsign)
{
if (!m_delayCache.contains(callsign)) { m_delayCache[callsign] = delayDefault; }
if (!successfulTransmissionsCache.contains(callsign)) { successfulTransmissionsCache[callsign] = 0; }
if (!m_successfulTransmissionsCache.contains(callsign)) { m_successfulTransmissionsCache[callsign] = 0; }
}
int CallsignDelayCache::get(const QString &callsign) { return m_delayCache[callsign]; }
void CallsignDelayCache::underflow(const QString &callsign)
{
if (!successfulTransmissionsCache.contains(callsign)) return;
if (!m_successfulTransmissionsCache.contains(callsign)) return;
successfulTransmissionsCache[callsign] = 0;
m_successfulTransmissionsCache[callsign] = 0;
increaseDelayMs(callsign);
}
void CallsignDelayCache::success(const QString &callsign)
{
if (!successfulTransmissionsCache.contains(callsign)) return;
if (!m_successfulTransmissionsCache.contains(callsign)) return;
successfulTransmissionsCache[callsign]++;
if (successfulTransmissionsCache[callsign] > 5)
m_successfulTransmissionsCache[callsign]++;
if (m_successfulTransmissionsCache[callsign] > 5)
{
decreaseDelayMs(callsign);
successfulTransmissionsCache[callsign] = 0;
m_successfulTransmissionsCache[callsign] = 0;
}
}
@@ -38,7 +40,7 @@ namespace swift::core::afv::audio
if (!m_delayCache.contains(callsign)) return;
m_delayCache[callsign] += delayIncrement;
if (m_delayCache[callsign] > delayMax) { m_delayCache[callsign] = delayMax; }
m_delayCache[callsign] = std::min(m_delayCache[callsign], delayMax);
}
void CallsignDelayCache::decreaseDelayMs(const QString &callsign)
@@ -46,7 +48,7 @@ namespace swift::core::afv::audio
if (!m_delayCache.contains(callsign)) return;
m_delayCache[callsign] -= delayIncrement;
if (m_delayCache[callsign] < delayMin) { m_delayCache[callsign] = delayMin; }
m_delayCache[callsign] = std::max(m_delayCache[callsign], delayMin);
}
CallsignDelayCache &CallsignDelayCache::instance()

View File

@@ -3,8 +3,8 @@
//! \file
#ifndef SWIFT_ORE_AFV_AUDIO_CALLSIGNDELAYCACHE_H
#define SWIFT_ORE_AFV_AUDIO_CALLSIGNDELAYCACHE_H
#ifndef SWIFT_CORE_AFV_AUDIO_CALLSIGNDELAYCACHE_H
#define SWIFT_CORE_AFV_AUDIO_CALLSIGNDELAYCACHE_H
#include <QHash>
#include <QString>
@@ -46,9 +46,9 @@ namespace swift::core::afv::audio
static constexpr int delayMax = 300;
QHash<QString, int> m_delayCache;
QHash<QString, int> successfulTransmissionsCache;
QHash<QString, int> m_successfulTransmissionsCache;
};
} // namespace swift::core::afv::audio
#endif // guard
#endif // SWIFT_CORE_AFV_AUDIO_CALLSIGNDELAYCACHE_H

View File

@@ -3,7 +3,6 @@
#include "core/afv/audio/callsignsampleprovider.h"
#include <QDebug>
#include <QStringBuilder>
#include <QStringLiteral>
#include <QtMath>
@@ -205,8 +204,7 @@ namespace swift::core::afv::audio
{
double crackleFactor = (((qExp(m_distanceRatio) * qPow(m_distanceRatio, -4.0)) / 350.0) - 0.00776652);
if (crackleFactor < 0.0) { crackleFactor = 0.0; }
if (crackleFactor > 0.20) { crackleFactor = 0.20; }
crackleFactor = std::clamp(crackleFactor, 0.0, 0.2);
m_crackleSoundProvider->setGain(crackleFactor * 2);
m_whiteNoise->setGain(m_whiteNoiseGainMin);

View File

@@ -8,7 +8,6 @@
#include <QAudioFormat>
#include <QDateTime>
#include <QSharedPointer>
#include <QSoundEffect>
#include <QTimer>
@@ -17,7 +16,6 @@
#include "sound/sampleprovider/bufferedwaveprovider.h"
#include "sound/sampleprovider/equalizersampleprovider.h"
#include "sound/sampleprovider/mixingsampleprovider.h"
#include "sound/sampleprovider/pinknoisegenerator.h"
#include "sound/sampleprovider/resourcesoundsampleprovider.h"
#include "sound/sampleprovider/sawtoothgenerator.h"
#include "sound/sampleprovider/simplecompressoreffect.h"
@@ -108,4 +106,4 @@ namespace swift::core::afv::audio
};
} // namespace swift::core::afv::audio
#endif // guard
#endif // SWIFT_CORE_AFV_AUDIO_CALLSIGNSAMPLEPROVIDER_H

View File

@@ -8,8 +8,6 @@
#include <cmath>
#include <QAudioDevice>
#include <QDebug>
#include <QStringBuilder>
#include <QtGlobal>
#include "misc/logmessage.h"
@@ -49,7 +47,6 @@ namespace swift::core::afv::audio
const int byteCount = 1920 * m_format.channelCount();
while (m_buffer.size() > byteCount)
{
// qDebug() << QDateTime::currentMSecsSinceEpoch() << "CAudioInputBuffer::writeData " << m_buffer.size();
emit frameAvailable(m_buffer.left(byteCount));
m_buffer.remove(0, byteCount);
}

View File

@@ -15,8 +15,6 @@
#endif
#include <QAudioSource>
#include <QDateTime>
#include <QSharedPointer>
#include <QString>
namespace swift::core::afv::audio

View File

@@ -5,7 +5,6 @@
#include <cmath>
#include <QDebug>
#include <QStringBuilder>
#include "misc/logmessage.h"

View File

@@ -45,10 +45,10 @@ namespace swift::core::afv::audio
#endif
//! \copydoc QIODevice::readData
virtual qint64 readData(char *data, qint64 maxlen) override;
qint64 readData(char *data, qint64 maxlen) override;
//! \copydoc QIODevice::writeData
virtual qint64 writeData(const char *data, qint64 len) override;
qint64 writeData(const char *data, qint64 len) override;
private:
swift::sound::sample_provider::ISampleProvider *m_sampleProvider = nullptr; //!< related provider
@@ -71,7 +71,7 @@ namespace swift::core::afv::audio
COutput(QObject *parent = nullptr);
//! Dtor
virtual ~COutput() override { this->stop(); }
~COutput() override { this->stop(); }
//! Start output
void start(const swift::misc::audio::CAudioDeviceInfo &outputDevice,
@@ -103,4 +103,4 @@ namespace swift::core::afv::audio
};
} // namespace swift::core::afv::audio
#endif // guard
#endif // SWIFT_CORE_AFV_AUDIO_OUTPUT_H

View File

@@ -5,7 +5,6 @@
#include "core/afv/audio/receiversampleprovider.h"
#include <QDebug>
#include <QStringBuilder>
#include "misc/logmessage.h"
@@ -65,9 +64,8 @@ namespace swift::core::afv::audio
int CReceiverSampleProvider::activeCallsigns() const
{
const int numberOfCallsigns =
static_cast<int>(std::count_if(m_voiceInputs.begin(), m_voiceInputs.end(),
[](const CCallsignSampleProvider *p) { return p->inUse() == true; }));
const int numberOfCallsigns = static_cast<int>(std::count_if(
m_voiceInputs.begin(), m_voiceInputs.end(), [](const CCallsignSampleProvider *p) { return p->inUse(); }));
return numberOfCallsigns;
}
@@ -92,11 +90,9 @@ namespace swift::core::afv::audio
if (m_doClickWhenAppropriate && numberOfInUseInputs == 0)
{
CResourceSoundSampleProvider *resourceSound =
new CResourceSoundSampleProvider(Samples::instance().click(), m_mixer);
auto *resourceSound = new CResourceSoundSampleProvider(Samples::instance().click(), m_mixer);
m_mixer->addMixerInput(resourceSound);
m_doClickWhenAppropriate = false;
// 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
@@ -132,7 +128,7 @@ namespace swift::core::afv::audio
if (!voiceInput)
{
it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(),
[](const CCallsignSampleProvider *p) { return p->inUse() == false; });
[](const CCallsignSampleProvider *p) { return !p->inUse(); });
if (it != m_voiceInputs.end())
{
voiceInput = *it;
@@ -162,7 +158,7 @@ namespace swift::core::afv::audio
if (!voiceInput)
{
it = std::find_if(m_voiceInputs.begin(), m_voiceInputs.end(),
[](const CCallsignSampleProvider *p) { return p->inUse() == false; });
[](const CCallsignSampleProvider *p) { return !p->inUse(); });
if (it != m_voiceInputs.end())
{
voiceInput = *it;

View File

@@ -11,7 +11,6 @@
#include "core/afv/audio/callsignsampleprovider.h"
#include "misc/audio/audiosettings.h"
#include "misc/aviation/callsignset.h"
#include "misc/logcategories.h"
#include "sound/sampleprovider/mixingsampleprovider.h"
#include "sound/sampleprovider/sampleprovider.h"
#include "sound/sampleprovider/sinusgenerator.h"
@@ -22,7 +21,7 @@ namespace swift::core::afv::audio
//! Arguments
struct TransceiverReceivingCallsignsChangedArgs
{
quint16 transceiverID; //!< transceiver id
quint16 transceiverID {}; //!< transceiver id
QStringList receivingCallsigns; //!< callsigns
};
@@ -58,7 +57,7 @@ namespace swift::core::afv::audio
//! @}
//! \copydoc swift::sound::sample_provider::ISampleProvider::readSamples
virtual int readSamples(QVector<float> &samples, qint64 count) override;
int readSamples(QVector<float> &samples, qint64 count) override;
//! @{
//! Add samples
@@ -117,4 +116,4 @@ namespace swift::core::afv::audio
Q_DECLARE_METATYPE(swift::core::afv::audio::TransceiverReceivingCallsignsChangedArgs)
#endif // guard
#endif // SWIFT_CORE_AFV_AUDIO_RECEIVERSAMPLEPROVIDER_H

View File

@@ -35,7 +35,7 @@ namespace swift::core::afv::audio
void pttUpdate(bool active, const QVector<TxTransceiverDto> &txTransceivers);
//! \copydoc swift::sound::sample_provider::ISampleProvider::readSamples
virtual int readSamples(QVector<float> &samples, qint64 count) override;
int readSamples(QVector<float> &samples, qint64 count) override;
//! Add OPUS samples
void addOpusSamples(const IAudioDto &audioDto, const QVector<RxTransceiverDto> &rxTransceivers);
@@ -65,4 +65,4 @@ namespace swift::core::afv::audio
} // namespace swift::core::afv::audio
#endif // guard
#endif // SWIFT_CORE_AFV_AUDIO_SOUNDCARDSAMPLEPROVIDER_H

View File

@@ -3,8 +3,6 @@
#include "core/afv/clients/afvclient.h"
#include <QDebug>
#ifdef Q_OS_WIN
# include "comdef.h"
#endif
@@ -33,15 +31,6 @@ using namespace swift::sound::sample_provider;
namespace swift::core::afv::clients
{
constexpr int CAfvClient::PositionUpdatesMs;
constexpr int CAfvClient::SampleRate;
constexpr int CAfvClient::FrameSize;
constexpr double CAfvClient::MinDbIn;
constexpr double CAfvClient::MaxDbIn;
constexpr double CAfvClient::MinDbOut;
constexpr double CAfvClient::MaxDbOut;
constexpr quint32 CAfvClient::UniCom;
const QStringList &CAfvClient::getLogCategories()
{
static const QStringList cats { CLogCategories::audio(), CLogCategories::vatsimSpecific() };

View File

@@ -8,9 +8,6 @@
#include <atomic>
#include <QAudioInput>
#include <QAudioOutput>
#include <QDateTime>
#include <QObject>
#include <QString>
#include <QVector>

View File

@@ -5,7 +5,6 @@
#include <QJsonArray>
#include <QJsonObject>
#include <QMetaEnum>
#include <QPointer>
#include <QScopedPointer>
#include <QUrl>

View File

@@ -6,8 +6,6 @@
#ifndef SWIFT_CORE_AFV_CONNECTION_APISERVERCONNECTION_H
#define SWIFT_CORE_AFV_CONNECTION_APISERVERCONNECTION_H
#include <QDebug>
#include <QElapsedTimer>
#include <QEventLoop>
#include <QJsonDocument>
#include <QNetworkAccessManager>

View File

@@ -10,6 +10,7 @@
#include <QString>
#include <QTimer>
#include <QUdpSocket>
#include <QUuid>
#include "core/afv/connection/apiserverconnection.h"
#include "core/afv/connection/clientconnectiondata.h"
@@ -137,4 +138,4 @@ namespace swift::core::afv::connection
};
} // namespace swift::core::afv::connection
#endif // guard
#endif // SWIFT_CORE_AFV_CONNECTION_CLIENTCONNECTION_H

View File

@@ -3,8 +3,6 @@
#include "core/afv/connection/clientconnectiondata.h"
#include <QDebug>
#include "misc/logmessage.h"
using namespace swift::misc;

View File

@@ -14,7 +14,6 @@
#include "core/afv/connection/apiserverconnection.h"
#include "core/afv/crypto/cryptodtochannel.h"
#include "core/afv/dto.h"
#include "misc/logcategories.h"
namespace swift::core::afv::connection
{
@@ -114,4 +113,4 @@ namespace swift::core::afv::connection
};
} // namespace swift::core::afv::connection
#endif // guard
#endif // SWIFT_CORE_AFV_CONNECTION_CLIENTCONNECTIONDATA_H

View File

@@ -15,4 +15,4 @@ namespace swift::core::afv
constexpr int c_sampleRate = 48000;
} // namespace swift::core::afv
#endif // guard
#endif // SWIFT_CORE_AFV_CONSTANTS_H

View File

@@ -3,6 +3,8 @@
#include "core/afv/crypto/cryptodtochannel.h"
#include <algorithm>
#include "sodium/crypto_aead_chacha20poly1305.h"
#include "misc/verify.h"
@@ -28,7 +30,7 @@ namespace swift::core::afv::crypto
throw std::invalid_argument("wrong receive key size");
}
if (m_receiveSequenceSizeMaxSize < 1) { m_receiveSequenceSizeMaxSize = 1; }
m_receiveSequenceSizeMaxSize = std::max(m_receiveSequenceSizeMaxSize, 1);
m_receiveSequenceHistory.fill(0, m_receiveSequenceSizeMaxSize);
m_receiveSequenceHistoryDepth = 0;
}
@@ -95,7 +97,7 @@ namespace swift::core::afv::crypto
}
else
{
int minIndex;
int minIndex {};
uint minValue = getMin(minIndex);
if (sequenceReceived < minValue) { return false; } // Possible replay attack
m_receiveSequenceHistory[minIndex] = sequenceReceived;

View File

@@ -6,8 +6,6 @@
#ifndef SWIFT_CORE_AFV_CRYPTO_CRYPTODTOCHANNEL_H
#define SWIFT_CORE_AFV_CRYPTO_CRYPTODTOCHANNEL_H
#include <limits>
#include <QByteArray>
#include <QDateTime>
#include <QVector>
@@ -58,4 +56,4 @@ namespace swift::core::afv::crypto
};
} // namespace swift::core::afv::crypto
#endif // guard
#endif // SWIFT_CORE_AFV_CRYPTO_CRYPTODTOCHANNEL_H

View File

@@ -26,4 +26,4 @@ namespace swift::core::afv::crypto
};
} // namespace swift::core::afv::crypto
#endif // gaurd
#endif // SWIFT_CORE_AFV_CRYPTO_CRYPTODTOHEADERDTO_H

View File

@@ -23,4 +23,4 @@ namespace swift::core::afv::crypto
//! \private
MSGPACK_ADD_ENUM(swift::core::afv::crypto::CryptoDtoMode);
#endif // guard
#endif // SWIFT_CORE_AFV_CRYPTO_CRYPTODTOMODE_H

View File

@@ -5,8 +5,6 @@
namespace swift::core::afv::crypto
{
CryptoDtoSerializer::CryptoDtoSerializer() {}
CryptoDtoSerializer::Deserializer CryptoDtoSerializer::deserialize(CCryptoDtoChannel &channel,
const QByteArray &bytes, bool loopback)
{

View File

@@ -30,7 +30,7 @@ namespace swift::core::afv::crypto
class CryptoDtoSerializer
{
public:
CryptoDtoSerializer();
CryptoDtoSerializer() = default;
//! Serialize a DTO
template <typename T>
@@ -44,16 +44,16 @@ namespace swift::core::afv::crypto
headerBuffer.open(QIODevice::WriteOnly);
msgpack::pack(headerBuffer, header);
headerBuffer.close();
const quint16 headerLength = static_cast<quint16>(headerBuffer.buffer().size());
const auto headerLength = static_cast<quint16>(headerBuffer.buffer().size());
const QByteArray dtoShortName = T::getShortDtoName();
const quint16 dtoNameLength = static_cast<quint16>(dtoShortName.size());
const auto dtoNameLength = static_cast<quint16>(dtoShortName.size());
QBuffer dtoBuffer;
dtoBuffer.open(QIODevice::WriteOnly);
msgpack::pack(dtoBuffer, dto);
dtoBuffer.close();
const quint16 dtoLength = static_cast<quint16>(dtoBuffer.buffer().size());
const auto dtoLength = static_cast<quint16>(dtoBuffer.buffer().size());
if (header.Mode == CryptoDtoMode::AEAD_ChaCha20Poly1305)
{
@@ -80,7 +80,7 @@ namespace swift::core::afv::crypto
nonceBuffer.write(reinterpret_cast<const char *>(&header.Sequence), sizeof(header.Sequence));
nonceBuffer.close();
unsigned long long clen;
unsigned long long clen {};
QByteArray aeadPayload;
aeadPayload.fill(0,
static_cast<int>(aePayloadBuffer.size() + crypto_aead_chacha20poly1305_IETF_ABYTES));
@@ -163,4 +163,4 @@ namespace swift::core::afv::crypto
};
} // namespace swift::core::afv::crypto
#endif // guard
#endif // SWIFT_CORE_AFV_CRYPTO_CRYPTODTO_SERIALIZER_H

View File

@@ -117,8 +117,8 @@ namespace swift::core::afv
{
//! @{
//! Properties
quint16 id;
quint32 frequencyHz;
quint16 id {};
quint32 frequencyHz {};
double LatDeg = 0.0;
double LonDeg = 0.0;
double HeightMslM = 0.0;
@@ -160,8 +160,8 @@ namespace swift::core::afv
//! Properties
QUuid id;
QString name;
quint32 frequencyHz;
quint32 frequencyAliasHz;
quint32 frequencyHz {};
quint32 frequencyAliasHz {};
//! @}
//! From JSON
@@ -219,15 +219,15 @@ namespace swift::core::afv
struct TxTransceiverDto
{
//! Ctor
TxTransceiverDto() {}
TxTransceiverDto() = default;
//! Ctor
TxTransceiverDto(const TransceiverDto &dto) { id = dto.id; }
TxTransceiverDto(const TransceiverDto &dto) : id(dto.id) {}
//! Ctor
TxTransceiverDto(uint16_t value) { id = value; }
TxTransceiverDto(uint16_t value) : id(value) {}
uint16_t id; //!< id
uint16_t id {}; //!< id
MSGPACK_DEFINE(id)
};
@@ -281,4 +281,4 @@ namespace swift::core::afv
};
} // namespace swift::core::afv
#endif // guard
#endif // SWIFT_CORE_AFV_DTO_H

View File

@@ -42,4 +42,4 @@ namespace swift::core::afv::model
};
} // namespace swift::core::afv::model
#endif // guard
#endif // SWIFT_CORE_AFV_AFVMAPREADER_H

View File

@@ -5,9 +5,6 @@
#define SWIFT_CORE_AFV_MODEL_ATCSTATIONMODEL_H
#include <QAbstractListModel>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QObject>
#include <QtGlobal>
@@ -21,7 +18,7 @@ namespace swift::core::afv::model
{
public:
//! Ctor
CSampleAtcStation() {}
CSampleAtcStation() = default;
//! Ctor
CSampleAtcStation(const QString &callsign, const swift::core::afv::TransceiverDto &transceiver);
@@ -68,7 +65,7 @@ namespace swift::core::afv::model
CSampleAtcStationModel(QObject *parent = nullptr);
//! Dtor
virtual ~CSampleAtcStationModel() override;
~CSampleAtcStationModel() override;
//! Update the stations
void updateAtcStations(const QVector<CSampleAtcStation> &atcStations);
@@ -91,4 +88,4 @@ namespace swift::core::afv::model
};
} // namespace swift::core::afv::model
#endif // guard
#endif // SWIFT_CORE_AFV_MODEL_ATCSTATIONMODEL_H