From 774332fcdc7bb466145faf474dad8c0969965e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Mon, 8 Jan 2024 12:00:28 +0100 Subject: [PATCH 1/5] C++: tidy up --- worker/.clang-tidy | 24 +++--- worker/include/Channel/ChannelSocket.hpp | 10 +-- worker/include/Logger.hpp | 36 +++++---- worker/include/MediaSoupErrors.hpp | 10 +-- worker/include/RTC/ActiveSpeakerObserver.hpp | 4 +- worker/include/RTC/Consumer.hpp | 4 +- worker/include/RTC/DataConsumer.hpp | 4 +- worker/include/RTC/DataProducer.hpp | 2 +- worker/include/RTC/DtlsTransport.hpp | 8 +- worker/include/RTC/IceCandidate.hpp | 12 +-- worker/include/RTC/KeyFrameRequestManager.hpp | 6 +- worker/include/RTC/PipeTransport.hpp | 4 +- worker/include/RTC/PlainTransport.hpp | 8 +- worker/include/RTC/Producer.hpp | 2 +- .../include/RTC/RTCP/FeedbackRtpTransport.hpp | 6 +- worker/include/RTC/RateCalculator.hpp | 2 +- worker/include/RTC/Router.hpp | 4 +- worker/include/RTC/RtcLogger.hpp | 12 +-- worker/include/RTC/RtpObserver.hpp | 2 +- worker/include/RTC/RtpPacket.hpp | 29 +++----- .../include/RTC/RtpRetransmissionBuffer.hpp | 6 +- worker/include/RTC/RtpStreamRecv.hpp | 2 +- worker/include/RTC/SctpAssociation.hpp | 4 +- worker/include/RTC/StunPacket.hpp | 8 +- worker/include/RTC/Transport.hpp | 4 +- .../RTC/TransportCongestionControlClient.hpp | 2 +- .../RTC/TransportCongestionControlServer.hpp | 2 +- worker/include/RTC/TransportTuple.hpp | 4 +- worker/include/RTC/TrendCalculator.hpp | 2 +- worker/include/RTC/WebRtcServer.hpp | 8 +- .../include/handles/TcpConnectionHandle.hpp | 9 ++- worker/include/handles/TcpServerHandle.hpp | 8 +- worker/include/handles/UdpSocketHandle.hpp | 9 ++- .../handles/UnixStreamSocketHandle.hpp | 5 +- worker/src/Channel/ChannelSocket.cpp | 20 ++--- worker/src/DepLibSRTP.cpp | 16 ++-- worker/src/DepLibWebRTC.cpp | 4 +- worker/src/DepOpenSSL.cpp | 4 +- worker/src/DepUsrSCTP.cpp | 16 ++-- worker/src/Logger.cpp | 4 +- worker/src/MediaSoupErrors.cpp | 2 +- worker/src/RTC/ActiveSpeakerObserver.cpp | 33 ++++----- worker/src/RTC/Consumer.cpp | 5 +- worker/src/RTC/DataConsumer.cpp | 8 +- worker/src/RTC/DataProducer.cpp | 2 +- worker/src/RTC/DirectTransport.cpp | 6 +- worker/src/RTC/DtlsTransport.cpp | 18 ++--- worker/src/RTC/KeyFrameRequestManager.cpp | 6 +- worker/src/RTC/NackGenerator.cpp | 23 ++---- worker/src/RTC/PortManager.cpp | 12 ++- worker/src/RTC/Producer.cpp | 5 +- worker/src/RTC/RtpPacket.cpp | 14 +--- worker/src/RTC/RtpRetransmissionBuffer.cpp | 74 ++++++++++--------- worker/src/RTC/RtpStreamRecv.cpp | 6 +- worker/src/RTC/SctpAssociation.cpp | 70 +++++++++++------- worker/src/RTC/SimulcastConsumer.cpp | 2 +- worker/src/RTC/StunPacket.cpp | 29 ++++---- worker/src/RTC/Transport.cpp | 8 +- worker/src/RTC/WebRtcServer.cpp | 58 ++++++++------- worker/src/RTC/WebRtcTransport.cpp | 6 +- worker/src/Settings.cpp | 4 +- worker/src/Utils/File.cpp | 4 +- worker/src/Utils/IP.cpp | 2 +- worker/src/Worker.cpp | 4 +- worker/src/handles/TcpConnectionHandle.cpp | 6 +- worker/src/handles/TcpServerHandle.cpp | 26 ++++--- worker/src/handles/TimerHandle.cpp | 3 +- worker/src/handles/UdpSocketHandle.cpp | 28 +++---- worker/src/handles/UnixStreamSocketHandle.cpp | 29 ++++---- worker/src/lib.cpp | 17 +++-- 70 files changed, 429 insertions(+), 407 deletions(-) diff --git a/worker/.clang-tidy b/worker/.clang-tidy index 2394ea1409..14d3b910c0 100644 --- a/worker/.clang-tidy +++ b/worker/.clang-tidy @@ -3,6 +3,8 @@ Checks: "*,\ -altera*,\ -boost-use-to-string,\ -bugprone-easily-swappable-parameters,\ + -bugprone-lambda-function-name,\ + -bugprone-macro-parentheses,\ -cert-*,\ -clang-analyzer-optin.osx.*,\ -clang-analyzer-osx.*,\ @@ -37,11 +39,15 @@ Checks: "*,\ -hicpp-uppercase-literal-suffix,\ -hicpp-vararg,\ -llvm-include-order,\ + -llvm-header-guard,\ + -llvm-else-after-return,\ -llvmlibc-*,\ -misc-non-private-member-variables-in-classes,\ -modernize-avoid-c-arrays,\ + -modernize-concat-nested-namespaces,\ -modernize-make-unique,\ -modernize-pass-by-value,\ + -modernize-use-nodiscard, \ -modernize-use-trailing-return-type,\ -readability-else-after-return,\ -readability-function-cognitive-complexity,\ @@ -49,22 +55,22 @@ Checks: "*,\ -readability-implicit-bool-cast,\ -readability-implicit-bool-conversion,\ -readability-magic-numbers,\ + -readability-redundant-access-specifiers, \ -readability-uppercase-literal-suffix,\ " HeaderFilterRegex: '' AnalyzeTemporaryDtors: false User: mediasoup - -# Old clang-tidy does not support this option which indicates to take the -# format options from .clang-format when applying fixes. -#FormatStyle: file +FormatStyle: file CheckOptions: - key: cppcoreguidelines-pro-bounds-constant-array-index.GslHeader value: '' - key: cppcoreguidelines-pro-bounds-constant-array-index.IncludeStyle value: '0' + - key: cppcoreguidelines-macro-usage.AllowedRegexp + value: ^MS_* - key: misc-assert-side-effect.AssertMacros value: assert - key: misc-assert-side-effect.CheckFunctionCalls @@ -98,7 +104,7 @@ CheckOptions: - key: readability-identifier-naming.ClassCase value: CamelCase - key: readability-identifier-naming.ClassConstantCase - value: camelBack + value: CamelCase - key: readability-identifier-naming.ClassConstantPrefix value: '' - key: readability-identifier-naming.ClassConstantSuffix @@ -156,9 +162,9 @@ CheckOptions: - key: readability-identifier-naming.ConstexprVariableSuffix value: '' - key: readability-identifier-naming.EnumCase - value: aNy_Case + value: aNy_CasE - key: readability-identifier-naming.EnumConstantCase - value: aNy_Case + value: aNy_CasE - key: readability-identifier-naming.EnumConstantPrefix value: '' - key: readability-identifier-naming.EnumConstantSuffix @@ -194,7 +200,7 @@ CheckOptions: - key: readability-identifier-naming.IgnoreFailedSplit value: '0' - key: readability-identifier-naming.InlineNamespaceCase - value: aNy_Case + value: aNy_CasE - key: readability-identifier-naming.InlineNamespacePrefix value: '' - key: readability-identifier-naming.InlineNamespaceSuffix @@ -224,7 +230,7 @@ CheckOptions: - key: readability-identifier-naming.MethodSuffix value: '' - key: readability-identifier-naming.NamespaceCase - value: aNy_Case + value: aNy_CasE - key: readability-identifier-naming.NamespacePrefix value: '' - key: readability-identifier-naming.NamespaceSuffix diff --git a/worker/include/Channel/ChannelSocket.hpp b/worker/include/Channel/ChannelSocket.hpp index 188ec03abb..83935b8b81 100644 --- a/worker/include/Channel/ChannelSocket.hpp +++ b/worker/include/Channel/ChannelSocket.hpp @@ -24,7 +24,7 @@ namespace Channel public: ConsumerSocket(int fd, size_t bufferSize, Listener* listener); - ~ConsumerSocket(); + ~ConsumerSocket() override; /* Pure virtual methods inherited from ::UnixStreamSocketHandle. */ public: @@ -75,7 +75,7 @@ namespace Channel class Listener : public RequestHandler, public NotificationHandler { public: - virtual ~Listener() = default; + ~Listener() override = default; public: virtual void OnChannelClosed(Channel::ChannelSocket* channel) = 0; @@ -88,13 +88,13 @@ namespace Channel ChannelReadCtx channelReadCtx, ChannelWriteFn channelWriteFn, ChannelWriteCtx channelWriteCtx); - virtual ~ChannelSocket(); + ~ChannelSocket() override; public: void Close(); void SetListener(Listener* listener); - void Send(const uint8_t* message, uint32_t messageLen); - void SendLog(const char* message, uint32_t messageLen); + void Send(const uint8_t* data, uint32_t dataLen); + void SendLog(const char* data, uint32_t dataLen); bool CallbackRead(); private: diff --git a/worker/include/Logger.hpp b/worker/include/Logger.hpp index e3c22bb71f..b10f600a20 100644 --- a/worker/include/Logger.hpp +++ b/worker/include/Logger.hpp @@ -96,8 +96,10 @@ // clang-format off +// NOLINTBEGIN #define _MS_TAG_ENABLED(tag) Settings::configuration.logTags.tag #define _MS_TAG_ENABLED_2(tag1, tag2) (Settings::configuration.logTags.tag1 || Settings::configuration.logTags.tag2) +// NOLINTEND #if !defined(MS_LOG_DEV_LEVEL) #define MS_LOG_DEV_LEVEL 0 @@ -145,14 +147,15 @@ class Logger static void ClassInit(Channel::ChannelSocket* channel); public: - static const uint64_t pid; + static const uint64_t Pid; thread_local static Channel::ChannelSocket* channel; - static const size_t bufferSize {50000}; + static const size_t BufferSize {50000}; thread_local static char buffer[]; }; /* Logging macros. */ +// NOLINTBEGIN #define _MS_LOG_SEPARATOR_CHAR_STD "\n" #ifdef MS_LOG_FILE_LINE @@ -165,6 +168,7 @@ class Logger #define _MS_LOG_STR_DESC _MS_LOG_STR " | " #define _MS_LOG_ARG MS_CLASS, __FUNCTION__ #endif +// NOLINTEND #ifdef MS_LOG_TRACE #define MS_TRACE() \ @@ -172,7 +176,7 @@ class Logger { \ if (Settings::configuration.logLevel == LogLevel::LOG_DEBUG) \ { \ - const int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "D(trace) " _MS_LOG_STR, _MS_LOG_ARG); \ + const int loggerWritten = std::snprintf(Logger::buffer, Logger::BufferSize, "D(trace) " _MS_LOG_STR, _MS_LOG_ARG); \ Logger::channel->SendLog(Logger::buffer, static_cast(loggerWritten)); \ } \ } \ @@ -204,7 +208,7 @@ class Logger { \ if (Settings::configuration.logLevel == LogLevel::LOG_DEBUG && _MS_TAG_ENABLED(tag)) \ { \ - const int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ + const int loggerWritten = std::snprintf(Logger::buffer, Logger::BufferSize, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ Logger::channel->SendLog(Logger::buffer, static_cast(loggerWritten)); \ } \ } \ @@ -226,7 +230,7 @@ class Logger { \ if (Settings::configuration.logLevel >= LogLevel::LOG_WARN && _MS_TAG_ENABLED(tag)) \ { \ - const int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ + const int loggerWritten = std::snprintf(Logger::buffer, Logger::BufferSize, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ Logger::channel->SendLog(Logger::buffer, static_cast(loggerWritten)); \ } \ } \ @@ -248,7 +252,7 @@ class Logger { \ if (Settings::configuration.logLevel == LogLevel::LOG_DEBUG && _MS_TAG_ENABLED_2(tag1, tag2)) \ { \ - const int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ + const int loggerWritten = std::snprintf(Logger::buffer, Logger::BufferSize, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ Logger::channel->SendLog(Logger::buffer, static_cast(loggerWritten)); \ } \ } \ @@ -270,7 +274,7 @@ class Logger { \ if (Settings::configuration.logLevel >= LogLevel::LOG_WARN && _MS_TAG_ENABLED_2(tag1, tag2)) \ { \ - const int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ + const int loggerWritten = std::snprintf(Logger::buffer, Logger::BufferSize, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ Logger::channel->SendLog(Logger::buffer, static_cast(loggerWritten)); \ } \ } \ @@ -291,7 +295,7 @@ class Logger #define MS_DEBUG_DEV(desc, ...) \ do \ { \ - const int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ + const int loggerWritten = std::snprintf(Logger::buffer, Logger::BufferSize, "D" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ Logger::channel->SendLog(Logger::buffer, static_cast(loggerWritten)); \ } \ while (false) @@ -313,7 +317,7 @@ class Logger #define MS_WARN_DEV(desc, ...) \ do \ { \ - const int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ + const int loggerWritten = std::snprintf(Logger::buffer, Logger::BufferSize, "W" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ Logger::channel->SendLog(Logger::buffer, static_cast(loggerWritten)); \ } \ while (false) @@ -333,7 +337,7 @@ class Logger #define MS_DUMP(desc, ...) \ do \ { \ - const int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "X" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ + const int loggerWritten = std::snprintf(Logger::buffer, Logger::BufferSize, "X" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ Logger::channel->SendLog(Logger::buffer, static_cast(loggerWritten)); \ } \ while (false) @@ -349,7 +353,7 @@ class Logger #define MS_DUMP_DATA(data, len) \ do \ { \ - const int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "X(data) " _MS_LOG_STR, _MS_LOG_ARG); \ + const int loggerWritten = std::snprintf(Logger::buffer, Logger::BufferSize, "X(data) " _MS_LOG_STR, _MS_LOG_ARG); \ Logger::channel->SendLog(Logger::buffer, static_cast(loggerWritten)); \ size_t bufferDataLen{ 0 }; \ for (size_t i{0}; i < len; ++i) \ @@ -361,10 +365,10 @@ class Logger Logger::channel->SendLog(Logger::buffer, static_cast(bufferDataLen)); \ bufferDataLen = 0; \ } \ - const int loggerWritten = std::snprintf(Logger::buffer + bufferDataLen, Logger::bufferSize, "X%06X ", static_cast(i)); \ + const int loggerWritten = std::snprintf(Logger::buffer + bufferDataLen, Logger::BufferSize, "X%06X ", static_cast(i)); \ bufferDataLen += loggerWritten; \ } \ - const int loggerWritten = std::snprintf(Logger::buffer + bufferDataLen, Logger::bufferSize, "%02X ", static_cast(data[i])); \ + const int loggerWritten = std::snprintf(Logger::buffer + bufferDataLen, Logger::BufferSize, "%02X ", static_cast(data[i])); \ bufferDataLen += loggerWritten; \ } \ if (bufferDataLen != 0) \ @@ -389,10 +393,10 @@ class Logger std::fprintf(stdout, "%s", Logger::buffer); \ bufferDataLen = 0; \ } \ - const int loggerWritten = std::snprintf(Logger::buffer + bufferDataLen, Logger::bufferSize, "\n%06X ", static_cast(i)); \ + const int loggerWritten = std::snprintf(Logger::buffer + bufferDataLen, Logger::BufferSize, "\n%06X ", static_cast(i)); \ bufferDataLen += loggerWritten; \ } \ - const int loggerWritten = std::snprintf(Logger::buffer + bufferDataLen, Logger::bufferSize, "%02X ", static_cast(data[i])); \ + const int loggerWritten = std::snprintf(Logger::buffer + bufferDataLen, Logger::BufferSize, "%02X ", static_cast(data[i])); \ bufferDataLen += loggerWritten; \ } \ if (bufferDataLen != 0) \ @@ -409,7 +413,7 @@ class Logger { \ if (Settings::configuration.logLevel >= LogLevel::LOG_ERROR || MS_LOG_DEV_LEVEL >= 1) \ { \ - const int loggerWritten = std::snprintf(Logger::buffer, Logger::bufferSize, "E" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ + const int loggerWritten = std::snprintf(Logger::buffer, Logger::BufferSize, "E" _MS_LOG_STR_DESC desc, _MS_LOG_ARG, ##__VA_ARGS__); \ Logger::channel->SendLog(Logger::buffer, static_cast(loggerWritten)); \ } \ } \ diff --git a/worker/include/MediaSoupErrors.hpp b/worker/include/MediaSoupErrors.hpp index 22697992cf..90d3b07ec8 100644 --- a/worker/include/MediaSoupErrors.hpp +++ b/worker/include/MediaSoupErrors.hpp @@ -13,7 +13,7 @@ class MediaSoupError : public std::runtime_error } public: - static const size_t bufferSize{ 2000 }; + static const size_t BufferSize{ 2000 }; thread_local static char buffer[]; }; @@ -30,7 +30,7 @@ class MediaSoupTypeError : public MediaSoupError do \ { \ MS_ERROR("throwing MediaSoupError: " desc, ##__VA_ARGS__); \ - std::snprintf(MediaSoupError::buffer, MediaSoupError::bufferSize, desc, ##__VA_ARGS__); \ + std::snprintf(MediaSoupError::buffer, MediaSoupError::BufferSize, desc, ##__VA_ARGS__); \ throw MediaSoupError(MediaSoupError::buffer); \ } while (false) @@ -38,7 +38,7 @@ class MediaSoupTypeError : public MediaSoupError do \ { \ MS_ERROR_STD("throwing MediaSoupError: " desc, ##__VA_ARGS__); \ - std::snprintf(MediaSoupError::buffer, MediaSoupError::bufferSize, desc, ##__VA_ARGS__); \ + std::snprintf(MediaSoupError::buffer, MediaSoupError::BufferSize, desc, ##__VA_ARGS__); \ throw MediaSoupError(MediaSoupError::buffer); \ } while (false) @@ -46,7 +46,7 @@ class MediaSoupTypeError : public MediaSoupError do \ { \ MS_ERROR("throwing MediaSoupTypeError: " desc, ##__VA_ARGS__); \ - std::snprintf(MediaSoupError::buffer, MediaSoupError::bufferSize, desc, ##__VA_ARGS__); \ + std::snprintf(MediaSoupError::buffer, MediaSoupError::BufferSize, desc, ##__VA_ARGS__); \ throw MediaSoupTypeError(MediaSoupError::buffer); \ } while (false) @@ -54,7 +54,7 @@ class MediaSoupTypeError : public MediaSoupError do \ { \ MS_ERROR_STD("throwing MediaSoupTypeError: " desc, ##__VA_ARGS__); \ - std::snprintf(MediaSoupError::buffer, MediaSoupError::bufferSize, desc, ##__VA_ARGS__); \ + std::snprintf(MediaSoupError::buffer, MediaSoupError::BufferSize, desc, ##__VA_ARGS__); \ throw MediaSoupTypeError(MediaSoupError::buffer); \ } while (false) // clang-format on diff --git a/worker/include/RTC/ActiveSpeakerObserver.hpp b/worker/include/RTC/ActiveSpeakerObserver.hpp index 556e6c0e02..293aa3d8d8 100644 --- a/worker/include/RTC/ActiveSpeakerObserver.hpp +++ b/worker/include/RTC/ActiveSpeakerObserver.hpp @@ -23,7 +23,7 @@ namespace RTC public: Speaker(); void EvalActivityScores(); - double GetActivityScore(uint8_t interval); + double GetActivityScore(uint8_t interval) const; void LevelChanged(uint32_t level, uint64_t now); void LevelTimedOut(uint64_t now); @@ -95,7 +95,7 @@ namespace RTC void OnTimer(TimerHandle* timer) override; private: - double relativeSpeachActivities[RelativeSpeachActivitiesLen]; + double relativeSpeachActivities[RelativeSpeachActivitiesLen]{}; std::string dominantId; TimerHandle* periodicTimer{ nullptr }; uint16_t interval{ 300u }; diff --git a/worker/include/RTC/Consumer.hpp b/worker/include/RTC/Consumer.hpp index 8d3a25c95e..28b4239b62 100644 --- a/worker/include/RTC/Consumer.hpp +++ b/worker/include/RTC/Consumer.hpp @@ -66,7 +66,7 @@ namespace RTC RTC::Consumer::Listener* listener, const FBS::Transport::ConsumeRequest* data, RTC::RtpParameters::Type type); - virtual ~Consumer(); + ~Consumer() override; public: flatbuffers::Offset FillBuffer( @@ -74,7 +74,7 @@ namespace RTC virtual flatbuffers::Offset FillBufferStats( flatbuffers::FlatBufferBuilder& builder) = 0; virtual flatbuffers::Offset FillBufferScore( - flatbuffers::FlatBufferBuilder& builder) const + flatbuffers::FlatBufferBuilder& /*builder*/) const { return 0; }; diff --git a/worker/include/RTC/DataConsumer.hpp b/worker/include/RTC/DataConsumer.hpp index f732726c83..994b616ed7 100644 --- a/worker/include/RTC/DataConsumer.hpp +++ b/worker/include/RTC/DataConsumer.hpp @@ -52,7 +52,7 @@ namespace RTC RTC::DataConsumer::Listener* listener, const FBS::Transport::ConsumeDataRequest* data, size_t maxMessageSize); - virtual ~DataConsumer(); + ~DataConsumer() override; public: flatbuffers::Offset FillBuffer( @@ -104,7 +104,7 @@ namespace RTC uint32_t ppid, std::vector& subchannels, std::optional requiredSubchannel, - onQueuedCallback* = nullptr); + onQueuedCallback* cb = nullptr); /* Methods inherited from Channel::ChannelSocket::RequestHandler. */ public: diff --git a/worker/include/RTC/DataProducer.hpp b/worker/include/RTC/DataProducer.hpp index 474ebb8214..6c0a8d3988 100644 --- a/worker/include/RTC/DataProducer.hpp +++ b/worker/include/RTC/DataProducer.hpp @@ -48,7 +48,7 @@ namespace RTC size_t maxMessageSize, RTC::DataProducer::Listener* listener, const FBS::Transport::ProduceDataRequest* data); - virtual ~DataProducer(); + ~DataProducer() override; public: flatbuffers::Offset FillBuffer( diff --git a/worker/include/RTC/DtlsTransport.hpp b/worker/include/RTC/DtlsTransport.hpp index bb635ea42f..27f4bd847f 100644 --- a/worker/include/RTC/DtlsTransport.hpp +++ b/worker/include/RTC/DtlsTransport.hpp @@ -112,6 +112,10 @@ namespace RTC ); // clang-format on } + static std::vector& GetLocalFingerprints() + { + return DtlsTransport::localFingerprints; + } private: static void GenerateCertificateAndPrivateKey(); @@ -137,10 +141,6 @@ namespace RTC public: void Dump() const; void Run(Role localRole); - std::vector& GetLocalFingerprints() const - { - return DtlsTransport::localFingerprints; - } bool SetRemoteFingerprint(const Fingerprint& fingerprint); void ProcessDtlsData(const uint8_t* data, size_t len); DtlsState GetState() const diff --git a/worker/include/RTC/IceCandidate.hpp b/worker/include/RTC/IceCandidate.hpp index 3993b9bef1..d2349706e0 100644 --- a/worker/include/RTC/IceCandidate.hpp +++ b/worker/include/RTC/IceCandidate.hpp @@ -36,27 +36,27 @@ namespace RTC public: IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority) : foundation("udpcandidate"), priority(priority), ip(udpSocket->GetLocalIp()), - protocol(Protocol::UDP), port(udpSocket->GetLocalPort()), type(CandidateType::HOST) + protocol(Protocol::UDP), port(udpSocket->GetLocalPort()) { } IceCandidate(RTC::UdpSocket* udpSocket, uint32_t priority, std::string& announcedIp) : foundation("udpcandidate"), priority(priority), ip(announcedIp), protocol(Protocol::UDP), - port(udpSocket->GetLocalPort()), type(CandidateType::HOST) + port(udpSocket->GetLocalPort()) { } IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority) : foundation("tcpcandidate"), priority(priority), ip(tcpServer->GetLocalIp()), - protocol(Protocol::TCP), port(tcpServer->GetLocalPort()), type(CandidateType::HOST), - tcpType(TcpCandidateType::PASSIVE) + protocol(Protocol::TCP), port(tcpServer->GetLocalPort()) + { } IceCandidate(RTC::TcpServer* tcpServer, uint32_t priority, std::string& announcedIp) : foundation("tcpcandidate"), priority(priority), ip(announcedIp), protocol(Protocol::TCP), - port(tcpServer->GetLocalPort()), type(CandidateType::HOST), - tcpType(TcpCandidateType::PASSIVE) + port(tcpServer->GetLocalPort()) + { } diff --git a/worker/include/RTC/KeyFrameRequestManager.hpp b/worker/include/RTC/KeyFrameRequestManager.hpp index e56482c2a6..76aaa6716c 100644 --- a/worker/include/RTC/KeyFrameRequestManager.hpp +++ b/worker/include/RTC/KeyFrameRequestManager.hpp @@ -20,7 +20,7 @@ namespace RTC public: PendingKeyFrameInfo(Listener* listener, uint32_t ssrc); - ~PendingKeyFrameInfo(); + ~PendingKeyFrameInfo() override; uint32_t GetSsrc() const { @@ -64,7 +64,7 @@ namespace RTC public: KeyFrameRequestDelayer(Listener* listener, uint32_t ssrc, uint32_t delay); - ~KeyFrameRequestDelayer(); + ~KeyFrameRequestDelayer() override; uint32_t GetSsrc() const { @@ -105,7 +105,7 @@ namespace RTC public: explicit KeyFrameRequestManager(Listener* listener, uint32_t keyFrameRequestDelay); - virtual ~KeyFrameRequestManager(); + ~KeyFrameRequestManager() override; void KeyFrameNeeded(uint32_t ssrc); void ForceKeyFrameNeeded(uint32_t ssrc); diff --git a/worker/include/RTC/PipeTransport.hpp b/worker/include/RTC/PipeTransport.hpp index 1c08492a42..21b3722c9a 100644 --- a/worker/include/RTC/PipeTransport.hpp +++ b/worker/include/RTC/PipeTransport.hpp @@ -75,7 +75,9 @@ namespace RTC RTC::SrtpSession* srtpSendSession{ nullptr }; // Others. ListenInfo listenInfo; - struct sockaddr_storage remoteAddrStorage; + struct sockaddr_storage remoteAddrStorage + { + }; // NOLINT bool rtx{ false }; std::string srtpKey; std::string srtpKeyBase64; diff --git a/worker/include/RTC/PlainTransport.hpp b/worker/include/RTC/PlainTransport.hpp index ad9783618f..ed8fb54352 100644 --- a/worker/include/RTC/PlainTransport.hpp +++ b/worker/include/RTC/PlainTransport.hpp @@ -76,8 +76,12 @@ namespace RTC ListenInfo rtcpListenInfo; bool rtcpMux{ true }; bool comedia{ false }; - struct sockaddr_storage remoteAddrStorage; - struct sockaddr_storage rtcpRemoteAddrStorage; + struct sockaddr_storage remoteAddrStorage + { + }; // NOLINT + struct sockaddr_storage rtcpRemoteAddrStorage + { + }; // NOLINT RTC::SrtpSession::CryptoSuite srtpCryptoSuite{ RTC::SrtpSession::CryptoSuite::AES_CM_128_HMAC_SHA1_80 }; diff --git a/worker/include/RTC/Producer.hpp b/worker/include/RTC/Producer.hpp index a7c3e14fae..d7562587c3 100644 --- a/worker/include/RTC/Producer.hpp +++ b/worker/include/RTC/Producer.hpp @@ -98,7 +98,7 @@ namespace RTC const std::string& id, RTC::Producer::Listener* listener, const FBS::Transport::ProduceRequest* data); - virtual ~Producer(); + ~Producer() override; public: flatbuffers::Offset FillBuffer( diff --git a/worker/include/RTC/RTCP/FeedbackRtpTransport.hpp b/worker/include/RTC/RTCP/FeedbackRtpTransport.hpp index 6c4398664d..cfbbf0c276 100644 --- a/worker/include/RTC/RTCP/FeedbackRtpTransport.hpp +++ b/worker/include/RTC/RTCP/FeedbackRtpTransport.hpp @@ -209,13 +209,13 @@ namespace RTC { } FeedbackRtpTransportPacket(CommonHeader* commonHeader, size_t availableLen); - ~FeedbackRtpTransportPacket(); + ~FeedbackRtpTransportPacket() override; public: AddPacketResult AddPacket(uint16_t sequenceNumber, uint64_t timestamp, size_t maxRtcpPacketLen); // Just for locally generated packets. void Finish(); - bool IsFull() + bool IsFull() const { // NOTE: Since AddPendingChunks() is called at the end, we cannot track // the exact ongoing value of packetStatusCount. Hence, let's reserve 7 @@ -224,7 +224,7 @@ namespace RTC } bool IsSerializable() const { - return this->deltas.size() > 0; + return !this->deltas.empty(); } bool IsCorrect() const // Just for locally generated packets. { diff --git a/worker/include/RTC/RateCalculator.hpp b/worker/include/RTC/RateCalculator.hpp index d4e974e740..871d4e5977 100644 --- a/worker/include/RTC/RateCalculator.hpp +++ b/worker/include/RTC/RateCalculator.hpp @@ -17,7 +17,7 @@ namespace RTC static constexpr uint16_t DefaultWindowItems{ 100u }; public: - RateCalculator( + explicit RateCalculator( size_t windowSizeMs = DefaultWindowSize, float scale = DefaultBpsScale, uint16_t windowItems = DefaultWindowItems) diff --git a/worker/include/RTC/Router.hpp b/worker/include/RTC/Router.hpp index 46b96f7d65..cd9ab24687 100644 --- a/worker/include/RTC/Router.hpp +++ b/worker/include/RTC/Router.hpp @@ -38,7 +38,7 @@ namespace RTC public: explicit Router(RTC::Shared* shared, const std::string& id, Listener* listener); - virtual ~Router(); + ~Router() override; public: flatbuffers::Offset FillBuffer( @@ -111,7 +111,7 @@ namespace RTC /* Pure virtual methods inherited from RTC::RtpObserver::Listener. */ public: - RTC::Producer* RtpObserverGetProducer(RTC::RtpObserver*, const std::string& id) override; + RTC::Producer* RtpObserverGetProducer(RTC::RtpObserver* rtpObserver, const std::string& id) override; void OnRtpObserverAddProducer(RTC::RtpObserver* rtpObserver, RTC::Producer* producer) override; void OnRtpObserverRemoveProducer(RTC::RtpObserver* rtpObserver, RTC::Producer* producer) override; diff --git a/worker/include/RTC/RtcLogger.hpp b/worker/include/RTC/RtcLogger.hpp index 76c1364870..a241d407c2 100644 --- a/worker/include/RTC/RtcLogger.hpp +++ b/worker/include/RTC/RtcLogger.hpp @@ -40,17 +40,17 @@ namespace RTC void Clear(); public: - uint64_t timestamp; + uint64_t timestamp{}; std::string recvTransportId{}; std::string sendTransportId{}; std::string routerId{}; std::string producerId{}; std::string consumerId{}; - uint32_t recvRtpTimestamp; - uint32_t sendRtpTimestamp; - uint16_t recvSeqNumber; - uint16_t sendSeqNumber; - bool dropped; + uint32_t recvRtpTimestamp{}; + uint32_t sendRtpTimestamp{}; + uint16_t recvSeqNumber{}; + uint16_t sendSeqNumber{}; + bool dropped{}; DropReason dropReason{ DropReason::NONE }; }; }; // namespace RtcLogger diff --git a/worker/include/RTC/RtpObserver.hpp b/worker/include/RTC/RtpObserver.hpp index c17efdc5ad..eee22f8cf7 100644 --- a/worker/include/RTC/RtpObserver.hpp +++ b/worker/include/RTC/RtpObserver.hpp @@ -27,7 +27,7 @@ namespace RTC public: RtpObserver(RTC::Shared* shared, const std::string& id, RTC::RtpObserver::Listener* listener); - virtual ~RtpObserver(); + ~RtpObserver() override; public: void Pause(); diff --git a/worker/include/RTC/RtpPacket.hpp b/worker/include/RTC/RtpPacket.hpp index 81be74fe4f..2058058365 100644 --- a/worker/include/RTC/RtpPacket.hpp +++ b/worker/include/RTC/RtpPacket.hpp @@ -217,7 +217,7 @@ namespace RTC bool HasHeaderExtension() const { - return (this->headerExtension ? true : false); + return (this->headerExtension != nullptr); } // After calling this method, all the extension ids are reset to 0. @@ -366,7 +366,7 @@ namespace RTC return true; } - bool UpdateAbsSendTime(uint64_t ms) + bool UpdateAbsSendTime(uint64_t ms) const { uint8_t extenLen; uint8_t* extenValue = GetExtension(this->absSendTimeExtensionId, extenLen); @@ -398,7 +398,7 @@ namespace RTC return true; } - bool UpdateTransportWideCc01(uint16_t wideSeqNumber) + bool UpdateTransportWideCc01(uint16_t wideSeqNumber) const { uint8_t extenLen; uint8_t* extenValue = GetExtension(this->transportWideCc01ExtensionId, extenLen); @@ -446,7 +446,7 @@ namespace RTC } volume = Utils::Byte::Get1Byte(extenValue, 0); - voice = (volume & (1 << 7)) ? true : false; + voice = (volume & (1 << 7)) != 0; volume &= ~(1 << 7); return true; @@ -462,13 +462,13 @@ namespace RTC return false; } - uint8_t cvoByte = Utils::Byte::Get1Byte(extenValue, 0); - uint8_t cameraValue = ((cvoByte & 0b00001000) >> 3); - uint8_t flipValue = ((cvoByte & 0b00000100) >> 2); - uint8_t rotationValue = (cvoByte & 0b00000011); + const uint8_t cvoByte = Utils::Byte::Get1Byte(extenValue, 0); + const uint8_t cameraValue = ((cvoByte & 0b00001000) >> 3); + const uint8_t flipValue = ((cvoByte & 0b00000100) >> 2); + const uint8_t rotationValue = (cvoByte & 0b00000011); - camera = cameraValue ? true : false; - flip = flipValue ? true : false; + camera = cameraValue != 0; + flip = flipValue != 0; // Using counter clockwise values. switch (rotationValue) @@ -517,12 +517,7 @@ namespace RTC auto* extension = it->second; // In Two-Byte extensions value length may be zero. If so, return false. - if (extension->len == 0u) - { - return false; - } - - return true; + return extension->len != 0u; } else { @@ -666,7 +661,7 @@ namespace RTC HeaderExtension* headerExtension{ nullptr }; // There might be up to 14 one-byte header extensions // (https://datatracker.ietf.org/doc/html/rfc5285#section-4.2), use std::array. - std::array oneByteExtensions; + std::array oneByteExtensions{}; absl::flat_hash_map mapTwoBytesExtensions; uint8_t midExtensionId{ 0u }; uint8_t ridExtensionId{ 0u }; diff --git a/worker/include/RTC/RtpRetransmissionBuffer.hpp b/worker/include/RTC/RtpRetransmissionBuffer.hpp index dee6894876..47229d7efe 100644 --- a/worker/include/RTC/RtpRetransmissionBuffer.hpp +++ b/worker/include/RTC/RtpRetransmissionBuffer.hpp @@ -32,6 +32,10 @@ namespace RTC uint8_t sentTimes{ 0u }; }; + private: + static Item* FillItem( + Item* item, RTC::RtpPacket* packet, std::shared_ptr& sharedPacket); + public: RtpRetransmissionBuffer(uint16_t maxItems, uint32_t maxRetransmissionDelayMs, uint32_t clockRate); ~RtpRetransmissionBuffer(); @@ -48,8 +52,6 @@ namespace RTC void RemoveOldest(uint16_t numItems); bool ClearTooOldByTimestamp(uint32_t newestTimestamp); bool IsTooOldTimestamp(uint32_t timestamp, uint32_t newestTimestamp) const; - Item* FillItem( - Item* item, RTC::RtpPacket* packet, std::shared_ptr& sharedPacket) const; protected: // Make buffer protected for testing purposes. diff --git a/worker/include/RTC/RtpStreamRecv.hpp b/worker/include/RTC/RtpStreamRecv.hpp index 19b25fa8df..932f52cbae 100644 --- a/worker/include/RTC/RtpStreamRecv.hpp +++ b/worker/include/RTC/RtpStreamRecv.hpp @@ -47,7 +47,7 @@ namespace RTC RTC::RtpStream::Params& params, unsigned int sendNackDelayMs, bool useRtpInactivityCheck); - ~RtpStreamRecv(); + ~RtpStreamRecv() override; flatbuffers::Offset FillBufferStats( flatbuffers::FlatBufferBuilder& builder) override; diff --git a/worker/include/RTC/SctpAssociation.hpp b/worker/include/RTC/SctpAssociation.hpp index 146aca32bd..e2f3fe7922 100644 --- a/worker/include/RTC/SctpAssociation.hpp +++ b/worker/include/RTC/SctpAssociation.hpp @@ -89,7 +89,7 @@ namespace RTC { return this->sctpBufferedAmount; } - void ProcessSctpData(const uint8_t* data, size_t len); + void ProcessSctpData(const uint8_t* data, size_t len) const; void SendSctpMessage( RTC::DataConsumer* dataConsumer, const uint8_t* msg, @@ -101,7 +101,7 @@ namespace RTC void DataConsumerClosed(RTC::DataConsumer* dataConsumer); private: - void ResetSctpStream(uint16_t streamId, StreamDirection); + void ResetSctpStream(uint16_t streamId, StreamDirection direction); void AddOutgoingStreams(bool force = false); /* Callbacks fired by usrsctp events. */ diff --git a/worker/include/RTC/StunPacket.hpp b/worker/include/RTC/StunPacket.hpp index 98e1f527eb..ab4846e237 100644 --- a/worker/include/RTC/StunPacket.hpp +++ b/worker/include/RTC/StunPacket.hpp @@ -63,15 +63,15 @@ namespace RTC // DOC: https://tools.ietf.org/html/draft-ietf-avtcore-rfc5764-mux-fixes (data[0] < 3) && // Magic cookie must match. - (data[4] == StunPacket::magicCookie[0]) && (data[5] == StunPacket::magicCookie[1]) && - (data[6] == StunPacket::magicCookie[2]) && (data[7] == StunPacket::magicCookie[3]) + (data[4] == StunPacket::MagicCookie[0]) && (data[5] == StunPacket::MagicCookie[1]) && + (data[6] == StunPacket::MagicCookie[2]) && (data[7] == StunPacket::MagicCookie[3]) ); // clang-format on } static StunPacket* Parse(const uint8_t* data, size_t len); private: - static const uint8_t magicCookie[]; + static const uint8_t MagicCookie[]; public: StunPacket( @@ -173,7 +173,7 @@ namespace RTC } bool HasMessageIntegrity() const { - return (this->messageIntegrity ? true : false); + return (this->messageIntegrity != nullptr); } bool HasFingerprint() const { diff --git a/worker/include/RTC/Transport.hpp b/worker/include/RTC/Transport.hpp index 95814a4920..8d0eed1615 100644 --- a/worker/include/RTC/Transport.hpp +++ b/worker/include/RTC/Transport.hpp @@ -148,7 +148,7 @@ namespace RTC const std::string& id, RTC::Transport::Listener* listener, const FBS::Transport::Options* options); - virtual ~Transport(); + ~Transport() override; public: void CloseProducersAndConsumers(); @@ -271,7 +271,7 @@ namespace RTC const uint8_t* msg, size_t len, uint32_t ppid, - onQueuedCallback* = nullptr) override; + onQueuedCallback* cb = nullptr) override; void OnDataConsumerDataProducerClosed(RTC::DataConsumer* dataConsumer) override; /* Pure virtual methods inherited from RTC::SctpAssociation::Listener. */ diff --git a/worker/include/RTC/TransportCongestionControlClient.hpp b/worker/include/RTC/TransportCongestionControlClient.hpp index 4bd3796284..50df900b58 100644 --- a/worker/include/RTC/TransportCongestionControlClient.hpp +++ b/worker/include/RTC/TransportCongestionControlClient.hpp @@ -58,7 +58,7 @@ namespace RTC uint32_t initialAvailableBitrate, uint32_t maxOutgoingBitrate, uint32_t minOutgoingBitrate); - virtual ~TransportCongestionControlClient(); + ~TransportCongestionControlClient() override; public: RTC::BweType GetBweType() const diff --git a/worker/include/RTC/TransportCongestionControlServer.hpp b/worker/include/RTC/TransportCongestionControlServer.hpp index ae1e307707..d25483c90e 100644 --- a/worker/include/RTC/TransportCongestionControlServer.hpp +++ b/worker/include/RTC/TransportCongestionControlServer.hpp @@ -31,7 +31,7 @@ namespace RTC RTC::TransportCongestionControlServer::Listener* listener, RTC::BweType bweType, size_t maxRtcpPacketLen); - virtual ~TransportCongestionControlServer(); + ~TransportCongestionControlServer() override; public: RTC::BweType GetBweType() const diff --git a/worker/include/RTC/TransportTuple.hpp b/worker/include/RTC/TransportTuple.hpp index d282de036b..cfdaa69e36 100644 --- a/worker/include/RTC/TransportTuple.hpp +++ b/worker/include/RTC/TransportTuple.hpp @@ -245,7 +245,9 @@ namespace RTC RTC::TcpConnection* tcpConnection{ nullptr }; std::string localAnnouncedIp; // Others. - struct sockaddr_storage udpRemoteAddrStorage; + struct sockaddr_storage udpRemoteAddrStorage + { + }; // NOLINT Protocol protocol; }; } // namespace RTC diff --git a/worker/include/RTC/TrendCalculator.hpp b/worker/include/RTC/TrendCalculator.hpp index 1e082a862a..a9150d8724 100644 --- a/worker/include/RTC/TrendCalculator.hpp +++ b/worker/include/RTC/TrendCalculator.hpp @@ -11,7 +11,7 @@ namespace RTC static constexpr float DecreaseFactor{ 0.05f }; // per second. public: - TrendCalculator(float decreaseFactor = DecreaseFactor); + explicit TrendCalculator(float decreaseFactor = DecreaseFactor); public: uint32_t GetValue() const diff --git a/worker/include/RTC/WebRtcServer.hpp b/worker/include/RTC/WebRtcServer.hpp index 49803dd6ec..ea8fe12e71 100644 --- a/worker/include/RTC/WebRtcServer.hpp +++ b/worker/include/RTC/WebRtcServer.hpp @@ -38,17 +38,20 @@ namespace RTC std::string announcedIp; }; + private: + static std::string GetLocalIceUsernameFragmentFromReceivedStunPacket(RTC::StunPacket* packet); + public: WebRtcServer( RTC::Shared* shared, const std::string& id, const flatbuffers::Vector>* listenInfos); - ~WebRtcServer(); + ~WebRtcServer() override; public: flatbuffers::Offset FillBuffer( flatbuffers::FlatBufferBuilder& builder) const; - const std::vector GetIceCandidates( + std::vector GetIceCandidates( bool enableUdp, bool enableTcp, bool preferUdp, bool preferTcp) const; /* Methods inherited from Channel::ChannelSocket::RequestHandler. */ @@ -56,7 +59,6 @@ namespace RTC void HandleRequest(Channel::ChannelRequest* request) override; private: - std::string GetLocalIceUsernameFragmentFromReceivedStunPacket(RTC::StunPacket* packet) const; void OnPacketReceived(RTC::TransportTuple* tuple, const uint8_t* data, size_t len); void OnStunDataReceived(RTC::TransportTuple* tuple, const uint8_t* data, size_t len); void OnNonStunDataReceived(RTC::TransportTuple* tuple, const uint8_t* data, size_t len); diff --git a/worker/include/handles/TcpConnectionHandle.hpp b/worker/include/handles/TcpConnectionHandle.hpp index 4fff59319a..d6ec543ce1 100644 --- a/worker/include/handles/TcpConnectionHandle.hpp +++ b/worker/include/handles/TcpConnectionHandle.hpp @@ -24,9 +24,8 @@ class TcpConnectionHandle /* Struct for the data field of uv_req_t when writing into the connection. */ struct UvWriteData { - explicit UvWriteData(size_t storeSize) + explicit UvWriteData(size_t storeSize) : store(new uint8_t[storeSize]) { - this->store = new uint8_t[storeSize]; } // Disable copy constructor because of the dynamically allocated data (store). @@ -38,7 +37,7 @@ class TcpConnectionHandle delete this->cb; } - uv_write_t req; + uv_write_t req{}; uint8_t* store{ nullptr }; TcpConnectionHandle::onSendCallback* cb{ nullptr }; }; @@ -132,7 +131,9 @@ class TcpConnectionHandle size_t bufferDataLen{ 0u }; std::string localIp; uint16_t localPort{ 0u }; - struct sockaddr_storage peerAddr; + struct sockaddr_storage peerAddr + { + }; // NOLINT std::string peerIp; uint16_t peerPort{ 0u }; diff --git a/worker/include/handles/TcpServerHandle.hpp b/worker/include/handles/TcpServerHandle.hpp index 3d7608d88d..4d1b572525 100644 --- a/worker/include/handles/TcpServerHandle.hpp +++ b/worker/include/handles/TcpServerHandle.hpp @@ -13,8 +13,8 @@ class TcpServerHandle : public TcpConnectionHandle::Listener /** * uvHandle must be an already initialized and binded uv_tcp_t pointer. */ - TcpServerHandle(uv_tcp_t* uvHandle); - virtual ~TcpServerHandle() override; + explicit TcpServerHandle(uv_tcp_t* uvHandle); + ~TcpServerHandle() override; public: void Close(); @@ -64,7 +64,9 @@ class TcpServerHandle : public TcpConnectionHandle::Listener void OnTcpConnectionClosed(TcpConnectionHandle* connection) override; protected: - struct sockaddr_storage localAddr; + struct sockaddr_storage localAddr + { + }; // NOLINT std::string localIp; uint16_t localPort{ 0u }; diff --git a/worker/include/handles/UdpSocketHandle.hpp b/worker/include/handles/UdpSocketHandle.hpp index 37ed5fd5dc..f5762cdd60 100644 --- a/worker/include/handles/UdpSocketHandle.hpp +++ b/worker/include/handles/UdpSocketHandle.hpp @@ -14,9 +14,8 @@ class UdpSocketHandle /* Struct for the data field of uv_req_t when sending a datagram. */ struct UvSendData { - explicit UvSendData(size_t storeSize) + explicit UvSendData(size_t storeSize) : store(new uint8_t[storeSize]) { - this->store = new uint8_t[storeSize]; } // Disable copy constructor because of the dynamically allocated data (store). @@ -28,7 +27,7 @@ class UdpSocketHandle delete this->cb; } - uv_udp_send_t req; + uv_udp_send_t req{}; uint8_t* store{ nullptr }; UdpSocketHandle::onSendCallback* cb{ nullptr }; }; @@ -95,7 +94,9 @@ class UdpSocketHandle const uint8_t* data, size_t len, const struct sockaddr* addr) = 0; protected: - struct sockaddr_storage localAddr; + struct sockaddr_storage localAddr + { + }; // NOLINT std::string localIp; uint16_t localPort{ 0u }; diff --git a/worker/include/handles/UnixStreamSocketHandle.hpp b/worker/include/handles/UnixStreamSocketHandle.hpp index 164ab02ec6..e7dc9be5e4 100644 --- a/worker/include/handles/UnixStreamSocketHandle.hpp +++ b/worker/include/handles/UnixStreamSocketHandle.hpp @@ -11,9 +11,8 @@ class UnixStreamSocketHandle /* Struct for the data field of uv_req_t when writing data. */ struct UvWriteData { - explicit UvWriteData(size_t storeSize) + explicit UvWriteData(size_t storeSize) : store(new uint8_t[storeSize]) { - this->store = new uint8_t[storeSize]; } // Disable copy constructor because of the dynamically allocated data (store). @@ -24,7 +23,7 @@ class UnixStreamSocketHandle delete[] this->store; } - uv_write_t req; + uv_write_t req{}; uint8_t* store{ nullptr }; }; diff --git a/worker/src/Channel/ChannelSocket.cpp b/worker/src/Channel/ChannelSocket.cpp index d9310692f8..556072df7b 100644 --- a/worker/src/Channel/ChannelSocket.cpp +++ b/worker/src/Channel/ChannelSocket.cpp @@ -43,13 +43,12 @@ namespace Channel ChannelWriteFn channelWriteFn, ChannelWriteCtx channelWriteCtx) : channelReadFn(channelReadFn), channelReadCtx(channelReadCtx), channelWriteFn(channelWriteFn), - channelWriteCtx(channelWriteCtx) + channelWriteCtx(channelWriteCtx), uvReadHandle(new uv_async_t) { MS_TRACE_STD(); int err; - this->uvReadHandle = new uv_async_t; this->uvReadHandle->data = static_cast(this); err = @@ -122,7 +121,7 @@ namespace Channel this->listener = listener; } - void ChannelSocket::Send(const uint8_t* message, uint32_t messageLen) + void ChannelSocket::Send(const uint8_t* data, uint32_t dataLen) { MS_TRACE_STD(); @@ -131,17 +130,17 @@ namespace Channel return; } - if (messageLen > PayloadMaxLen) + if (dataLen > PayloadMaxLen) { MS_ERROR_STD("message too big"); return; } - SendImpl(reinterpret_cast(message), messageLen); + SendImpl(reinterpret_cast(data), dataLen); } - void ChannelSocket::SendLog(const char* msg, uint32_t messageLen) + void ChannelSocket::SendLog(const char* data, uint32_t dataLen) { MS_TRACE_STD(); @@ -150,14 +149,14 @@ namespace Channel return; } - if (messageLen > PayloadMaxLen) + if (dataLen > PayloadMaxLen) { MS_ERROR_STD("message too big"); return; } - auto log = FBS::Log::CreateLogDirect(this->bufferBuilder, msg); + auto log = FBS::Log::CreateLogDirect(this->bufferBuilder, data); auto message = FBS::Message::CreateMessage(this->bufferBuilder, FBS::Message::Body::Log, log.Union()); @@ -263,7 +262,8 @@ namespace Channel } } - void ChannelSocket::OnConsumerSocketMessage(ConsumerSocket* /*consumerSocket*/, char* msg, size_t msgLen) + void ChannelSocket::OnConsumerSocketMessage( + ConsumerSocket* /*consumerSocket*/, char* msg, size_t /*msgLen*/) { MS_TRACE(); @@ -356,7 +356,7 @@ namespace Channel return; } - size_t readLen = this->bufferDataLen - msgStart; + const size_t readLen = this->bufferDataLen - msgStart; if (readLen < sizeof(uint32_t)) { diff --git a/worker/src/DepLibSRTP.cpp b/worker/src/DepLibSRTP.cpp index e3c8c4be3f..bb9fdde4d6 100644 --- a/worker/src/DepLibSRTP.cpp +++ b/worker/src/DepLibSRTP.cpp @@ -8,8 +8,8 @@ /* Static variables. */ -static std::mutex globalSyncMutex; -static size_t globalInstances = 0; +static std::mutex GlobalSyncMutex; +static size_t GlobalInstances = 0; // clang-format off std::vector DepLibSRTP::errors = @@ -50,9 +50,9 @@ void DepLibSRTP::ClassInit() MS_TRACE(); { - std::lock_guard lock(globalSyncMutex); + const std::lock_guard lock(GlobalSyncMutex); - if (globalInstances == 0) + if (GlobalInstances == 0) { MS_DEBUG_TAG(info, "libsrtp version: \"%s\"", srtp_get_version_string()); @@ -64,7 +64,7 @@ void DepLibSRTP::ClassInit() } } - ++globalInstances; + ++GlobalInstances; } } @@ -73,10 +73,10 @@ void DepLibSRTP::ClassDestroy() MS_TRACE(); { - std::lock_guard lock(globalSyncMutex); - --globalInstances; + const std::lock_guard lock(GlobalSyncMutex); + --GlobalInstances; - if (globalInstances == 0) + if (GlobalInstances == 0) { srtp_shutdown(); } diff --git a/worker/src/DepLibWebRTC.cpp b/worker/src/DepLibWebRTC.cpp index c5edfa2999..dda51cc403 100644 --- a/worker/src/DepLibWebRTC.cpp +++ b/worker/src/DepLibWebRTC.cpp @@ -9,7 +9,7 @@ /* Static. */ -static std::once_flag globalInitOnce; +static std::once_flag GlobalInitOnce; /* Static methods. */ @@ -21,7 +21,7 @@ void DepLibWebRTC::ClassInit() info, "libwebrtc field trials: \"%s\"", Settings::configuration.libwebrtcFieldTrials.c_str()); std::call_once( - globalInitOnce, + GlobalInitOnce, [] { webrtc::field_trial::InitFieldTrialsFromString( diff --git a/worker/src/DepOpenSSL.cpp b/worker/src/DepOpenSSL.cpp index f38be5fe67..1f75d46d6c 100644 --- a/worker/src/DepOpenSSL.cpp +++ b/worker/src/DepOpenSSL.cpp @@ -9,7 +9,7 @@ /* Static. */ -static std::once_flag globalInitOnce; +static std::once_flag GlobalInitOnce; /* Static methods. */ @@ -18,7 +18,7 @@ void DepOpenSSL::ClassInit() MS_TRACE(); std::call_once( - globalInitOnce, + GlobalInitOnce, [] { MS_DEBUG_TAG(info, "openssl version: \"%s\"", OpenSSL_version(OPENSSL_VERSION)); diff --git a/worker/src/DepUsrSCTP.cpp b/worker/src/DepUsrSCTP.cpp index 4eb0e40713..700bac3348 100644 --- a/worker/src/DepUsrSCTP.cpp +++ b/worker/src/DepUsrSCTP.cpp @@ -69,7 +69,7 @@ void DepUsrSCTP::ClassInit() MS_DEBUG_TAG(info, "usrsctp"); - std::lock_guard lock(GlobalSyncMutex); + const std::lock_guard lock(GlobalSyncMutex); if (GlobalInstances == 0) { @@ -90,7 +90,7 @@ void DepUsrSCTP::ClassDestroy() { MS_TRACE(); - std::lock_guard lock(GlobalSyncMutex); + const std::lock_guard lock(GlobalSyncMutex); --GlobalInstances; if (GlobalInstances == 0) @@ -126,7 +126,7 @@ uintptr_t DepUsrSCTP::GetNextSctpAssociationId() { MS_TRACE(); - std::lock_guard lock(GlobalSyncMutex); + const std::lock_guard lock(GlobalSyncMutex); // NOTE: usrsctp_connect() fails with a value of 0. if (DepUsrSCTP::nextSctpAssociationId == 0u) @@ -154,7 +154,7 @@ void DepUsrSCTP::RegisterSctpAssociation(RTC::SctpAssociation* sctpAssociation) { MS_TRACE(); - std::lock_guard lock(GlobalSyncMutex); + const std::lock_guard lock(GlobalSyncMutex); MS_ASSERT(DepUsrSCTP::checker != nullptr, "Checker not created"); @@ -176,7 +176,7 @@ void DepUsrSCTP::DeregisterSctpAssociation(RTC::SctpAssociation* sctpAssociation { MS_TRACE(); - std::lock_guard lock(GlobalSyncMutex); + const std::lock_guard lock(GlobalSyncMutex); MS_ASSERT(DepUsrSCTP::checker != nullptr, "Checker not created"); @@ -195,7 +195,7 @@ RTC::SctpAssociation* DepUsrSCTP::RetrieveSctpAssociation(uintptr_t id) { MS_TRACE(); - std::lock_guard lock(GlobalSyncMutex); + const std::lock_guard lock(GlobalSyncMutex); auto it = DepUsrSCTP::mapIdSctpAssociation.find(id); @@ -209,11 +209,9 @@ RTC::SctpAssociation* DepUsrSCTP::RetrieveSctpAssociation(uintptr_t id) /* DepUsrSCTP::Checker instance methods. */ -DepUsrSCTP::Checker::Checker() +DepUsrSCTP::Checker::Checker() : timer(new TimerHandle(this)) { MS_TRACE(); - - this->timer = new TimerHandle(this); } DepUsrSCTP::Checker::~Checker() diff --git a/worker/src/Logger.cpp b/worker/src/Logger.cpp index d7d972c9d7..6ec0c4181f 100644 --- a/worker/src/Logger.cpp +++ b/worker/src/Logger.cpp @@ -6,9 +6,9 @@ /* Class variables. */ -const uint64_t Logger::pid{ static_cast(uv_os_getpid()) }; +const uint64_t Logger::Pid{ static_cast(uv_os_getpid()) }; thread_local Channel::ChannelSocket* Logger::channel{ nullptr }; -thread_local char Logger::buffer[Logger::bufferSize]; +thread_local char Logger::buffer[Logger::BufferSize]; /* Class methods. */ diff --git a/worker/src/MediaSoupErrors.cpp b/worker/src/MediaSoupErrors.cpp index 29e3492f4a..d40b6d225b 100644 --- a/worker/src/MediaSoupErrors.cpp +++ b/worker/src/MediaSoupErrors.cpp @@ -2,4 +2,4 @@ #include "MediaSoupErrors.hpp" -thread_local char MediaSoupError::buffer[MediaSoupError::bufferSize]; +thread_local char MediaSoupError::buffer[MediaSoupError::BufferSize]; diff --git a/worker/src/RTC/ActiveSpeakerObserver.cpp b/worker/src/RTC/ActiveSpeakerObserver.cpp index b0f15ae037..ff27d63d67 100644 --- a/worker/src/RTC/ActiveSpeakerObserver.cpp +++ b/worker/src/RTC/ActiveSpeakerObserver.cpp @@ -67,8 +67,8 @@ namespace RTC inline bool ComputeBigs( const std::vector& littles, std::vector& bigs, uint8_t threashold) { - uint32_t littleLen = littles.size(); - uint32_t bigLen = bigs.size(); + const uint32_t littleLen = littles.size(); + const uint32_t bigLen = bigs.size(); const uint32_t littleLenPerBig = littleLen / bigLen; bool changed{ false }; @@ -99,12 +99,10 @@ namespace RTC const std::string& id, RTC::RtpObserver::Listener* listener, const FBS::ActiveSpeakerObserver::ActiveSpeakerObserverOptions* options) - : RTC::RtpObserver(shared, id, listener) + : RTC::RtpObserver(shared, id, listener), interval(options->interval()) { MS_TRACE(); - this->interval = options->interval(); - if (this->interval < 100) { this->interval = 100; @@ -231,14 +229,14 @@ namespace RTC return; } - uint8_t volume = 127 - level; + const uint8_t volume = 127 - level; auto it = this->mapProducerSpeakers.find(producer->id); if (it != this->mapProducerSpeakers.end()) { auto* producerSpeaker = it->second; - uint64_t now = DepLibUV::GetTimeMs(); + const uint64_t now = DepLibUV::GetTimeMs(); producerSpeaker->speaker->LevelChanged(volume, now); } @@ -258,7 +256,7 @@ namespace RTC this->periodicTimer->Restart(); } - void ActiveSpeakerObserver::OnTimer(TimerHandle* timer) + void ActiveSpeakerObserver::OnTimer(TimerHandle* /*timer*/) { MS_TRACE(); @@ -299,7 +297,7 @@ namespace RTC MS_TRACE(); std::string newDominantId; - int32_t speakerCount = this->mapProducerSpeakers.size(); + const int32_t speakerCount = this->mapProducerSpeakers.size(); if (speakerCount == 0) { @@ -352,9 +350,9 @@ namespace RTC speaker->GetActivityScore(interval) / dominantSpeaker->GetActivityScore(interval)); } - double c1 = this->relativeSpeachActivities[0]; - double c2 = this->relativeSpeachActivities[1]; - double c3 = this->relativeSpeachActivities[2]; + const double c1 = this->relativeSpeachActivities[0]; + const double c2 = this->relativeSpeachActivities[1]; + const double c3 = this->relativeSpeachActivities[2]; if ((c1 > C1) && (c2 > C2) && (c3 > C3) && (c2 > newDominantC2)) { @@ -383,7 +381,7 @@ namespace RTC auto* producerSpeaker = kv.second; auto* speaker = producerSpeaker->speaker; const auto& id = producerSpeaker->producer->id; - uint64_t idle = now - speaker->lastLevelChangeTime; + const uint64_t idle = now - speaker->lastLevelChangeTime; if (SpeakerIdleTimeout < idle && (this->dominantId.empty() || id != this->dominantId)) { @@ -397,11 +395,10 @@ namespace RTC } ActiveSpeakerObserver::ProducerSpeaker::ProducerSpeaker(RTC::Producer* producer) - : producer(producer) + : producer(producer), speaker(new Speaker()) { MS_TRACE(); - this->speaker = new Speaker(); this->speaker->paused = producer->IsPaused(); } @@ -416,7 +413,7 @@ namespace RTC : immediateActivityScore(MinActivityScore), mediumActivityScore(MinActivityScore), longActivityScore(MinActivityScore), lastLevelChangeTime(DepLibUV::GetTimeMs()), minLevel(MinLevel), nextMinLevel(MinLevel), immediates(ImmediateBuffLen, 0), - mediums(MediumsBuffLen, 0), longs(LongsBuffLen, 0), levels(LevelsBuffLen, 0), nextLevelIndex(0) + mediums(MediumsBuffLen, 0), longs(LongsBuffLen, 0), levels(LevelsBuffLen, 0) { MS_TRACE(); } @@ -441,7 +438,7 @@ namespace RTC } } - double ActiveSpeakerObserver::Speaker::GetActivityScore(uint8_t interval) + double ActiveSpeakerObserver::Speaker::GetActivityScore(uint8_t interval) const { MS_TRACE(); @@ -486,7 +483,7 @@ namespace RTC // The algorithm expect to have an update every 20 milliseconds. If the // Producer is paused, using a different packetization time or using DTX // we need to update more than one sample when receiving an audio packet. - uint32_t intervalsUpdated = + const uint32_t intervalsUpdated = std::min(std::max(static_cast(elapsed / 20), 1U), LevelsBuffLen); for (uint32_t i{ 0u }; i < intervalsUpdated; ++i) diff --git a/worker/src/RTC/Consumer.cpp b/worker/src/RTC/Consumer.cpp index 796924f795..84cda670ec 100644 --- a/worker/src/RTC/Consumer.cpp +++ b/worker/src/RTC/Consumer.cpp @@ -19,12 +19,11 @@ namespace RTC Listener* listener, const FBS::Transport::ConsumeRequest* data, RTC::RtpParameters::Type type) - : id(id), producerId(producerId), shared(shared), listener(listener), type(type) + : id(id), producerId(producerId), shared(shared), listener(listener), + kind(RTC::Media::Kind(data->kind())), type(type) { MS_TRACE(); - this->kind = RTC::Media::Kind(data->kind()); - // This may throw. this->rtpParameters = RTC::RtpParameters(data->rtpParameters()); diff --git a/worker/src/RTC/DataConsumer.cpp b/worker/src/RTC/DataConsumer.cpp index fdabc812a5..b54ce8c5cc 100644 --- a/worker/src/RTC/DataConsumer.cpp +++ b/worker/src/RTC/DataConsumer.cpp @@ -280,7 +280,7 @@ namespace RTC const auto* body = request->data->body_as(); const uint8_t* data = body->data()->Data(); - size_t len = body->data()->size(); + const size_t len = body->data()->size(); if (len > this->maxMessageSize) { @@ -303,9 +303,9 @@ namespace RTC } }); - static std::vector EmptySubchannels; + static std::vector emptySubchannels; - SendMessage(data, len, body->ppid(), EmptySubchannels, std::nullopt, cb); + SendMessage(data, len, body->ppid(), emptySubchannels, std::nullopt, cb); break; } @@ -543,7 +543,7 @@ namespace RTC // If subchannels are given, verify that this data consumer is subscribed // to at least one of them. - if (subchannels.size() > 0) + if (!subchannels.empty()) { bool subchannelMatched{ false }; diff --git a/worker/src/RTC/DataProducer.cpp b/worker/src/RTC/DataProducer.cpp index 2bb16ecab6..136f0bdbf9 100644 --- a/worker/src/RTC/DataProducer.cpp +++ b/worker/src/RTC/DataProducer.cpp @@ -202,7 +202,7 @@ namespace RTC { const auto* body = notification->data->body_as(); const uint8_t* data = body->data()->Data(); - size_t len = body->data()->size(); + const size_t len = body->data()->size(); if (len > this->maxMessageSize) { diff --git a/worker/src/RTC/DirectTransport.cpp b/worker/src/RTC/DirectTransport.cpp index d11d5a3acd..d0f0b9d118 100644 --- a/worker/src/RTC/DirectTransport.cpp +++ b/worker/src/RTC/DirectTransport.cpp @@ -213,7 +213,11 @@ namespace RTC } void DirectTransport::SendMessage( - RTC::DataConsumer* dataConsumer, const uint8_t* msg, size_t len, uint32_t ppid, onQueuedCallback* cb) + RTC::DataConsumer* dataConsumer, + const uint8_t* msg, + size_t len, + uint32_t ppid, + onQueuedCallback* /*cb*/) { MS_TRACE(); diff --git a/worker/src/RTC/DtlsTransport.cpp b/worker/src/RTC/DtlsTransport.cpp index adada495d3..3199c6aed4 100644 --- a/worker/src/RTC/DtlsTransport.cpp +++ b/worker/src/RTC/DtlsTransport.cpp @@ -71,14 +71,13 @@ inline static long onSslBioOut( int ret, size_t* /*processed*/) { - long resultOfcallback = (operationType == BIO_CB_RETURN) ? static_cast(ret) : 1; + const long resultOfcallback = (operationType == BIO_CB_RETURN) ? static_cast(ret) : 1; if (operationType == BIO_CB_WRITE && argp && len > 0) { MS_DEBUG_DEV("%zu bytes of DTLS data ready to be sent", len); - RTC::DtlsTransport* dtlsTransport = - reinterpret_cast(BIO_get_callback_arg(bio)); + auto* dtlsTransport = reinterpret_cast(BIO_get_callback_arg(bio)); dtlsTransport->SendDtlsData(reinterpret_cast(argp), len); } @@ -333,7 +332,7 @@ namespace RTC int ret{ 0 }; X509_NAME* certName{ nullptr }; - std::string subject = + const std::string subject = std::string("mediasoup") + std::to_string(Utils::Crypto::GetRandomUInt(100000, 999999)); // Create key with curve. @@ -618,8 +617,8 @@ namespace RTC for (auto& kv : DtlsTransport::string2FingerprintAlgorithm) { - const std::string& algorithmString = kv.first; - FingerprintAlgorithm algorithm = kv.second; + const std::string& algorithmString = kv.first; + const FingerprintAlgorithm algorithm = kv.second; uint8_t binaryFingerprint[EVP_MAX_MD_SIZE]; unsigned int size{ 0 }; char hexFingerprint[(EVP_MAX_MD_SIZE * 3) + 1]; @@ -693,14 +692,11 @@ namespace RTC /* Instance methods. */ - DtlsTransport::DtlsTransport(Listener* listener) : listener(listener) + DtlsTransport::DtlsTransport(Listener* listener) + : listener(listener), ssl(SSL_new(DtlsTransport::sslCtx)) { MS_TRACE(); - /* Set SSL. */ - - this->ssl = SSL_new(DtlsTransport::sslCtx); - if (!this->ssl) { LOG_OPENSSL_ERROR("SSL_new() failed"); diff --git a/worker/src/RTC/KeyFrameRequestManager.cpp b/worker/src/RTC/KeyFrameRequestManager.cpp index f3b1e7ed67..1112901b49 100644 --- a/worker/src/RTC/KeyFrameRequestManager.cpp +++ b/worker/src/RTC/KeyFrameRequestManager.cpp @@ -9,11 +9,10 @@ static constexpr uint32_t KeyFrameRetransmissionWaitTime{ 1000 }; /* PendingKeyFrameInfo methods. */ RTC::PendingKeyFrameInfo::PendingKeyFrameInfo(PendingKeyFrameInfo::Listener* listener, uint32_t ssrc) - : listener(listener), ssrc(ssrc) + : listener(listener), ssrc(ssrc), timer(new TimerHandle(this)) { MS_TRACE(); - this->timer = new TimerHandle(this); this->timer->Start(KeyFrameRetransmissionWaitTime); } @@ -39,11 +38,10 @@ inline void RTC::PendingKeyFrameInfo::OnTimer(TimerHandle* timer) RTC::KeyFrameRequestDelayer::KeyFrameRequestDelayer( KeyFrameRequestDelayer::Listener* listener, uint32_t ssrc, uint32_t delay) - : listener(listener), ssrc(ssrc) + : listener(listener), ssrc(ssrc), timer(new TimerHandle(this)) { MS_TRACE(); - this->timer = new TimerHandle(this); this->timer->Start(delay); } diff --git a/worker/src/RTC/NackGenerator.cpp b/worker/src/RTC/NackGenerator.cpp index 7eb168df40..f77c1f3c6b 100644 --- a/worker/src/RTC/NackGenerator.cpp +++ b/worker/src/RTC/NackGenerator.cpp @@ -21,12 +21,10 @@ namespace RTC /* Instance methods. */ NackGenerator::NackGenerator(Listener* listener, unsigned int sendNackDelayMs) - : listener(listener), sendNackDelayMs(sendNackDelayMs), rtt(DefaultRtt) + : listener(listener), sendNackDelayMs(sendNackDelayMs), timer(new TimerHandle(this)), + rtt(DefaultRtt) { MS_TRACE(); - - // Set the timer. - this->timer = new TimerHandle(this); } NackGenerator::~NackGenerator() @@ -42,7 +40,7 @@ namespace RTC { MS_TRACE(); - uint16_t seq = packet->GetSequenceNumber(); + const uint16_t seq = packet->GetSequenceNumber(); const bool isKeyFrame = packet->IsKeyFrame(); if (!this->started) @@ -83,14 +81,7 @@ namespace RTC this->nackList.erase(it); - if (retries != 0) - { - return true; - } - else - { - return false; - } + return retries != 0; } // Out of order packet or already handled NACKed packet. @@ -145,7 +136,7 @@ namespace RTC this->lastSeq = seq; // Check if there are any nacks that are waiting for this seq number. - std::vector nackBatch = GetNackBatch(NackFilter::SEQ); + const std::vector nackBatch = GetNackBatch(NackFilter::SEQ); if (!nackBatch.empty()) { @@ -256,7 +247,7 @@ namespace RTC while (it != this->nackList.end()) { NackInfo& nackInfo = it->second; - uint16_t seq = nackInfo.seq; + const uint16_t seq = nackInfo.seq; if (this->sendNackDelayMs > 0 && nowMs - nackInfo.createdAtMs < this->sendNackDelayMs) { @@ -376,7 +367,7 @@ namespace RTC { MS_TRACE(); - std::vector nackBatch = GetNackBatch(NackFilter::TIME); + const std::vector nackBatch = GetNackBatch(NackFilter::TIME); if (!nackBatch.empty()) { diff --git a/worker/src/RTC/PortManager.cpp b/worker/src/RTC/PortManager.cpp index eea8dbb97c..69019dacf9 100644 --- a/worker/src/RTC/PortManager.cpp +++ b/worker/src/RTC/PortManager.cpp @@ -47,7 +47,9 @@ namespace RTC int err; const int family = Utils::IP::GetFamily(ip); - struct sockaddr_storage bindAddr; // NOLINT(cppcoreguidelines-pro-type-member-init) + struct sockaddr_storage bindAddr + { + }; // NOLINT size_t portIdx; std::vector& ports = PortManager::GetPorts(transport, ip); size_t attempt{ 0u }; @@ -55,7 +57,7 @@ namespace RTC uv_handle_t* uvHandle{ nullptr }; uint16_t port; std::string transportStr; - uint8_t bitFlags = ConvertSocketFlags(flags, transport, family); + const uint8_t bitFlags = ConvertSocketFlags(flags, transport, family); switch (transport) { @@ -375,10 +377,12 @@ namespace RTC int err; const int family = Utils::IP::GetFamily(ip); - struct sockaddr_storage bindAddr; // NOLINT(cppcoreguidelines-pro-type-member-init) + struct sockaddr_storage bindAddr + { + }; // NOLINT uv_handle_t* uvHandle{ nullptr }; std::string transportStr; - uint8_t bitFlags = ConvertSocketFlags(flags, transport, family); + const uint8_t bitFlags = ConvertSocketFlags(flags, transport, family); switch (transport) { diff --git a/worker/src/RTC/Producer.cpp b/worker/src/RTC/Producer.cpp index 5e2f195675..c465152d6c 100644 --- a/worker/src/RTC/Producer.cpp +++ b/worker/src/RTC/Producer.cpp @@ -32,13 +32,10 @@ namespace RTC const std::string& id, RTC::Producer::Listener* listener, const FBS::Transport::ProduceRequest* data) - : id(id), shared(shared), listener(listener) + : id(id), shared(shared), listener(listener), kind(RTC::Media::Kind(data->kind())) { MS_TRACE(); - // This may throw. - this->kind = RTC::Media::Kind(data->kind()); - // This may throw. this->rtpParameters = RTC::RtpParameters(data->rtpParameters()); diff --git a/worker/src/RTC/RtpPacket.cpp b/worker/src/RTC/RtpPacket.cpp index 8ebe9cce96..ef05d24a41 100644 --- a/worker/src/RTC/RtpPacket.cpp +++ b/worker/src/RTC/RtpPacket.cpp @@ -158,10 +158,7 @@ namespace RTC { MS_TRACE(); - if (this->buffer) - { - delete[] this->buffer; - } + delete[] this->buffer; } void RtpPacket::Dump() const @@ -840,14 +837,7 @@ namespace RTC return true; } - if (this->payloadDescriptorHandler->Process(context, this->payload, marker)) - { - return true; - } - else - { - return false; - } + return this->payloadDescriptorHandler->Process(context, this->payload, marker); } void RtpPacket::RestorePayload() diff --git a/worker/src/RTC/RtpRetransmissionBuffer.cpp b/worker/src/RTC/RtpRetransmissionBuffer.cpp index 78e57d0c77..284d5e3c51 100644 --- a/worker/src/RTC/RtpRetransmissionBuffer.cpp +++ b/worker/src/RTC/RtpRetransmissionBuffer.cpp @@ -7,6 +7,37 @@ namespace RTC { + /* Class methods. */ + + RtpRetransmissionBuffer::Item* RtpRetransmissionBuffer::FillItem( + RtpRetransmissionBuffer::Item* item, + RTC::RtpPacket* packet, + std::shared_ptr& sharedPacket) + { + MS_TRACE(); + + // Store original packet into the item. Only clone once and only if + // necessary. + // + // NOTE: This must be done BEFORE assigning item->packet = sharedPacket, + // otherwise the value being copied in item->packet will remain nullptr. + // This is because we are copying an **empty** shared_ptr into another + // shared_ptr (item->packet), so future value assigned via reset() in the + // former doesn't update the value in the copy. + if (!sharedPacket) + { + sharedPacket.reset(packet->Clone()); + } + + // Store original packet and some extra info into the item. + item->packet = sharedPacket; + item->ssrc = packet->GetSsrc(); + item->sequenceNumber = packet->GetSequenceNumber(); + item->timestamp = packet->GetTimestamp(); + + return item; + } + /* Instance methods. */ RtpRetransmissionBuffer::RtpRetransmissionBuffer( @@ -76,7 +107,7 @@ namespace RTC auto* item = new Item(); - this->buffer.push_back(FillItem(item, packet, sharedPacket)); + this->buffer.push_back(RtpRetransmissionBuffer::FillItem(item, packet, sharedPacket)); return; } @@ -102,7 +133,7 @@ namespace RTC auto* item = new Item(); - this->buffer.push_back(FillItem(item, packet, sharedPacket)); + this->buffer.push_back(RtpRetransmissionBuffer::FillItem(item, packet, sharedPacket)); return; } @@ -132,7 +163,7 @@ namespace RTC auto* item = new Item(); - this->buffer.push_back(FillItem(item, packet, sharedPacket)); + this->buffer.push_back(RtpRetransmissionBuffer::FillItem(item, packet, sharedPacket)); return; } @@ -215,7 +246,7 @@ namespace RTC // Push the packet, which becomes the newest one in the buffer. auto* item = new Item(); - this->buffer.push_back(FillItem(item, packet, sharedPacket)); + this->buffer.push_back(RtpRetransmissionBuffer::FillItem(item, packet, sharedPacket)); } // Packet arrived out order and its seq is less than seq of the oldest // stored packet, so will become the oldest one in the buffer. @@ -281,7 +312,7 @@ namespace RTC // Insert the packet, which becomes the oldest one in the buffer. auto* item = new Item(); - this->buffer.push_front(FillItem(item, packet, sharedPacket)); + this->buffer.push_front(RtpRetransmissionBuffer::FillItem(item, packet, sharedPacket)); } // Otherwise packet must be inserted between oldest and newest stored items // so there is already an allocated slot for it. @@ -375,7 +406,7 @@ namespace RTC // Store the packet. item = new Item(); - this->buffer[idx] = FillItem(item, packet, sharedPacket); + this->buffer[idx] = RtpRetransmissionBuffer::FillItem(item, packet, sharedPacket); } MS_ASSERT( @@ -411,7 +442,7 @@ namespace RTC MS_DUMP(""); MS_DUMP(" buffer [size:%zu, maxSize:%" PRIu16 "]", this->buffer.size(), this->maxItems); - if (this->buffer.size() > 0) + if (!this->buffer.empty()) { const auto* oldestItem = GetOldest(); const auto* newestItem = GetNewest(); @@ -554,35 +585,6 @@ namespace RTC return static_cast(diffTs * 1000 / this->clockRate) > this->maxRetransmissionDelayMs; } - RtpRetransmissionBuffer::Item* RtpRetransmissionBuffer::FillItem( - RtpRetransmissionBuffer::Item* item, - RTC::RtpPacket* packet, - std::shared_ptr& sharedPacket) const - { - MS_TRACE(); - - // Store original packet into the item. Only clone once and only if - // necessary. - // - // NOTE: This must be done BEFORE assigning item->packet = sharedPacket, - // otherwise the value being copied in item->packet will remain nullptr. - // This is because we are copying an **empty** shared_ptr into another - // shared_ptr (item->packet), so future value assigned via reset() in the - // former doesn't update the value in the copy. - if (!sharedPacket.get()) - { - sharedPacket.reset(packet->Clone()); - } - - // Store original packet and some extra info into the item. - item->packet = sharedPacket; - item->ssrc = packet->GetSsrc(); - item->sequenceNumber = packet->GetSequenceNumber(); - item->timestamp = packet->GetTimestamp(); - - return item; - } - void RtpRetransmissionBuffer::Item::Reset() { MS_TRACE(); diff --git a/worker/src/RTC/RtpStreamRecv.cpp b/worker/src/RTC/RtpStreamRecv.cpp index fd55c94618..ba9e50c6d8 100644 --- a/worker/src/RTC/RtpStreamRecv.cpp +++ b/worker/src/RTC/RtpStreamRecv.cpp @@ -27,7 +27,7 @@ namespace RTC { for (uint8_t tIdx{ 0u }; tIdx < temporalLayers; ++tIdx) { - spatialLayerCounter.emplace_back(RTC::RtpDataCounter(windowSize)); + spatialLayerCounter.emplace_back(windowSize); } } } @@ -561,7 +561,7 @@ namespace RTC this->lastSrTimestamp += report->GetNtpFrac() >> 16; // Update info about last Sender Report. - Utils::Time::Ntp ntp; // NOLINT(cppcoreguidelines-pro-type-member-init) + Utils::Time::Ntp ntp{}; // NOLINT(cppcoreguidelines-pro-type-member-init) ntp.seconds = report->GetNtpSec(); ntp.fractions = report->GetNtpFrac(); @@ -900,7 +900,7 @@ namespace RTC while (it != end) { - uint16_t shift = *it - seq - 1; + const uint16_t shift = *it - seq - 1; if (shift > 15) { diff --git a/worker/src/RTC/SctpAssociation.cpp b/worker/src/RTC/SctpAssociation.cpp index b83c740a69..e9734684ea 100644 --- a/worker/src/RTC/SctpAssociation.cpp +++ b/worker/src/RTC/SctpAssociation.cpp @@ -115,29 +115,25 @@ namespace RTC size_t maxSctpMessageSize, size_t sctpSendBufferSize, bool isDataChannel) - : listener(listener), os(os), mis(mis), maxSctpMessageSize(maxSctpMessageSize), - sctpSendBufferSize(sctpSendBufferSize), isDataChannel(isDataChannel) + : id(DepUsrSCTP::GetNextSctpAssociationId()), listener(listener), os(os), mis(mis), + maxSctpMessageSize(maxSctpMessageSize), sctpSendBufferSize(sctpSendBufferSize), + isDataChannel(isDataChannel), socket(usrsctp_socket( + AF_CONN, + SOCK_STREAM, + IPPROTO_SCTP, + onRecvSctpData, + onSendSctpData, + SendBufferThreshold, + reinterpret_cast(this->id))) { MS_TRACE(); - // Get a id for this SctpAssociation. - this->id = DepUsrSCTP::GetNextSctpAssociationId(); - // Register ourselves in usrsctp. // NOTE: This must be done before calling usrsctp_bind(). usrsctp_register_address(reinterpret_cast(this->id)); int ret; - this->socket = usrsctp_socket( - AF_CONN, - SOCK_STREAM, - IPPROTO_SCTP, - onRecvSctpData, - onSendSctpData, - SendBufferThreshold, - reinterpret_cast(this->id)); - if (!this->socket) { usrsctp_deregister_address(reinterpret_cast(this->id)); @@ -161,7 +157,9 @@ namespace RTC // This ensures that the usrsctp close call deletes the association. This // prevents usrsctp from calling the global send callback with references to // this class as the address. - struct linger lingerOpt; // NOLINT(cppcoreguidelines-pro-type-member-init) + struct linger lingerOpt + { + }; // NOLINT(cppcoreguidelines-pro-type-member-init) lingerOpt.l_onoff = 1; lingerOpt.l_linger = 0; @@ -176,7 +174,9 @@ namespace RTC } // Set SCTP_ENABLE_STREAM_RESET. - struct sctp_assoc_value av; // NOLINT(cppcoreguidelines-pro-type-member-init) + struct sctp_assoc_value av + { + }; // NOLINT(cppcoreguidelines-pro-type-member-init) av.assoc_value = SCTP_ENABLE_RESET_STREAM_REQ | SCTP_ENABLE_RESET_ASSOC_REQ | SCTP_ENABLE_CHANGE_ASSOC_REQ; @@ -203,7 +203,9 @@ namespace RTC } // Enable events. - struct sctp_event event; // NOLINT(cppcoreguidelines-pro-type-member-init) + struct sctp_event event + { + }; // NOLINT(cppcoreguidelines-pro-type-member-init) std::memset(&event, 0, sizeof(event)); event.se_on = 1; @@ -223,7 +225,9 @@ namespace RTC } // Init message. - struct sctp_initmsg initmsg; // NOLINT(cppcoreguidelines-pro-type-member-init) + struct sctp_initmsg initmsg + { + }; // NOLINT(cppcoreguidelines-pro-type-member-init) std::memset(&initmsg, 0, sizeof(initmsg)); initmsg.sinit_num_ostreams = this->os; @@ -239,7 +243,9 @@ namespace RTC } // Server side. - struct sockaddr_conn sconn; // NOLINT(cppcoreguidelines-pro-type-member-init) + struct sockaddr_conn sconn + { + }; // NOLINT(cppcoreguidelines-pro-type-member-init) std::memset(&sconn, 0, sizeof(sconn)); sconn.sconn_family = AF_CONN; @@ -300,7 +306,9 @@ namespace RTC try { int ret; - struct sockaddr_conn rconn; // NOLINT(cppcoreguidelines-pro-type-member-init) + struct sockaddr_conn rconn + { + }; // NOLINT(cppcoreguidelines-pro-type-member-init) std::memset(&rconn, 0, sizeof(rconn)); rconn.sconn_family = AF_CONN; @@ -318,7 +326,7 @@ namespace RTC } // Disable MTU discovery. - sctp_paddrparams peerAddrParams; // NOLINT(cppcoreguidelines-pro-type-member-init) + sctp_paddrparams peerAddrParams{}; // NOLINT(cppcoreguidelines-pro-type-member-init) std::memset(&peerAddrParams, 0, sizeof(peerAddrParams)); std::memcpy(&peerAddrParams.spp_address, &rconn, sizeof(rconn)); @@ -370,7 +378,7 @@ namespace RTC this->isDataChannel); } - void SctpAssociation::ProcessSctpData(const uint8_t* data, size_t len) + void SctpAssociation::ProcessSctpData(const uint8_t* data, size_t len) const { MS_TRACE(); @@ -396,7 +404,9 @@ namespace RTC const auto& parameters = dataConsumer->GetSctpStreamParameters(); // Fill sctp_sendv_spa. - struct sctp_sendv_spa spa; // NOLINT(cppcoreguidelines-pro-type-member-init) + struct sctp_sendv_spa spa + { + }; // NOLINT(cppcoreguidelines-pro-type-member-init) std::memset(&spa, 0, sizeof(spa)); spa.sendv_flags = SCTP_SEND_SNDINFO_VALID; @@ -436,12 +446,12 @@ namespace RTC // via onSendSctpData. this->listener->OnSctpAssociationBufferedAmount(this, this->sctpBufferedAmount); - int ret = usrsctp_sendv( + const int ret = usrsctp_sendv( this->socket, msg, len, nullptr, 0, &spa, static_cast(sizeof(spa)), SCTP_SENDV_SPA, 0); if (ret < 0) { - bool sctpSendBufferFull = errno == EWOULDBLOCK || errno == EAGAIN; + const bool sctpSendBufferFull = errno == EWOULDBLOCK || errno == EAGAIN; // SCTP send buffer being full is legit, not an error. if (sctpSendBufferFull) @@ -535,7 +545,9 @@ namespace RTC } int ret; - struct sctp_assoc_value av; // NOLINT(cppcoreguidelines-pro-type-member-init) + struct sctp_assoc_value av + { + }; // NOLINT(cppcoreguidelines-pro-type-member-init) socklen_t len = sizeof(av); ret = usrsctp_getsockopt(this->socket, IPPROTO_SCTP, SCTP_RECONFIG_SUPPORTED, &av, &len); @@ -633,7 +645,9 @@ namespace RTC return; } - struct sctp_add_streams sas; // NOLINT(cppcoreguidelines-pro-type-member-init) + struct sctp_add_streams sas + { + }; // NOLINT(cppcoreguidelines-pro-type-member-init) std::memset(&sas, 0, sizeof(sas)); sas.sas_instrms = 0; @@ -641,7 +655,7 @@ namespace RTC MS_DEBUG_TAG(sctp, "adding %" PRIu16 " outgoing streams", additionalOs); - int ret = usrsctp_setsockopt( + const int ret = usrsctp_setsockopt( this->socket, IPPROTO_SCTP, SCTP_ADD_STREAMS, &sas, static_cast(sizeof(sas))); if (ret < 0) diff --git a/worker/src/RTC/SimulcastConsumer.cpp b/worker/src/RTC/SimulcastConsumer.cpp index c17c15dde4..66c7a75c23 100644 --- a/worker/src/RTC/SimulcastConsumer.cpp +++ b/worker/src/RTC/SimulcastConsumer.cpp @@ -1713,7 +1713,7 @@ namespace RTC } inline void SimulcastConsumer::OnRtpStreamScore( - RTC::RtpStream* /*rtpStream*/, uint8_t score, uint8_t /*previousScore*/) + RTC::RtpStream* /*rtpStream*/, uint8_t /*score*/, uint8_t /*previousScore*/) { MS_TRACE(); diff --git a/worker/src/RTC/StunPacket.cpp b/worker/src/RTC/StunPacket.cpp index e420871595..532de610a5 100644 --- a/worker/src/RTC/StunPacket.cpp +++ b/worker/src/RTC/StunPacket.cpp @@ -4,6 +4,7 @@ #include "RTC/StunPacket.hpp" #include "Logger.hpp" #include "Utils.hpp" +#include #include // std::snprintf() #include // std::memcmp(), std::memcpy() @@ -11,7 +12,7 @@ namespace RTC { /* Class variables. */ - const uint8_t StunPacket::magicCookie[] = { 0x21, 0x12, 0xA4, 0x42 }; + const uint8_t StunPacket::MagicCookie[] = { 0x21, 0x12, 0xA4, 0x42 }; /* Class methods. */ @@ -651,7 +652,7 @@ namespace RTC // Set length field. Utils::Byte::Set2Bytes(buffer, 2, static_cast(this->size) - 20); // Set magic cookie. - std::memcpy(buffer + 4, StunPacket::magicCookie, 4); + std::memcpy(buffer + 4, StunPacket::MagicCookie, 4); // Set TransactionId field. std::memcpy(buffer + 8, this->transactionId, 12); // Update the transaction ID pointer. @@ -724,17 +725,17 @@ namespace RTC attrValue + 2, &(reinterpret_cast(this->xorMappedAddress))->sin_port, 2); - attrValue[2] ^= StunPacket::magicCookie[0]; - attrValue[3] ^= StunPacket::magicCookie[1]; + attrValue[2] ^= StunPacket::MagicCookie[0]; + attrValue[3] ^= StunPacket::MagicCookie[1]; // Set address and XOR it. std::memcpy( attrValue + 4, &(reinterpret_cast(this->xorMappedAddress))->sin_addr.s_addr, 4); - attrValue[4] ^= StunPacket::magicCookie[0]; - attrValue[5] ^= StunPacket::magicCookie[1]; - attrValue[6] ^= StunPacket::magicCookie[2]; - attrValue[7] ^= StunPacket::magicCookie[3]; + attrValue[4] ^= StunPacket::MagicCookie[0]; + attrValue[5] ^= StunPacket::MagicCookie[1]; + attrValue[6] ^= StunPacket::MagicCookie[2]; + attrValue[7] ^= StunPacket::MagicCookie[3]; pos += 4 + 8; @@ -752,17 +753,17 @@ namespace RTC attrValue + 2, &(reinterpret_cast(this->xorMappedAddress))->sin6_port, 2); - attrValue[2] ^= StunPacket::magicCookie[0]; - attrValue[3] ^= StunPacket::magicCookie[1]; + attrValue[2] ^= StunPacket::MagicCookie[0]; + attrValue[3] ^= StunPacket::MagicCookie[1]; // Set address and XOR it. std::memcpy( attrValue + 4, &(reinterpret_cast(this->xorMappedAddress))->sin6_addr.s6_addr, 16); - attrValue[4] ^= StunPacket::magicCookie[0]; - attrValue[5] ^= StunPacket::magicCookie[1]; - attrValue[6] ^= StunPacket::magicCookie[2]; - attrValue[7] ^= StunPacket::magicCookie[3]; + attrValue[4] ^= StunPacket::MagicCookie[0]; + attrValue[5] ^= StunPacket::MagicCookie[1]; + attrValue[6] ^= StunPacket::MagicCookie[2]; + attrValue[7] ^= StunPacket::MagicCookie[3]; attrValue[8] ^= this->transactionId[0]; attrValue[9] ^= this->transactionId[1]; attrValue[10] ^= this->transactionId[2]; diff --git a/worker/src/RTC/Transport.cpp b/worker/src/RTC/Transport.cpp index 2d1da9e623..487343e29f 100644 --- a/worker/src/RTC/Transport.cpp +++ b/worker/src/RTC/Transport.cpp @@ -2320,7 +2320,7 @@ namespace RTC this->tccClient->SetDesiredBitrate(totalDesiredBitrate, forceBitrate); } - inline void Transport::EmitTraceEventProbationType(RTC::RtpPacket* packet) const + inline void Transport::EmitTraceEventProbationType(RTC::RtpPacket* /*packet*/) const { MS_TRACE(); @@ -2893,10 +2893,10 @@ namespace RTC // Pass the SCTP message to the corresponding DataProducer. try { - static std::vector EmptySubchannels; + static std::vector emptySubchannels; dataProducer->ReceiveMessage( - msg, len, ppid, EmptySubchannels, /*requiredSubchannel*/ std::nullopt); + msg, len, ppid, emptySubchannels, /*requiredSubchannel*/ std::nullopt); } catch (std::exception& error) { @@ -2936,7 +2936,7 @@ namespace RTC } inline void Transport::OnTransportCongestionControlClientSendRtpPacket( - RTC::TransportCongestionControlClient* tccClient, + RTC::TransportCongestionControlClient* /*tccClient*/, RTC::RtpPacket* packet, const webrtc::PacedPacketInfo& pacingInfo) { diff --git a/worker/src/RTC/WebRtcServer.cpp b/worker/src/RTC/WebRtcServer.cpp index 94801fe5a2..0a4c027d40 100644 --- a/worker/src/RTC/WebRtcServer.cpp +++ b/worker/src/RTC/WebRtcServer.cpp @@ -25,6 +25,30 @@ namespace RTC std::pow(2, 0) * (256 - IceComponent); } + /* Class methods. */ + + inline std::string WebRtcServer::GetLocalIceUsernameFragmentFromReceivedStunPacket( + RTC::StunPacket* packet) + { + MS_TRACE(); + + // Here we inspect the USERNAME attribute of a received STUN request and + // extract its remote usernameFragment (the one given to our IceServer as + // local usernameFragment) which is the first value in the attribute value + // before the ":" symbol. + + const auto& username = packet->GetUsername(); + const size_t colonPos = username.find(':'); + + // If no colon is found just return the whole USERNAME attribute anyway. + if (colonPos == std::string::npos) + { + return username; + } + + return username.substr(0, colonPos); + } + /* Instance methods. */ WebRtcServer::WebRtcServer( @@ -265,7 +289,7 @@ namespace RTC } } - const std::vector WebRtcServer::GetIceCandidates( + std::vector WebRtcServer::GetIceCandidates( bool enableUdp, bool enableTcp, bool preferUdp, bool preferTcp) const { MS_TRACE(); @@ -284,7 +308,7 @@ namespace RTC iceLocalPreference += 1000; } - uint32_t icePriority = generateIceCandidatePriority(iceLocalPreference); + const uint32_t icePriority = generateIceCandidatePriority(iceLocalPreference); if (item.announcedIp.empty()) { @@ -305,7 +329,7 @@ namespace RTC iceLocalPreference += 1000; } - uint32_t icePriority = generateIceCandidatePriority(iceLocalPreference); + const uint32_t icePriority = generateIceCandidatePriority(iceLocalPreference); if (item.announcedIp.empty()) { @@ -325,28 +349,6 @@ namespace RTC return iceCandidates; } - inline std::string WebRtcServer::GetLocalIceUsernameFragmentFromReceivedStunPacket( - RTC::StunPacket* packet) const - { - MS_TRACE(); - - // Here we inspect the USERNAME attribute of a received STUN request and - // extract its remote usernameFragment (the one given to our IceServer as - // local usernameFragment) which is the first value in the attribute value - // before the ":" symbol. - - const auto& username = packet->GetUsername(); - const size_t colonPos = username.find(':'); - - // If no colon is found just return the whole USERNAME attribute anyway. - if (colonPos == std::string::npos) - { - return username; - } - - return username.substr(0, colonPos); - } - inline void WebRtcServer::OnPacketReceived(RTC::TransportTuple* tuple, const uint8_t* data, size_t len) { MS_TRACE(); @@ -389,7 +391,7 @@ namespace RTC } // Otherwise try to match the local ICE username fragment. - auto key = GetLocalIceUsernameFragmentFromReceivedStunPacket(packet); + auto key = WebRtcServer::GetLocalIceUsernameFragmentFromReceivedStunPacket(packet); auto it2 = this->mapLocalIceUsernameFragmentWebRtcTransport.find(key); if (it2 == this->mapLocalIceUsernameFragmentWebRtcTransport.end()) @@ -463,7 +465,7 @@ namespace RTC } inline void WebRtcServer::OnWebRtcTransportLocalIceUsernameFragmentRemoved( - RTC::WebRtcTransport* webRtcTransport, const std::string& usernameFragment) + RTC::WebRtcTransport* /*webRtcTransport*/, const std::string& usernameFragment) { MS_TRACE(); @@ -491,7 +493,7 @@ namespace RTC } inline void WebRtcServer::OnWebRtcTransportTransportTupleRemoved( - RTC::WebRtcTransport* webRtcTransport, RTC::TransportTuple* tuple) + RTC::WebRtcTransport* /*webRtcTransport*/, RTC::TransportTuple* tuple) { MS_TRACE(); diff --git a/worker/src/RTC/WebRtcTransport.cpp b/worker/src/RTC/WebRtcTransport.cpp index 6eb1f9717d..a795fef798 100644 --- a/worker/src/RTC/WebRtcTransport.cpp +++ b/worker/src/RTC/WebRtcTransport.cpp @@ -86,7 +86,7 @@ namespace RTC this->udpSockets[udpSocket] = announcedIp; - if (announcedIp.size() == 0) + if (announcedIp.empty()) { this->iceCandidates.emplace_back(udpSocket, icePriority); } @@ -128,7 +128,7 @@ namespace RTC this->tcpServers[tcpServer] = announcedIp; - if (announcedIp.size() == 0) + if (announcedIp.empty()) { this->iceCandidates.emplace_back(tcpServer, icePriority); } @@ -341,7 +341,7 @@ namespace RTC // Add dtlsParameters.fingerprints. std::vector> fingerprints; - for (const auto& fingerprint : this->dtlsTransport->GetLocalFingerprints()) + for (const auto& fingerprint : RTC::DtlsTransport::GetLocalFingerprints()) { auto algorithm = DtlsTransport::AlgorithmToFbs(fingerprint.algorithm); const auto& value = fingerprint.value; diff --git a/worker/src/Settings.cpp b/worker/src/Settings.cpp index 655e1b2b1e..7aa0006d85 100644 --- a/worker/src/Settings.cpp +++ b/worker/src/Settings.cpp @@ -18,7 +18,7 @@ extern "C" /* Static. */ -static std::mutex globalSyncMutex; +static std::mutex GlobalSyncMutex; /* Class variables. */ @@ -69,7 +69,7 @@ void Settings::SetConfiguration(int argc, char* argv[]) /* Parse command line options. */ // getopt_long_only() is not thread-safe - std::lock_guard lock(globalSyncMutex); + const std::lock_guard lock(GlobalSyncMutex); optind = 1; // Set explicitly, otherwise subsequent runs will fail. opterr = 0; // Don't allow getopt to print error messages. diff --git a/worker/src/Utils/File.cpp b/worker/src/Utils/File.cpp index 196eddca7c..58155d0862 100644 --- a/worker/src/Utils/File.cpp +++ b/worker/src/Utils/File.cpp @@ -20,7 +20,9 @@ namespace Utils { MS_TRACE(); - struct stat fileStat; // NOLINT(cppcoreguidelines-pro-type-member-init) + struct stat fileStat + { + }; // NOLINT(cppcoreguidelines-pro-type-member-init) int err; // Ensure the given file exists. diff --git a/worker/src/Utils/IP.cpp b/worker/src/Utils/IP.cpp index 0ba2416fbf..349f141862 100644 --- a/worker/src/Utils/IP.cpp +++ b/worker/src/Utils/IP.cpp @@ -118,7 +118,7 @@ namespace Utils { MS_TRACE(); - sockaddr_storage addrStorage; + sockaddr_storage addrStorage{}; char ipBuffer[INET6_ADDRSTRLEN] = { 0 }; int err; diff --git a/worker/src/Worker.cpp b/worker/src/Worker.cpp index 04ccee6c31..faef45fbf3 100644 --- a/worker/src/Worker.cpp +++ b/worker/src/Worker.cpp @@ -50,7 +50,7 @@ Worker::Worker(::Channel::ChannelSocket* channel) : channel(channel) // Tell the Node process that we are running. this->shared->channelNotifier->Emit( - std::to_string(Logger::pid), FBS::Notification::Event::WORKER_RUNNING); + std::to_string(Logger::Pid), FBS::Notification::Event::WORKER_RUNNING); MS_DEBUG_DEV("starting libuv loop"); DepLibUV::RunLoop(); @@ -143,7 +143,7 @@ flatbuffers::Offset Worker::FillBuffer( return FBS::Worker::CreateDumpResponseDirect( builder, - Logger::pid, + Logger::Pid, &webRtcServerIds, &routerIds, channelMessageHandlers diff --git a/worker/src/handles/TcpConnectionHandle.cpp b/worker/src/handles/TcpConnectionHandle.cpp index 6a3799becd..96b475045a 100644 --- a/worker/src/handles/TcpConnectionHandle.cpp +++ b/worker/src/handles/TcpConnectionHandle.cpp @@ -74,11 +74,11 @@ inline static void onShutdown(uv_shutdown_t* req, int /*status*/) /* Instance methods. */ // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) -TcpConnectionHandle::TcpConnectionHandle(size_t bufferSize) : bufferSize(bufferSize) +TcpConnectionHandle::TcpConnectionHandle(size_t bufferSize) + : bufferSize(bufferSize), uvHandle(new uv_tcp_t) { MS_TRACE(); - this->uvHandle = new uv_tcp_t; this->uvHandle->data = static_cast(this); // NOTE: Don't allocate the buffer here. Instead wait for the first uv_alloc_cb(). @@ -187,7 +187,7 @@ void TcpConnectionHandle::Start() return; } - int err = uv_read_start( + const int err = uv_read_start( reinterpret_cast(this->uvHandle), static_cast(onAlloc), static_cast(onRead)); diff --git a/worker/src/handles/TcpServerHandle.cpp b/worker/src/handles/TcpServerHandle.cpp index fff1c9e3e2..217f0aee90 100644 --- a/worker/src/handles/TcpServerHandle.cpp +++ b/worker/src/handles/TcpServerHandle.cpp @@ -110,7 +110,8 @@ uint32_t TcpServerHandle::GetSendBufferSize() const MS_TRACE(); int size{ 0 }; - int err = uv_send_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(size)); + const int err = + uv_send_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(size)); if (err) { @@ -124,15 +125,15 @@ void TcpServerHandle::SetSendBufferSize(uint32_t size) { MS_TRACE(); - auto size_int = static_cast(size); + auto sizeInt = static_cast(size); - if (size_int <= 0) + if (sizeInt <= 0) { - MS_THROW_TYPE_ERROR("invalid size: %d", size_int); + MS_THROW_TYPE_ERROR("invalid size: %d", sizeInt); } - int err = - uv_send_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(size_int)); + const int err = + uv_send_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(sizeInt)); if (err) { @@ -145,7 +146,8 @@ uint32_t TcpServerHandle::GetRecvBufferSize() const MS_TRACE(); int size{ 0 }; - int err = uv_recv_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(size)); + const int err = + uv_recv_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(size)); if (err) { @@ -159,15 +161,15 @@ void TcpServerHandle::SetRecvBufferSize(uint32_t size) { MS_TRACE(); - auto size_int = static_cast(size); + auto sizeInt = static_cast(size); - if (size_int <= 0) + if (sizeInt <= 0) { - MS_THROW_TYPE_ERROR("invalid size: %d", size_int); + MS_THROW_TYPE_ERROR("invalid size: %d", sizeInt); } - int err = - uv_recv_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(size_int)); + const int err = + uv_recv_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(sizeInt)); if (err) { diff --git a/worker/src/handles/TimerHandle.cpp b/worker/src/handles/TimerHandle.cpp index 1b85ce929c..e40ae8efb1 100644 --- a/worker/src/handles/TimerHandle.cpp +++ b/worker/src/handles/TimerHandle.cpp @@ -20,11 +20,10 @@ inline static void onCloseTimer(uv_handle_t* handle) /* Instance methods. */ -TimerHandle::TimerHandle(Listener* listener) : listener(listener) +TimerHandle::TimerHandle(Listener* listener) : listener(listener), uvHandle(new uv_timer_t) { MS_TRACE(); - this->uvHandle = new uv_timer_t; this->uvHandle->data = static_cast(this); const int err = uv_timer_init(DepLibUV::GetLoop(), this->uvHandle); diff --git a/worker/src/handles/UdpSocketHandle.cpp b/worker/src/handles/UdpSocketHandle.cpp index 2f30180a0e..60a0041d66 100644 --- a/worker/src/handles/UdpSocketHandle.cpp +++ b/worker/src/handles/UdpSocketHandle.cpp @@ -243,7 +243,7 @@ void UdpSocketHandle::Send( buffer = uv_buf_init(reinterpret_cast(sendData->store), len); - int err = uv_udp_send( + const int err = uv_udp_send( &sendData->req, this->uvHandle, &buffer, 1, addr, static_cast(onSend)); if (err != 0) @@ -272,7 +272,8 @@ uint32_t UdpSocketHandle::GetSendBufferSize() const MS_TRACE(); int size{ 0 }; - int err = uv_send_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(size)); + const int err = + uv_send_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(size)); if (err) { @@ -286,15 +287,15 @@ void UdpSocketHandle::SetSendBufferSize(uint32_t size) { MS_TRACE(); - auto size_int = static_cast(size); + auto sizeInt = static_cast(size); - if (size_int <= 0) + if (sizeInt <= 0) { - MS_THROW_TYPE_ERROR("invalid size: %d", size_int); + MS_THROW_TYPE_ERROR("invalid size: %d", sizeInt); } - int err = - uv_send_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(size_int)); + const int err = + uv_send_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(sizeInt)); if (err) { @@ -307,7 +308,8 @@ uint32_t UdpSocketHandle::GetRecvBufferSize() const MS_TRACE(); int size{ 0 }; - int err = uv_recv_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(size)); + const int err = + uv_recv_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(size)); if (err) { @@ -321,15 +323,15 @@ void UdpSocketHandle::SetRecvBufferSize(uint32_t size) { MS_TRACE(); - auto size_int = static_cast(size); + auto sizeInt = static_cast(size); - if (size_int <= 0) + if (sizeInt <= 0) { - MS_THROW_TYPE_ERROR("invalid size: %d", size_int); + MS_THROW_TYPE_ERROR("invalid size: %d", sizeInt); } - int err = - uv_recv_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(size_int)); + const int err = + uv_recv_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(sizeInt)); if (err) { diff --git a/worker/src/handles/UnixStreamSocketHandle.cpp b/worker/src/handles/UnixStreamSocketHandle.cpp index 15afe5ead8..bf024d1d8e 100644 --- a/worker/src/handles/UnixStreamSocketHandle.cpp +++ b/worker/src/handles/UnixStreamSocketHandle.cpp @@ -76,13 +76,12 @@ inline static void onShutdown(uv_shutdown_t* req, int /*status*/) UnixStreamSocketHandle::UnixStreamSocketHandle( int fd, size_t bufferSize, UnixStreamSocketHandle::Role role) - : bufferSize(bufferSize), role(role) + : uvHandle(new uv_pipe_t), bufferSize(bufferSize), role(role) { MS_TRACE_STD(); int err; - this->uvHandle = new uv_pipe_t; this->uvHandle->data = static_cast(this); err = uv_pipe_init(DepLibUV::GetLoop(), this->uvHandle, 0); @@ -252,7 +251,8 @@ uint32_t UnixStreamSocketHandle::GetSendBufferSize() const MS_TRACE(); int size{ 0 }; - int err = uv_send_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(size)); + const int err = + uv_send_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(size)); if (err) { @@ -266,15 +266,15 @@ void UnixStreamSocketHandle::SetSendBufferSize(uint32_t size) { MS_TRACE(); - auto size_int = static_cast(size); + auto sizeInt = static_cast(size); - if (size_int <= 0) + if (sizeInt <= 0) { - MS_THROW_TYPE_ERROR_STD("invalid size: %d", size_int); + MS_THROW_TYPE_ERROR_STD("invalid size: %d", sizeInt); } - int err = - uv_send_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(size_int)); + const int err = + uv_send_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(sizeInt)); if (err) { @@ -287,7 +287,8 @@ uint32_t UnixStreamSocketHandle::GetRecvBufferSize() const MS_TRACE(); int size{ 0 }; - int err = uv_recv_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(size)); + const int err = + uv_recv_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(size)); if (err) { @@ -301,15 +302,15 @@ void UnixStreamSocketHandle::SetRecvBufferSize(uint32_t size) { MS_TRACE(); - auto size_int = static_cast(size); + auto sizeInt = static_cast(size); - if (size_int <= 0) + if (sizeInt <= 0) { - MS_THROW_TYPE_ERROR_STD("invalid size: %d", size_int); + MS_THROW_TYPE_ERROR_STD("invalid size: %d", sizeInt); } - int err = - uv_recv_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(size_int)); + const int err = + uv_recv_buffer_size(reinterpret_cast(this->uvHandle), std::addressof(sizeInt)); if (err) { diff --git a/worker/src/lib.cpp b/worker/src/lib.cpp index 7d427db63d..8ea2572b6a 100644 --- a/worker/src/lib.cpp +++ b/worker/src/lib.cpp @@ -26,14 +26,15 @@ void IgnoreSignals(); +// NOLINTNEXTLINE extern "C" int mediasoup_worker_run( int argc, char* argv[], const char* version, int consumerChannelFd, int producerChannelFd, - int payloadConsumeChannelFd, - int payloadProduceChannelFd, + int /*payloadConsumeChannelFd*/, + int /*payloadProduceChannelFd*/, ChannelReadFn channelReadFn, ChannelReadCtx channelReadCtx, ChannelWriteFn channelWriteFn, @@ -141,7 +142,7 @@ extern "C" int mediasoup_worker_run( #endif // Run the Worker. - Worker worker(channel.get()); + const Worker worker(channel.get()); // Free static stuff. DepLibSRTP::ClassDestroy(); @@ -177,10 +178,12 @@ void IgnoreSignals() MS_TRACE(); int err; - struct sigaction act; // NOLINT(cppcoreguidelines-pro-type-member-init) + struct sigaction act + { + }; // NOLINT(cppcoreguidelines-pro-type-member-init) // clang-format off - absl::flat_hash_map ignoredSignals = + absl::flat_hash_map const ignoredSignals = { { "PIPE", SIGPIPE }, { "HUP", SIGHUP }, @@ -199,10 +202,10 @@ void IgnoreSignals() MS_THROW_ERROR("sigfillset() failed: %s", std::strerror(errno)); } - for (auto& kv : ignoredSignals) + for (const auto& kv : ignoredSignals) { const auto& sigName = kv.first; - int sigId = kv.second; + const int sigId = kv.second; err = sigaction(sigId, &act, nullptr); From bd5b634bf0afb3106b085537ece227abb124021f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Mon, 8 Jan 2024 12:07:19 +0100 Subject: [PATCH 2/5] remove unneeded include --- worker/src/RTC/StunPacket.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/worker/src/RTC/StunPacket.cpp b/worker/src/RTC/StunPacket.cpp index 532de610a5..518ca8ff97 100644 --- a/worker/src/RTC/StunPacket.cpp +++ b/worker/src/RTC/StunPacket.cpp @@ -4,7 +4,6 @@ #include "RTC/StunPacket.hpp" #include "Logger.hpp" #include "Utils.hpp" -#include #include // std::snprintf() #include // std::memcmp(), std::memcpy() From be8bcec38b867e530d1ad04c99c892d471c4f185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Mon, 8 Jan 2024 12:13:46 +0100 Subject: [PATCH 3/5] remove const --- worker/src/handles/TcpConnectionHandle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/worker/src/handles/TcpConnectionHandle.cpp b/worker/src/handles/TcpConnectionHandle.cpp index 96b475045a..a35c7f9b79 100644 --- a/worker/src/handles/TcpConnectionHandle.cpp +++ b/worker/src/handles/TcpConnectionHandle.cpp @@ -187,7 +187,7 @@ void TcpConnectionHandle::Start() return; } - const int err = uv_read_start( + int err = uv_read_start( reinterpret_cast(this->uvHandle), static_cast(onAlloc), static_cast(onRead)); From 46a006d29c44fbb1405c2ce0b88c9f1eae901f7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Mon, 8 Jan 2024 12:19:05 +0100 Subject: [PATCH 4/5] remove unneeded NOLINT directives --- worker/include/RTC/PipeTransport.hpp | 2 +- worker/include/RTC/PlainTransport.hpp | 4 ++-- worker/include/RTC/TransportTuple.hpp | 2 +- worker/include/handles/TcpConnectionHandle.hpp | 2 +- worker/include/handles/TcpServerHandle.hpp | 2 +- worker/include/handles/UdpSocketHandle.hpp | 2 +- worker/src/RTC/PortManager.cpp | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/worker/include/RTC/PipeTransport.hpp b/worker/include/RTC/PipeTransport.hpp index 21b3722c9a..3a5a38fd93 100644 --- a/worker/include/RTC/PipeTransport.hpp +++ b/worker/include/RTC/PipeTransport.hpp @@ -77,7 +77,7 @@ namespace RTC ListenInfo listenInfo; struct sockaddr_storage remoteAddrStorage { - }; // NOLINT + }; bool rtx{ false }; std::string srtpKey; std::string srtpKeyBase64; diff --git a/worker/include/RTC/PlainTransport.hpp b/worker/include/RTC/PlainTransport.hpp index ed8fb54352..2c7b5c20d3 100644 --- a/worker/include/RTC/PlainTransport.hpp +++ b/worker/include/RTC/PlainTransport.hpp @@ -78,10 +78,10 @@ namespace RTC bool comedia{ false }; struct sockaddr_storage remoteAddrStorage { - }; // NOLINT + }; struct sockaddr_storage rtcpRemoteAddrStorage { - }; // NOLINT + }; RTC::SrtpSession::CryptoSuite srtpCryptoSuite{ RTC::SrtpSession::CryptoSuite::AES_CM_128_HMAC_SHA1_80 }; diff --git a/worker/include/RTC/TransportTuple.hpp b/worker/include/RTC/TransportTuple.hpp index cfdaa69e36..d23545051a 100644 --- a/worker/include/RTC/TransportTuple.hpp +++ b/worker/include/RTC/TransportTuple.hpp @@ -247,7 +247,7 @@ namespace RTC // Others. struct sockaddr_storage udpRemoteAddrStorage { - }; // NOLINT + }; Protocol protocol; }; } // namespace RTC diff --git a/worker/include/handles/TcpConnectionHandle.hpp b/worker/include/handles/TcpConnectionHandle.hpp index d6ec543ce1..073602d305 100644 --- a/worker/include/handles/TcpConnectionHandle.hpp +++ b/worker/include/handles/TcpConnectionHandle.hpp @@ -133,7 +133,7 @@ class TcpConnectionHandle uint16_t localPort{ 0u }; struct sockaddr_storage peerAddr { - }; // NOLINT + }; std::string peerIp; uint16_t peerPort{ 0u }; diff --git a/worker/include/handles/TcpServerHandle.hpp b/worker/include/handles/TcpServerHandle.hpp index 4d1b572525..6d0fa9d1f9 100644 --- a/worker/include/handles/TcpServerHandle.hpp +++ b/worker/include/handles/TcpServerHandle.hpp @@ -66,7 +66,7 @@ class TcpServerHandle : public TcpConnectionHandle::Listener protected: struct sockaddr_storage localAddr { - }; // NOLINT + }; std::string localIp; uint16_t localPort{ 0u }; diff --git a/worker/include/handles/UdpSocketHandle.hpp b/worker/include/handles/UdpSocketHandle.hpp index f5762cdd60..2b7a708105 100644 --- a/worker/include/handles/UdpSocketHandle.hpp +++ b/worker/include/handles/UdpSocketHandle.hpp @@ -96,7 +96,7 @@ class UdpSocketHandle protected: struct sockaddr_storage localAddr { - }; // NOLINT + }; std::string localIp; uint16_t localPort{ 0u }; diff --git a/worker/src/RTC/PortManager.cpp b/worker/src/RTC/PortManager.cpp index 69019dacf9..a2247bf256 100644 --- a/worker/src/RTC/PortManager.cpp +++ b/worker/src/RTC/PortManager.cpp @@ -49,7 +49,7 @@ namespace RTC const int family = Utils::IP::GetFamily(ip); struct sockaddr_storage bindAddr { - }; // NOLINT + }; size_t portIdx; std::vector& ports = PortManager::GetPorts(transport, ip); size_t attempt{ 0u }; @@ -379,7 +379,7 @@ namespace RTC const int family = Utils::IP::GetFamily(ip); struct sockaddr_storage bindAddr { - }; // NOLINT + }; uv_handle_t* uvHandle{ nullptr }; std::string transportStr; const uint8_t bitFlags = ConvertSocketFlags(flags, transport, family); From e4fac98b8f0f2d5fcb77a26ace6295b97da74a49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Luis=20Mill=C3=A1n?= Date: Mon, 8 Jan 2024 12:23:48 +0100 Subject: [PATCH 5/5] SctpAssociation: initialize socket in constructor body --- worker/src/RTC/SctpAssociation.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/worker/src/RTC/SctpAssociation.cpp b/worker/src/RTC/SctpAssociation.cpp index e9734684ea..2c2da971f1 100644 --- a/worker/src/RTC/SctpAssociation.cpp +++ b/worker/src/RTC/SctpAssociation.cpp @@ -117,14 +117,7 @@ namespace RTC bool isDataChannel) : id(DepUsrSCTP::GetNextSctpAssociationId()), listener(listener), os(os), mis(mis), maxSctpMessageSize(maxSctpMessageSize), sctpSendBufferSize(sctpSendBufferSize), - isDataChannel(isDataChannel), socket(usrsctp_socket( - AF_CONN, - SOCK_STREAM, - IPPROTO_SCTP, - onRecvSctpData, - onSendSctpData, - SendBufferThreshold, - reinterpret_cast(this->id))) + isDataChannel(isDataChannel) { MS_TRACE(); @@ -134,6 +127,15 @@ namespace RTC int ret; + this->socket = usrsctp_socket( + AF_CONN, + SOCK_STREAM, + IPPROTO_SCTP, + onRecvSctpData, + onSendSctpData, + SendBufferThreshold, + reinterpret_cast(this->id)); + if (!this->socket) { usrsctp_deregister_address(reinterpret_cast(this->id));