提交 96aaea2e authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Merge branch 'v3' of github.com:versatica/mediasoup into v3

# Changelog # Changelog
### 3.2.1 (COMING SOON)
* Add RTCP Extended Reports for RTT calculation on receiver RTP stream (Thanks @yangjinechofor for initial pull request) .
### 3.2.0 ### 3.2.0
* Add DataChannel support via DataProducers and DataConsumers (#10). * Add DataChannel support via DataProducers and DataConsumers (#10).
......
#ifndef MS_FUZZER_RTC_RTCP_XR_PACKET
#define MS_FUZZER_RTC_RTCP_XR_PACKET
#include "common.hpp"
#include "RTC/RTCP/XR.hpp"
namespace Fuzzer
{
namespace RTC
{
namespace RTCP
{
namespace ExtendedReport
{
void Fuzz(::RTC::RTCP::ExtendedReportPacket* packet);
}
} // namespace RTCP
} // namespace RTC
} // namespace Fuzzer
#endif
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "RTC/RTCP/FuzzerReceiverReport.hpp" #include "RTC/RTCP/FuzzerReceiverReport.hpp"
#include "RTC/RTCP/FuzzerSdes.hpp" #include "RTC/RTCP/FuzzerSdes.hpp"
#include "RTC/RTCP/FuzzerSenderReport.hpp" #include "RTC/RTCP/FuzzerSenderReport.hpp"
#include "RTC/RTCP/FuzzerXr.hpp"
#include "RTC/RTCP/Packet.hpp" #include "RTC/RTCP/Packet.hpp"
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)
...@@ -79,6 +80,15 @@ void Fuzzer::RTC::RTCP::Packet::Fuzz(const uint8_t* data, size_t len) ...@@ -79,6 +80,15 @@ void Fuzzer::RTC::RTCP::Packet::Fuzz(const uint8_t* data, size_t len)
break; break;
} }
case ::RTC::RTCP::Type::XR:
{
auto* xr = dynamic_cast<::RTC::RTCP::ExtendedReportPacket*>(packet);
RTC::RTCP::ExtendedReport::Fuzz(xr);
break;
}
default: default:
{ {
} }
......
#include "RTC/RTCP/FuzzerXr.hpp"
void Fuzzer::RTC::RTCP::ExtendedReport::Fuzz(::RTC::RTCP::ExtendedReportPacket* packet)
{
packet->Dump();
packet->Serialize(::RTC::RTCP::Buffer);
packet->GetCount();
packet->GetSize();
packet->GetSsrc();
packet->SetSsrc(1111);
auto it = packet->Begin();
for (; it != packet->End(); ++it)
{
auto& report = (*it);
report->Dump();
report->Serialize(::RTC::RTCP::Buffer);
report->GetSize();
report->GetType();
}
}
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "RTC/RTCP/CompoundPacket.hpp" #include "RTC/RTCP/CompoundPacket.hpp"
#include "RTC/RTCP/Packet.hpp" #include "RTC/RTCP/Packet.hpp"
#include "RTC/RTCP/SenderReport.hpp" #include "RTC/RTCP/SenderReport.hpp"
#include "RTC/RTCP/XrDelaySinceLastRr.hpp"
#include "RTC/RtpDictionaries.hpp" #include "RTC/RtpDictionaries.hpp"
#include "RTC/RtpHeaderExtensionIds.hpp" #include "RTC/RtpHeaderExtensionIds.hpp"
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
...@@ -77,6 +78,7 @@ namespace RTC ...@@ -77,6 +78,7 @@ namespace RTC
std::map<RTC::RtpStreamRecv*, uint32_t>& GetRtpStreams(); std::map<RTC::RtpStreamRecv*, uint32_t>& GetRtpStreams();
void ReceiveRtpPacket(RTC::RtpPacket* packet); void ReceiveRtpPacket(RTC::RtpPacket* packet);
void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report); void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report);
void ReceiveRtcpXrDelaySinceLastRr(RTC::RTCP::DelaySinceLastRr::SsrcInfo* ssrcInfo);
void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now); void GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now);
void RequestKeyFrame(uint32_t mappedSsrc); void RequestKeyFrame(uint32_t mappedSsrc);
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "RTC/RTCP/ReceiverReport.hpp" #include "RTC/RTCP/ReceiverReport.hpp"
#include "RTC/RTCP/Sdes.hpp" #include "RTC/RTCP/Sdes.hpp"
#include "RTC/RTCP/SenderReport.hpp" #include "RTC/RTCP/SenderReport.hpp"
#include "RTC/RTCP/XrReceiverReferenceTime.hpp"
#include <vector> #include <vector>
namespace RTC namespace RTC
...@@ -25,7 +26,9 @@ namespace RTC ...@@ -25,7 +26,9 @@ namespace RTC
void AddSenderReport(SenderReport* report); void AddSenderReport(SenderReport* report);
void AddReceiverReport(ReceiverReport* report); void AddReceiverReport(ReceiverReport* report);
void AddSdesChunk(SdesChunk* chunk); void AddSdesChunk(SdesChunk* chunk);
void AddReceiverReferenceTime(ReceiverReferenceTime* report);
bool HasSenderReport(); bool HasSenderReport();
bool HasReceiverReferenceTime();
void Serialize(uint8_t* data); void Serialize(uint8_t* data);
private: private:
...@@ -34,6 +37,7 @@ namespace RTC ...@@ -34,6 +37,7 @@ namespace RTC
SenderReportPacket senderReportPacket; SenderReportPacket senderReportPacket;
ReceiverReportPacket receiverReportPacket; ReceiverReportPacket receiverReportPacket;
SdesPacket sdesPacket; SdesPacket sdesPacket;
ExtendedReportPacket xrPacket;
}; };
/* Inline methods. */ /* Inline methods. */
...@@ -68,10 +72,23 @@ namespace RTC ...@@ -68,10 +72,23 @@ namespace RTC
this->sdesPacket.AddChunk(chunk); this->sdesPacket.AddChunk(chunk);
} }
inline void CompoundPacket::AddReceiverReferenceTime(ReceiverReferenceTime* report)
{
this->xrPacket.AddReport(report);
}
inline bool CompoundPacket::HasSenderReport() inline bool CompoundPacket::HasSenderReport()
{ {
return this->senderReportPacket.Begin() != this->senderReportPacket.End(); return this->senderReportPacket.Begin() != this->senderReportPacket.End();
} }
inline bool CompoundPacket::HasReceiverReferenceTime()
{
return std::any_of(
this->xrPacket.Begin(), this->xrPacket.End(), [](const ExtendedReportBlock* report) {
return report->GetType() == ExtendedReportBlock::Type::RRT;
});
}
} // namespace RTCP } // namespace RTCP
} // namespace RTC } // namespace RTC
......
#ifndef MS_RTC_RTCP_XR_HPP
#define MS_RTC_RTCP_XR_HPP
#include "common.hpp"
#include "RTC/RTCP/Packet.hpp"
#include <vector>
/* https://tools.ietf.org/html/rfc3611
* RTP Control Protocol Extended Reports (RTCP XR)
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|V=2|P|reserved | PT=XR=207 | length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| SSRC |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
: report blocks :
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
namespace RTC
{
namespace RTCP
{
class ExtendedReportBlock
{
public:
enum class Type : uint8_t
{
LRLE = 1,
DRLE = 2,
PRT = 3,
RRT = 4,
DLRR = 5,
SS = 6,
VM = 7
};
public:
/* Struct for Extended Report Block common header. */
struct CommonHeader
{
uint8_t blockType : 8;
uint8_t reserved : 8;
uint16_t length : 16;
};
public:
static ExtendedReportBlock* Parse(const uint8_t* data, size_t len);
public:
ExtendedReportBlock(Type type);
virtual ~ExtendedReportBlock() = default;
public:
virtual void Dump() const = 0;
virtual size_t Serialize(uint8_t* buffer) = 0;
virtual size_t GetSize() const = 0;
ExtendedReportBlock::Type GetType() const;
protected:
Type type;
CommonHeader* header{ nullptr };
private:
uint8_t raw[sizeof(CommonHeader)] = { 0 };
};
class ExtendedReportPacket : public Packet
{
public:
using Iterator = std::vector<ExtendedReportBlock*>::iterator;
public:
static ExtendedReportPacket* Parse(const uint8_t* data, size_t len);
public:
ExtendedReportPacket();
~ExtendedReportPacket() override;
void AddReport(ExtendedReportBlock* report);
uint32_t GetSsrc() const;
void SetSsrc(uint32_t ssrc);
Iterator Begin();
Iterator End();
/* Pure virtual methods inherited from Packet. */
public:
void Dump() const override;
size_t Serialize(uint8_t* buffer) override;
size_t GetCount() const override;
size_t GetSize() const override;
private:
uint32_t ssrc{ 0 };
std::vector<ExtendedReportBlock*> reports;
};
/* Inline ExtendedReportBlock instance methods. */
inline ExtendedReportBlock::ExtendedReportBlock(Type type) : type(type)
{
this->header = reinterpret_cast<CommonHeader*>(this->raw);
this->header->reserved = 0;
}
inline ExtendedReportBlock::Type ExtendedReportBlock::GetType() const
{
return this->type;
}
inline void ExtendedReportPacket::AddReport(ExtendedReportBlock* report)
{
this->reports.push_back(report);
}
inline uint32_t ExtendedReportPacket::GetSsrc() const
{
return uint32_t{ ntohl(this->ssrc) };
}
inline void ExtendedReportPacket::SetSsrc(uint32_t ssrc)
{
this->ssrc = uint32_t{ htonl(ssrc) };
}
/* Inline ExtendedReportPacket instance methods. */
inline ExtendedReportPacket::ExtendedReportPacket() : Packet(Type::XR)
{
}
inline ExtendedReportPacket::~ExtendedReportPacket()
{
for (auto* report : this->reports)
{
delete report;
}
}
inline ExtendedReportPacket::Iterator ExtendedReportPacket::Begin()
{
return this->reports.begin();
}
inline ExtendedReportPacket::Iterator ExtendedReportPacket::End()
{
return this->reports.end();
}
inline size_t ExtendedReportPacket::GetCount() const
{
return 0;
}
inline size_t ExtendedReportPacket::GetSize() const
{
size_t size = sizeof(Packet::CommonHeader) + sizeof(this->ssrc);
for (auto* report : this->reports)
{
size += report->GetSize();
}
return size;
}
} // namespace RTCP
} // namespace RTC
#endif
#ifndef MS_RTC_RTCP_XR_DELAY_SINCE_LAST_RR_HPP
#define MS_RTC_RTCP_XR_DELAY_SINCE_LAST_RR_HPP
#include "common.hpp"
#include "RTC/RTCP/XR.hpp"
/* https://tools.ietf.org/html/rfc3611
* Delay Since Last Receiver Report (DLRR) Report Block
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| BT=5 | reserved | block length |
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
| SSRC_1 (SSRC of first receiver) | sub-
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block
| last RR (LRR) | 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| delay since last RR (DLRR) |
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
| SSRC_2 (SSRC of second receiver) | sub-
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ block
: ... : 2
+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
*/
namespace RTC
{
namespace RTCP
{
class DelaySinceLastRr : public ExtendedReportBlock
{
public:
static DelaySinceLastRr* Parse(const uint8_t* data, size_t len);
public:
class SsrcInfo
{
public:
static SsrcInfo* Parse(const uint8_t* data, size_t len);
public:
struct Body
{
uint32_t ssrc;
uint32_t lrr;
uint32_t dlrr;
};
public:
// Parsed Report. Points to an external data.
explicit SsrcInfo(Body* body);
// Locally generated Report. Holds the data internally.
SsrcInfo();
void Dump() const;
size_t Serialize(uint8_t* buffer);
size_t GetSize() const;
uint32_t GetSsrc() const;
void SetSsrc(uint32_t ssrc);
uint32_t GetLastReceiverReport() const;
void SetLastReceiverReport(uint32_t lrr);
uint32_t GetDelaySinceLastReceiverReport() const;
void SetDelaySinceLastReceiverReport(uint32_t dlrr);
private:
Body* body{ nullptr };
uint8_t raw[sizeof(Body)] = { 0 };
};
public:
using Iterator = std::vector<SsrcInfo*>::iterator;
public:
explicit DelaySinceLastRr(CommonHeader* header);
DelaySinceLastRr();
~DelaySinceLastRr();
public:
void AddSsrcInfo(SsrcInfo* ssrcInfo);
Iterator Begin();
Iterator End();
/* Pure virtual methods inherited from ExtendedReportBlock. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
private:
std::vector<SsrcInfo*> ssrcInfos;
};
/* Inline SsrcInfo instance methods. */
inline DelaySinceLastRr::SsrcInfo::SsrcInfo()
{
this->body = reinterpret_cast<Body*>(this->raw);
}
inline DelaySinceLastRr::SsrcInfo::SsrcInfo(Body* body) : body(body)
{
}
inline size_t DelaySinceLastRr::SsrcInfo::GetSize() const
{
return sizeof(Body);
}
inline uint32_t DelaySinceLastRr::SsrcInfo::GetSsrc() const
{
return uint32_t{ ntohl(this->body->ssrc) };
}
inline void DelaySinceLastRr::SsrcInfo::SetSsrc(uint32_t ssrc)
{
this->body->ssrc = uint32_t{ htonl(ssrc) };
}
inline uint32_t DelaySinceLastRr::SsrcInfo::GetLastReceiverReport() const
{
return uint32_t{ ntohl(this->body->lrr) };
}
inline void DelaySinceLastRr::SsrcInfo::SetLastReceiverReport(uint32_t lrr)
{
this->body->lrr = uint32_t{ htonl(lrr) };
}
inline uint32_t DelaySinceLastRr::SsrcInfo::GetDelaySinceLastReceiverReport() const
{
return uint32_t{ ntohl(this->body->dlrr) };
}
inline void DelaySinceLastRr::SsrcInfo::SetDelaySinceLastReceiverReport(uint32_t dlrr)
{
this->body->dlrr = uint32_t{ htonl(dlrr) };
}
/* Inline DelaySinceLastRr instance methods. */
inline DelaySinceLastRr::DelaySinceLastRr(CommonHeader* header)
: ExtendedReportBlock(ExtendedReportBlock::Type::DLRR)
{
this->header = header;
}
inline DelaySinceLastRr::DelaySinceLastRr()
: ExtendedReportBlock(ExtendedReportBlock::Type::DLRR)
{
}
inline DelaySinceLastRr::~DelaySinceLastRr()
{
for (auto* ssrcInfo : this->ssrcInfos)
{
delete ssrcInfo;
}
}
inline void DelaySinceLastRr::AddSsrcInfo(SsrcInfo* ssrcInfo)
{
this->ssrcInfos.push_back(ssrcInfo);
}
inline DelaySinceLastRr::Iterator DelaySinceLastRr::Begin()
{
return this->ssrcInfos.begin();
}
inline DelaySinceLastRr::Iterator DelaySinceLastRr::End()
{
return this->ssrcInfos.end();
}
inline size_t DelaySinceLastRr::GetSize() const
{
size_t size{ 4 }; // Common header.
for (auto* ssrcInfo : this->ssrcInfos)
{
size += ssrcInfo->GetSize();
}
return size;
}
} // namespace RTCP
} // namespace RTC
#endif
#ifndef MS_RTC_RTCP_XR_RECEIVER_REFERENCE_TIME_HPP
#define MS_RTC_RTCP_XR_RECEIVER_REFERENCE_TIME_HPP
#include "common.hpp"
#include "RTC/RTCP/XR.hpp"
/* https://tools.ietf.org/html/rfc3611
* Receiver Reference Time Report Block
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| BT=4 | reserved | block length = 2 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| NTP timestamp, most significant word |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| NTP timestamp, least significant word |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
namespace RTC
{
namespace RTCP
{
class ReceiverReferenceTime : public ExtendedReportBlock
{
public:
struct Body
{
uint32_t ntpSec;
uint32_t ntpFrac;
};
public:
static ReceiverReferenceTime* Parse(const uint8_t* data, size_t len);
public:
// Parsed Report. Points to an external data.
explicit ReceiverReferenceTime(CommonHeader* header);
// Locally generated Report. Holds the data internally.
ReceiverReferenceTime();
public:
uint32_t GetNtpSec() const;
void SetNtpSec(uint32_t ntpSec);
uint32_t GetNtpFrac() const;
void SetNtpFrac(uint32_t ntpFrac);
/* Pure virtual methods inherited from ExtendedReportBlock. */
public:
virtual void Dump() const override;
virtual size_t Serialize(uint8_t* buffer) override;
virtual size_t GetSize() const override;
private:
Body* body{ nullptr };
uint8_t raw[sizeof(Body)] = { 0 };
};
/* Inline ReceiverReferenceTime instance methods. */
inline ReceiverReferenceTime::ReceiverReferenceTime()
: ExtendedReportBlock(RTCP::ExtendedReportBlock::Type::RRT)
{
this->body = reinterpret_cast<Body*>(this->raw);
}
inline ReceiverReferenceTime::ReceiverReferenceTime(CommonHeader* header)
: ExtendedReportBlock(ExtendedReportBlock::Type::RRT)
{
this->header = header;
this->body = reinterpret_cast<Body*>((header) + 1);
}
inline size_t ReceiverReferenceTime::GetSize() const
{
size_t size{ 4 }; // Common header.
size += sizeof(Body);
return size;
}
inline uint32_t ReceiverReferenceTime::GetNtpSec() const
{
return uint32_t{ ntohl(this->body->ntpSec) };
}
inline void ReceiverReferenceTime::SetNtpSec(uint32_t ntpSec)
{
this->body->ntpSec = uint32_t{ htonl(ntpSec) };
}
inline uint32_t ReceiverReferenceTime::GetNtpFrac() const
{
return uint32_t{ ntohl(this->body->ntpFrac) };
}
inline void ReceiverReferenceTime::SetNtpFrac(uint32_t ntpFrac)
{
this->body->ntpFrac = uint32_t{ htonl(ntpFrac) };
}
} // namespace RTCP
} // namespace RTC
#endif
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define MS_RTC_RTP_STREAM_RECV_HPP #define MS_RTC_RTP_STREAM_RECV_HPP
#include "RTC/NackGenerator.hpp" #include "RTC/NackGenerator.hpp"
#include "RTC/RTCP/XrDelaySinceLastRr.hpp"
#include "RTC/RateCalculator.hpp" #include "RTC/RateCalculator.hpp"
#include "RTC/RtpStream.hpp" #include "RTC/RtpStream.hpp"
#include "handles/Timer.hpp" #include "handles/Timer.hpp"
...@@ -49,6 +50,7 @@ namespace RTC ...@@ -49,6 +50,7 @@ namespace RTC
bool ReceiveRtxPacket(RTC::RtpPacket* packet); bool ReceiveRtxPacket(RTC::RtpPacket* packet);
RTC::RTCP::ReceiverReport* GetRtcpReceiverReport(); RTC::RTCP::ReceiverReport* GetRtcpReceiverReport();
void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report); void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report);
void ReceiveRtcpXrDelaySinceLastRr(RTC::RTCP::DelaySinceLastRr::SsrcInfo* ssrcInfo);
void RequestKeyFrame(); void RequestKeyFrame();
void Pause() override; void Pause() override;
void Resume() override; void Resume() override;
...@@ -79,6 +81,7 @@ namespace RTC ...@@ -79,6 +81,7 @@ namespace RTC
// sender report arrival. // sender report arrival.
uint32_t transit{ 0 }; // Relative transit time for prev packet. uint32_t transit{ 0 }; // Relative transit time for prev packet.
uint32_t jitter{ 0 }; uint32_t jitter{ 0 };
float rtt{ 0 };
uint8_t firSeqNumber{ 0 }; uint8_t firSeqNumber{ 0 };
uint32_t reportedPacketLost{ 0 }; uint32_t reportedPacketLost{ 0 };
std::unique_ptr<RTC::NackGenerator> nackGenerator; std::unique_ptr<RTC::NackGenerator> nackGenerator;
......
...@@ -108,6 +108,9 @@ ...@@ -108,6 +108,9 @@
'src/RTC/RTCP/FeedbackPsLei.cpp', 'src/RTC/RTCP/FeedbackPsLei.cpp',
'src/RTC/RTCP/FeedbackPsAfb.cpp', 'src/RTC/RTCP/FeedbackPsAfb.cpp',
'src/RTC/RTCP/FeedbackPsRemb.cpp', 'src/RTC/RTCP/FeedbackPsRemb.cpp',
'src/RTC/RTCP/XR.cpp',
'src/RTC/RTCP/XrDelaySinceLastRr.cpp',
'src/RTC/RTCP/XrReceiverReferenceTime.cpp',
'src/RTC/RembClient.cpp', 'src/RTC/RembClient.cpp',
'src/RTC/RembServer/AimdRateControl.cpp', 'src/RTC/RembServer/AimdRateControl.cpp',
'src/RTC/RembServer/InterArrival.cpp', 'src/RTC/RembServer/InterArrival.cpp',
...@@ -205,6 +208,9 @@ ...@@ -205,6 +208,9 @@
'include/RTC/RTCP/FeedbackPsLei.hpp', 'include/RTC/RTCP/FeedbackPsLei.hpp',
'include/RTC/RTCP/FeedbackPsAfb.hpp', 'include/RTC/RTCP/FeedbackPsAfb.hpp',
'include/RTC/RTCP/FeedbackPsRemb.hpp', 'include/RTC/RTCP/FeedbackPsRemb.hpp',
'include/RTC/RTCP/XR.hpp',
'include/RTC/RTCP/XrDelaySinceLastRr.hpp',
'include/RTC/RTCP/XrReceiverReferenceTime.hpp',
'include/RTC/RembClient.hpp', 'include/RTC/RembClient.hpp',
'include/RTC/RembServer/AimdRateControl.hpp', 'include/RTC/RembServer/AimdRateControl.hpp',
'include/RTC/RembServer/InterArrival.hpp', 'include/RTC/RembServer/InterArrival.hpp',
...@@ -328,6 +334,7 @@ ...@@ -328,6 +334,7 @@
'test/src/RTC/RTCP/TestSdes.cpp', 'test/src/RTC/RTCP/TestSdes.cpp',
'test/src/RTC/RTCP/TestSenderReport.cpp', 'test/src/RTC/RTCP/TestSenderReport.cpp',
'test/src/RTC/RTCP/TestPacket.cpp', 'test/src/RTC/RTCP/TestPacket.cpp',
'test/src/RTC/RTCP/TestXr.cpp',
'test/src/Utils/TestBits.cpp', 'test/src/Utils/TestBits.cpp',
'test/src/Utils/TestIP.cpp', 'test/src/Utils/TestIP.cpp',
'test/src/Utils/TestString.cpp', 'test/src/Utils/TestString.cpp',
...@@ -381,6 +388,7 @@ ...@@ -381,6 +388,7 @@
'fuzzer/src/RTC/RTCP/FuzzerReceiverReport.cpp', 'fuzzer/src/RTC/RTCP/FuzzerReceiverReport.cpp',
'fuzzer/src/RTC/RTCP/FuzzerSdes.cpp', 'fuzzer/src/RTC/RTCP/FuzzerSdes.cpp',
'fuzzer/src/RTC/RTCP/FuzzerSenderReport.cpp', 'fuzzer/src/RTC/RTCP/FuzzerSenderReport.cpp',
'fuzzer/src/RTC/RTCP/FuzzerXr.cpp',
# C++ include files. # C++ include files.
'fuzzer/include/RTC/FuzzerStunMessage.hpp', 'fuzzer/include/RTC/FuzzerStunMessage.hpp',
'fuzzer/include/RTC/FuzzerRtpPacket.hpp', 'fuzzer/include/RTC/FuzzerRtpPacket.hpp',
...@@ -405,6 +413,7 @@ ...@@ -405,6 +413,7 @@
'fuzzer/include/RTC/RTCP/FuzzerReceiverReport.hpp', 'fuzzer/include/RTC/RTCP/FuzzerReceiverReport.hpp',
'fuzzer/include/RTC/RTCP/FuzzerSdesReport.hpp', 'fuzzer/include/RTC/RTCP/FuzzerSdesReport.hpp',
'fuzzer/include/RTC/RTCP/FuzzerSenderReport.hpp', 'fuzzer/include/RTC/RTCP/FuzzerSenderReport.hpp',
'fuzzer/include/RTC/RTCP/FuzzerXr.hpp',
], ],
'include_dirs': 'include_dirs':
[ [
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "Utils.hpp" #include "Utils.hpp"
#include "Channel/Notifier.hpp" #include "Channel/Notifier.hpp"
#include "RTC/Codecs/Codecs.hpp" #include "RTC/Codecs/Codecs.hpp"
#include "RTC/RTCP/XrReceiverReferenceTime.hpp"
#include <cstring> // std::memcpy() #include <cstring> // std::memcpy()
namespace RTC namespace RTC
...@@ -566,6 +567,24 @@ namespace RTC ...@@ -566,6 +567,24 @@ namespace RTC
this->listener->OnProducerRtcpSenderReport(this, rtpStream, first); this->listener->OnProducerRtcpSenderReport(this, rtpStream, first);
} }
void Producer::ReceiveRtcpXrDelaySinceLastRr(RTC::RTCP::DelaySinceLastRr::SsrcInfo* ssrcInfo)
{
MS_TRACE();
auto it = this->mapSsrcRtpStream.find(ssrcInfo->GetSsrc());
if (it == this->mapSsrcRtpStream.end())
{
MS_WARN_TAG(rtcp, "RtpStream not found [ssrc:%" PRIu32 "]", ssrcInfo->GetSsrc());
return;
}
auto* rtpStream = it->second;
rtpStream->ReceiveRtcpXrDelaySinceLastRr(ssrcInfo);
}
void Producer::GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now) void Producer::GetRtcp(RTC::RTCP::CompoundPacket* packet, uint64_t now)
{ {
MS_TRACE(); MS_TRACE();
...@@ -581,6 +600,17 @@ namespace RTC ...@@ -581,6 +600,17 @@ namespace RTC
packet->AddReceiverReport(report); packet->AddReceiverReport(report);
} }
// Add a receiver reference time report if no present in the packet.
if (!packet->HasReceiverReferenceTime())
{
auto ntp = Utils::Time::TimeMs2Ntp(now);
auto report = new RTC::RTCP::ReceiverReferenceTime();
report->SetNtpSec(ntp.seconds);
report->SetNtpFrac(ntp.fractions);
packet->AddReceiverReferenceTime(report);
}
this->lastRtcpSentTime = now; this->lastRtcpSentTime = now;
} }
......
...@@ -36,6 +36,9 @@ namespace RTC ...@@ -36,6 +36,9 @@ namespace RTC
if (this->sdesPacket.GetCount() != 0u) if (this->sdesPacket.GetCount() != 0u)
this->size += this->sdesPacket.GetSize(); this->size += this->sdesPacket.GetSize();
if (this->xrPacket.Begin() != this->xrPacket.End())
this->size += this->xrPacket.GetSize();
// Fill it. // Fill it.
size_t offset{ 0 }; size_t offset{ 0 };
...@@ -80,7 +83,10 @@ namespace RTC ...@@ -80,7 +83,10 @@ namespace RTC
} }
if (this->sdesPacket.GetCount() != 0u) if (this->sdesPacket.GetCount() != 0u)
this->sdesPacket.Serialize(this->header + offset); offset += this->sdesPacket.Serialize(this->header + offset);
if (this->xrPacket.Begin() != this->xrPacket.End())
this->xrPacket.Serialize(this->header + offset);
} }
void CompoundPacket::Dump() void CompoundPacket::Dump()
...@@ -104,6 +110,9 @@ namespace RTC ...@@ -104,6 +110,9 @@ namespace RTC
if (this->sdesPacket.GetCount() != 0u) if (this->sdesPacket.GetCount() != 0u)
this->sdesPacket.Dump(); this->sdesPacket.Dump();
if (this->xrPacket.Begin() != this->xrPacket.End())
this->xrPacket.Dump();
MS_DUMP("</CompoundPacket>"); MS_DUMP("</CompoundPacket>");
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "RTC/RTCP/ReceiverReport.hpp" #include "RTC/RTCP/ReceiverReport.hpp"
#include "RTC/RTCP/Sdes.hpp" #include "RTC/RTCP/Sdes.hpp"
#include "RTC/RTCP/SenderReport.hpp" #include "RTC/RTCP/SenderReport.hpp"
#include "RTC/RTCP/XR.hpp"
namespace RTC namespace RTC
{ {
...@@ -136,7 +137,7 @@ namespace RTC ...@@ -136,7 +137,7 @@ namespace RTC
case Type::XR: case Type::XR:
{ {
current = nullptr; current = ExtendedReportPacket::Parse(data, packetLen);
break; break;
} }
......
#define MS_CLASS "RTC::RTCP::XR"
// #define MS_LOG_DEV
#include "Logger.hpp"
#include "Utils.hpp"
#include "RTC/RTCP/XrDelaySinceLastRr.hpp"
#include "RTC/RTCP/XrReceiverReferenceTime.hpp"
namespace RTC
{
namespace RTCP
{
/* Class methods. */
ExtendedReportBlock* ExtendedReportBlock::Parse(const uint8_t* data, size_t len)
{
MS_TRACE();
// Get the header.
auto* header = const_cast<CommonHeader*>(reinterpret_cast<const CommonHeader*>(data));
// Ensure there is space for the common header and the SSRC of packet sender.
if (sizeof(CommonHeader) > len)
{
MS_WARN_TAG(rtcp, "not enough space for a extended report block, report discarded");
return nullptr;
}
switch (ExtendedReportBlock::Type(header->blockType))
{
case RTC::RTCP::ExtendedReportBlock::Type::RRT:
{
return ReceiverReferenceTime::Parse(data, len);
}
case RTC::RTCP::ExtendedReportBlock::Type::DLRR:
{
return DelaySinceLastRr::Parse(data, len);
}
default:
{
MS_WARN_TAG(rtcp, "unknown RTCP XR block type [blockType:%" PRIu8 "]", header->blockType);
break;
}
}
return nullptr;
}
/* Instance methods. */
/* Class methods. */
ExtendedReportPacket* ExtendedReportPacket::Parse(const uint8_t* data, size_t len)
{
MS_TRACE();
// Get the header.
auto* header = const_cast<CommonHeader*>(reinterpret_cast<const CommonHeader*>(data));
// Ensure there is space for the common header and the SSRC of packet sender.
if (sizeof(CommonHeader) + sizeof(uint32_t) > len)
{
MS_WARN_TAG(rtcp, "not enough space for a extended report packet, packet discarded");
return nullptr;
}
std::unique_ptr<ExtendedReportPacket> packet(new ExtendedReportPacket());
packet->SetSsrc(
Utils::Byte::Get4Bytes(reinterpret_cast<uint8_t*>(header), sizeof(CommonHeader)));
auto offset = sizeof(Packet::CommonHeader) + sizeof(uint32_t) /* ssrc */;
while (len > offset)
{
ExtendedReportBlock* report = ExtendedReportBlock::Parse(data + offset, len - offset);
if (report != nullptr)
{
packet->AddReport(report);
offset += report->GetSize();
}
else
{
return packet.release();
}
}
return packet.release();
}
/* Instance methods. */
size_t ExtendedReportPacket::Serialize(uint8_t* buffer)
{
MS_TRACE();
size_t offset = Packet::Serialize(buffer);
// Copy the SSRC.
std::memcpy(buffer + sizeof(Packet::CommonHeader), &this->ssrc, sizeof(this->ssrc));
offset += sizeof(this->ssrc);
// Serialize reports.
for (auto* report : this->reports)
{
offset += report->Serialize(buffer + offset);
}
return offset;
}
void ExtendedReportPacket::Dump() const
{
MS_TRACE();
MS_DUMP("<ExtendedReportPacket>");
MS_DUMP(" ssrc: %" PRIu32, static_cast<uint32_t>(ntohl(this->ssrc)));
for (auto* report : this->reports)
{
report->Dump();
}
MS_DUMP("</ExtendedReportPacket>");
}
} // namespace RTCP
} // namespace RTC
#define MS_CLASS "RTC::RTCP::XrDelaySinceLastRr"
// #define MS_LOG_DEV
#include "RTC/RTCP/XrDelaySinceLastRr.hpp"
#include "Logger.hpp"
#include <cstring>
namespace RTC
{
namespace RTCP
{
/* Class methods. */
DelaySinceLastRr::SsrcInfo* DelaySinceLastRr::SsrcInfo::Parse(const uint8_t* data, size_t len)
{
MS_TRACE();
// Ensure there is space for the common header and the SSRC of packet sender.
if (sizeof(Body) > len)
{
MS_WARN_TAG(rtcp, "not enough space for a extended DSLR sub-block, sub-block discarded");
return nullptr;
}
// Get the header.
auto* body = const_cast<SsrcInfo::Body*>(reinterpret_cast<const SsrcInfo::Body*>(data));
auto ssrcInfo = new DelaySinceLastRr::SsrcInfo(body);
return ssrcInfo;
}
/* Instance methods. */
void DelaySinceLastRr::SsrcInfo::Dump() const
{
MS_TRACE();
MS_DUMP(" <SsrcInfo>");
MS_DUMP(" ssrc : %" PRIu32, GetSsrc());
MS_DUMP(" lrr : %" PRIu32, GetLastReceiverReport());
MS_DUMP(" dlrr : %" PRIu32, GetDelaySinceLastReceiverReport());
MS_DUMP(" <SsrcInfo>");
}
size_t DelaySinceLastRr::SsrcInfo::Serialize(uint8_t* buffer)
{
MS_TRACE();
// Copy the body.
std::memcpy(buffer, this->body, sizeof(DelaySinceLastRr::SsrcInfo::Body));
return sizeof(DelaySinceLastRr::SsrcInfo::Body);
}
/* Class methods. */
DelaySinceLastRr* DelaySinceLastRr::Parse(const uint8_t* data, size_t len)
{
MS_TRACE();
auto* header = const_cast<ExtendedReportBlock::CommonHeader*>(
reinterpret_cast<const ExtendedReportBlock::CommonHeader*>(data));
std::unique_ptr<DelaySinceLastRr> report(new DelaySinceLastRr(header));
size_t offset{ sizeof(ExtendedReportBlock::CommonHeader) };
uint16_t reportLength = ntohs(header->length) * 4;
while (len > offset && reportLength >= sizeof(DelaySinceLastRr::SsrcInfo::Body))
{
DelaySinceLastRr::SsrcInfo* ssrcInfo =
DelaySinceLastRr::SsrcInfo::Parse(data + offset, len - offset);
if (ssrcInfo != nullptr)
{
report->AddSsrcInfo(ssrcInfo);
offset += ssrcInfo->GetSize();
}
else
{
return report.release();
}
offset += ssrcInfo->GetSize();
reportLength -= sizeof(DelaySinceLastRr::SsrcInfo::Body);
}
return report.release();
}
/* Instance methods. */
size_t DelaySinceLastRr::Serialize(uint8_t* buffer)
{
MS_TRACE();
size_t length = static_cast<uint16_t>((sizeof(SsrcInfo::Body) * this->ssrcInfos.size() / 4));
// Fill the common header.
this->header->blockType = static_cast<uint8_t>(this->type);
this->header->reserved = 0;
this->header->length = uint16_t{ htons(length) };
std::memcpy(buffer, this->header, sizeof(ExtendedReportBlock::CommonHeader));
size_t offset{ sizeof(ExtendedReportBlock::CommonHeader) };
// Serialize sub-blocks.
for (auto* ssrcInfo : this->ssrcInfos)
{
offset += ssrcInfo->Serialize(buffer + offset);
}
return offset;
}
void DelaySinceLastRr::Dump() const
{
MS_TRACE();
MS_DUMP("<DelaySinceLastRr>");
MS_DUMP(" block type : %" PRIu8, (uint8_t)this->type);
MS_DUMP(" reserved : 0");
MS_DUMP(
" length : %" PRIu16,
static_cast<uint16_t>((sizeof(SsrcInfo::Body) * this->ssrcInfos.size() / 4)));
for (auto* ssrcInfo : this->ssrcInfos)
{
ssrcInfo->Dump();
}
MS_DUMP("</DelaySinceLastRr>");
}
} // namespace RTCP
} // namespace RTC
#define MS_CLASS "RTC::RTCP::XrReceiverReferenceTime"
// #define MS_LOG_DEV
#include "RTC/RTCP/XrReceiverReferenceTime.hpp"
#include "Logger.hpp"
#include <cstring>
namespace RTC
{
namespace RTCP
{
/* Class methods. */
ReceiverReferenceTime* ReceiverReferenceTime::Parse(const uint8_t* data, size_t len)
{
MS_TRACE();
// Ensure there is space for the common header and the body.
if (sizeof(ExtendedReportBlock::CommonHeader) + sizeof(ReceiverReferenceTime::Body) > len)
{
MS_WARN_TAG(rtcp, "not enough space for a extended RRT block, block discarded");
return nullptr;
}
// Get the header.
auto* header = const_cast<ExtendedReportBlock::CommonHeader*>(
reinterpret_cast<const ExtendedReportBlock::CommonHeader*>(data));
return new ReceiverReferenceTime(header);
}
void ReceiverReferenceTime::Dump() const
{
MS_TRACE();
MS_DUMP("<ReceiverReferenceTime>");
MS_DUMP(" block type : %" PRIu8, (uint8_t)this->type);
MS_DUMP(" reserved : 0");
MS_DUMP(" length : 2");
MS_DUMP(" ntp sec : %" PRIu32, GetNtpSec());
MS_DUMP(" ntp frac : %" PRIu32, GetNtpFrac());
MS_DUMP("</ReceiverReferenceTime>");
}
size_t ReceiverReferenceTime::Serialize(uint8_t* buffer)
{
MS_TRACE();
// Fill the common header.
this->header->blockType = static_cast<uint8_t>(this->type);
this->header->reserved = 0;
this->header->length = htons(2);
std::memcpy(buffer, this->header, sizeof(ExtendedReportBlock::CommonHeader));
size_t offset{ sizeof(ExtendedReportBlock::CommonHeader) };
// Copy the body.
std::memcpy(buffer + offset, this->body, sizeof(ReceiverReferenceTime::Body));
offset += sizeof(ReceiverReferenceTime::Body);
return offset;
}
} // namespace RTCP
} // namespace RTC
...@@ -213,6 +213,9 @@ namespace RTC ...@@ -213,6 +213,9 @@ namespace RTC
jsonObject["byteCount"] = this->transmissionCounter.GetBytes(); jsonObject["byteCount"] = this->transmissionCounter.GetBytes();
jsonObject["bitrate"] = this->transmissionCounter.GetBitrate(now); jsonObject["bitrate"] = this->transmissionCounter.GetBitrate(now);
if (this->rtt != 0.0f)
jsonObject["roundTripTime"] = this->rtt;
if (GetSpatialLayers() > 1 || GetTemporalLayers() > 1) if (GetSpatialLayers() > 1 || GetTemporalLayers() > 1)
{ {
jsonObject["bitrateByLayer"] = json::object(); jsonObject["bitrateByLayer"] = json::object();
...@@ -492,6 +495,41 @@ namespace RTC ...@@ -492,6 +495,41 @@ namespace RTC
UpdateScore(); UpdateScore();
} }
void RtpStreamRecv::ReceiveRtcpXrDelaySinceLastRr(RTC::RTCP::DelaySinceLastRr::SsrcInfo* ssrcInfo)
{
MS_TRACE();
/* Calculate RTT. */
// Get the NTP representation of the current timestamp.
uint64_t now = DepLibUV::GetTime();
auto ntp = Utils::Time::TimeMs2Ntp(now);
// Get the compact NTP representation of the current timestamp.
uint32_t compactNtp = (ntp.seconds & 0x0000FFFF) << 16;
compactNtp |= (ntp.fractions & 0xFFFF0000) >> 16;
uint32_t lastRr = ssrcInfo->GetLastReceiverReport();
uint32_t dlrr = ssrcInfo->GetDelaySinceLastReceiverReport();
// RTT in 1/2^16 second fractions.
uint32_t rtt{ 0 };
// If no Receiver Extended Report was received by the remote endpoint yet, ignore lastRr
// and dlrr values in the Sender Extended Report.
if (!lastRr || !dlrr)
rtt = 0;
else if (compactNtp > dlrr + lastRr)
rtt = compactNtp - dlrr - lastRr;
else
rtt = 0;
// RTT in milliseconds.
this->rtt = (rtt >> 16) * 1000;
this->rtt += (static_cast<float>(rtt & 0x0000FFFF) / 65536) * 1000;
}
void RtpStreamRecv::RequestKeyFrame() void RtpStreamRecv::RequestKeyFrame()
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -44,12 +44,14 @@ namespace RTC ...@@ -44,12 +44,14 @@ namespace RTC
RTC::RtpStream::FillJsonStats(jsonObject); RTC::RtpStream::FillJsonStats(jsonObject);
jsonObject["timestamp"] = now; jsonObject["timestamp"] = now;
jsonObject["type"] = "outbound-rtp"; jsonObject["type"] = "outbound-rtp";
jsonObject["roundTripTime"] = this->rtt; jsonObject["packetCount"] = this->transmissionCounter.GetPacketCount();
jsonObject["packetCount"] = this->transmissionCounter.GetPacketCount(); jsonObject["byteCount"] = this->transmissionCounter.GetBytes();
jsonObject["byteCount"] = this->transmissionCounter.GetBytes(); jsonObject["bitrate"] = this->transmissionCounter.GetBitrate(now);
jsonObject["bitrate"] = this->transmissionCounter.GetBitrate(now);
if (this->rtt != 0.0f)
jsonObject["roundTripTime"] = this->rtt;
} }
bool RtpStreamSend::ReceivePacket(RTC::RtpPacket* packet) bool RtpStreamSend::ReceivePacket(RTC::RtpPacket* packet)
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "RTC/RTCP/FeedbackRtp.hpp" #include "RTC/RTCP/FeedbackRtp.hpp"
#include "RTC/RTCP/FeedbackRtpNack.hpp" #include "RTC/RTCP/FeedbackRtpNack.hpp"
#include "RTC/RTCP/ReceiverReport.hpp" #include "RTC/RTCP/ReceiverReport.hpp"
#include "RTC/RTCP/XrDelaySinceLastRr.hpp"
#include "RTC/RtpDictionaries.hpp" #include "RTC/RtpDictionaries.hpp"
#include "RTC/SimpleConsumer.hpp" #include "RTC/SimpleConsumer.hpp"
#include "RTC/SimulcastConsumer.hpp" #include "RTC/SimulcastConsumer.hpp"
...@@ -1058,6 +1059,56 @@ namespace RTC ...@@ -1058,6 +1059,56 @@ namespace RTC
break; break;
} }
case RTC::RTCP::Type::XR:
{
auto* xr = static_cast<RTC::RTCP::ExtendedReportPacket*>(packet);
for (auto it = xr->Begin(); it != xr->End(); ++it)
{
auto& report = (*it);
switch (report->GetType())
{
case RTC::RTCP::ExtendedReportBlock::Type::DLRR:
{
auto* dlrr = static_cast<RTC::RTCP::DelaySinceLastRr*>(report);
for (auto it2 = dlrr->Begin(); it2 != dlrr->End(); ++it2)
{
auto& ssrcInfo = (*it2);
// SSRC should be filled in the sub-block.
if (ssrcInfo->GetSsrc() == 0)
ssrcInfo->SetSsrc(xr->GetSsrc());
auto* producer = this->rtpListener.GetProducer(ssrcInfo->GetSsrc());
if (producer == nullptr)
{
MS_WARN_TAG(
rtcp,
"no Producer found for received Sender Extended Report [ssrc:%" PRIu32 "]",
ssrcInfo->GetSsrc());
continue;
}
producer->ReceiveRtcpXrDelaySinceLastRr(ssrcInfo);
}
break;
}
default:
{
break;
}
}
}
break;
}
default: default:
{ {
MS_DEBUG_TAG( MS_DEBUG_TAG(
......
#include "common.hpp"
#include "catch.hpp"
#include "RTC/RTCP/XrDelaySinceLastRr.hpp"
#include "RTC/RTCP/XrReceiverReferenceTime.hpp"
#include <cstring> // std::memcmp
using namespace RTC::RTCP;
SCENARIO("RTCP XrDelaySinceLastRt parsing", "[parser][rtcp][xr-dlrr]")
{
SECTION("create RRT")
{
// Create local report and check content.
auto* report1 = new ReceiverReferenceTime();
report1->SetNtpSec(11111111);
report1->SetNtpFrac(22222222);
REQUIRE(report1->GetType() == ExtendedReportBlock::Type::RRT);
REQUIRE(report1->GetNtpSec() == 11111111);
REQUIRE(report1->GetNtpFrac() == 22222222);
// Serialize the report into an external buffer.
uint8_t bufferReport1[256]{ 0 };
report1->Serialize(bufferReport1);
// Create a new report out of the external buffer.
auto report2 = ReceiverReferenceTime::Parse(bufferReport1, report1->GetSize());
REQUIRE(report1->GetType() == report2->GetType());
REQUIRE(report1->GetNtpSec() == report2->GetNtpSec());
REQUIRE(report1->GetNtpFrac() == report2->GetNtpFrac());
// Create a local packet.
std::unique_ptr<ExtendedReportPacket> packet1(new ExtendedReportPacket());
packet1->SetSsrc(2222);
packet1->AddReport(report1);
packet1->AddReport(report2);
REQUIRE(packet1->GetType() == Type::XR);
REQUIRE(packet1->GetCount() == 0);
REQUIRE(packet1->GetSsrc() == 2222);
// Total size:
// - RTCP common header
// - SSRC
// - block 1
// - block 2
REQUIRE(packet1->GetSize() == 4 + 4 + 12 + 12);
// Serialize the packet into an external buffer.
uint8_t bufferPacket1[256]{ 0 };
uint8_t bufferPacket2[256]{ 0 };
packet1->Serialize(bufferPacket1);
// Create a new packet out of the external buffer.
auto packet2 = ExtendedReportPacket::Parse(bufferPacket1, packet1->GetSize());
REQUIRE(packet2->GetType() == packet1->GetType());
REQUIRE(packet2->GetCount() == packet1->GetCount());
REQUIRE(packet2->GetSsrc() == packet1->GetSsrc());
REQUIRE(packet2->GetSize() == packet1->GetSize());
packet2->Serialize(bufferPacket2);
REQUIRE(std::memcmp(bufferPacket1, bufferPacket2, packet1->GetSize()) == 0);
}
SECTION("create DLRR")
{
// Create local report and check content.
auto* report1 = new DelaySinceLastRr();
auto* ssrcInfo1 = new DelaySinceLastRr::SsrcInfo();
ssrcInfo1->SetSsrc(1234);
ssrcInfo1->SetLastReceiverReport(11111111);
ssrcInfo1->SetDelaySinceLastReceiverReport(22222222);
REQUIRE(ssrcInfo1->GetSsrc() == 1234);
REQUIRE(ssrcInfo1->GetLastReceiverReport() == 11111111);
REQUIRE(ssrcInfo1->GetDelaySinceLastReceiverReport() == 22222222);
REQUIRE(ssrcInfo1->GetSize() == sizeof(DelaySinceLastRr::SsrcInfo::Body));
report1->AddSsrcInfo(ssrcInfo1);
// Serialize the report into an external buffer.
uint8_t bufferReport1[256]{ 0 };
report1->Serialize(bufferReport1);
// Create a new report out of the external buffer.
auto report2 = DelaySinceLastRr::Parse(bufferReport1, report1->GetSize());
REQUIRE(report1->GetType() == report2->GetType());
auto ssrcInfoIt = report2->Begin();
auto* ssrcInfo2 = *ssrcInfoIt;
REQUIRE(ssrcInfo1->GetSsrc() == ssrcInfo2->GetSsrc());
REQUIRE(ssrcInfo1->GetLastReceiverReport() == ssrcInfo2->GetLastReceiverReport());
REQUIRE(
ssrcInfo1->GetDelaySinceLastReceiverReport() == ssrcInfo2->GetDelaySinceLastReceiverReport());
REQUIRE(ssrcInfo1->GetSize() == ssrcInfo2->GetSize());
// Create a local packet.
std::unique_ptr<ExtendedReportPacket> packet1(new ExtendedReportPacket());
packet1->SetSsrc(2222);
packet1->AddReport(report1);
packet1->AddReport(report2);
REQUIRE(packet1->GetType() == Type::XR);
REQUIRE(packet1->GetCount() == 0);
REQUIRE(packet1->GetSsrc() == 2222);
// Total size:
// - RTCP common header
// - SSRC
// - block 1
// - block 2
REQUIRE(packet1->GetSize() == 4 + 4 + 16 + 16);
// Serialize the packet into an external buffer.
uint8_t bufferPacket1[256]{ 0 };
uint8_t bufferPacket2[256]{ 0 };
packet1->Serialize(bufferPacket1);
// Create a new packet out of the external buffer.
auto packet2 = ExtendedReportPacket::Parse(bufferPacket1, packet1->GetSize());
REQUIRE(packet2->GetType() == packet1->GetType());
REQUIRE(packet2->GetCount() == packet1->GetCount());
REQUIRE(packet2->GetSsrc() == packet1->GetSsrc());
REQUIRE(packet2->GetSize() == packet1->GetSize());
packet2->Serialize(bufferPacket2);
REQUIRE(std::memcmp(bufferPacket1, bufferPacket2, packet1->GetSize()) == 0);
}
}
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论