提交 ead33e5c authored 作者: José Luis Millán's avatar José Luis Millán

const correctness

上级 1d0734ff
......@@ -4,6 +4,7 @@
### 3.6.8 (WIP)
* Update `nlohmann::json` C++ dep to 3.8.0.
* Enhance const correctness.
### 3.6.7
......
......@@ -33,7 +33,7 @@ namespace RTC
public:
void FillJson(json& jsonObject) const;
void FillJsonStats(json& jsonArray) const;
void HandleRequest(Channel::Request* request);
void HandleRequest(Channel::Request* request) const;
Type GetType() const
{
return this->type;
......
......@@ -58,7 +58,6 @@ namespace RTC
private:
void StorePacket(RTC::RtpPacket* packet);
void ClearBuffer();
void ResetStorageItem(StorageItem* storageItem);
void UpdateBufferStartIdx();
void FillRetransmissionContainer(uint16_t seq, uint16_t bitmask);
void UpdateScore(RTC::RTCP::ReceiverReport* report);
......
......@@ -186,7 +186,7 @@ namespace RTC
jsonConsumableRtpEncodingsIt->emplace_back(json::value_t::object);
auto& jsonEntry = (*jsonConsumableRtpEncodingsIt)[i];
auto& encoding = this->consumableRtpEncodings[i];
const auto& encoding = this->consumableRtpEncodings[i];
encoding.FillJson(jsonEntry);
}
......
......@@ -110,7 +110,7 @@ namespace RTC
jsonObject["bytesReceived"] = this->bytesReceived;
}
void DataProducer::HandleRequest(Channel::Request* request)
void DataProducer::HandleRequest(Channel::Request* request) const
{
MS_TRACE();
......
......@@ -481,7 +481,7 @@ namespace RTC
for (size_t idx{ 0u }; idx < this->rtpParameters.encodings.size(); ++idx)
{
auto& encoding = this->rtpParameters.encodings[idx];
auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
const auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
MS_DEBUG_TAG(
rtp, "[ssrc:%" PRIu32 ", payloadType:%" PRIu8 "]", encoding.ssrc, mediaCodec->payloadType);
......@@ -522,9 +522,9 @@ namespace RTC
params.useDtx = true;
}
for (auto& fb : mediaCodec->rtcpFeedback)
for (const auto& fb : mediaCodec->rtcpFeedback)
{
if (!params.useNack && fb.type == "nack" && fb.parameter == "")
if (!params.useNack && fb.type == "nack" && fb.parameter.empty())
{
MS_DEBUG_2TAGS(rtp, rtcp, "NACK supported");
......@@ -552,7 +552,7 @@ namespace RTC
if (IsPaused() || IsProducerPaused())
rtpStream->Pause();
auto* rtxCodec = this->rtpParameters.GetRtxCodecForEncoding(encoding);
const auto* rtxCodec = this->rtpParameters.GetRtxCodecForEncoding(encoding);
if (rtxCodec && encoding.hasRtx)
rtpStream->SetRtx(rtxCodec->payloadType, encoding.rtx.ssrc);
......
......@@ -438,7 +438,7 @@ namespace RTC
for (auto& kv : PortManager::mapUdpIpPorts)
{
auto& ip = kv.first;
const auto& ip = kv.first;
auto& ports = kv.second;
(*jsonUdpIt)[ip] = json::array();
......@@ -461,7 +461,7 @@ namespace RTC
for (auto& kv : PortManager::mapTcpIpPorts)
{
auto& ip = kv.first;
const auto& ip = kv.first;
auto& ports = kv.second;
(*jsonTcpIt)[ip] = json::array();
......
......@@ -355,7 +355,7 @@ namespace RTC
jsonEncodingsIt->emplace_back(json::value_t::object);
auto& jsonEntry = (*jsonEncodingsIt)[i];
auto& encodingMapping = this->rtpMapping.encodings[i];
const auto& encodingMapping = this->rtpMapping.encodings[i];
if (!encodingMapping.rid.empty())
jsonEntry["rid"] = encodingMapping.rid;
......@@ -841,8 +841,8 @@ namespace RTC
for (size_t i{ 0 }; i < this->rtpParameters.encodings.size(); ++i)
{
auto& encoding = this->rtpParameters.encodings[i];
auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
auto* rtxCodec = this->rtpParameters.GetRtxCodecForEncoding(encoding);
const auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
const auto* rtxCodec = this->rtpParameters.GetRtxCodecForEncoding(encoding);
bool isMediaPacket = (mediaCodec->payloadType == payloadType);
bool isRtxPacket = (rtxCodec && rtxCodec->payloadType == payloadType);
......@@ -896,8 +896,8 @@ namespace RTC
if (encoding.rid != rid)
continue;
auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
auto* rtxCodec = this->rtpParameters.GetRtxCodecForEncoding(encoding);
const auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
const auto* rtxCodec = this->rtpParameters.GetRtxCodecForEncoding(encoding);
bool isMediaPacket = (mediaCodec->payloadType == payloadType);
bool isRtxPacket = (rtxCodec && rtxCodec->payloadType == payloadType);
......@@ -971,8 +971,8 @@ namespace RTC
// clang-format on
{
auto& encoding = this->rtpParameters.encodings[0];
auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
auto* rtxCodec = this->rtpParameters.GetRtxCodecForEncoding(encoding);
const auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
const auto* rtxCodec = this->rtpParameters.GetRtxCodecForEncoding(encoding);
bool isMediaPacket = (mediaCodec->payloadType == payloadType);
bool isRtxPacket = (rtxCodec && rtxCodec->payloadType == payloadType);
......@@ -1090,9 +1090,9 @@ namespace RTC
params.useDtx = true;
}
for (auto& fb : mediaCodec.rtcpFeedback)
for (const auto& fb : mediaCodec.rtcpFeedback)
{
if (!params.useNack && fb.type == "nack" && fb.parameter == "")
if (!params.useNack && fb.type == "nack" && fb.parameter.empty())
{
MS_DEBUG_2TAGS(rtp, rtcp, "NACK supported");
......
......@@ -668,7 +668,7 @@ namespace RTC
for (auto* consumer : consumers)
{
// Update MID RTP extension value.
auto& mid = consumer->GetRtpParameters().mid;
const auto& mid = consumer->GetRtpParameters().mid;
if (!mid.empty())
packet->UpdateMid(mid);
......@@ -736,7 +736,7 @@ namespace RTC
this->mapConsumerProducer[consumer] = producer;
// Get all streams in the Producer and provide the Consumer with them.
for (auto& kv : producer->GetRtpStreams())
for (const auto& kv : producer->GetRtpStreams())
{
auto* rtpStream = kv.first;
uint32_t mappedSsrc = kv.second;
......
......@@ -179,7 +179,7 @@ namespace RTC
{
extIds.reserve(this->mapOneByteExtensions.size());
for (auto& kv : this->mapOneByteExtensions)
for (const auto& kv : this->mapOneByteExtensions)
{
extIds.push_back(std::to_string(kv.first));
}
......@@ -188,7 +188,7 @@ namespace RTC
{
extIds.reserve(this->mapTwoBytesExtensions.size());
for (auto& kv : this->mapTwoBytesExtensions)
for (const auto& kv : this->mapTwoBytesExtensions)
{
extIds.push_back(std::to_string(kv.first));
}
......@@ -407,7 +407,7 @@ namespace RTC
// Calculate total size required for all extensions (with padding if needed).
size_t extensionsTotalSize{ 0 };
for (auto& extension : extensions)
for (const auto& extension : extensions)
{
if (type == 1u)
{
......@@ -484,7 +484,7 @@ namespace RTC
// Write the new extensions into the header extension value.
uint8_t* ptr = this->headerExtension->value;
for (auto& extension : extensions)
for (const auto& extension : extensions)
{
if (type == 1u)
{
......
......@@ -274,7 +274,7 @@ namespace RTC
// clang-tidy "thinks" that this can lead to division by zero but we are
// smarter.
// NOLINTNEXTLINE(clang-analyzer-core.DivideZero)
this->score = static_cast<uint8_t>(std::round(static_cast<float>(totalScore) / samples));
this->score = static_cast<uint8_t>(std::round(static_cast<double>(totalScore) / samples));
// Call the listener if the global score has changed.
if (this->score != previousScore)
......
......@@ -448,7 +448,7 @@ namespace RTC
if (expectedInterval == 0 || lostInterval <= 0)
this->fractionLost = 0;
else
this->fractionLost = std::round(((lostInterval << 8) / expectedInterval));
this->fractionLost = std::round((static_cast<double>(lostInterval << 8) / expectedInterval));
// Worst remote fraction lost is not worse than local one.
if (worstRemoteFractionLost <= this->fractionLost)
......@@ -557,15 +557,11 @@ namespace RTC
// If no Receiver Extended Report was received by the remote endpoint yet,
// ignore lastRr and dlrr values in the Sender Extended Report.
if (!lastRr || !dlrr)
rtt = 0;
else if (compactNtp > dlrr + lastRr)
if (lastRr && dlrr && (compactNtp > dlrr + lastRr))
rtt = compactNtp - dlrr - lastRr;
else
rtt = 0;
// RTT in milliseconds.
this->rtt = (rtt >> 16) * 1000;
this->rtt = static_cast<float>(rtt >> 16) * 1000;
this->rtt += (static_cast<float>(rtt & 0x0000FFFF) / 65536) * 1000;
if (this->rtt > 0.0f)
......@@ -740,7 +736,7 @@ namespace RTC
MS_ASSERT(retransmitted >= repaired, "repaired packets cannot be more than retransmitted ones");
if (retransmitted > 0)
repairedWeight *= repaired / retransmitted;
repairedWeight *= static_cast<float>(repaired) / retransmitted;
lost -= repaired * repairedWeight;
......
......@@ -17,6 +17,20 @@ namespace RTC
static constexpr uint32_t MaxRetransmissionDelay{ 2000 };
static constexpr uint32_t DefaultRtt{ 100 };
static void resetStorageItem(RTC::RtpStreamSend::StorageItem* storageItem)
{
MS_TRACE();
MS_ASSERT(storageItem, "storageItem cannot be nullptr");
delete storageItem->packet;
storageItem->packet = nullptr;
storageItem->resentAtMs = 0;
storageItem->sentTimes = 0;
storageItem->rtxEncoded = false;
}
/* Instance methods. */
RtpStreamSend::RtpStreamSend(
......@@ -288,7 +302,7 @@ namespace RTC
return;
// Reset the storage item.
ResetStorageItem(storageItem);
resetStorageItem(storageItem);
// If this was the item referenced by the buffer start index, move it to
// the next one.
......@@ -311,7 +325,7 @@ namespace RTC
auto* firstStorageItem = this->buffer[this->bufferStartIdx];
// Reset the first storage item.
ResetStorageItem(firstStorageItem);
resetStorageItem(firstStorageItem);
// Unfill the buffer start item.
this->buffer[this->bufferStartIdx] = nullptr;
......@@ -347,7 +361,7 @@ namespace RTC
}
// Reset (free RTP packet) the storage item.
ResetStorageItem(storageItem);
resetStorageItem(storageItem);
// Unfill the buffer item.
this->buffer[idx] = nullptr;
......@@ -358,20 +372,6 @@ namespace RTC
this->bufferSize = 0;
}
inline void RtpStreamSend::ResetStorageItem(StorageItem* storageItem)
{
MS_TRACE();
MS_ASSERT(storageItem, "storageItem cannot be nullptr");
delete storageItem->packet;
storageItem->packet = nullptr;
storageItem->resentAtMs = 0;
storageItem->sentTimes = 0;
storageItem->rtxEncoded = false;
}
/**
* Iterates the buffer starting from the current start idx + 1 until next
* used one. It takes into account that the buffer is circular.
......
......@@ -110,7 +110,7 @@ namespace RTC
if (expectedInterval == 0 || lostInterval <= 0)
this->fractionLost = 0;
else
this->fractionLost = std::round(((lostInterval << 8) / expectedInterval));
this->fractionLost = std::round((static_cast<double>(lostInterval << 8) / expectedInterval));
this->reportedPacketLost += (this->packetsLost - prevPacketsLost);
......
......@@ -19,7 +19,7 @@ namespace RTC
auto jsonStreamIdTableIt = jsonObject.find("streamIdTable");
// Add streamIdTable.
for (auto& kv : this->streamIdTable)
for (const auto& kv : this->streamIdTable)
{
auto streamId = kv.first;
auto* dataProducer = kv.second;
......
......@@ -463,7 +463,7 @@ namespace RTC
MS_TRACE();
auto& encoding = this->rtpParameters.encodings[0];
auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
const auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
MS_DEBUG_TAG(
rtp, "[ssrc:%" PRIu32 ", payloadType:%" PRIu8 "]", encoding.ssrc, mediaCodec->payloadType);
......
......@@ -481,7 +481,7 @@ namespace RTC
this->klass == Class::REQUEST,
"attempt to create an error response for a non Request STUN packet");
auto response =
auto* response =
new StunPacket(Class::ERROR_RESPONSE, this->method, this->transactionId, nullptr, 0);
response->SetErrorCode(errorCode);
......
......@@ -295,9 +295,9 @@ namespace RTC
jsonObject["producerIds"] = json::array();
auto jsonProducerIdsIt = jsonObject.find("producerIds");
for (auto& kv : this->mapProducers)
for (const auto& kv : this->mapProducers)
{
auto& producerId = kv.first;
const auto& producerId = kv.first;
jsonProducerIdsIt->emplace_back(producerId);
}
......@@ -306,9 +306,9 @@ namespace RTC
jsonObject["consumerIds"] = json::array();
auto jsonConsumerIdsIt = jsonObject.find("consumerIds");
for (auto& kv : this->mapConsumers)
for (const auto& kv : this->mapConsumers)
{
auto& consumerId = kv.first;
const auto& consumerId = kv.first;
jsonConsumerIdsIt->emplace_back(consumerId);
}
......@@ -317,7 +317,7 @@ namespace RTC
jsonObject["mapSsrcConsumerId"] = json::object();
auto jsonMapSsrcConsumerId = jsonObject.find("mapSsrcConsumerId");
for (auto& kv : this->mapSsrcConsumer)
for (const auto& kv : this->mapSsrcConsumer)
{
auto ssrc = kv.first;
auto* consumer = kv.second;
......@@ -329,7 +329,7 @@ namespace RTC
jsonObject["mapRtxSsrcConsumerId"] = json::object();
auto jsonMapRtxSsrcConsumerId = jsonObject.find("mapRtxSsrcConsumerId");
for (auto& kv : this->mapRtxSsrcConsumer)
for (const auto& kv : this->mapRtxSsrcConsumer)
{
auto ssrc = kv.first;
auto* consumer = kv.second;
......@@ -341,9 +341,9 @@ namespace RTC
jsonObject["dataProducerIds"] = json::array();
auto jsonDataProducerIdsIt = jsonObject.find("dataProducerIds");
for (auto& kv : this->mapDataProducers)
for (const auto& kv : this->mapDataProducers)
{
auto& dataProducerId = kv.first;
const auto& dataProducerId = kv.first;
jsonDataProducerIdsIt->emplace_back(dataProducerId);
}
......@@ -352,9 +352,9 @@ namespace RTC
jsonObject["dataConsumerIds"] = json::array();
auto jsonDataConsumerIdsIt = jsonObject.find("dataConsumerIds");
for (auto& kv : this->mapDataConsumers)
for (const auto& kv : this->mapDataConsumers)
{
auto& dataConsumerId = kv.first;
const auto& dataConsumerId = kv.first;
jsonDataConsumerIdsIt->emplace_back(dataConsumerId);
}
......@@ -629,7 +629,7 @@ namespace RTC
// add them to the Transport.
// NOTE: Producer::GetRtpHeaderExtensionIds() returns the original
// header extension ids of the Producer (and not their mapped values).
auto& producerRtpHeaderExtensionIds = producer->GetRtpHeaderExtensionIds();
const auto& producerRtpHeaderExtensionIds = producer->GetRtpHeaderExtensionIds();
if (producerRtpHeaderExtensionIds.mid != 0u)
this->recvRtpHeaderExtensionIds.mid = producerRtpHeaderExtensionIds.mid;
......@@ -656,8 +656,8 @@ namespace RTC
// Check if TransportCongestionControlServer or REMB server must be
// created.
auto& rtpHeaderExtensionIds = producer->GetRtpHeaderExtensionIds();
auto& codecs = producer->GetRtpParameters().codecs;
const auto& rtpHeaderExtensionIds = producer->GetRtpHeaderExtensionIds();
const auto& codecs = producer->GetRtpParameters().codecs;
// Set TransportCongestionControlServer.
if (!this->tccServer)
......@@ -844,7 +844,7 @@ namespace RTC
// Check if Transport Congestion Control client must be created.
const auto& rtpHeaderExtensionIds = consumer->GetRtpHeaderExtensionIds();
auto& codecs = consumer->GetRtpParameters().codecs;
const auto& codecs = consumer->GetRtpParameters().codecs;
// Set TransportCongestionControlClient.
if (!this->tccClient)
......@@ -1412,8 +1412,8 @@ namespace RTC
}
auto ppid = jsonPpidIt->get<uint32_t>();
auto* msg = notification->payload;
auto len = notification->payloadLen;
const auto* msg = notification->payload;
if (len > this->maxMessageSize)
{
......@@ -2441,7 +2441,7 @@ namespace RTC
SendRtpPacket(packet, cb);
#else
auto* cb = new onSendCallback([tccClient, &packetInfo](bool sent) {
const auto* cb = new onSendCallback([tccClient, &packetInfo](bool sent) {
if (sent)
tccClient->PacketSent(packetInfo, DepLibUV::GetTimeMsInt64());
});
......@@ -2509,7 +2509,7 @@ namespace RTC
SendRtpPacket(packet, cb);
#else
auto* cb = new onSendCallback([tccClient, &packetInfo](bool sent) {
const auto* cb = new onSendCallback([tccClient, &packetInfo](bool sent) {
if (sent)
tccClient->PacketSent(packetInfo, DepLibUV::GetTimeMsInt64());
});
......@@ -2840,7 +2840,7 @@ namespace RTC
SendRtpPacket(packet, cb);
#else
auto* cb = new onSendCallback([tccClient, &packetInfo](bool sent) {
const auto* cb = new onSendCallback([tccClient, &packetInfo](bool sent) {
if (sent)
tccClient->PacketSent(packetInfo, DepLibUV::GetTimeMsInt64());
});
......
......@@ -508,13 +508,8 @@ namespace RTC
break;
}
case RTC::DtlsTransport::Role::SERVER:
{
this->dtlsRole = RTC::DtlsTransport::Role::CLIENT;
break;
}
// If the peer has role "auto" we become "client" since we are ICE controlled.
case RTC::DtlsTransport::Role::SERVER:
case RTC::DtlsTransport::Role::AUTO:
{
this->dtlsRole = RTC::DtlsTransport::Role::CLIENT;
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论