Skip to content

Commit

Permalink
RTCP CompoundPacket: Use a single DLRR block to hold all ssrc infos (
Browse files Browse the repository at this point in the history
  • Loading branch information
ibc committed Nov 22, 2023
1 parent 1ed3a24 commit e952f34
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 70 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
### NEXT

* Fix RTCP SDES packet size calculation ([PR #1236](https://github.com/versatica/mediasoup/pull/1236) based on PR [PR #1234](https://github.com/versatica/mediasoup/pull/1234) by @ybybwdwd).
* RTCP Compound Packet: Use a single DLRR report to hold all ssrc info sub-blocks ([PR #1237](https://github.com/versatica/mediasoup/pull/1237)).


### 3.13.4
Expand Down
17 changes: 13 additions & 4 deletions worker/include/RTC/RTCP/CompoundPacket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@ namespace RTC
// Adds the given data and returns true if there is enough space to hold it,
// false otherwise.
bool Add(
SenderReport* senderReport, SdesChunk* sdesChunk, DelaySinceLastRr* delaySinceLastRrReport);
SenderReport* senderReport,
SdesChunk* sdesChunk,
DelaySinceLastRr::SsrcInfo* delaySinceLastRrSsrcInfo);
// RTCP additions per Consumer (pipe).
// Adds the given data and returns true if there is enough space to hold it,
// false otherwise.
bool Add(
std::vector<SenderReport*>& senderReports,
std::vector<SdesChunk*>& sdesChunks,
std::vector<DelaySinceLastRr*>& delaySinceLastRrReports);
std::vector<DelaySinceLastRr::SsrcInfo*>& delaySinceLastRrSsrcInfos);
// RTCP additions per Producer.
// Adds the given data and returns true if there is enough space to hold it,
// false otherwise.
bool Add(std::vector<ReceiverReport*>&, ReceiverReferenceTime*);
void AddSenderReport(SenderReport* report);
void AddReceiverReport(ReceiverReport* report);
void AddSdesChunk(SdesChunk* chunk);
void AddReceiverReferenceTime(ReceiverReferenceTime* report);
void AddDelaySinceLastRr(DelaySinceLastRr* report);
bool HasSenderReport()
{
return this->senderReportPacket.Begin() != this->senderReportPacket.End();
Expand All @@ -77,6 +77,14 @@ namespace RTC
[](const ExtendedReportBlock* report)
{ return report->GetType() == ExtendedReportBlock::Type::RRT; });
}
bool HasDelaySinceLastRr()
{
return std::any_of(
this->xrPacket.Begin(),
this->xrPacket.End(),
[](const ExtendedReportBlock* report)
{ return report->GetType() == ExtendedReportBlock::Type::DLRR; });
}
void Serialize(uint8_t* data);

private:
Expand All @@ -85,6 +93,7 @@ namespace RTC
ReceiverReportPacket receiverReportPacket;
SdesPacket sdesPacket;
ExtendedReportPacket xrPacket;
DelaySinceLastRr* delaySinceLastRr{ nullptr };
};
} // namespace RTCP
} // namespace RTC
Expand Down
13 changes: 13 additions & 0 deletions worker/include/RTC/RTCP/XrDelaySinceLastRr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ namespace RTC
{
this->ssrcInfos.push_back(ssrcInfo);
}
// NOTE: This method not only removes given number of ssrc info sub-blocks
// but also deletes their SsrcInfo instances.
void RemoveLastSsrcInfos(size_t number)
{
while (!this->ssrcInfos.empty() && number-- > 0)
{
auto* ssrcInfo = this->ssrcInfos.back();

this->ssrcInfos.pop_back();

delete ssrcInfo;
}
}
Iterator Begin()
{
return this->ssrcInfos.begin();
Expand Down
2 changes: 1 addition & 1 deletion worker/include/RTC/RtpStreamSend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace RTC
void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report);
void ReceiveRtcpXrReceiverReferenceTime(RTC::RTCP::ReceiverReferenceTime* report);
RTC::RTCP::SenderReport* GetRtcpSenderReport(uint64_t nowMs);
RTC::RTCP::DelaySinceLastRr::SsrcInfo* GetRtcpXrDelaySinceLastRr(uint64_t nowMs);
RTC::RTCP::DelaySinceLastRr::SsrcInfo* GetRtcpXrDelaySinceLastRrSsrcInfo(uint64_t nowMs);
RTC::RTCP::SdesChunk* GetRtcpSdesChunk();
void Pause() override;
void Resume() override;
Expand Down
13 changes: 5 additions & 8 deletions worker/src/RTC/PipeConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ namespace RTC

std::vector<RTCP::SenderReport*> senderReports;
std::vector<RTCP::SdesChunk*> sdesChunks;
std::vector<RTCP::DelaySinceLastRr*> xrReports;
std::vector<RTCP::DelaySinceLastRr::SsrcInfo*> delaySinceLastRrSsrcInfos;

for (auto* rtpStream : this->rtpStreams)
{
Expand All @@ -362,19 +362,16 @@ namespace RTC
auto* sdesChunk = rtpStream->GetRtcpSdesChunk();
sdesChunks.push_back(sdesChunk);

auto* dlrr = rtpStream->GetRtcpXrDelaySinceLastRr(nowMs);
auto* delaySinceLastRrSsrcInfo = rtpStream->GetRtcpXrDelaySinceLastRrSsrcInfo(nowMs);

if (dlrr)
if (delaySinceLastRrSsrcInfo)
{
auto* report = new RTC::RTCP::DelaySinceLastRr();
report->AddSsrcInfo(dlrr);

xrReports.push_back(report);
delaySinceLastRrSsrcInfos.push_back(delaySinceLastRrSsrcInfo);
}
}

// RTCP Compound packet buffer cannot hold the data.
if (!packet->Add(senderReports, sdesChunks, xrReports))
if (!packet->Add(senderReports, sdesChunks, delaySinceLastRrSsrcInfos))
{
return false;
}
Expand Down
54 changes: 28 additions & 26 deletions worker/src/RTC/RTCP/CompoundPacket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ namespace RTC
}

bool CompoundPacket::Add(
SenderReport* senderReport, SdesChunk* sdesChunk, DelaySinceLastRr* delaySinceLastRrReport)
SenderReport* senderReport,
SdesChunk* sdesChunk,
DelaySinceLastRr::SsrcInfo* delaySinceLastRrSsrcInfo)
{
// Add the items into the packet.

Expand All @@ -86,9 +88,16 @@ namespace RTC
this->sdesPacket.AddChunk(sdesChunk);
}

if (delaySinceLastRrReport)
if (delaySinceLastRrSsrcInfo)
{
this->xrPacket.AddReport(delaySinceLastRrReport);
// Add a DLRR block into the XR packet if no present.
if (!this->delaySinceLastRr)
{
this->delaySinceLastRr = new RTC::RTCP::DelaySinceLastRr();
this->xrPacket.AddReport(this->delaySinceLastRr);
}

this->delaySinceLastRr->AddSsrcInfo(delaySinceLastRrSsrcInfo);
}

// New items can hold in the packet, report it.
Expand All @@ -112,10 +121,10 @@ namespace RTC
delete sdesChunk;
}

if (delaySinceLastRrReport)
if (delaySinceLastRrSsrcInfo)
{
this->xrPacket.RemoveReport(delaySinceLastRrReport);
delete delaySinceLastRrReport;
// NOTE: This method deletes the removed instances in place.
this->delaySinceLastRr->RemoveLastSsrcInfos(1);
}

return false;
Expand All @@ -124,7 +133,7 @@ namespace RTC
bool CompoundPacket::Add(
std::vector<SenderReport*>& senderReports,
std::vector<SdesChunk*>& sdesChunks,
std::vector<DelaySinceLastRr*>& delaySinceLastRrReports)
std::vector<DelaySinceLastRr::SsrcInfo*>& delaySinceLastRrSsrcInfos)
{
// Add the items into the packet.

Expand All @@ -138,9 +147,16 @@ namespace RTC
this->sdesPacket.AddChunk(chunk);
}

for (auto* report : delaySinceLastRrReports)
// Add a DLRR block into the XR packet if no present.
if (!delaySinceLastRrSsrcInfos.empty() && !this->delaySinceLastRr)
{
this->xrPacket.AddReport(report);
this->delaySinceLastRr = new RTC::RTCP::DelaySinceLastRr();
this->xrPacket.AddReport(this->delaySinceLastRr);
}

for (auto* ssrcInfo : delaySinceLastRrSsrcInfos)
{
this->delaySinceLastRr->AddSsrcInfo(ssrcInfo);
}

// New items can hold in the packet, report it.
Expand All @@ -164,10 +180,10 @@ namespace RTC
delete chunk;
}

for (auto* report : delaySinceLastRrReports)
if (!delaySinceLastRrSsrcInfos.empty())
{
this->xrPacket.RemoveReport(report);
delete report;
// NOTE: This method deletes the instances in place.
this->delaySinceLastRr->RemoveLastSsrcInfos(delaySinceLastRrSsrcInfos.size());
}

return false;
Expand Down Expand Up @@ -266,19 +282,5 @@ namespace RTC

this->sdesPacket.AddChunk(chunk);
}

void CompoundPacket::AddReceiverReferenceTime(ReceiverReferenceTime* report)
{
MS_TRACE();

this->xrPacket.AddReport(report);
}

void CompoundPacket::AddDelaySinceLastRr(DelaySinceLastRr* report)
{
MS_TRACE();

this->xrPacket.AddReport(report);
}
} // namespace RTCP
} // namespace RTC
2 changes: 1 addition & 1 deletion worker/src/RTC/RtpStreamSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ namespace RTC
return report;
}

RTC::RTCP::DelaySinceLastRr::SsrcInfo* RtpStreamSend::GetRtcpXrDelaySinceLastRr(uint64_t nowMs)
RTC::RTCP::DelaySinceLastRr::SsrcInfo* RtpStreamSend::GetRtcpXrDelaySinceLastRrSsrcInfo(uint64_t nowMs)
{
MS_TRACE();

Expand Down
12 changes: 2 additions & 10 deletions worker/src/RTC/SimpleConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,18 +439,10 @@ namespace RTC
// Build SDES chunk for this sender.
auto* sdesChunk = this->rtpStream->GetRtcpSdesChunk();

RTC::RTCP::DelaySinceLastRr* delaySinceLastRrReport{ nullptr };

auto* dlrr = this->rtpStream->GetRtcpXrDelaySinceLastRr(nowMs);

if (dlrr)
{
delaySinceLastRrReport = new RTC::RTCP::DelaySinceLastRr();
delaySinceLastRrReport->AddSsrcInfo(dlrr);
}
auto* delaySinceLastRrSsrcInfo = this->rtpStream->GetRtcpXrDelaySinceLastRrSsrcInfo(nowMs);

// RTCP Compound packet buffer cannot hold the data.
if (!packet->Add(senderReport, sdesChunk, delaySinceLastRrReport))
if (!packet->Add(senderReport, sdesChunk, delaySinceLastRrSsrcInfo))
{
return false;
}
Expand Down
12 changes: 2 additions & 10 deletions worker/src/RTC/SimulcastConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1081,18 +1081,10 @@ namespace RTC
// Build SDES chunk for this sender.
auto* sdesChunk = this->rtpStream->GetRtcpSdesChunk();

RTC::RTCP::DelaySinceLastRr* delaySinceLastRrReport{ nullptr };

auto* dlrr = this->rtpStream->GetRtcpXrDelaySinceLastRr(nowMs);

if (dlrr)
{
delaySinceLastRrReport = new RTC::RTCP::DelaySinceLastRr();
delaySinceLastRrReport->AddSsrcInfo(dlrr);
}
auto* delaySinceLastRrSsrcInfo = this->rtpStream->GetRtcpXrDelaySinceLastRrSsrcInfo(nowMs);

// RTCP Compound packet buffer cannot hold the data.
if (!packet->Add(senderReport, sdesChunk, delaySinceLastRrReport))
if (!packet->Add(senderReport, sdesChunk, delaySinceLastRrSsrcInfo))
{
return false;
}
Expand Down
12 changes: 2 additions & 10 deletions worker/src/RTC/SvcConsumer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,18 +795,10 @@ namespace RTC
// Build SDES chunk for this sender.
auto* sdesChunk = this->rtpStream->GetRtcpSdesChunk();

RTC::RTCP::DelaySinceLastRr* delaySinceLastRrReport{ nullptr };

auto* dlrr = this->rtpStream->GetRtcpXrDelaySinceLastRr(nowMs);

if (dlrr)
{
delaySinceLastRrReport = new RTC::RTCP::DelaySinceLastRr();
delaySinceLastRrReport->AddSsrcInfo(dlrr);
}
auto* delaySinceLastRrSsrcInfo = this->rtpStream->GetRtcpXrDelaySinceLastRrSsrcInfo(nowMs);

// RTCP Compound packet buffer cannot hold the data.
if (!packet->Add(senderReport, sdesChunk, delaySinceLastRrReport))
if (!packet->Add(senderReport, sdesChunk, delaySinceLastRrSsrcInfo))
{
return false;
}
Expand Down

0 comments on commit e952f34

Please sign in to comment.