Unverified 提交 6a573c26 authored 作者: José Luis Millán's avatar José Luis Millán 提交者: GitHub

C++: tidy up (#1304)

C++: tidy up
上级 bca9b0d7
......@@ -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
......
......@@ -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:
......
......@@ -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 @@ public:
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 @@ public:
#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 @@ public:
{ \
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<uint32_t>(loggerWritten)); \
} \
} \
......@@ -204,7 +208,7 @@ public:
{ \
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<uint32_t>(loggerWritten)); \
} \
} \
......@@ -226,7 +230,7 @@ public:
{ \
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<uint32_t>(loggerWritten)); \
} \
} \
......@@ -248,7 +252,7 @@ public:
{ \
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<uint32_t>(loggerWritten)); \
} \
} \
......@@ -270,7 +274,7 @@ public:
{ \
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<uint32_t>(loggerWritten)); \
} \
} \
......@@ -291,7 +295,7 @@ public:
#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<uint32_t>(loggerWritten)); \
} \
while (false)
......@@ -313,7 +317,7 @@ public:
#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<uint32_t>(loggerWritten)); \
} \
while (false)
......@@ -333,7 +337,7 @@ public:
#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<uint32_t>(loggerWritten)); \
} \
while (false)
......@@ -349,7 +353,7 @@ public:
#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<uint32_t>(loggerWritten)); \
size_t bufferDataLen{ 0 }; \
for (size_t i{0}; i < len; ++i) \
......@@ -361,10 +365,10 @@ public:
Logger::channel->SendLog(Logger::buffer, static_cast<uint32_t>(bufferDataLen)); \
bufferDataLen = 0; \
} \
const int loggerWritten = std::snprintf(Logger::buffer + bufferDataLen, Logger::bufferSize, "X%06X ", static_cast<unsigned int>(i)); \
const int loggerWritten = std::snprintf(Logger::buffer + bufferDataLen, Logger::BufferSize, "X%06X ", static_cast<unsigned int>(i)); \
bufferDataLen += loggerWritten; \
} \
const int loggerWritten = std::snprintf(Logger::buffer + bufferDataLen, Logger::bufferSize, "%02X ", static_cast<unsigned char>(data[i])); \
const int loggerWritten = std::snprintf(Logger::buffer + bufferDataLen, Logger::BufferSize, "%02X ", static_cast<unsigned char>(data[i])); \
bufferDataLen += loggerWritten; \
} \
if (bufferDataLen != 0) \
......@@ -389,10 +393,10 @@ public:
std::fprintf(stdout, "%s", Logger::buffer); \
bufferDataLen = 0; \
} \
const int loggerWritten = std::snprintf(Logger::buffer + bufferDataLen, Logger::bufferSize, "\n%06X ", static_cast<unsigned int>(i)); \
const int loggerWritten = std::snprintf(Logger::buffer + bufferDataLen, Logger::BufferSize, "\n%06X ", static_cast<unsigned int>(i)); \
bufferDataLen += loggerWritten; \
} \
const int loggerWritten = std::snprintf(Logger::buffer + bufferDataLen, Logger::bufferSize, "%02X ", static_cast<unsigned char>(data[i])); \
const int loggerWritten = std::snprintf(Logger::buffer + bufferDataLen, Logger::BufferSize, "%02X ", static_cast<unsigned char>(data[i])); \
bufferDataLen += loggerWritten; \
} \
if (bufferDataLen != 0) \
......@@ -409,7 +413,7 @@ public:
{ \
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<uint32_t>(loggerWritten)); \
} \
} \
......
......@@ -13,7 +13,7 @@ public:
}
public:
static const size_t bufferSize{ 2000 };
static const size_t BufferSize{ 2000 };
thread_local static char buffer[];
};
......@@ -30,7 +30,7 @@ public:
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 @@ public:
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 @@ public:
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 @@ public:
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
......
......@@ -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 };
......
......@@ -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<FBS::Consumer::BaseConsumerDump> FillBuffer(
......@@ -74,7 +74,7 @@ namespace RTC
virtual flatbuffers::Offset<FBS::Consumer::GetStatsResponse> FillBufferStats(
flatbuffers::FlatBufferBuilder& builder) = 0;
virtual flatbuffers::Offset<FBS::Consumer::ConsumerScore> FillBufferScore(
flatbuffers::FlatBufferBuilder& builder) const
flatbuffers::FlatBufferBuilder& /*builder*/) const
{
return 0;
};
......
......@@ -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<FBS::DataConsumer::DumpResponse> FillBuffer(
......@@ -104,7 +104,7 @@ namespace RTC
uint32_t ppid,
std::vector<uint16_t>& subchannels,
std::optional<uint16_t> requiredSubchannel,
onQueuedCallback* = nullptr);
onQueuedCallback* cb = nullptr);
/* Methods inherited from Channel::ChannelSocket::RequestHandler. */
public:
......
......@@ -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<FBS::DataProducer::DumpResponse> FillBuffer(
......
......@@ -112,6 +112,10 @@ namespace RTC
);
// clang-format on
}
static std::vector<Fingerprint>& GetLocalFingerprints()
{
return DtlsTransport::localFingerprints;
}
private:
static void GenerateCertificateAndPrivateKey();
......@@ -137,10 +141,6 @@ namespace RTC
public:
void Dump() const;
void Run(Role localRole);
std::vector<Fingerprint>& GetLocalFingerprints() const
{
return DtlsTransport::localFingerprints;
}
bool SetRemoteFingerprint(const Fingerprint& fingerprint);
void ProcessDtlsData(const uint8_t* data, size_t len);
DtlsState GetState() const
......
......@@ -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())
{
}
......
......@@ -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);
......
......@@ -75,7 +75,9 @@ namespace RTC
RTC::SrtpSession* srtpSendSession{ nullptr };
// Others.
ListenInfo listenInfo;
struct sockaddr_storage remoteAddrStorage;
struct sockaddr_storage remoteAddrStorage
{
};
bool rtx{ false };
std::string srtpKey;
std::string srtpKeyBase64;
......
......@@ -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
{
};
struct sockaddr_storage rtcpRemoteAddrStorage
{
};
RTC::SrtpSession::CryptoSuite srtpCryptoSuite{
RTC::SrtpSession::CryptoSuite::AES_CM_128_HMAC_SHA1_80
};
......
......@@ -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<FBS::Producer::DumpResponse> FillBuffer(
......
......@@ -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.
{
......
......@@ -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)
......
......@@ -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<FBS::Router::DumpResponse> 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;
......
......@@ -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
......
......@@ -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();
......
......@@ -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<OneByteExtension*, 14> oneByteExtensions;
std::array<OneByteExtension*, 14> oneByteExtensions{};
absl::flat_hash_map<uint8_t, TwoBytesExtension*> mapTwoBytesExtensions;
uint8_t midExtensionId{ 0u };
uint8_t ridExtensionId{ 0u };
......
......@@ -32,6 +32,10 @@ namespace RTC
uint8_t sentTimes{ 0u };
};
private:
static Item* FillItem(
Item* item, RTC::RtpPacket* packet, std::shared_ptr<RTC::RtpPacket>& 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<RTC::RtpPacket>& sharedPacket) const;
protected:
// Make buffer protected for testing purposes.
......
......@@ -47,7 +47,7 @@ namespace RTC
RTC::RtpStream::Params& params,
unsigned int sendNackDelayMs,
bool useRtpInactivityCheck);
~RtpStreamRecv();
~RtpStreamRecv() override;
flatbuffers::Offset<FBS::RtpStream::Stats> FillBufferStats(
flatbuffers::FlatBufferBuilder& builder) override;
......
......@@ -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. */
......
......@@ -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
{
......
......@@ -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. */
......
......@@ -58,7 +58,7 @@ namespace RTC
uint32_t initialAvailableBitrate,
uint32_t maxOutgoingBitrate,
uint32_t minOutgoingBitrate);
virtual ~TransportCongestionControlClient();
~TransportCongestionControlClient() override;
public:
RTC::BweType GetBweType() const
......
......@@ -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
......
......@@ -245,7 +245,9 @@ namespace RTC
RTC::TcpConnection* tcpConnection{ nullptr };
std::string localAnnouncedIp;
// Others.
struct sockaddr_storage udpRemoteAddrStorage;
struct sockaddr_storage udpRemoteAddrStorage
{
};
Protocol protocol;
};
} // namespace RTC
......
......@@ -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
......
......@@ -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<flatbuffers::Offset<FBS::Transport::ListenInfo>>* listenInfos);
~WebRtcServer();
~WebRtcServer() override;
public:
flatbuffers::Offset<FBS::WebRtcServer::DumpResponse> FillBuffer(
flatbuffers::FlatBufferBuilder& builder) const;
const std::vector<RTC::IceCandidate> GetIceCandidates(
std::vector<RTC::IceCandidate> 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);
......
......@@ -24,9 +24,8 @@ public:
/* 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 @@ public:
delete this->cb;
}
uv_write_t req;
uv_write_t req{};
uint8_t* store{ nullptr };
TcpConnectionHandle::onSendCallback* cb{ nullptr };
};
......@@ -132,7 +131,9 @@ protected:
size_t bufferDataLen{ 0u };
std::string localIp;
uint16_t localPort{ 0u };
struct sockaddr_storage peerAddr;
struct sockaddr_storage peerAddr
{
};
std::string peerIp;
uint16_t peerPort{ 0u };
......
......@@ -13,8 +13,8 @@ public:
/**
* 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 @@ public:
void OnTcpConnectionClosed(TcpConnectionHandle* connection) override;
protected:
struct sockaddr_storage localAddr;
struct sockaddr_storage localAddr
{
};
std::string localIp;
uint16_t localPort{ 0u };
......
......@@ -14,9 +14,8 @@ public:
/* 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 @@ public:
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 @@ protected:
const uint8_t* data, size_t len, const struct sockaddr* addr) = 0;
protected:
struct sockaddr_storage localAddr;
struct sockaddr_storage localAddr
{
};
std::string localIp;
uint16_t localPort{ 0u };
......
......@@ -11,9 +11,8 @@ public:
/* 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 @@ public:
delete[] this->store;
}
uv_write_t req;
uv_write_t req{};
uint8_t* store{ nullptr };
};
......
......@@ -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<void*>(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<const uint8_t*>(message), messageLen);
SendImpl(reinterpret_cast<const uint8_t*>(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))
{
......
......@@ -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<const char*> DepLibSRTP::errors =
......@@ -50,9 +50,9 @@ void DepLibSRTP::ClassInit()
MS_TRACE();
{
std::lock_guard<std::mutex> lock(globalSyncMutex);
const std::lock_guard<std::mutex> 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<std::mutex> lock(globalSyncMutex);
--globalInstances;
const std::lock_guard<std::mutex> lock(GlobalSyncMutex);
--GlobalInstances;
if (globalInstances == 0)
if (GlobalInstances == 0)
{
srtp_shutdown();
}
......
......@@ -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(
......
......@@ -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));
......
......@@ -69,7 +69,7 @@ void DepUsrSCTP::ClassInit()
MS_DEBUG_TAG(info, "usrsctp");
std::lock_guard<std::mutex> lock(GlobalSyncMutex);
const std::lock_guard<std::mutex> lock(GlobalSyncMutex);
if (GlobalInstances == 0)
{
......@@ -90,7 +90,7 @@ void DepUsrSCTP::ClassDestroy()
{
MS_TRACE();
std::lock_guard<std::mutex> lock(GlobalSyncMutex);
const std::lock_guard<std::mutex> lock(GlobalSyncMutex);
--GlobalInstances;
if (GlobalInstances == 0)
......@@ -126,7 +126,7 @@ uintptr_t DepUsrSCTP::GetNextSctpAssociationId()
{
MS_TRACE();
std::lock_guard<std::mutex> lock(GlobalSyncMutex);
const std::lock_guard<std::mutex> 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<std::mutex> lock(GlobalSyncMutex);
const std::lock_guard<std::mutex> 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<std::mutex> lock(GlobalSyncMutex);
const std::lock_guard<std::mutex> 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<std::mutex> lock(GlobalSyncMutex);
const std::lock_guard<std::mutex> 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()
......
......@@ -6,9 +6,9 @@
/* Class variables. */
const uint64_t Logger::pid{ static_cast<uint64_t>(uv_os_getpid()) };
const uint64_t Logger::Pid{ static_cast<uint64_t>(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. */
......
......@@ -2,4 +2,4 @@
#include "MediaSoupErrors.hpp"
thread_local char MediaSoupError::buffer[MediaSoupError::bufferSize];
thread_local char MediaSoupError::buffer[MediaSoupError::BufferSize];
......@@ -67,8 +67,8 @@ namespace RTC
inline bool ComputeBigs(
const std::vector<uint8_t>& littles, std::vector<uint8_t>& 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<uint32_t>(elapsed / 20), 1U), LevelsBuffLen);
for (uint32_t i{ 0u }; i < intervalsUpdated; ++i)
......
......@@ -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());
......
......@@ -280,7 +280,7 @@ namespace RTC
const auto* body = request->data->body_as<FBS::DataConsumer::SendRequest>();
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<uint16_t> EmptySubchannels;
static std::vector<uint16_t> 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 };
......
......@@ -202,7 +202,7 @@ namespace RTC
{
const auto* body = notification->data->body_as<FBS::DataProducer::SendNotification>();
const uint8_t* data = body->data()->Data();
size_t len = body->data()->size();
const size_t len = body->data()->size();
if (len > this->maxMessageSize)
{
......
......@@ -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();
......
......@@ -71,14 +71,13 @@ inline static long onSslBioOut(
int ret,
size_t* /*processed*/)
{
long resultOfcallback = (operationType == BIO_CB_RETURN) ? static_cast<long>(ret) : 1;
const long resultOfcallback = (operationType == BIO_CB_RETURN) ? static_cast<long>(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<RTC::DtlsTransport*>(BIO_get_callback_arg(bio));
auto* dtlsTransport = reinterpret_cast<RTC::DtlsTransport*>(BIO_get_callback_arg(bio));
dtlsTransport->SendDtlsData(reinterpret_cast<const uint8_t*>(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");
......
......@@ -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);
}
......
......@@ -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<uint16_t> nackBatch = GetNackBatch(NackFilter::SEQ);
const std::vector<uint16_t> 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<uint16_t> nackBatch = GetNackBatch(NackFilter::TIME);
const std::vector<uint16_t> nackBatch = GetNackBatch(NackFilter::TIME);
if (!nackBatch.empty())
{
......
......@@ -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
{
};
size_t portIdx;
std::vector<bool>& 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
{
};
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)
{
......
......@@ -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());
......
......@@ -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()
......
......@@ -7,6 +7,37 @@
namespace RTC
{
/* Class methods. */
RtpRetransmissionBuffer::Item* RtpRetransmissionBuffer::FillItem(
RtpRetransmissionBuffer::Item* item,
RTC::RtpPacket* packet,
std::shared_ptr<RTC::RtpPacket>& 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("<RtpRetransmissionBuffer>");
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<uint32_t>(diffTs * 1000 / this->clockRate) > this->maxRetransmissionDelayMs;
}
RtpRetransmissionBuffer::Item* RtpRetransmissionBuffer::FillItem(
RtpRetransmissionBuffer::Item* item,
RTC::RtpPacket* packet,
std::shared_ptr<RTC::RtpPacket>& 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();
......
......@@ -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)
{
......
......@@ -115,14 +115,12 @@ 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)
{
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<void*>(this->id));
......@@ -161,7 +159,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 +176,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 +205,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 +227,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 +245,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 +308,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 +328,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 +380,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 +406,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 +448,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<socklen_t>(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 +547,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 +647,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 +657,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<socklen_t>(sizeof(sas)));
if (ret < 0)
......
......@@ -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();
......
......@@ -11,7 +11,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 +651,7 @@ namespace RTC
// Set length field.
Utils::Byte::Set2Bytes(buffer, 2, static_cast<uint16_t>(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 +724,17 @@ namespace RTC
attrValue + 2,
&(reinterpret_cast<const sockaddr_in*>(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<const sockaddr_in*>(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 +752,17 @@ namespace RTC
attrValue + 2,
&(reinterpret_cast<const sockaddr_in6*>(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<const sockaddr_in6*>(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];
......
......@@ -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<uint16_t> EmptySubchannels;
static std::vector<uint16_t> 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)
{
......
......@@ -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<RTC::IceCandidate> WebRtcServer::GetIceCandidates(
std::vector<RTC::IceCandidate> 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();
......
......@@ -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<flatbuffers::Offset<FBS::WebRtcTransport::Fingerprint>> 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;
......
......@@ -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<std::mutex> lock(globalSyncMutex);
const std::lock_guard<std::mutex> lock(GlobalSyncMutex);
optind = 1; // Set explicitly, otherwise subsequent runs will fail.
opterr = 0; // Don't allow getopt to print error messages.
......
......@@ -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.
......
......@@ -118,7 +118,7 @@ namespace Utils
{
MS_TRACE();
sockaddr_storage addrStorage;
sockaddr_storage addrStorage{};
char ipBuffer[INET6_ADDRSTRLEN] = { 0 };
int err;
......
......@@ -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<FBS::Worker::DumpResponse> Worker::FillBuffer(
return FBS::Worker::CreateDumpResponseDirect(
builder,
Logger::pid,
Logger::Pid,
&webRtcServerIds,
&routerIds,
channelMessageHandlers
......
......@@ -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<void*>(this);
// NOTE: Don't allocate the buffer here. Instead wait for the first uv_alloc_cb().
......
......@@ -110,7 +110,8 @@ uint32_t TcpServerHandle::GetSendBufferSize() const
MS_TRACE();
int size{ 0 };
int err = uv_send_buffer_size(reinterpret_cast<uv_handle_t*>(this->uvHandle), std::addressof(size));
const int err =
uv_send_buffer_size(reinterpret_cast<uv_handle_t*>(this->uvHandle), std::addressof(size));
if (err)
{
......@@ -124,15 +125,15 @@ void TcpServerHandle::SetSendBufferSize(uint32_t size)
{
MS_TRACE();
auto size_int = static_cast<int>(size);
auto sizeInt = static_cast<int>(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<uv_handle_t*>(this->uvHandle), std::addressof(size_int));
const int err =
uv_send_buffer_size(reinterpret_cast<uv_handle_t*>(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<uv_handle_t*>(this->uvHandle), std::addressof(size));
const int err =
uv_recv_buffer_size(reinterpret_cast<uv_handle_t*>(this->uvHandle), std::addressof(size));
if (err)
{
......@@ -159,15 +161,15 @@ void TcpServerHandle::SetRecvBufferSize(uint32_t size)
{
MS_TRACE();
auto size_int = static_cast<int>(size);
auto sizeInt = static_cast<int>(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<uv_handle_t*>(this->uvHandle), std::addressof(size_int));
const int err =
uv_recv_buffer_size(reinterpret_cast<uv_handle_t*>(this->uvHandle), std::addressof(sizeInt));
if (err)
{
......
......@@ -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<void*>(this);
const int err = uv_timer_init(DepLibUV::GetLoop(), this->uvHandle);
......
......@@ -243,7 +243,7 @@ send_libuv:
buffer = uv_buf_init(reinterpret_cast<char*>(sendData->store), len);
int err = uv_udp_send(
const int err = uv_udp_send(
&sendData->req, this->uvHandle, &buffer, 1, addr, static_cast<uv_udp_send_cb>(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<uv_handle_t*>(this->uvHandle), std::addressof(size));
const int err =
uv_send_buffer_size(reinterpret_cast<uv_handle_t*>(this->uvHandle), std::addressof(size));
if (err)
{
......@@ -286,15 +287,15 @@ void UdpSocketHandle::SetSendBufferSize(uint32_t size)
{
MS_TRACE();
auto size_int = static_cast<int>(size);
auto sizeInt = static_cast<int>(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<uv_handle_t*>(this->uvHandle), std::addressof(size_int));
const int err =
uv_send_buffer_size(reinterpret_cast<uv_handle_t*>(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<uv_handle_t*>(this->uvHandle), std::addressof(size));
const int err =
uv_recv_buffer_size(reinterpret_cast<uv_handle_t*>(this->uvHandle), std::addressof(size));
if (err)
{
......@@ -321,15 +323,15 @@ void UdpSocketHandle::SetRecvBufferSize(uint32_t size)
{
MS_TRACE();
auto size_int = static_cast<int>(size);
auto sizeInt = static_cast<int>(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<uv_handle_t*>(this->uvHandle), std::addressof(size_int));
const int err =
uv_recv_buffer_size(reinterpret_cast<uv_handle_t*>(this->uvHandle), std::addressof(sizeInt));
if (err)
{
......
......@@ -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<void*>(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<uv_handle_t*>(this->uvHandle), std::addressof(size));
const int err =
uv_send_buffer_size(reinterpret_cast<uv_handle_t*>(this->uvHandle), std::addressof(size));
if (err)
{
......@@ -266,15 +266,15 @@ void UnixStreamSocketHandle::SetSendBufferSize(uint32_t size)
{
MS_TRACE();
auto size_int = static_cast<int>(size);
auto sizeInt = static_cast<int>(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<uv_handle_t*>(this->uvHandle), std::addressof(size_int));
const int err =
uv_send_buffer_size(reinterpret_cast<uv_handle_t*>(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<uv_handle_t*>(this->uvHandle), std::addressof(size));
const int err =
uv_recv_buffer_size(reinterpret_cast<uv_handle_t*>(this->uvHandle), std::addressof(size));
if (err)
{
......@@ -301,15 +302,15 @@ void UnixStreamSocketHandle::SetRecvBufferSize(uint32_t size)
{
MS_TRACE();
auto size_int = static_cast<int>(size);
auto sizeInt = static_cast<int>(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<uv_handle_t*>(this->uvHandle), std::addressof(size_int));
const int err =
uv_recv_buffer_size(reinterpret_cast<uv_handle_t*>(this->uvHandle), std::addressof(sizeInt));
if (err)
{
......
......@@ -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<std::string, int> ignoredSignals =
absl::flat_hash_map<std::string, int> 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);
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论