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