diff --git a/worker/.clang-format b/worker/.clang-format index e9d4091214..00181a08c8 100644 --- a/worker/.clang-format +++ b/worker/.clang-format @@ -36,6 +36,7 @@ BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: false BreakStringLiterals: false ColumnLimit: 100 +QualifierAlignment: Left CommentPragmas: 'NOLINT' ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerIndentWidth: 2 diff --git a/worker/.clang-tidy b/worker/.clang-tidy index 689093fedf..6e5b58e510 100644 --- a/worker/.clang-tidy +++ b/worker/.clang-tidy @@ -4,6 +4,7 @@ Checks: '*,-llvmlibc-*,-boost-use-to-string,-cert-*,-clang-analyzer-osx.*,-clang HeaderFilterRegex: '' AnalyzeTemporaryDtors: false User: mediasoup +FormatStyle: file CheckOptions: - key: cppcoreguidelines-pro-bounds-constant-array-index.GslHeader value: '' diff --git a/worker/src/RTC/ActiveSpeakerObserver.cpp b/worker/src/RTC/ActiveSpeakerObserver.cpp index 8ff3898c2f..e86bdfcdb1 100644 --- a/worker/src/RTC/ActiveSpeakerObserver.cpp +++ b/worker/src/RTC/ActiveSpeakerObserver.cpp @@ -33,7 +33,7 @@ namespace RTC inline int64_t BinomialCoefficient(int32_t n, int32_t r) { - int32_t m = n - r; + const int32_t m = n - r; if (r < m) { @@ -67,16 +67,16 @@ 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(); - uint32_t littleLenPerBig = littleLen / bigLen; + uint32_t littleLen = littles.size(); + uint32_t bigLen = bigs.size(); + const uint32_t littleLenPerBig = littleLen / bigLen; bool changed{ false }; for (uint32_t b = 0u, l = 0u; b < bigLen; ++b) { uint8_t sum{ 0u }; - for (uint32_t lEnd = l + littleLenPerBig; l < lEnd; ++l) + for (const uint32_t lEnd = l + littleLenPerBig; l < lEnd; ++l) { if (littles[l] > threashold) { @@ -261,7 +261,7 @@ namespace RTC { MS_TRACE(); - uint64_t now = DepLibUV::GetTimeMs(); + const uint64_t now = DepLibUV::GetTimeMs(); if (now - this->lastLevelIdleTime >= LevelIdleTimeout) { @@ -452,7 +452,7 @@ namespace RTC { if (this->lastLevelChangeTime <= now) { - uint64_t elapsed = now - this->lastLevelChangeTime; + const uint64_t elapsed = now - this->lastLevelChangeTime; this->lastLevelChangeTime = now; @@ -498,25 +498,25 @@ namespace RTC { MS_TRACE(); - int8_t minLevel = this->minLevel + SubunitLengthN1; - bool changed = false; + const int8_t minLevel = this->minLevel + SubunitLengthN1; + bool changed = false; for (uint32_t i = 0; i < ImmediateBuffLen; ++i) { // this->levels is a circular buffer where new samples are written in the // next vector index. this->immediates is a buffer where the most recent // value is always in index 0. - size_t levelIndex = this->nextLevelIndex >= (i + 1) - ? this->nextLevelIndex - i - 1 - : this->nextLevelIndex + LevelsBuffLen - i - 1; - uint8_t level = this->levels[levelIndex]; + const size_t levelIndex = this->nextLevelIndex >= (i + 1) + ? this->nextLevelIndex - i - 1 + : this->nextLevelIndex + LevelsBuffLen - i - 1; + uint8_t level = this->levels[levelIndex]; if (level < minLevel) { level = MinLevel; } - uint8_t immediate = (level / SubunitLengthN1); + const uint8_t immediate = (level / SubunitLengthN1); if (this->immediates[i] != immediate) { diff --git a/worker/src/RTC/Consumer.cpp b/worker/src/RTC/Consumer.cpp index f1e0296931..0f09842377 100644 --- a/worker/src/RTC/Consumer.cpp +++ b/worker/src/RTC/Consumer.cpp @@ -273,7 +273,7 @@ namespace RTC return; } - bool wasActive = IsActive(); + const bool wasActive = IsActive(); this->paused = true; @@ -410,7 +410,7 @@ namespace RTC if (this->producerPaused) return; - bool wasActive = IsActive(); + const bool wasActive = IsActive(); this->producerPaused = true; diff --git a/worker/src/RTC/DtlsTransport.cpp b/worker/src/RTC/DtlsTransport.cpp index d461e7d2a1..d639f64767 100644 --- a/worker/src/RTC/DtlsTransport.cpp +++ b/worker/src/RTC/DtlsTransport.cpp @@ -647,7 +647,7 @@ namespace RTC localRole == Role::CLIENT || localRole == Role::SERVER, "local DTLS role must be 'client' or 'server'"); - Role previousLocalRole = this->localRole; + const Role previousLocalRole = this->localRole; if (localRole == previousLocalRole) { @@ -860,7 +860,7 @@ namespace RTC MS_TRACE(); int err; - bool wasHandshakeDone = this->handshakeDone; + const bool wasHandshakeDone = this->handshakeDone; err = SSL_get_error(this->ssl, returnCode); @@ -1342,7 +1342,7 @@ namespace RTC { MS_TRACE(); - int w = where & -SSL_ST_MASK; + const int w = where & -SSL_ST_MASK; const char* role; if ((w & SSL_ST_CONNECT) != 0) diff --git a/worker/src/RTC/NackGenerator.cpp b/worker/src/RTC/NackGenerator.cpp index 577a240224..48fe2e8512 100644 --- a/worker/src/RTC/NackGenerator.cpp +++ b/worker/src/RTC/NackGenerator.cpp @@ -42,8 +42,8 @@ namespace RTC { MS_TRACE(); - uint16_t seq = packet->GetSequenceNumber(); - bool isKeyFrame = packet->IsKeyFrame(); + uint16_t seq = packet->GetSequenceNumber(); + const bool isKeyFrame = packet->IsKeyFrame(); if (!this->started) { @@ -156,7 +156,7 @@ namespace RTC // If the nack list is too large, remove packets from the nack list until // the latest first packet of a keyframe. If the list is still too large, // clear it and request a keyframe. - uint16_t numNewNacks = seqEnd - seqStart; + const uint16_t numNewNacks = seqEnd - seqStart; if (static_cast(this->nackList.size()) + numNewNacks > MaxNackPackets) { @@ -228,7 +228,7 @@ namespace RTC { MS_TRACE(); - uint64_t nowMs = DepLibUV::GetTimeMs(); + const uint64_t nowMs = DepLibUV::GetTimeMs(); std::vector nackBatch; auto it = this->nackList.begin(); diff --git a/worker/src/RTC/PortManager.cpp b/worker/src/RTC/PortManager.cpp index a032a05d70..b8afdfce10 100644 --- a/worker/src/RTC/PortManager.cpp +++ b/worker/src/RTC/PortManager.cpp @@ -505,7 +505,7 @@ namespace RTC return; } - size_t portIdx = static_cast(port) - Settings::configuration.rtcMinPort; + const size_t portIdx = static_cast(port) - Settings::configuration.rtcMinPort; switch (transport) { @@ -564,7 +564,7 @@ namespace RTC } // Otherwise add an entry in the map and return it. - uint16_t numPorts = + const uint16_t numPorts = Settings::configuration.rtcMaxPort - Settings::configuration.rtcMinPort + 1; // Emplace a new vector filled with numPorts false values, meaning that @@ -591,7 +591,7 @@ namespace RTC } // Otherwise add an entry in the map and return it. - uint16_t numPorts = + const uint16_t numPorts = Settings::configuration.rtcMaxPort - Settings::configuration.rtcMinPort + 1; // Emplace a new vector filled with numPorts false values, meaning that diff --git a/worker/src/RTC/Producer.cpp b/worker/src/RTC/Producer.cpp index b817dc2e98..4b0c353513 100644 --- a/worker/src/RTC/Producer.cpp +++ b/worker/src/RTC/Producer.cpp @@ -1351,7 +1351,7 @@ namespace RTC extenLen = 3u; // NOTE: Add value 0. The sending Transport will update it. - uint32_t absSendTime{ 0u }; + const uint32_t absSendTime{ 0u }; Utils::Byte::Set3Bytes(bufferPtr, 0, absSendTime); @@ -1367,7 +1367,7 @@ namespace RTC extenLen = 2u; // NOTE: Add value 0. The sending Transport will update it. - uint16_t wideSeqNumber{ 0u }; + const uint16_t wideSeqNumber{ 0u }; Utils::Byte::Set2Bytes(bufferPtr, 0, wideSeqNumber); diff --git a/worker/src/RTC/RateCalculator.cpp b/worker/src/RTC/RateCalculator.cpp index d06d851bde..929692fc8f 100644 --- a/worker/src/RTC/RateCalculator.cpp +++ b/worker/src/RTC/RateCalculator.cpp @@ -69,7 +69,7 @@ namespace RTC RemoveOldData(nowMs); - float scale = this->scale / this->windowSizeMs; + const float scale = this->scale / this->windowSizeMs; this->lastTime = nowMs; this->lastRate = static_cast(std::trunc(this->totalCount * scale + 0.5f)); @@ -85,7 +85,7 @@ namespace RTC if (this->newestItemIndex < 0 || this->oldestItemIndex < 0) return; - uint64_t newOldestTime = nowMs - this->windowSizeMs; + const uint64_t newOldestTime = nowMs - this->windowSizeMs; // Oldest item already removed. if (newOldestTime < this->oldestItemStartTime) diff --git a/worker/src/RTC/RtpPacket.cpp b/worker/src/RTC/RtpPacket.cpp index f6a9905831..51d4757eab 100644 --- a/worker/src/RTC/RtpPacket.cpp +++ b/worker/src/RTC/RtpPacket.cpp @@ -434,7 +434,7 @@ namespace RTC auto paddedExtensionsTotalSize = static_cast(Utils::Byte::PadTo4Bytes(static_cast(extensionsTotalSize))); - size_t padding = paddedExtensionsTotalSize - extensionsTotalSize; + const size_t padding = paddedExtensionsTotalSize - extensionsTotalSize; extensionsTotalSize = paddedExtensionsTotalSize; @@ -876,8 +876,8 @@ namespace RTC // One-Byte extensions cannot have length 0. while (ptr < extensionEnd) { - uint8_t id = (*ptr & 0xF0) >> 4; - size_t len = static_cast(*ptr & 0x0F) + 1; + const uint8_t id = (*ptr & 0xF0) >> 4; + const size_t len = static_cast(*ptr & 0x0F) + 1; // id=15 in One-Byte extensions means "stop parsing here". if (id == 15u) @@ -929,8 +929,8 @@ namespace RTC // Two-Byte extensions can have length 0. while (ptr + 1 < extensionEnd) { - uint8_t id = *ptr; - uint8_t len = *(ptr + 1); + const uint8_t id = *ptr; + const uint8_t len = *(ptr + 1); // Valid extension id. if (id != 0u) diff --git a/worker/src/RTC/RtpStream.cpp b/worker/src/RTC/RtpStream.cpp index 68b4af3bd8..b8e123c6af 100644 --- a/worker/src/RTC/RtpStream.cpp +++ b/worker/src/RTC/RtpStream.cpp @@ -49,7 +49,7 @@ namespace RTC { MS_TRACE(); - uint64_t nowMs = DepLibUV::GetTimeMs(); + const uint64_t nowMs = DepLibUV::GetTimeMs(); jsonObject["timestamp"] = nowMs; jsonObject["ssrc"] = this->params.ssrc; @@ -113,7 +113,7 @@ namespace RTC { MS_TRACE(); - uint16_t seq = packet->GetSequenceNumber(); + const uint16_t seq = packet->GetSequenceNumber(); // If this is the first packet seen, initialize stuff. if (!this->started) @@ -174,8 +174,8 @@ namespace RTC { MS_TRACE(); - uint16_t seq = packet->GetSequenceNumber(); - uint16_t udelta = seq - this->maxSeq; + const uint16_t seq = packet->GetSequenceNumber(); + const uint16_t udelta = seq - this->maxSeq; // If the new packet sequence number is greater than the max seen but not // "so much bigger", accept it. diff --git a/worker/src/RTC/RtpStreamRecv.cpp b/worker/src/RTC/RtpStreamRecv.cpp index e3458d077d..4988e4163f 100644 --- a/worker/src/RTC/RtpStreamRecv.cpp +++ b/worker/src/RTC/RtpStreamRecv.cpp @@ -216,7 +216,7 @@ namespace RTC { MS_TRACE(); - uint64_t nowMs = DepLibUV::GetTimeMs(); + const uint64_t nowMs = DepLibUV::GetTimeMs(); RTC::RtpStream::FillJsonStats(jsonObject); @@ -429,7 +429,7 @@ namespace RTC report->SetSsrc(GetSsrc()); - uint32_t prevPacketsLost = this->packetsLost; + const uint32_t prevPacketsLost = this->packetsLost; // Calculate Packets Expected and Lost. auto expected = GetExpectedPackets(); @@ -448,7 +448,7 @@ namespace RTC this->receivedPrior = this->mediaTransmissionCounter.GetPacketCount(); - int32_t lostInterval = expectedInterval - receivedInterval; + const int32_t lostInterval = expectedInterval - receivedInterval; if (expectedInterval == 0 || lostInterval <= 0) this->fractionLost = 0; @@ -466,7 +466,7 @@ namespace RTC else { // Recalculate packetsLost. - uint32_t newLostInterval = (worstRemoteFractionLost * expectedInterval) >> 8; + const uint32_t newLostInterval = (worstRemoteFractionLost * expectedInterval) >> 8; this->reportedPacketLost += newLostInterval; @@ -545,16 +545,16 @@ namespace RTC /* Calculate RTT. */ // Get the NTP representation of the current timestamp. - uint64_t nowMs = DepLibUV::GetTimeMs(); - auto ntp = Utils::Time::TimeMs2Ntp(nowMs); + const uint64_t nowMs = DepLibUV::GetTimeMs(); + auto ntp = Utils::Time::TimeMs2Ntp(nowMs); // Get the compact NTP representation of the current timestamp. uint32_t compactNtp = (ntp.seconds & 0x0000FFFF) << 16; compactNtp |= (ntp.fractions & 0xFFFF0000) >> 16; - uint32_t lastRr = ssrcInfo->GetLastReceiverReport(); - uint32_t dlrr = ssrcInfo->GetDelaySinceLastReceiverReport(); + const uint32_t lastRr = ssrcInfo->GetLastReceiverReport(); + const uint32_t dlrr = ssrcInfo->GetDelaySinceLastReceiverReport(); // RTT in 1/2^16 second fractions. uint32_t rtt{ 0 }; diff --git a/worker/src/RTC/RtpStreamSend.cpp b/worker/src/RTC/RtpStreamSend.cpp index f0cf95ac59..85eb69dae1 100644 --- a/worker/src/RTC/RtpStreamSend.cpp +++ b/worker/src/RTC/RtpStreamSend.cpp @@ -285,16 +285,16 @@ namespace RTC /* Calculate RTT. */ // Get the NTP representation of the current timestamp. - uint64_t nowMs = DepLibUV::GetTimeMs(); - auto ntp = Utils::Time::TimeMs2Ntp(nowMs); + const uint64_t nowMs = DepLibUV::GetTimeMs(); + auto ntp = Utils::Time::TimeMs2Ntp(nowMs); // Get the compact NTP representation of the current timestamp. uint32_t compactNtp = (ntp.seconds & 0x0000FFFF) << 16; compactNtp |= (ntp.fractions & 0xFFFF0000) >> 16; - uint32_t lastSr = report->GetLastSenderReport(); - uint32_t dlsr = report->GetDelaySinceLastSenderReport(); + const uint32_t lastSr = report->GetLastSenderReport(); + const uint32_t dlsr = report->GetDelaySinceLastSenderReport(); // RTT in 1/2^16 second fractions. uint32_t rtt{ 0 }; @@ -567,14 +567,14 @@ namespace RTC } // Look for each requested packet. - uint64_t nowMs = DepLibUV::GetTimeMs(); - uint16_t rtt = (this->rtt != 0u ? this->rtt : DefaultRtt); - uint16_t currentSeq = seq; + const uint64_t nowMs = DepLibUV::GetTimeMs(); + const uint16_t rtt = (this->rtt != 0u ? this->rtt : DefaultRtt); + uint16_t currentSeq = seq; bool requested{ true }; size_t containerIdx{ 0 }; // Variables for debugging. - uint16_t origBitmask = bitmask; + const uint16_t origBitmask = bitmask; uint16_t sentBitmask{ 0b0000000000000000 }; bool isFirstPacket{ true }; bool firstPacketSent{ false }; @@ -724,7 +724,7 @@ namespace RTC this->sentPriorScore = totalSent; // Calculate number of packets lost in this interval. - uint32_t totalLost = report->GetTotalLost() > 0 ? report->GetTotalLost() : 0; + const uint32_t totalLost = report->GetTotalLost() > 0 ? report->GetTotalLost() : 0; uint32_t lost; if (totalLost < this->lostPriorScore) @@ -741,8 +741,8 @@ namespace RTC this->repairedPriorScore = totalRepaired; // Calculate number of packets retransmitted in this interval. - auto totatRetransmitted = this->packetsRetransmitted; - uint32_t retransmitted = totatRetransmitted - this->retransmittedPriorScore; + auto totatRetransmitted = this->packetsRetransmitted; + const uint32_t retransmitted = totatRetransmitted - this->retransmittedPriorScore; this->retransmittedPriorScore = totatRetransmitted; diff --git a/worker/src/RTC/RtxStream.cpp b/worker/src/RTC/RtxStream.cpp index 2a291981b5..44b5c3bc12 100644 --- a/worker/src/RTC/RtxStream.cpp +++ b/worker/src/RTC/RtxStream.cpp @@ -40,7 +40,7 @@ namespace RTC { MS_TRACE(); - uint16_t seq = packet->GetSequenceNumber(); + const uint16_t seq = packet->GetSequenceNumber(); // If this is the first packet seen, initialize stuff. if (!this->started) @@ -86,7 +86,7 @@ namespace RTC report->SetSsrc(GetSsrc()); - uint32_t prevPacketsLost = this->packetsLost; + const uint32_t prevPacketsLost = this->packetsLost; // Calculate Packets Expected and Lost. auto expected = GetExpectedPackets(); @@ -97,15 +97,15 @@ namespace RTC this->packetsLost = 0u; // Calculate Fraction Lost. - uint32_t expectedInterval = expected - this->expectedPrior; + const uint32_t expectedInterval = expected - this->expectedPrior; this->expectedPrior = expected; - uint32_t receivedInterval = this->packetsCount - this->receivedPrior; + const uint32_t receivedInterval = this->packetsCount - this->receivedPrior; this->receivedPrior = this->packetsCount; - int32_t lostInterval = expectedInterval - receivedInterval; + const int32_t lostInterval = expectedInterval - receivedInterval; if (expectedInterval == 0 || lostInterval <= 0) this->fractionLost = 0; @@ -157,8 +157,8 @@ namespace RTC { MS_TRACE(); - uint16_t seq = packet->GetSequenceNumber(); - uint16_t udelta = seq - this->maxSeq; + const uint16_t seq = packet->GetSequenceNumber(); + const uint16_t udelta = seq - this->maxSeq; // If the new packet sequence number is greater than the max seen but not // "so much bigger", accept it. diff --git a/worker/src/RTC/SctpAssociation.cpp b/worker/src/RTC/SctpAssociation.cpp index 67d5fb41a3..2c0ee8cf6e 100644 --- a/worker/src/RTC/SctpAssociation.cpp +++ b/worker/src/RTC/SctpAssociation.cpp @@ -58,9 +58,9 @@ inline static int onRecvSctpData( } else { - uint16_t streamId = rcv.rcv_sid; - uint32_t ppid = ntohl(rcv.rcv_ppid); - uint16_t ssn = rcv.rcv_ssn; + const uint16_t streamId = rcv.rcv_sid; + uint32_t ppid = ntohl(rcv.rcv_ppid); + const uint16_t ssn = rcv.rcv_ssn; MS_DEBUG_TAG( sctp, @@ -191,7 +191,7 @@ namespace RTC } // Set SCTP_NODELAY. - uint32_t noDelay = 1; + const uint32_t noDelay = 1; ret = usrsctp_setsockopt(this->socket, IPPROTO_SCTP, SCTP_NODELAY, &noDelay, sizeof(noDelay)); @@ -772,7 +772,7 @@ namespace RTC static const size_t BufferSize{ 1024 }; thread_local static char buffer[BufferSize]; - uint32_t len = + const uint32_t len = notification->sn_assoc_change.sac_length - sizeof(struct sctp_assoc_change); for (uint32_t i{ 0 }; i < len; ++i) @@ -841,7 +841,7 @@ namespace RTC static const size_t BufferSize{ 1024 }; thread_local static char buffer[BufferSize]; - uint32_t len = + const uint32_t len = notification->sn_assoc_change.sac_length - sizeof(struct sctp_assoc_change); for (uint32_t i{ 0 }; i < len; ++i) @@ -883,7 +883,8 @@ namespace RTC static const size_t BufferSize{ 1024 }; thread_local static char buffer[BufferSize]; - uint32_t len = notification->sn_remote_error.sre_length - sizeof(struct sctp_remote_error); + const uint32_t len = + notification->sn_remote_error.sre_length - sizeof(struct sctp_remote_error); for (uint32_t i{ 0 }; i < len; i++) { @@ -919,7 +920,7 @@ namespace RTC static const size_t BufferSize{ 1024 }; thread_local static char buffer[BufferSize]; - uint32_t len = + const uint32_t len = notification->sn_send_failed_event.ssfe_length - sizeof(struct sctp_send_failed_event); for (uint32_t i{ 0 }; i < len; ++i) @@ -944,7 +945,7 @@ namespace RTC { bool incoming{ false }; bool outgoing{ false }; - uint16_t numStreams = + const uint16_t numStreams = (notification->sn_strreset_event.strreset_length - sizeof(struct sctp_stream_reset_event)) / sizeof(uint16_t); diff --git a/worker/src/RTC/SenderBandwidthEstimator.cpp b/worker/src/RTC/SenderBandwidthEstimator.cpp index 68a7ff4fc7..ca98eda585 100644 --- a/worker/src/RTC/SenderBandwidthEstimator.cpp +++ b/worker/src/RTC/SenderBandwidthEstimator.cpp @@ -83,8 +83,8 @@ namespace RTC { MS_TRACE(); - auto nowMs = DepLibUV::GetTimeMs(); - uint64_t elapsedMs = nowMs - this->cummulativeResult.GetStartedAtMs(); + auto nowMs = DepLibUV::GetTimeMs(); + const uint64_t elapsedMs = nowMs - this->cummulativeResult.GetStartedAtMs(); // Drop ongoing cummulative result if too old. if (elapsedMs > 1000u) @@ -172,8 +172,8 @@ namespace RTC auto previousAvailableBitrate = this->availableBitrate; - double ratio = static_cast(cummulativeResult.GetReceiveBitrate()) / - static_cast(cummulativeResult.GetSendBitrate()); + const double ratio = static_cast(cummulativeResult.GetReceiveBitrate()) / + static_cast(cummulativeResult.GetSendBitrate()); auto bitrate = std::min(cummulativeResult.GetReceiveBitrate(), cummulativeResult.GetSendBitrate()); diff --git a/worker/src/RTC/SimpleConsumer.cpp b/worker/src/RTC/SimpleConsumer.cpp index fdc7e0bd2f..7ed5f44d2f 100644 --- a/worker/src/RTC/SimpleConsumer.cpp +++ b/worker/src/RTC/SimpleConsumer.cpp @@ -301,7 +301,7 @@ namespace RTC return; // Whether this is the first packet after re-sync. - bool isSyncPacket = this->syncRequired; + const bool isSyncPacket = this->syncRequired; // Sync sequence number and timestamp if required. if (isSyncPacket) diff --git a/worker/src/RTC/SimulcastConsumer.cpp b/worker/src/RTC/SimulcastConsumer.cpp index 0ac7077c69..59b63ebcf9 100644 --- a/worker/src/RTC/SimulcastConsumer.cpp +++ b/worker/src/RTC/SimulcastConsumer.cpp @@ -709,7 +709,7 @@ namespace RTC return; // Whether this is the first packet after re-sync. - bool isSyncPacket = this->syncRequired; + const bool isSyncPacket = this->syncRequired; // Sync sequence number and timestamp if required. if (isSyncPacket && (this->spatialLayerToSync == -1 || this->spatialLayerToSync == spatialLayer)) @@ -750,8 +750,8 @@ namespace RTC else diffMs = -1 * (ntpMs1 - ntpMs2); - int64_t diffTs = diffMs * this->rtpStream->GetClockRate() / 1000; - uint32_t newTs2 = ts2 - diffTs; + int64_t diffTs = diffMs * this->rtpStream->GetClockRate() / 1000; + const uint32_t newTs2 = ts2 - diffTs; // Apply offset. This is the difference that later must be removed from the // sending RTP packet. @@ -902,7 +902,7 @@ namespace RTC // Update RTP seq number and timestamp based on NTP offset. uint16_t seq; - uint32_t timestamp = packet->GetTimestamp() - this->tsOffset; + const uint32_t timestamp = packet->GetTimestamp() - this->tsOffset; this->rtpSeqManager.Input(packet->GetSequenceNumber(), seq); diff --git a/worker/src/RTC/SrtpSession.cpp b/worker/src/RTC/SrtpSession.cpp index fd87fc0bdf..97051e0cfd 100644 --- a/worker/src/RTC/SrtpSession.cpp +++ b/worker/src/RTC/SrtpSession.cpp @@ -19,7 +19,7 @@ namespace RTC void SrtpSession::ClassInit() { // Set libsrtp event handler. - srtp_err_status_t err = + const srtp_err_status_t err = srtp_install_event_handler(static_cast(OnSrtpEvent)); if (DepLibSRTP::IsError(err)) @@ -127,7 +127,7 @@ namespace RTC policy.next = nullptr; // Set the SRTP session. - srtp_err_status_t err = srtp_create(&this->session, &policy); + const srtp_err_status_t err = srtp_create(&this->session, &policy); if (DepLibSRTP::IsError(err)) MS_THROW_ERROR("srtp_create() failed: %s", DepLibSRTP::GetErrorString(err)); @@ -139,7 +139,7 @@ namespace RTC if (this->session != nullptr) { - srtp_err_status_t err = srtp_dealloc(this->session); + const srtp_err_status_t err = srtp_dealloc(this->session); if (DepLibSRTP::IsError(err)) MS_ABORT("srtp_dealloc() failed: %s", DepLibSRTP::GetErrorString(err)); @@ -160,7 +160,7 @@ namespace RTC std::memcpy(EncryptBuffer, *data, *len); - srtp_err_status_t err = srtp_protect(this->session, static_cast(EncryptBuffer), len); + const srtp_err_status_t err = srtp_protect(this->session, static_cast(EncryptBuffer), len); if (DepLibSRTP::IsError(err)) { @@ -179,7 +179,7 @@ namespace RTC { MS_TRACE(); - srtp_err_status_t err = srtp_unprotect(this->session, static_cast(data), len); + const srtp_err_status_t err = srtp_unprotect(this->session, static_cast(data), len); if (DepLibSRTP::IsError(err)) { @@ -205,7 +205,8 @@ namespace RTC std::memcpy(EncryptBuffer, *data, *len); - srtp_err_status_t err = srtp_protect_rtcp(this->session, static_cast(EncryptBuffer), len); + const srtp_err_status_t err = + srtp_protect_rtcp(this->session, static_cast(EncryptBuffer), len); if (DepLibSRTP::IsError(err)) { @@ -224,7 +225,7 @@ namespace RTC { MS_TRACE(); - srtp_err_status_t err = srtp_unprotect_rtcp(this->session, static_cast(data), len); + const srtp_err_status_t err = srtp_unprotect_rtcp(this->session, static_cast(data), len); if (DepLibSRTP::IsError(err)) { diff --git a/worker/src/RTC/StunPacket.cpp b/worker/src/RTC/StunPacket.cpp index a024e90701..6a453bca24 100644 --- a/worker/src/RTC/StunPacket.cpp +++ b/worker/src/RTC/StunPacket.cpp @@ -42,10 +42,10 @@ namespace RTC */ // Get type field. - uint16_t msgType = Utils::Byte::Get2Bytes(data, 0); + const uint16_t msgType = Utils::Byte::Get2Bytes(data, 0); // Get length field. - uint16_t msgLength = Utils::Byte::Get2Bytes(data, 2); + const uint16_t msgLength = Utils::Byte::Get2Bytes(data, 2); // length field must be total size minus header's 20 bytes, and must be multiple of 4 Bytes. if ((static_cast(msgLength) != len - 20) || ((msgLength & 0x03) != 0)) @@ -59,10 +59,11 @@ namespace RTC } // Get STUN method. - uint16_t msgMethod = (msgType & 0x000f) | ((msgType & 0x00e0) >> 1) | ((msgType & 0x3E00) >> 2); + const uint16_t msgMethod = + (msgType & 0x000f) | ((msgType & 0x00e0) >> 1) | ((msgType & 0x3E00) >> 2); // Get STUN class. - uint16_t msgClass = ((data[0] & 0x01) << 1) | ((data[1] & 0x10) >> 4); + const uint16_t msgClass = ((data[0] & 0x01) << 1) | ((data[1] & 0x10) >> 4); // Create a new StunPacket (data + 8 points to the received TransactionID field). auto* packet = new StunPacket( @@ -101,7 +102,7 @@ namespace RTC auto attrType = static_cast(Utils::Byte::Get2Bytes(data, pos)); // Get the attribute length. - uint16_t attrLength = Utils::Byte::Get2Bytes(data, pos + 2); + const uint16_t attrLength = Utils::Byte::Get2Bytes(data, pos + 2); // Ensure the attribute length is not greater than the remaining size. if ((pos + 4 + attrLength) > len) @@ -273,9 +274,9 @@ namespace RTC return nullptr; } - uint8_t errorClass = Utils::Byte::Get1Byte(attrValuePos, 2); - uint8_t errorNumber = Utils::Byte::Get1Byte(attrValuePos, 3); - auto errorCode = static_cast(errorClass * 100 + errorNumber); + const uint8_t errorClass = Utils::Byte::Get1Byte(attrValuePos, 2); + const uint8_t errorNumber = Utils::Byte::Get1Byte(attrValuePos, 3); + auto errorCode = static_cast(errorClass * 100 + errorNumber); packet->SetErrorCode(errorCode); @@ -304,7 +305,8 @@ namespace RTC { // Compute the CRC32 of the received packet up to (but excluding) the // FINGERPRINT attribute and XOR it with 0x5354554e. - uint32_t computedFingerprint = Utils::Crypto::GetCRC32(data, fingerprintAttrPos) ^ 0x5354554e; + const uint32_t computedFingerprint = + Utils::Crypto::GetCRC32(data, fingerprintAttrPos) ^ 0x5354554e; // Compare with the FINGERPRINT value in the packet. if (fingerprint != computedFingerprint) @@ -531,7 +533,7 @@ namespace RTC this->klass == Class::SUCCESS_RESPONSE); bool addErrorCode = ((this->errorCode != 0u) && this->klass == Class::ERROR_RESPONSE); bool addMessageIntegrity = (this->klass != Class::ERROR_RESPONSE && !this->password.empty()); - bool addFingerprint{ true }; // Do always. + const bool addFingerprint{ true }; // Do always. // Update data pointer. this->data = buffer; @@ -789,7 +791,7 @@ namespace RTC { // Compute the CRC32 of the packet up to (but excluding) the FINGERPRINT // attribute and XOR it with 0x5354554e. - uint32_t computedFingerprint = Utils::Crypto::GetCRC32(buffer, pos) ^ 0x5354554e; + const uint32_t computedFingerprint = Utils::Crypto::GetCRC32(buffer, pos) ^ 0x5354554e; Utils::Byte::Set2Bytes(buffer, pos, static_cast(Attribute::FINGERPRINT)); Utils::Byte::Set2Bytes(buffer, pos + 2, 4); diff --git a/worker/src/RTC/SvcConsumer.cpp b/worker/src/RTC/SvcConsumer.cpp index c13b809177..f9a84da769 100644 --- a/worker/src/RTC/SvcConsumer.cpp +++ b/worker/src/RTC/SvcConsumer.cpp @@ -577,7 +577,7 @@ namespace RTC return; // Whether this is the first packet after re-sync. - bool isSyncPacket = this->syncRequired; + const bool isSyncPacket = this->syncRequired; // Sync sequence number and timestamp if required. if (isSyncPacket) @@ -595,7 +595,7 @@ namespace RTC auto previousTemporalLayer = this->encodingContext->GetCurrentTemporalLayer(); bool marker{ false }; - bool origMarker = packet->HasMarker(); + const bool origMarker = packet->HasMarker(); if (!packet->ProcessPayload(this->encodingContext.get(), marker)) { diff --git a/worker/src/RTC/TcpConnection.cpp b/worker/src/RTC/TcpConnection.cpp index 511ec56190..b13cfd430c 100644 --- a/worker/src/RTC/TcpConnection.cpp +++ b/worker/src/RTC/TcpConnection.cpp @@ -62,7 +62,7 @@ namespace RTC if (IsClosed()) return; - size_t dataLen = this->bufferDataLen - this->frameStart; + const size_t dataLen = this->bufferDataLen - this->frameStart; size_t packetLen; if (dataLen >= 2) diff --git a/worker/src/RTC/Transport.cpp b/worker/src/RTC/Transport.cpp index 665da0216c..efcbe6815d 100644 --- a/worker/src/RTC/Transport.cpp +++ b/worker/src/RTC/Transport.cpp @@ -3076,8 +3076,8 @@ namespace RTC // RTCP timer. if (timer == this->rtcpTimer) { - auto interval = static_cast(RTC::RTCP::MaxVideoIntervalMs); - uint64_t nowMs = DepLibUV::GetTimeMs(); + auto interval = static_cast(RTC::RTCP::MaxVideoIntervalMs); + const uint64_t nowMs = DepLibUV::GetTimeMs(); SendRtcp(nowMs); diff --git a/worker/src/RTC/TransportCongestionControlClient.cpp b/worker/src/RTC/TransportCongestionControlClient.cpp index bf6b11425d..f555bdf7a5 100644 --- a/worker/src/RTC/TransportCongestionControlClient.cpp +++ b/worker/src/RTC/TransportCongestionControlClient.cpp @@ -161,7 +161,7 @@ namespace RTC } // Notify the transport feedback adapter about the sent packet. - rtc::SentPacket sentPacket(packetInfo.transport_sequence_number, nowMs); + rtc::SentPacket const sentPacket(packetInfo.transport_sequence_number, nowMs); this->rtpTransportControllerSend->OnSentPacket(sentPacket, packetInfo.length); } @@ -214,8 +214,8 @@ namespace RTC MS_TRACE(); // Update packet loss history. - size_t expected_packets = feedback->GetPacketStatusCount(); - size_t lost_packets = 0; + const size_t expected_packets = feedback->GetPacketStatusCount(); + size_t lost_packets = 0; for (const auto& result : feedback->GetPacketResults()) { if (!result.received) @@ -411,7 +411,7 @@ namespace RTC { MS_TRACE(); - uint64_t nowMs = DepLibUV::GetTimeMsInt64(); + const uint64_t nowMs = DepLibUV::GetTimeMsInt64(); bool notify{ false }; // Ignore if first event. diff --git a/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp b/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp index 5850735c53..9cc7b65f59 100644 --- a/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp +++ b/worker/test/src/RTC/RTCP/TestFeedbackRtpTransport.cpp @@ -723,7 +723,7 @@ SCENARIO("RTCP Feeback RTP transport", "[parser][rtcp][feedback-rtp][transport]" auto packetsResults = feedback->GetPacketResults(); int deltasIt = 0; - for (auto const& delta : packetMeta.deltas) + for (const auto& delta : packetMeta.deltas) { auto resultDelta = packetsResults[deltasIt].delta; REQUIRE(static_cast(resultDelta / 4) == delta);