提交 88a399d4 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

C++: add brackers in if () conditions in all .cpp files

上级 b65509ef
......@@ -10,8 +10,7 @@ void Fuzzer::RTC::RTCP::FeedbackPsFir::Fuzz(::RTC::RTCP::FeedbackPsFirPacket* pa
// TODO.
// AddItem(Item* item);
auto it = packet->Begin();
for (; it != packet->End(); ++it)
for (auto it = packet->Begin(); it != packet->End(); ++it)
{
auto& item = (*it);
......
......@@ -10,8 +10,7 @@ void Fuzzer::RTC::RTCP::FeedbackPsLei::Fuzz(::RTC::RTCP::FeedbackPsLeiPacket* pa
// TODO.
// AddItem(Item* item);
auto it = packet->Begin();
for (; it != packet->End(); ++it)
for (auto it = packet->Begin(); it != packet->End(); ++it)
{
auto& item = (*it);
......
......@@ -10,8 +10,7 @@ void Fuzzer::RTC::RTCP::FeedbackPsRpsi::Fuzz(::RTC::RTCP::FeedbackPsRpsiPacket*
// TODO.
// AddItem(Item* item);
auto it = packet->Begin();
for (; it != packet->End(); ++it)
for (auto it = packet->Begin(); it != packet->End(); ++it)
{
auto& item = (*it);
......
......@@ -10,8 +10,7 @@ void Fuzzer::RTC::RTCP::FeedbackPsSli::Fuzz(::RTC::RTCP::FeedbackPsSliPacket* pa
// TODO.
// AddItem(Item* item);
auto it = packet->Begin();
for (; it != packet->End(); ++it)
for (auto it = packet->Begin(); it != packet->End(); ++it)
{
auto& item = (*it);
......
......@@ -10,8 +10,7 @@ void Fuzzer::RTC::RTCP::FeedbackPsTstn::Fuzz(::RTC::RTCP::FeedbackPsTstnPacket*
// TODO.
// AddItem(Item* item);
auto it = packet->Begin();
for (; it != packet->End(); ++it)
for (auto it = packet->Begin(); it != packet->End(); ++it)
{
auto& item = (*it);
......@@ -34,8 +33,7 @@ void Fuzzer::RTC::RTCP::FeedbackPsTstr::Fuzz(::RTC::RTCP::FeedbackPsTstrPacket*
// TODO.
// AddItem(Item* item);
auto it = packet->Begin();
for (; it != packet->End(); ++it)
for (auto it = packet->Begin(); it != packet->End(); ++it)
{
auto& item = (*it);
......
......@@ -12,8 +12,7 @@ void Fuzzer::RTC::RTCP::FeedbackPsVbcm::Fuzz(::RTC::RTCP::FeedbackPsVbcmPacket*
// TODO.
// AddItem(Item* item);
auto it = packet->Begin();
for (; it != packet->End(); ++it)
for (auto it = packet->Begin(); it != packet->End(); ++it)
{
auto& item = (*it);
......
......@@ -10,8 +10,7 @@ void Fuzzer::RTC::RTCP::FeedbackRtpEcn::Fuzz(::RTC::RTCP::FeedbackRtpEcnPacket*
// TODO.
// AddItem(Item* item);
auto it = packet->Begin();
for (; it != packet->End(); ++it)
for (auto it = packet->Begin(); it != packet->End(); ++it)
{
auto& item = (*it);
......
......@@ -10,8 +10,7 @@ void Fuzzer::RTC::RTCP::FeedbackRtpNack::Fuzz(::RTC::RTCP::FeedbackRtpNackPacket
// TODO.
// AddItem(Item* item);
auto it = packet->Begin();
for (; it != packet->End(); ++it)
for (auto it = packet->Begin(); it != packet->End(); ++it)
{
auto& item = (*it);
......
......@@ -10,8 +10,7 @@ void Fuzzer::RTC::RTCP::FeedbackRtpTllei::Fuzz(::RTC::RTCP::FeedbackRtpTlleiPack
// TODO.
// AddItem(Item* item);
auto it = packet->Begin();
for (; it != packet->End(); ++it)
for (auto it = packet->Begin(); it != packet->End(); ++it)
{
auto& item = (*it);
......
......@@ -10,8 +10,7 @@ void Fuzzer::RTC::RTCP::FeedbackRtpTmmbn::Fuzz(::RTC::RTCP::FeedbackRtpTmmbnPack
// TODO.
// AddItem(Item* item);
auto it = packet->Begin();
for (; it != packet->End(); ++it)
for (auto it = packet->Begin(); it != packet->End(); ++it)
{
auto& item = (*it);
......@@ -37,8 +36,7 @@ void Fuzzer::RTC::RTCP::FeedbackRtpTmmbr::Fuzz(::RTC::RTCP::FeedbackRtpTmmbrPack
// TODO.
// AddItem(Item* item);
auto it = packet->Begin();
for (; it != packet->End(); ++it)
for (auto it = packet->Begin(); it != packet->End(); ++it)
{
auto& item = (*it);
......
......@@ -11,7 +11,9 @@
void Fuzzer::RTC::RTCP::Packet::Fuzz(const uint8_t* data, size_t len)
{
if (!::RTC::RTCP::Packet::IsRtcp(data, len))
{
return;
}
// We need to clone the given data into a separate buffer because setters
// below will try to write into packet memory.
......@@ -22,7 +24,9 @@ void Fuzzer::RTC::RTCP::Packet::Fuzz(const uint8_t* data, size_t len)
::RTC::RTCP::Packet* packet = ::RTC::RTCP::Packet::Parse(data2, len);
if (!packet)
{
return;
}
while (packet != nullptr)
{
......
......@@ -14,8 +14,7 @@ void Fuzzer::RTC::RTCP::ReceiverReport::Fuzz(::RTC::RTCP::ReceiverReportPacket*
// TODO.
// AddReport(ReceiverReport* report);
auto it = packet->Begin();
for (; it != packet->End(); ++it)
for (auto it = packet->Begin(); it != packet->End(); ++it)
{
auto& report = (*it);
......
......@@ -10,8 +10,7 @@ void Fuzzer::RTC::RTCP::Sdes::Fuzz(::RTC::RTCP::SdesPacket* packet)
// TODO.
// AddChunk(SdesChunk* chunk);
auto it = packet->Begin();
for (; it != packet->End(); ++it)
for (auto it = packet->Begin(); it != packet->End(); ++it)
{
auto& chunk = (*it);
......@@ -24,15 +23,13 @@ void Fuzzer::RTC::RTCP::Sdes::Fuzz(::RTC::RTCP::SdesPacket* packet)
// TODO
// AddItem(SdesItem* item);
auto it2 = chunk->Begin();
for (; it2 != chunk->End(); ++it2)
for (auto it2 = chunk->Begin(); it2 != chunk->End(); ++it2)
{
auto& item = (*it2);
// item->Dump();
item->Serialize(::RTC::RTCP::Buffer);
item->GetSize();
item->GetType();
item->GetLength();
item->GetValue();
......
......@@ -5,7 +5,9 @@ void Fuzzer::RTC::RTCP::SenderReport::Fuzz(::RTC::RTCP::SenderReportPacket* pack
{
// A well formed packet must have a single report.
if (packet->GetCount() == 1)
{
packet->Serialize(::RTC::RTCP::Buffer);
}
// packet->Dump();
packet->GetCount();
......@@ -14,8 +16,7 @@ void Fuzzer::RTC::RTCP::SenderReport::Fuzz(::RTC::RTCP::SenderReportPacket* pack
// TODO.
// AddReport(SenderReport* report);
auto it = packet->Begin();
for (; it != packet->End(); ++it)
for (auto it = packet->Begin(); it != packet->End(); ++it)
{
auto& report = (*it);
......
......@@ -10,8 +10,7 @@ void Fuzzer::RTC::RTCP::ExtendedReport::Fuzz(::RTC::RTCP::ExtendedReportPacket*
packet->GetSsrc();
packet->SetSsrc(1111);
auto it = packet->Begin();
for (; it != packet->End(); ++it)
for (auto it = packet->Begin(); it != packet->End(); ++it)
{
auto& report = (*it);
......
......@@ -79,7 +79,9 @@ namespace Channel
MS_TRACE_STD();
if (!this->closed)
{
Close();
}
delete this->consumerSocket;
delete this->producerSocket;
......@@ -90,7 +92,9 @@ namespace Channel
MS_TRACE_STD();
if (this->closed)
{
return;
}
this->closed = true;
......@@ -123,7 +127,9 @@ namespace Channel
MS_TRACE_STD();
if (this->closed)
{
return;
}
if (messageLen > PayloadMaxLen)
{
......@@ -140,7 +146,9 @@ namespace Channel
MS_TRACE_STD();
if (this->closed)
{
return;
}
if (messageLen > PayloadMaxLen)
{
......@@ -163,7 +171,9 @@ namespace Channel
MS_TRACE_STD();
if (this->closed)
{
return false;
}
uint8_t* msg{ nullptr };
uint32_t msgLen;
......@@ -342,7 +352,9 @@ namespace Channel
while (true)
{
if (IsClosed())
{
return;
}
size_t readLen = this->bufferDataLen - msgStart;
......
......@@ -106,9 +106,13 @@ namespace RTC
this->interval = options->interval();
if (this->interval < 100)
{
this->interval = 100;
}
else if (this->interval > 5000)
{
this->interval = 5000;
}
this->periodicTimer = new TimerHandle(this);
......@@ -145,10 +149,14 @@ namespace RTC
MS_TRACE();
if (producer->GetKind() != RTC::Media::Kind::AUDIO)
{
MS_THROW_TYPE_ERROR("not an audio Producer");
}
if (this->mapProducerSpeakers.find(producer->id) != this->mapProducerSpeakers.end())
{
MS_THROW_ERROR("Producer already in map");
}
this->mapProducerSpeakers[producer->id] = new ProducerSpeaker(producer);
}
......@@ -211,13 +219,18 @@ namespace RTC
MS_TRACE();
if (IsPaused())
{
return;
}
uint8_t level;
bool voice;
if (!packet->ReadSsrcAudioLevel(level, voice))
{
return;
}
uint8_t volume = 127 - level;
auto it = this->mapProducerSpeakers.find(producer->id);
......
......@@ -27,12 +27,18 @@ namespace RTC
this->interval = options->interval();
if (this->threshold > 0)
{
MS_THROW_TYPE_ERROR("invalid threshold value %" PRIi8, this->threshold);
}
if (this->interval < 250)
{
this->interval = 250;
}
else if (this->interval > 5000)
{
this->interval = 5000;
}
this->periodicTimer = new TimerHandle(this);
......@@ -59,7 +65,9 @@ namespace RTC
MS_TRACE();
if (producer->GetKind() != RTC::Media::Kind::AUDIO)
{
MS_THROW_TYPE_ERROR("not an audio Producer");
}
// Insert into the map.
this->mapProducerDBovs[producer];
......@@ -78,13 +86,17 @@ namespace RTC
MS_TRACE();
if (IsPaused())
{
return;
}
uint8_t volume;
bool voice;
if (!packet->ReadSsrcAudioLevel(volume, voice))
{
return;
}
auto& dBovs = this->mapProducerDBovs.at(producer);
......
......@@ -170,11 +170,17 @@ namespace RTC
this->d,
this->b);
if (this->hasTid)
{
MS_DUMP(" tid : %" PRIu8, this->tid);
}
if (this->hasLid)
{
MS_DUMP(" lid : %" PRIu8, this->lid);
}
if (this->hasTl0picidx)
{
MS_DUMP(" tl0picidx : %" PRIu8, this->tl0picidx);
}
MS_DUMP(" isKeyFrame : %s", this->isKeyFrame ? "true" : "false");
MS_DUMP("</PayloadDescriptor>");
}
......
......@@ -16,7 +16,9 @@ namespace RTC
MS_TRACE();
if (len < 2)
{
return nullptr;
}
std::unique_ptr<PayloadDescriptor> payloadDescriptor(new PayloadDescriptor());
......@@ -47,7 +49,9 @@ namespace RTC
// Detect key frame.
if (frameMarking->start && frameMarking->independent)
{
payloadDescriptor->isKeyFrame = true;
}
}
// NOTE: Unfortunately libwebrtc produces wrong Frame-Marking (without i=1 in
......@@ -74,7 +78,9 @@ namespace RTC
H264_SVC::ParseSingleNalu(data, len, std::move(payloadDescriptor), true);
if (payloadDescriptor == nullptr)
{
return nullptr;
}
break;
}
......@@ -97,8 +103,11 @@ namespace RTC
(len - sizeof(naluSize)),
std::move(payloadDescriptor),
true);
if (payloadDescriptor == nullptr)
{
return nullptr;
}
if (payloadDescriptor->isKeyFrame)
{
......@@ -107,7 +116,9 @@ namespace RTC
// Check if there is room for the indicated NAL unit size.
if (len < (naluSize + sizeof(naluSize)))
{
break;
}
offset += naluSize + sizeof(naluSize);
len -= naluSize + sizeof(naluSize);
......@@ -128,8 +139,11 @@ namespace RTC
payloadDescriptor = H264_SVC::ParseSingleNalu(
(data + 1), (len - 1), std::move(payloadDescriptor), (startBit == 128 ? true : false));
}
if (payloadDescriptor == nullptr)
{
return nullptr;
}
break;
}
......@@ -174,14 +188,18 @@ namespace RTC
payloadDescriptor->isKeyFrame = (isStartBit && payloadDescriptor->idr) ? true : false;
if (len < ++offset + 1)
{
return nullptr;
}
byte = data[offset];
payloadDescriptor->noIntLayerPredFlag = byte >> 7 & 0x01;
payloadDescriptor->slIndex = byte >> 4 & 0x03;
if (len < ++offset + 1)
{
return nullptr;
}
byte = data[offset];
......@@ -218,7 +236,9 @@ namespace RTC
H264_SVC::Parse(data, len, frameMarking, frameMarkingLen);
if (!payloadDescriptor)
{
return;
}
auto* payloadDescriptorHandler = new PayloadDescriptorHandler(payloadDescriptor);
......@@ -352,7 +372,9 @@ namespace RTC
// Filter spatial layers higher than current one (unless old packet).
if (packetSpatialLayer > tmpSpatialLayer && !isOldPacket)
{
return false;
}
// Check and handle temporal layer (unless old packet).
if (!isOldPacket)
......@@ -402,20 +424,28 @@ namespace RTC
// Filter temporal layers higher than current one.
if (packetTemporalLayer > tmpTemporalLayer)
{
return false;
}
}
// Set marker bit if needed.
if (packetSpatialLayer == tmpSpatialLayer && this->payloadDescriptor->e)
{
marker = true;
}
// Update current spatial layer if needed.
if (tmpSpatialLayer != context->GetCurrentSpatialLayer())
{
context->SetCurrentSpatialLayer(tmpSpatialLayer);
}
// Update current temporal layer if needed.
if (tmpTemporalLayer != context->GetCurrentTemporalLayer())
{
context->SetCurrentTemporalLayer(tmpTemporalLayer);
}
return true;
}
......
......@@ -31,6 +31,7 @@ namespace RTC
break;
}
case FBS::DataProducer::Type::DIRECT:
{
this->type = DataProducer::Type::DIRECT;
......
......@@ -20,16 +20,24 @@ namespace RTC
switch (state)
{
case FBS::WebRtcTransport::IceState::NEW:
{
return IceServer::IceState::NEW;
}
case FBS::WebRtcTransport::IceState::CONNECTED:
{
return IceServer::IceState::CONNECTED;
}
case FBS::WebRtcTransport::IceState::COMPLETED:
{
return IceServer::IceState::COMPLETED;
}
case FBS::WebRtcTransport::IceState::DISCONNECTED:
{
return IceServer::IceState::DISCONNECTED;
}
}
}
......
......@@ -24,7 +24,9 @@ namespace RTC
// Ensure there are as many encodings as consumable encodings.
if (this->rtpParameters.encodings.size() != this->consumableRtpEncodings.size())
{
MS_THROW_TYPE_ERROR("number of rtpParameters.encodings and consumableRtpEncodings do not match");
}
auto& encoding = this->rtpParameters.encodings[0];
const auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
......@@ -124,7 +126,9 @@ namespace RTC
case Channel::ChannelRequest::Method::CONSUMER_REQUEST_KEY_FRAME:
{
if (IsActive())
{
RequestKeyFrame();
}
request->Accept();
......@@ -258,7 +262,9 @@ namespace RTC
if (isSyncPacket)
{
if (packet->IsKeyFrame())
{
MS_DEBUG_TAG(rtp, "sync key frame received");
}
rtpSeqManager.Sync(packet->GetSequenceNumber() - 1);
......@@ -346,7 +352,9 @@ namespace RTC
auto* report = rtpStream->GetRtcpSenderReport(nowMs);
if (!report)
{
continue;
}
senderReports.push_back(report);
......@@ -367,7 +375,9 @@ namespace RTC
// RTCP Compound packet buffer cannot hold the data.
if (!packet->Add(senderReports, sdesChunks, xrReports))
{
return false;
}
this->lastRtcpSentTime = nowMs;
......@@ -379,7 +389,9 @@ namespace RTC
MS_TRACE();
if (!IsActive())
{
return;
}
for (auto* rtpStream : this->rtpStreams)
{
......@@ -387,7 +399,9 @@ namespace RTC
// If our fraction lost is worse than the given one, update it.
if (fractionLost > worstRemoteFractionLost)
{
worstRemoteFractionLost = fractionLost;
}
}
}
......@@ -396,7 +410,9 @@ namespace RTC
MS_TRACE();
if (!IsActive())
{
return;
}
// May emit 'trace' event.
EmitTraceEventNackType();
......@@ -435,7 +451,9 @@ namespace RTC
rtpStream->ReceiveKeyFrameRequest(messageType);
if (IsActive())
{
RequestKeyFrame();
}
}
void PipeConsumer::ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report)
......@@ -462,7 +480,9 @@ namespace RTC
MS_TRACE();
if (!IsActive())
{
return 0u;
}
uint32_t rate{ 0u };
......@@ -483,7 +503,9 @@ namespace RTC
for (auto* rtpStream : this->rtpStreams)
{
if (rtpStream->GetRtt() > rtt)
{
rtt = rtpStream->GetRtt();
}
}
return rtt;
......@@ -626,12 +648,16 @@ namespace RTC
// If the Consumer is paused, tell the RtpStreamSend.
if (IsPaused() || IsProducerPaused())
{
rtpStream->Pause();
}
const auto* rtxCodec = this->rtpParameters.GetRtxCodecForEncoding(encoding);
if (rtxCodec && encoding.hasRtx)
{
rtpStream->SetRtx(rtxCodec->payloadType, encoding.rtx.ssrc);
}
this->rtpStreams.push_back(rtpStream);
this->mapMappedSsrcSsrc[consumableEncoding.ssrc] = encoding.ssrc;
......@@ -646,7 +672,9 @@ namespace RTC
MS_TRACE();
if (this->kind != RTC::Media::Kind::VIDEO)
{
return;
}
for (auto& consumableRtpEncoding : this->consumableRtpEncodings)
{
......
......@@ -266,7 +266,9 @@ namespace RTC
{
// Ensure this method is not called twice.
if (this->tuple)
{
MS_THROW_ERROR("connect() already called");
}
try
{
......@@ -306,7 +308,9 @@ namespace RTC
auto* srtpKey = Utils::String::Base64Decode(srtpKeyBase64, outLen);
if (outLen != PipeTransport::srtpMasterLength)
{
MS_THROW_TYPE_ERROR("invalid decoded SRTP key length");
}
auto* srtpLocalKey = new uint8_t[PipeTransport::srtpMasterLength];
auto* srtpRemoteKey = new uint8_t[PipeTransport::srtpMasterLength];
......@@ -351,7 +355,9 @@ namespace RTC
}
if (!flatbuffers::IsFieldPresent(body, FBS::PipeTransport::ConnectRequest::VT_IP))
{
MS_THROW_TYPE_ERROR("missing ip");
}
ip = body->ip()->str();
......@@ -377,7 +383,9 @@ namespace RTC
reinterpret_cast<struct sockaddr_in*>(&this->remoteAddrStorage));
if (err != 0)
{
MS_THROW_ERROR("uv_ip4_addr() failed: %s", uv_strerror(err));
}
break;
}
......@@ -390,7 +398,9 @@ namespace RTC
reinterpret_cast<struct sockaddr_in6*>(&this->remoteAddrStorage));
if (err != 0)
{
MS_THROW_ERROR("uv_ip6_addr() failed: %s", uv_strerror(err));
}
break;
}
......@@ -507,13 +517,17 @@ namespace RTC
MS_TRACE();
if (!IsConnected())
{
return;
}
const uint8_t* data = packet->GetData();
auto intLen = static_cast<int>(packet->GetSize());
if (HasSrtp() && !this->srtpSendSession->EncryptRtcp(&data, &intLen))
{
return;
}
auto len = static_cast<size_t>(intLen);
......@@ -528,7 +542,9 @@ namespace RTC
MS_TRACE();
if (!IsConnected())
{
return;
}
packet->Serialize(RTC::RTCP::Buffer);
......@@ -536,7 +552,9 @@ namespace RTC
auto intLen = static_cast<int>(packet->GetSize());
if (HasSrtp() && !this->srtpSendSession->EncryptRtcp(&data, &intLen))
{
return;
}
auto len = static_cast<size_t>(intLen);
......@@ -559,7 +577,9 @@ namespace RTC
MS_TRACE();
if (!IsConnected())
{
return;
}
this->tuple->Send(data, len);
......@@ -620,7 +640,9 @@ namespace RTC
MS_TRACE();
if (!IsConnected())
{
return;
}
// Decrypt the SRTP packet.
auto intLen = static_cast<int>(len);
......@@ -680,7 +702,9 @@ namespace RTC
MS_TRACE();
if (!IsConnected())
{
return;
}
// Decrypt the SRTCP packet.
auto intLen = static_cast<int>(len);
......@@ -717,7 +741,9 @@ namespace RTC
MS_TRACE();
if (!IsConnected())
{
return;
}
// Verify that the packet's tuple matches our tuple.
if (!this->tuple->Compare(tuple))
......
......@@ -75,7 +75,9 @@ namespace RTC
err = uv_ip4_addr(ip.c_str(), 0, reinterpret_cast<struct sockaddr_in*>(&bindAddr));
if (err != 0)
{
MS_THROW_ERROR("uv_ip4_addr() failed: %s", uv_strerror(err));
}
break;
}
......@@ -85,7 +87,9 @@ namespace RTC
err = uv_ip6_addr(ip.c_str(), 0, reinterpret_cast<struct sockaddr_in6*>(&bindAddr));
if (err != 0)
{
MS_THROW_ERROR("uv_ip6_addr() failed: %s", uv_strerror(err));
}
// Don't also bind into IPv4 when listening in IPv6.
flags |= UV_UDP_IPV6ONLY;
......@@ -277,7 +281,9 @@ namespace RTC
// If it succeeded, exit the loop here.
if (err == 0)
{
break;
}
// If it failed, close the handle and check the reason.
switch (transport)
......@@ -382,7 +388,9 @@ namespace RTC
err = uv_ip4_addr(ip.c_str(), 0, reinterpret_cast<struct sockaddr_in*>(&bindAddr));
if (err != 0)
{
MS_THROW_ERROR("uv_ip4_addr() failed: %s", uv_strerror(err));
}
break;
}
......@@ -392,7 +400,9 @@ namespace RTC
err = uv_ip6_addr(ip.c_str(), 0, reinterpret_cast<struct sockaddr_in6*>(&bindAddr));
if (err != 0)
{
MS_THROW_ERROR("uv_ip6_addr() failed: %s", uv_strerror(err));
}
// Don't also bind into IPv4 when listening in IPv6.
flags |= UV_UDP_IPV6ONLY;
......@@ -558,7 +568,9 @@ namespace RTC
auto it = PortManager::mapUdpIpPorts.find(ip);
if (it == PortManager::mapUdpIpPorts.end())
{
return;
}
auto& ports = it->second;
......@@ -573,7 +585,9 @@ namespace RTC
auto it = PortManager::mapTcpIpPorts.find(ip);
if (it == PortManager::mapTcpIpPorts.end())
{
return;
}
auto& ports = it->second;
......
......@@ -42,7 +42,9 @@ namespace RTC
offset += 1u;
if (length <= len - offset)
{
packet->SetReason(std::string(reinterpret_cast<const char*>(data) + offset, length));
}
}
return packet.release();
......@@ -95,7 +97,9 @@ namespace RTC
MS_DUMP(" ssrc : %" PRIu32, ssrc);
}
if (!this->reason.empty())
{
MS_DUMP(" reason : %s", this->reason.c_str());
}
MS_DUMP("</ByePacket>");
}
} // namespace RTCP
......
......@@ -18,16 +18,21 @@ namespace RTC
{
size += this->senderReportPacket.GetSize();
}
if (this->receiverReportPacket.GetCount() > 0u)
{
size += this->receiverReportPacket.GetSize();
}
if (this->sdesPacket.GetCount() > 0u)
{
size += this->sdesPacket.GetSize();
}
if (this->xrPacket.Begin() != this->xrPacket.End())
{
size += this->xrPacket.GetSize();
}
return size;
}
......@@ -72,17 +77,25 @@ namespace RTC
// Add the items into the packet.
if (senderReport)
{
this->senderReportPacket.AddReport(senderReport);
}
if (sdesChunk)
{
this->sdesPacket.AddChunk(sdesChunk);
}
if (delaySinceLastRrReport)
{
this->xrPacket.AddReport(delaySinceLastRrReport);
}
// New items can hold in the packet, report it.
if (GetSize() <= MaxSize)
{
return true;
}
// New items can not hold in the packet, remove them,
// delete and report it.
......@@ -126,7 +139,9 @@ namespace RTC
// New items can hold in the packet, report it.
if (GetSize() <= MaxSize)
{
return true;
}
// New items can not hold in the packet, remove them,
// delete and report it.
......@@ -162,11 +177,15 @@ namespace RTC
this->receiverReportPacket.AddReport(report);
if (receiverReferenceTimeReport)
{
this->xrPacket.AddReport(receiverReferenceTimeReport);
}
// New items can hold in the packet, report it.
if (GetSize() <= MaxSize)
{
return true;
}
// New items can not hold in the packet, remove them,
// delete and report it.
......@@ -197,7 +216,9 @@ namespace RTC
this->senderReportPacket.Dump();
if (this->receiverReportPacket.GetCount() != 0u)
{
this->receiverReportPacket.Dump();
}
}
else
{
......@@ -205,10 +226,14 @@ namespace RTC
}
if (this->sdesPacket.GetCount() != 0u)
{
this->sdesPacket.Dump();
}
if (this->xrPacket.Begin() != this->xrPacket.End())
{
this->xrPacket.Dump();
}
MS_DUMP("</CompoundPacket>");
}
......
......@@ -34,7 +34,9 @@ namespace RTC
auto it = FeedbackPacket<T>::type2String.find(type);
if (it == FeedbackPacket<T>::type2String.end())
{
return Unknown;
}
return it->second;
}
......
......@@ -32,7 +32,9 @@ namespace RTC
std::unique_ptr<FeedbackPsRembPacket> packet(new FeedbackPsRembPacket(commonHeader, len));
if (!packet->IsCorrect())
{
return nullptr;
}
return packet.release();
}
......
......@@ -76,14 +76,18 @@ namespace RTC
current = SenderReportPacket::Parse(data, packetLen);
if (!current)
{
break;
}
if (header->count > 0)
{
Packet* rr = ReceiverReportPacket::Parse(data, packetLen, current->GetSize());
if (!rr)
{
break;
}
current->SetNext(rr);
}
......@@ -172,9 +176,13 @@ namespace RTC
len -= packetLen;
if (!first)
{
first = current;
}
else
{
last->SetNext(current);
}
last = current->GetNext() != nullptr ? current->GetNext() : current;
}
......@@ -191,7 +199,9 @@ namespace RTC
auto it = Packet::type2String.find(type);
if (it == Packet::type2String.end())
{
return Unknown;
}
return it->second;
}
......
......@@ -92,7 +92,9 @@ namespace RTC
packet->SetSsrc(ssrc);
if (offset == 0)
{
offset = Packet::CommonHeaderSize + 4u /* ssrc */;
}
uint8_t count = header->count;
......
......@@ -70,7 +70,9 @@ namespace RTC
SenderReport* report = SenderReport::Parse(data + offset, len - offset);
if (report)
{
packet->AddReport(report);
}
return packet.release();
}
......
......@@ -13,7 +13,9 @@ namespace RTC
// Ignore too old data. Should never happen.
if (nowMs < this->oldestItemStartTime)
{
return;
}
// Increase bytes.
this->bytes += size;
......@@ -26,8 +28,11 @@ namespace RTC
{
this->newestItemIndex++;
this->newestItemStartTime = nowMs;
if (this->newestItemIndex >= this->windowItems)
{
this->newestItemIndex = 0;
}
MS_ASSERT(
this->newestItemIndex != this->oldestItemIndex || this->oldestItemIndex == -1,
......@@ -65,7 +70,9 @@ namespace RTC
MS_TRACE();
if (nowMs == this->lastTime)
{
return this->lastRate;
}
RemoveOldData(nowMs);
......@@ -83,13 +90,17 @@ namespace RTC
// No item set.
if (this->newestItemIndex < 0 || this->oldestItemIndex < 0)
{
return;
}
const uint64_t newOldestTime = nowMs - this->windowSizeMs;
// Oldest item already removed.
if (newOldestTime < this->oldestItemStartTime)
{
return;
}
// A whole window size time has elapsed since last entry. Reset the buffer.
if (newOldestTime >= this->newestItemStartTime)
......@@ -107,7 +118,9 @@ namespace RTC
oldestItem.time = 0u;
if (++this->oldestItemIndex >= this->windowItems)
{
this->oldestItemIndex = 0;
}
const BufferItem& newOldestItem = this->buffer[this->oldestItemIndex];
this->oldestItemStartTime = newOldestItem.time;
......
......@@ -246,7 +246,9 @@ namespace RTC
auto* webRtcServer = this->listener->OnRouterNeedWebRtcServer(this, webRtcServerId);
if (!webRtcServer)
{
MS_THROW_ERROR("wrong webRtcServerId (no associated WebRtcServer found)");
}
auto iceCandidates = webRtcServer->GetIceCandidates(
options->enableUdp(), options->enableTcp(), options->preferUdp(), options->preferTcp());
......@@ -443,13 +445,17 @@ namespace RTC
void Router::CheckNoTransport(const std::string& transportId) const
{
if (this->mapTransports.find(transportId) != this->mapTransports.end())
{
MS_THROW_ERROR("a Transport with same id already exists");
}
}
void Router::CheckNoRtpObserver(const std::string& rtpObserverId) const
{
if (this->mapRtpObservers.find(rtpObserverId) != this->mapRtpObservers.end())
{
MS_THROW_ERROR("an RtpObserver with same id already exists");
}
}
RTC::Transport* Router::GetTransportById(const std::string& transportId) const
......@@ -459,7 +465,9 @@ namespace RTC
auto it = this->mapTransports.find(transportId);
if (this->mapTransports.find(transportId) == this->mapTransports.end())
{
MS_THROW_ERROR("Transport not found");
}
return it->second;
}
......@@ -471,7 +479,9 @@ namespace RTC
auto it = this->mapRtpObservers.find(rtpObserverId);
if (this->mapRtpObservers.find(rtpObserverId) == this->mapRtpObservers.end())
{
MS_THROW_ERROR("RtpObserver not found");
}
return it->second;
}
......@@ -656,7 +666,9 @@ namespace RTC
const auto& mid = consumer->GetRtpParameters().mid;
if (!mid.empty())
{
packet->UpdateMid(mid);
}
consumer->SendRtpPacket(packet, sharedPacket);
}
......@@ -699,7 +711,9 @@ namespace RTC
auto mapProducersIt = this->mapProducers.find(producerId);
if (mapProducersIt == this->mapProducers.end())
{
MS_THROW_ERROR("Producer not found [producerId:%s]", producerId.c_str());
}
auto* producer = mapProducersIt->second;
auto mapProducerConsumersIt = this->mapProducerConsumers.find(producer);
......@@ -1025,7 +1039,9 @@ namespace RTC
auto it = this->mapProducers.find(id);
if (it == this->mapProducers.end())
{
MS_THROW_ERROR("Producer not found");
}
RTC::Producer* producer = it->second;
......
......@@ -139,7 +139,9 @@ namespace RTC
auto it = this->mapKeyValues.find(key);
if (it == this->mapKeyValues.end())
{
return false;
}
const auto& value = it->second;
......@@ -153,7 +155,9 @@ namespace RTC
auto it = this->mapKeyValues.find(key);
if (it == this->mapKeyValues.end())
{
return false;
}
const auto& value = it->second;
......@@ -167,7 +171,9 @@ namespace RTC
auto it = this->mapKeyValues.find(key);
if (it == this->mapKeyValues.end())
{
return false;
}
const auto& value = it->second;
......@@ -181,7 +187,9 @@ namespace RTC
auto it = this->mapKeyValues.find(key);
if (it == this->mapKeyValues.end())
{
return false;
}
const auto& value = it->second;
......@@ -195,7 +203,9 @@ namespace RTC
auto it = this->mapKeyValues.find(key);
if (it == this->mapKeyValues.end())
{
return false;
}
const auto& value = it->second;
......@@ -209,7 +219,9 @@ namespace RTC
auto it = this->mapKeyValues.find(key);
if (it == this->mapKeyValues.end())
{
return false;
}
const auto& value = it->second;
......@@ -223,7 +235,9 @@ namespace RTC
auto it = this->mapKeyValues.find(key);
if (it == this->mapKeyValues.end())
{
return false;
}
const auto& value = it->second;
const auto& array = value.arrayOfIntegers;
......
......@@ -16,7 +16,9 @@ namespace RTC
// cname is optional.
if (flatbuffers::IsFieldPresent(data, FBS::RtpParameters::RtcpParameters::VT_CNAME))
{
this->cname = data->cname()->str();
}
// reducedSize is optional, default value is true.
this->reducedSize = data->reducedSize();
......
......@@ -104,7 +104,9 @@ namespace RTC
auto it = RtpCodecMimeType::string2Type.find(type);
if (it == RtpCodecMimeType::string2Type.end())
{
MS_THROW_TYPE_ERROR("unknown codec MIME type '%s'", type.c_str());
}
this->type = it->second;
}
......@@ -114,7 +116,9 @@ namespace RTC
auto it = RtpCodecMimeType::string2Subtype.find(subtype);
if (it == RtpCodecMimeType::string2Subtype.end())
{
MS_THROW_TYPE_ERROR("unknown codec MIME subtype '%s'", subtype.c_str());
}
this->subtype = it->second;
}
......
......@@ -32,7 +32,9 @@ namespace RTC
// parameters is optional.
if (flatbuffers::IsFieldPresent(data, FBS::RtpParameters::RtpCodecParameters::VT_PARAMETERS))
{
this->parameters.Set(data->parameters());
}
// rtcpFeedback is optional.
if (flatbuffers::IsFieldPresent(data, FBS::RtpParameters::RtpCodecParameters::VT_RTCPFEEDBACK))
......@@ -87,7 +89,9 @@ namespace RTC
{
// A RTX codec must have 'apt' parameter.
if (!this->parameters.HasPositiveInteger(aptString))
{
MS_THROW_TYPE_ERROR("missing apt parameter in RTX codec");
}
break;
}
......
......@@ -18,11 +18,15 @@ namespace RTC
// ssrc is optional.
if (data->ssrc().has_value())
{
this->ssrc = data->ssrc().value();
}
// rid is optional.
if (flatbuffers::IsFieldPresent(data, FBS::RtpParameters::RtpEncodingParameters::VT_RID))
{
this->rid = data->rid()->str();
}
// codecPayloadType is optional.
if (data->codecPayloadType().has_value())
......@@ -40,7 +44,9 @@ namespace RTC
// maxBitrate is optional.
if (data->maxBitrate().has_value())
{
this->maxBitrate = data->maxBitrate().value();
}
// dtx is optional, default is false.
this->dtx = data->dtx();
......
......@@ -22,7 +22,9 @@ namespace RTC
// Don't allow id 0.
if (this->id == 0u)
{
MS_THROW_TYPE_ERROR("invalid id 0");
}
// encrypt is false by default.
this->encrypt = data->encrypt();
......
......@@ -15,27 +15,59 @@ namespace RTC
switch (uri)
{
case FBS::RtpParameters::RtpHeaderExtensionUri::Mid:
{
return RtpHeaderExtensionUri::Type::MID;
}
case FBS::RtpParameters::RtpHeaderExtensionUri::RtpStreamId:
{
return RtpHeaderExtensionUri::Type::RTP_STREAM_ID;
}
case FBS::RtpParameters::RtpHeaderExtensionUri::RepairRtpStreamId:
{
return RtpHeaderExtensionUri::Type::REPAIRED_RTP_STREAM_ID;
}
case FBS::RtpParameters::RtpHeaderExtensionUri::FrameMarkingDraft07:
{
return RtpHeaderExtensionUri::Type::FRAME_MARKING_07;
}
case FBS::RtpParameters::RtpHeaderExtensionUri::FrameMarking:
{
return RtpHeaderExtensionUri::Type::FRAME_MARKING;
}
case FBS::RtpParameters::RtpHeaderExtensionUri::AudioLevel:
{
return RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL;
}
case FBS::RtpParameters::RtpHeaderExtensionUri::VideoOrientation:
{
return RtpHeaderExtensionUri::Type::VIDEO_ORIENTATION;
}
case FBS::RtpParameters::RtpHeaderExtensionUri::TimeOffset:
{
return RtpHeaderExtensionUri::Type::TOFFSET;
}
case FBS::RtpParameters::RtpHeaderExtensionUri::TransportWideCcDraft01:
{
return RtpHeaderExtensionUri::Type::TRANSPORT_WIDE_CC_01;
}
case FBS::RtpParameters::RtpHeaderExtensionUri::AbsSendTime:
{
return RtpHeaderExtensionUri::Type::ABS_SEND_TIME;
}
case FBS::RtpParameters::RtpHeaderExtensionUri::AbsCaptureTime:
{
return RtpHeaderExtensionUri::Type::ABS_CAPTURE_TIME;
}
}
}
......@@ -45,27 +77,59 @@ namespace RTC
switch (uri)
{
case RtpHeaderExtensionUri::Type::MID:
{
return FBS::RtpParameters::RtpHeaderExtensionUri::Mid;
}
case RtpHeaderExtensionUri::Type::RTP_STREAM_ID:
{
return FBS::RtpParameters::RtpHeaderExtensionUri::RtpStreamId;
}
case RtpHeaderExtensionUri::Type::REPAIRED_RTP_STREAM_ID:
{
return FBS::RtpParameters::RtpHeaderExtensionUri::RepairRtpStreamId;
}
case RtpHeaderExtensionUri::Type::ABS_SEND_TIME:
{
return FBS::RtpParameters::RtpHeaderExtensionUri::AbsSendTime;
}
case RtpHeaderExtensionUri::Type::TRANSPORT_WIDE_CC_01:
{
return FBS::RtpParameters::RtpHeaderExtensionUri::TransportWideCcDraft01;
}
case RtpHeaderExtensionUri::Type::FRAME_MARKING_07:
{
return FBS::RtpParameters::RtpHeaderExtensionUri::FrameMarkingDraft07;
}
case RtpHeaderExtensionUri::Type::FRAME_MARKING:
{
return FBS::RtpParameters::RtpHeaderExtensionUri::FrameMarking;
}
case RtpHeaderExtensionUri::Type::SSRC_AUDIO_LEVEL:
{
return FBS::RtpParameters::RtpHeaderExtensionUri::AudioLevel;
}
case RtpHeaderExtensionUri::Type::VIDEO_ORIENTATION:
{
return FBS::RtpParameters::RtpHeaderExtensionUri::VideoOrientation;
}
case RtpHeaderExtensionUri::Type::TOFFSET:
{
return FBS::RtpParameters::RtpHeaderExtensionUri::TimeOffset;
}
case RtpHeaderExtensionUri::Type::ABS_CAPTURE_TIME:
{
return FBS::RtpParameters::RtpHeaderExtensionUri::AbsCaptureTime;
}
}
}
......
......@@ -72,13 +72,24 @@ namespace RTC
switch (type)
{
case Type::SIMPLE:
{
return FBS::RtpParameters::Type::SIMPLE;
}
case Type::SIMULCAST:
{
return FBS::RtpParameters::Type::SIMULCAST;
}
case Type::SVC:
{
return FBS::RtpParameters::Type::SVC;
}
case Type::PIPE:
{
return FBS::RtpParameters::Type::PIPE;
}
}
}
......@@ -94,7 +105,9 @@ namespace RTC
this->mid = data->mid()->str();
if (this->mid.empty())
{
MS_THROW_TYPE_ERROR("empty mid");
}
}
this->codecs.reserve(data->codecs()->size());
......@@ -106,7 +119,9 @@ namespace RTC
}
if (this->codecs.empty())
{
MS_THROW_TYPE_ERROR("empty codecs");
}
this->encodings.reserve(data->encodings()->size());
......@@ -117,7 +132,9 @@ namespace RTC
}
if (this->encodings.empty())
{
MS_THROW_TYPE_ERROR("empty encodings");
}
this->headerExtensions.reserve(data->headerExtensions()->size());
......@@ -188,12 +205,16 @@ namespace RTC
const auto& codec = *it;
if (codec.payloadType == payloadType)
{
return std::addressof(codec);
}
}
// This should never happen.
if (it == this->codecs.end())
{
MS_ABORT("no valid codec payload type for the given encoding");
}
return nullptr;
}
......@@ -228,7 +249,9 @@ namespace RTC
for (auto& codec : this->codecs)
{
if (payloadTypes.find(codec.payloadType) != payloadTypes.end())
{
MS_THROW_TYPE_ERROR("duplicated payloadType");
}
payloadTypes.insert(codec.payloadType);
......@@ -248,18 +271,28 @@ namespace RTC
if (static_cast<int32_t>(codec.payloadType) == apt)
{
if (codec.mimeType.subtype == RTC::RtpCodecMimeType::Subtype::RTX)
{
MS_THROW_TYPE_ERROR("apt in RTX codec points to a RTX codec");
}
else if (codec.mimeType.subtype == RTC::RtpCodecMimeType::Subtype::ULPFEC)
{
MS_THROW_TYPE_ERROR("apt in RTX codec points to a ULPFEC codec");
}
else if (codec.mimeType.subtype == RTC::RtpCodecMimeType::Subtype::FLEXFEC)
{
MS_THROW_TYPE_ERROR("apt in RTX codec points to a FLEXFEC codec");
}
else
{
break;
}
}
}
if (it == this->codecs.end())
{
MS_THROW_TYPE_ERROR("apt in RTX codec points to a non existing codec");
}
break;
}
......@@ -290,7 +323,9 @@ namespace RTC
}
if (it == this->codecs.end())
{
MS_THROW_TYPE_ERROR("no media codecs found");
}
}
// Iterate all the encodings, set the first payloadType in all of them with
......@@ -323,14 +358,18 @@ namespace RTC
{
// Must be a media codec.
if (codec.mimeType.IsMediaCodec())
{
break;
}
MS_THROW_TYPE_ERROR("invalid codecPayloadType");
}
}
if (it == this->codecs.end())
{
MS_THROW_TYPE_ERROR("unknown codecPayloadType");
}
}
}
}
......
......@@ -123,7 +123,9 @@ namespace RTC
const auto& rid = encoding.rid;
if (rid.empty())
{
continue;
}
if (this->ridTable.find(rid) == this->ridTable.end())
{
......@@ -148,25 +150,37 @@ namespace RTC
for (auto it = this->ssrcTable.begin(); it != this->ssrcTable.end();)
{
if (it->second == producer)
{
it = this->ssrcTable.erase(it);
}
else
{
++it;
}
}
for (auto it = this->midTable.begin(); it != this->midTable.end();)
{
if (it->second == producer)
{
it = this->midTable.erase(it);
}
else
{
++it;
}
}
for (auto it = this->ridTable.begin(); it != this->ridTable.end();)
{
if (it->second == producer)
{
it = this->ridTable.erase(it);
}
else
{
++it;
}
}
}
......
......@@ -89,7 +89,9 @@ namespace RTC
MS_TRACE();
if (this->paused)
{
return;
}
this->paused = true;
......@@ -101,7 +103,9 @@ namespace RTC
MS_TRACE();
if (!this->paused)
{
return;
}
this->paused = false;
......
......@@ -17,7 +17,9 @@ namespace RTC
MS_TRACE();
if (!RtpPacket::IsRtp(data, len))
{
return nullptr;
}
auto* ptr = const_cast<uint8_t*>(data);
......@@ -136,7 +138,9 @@ namespace RTC
MS_TRACE();
if (this->header->csrcCount != 0u)
{
this->csrcList = reinterpret_cast<uint8_t*>(header) + HeaderSize;
}
// Parse RFC 5285 header extension.
ParseExtensions();
......@@ -408,9 +412,13 @@ namespace RTC
else if (this->headerExtension)
{
if (type == 1u)
{
this->headerExtension->id = uint16_t{ htons(0xBEDE) };
}
else if (type == 2u)
{
this->headerExtension->id = uint16_t{ htons(0b0001000000000000) };
}
}
// Calculate total size required for all extensions (with padding if needed).
......@@ -486,9 +494,13 @@ namespace RTC
// Set the header extension id.
if (type == 1u)
{
this->headerExtension->id = uint16_t{ htons(0xBEDE) };
}
else if (type == 2u)
{
this->headerExtension->id = uint16_t{ htons(0b0001000000000000) };
}
// Set the header extension length.
this->headerExtension->length = htons(extensionsTotalSize / 4);
......@@ -502,7 +514,9 @@ namespace RTC
if (type == 1u)
{
if (extension.id == 0 || extension.id > 14 || extension.len == 0 || extension.len > 16)
{
continue;
}
// Store the One-Byte extension element in an array.
// `-1` because we have 14 elements total 0..13 and `id` is in the range 1..14.
......@@ -516,7 +530,9 @@ namespace RTC
else if (type == 2u)
{
if (extension.id == 0)
{
continue;
}
// Store the Two-Bytes extension element in the map.
this->mapTwoBytesExtensions[extension.id] = reinterpret_cast<TwoBytesExtension*>(ptr);
......@@ -547,7 +563,9 @@ namespace RTC
uint8_t* extenValue = GetExtension(this->midExtensionId, extenLen);
if (!extenValue)
{
return;
}
const size_t midLen = mid.length();
......@@ -593,13 +611,17 @@ namespace RTC
auto* extension = this->oneByteExtensions[id - 1];
if (!extension)
{
return false;
}
auto currentLen = extension->len + 1;
// Fill with 0's if new length is minor.
if (len < currentLen)
{
std::memset(extension->value + len, 0, currentLen - len);
}
// In One-Byte extensions value length 0 means 1.
extension->len = len - 1;
......@@ -611,14 +633,18 @@ namespace RTC
auto it = this->mapTwoBytesExtensions.find(id);
if (it == this->mapTwoBytesExtensions.end())
{
return false;
}
auto* extension = it->second;
auto currentLen = extension->len;
// Fill with 0's if new length is minor.
if (len < currentLen)
{
std::memset(extension->value + len, 0, currentLen - len);
}
extension->len = len;
......@@ -771,7 +797,9 @@ namespace RTC
// Chrome sends some RTX packets with no payload when the stream is started.
// Just ignore them.
if (this->payloadLength < 2u)
{
return false;
}
// Rewrite the payload type.
SetPayloadType(payloadType);
......@@ -808,7 +836,9 @@ namespace RTC
MS_TRACE();
if (!this->payloadDescriptorHandler)
{
return true;
}
if (this->payloadDescriptorHandler->Process(context, this->payload, marker))
{
......@@ -825,7 +855,9 @@ namespace RTC
MS_TRACE();
if (!this->payloadDescriptorHandler)
{
return;
}
this->payloadDescriptorHandler->Restore(this->payload);
}
......@@ -835,12 +867,16 @@ namespace RTC
MS_TRACE();
if (shift == 0u)
{
return;
}
MS_ASSERT(payloadOffset < this->payloadLength, "payload offset bigger than payload size");
if (!expand)
{
MS_ASSERT(shift <= (this->payloadLength - payloadOffset), "shift too big");
}
uint8_t* payloadOffsetPtr = this->payload + payloadOffset;
size_t shiftedLen{ 0 };
......@@ -887,7 +923,9 @@ namespace RTC
// id=15 in One-Byte extensions means "stop parsing here".
if (id == 15u)
{
break;
}
// Valid extension id.
if (id != 0u)
......
......@@ -139,9 +139,13 @@ namespace RTC
// Make the packet length fit into our available limits.
if (size > MaxProbationPacketSize)
{
size = MaxProbationPacketSize;
}
else if (size < ProbationPacketHeaderSize)
{
size = ProbationPacketHeaderSize;
}
// Just send up to StepNumPackets per step.
// Increase RTP seq number and timestamp.
......
......@@ -43,7 +43,9 @@ namespace RTC
flatbuffers::Offset<FBS::RtxStream::RtxDump> rtxStream;
if (HasRtx())
{
rtxStream = this->rtxStream->FillBuffer(builder);
}
return FBS::RtpStream::CreateDump(builder, params, this->score, rtxStream);
}
......@@ -167,11 +169,15 @@ namespace RTC
// If previous score was 0 (and new one is not 0) then update activeSinceMs.
if (previousScore == 0u)
{
this->activeSinceMs = DepLibUV::GetTimeMs();
}
// Notify the listener.
if (notify)
{
this->listener->OnRtpStreamScore(this, score, previousScore);
}
}
}
......@@ -252,7 +258,9 @@ namespace RTC
// Add the score into the histogram.
if (this->scores.size() == ScoreHistogramLength)
{
this->scores.erase(this->scores.begin());
}
auto previousScore = this->score;
......@@ -300,7 +308,9 @@ namespace RTC
// If previous score was 0 (and new one is not 0) then update activeSinceMs.
if (previousScore == 0u)
{
this->activeSinceMs = DepLibUV::GetTimeMs();
}
this->listener->OnRtpStreamScore(this, this->score, previousScore);
}
......
......@@ -95,9 +95,13 @@ namespace RTC
auto expected = GetExpectedPackets();
if (expected > this->packetsCount)
{
this->packetsLost = expected - this->packetsCount;
}
else
{
this->packetsLost = 0u;
}
// Calculate Fraction Lost.
const uint32_t expectedInterval = expected - this->expectedPrior;
......@@ -111,9 +115,13 @@ namespace RTC
const int32_t lostInterval = expectedInterval - receivedInterval;
if (expectedInterval == 0 || lostInterval <= 0)
{
this->fractionLost = 0;
}
else
{
this->fractionLost = std::round((static_cast<double>(lostInterval << 8) / expectedInterval));
}
this->reportedPacketLost += (this->packetsLost - prevPacketsLost);
......
......@@ -293,7 +293,9 @@ namespace RTC
// Just run the SCTP stack if our state is 'new'.
if (this->state != SctpState::NEW)
{
return;
}
try
{
......@@ -311,7 +313,9 @@ namespace RTC
ret = usrsctp_connect(this->socket, reinterpret_cast<struct sockaddr*>(&rconn), sizeof(rconn));
if (ret < 0 && errno != EINPROGRESS)
{
MS_THROW_ERROR("usrsctp_connect() failed: %s", std::strerror(errno));
}
// Disable MTU discovery.
sctp_paddrparams peerAddrParams; // NOLINT(cppcoreguidelines-pro-type-member-init)
......@@ -328,7 +332,9 @@ namespace RTC
this->socket, IPPROTO_SCTP, SCTP_PEER_ADDR_PARAMS, &peerAddrParams, sizeof(peerAddrParams));
if (ret < 0)
{
MS_THROW_ERROR("usrsctp_setsockopt(SCTP_PEER_ADDR_PARAMS) failed: %s", std::strerror(errno));
}
// Announce connecting state.
this->state = SctpState::CONNECTING;
......@@ -485,7 +491,9 @@ namespace RTC
// We need more OS.
if (streamId > this->os - 1)
{
AddOutgoingStreams(/*force*/ false);
}
}
void SctpAssociation::DataProducerClosed(RTC::DataProducer* dataProducer)
......@@ -497,9 +505,13 @@ namespace RTC
// Send SCTP_RESET_STREAMS to the remote.
// https://tools.ietf.org/html/draft-ietf-rtcweb-data-channel-13#section-6.7
if (this->isDataChannel)
{
ResetSctpStream(streamId, StreamDirection::OUTGOING);
}
else
{
ResetSctpStream(streamId, StreamDirection::INCOMING);
}
}
void SctpAssociation::DataConsumerClosed(RTC::DataConsumer* dataConsumer)
......@@ -518,7 +530,9 @@ namespace RTC
// Do nothing if an outgoing stream that could not be allocated by us.
if (direction == StreamDirection::OUTGOING && streamId > this->os - 1)
{
return;
}
int ret;
struct sctp_assoc_value av; // NOLINT(cppcoreguidelines-pro-type-member-init)
......@@ -585,9 +599,13 @@ namespace RTC
uint16_t additionalOs{ 0 };
if (MaxSctpStreams - this->os >= 32)
{
additionalOs = 32;
}
else
{
additionalOs = MaxSctpStreams - this->os;
}
if (additionalOs == 0)
{
......@@ -600,7 +618,9 @@ namespace RTC
// Already in progress, ignore (unless forced).
if (!force && nextDesiredOs == this->desiredOs)
{
return;
}
// Update desired value.
this->desiredOs = nextDesiredOs;
......@@ -625,7 +645,9 @@ namespace RTC
this->socket, IPPROTO_SCTP, SCTP_ADD_STREAMS, &sas, static_cast<socklen_t>(sizeof(sas)));
if (ret < 0)
{
MS_WARN_TAG(sctp, "usrsctp_setsockopt(SCTP_ADD_STREAMS) failed: %s", std::strerror(errno));
}
}
void SctpAssociation::OnUsrSctpSendSctpData(void* buffer, size_t len)
......@@ -708,7 +730,9 @@ namespace RTC
{
// Allocate the buffer if not already done.
if (!this->messageBuffer)
{
this->messageBuffer = new uint8_t[this->maxSctpMessageSize];
}
std::memcpy(this->messageBuffer + this->messageBufferLen, data, len);
this->messageBufferLen += len;
......@@ -720,7 +744,9 @@ namespace RTC
void SctpAssociation::OnUsrSctpReceiveSctpNotification(union sctp_notification* notification, size_t len)
{
if (notification->sn_header.sn_length != (uint32_t)len)
{
return;
}
switch (notification->sn_header.sn_type)
{
......@@ -751,7 +777,9 @@ namespace RTC
// Increase if requested before connected.
if (this->desiredOs > this->os)
{
AddOutgoingStreams(/*force*/ true);
}
if (this->state != SctpState::CONNECTED)
{
......@@ -807,7 +835,9 @@ namespace RTC
// Increase if requested before connected.
if (this->desiredOs > this->os)
{
AddOutgoingStreams(/*force*/ true);
}
if (this->state != SctpState::CONNECTED)
{
......@@ -947,10 +977,14 @@ namespace RTC
sizeof(uint16_t);
if (notification->sn_strreset_event.strreset_flags & SCTP_STREAM_RESET_INCOMING_SSN)
{
incoming = true;
}
if (notification->sn_strreset_event.strreset_flags & SCTP_STREAM_RESET_OUTGOING_SSN)
{
outgoing = true;
}
if (MS_HAS_DEBUG_TAG(sctp))
{
......@@ -969,7 +1003,9 @@ namespace RTC
}
if (i > 0)
{
streamIds.append(",");
}
streamIds.append(std::to_string(streamId));
}
......
......@@ -17,7 +17,9 @@ namespace RTC
this->streamId = data->streamId();
if (this->streamId > 65534)
{
MS_THROW_TYPE_ERROR("streamId must not be greater than 65534");
}
// ordered is optional.
bool orderedGiven = false;
......@@ -41,7 +43,9 @@ namespace RTC
}
if (this->maxPacketLifeTime && this->maxRetransmits)
{
MS_THROW_TYPE_ERROR("cannot provide both maxPacketLifeTime and maxRetransmits");
}
// clang-format off
if (
......
......@@ -88,12 +88,16 @@ namespace RTC
// Drop ongoing cummulative result if too old.
if (elapsedMs > 1000u)
{
this->cummulativeResult.Reset();
}
for (auto& result : feedback->GetPacketResults())
{
if (!result.received)
{
continue;
}
const uint16_t wideSeq = result.sequenceNumber;
auto it = this->sentInfos.find(wideSeq);
......@@ -238,16 +242,24 @@ namespace RTC
else
{
if (sentAtMs < this->firstPacketSentAtMs)
{
this->firstPacketSentAtMs = sentAtMs;
}
if (receivedAtMs < this->firstPacketReceivedAtMs)
{
this->firstPacketReceivedAtMs = receivedAtMs;
}
if (sentAtMs > this->lastPacketSentAtMs)
{
this->lastPacketSentAtMs = sentAtMs;
}
if (receivedAtMs > this->lastPacketReceivedAtMs)
{
this->lastPacketReceivedAtMs = receivedAtMs;
}
}
this->numPackets++;
......
......@@ -24,7 +24,9 @@ namespace RTC
// Ensure there is a single encoding.
if (this->consumableRtpEncodings.size() != 1u)
{
MS_THROW_TYPE_ERROR("invalid consumableRtpEncodings with size != 1");
}
auto& encoding = this->rtpParameters.encodings[0];
const auto* mediaCodec = this->rtpParameters.GetCodecForEncoding(encoding);
......@@ -110,7 +112,9 @@ namespace RTC
uint8_t producerScore{ 0 };
if (this->producerRtpStream)
{
producerScore = this->producerRtpStream->GetScore();
}
return FBS::Consumer::CreateConsumerScoreDirect(
builder, this->rtpStream->GetScore(), producerScore, this->producerRtpStreamScores);
......@@ -134,7 +138,9 @@ namespace RTC
case Channel::ChannelRequest::Method::CONSUMER_REQUEST_KEY_FRAME:
{
if (IsActive())
{
RequestKeyFrame();
}
request->Accept();
......@@ -202,10 +208,14 @@ namespace RTC
// Audio SimpleConsumer does not play the BWE game.
if (this->kind != RTC::Media::Kind::VIDEO)
{
return 0u;
}
if (!IsActive())
{
return 0u;
}
return this->priority;
}
......@@ -221,7 +231,9 @@ namespace RTC
// If this is not the first time this method is called within the same iteration,
// return 0 since a video SimpleConsumer does not keep state about this.
if (this->managingBitrate)
{
return 0u;
}
this->managingBitrate = true;
......@@ -231,9 +243,13 @@ namespace RTC
auto desiredBitrate = this->producerRtpStream->GetBitrate(nowMs);
if (desiredBitrate < bitrate)
{
return desiredBitrate;
}
else
{
return bitrate;
}
}
void SimpleConsumer::ApplyLayers()
......@@ -257,10 +273,14 @@ namespace RTC
// Audio SimpleConsumer does not play the BWE game.
if (this->kind != RTC::Media::Kind::VIDEO)
{
return 0u;
}
if (!IsActive())
{
return 0u;
}
auto nowMs = DepLibUV::GetTimeMs();
auto desiredBitrate = this->producerRtpStream->GetBitrate(nowMs);
......@@ -270,7 +290,9 @@ namespace RTC
auto maxBitrate = this->rtpParameters.encodings[0].maxBitrate;
if (maxBitrate > desiredBitrate)
{
desiredBitrate = maxBitrate;
}
return desiredBitrate;
}
......@@ -335,7 +357,9 @@ namespace RTC
if (isSyncPacket)
{
if (packet->IsKeyFrame())
{
MS_DEBUG_TAG(rtp, "sync key frame received");
}
this->rtpSeqManager.Sync(packet->GetSequenceNumber() - 1);
......@@ -401,12 +425,16 @@ namespace RTC
MS_TRACE();
if (static_cast<float>((nowMs - this->lastRtcpSentTime) * 1.15) < this->maxRtcpInterval)
{
return true;
}
auto* senderReport = this->rtpStream->GetRtcpSenderReport(nowMs);
if (!senderReport)
{
return true;
}
// Build SDES chunk for this sender.
auto* sdesChunk = this->rtpStream->GetRtcpSdesChunk();
......@@ -423,7 +451,9 @@ namespace RTC
// RTCP Compound packet buffer cannot hold the data.
if (!packet->Add(senderReport, sdesChunk, delaySinceLastRrReport))
{
return false;
}
this->lastRtcpSentTime = nowMs;
......@@ -436,13 +466,17 @@ namespace RTC
MS_TRACE();
if (!IsActive())
{
return;
}
auto fractionLost = this->rtpStream->GetFractionLost();
// If our fraction lost is worse than the given one, update it.
if (fractionLost > worstRemoteFractionLost)
{
worstRemoteFractionLost = fractionLost;
}
}
void SimpleConsumer::ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket)
......@@ -450,7 +484,9 @@ namespace RTC
MS_TRACE();
if (!IsActive())
{
return;
}
// May emit 'trace' event.
EmitTraceEventNackType();
......@@ -485,7 +521,9 @@ namespace RTC
this->rtpStream->ReceiveKeyFrameRequest(messageType);
if (IsActive())
{
RequestKeyFrame();
}
}
void SimpleConsumer::ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report)
......@@ -507,7 +545,9 @@ namespace RTC
MS_TRACE();
if (!IsActive())
{
return 0u;
}
return this->rtpStream->GetBitrate(nowMs);
}
......@@ -526,7 +566,9 @@ namespace RTC
this->syncRequired = true;
if (IsActive())
{
RequestKeyFrame();
}
}
void SimpleConsumer::UserOnTransportDisconnected()
......@@ -543,7 +585,9 @@ namespace RTC
this->rtpStream->Pause();
if (this->externallyManagedBitrate && this->kind == RTC::Media::Kind::VIDEO)
{
this->listener->OnConsumerNeedZeroBitrate(this);
}
}
void SimpleConsumer::UserOnResumed()
......@@ -553,7 +597,9 @@ namespace RTC
this->syncRequired = true;
if (IsActive())
{
RequestKeyFrame();
}
}
void SimpleConsumer::CreateRtpStream()
......@@ -626,12 +672,16 @@ namespace RTC
// If the Consumer is paused, tell the RtpStreamSend.
if (IsPaused() || IsProducerPaused())
{
this->rtpStream->Pause();
}
const auto* rtxCodec = this->rtpParameters.GetRtxCodecForEncoding(encoding);
if (rtxCodec && encoding.hasRtx)
{
this->rtpStream->SetRtx(rtxCodec->payloadType, encoding.rtx.ssrc);
}
}
void SimpleConsumer::RequestKeyFrame()
......@@ -639,7 +689,9 @@ namespace RTC
MS_TRACE();
if (this->kind != RTC::Media::Kind::VIDEO)
{
return;
}
auto mappedSsrc = this->consumableRtpEncodings[0].ssrc;
......
......@@ -166,7 +166,9 @@ namespace RTC
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));
}
}
SrtpSession::~SrtpSession()
......@@ -178,7 +180,9 @@ namespace RTC
const srtp_err_status_t err = srtp_dealloc(this->session);
if (DepLibSRTP::IsError(err))
{
MS_ABORT("srtp_dealloc() failed: %s", DepLibSRTP::GetErrorString(err));
}
}
}
......
......@@ -20,7 +20,9 @@ namespace RTC
MS_TRACE();
if (!StunPacket::IsStun(data, len))
{
return nullptr;
}
/*
The message type field is decomposed further into the following
......@@ -381,17 +383,29 @@ namespace RTC
}
MS_DUMP(" transactionId: %s", transactionId);
if (this->errorCode != 0u)
{
MS_DUMP(" errorCode: %" PRIu16, this->errorCode);
}
if (!this->username.empty())
{
MS_DUMP(" username: %s", this->username.c_str());
}
if (this->priority != 0u)
{
MS_DUMP(" priority: %" PRIu32, this->priority);
}
if (this->iceControlling != 0u)
{
MS_DUMP(" iceControlling: %" PRIu64, this->iceControlling);
}
if (this->iceControlled != 0u)
{
MS_DUMP(" iceControlled: %" PRIu64, this->iceControlled);
}
if (this->hasUseCandidate)
{
MS_DUMP(" useCandidate");
}
if (this->xorMappedAddress != nullptr)
{
int family;
......@@ -414,7 +428,9 @@ namespace RTC
MS_DUMP(" messageIntegrity: %s", messageIntegrity);
}
if (this->hasFingerprint)
{
MS_DUMP(" has fingerprint");
}
MS_DUMP("</StunPacket>");
}
......@@ -431,7 +447,9 @@ namespace RTC
{
// Both USERNAME and MESSAGE-INTEGRITY must be present.
if (!this->messageIntegrity || this->username.empty())
{
return Authentication::BAD_REQUEST;
}
// Check that USERNAME attribute begins with our local username plus ":".
const size_t localUsernameLen = localUsername.length();
......@@ -459,8 +477,10 @@ namespace RTC
// If there is FINGERPRINT it must be discarded for MESSAGE-INTEGRITY calculation,
// so the header length field must be modified (and later restored).
if (this->hasFingerprint)
{
// Set the header length field: full size - header length (20) - FINGERPRINT length (8).
Utils::Byte::Set2Bytes(this->data, 2, static_cast<uint16_t>(this->size - 20 - 8));
}
// Calculate the HMAC-SHA1 of the message according to MESSAGE-INTEGRITY rules.
const uint8_t* computedMessageIntegrity = Utils::Crypto::GetHmacSha1(
......@@ -470,13 +490,19 @@ namespace RTC
// Compare the computed HMAC-SHA1 with the MESSAGE-INTEGRITY in the packet.
if (std::memcmp(this->messageIntegrity, computedMessageIntegrity, 20) == 0)
{
result = Authentication::OK;
}
else
{
result = Authentication::UNAUTHORIZED;
}
// Restore the header length field.
if (this->hasFingerprint)
{
Utils::Byte::Set2Bytes(this->data, 2, static_cast<uint16_t>(this->size - 20));
}
return result;
}
......@@ -549,16 +575,24 @@ namespace RTC
}
if (this->priority != 0u)
{
this->size += 4 + 4;
}
if (this->iceControlling != 0u)
{
this->size += 4 + 8;
}
if (this->iceControlled != 0u)
{
this->size += 4 + 8;
}
if (this->hasUseCandidate)
{
this->size += 4;
}
if (addXorMappedAddress)
{
......@@ -590,13 +624,19 @@ namespace RTC
}
if (addErrorCode)
{
this->size += 4 + 4;
}
if (addMessageIntegrity)
{
this->size += 4 + 20;
}
if (addFingerprint)
{
this->size += 4 + 4;
}
// Merge class and method fields into type.
uint16_t typeField = (static_cast<uint16_t>(this->method) & 0x0f80) << 2;
......@@ -763,7 +803,9 @@ namespace RTC
{
// Ignore FINGERPRINT.
if (addFingerprint)
{
Utils::Byte::Set2Bytes(buffer, 2, static_cast<uint16_t>(this->size - 20 - 8));
}
// Calculate the HMAC-SHA1 of the packet according to MESSAGE-INTEGRITY rules.
const uint8_t* computedMessageIntegrity =
......@@ -779,7 +821,9 @@ namespace RTC
// Restore length field.
if (addFingerprint)
{
Utils::Byte::Set2Bytes(buffer, 2, static_cast<uint16_t>(this->size - 20));
}
}
else
{
......
......@@ -218,7 +218,9 @@ namespace RTC
try
{
if (iceCandidates.empty())
{
MS_THROW_TYPE_ERROR("empty iceCandidates");
}
// Create a ICE server.
this->iceServer = new RTC::IceServer(
......@@ -295,7 +297,9 @@ namespace RTC
// Notify the webRtcTransportListener.
if (this->webRtcTransportListener)
{
this->webRtcTransportListener->OnWebRtcTransportClosed(this);
}
}
flatbuffers::Offset<FBS::WebRtcTransport::DumpResponse> WebRtcTransport::FillBuffer(
......@@ -325,7 +329,9 @@ namespace RTC
flatbuffers::Offset<FBS::Transport::Tuple> iceSelectedTuple;
if (this->iceServer->GetSelectedTuple())
{
iceSelectedTuple = this->iceServer->GetSelectedTuple()->FillBuffer(builder);
}
// Add dtlsParameters.fingerprints.
std::vector<flatbuffers::Offset<FBS::WebRtcTransport::Fingerprint>> fingerprints;
......@@ -373,7 +379,9 @@ namespace RTC
flatbuffers::Offset<FBS::Transport::Tuple> iceSelectedTuple;
if (this->iceServer->GetSelectedTuple())
{
iceSelectedTuple = this->iceServer->GetSelectedTuple()->FillBuffer(builder);
}
auto dtlsState = DtlsTransport::StateToFbs(this->dtlsTransport->GetState());
......@@ -418,7 +426,9 @@ namespace RTC
{
// Ensure this method is not called twice.
if (this->connectCalled)
{
MS_THROW_ERROR("connect() already called");
}
const auto* body = request->data->body_as<FBS::WebRtcTransport::ConnectRequest>();
const auto* dtlsParameters = body->dtlsParameters();
......@@ -589,7 +599,9 @@ namespace RTC
// Do nothing if we have the same local DTLS role as the DTLS transport.
// NOTE: local role in DTLS transport can be NONE, but not ours.
if (this->dtlsTransport->GetLocalRole() == this->dtlsRole)
{
return;
}
// Check our local DTLS role.
switch (this->dtlsRole)
......@@ -717,7 +729,9 @@ namespace RTC
MS_TRACE();
if (!IsConnected())
{
return;
}
const uint8_t* data = packet->GetData();
auto intLen = static_cast<int>(packet->GetSize());
......@@ -731,7 +745,9 @@ namespace RTC
}
if (!this->srtpSendSession->EncryptRtcp(&data, &intLen))
{
return;
}
auto len = static_cast<size_t>(intLen);
......@@ -746,7 +762,9 @@ namespace RTC
MS_TRACE();
if (!IsConnected())
{
return;
}
packet->Serialize(RTC::RTCP::Buffer);
......@@ -762,7 +780,9 @@ namespace RTC
}
if (!this->srtpSendSession->EncryptRtcp(&data, &intLen))
{
return;
}
auto len = static_cast<size_t>(intLen);
......@@ -1006,7 +1026,9 @@ namespace RTC
auto intLen = static_cast<int>(len);
if (!this->srtpRecvSession->DecryptSrtcp(const_cast<uint8_t*>(data), &intLen))
{
return;
}
RTC::RTCP::Packet* packet = RTC::RTCP::Packet::Parse(data, static_cast<size_t>(intLen));
......
......@@ -76,7 +76,9 @@ void Settings::SetConfiguration(int argc, char* argv[])
while ((c = getopt_long_only(argc, argv, "", options, &optionIdx)) != -1)
{
if (!optarg)
{
MS_THROW_TYPE_ERROR("unknown configuration parameter: %s", optarg);
}
switch (c)
{
......@@ -160,9 +162,13 @@ void Settings::SetConfiguration(int argc, char* argv[])
case '?':
{
if (isprint(optopt) != 0)
{
MS_THROW_TYPE_ERROR("invalid option '-%c'", (char)optopt);
}
else
{
MS_THROW_TYPE_ERROR("unknown long option given as argument");
}
}
// Valid option, but it requires and argument that is not given.
......@@ -183,11 +189,15 @@ void Settings::SetConfiguration(int argc, char* argv[])
// Set logTags.
if (!logTags.empty())
{
Settings::SetLogTags(logTags);
}
// Validate RTC ports.
if (Settings::configuration.rtcMaxPort < Settings::configuration.rtcMinPort)
{
MS_THROW_TYPE_ERROR("rtcMaxPort cannot be less than rtcMinPort");
}
// Set DTLS certificate files (if provided),
Settings::SetDtlsCertificateAndPrivateKeyFiles();
......@@ -201,31 +211,57 @@ void Settings::PrintConfiguration()
std::ostringstream logTagsStream;
if (Settings::configuration.logTags.info)
{
logTags.emplace_back("info");
}
if (Settings::configuration.logTags.ice)
{
logTags.emplace_back("ice");
}
if (Settings::configuration.logTags.dtls)
{
logTags.emplace_back("dtls");
}
if (Settings::configuration.logTags.rtp)
{
logTags.emplace_back("rtp");
}
if (Settings::configuration.logTags.srtp)
{
logTags.emplace_back("srtp");
}
if (Settings::configuration.logTags.rtcp)
{
logTags.emplace_back("rtcp");
}
if (Settings::configuration.logTags.rtx)
{
logTags.emplace_back("rtx");
}
if (Settings::configuration.logTags.bwe)
{
logTags.emplace_back("bwe");
}
if (Settings::configuration.logTags.score)
{
logTags.emplace_back("score");
}
if (Settings::configuration.logTags.simulcast)
{
logTags.emplace_back("simulcast");
}
if (Settings::configuration.logTags.svc)
{
logTags.emplace_back("svc");
}
if (Settings::configuration.logTags.sctp)
{
logTags.emplace_back("sctp");
}
if (Settings::configuration.logTags.message)
{
logTags.emplace_back("message");
}
if (!logTags.empty())
{
......@@ -313,7 +349,9 @@ void Settings::SetLogLevel(std::string& level)
Utils::String::ToLowerCase(level);
if (Settings::string2LogLevel.find(level) == Settings::string2LogLevel.end())
{
MS_THROW_TYPE_ERROR("invalid value '%s' for logLevel", level.c_str());
}
Settings::configuration.logLevel = Settings::string2LogLevel[level];
}
......@@ -328,31 +366,57 @@ void Settings::SetLogTags(const std::vector<std::string>& tags)
for (const auto& tag : tags)
{
if (tag == "info")
{
newLogTags.info = true;
}
else if (tag == "ice")
{
newLogTags.ice = true;
}
else if (tag == "dtls")
{
newLogTags.dtls = true;
}
else if (tag == "rtp")
{
newLogTags.rtp = true;
}
else if (tag == "srtp")
{
newLogTags.srtp = true;
}
else if (tag == "rtcp")
{
newLogTags.rtcp = true;
}
else if (tag == "rtx")
{
newLogTags.rtx = true;
}
else if (tag == "bwe")
{
newLogTags.bwe = true;
}
else if (tag == "score")
{
newLogTags.score = true;
}
else if (tag == "simulcast")
{
newLogTags.simulcast = true;
}
else if (tag == "svc")
{
newLogTags.svc = true;
}
else if (tag == "sctp")
{
newLogTags.sctp = true;
}
else if (tag == "message")
{
newLogTags.message = true;
}
}
Settings::configuration.logTags = newLogTags;
......
......@@ -71,10 +71,14 @@ namespace Utils
MS_TRACE();
if (Crypto::hmacSha1Ctx != nullptr)
{
EVP_MAC_CTX_free(Crypto::hmacSha1Ctx);
}
if (Crypto::mac != nullptr)
{
EVP_MAC_free(Crypto::mac);
}
}
const uint8_t* Crypto::GetHmacSha1(const std::string& key, const uint8_t* data, size_t len)
......
......@@ -27,16 +27,22 @@ namespace Utils
err = stat(file, &fileStat);
if (err != 0)
{
MS_THROW_ERROR("cannot read file '%s': %s", file, std::strerror(errno));
}
// Ensure it is a regular file.
if (!S_ISREG(fileStat.st_mode))
{
MS_THROW_ERROR("'%s' is not a regular file", file);
}
// Ensure it is readable.
err = access(file, R_OK);
if (err != 0)
{
MS_THROW_ERROR("cannot read file '%s': %s", file, std::strerror(errno));
}
}
} // namespace Utils
......@@ -13,17 +13,25 @@ namespace Utils
MS_TRACE();
if (ip.size() >= INET6_ADDRSTRLEN)
{
return AF_UNSPEC;
}
auto ipPtr = ip.c_str();
char ipBuffer[INET6_ADDRSTRLEN] = { 0 };
if (uv_inet_pton(AF_INET, ipPtr, ipBuffer) == 0)
{
return AF_INET;
}
else if (uv_inet_pton(AF_INET6, ipPtr, ipBuffer) == 0)
{
return AF_INET6;
}
else
{
return AF_UNSPEC;
}
}
void IP::GetAddressInfo(const struct sockaddr* addr, int& family, std::string& ip, uint16_t& port)
......@@ -44,7 +52,9 @@ namespace Utils
sizeof(ipBuffer));
if (err)
{
MS_ABORT("uv_inet_ntop() failed: %s", uv_strerror(err));
}
port =
static_cast<uint16_t>(ntohs(reinterpret_cast<const struct sockaddr_in*>(addr)->sin_port));
......@@ -61,7 +71,9 @@ namespace Utils
sizeof(ipBuffer));
if (err)
{
MS_ABORT("uv_inet_ntop() failed: %s", uv_strerror(err));
}
port =
static_cast<uint16_t>(ntohs(reinterpret_cast<const struct sockaddr_in6*>(addr)->sin6_port));
......
......@@ -38,9 +38,13 @@ namespace Utils
olen = len * 4 / 3 + 4; // 3-byte blocks to 4-byte.
if (olen < len)
{
MS_THROW_TYPE_ERROR("integer overflow");
}
else if (olen > BufferOutSize - 1)
{
MS_THROW_TYPE_ERROR("data too big");
}
end = data + len;
in = data;
......@@ -100,7 +104,9 @@ namespace Utils
// NOTE: This is not really accurate but anyway.
if (len > BufferOutSize - 1)
{
MS_THROW_TYPE_ERROR("data too big");
}
std::memset(dtable, 0x80, 256);
......@@ -114,11 +120,15 @@ namespace Utils
for (i = 0; i < len; ++i)
{
if (dtable[data[i]] != 0x80)
{
count++;
}
}
if (count == 0 || count % 4)
{
MS_THROW_TYPE_ERROR("invalid data");
}
pos = out;
count = 0;
......@@ -128,10 +138,14 @@ namespace Utils
tmp = dtable[data[i]];
if (tmp == 0x80)
{
continue;
}
if (data[i] == '=')
{
pad++;
}
block[count] = tmp;
count++;
......@@ -146,11 +160,17 @@ namespace Utils
if (pad)
{
if (pad == 1)
{
pos--;
}
else if (pad == 2)
{
pos -= 2;
}
else
{
MS_THROW_TYPE_ERROR("integer padding");
}
break;
}
......
......@@ -54,7 +54,9 @@ Worker::~Worker()
MS_TRACE();
if (!this->closed)
{
Close();
}
}
void Worker::Close()
......@@ -62,7 +64,9 @@ void Worker::Close()
MS_TRACE();
if (this->closed)
{
return;
}
this->closed = true;
......@@ -139,7 +143,9 @@ flatbuffers::Offset<FBS::Worker::ResourceUsageResponse> Worker::FillBufferResour
err = uv_getrusage(std::addressof(uvRusage));
if (err != 0)
{
MS_THROW_ERROR("uv_getrusagerequest() failed: %s", uv_strerror(err));
}
return FBS::Worker::CreateResourceUsageResponse(
builder,
......@@ -195,7 +201,9 @@ RTC::Router* Worker::GetRouter(const std::string& routerId) const
auto it = this->mapRouters.find(routerId);
if (it == this->mapRouters.end())
{
MS_THROW_ERROR("Router not found");
}
return it->second;
}
......@@ -203,13 +211,17 @@ RTC::Router* Worker::GetRouter(const std::string& routerId) const
void Worker::CheckNoWebRtcServer(const std::string& webRtcServerId) const
{
if (this->mapWebRtcServers.find(webRtcServerId) != this->mapWebRtcServers.end())
{
MS_THROW_ERROR("a WebRtcServer with same webRtcServerId already exists");
}
}
void Worker::CheckNoRouter(const std::string& routerId) const
{
if (this->mapRouters.find(routerId) != this->mapRouters.end())
{
MS_THROW_ERROR("a Router with same routerId already exists");
}
}
RTC::WebRtcServer* Worker::GetWebRtcServer(const std::string& webRtcServerId) const
......@@ -217,7 +229,9 @@ RTC::WebRtcServer* Worker::GetWebRtcServer(const std::string& webRtcServerId) co
auto it = this->mapWebRtcServers.find(webRtcServerId);
if (it == this->mapWebRtcServers.end())
{
MS_THROW_ERROR("WebRtcServer not found");
}
return it->second;
}
......@@ -234,7 +248,9 @@ inline void Worker::HandleRequest(Channel::ChannelRequest* request)
case Channel::ChannelRequest::Method::WORKER_CLOSE:
{
if (this->closed)
{
return;
}
MS_DEBUG_DEV("Worker close request, stopping");
......@@ -459,14 +475,18 @@ inline void Worker::OnSignal(SignalHandle* /*signalHandle*/, int signum)
MS_TRACE();
if (this->closed)
{
return;
}
switch (signum)
{
case SIGINT:
{
if (this->closed)
{
return;
}
MS_DEBUG_DEV("INT signal received, closing myself");
......@@ -478,7 +498,9 @@ inline void Worker::OnSignal(SignalHandle* /*signalHandle*/, int signum)
case SIGTERM:
{
if (this->closed)
{
return;
}
MS_DEBUG_DEV("TERM signal received, closing myself");
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论