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

Rtcp: generate sender reports internally

上级 ac9f33e3
...@@ -12,17 +12,17 @@ In order to get the best media quality from the remote RTP senders, *mediasoup* ...@@ -12,17 +12,17 @@ In order to get the best media quality from the remote RTP senders, *mediasoup*
### Sender Reports ### Sender Reports
*mediasoup* relays the Sender Reports coming from the remote RTP senders. *mediasoup* locally generates the Sender Reports of the streams it sends.
### Receiver Reports ### Receiver Reports
*mediasoup* will locally generate the Receiver Reports of the streams it receivers. At the same time, it will consume the Receiver Reports from every remote RTP receivers. *mediasoup* locally generates the Receiver Reports of the streams it receives. At the same time, it will consume the Receiver Reports from every remote RTP receivers.
The combination of Sender and Receiver Reports will be used to determine the quality of each link. Information that will be available at the JavaScript API level in order to determine the quality of each participant in the room. The combination of Sender and Receiver Reports will be used to determine the quality of each link. Information that will be available at the JavaScript API level in order to determine the quality of each participant in the room.
### SDES ### SDES
SDES information will be relayed from the remote RTP sender to the corresponding remote RTP receivers. SDES information is relayed from the remote RTP sender to the corresponding remote RTP receivers.
### BYE ### BYE
...@@ -153,7 +153,7 @@ In future, this information is to be consumed by the local RTP Senders in order ...@@ -153,7 +153,7 @@ In future, this information is to be consumed by the local RTP Senders in order
| SR | RR | SDES | BYE | APP | | SR | RR | SDES | BYE | APP |
-------------|----|----|------|-----|-----| -------------|----|----|------|-----|-----|
RtpSender | B | C | | | | RtpSender | G | C | | | |
RtpReceiver | C | G | B | B | B | RtpReceiver | C | G | B | B | B |
### RTP Feedback RTCP ### RTP Feedback RTCP
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "RTC/RtpDictionaries.h" #include "RTC/RtpDictionaries.h"
#include "RTC/RtpPacket.h" #include "RTC/RtpPacket.h"
#include "RTC/RtpDataCounter.h" #include "RTC/RtpDataCounter.h"
#include "RTC/RTCP/SenderReport.h"
#include "RTC/RTCP/Sdes.h" #include "RTC/RTCP/Sdes.h"
#include "RTC/RTCP/FeedbackRtpNack.h" #include "RTC/RTCP/FeedbackRtpNack.h"
#include "RTC/RTCP/CompoundPacket.h" #include "RTC/RTCP/CompoundPacket.h"
...@@ -49,7 +48,6 @@ namespace RTC ...@@ -49,7 +48,6 @@ namespace RTC
void RemoveTransport(RTC::Transport* transport); void RemoveTransport(RTC::Transport* transport);
RTC::RtpParameters* GetParameters(); RTC::RtpParameters* GetParameters();
void SendRtpPacket(RTC::RtpPacket* packet); void SendRtpPacket(RTC::RtpPacket* packet);
void ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report);
void ReceiveRtcpSdesChunk(RTC::RTCP::SdesChunk* chunk); void ReceiveRtcpSdesChunk(RTC::RTCP::SdesChunk* chunk);
void GetRtcp(RTC::RTCP::CompoundPacket *packet, uint64_t now); void GetRtcp(RTC::RTCP::CompoundPacket *packet, uint64_t now);
void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket); void ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket);
...@@ -76,8 +74,6 @@ namespace RTC ...@@ -76,8 +74,6 @@ namespace RTC
std::unordered_set<uint8_t> supportedPayloadTypes; std::unordered_set<uint8_t> supportedPayloadTypes;
// Whether this RtpSender is valid according to Peer capabilities. // Whether this RtpSender is valid according to Peer capabilities.
bool available = false; bool available = false;
// Sender Report holding the RTP stats.
std::unique_ptr<RTC::RTCP::SenderReport> senderReport;
std::unique_ptr<RTC::RTCP::SdesChunk> sdesChunk; std::unique_ptr<RTC::RTCP::SdesChunk> sdesChunk;
// RTP counters. // RTP counters.
RTC::RtpDataCounter transmitted; RTC::RtpDataCounter transmitted;
...@@ -116,13 +112,6 @@ namespace RTC ...@@ -116,13 +112,6 @@ namespace RTC
return this->rtpParameters; return this->rtpParameters;
} }
inline
void RtpSender::ReceiveRtcpSenderReport(RTC::RTCP::SenderReport* report)
{
this->senderReport.reset(new RTC::RTCP::SenderReport(report));
this->senderReport->Serialize();
};
inline inline
void RtpSender::ReceiveRtcpSdesChunk(RTC::RTCP::SdesChunk* chunk) void RtpSender::ReceiveRtcpSdesChunk(RTC::RTCP::SdesChunk* chunk)
{ {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define MS_RTC_RTP_STREAM_SEND_H #define MS_RTC_RTP_STREAM_SEND_H
#include "RTC/RtpStream.h" #include "RTC/RtpStream.h"
#include "RTC/RTCP/SenderReport.h"
#include <vector> #include <vector>
#include <list> #include <list>
...@@ -29,6 +30,7 @@ namespace RTC ...@@ -29,6 +30,7 @@ namespace RTC
bool ReceivePacket(RTC::RtpPacket* packet); bool ReceivePacket(RTC::RtpPacket* packet);
void RequestRtpRetransmission(uint16_t seq, uint16_t bitmask, std::vector<RTC::RtpPacket*>& container); void RequestRtpRetransmission(uint16_t seq, uint16_t bitmask, std::vector<RTC::RtpPacket*>& container);
RTC::RTCP::SenderReport* GetRtcpSenderReport(uint64_t now);
private: private:
void ClearBuffer(); void ClearBuffer();
...@@ -39,6 +41,11 @@ namespace RTC ...@@ -39,6 +41,11 @@ namespace RTC
std::vector<StorageItem> storage; std::vector<StorageItem> storage;
typedef std::list<BufferItem> Buffer; typedef std::list<BufferItem> Buffer;
Buffer buffer; Buffer buffer;
private:
size_t receivedBytes = 0; // Bytes received.
uint64_t lastPacketTimeMs = 0; // Time (MS) when the last packet was received.
uint32_t lastPacketRtpTimestamp = 0; // RTP Timestamp of the last packet.
}; };
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <string> #include <string>
#include <cstring> // std::memcmp(), std::memcpy() #include <cstring> // std::memcmp(), std::memcpy()
#include <openssl/hmac.h> #include <openssl/hmac.h>
#include <sys/time.h> // gettimeofday
namespace Utils namespace Utils
{ {
...@@ -269,6 +270,33 @@ namespace Utils ...@@ -269,6 +270,33 @@ namespace Utils
{ {
std::transform(str.begin(), str.end(), str.begin(), ::tolower); std::transform(str.begin(), str.end(), str.begin(), ::tolower);
} }
class Time
{
// Seconds from Jan 1, 1900 to Jan 1, 1970
static constexpr uint32_t UnixNtpOffset = 0x83AA7E80;
// NTP fractional unit.
static constexpr double NtpFractionalUnit = 1LL<<32;
public:
struct Ntp
{
uint32_t seconds;
uint32_t fractions;
};
static void CurrentTimeNtp(Ntp& ntp);
};
inline
void Time::CurrentTimeNtp(Ntp& ntp)
{
struct timeval tv;
gettimeofday(&tv, NULL);
ntp.seconds = tv.tv_sec + UnixNtpOffset;
ntp.fractions = (uint32_t)((double)(tv.tv_usec) * NtpFractionalUnit * 1.0e-6);
}
} }
#endif #endif
...@@ -663,13 +663,6 @@ namespace RTC ...@@ -663,13 +663,6 @@ namespace RTC
rtpReceiver->ReceiveRtcpSenderReport(report); rtpReceiver->ReceiveRtcpSenderReport(report);
MS_ASSERT(this->mapRtpReceiverRtpSenders.find(rtpReceiver) != this->mapRtpReceiverRtpSenders.end(), "RtpReceiver not present in the map"); MS_ASSERT(this->mapRtpReceiverRtpSenders.find(rtpReceiver) != this->mapRtpReceiverRtpSenders.end(), "RtpReceiver not present in the map");
auto& rtpSenders = this->mapRtpReceiverRtpSenders[rtpReceiver];
for (auto& rtpSender : rtpSenders)
{
rtpSender->ReceiveRtcpSenderReport(report);
}
} }
void Room::onPeerRtcpSdesChunk(RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RTCP::SdesChunk* chunk) void Room::onPeerRtcpSdesChunk(RTC::Peer* peer, RTC::RtpReceiver* rtpReceiver, RTC::RTCP::SdesChunk* chunk)
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// #define MS_LOG_DEV // #define MS_LOG_DEV
#include "RTC/RtpSender.h" #include "RTC/RtpSender.h"
#include "RTC/RTCP/SenderReport.h"
#include "RTC/RTCP/FeedbackRtpNack.h" #include "RTC/RTCP/FeedbackRtpNack.h"
#include "MediaSoupError.h" #include "MediaSoupError.h"
#include "Logger.h" #include "Logger.h"
...@@ -272,12 +273,17 @@ namespace RTC ...@@ -272,12 +273,17 @@ namespace RTC
void RtpSender::GetRtcp(RTC::RTCP::CompoundPacket *packet, uint64_t now) void RtpSender::GetRtcp(RTC::RTCP::CompoundPacket *packet, uint64_t now)
{ {
// TODO: Until we generate Sender Report. if (this->rtpStream)
if (this->senderReport)
{ {
if (static_cast<float>((now - this->lastRtcpSentTime) * 1.15) >= this->maxRtcpInterval) if (static_cast<float>((now - this->lastRtcpSentTime) * 1.15) >= this->maxRtcpInterval)
{ {
packet->AddSenderReport(this->senderReport.release()); RTC::RTCP::SenderReport* report = this->rtpStream->GetRtcpSenderReport(now);
if (report)
{
// TODO: This assumes a single stream for now.
report->SetSsrc(this->rtpParameters->encodings[0].ssrc);
packet->AddSenderReport(report);
if (this->sdesChunk) if (this->sdesChunk)
packet->AddSdesChunk(this->sdesChunk.release()); packet->AddSdesChunk(this->sdesChunk.release());
...@@ -285,6 +291,7 @@ namespace RTC ...@@ -285,6 +291,7 @@ namespace RTC
this->lastRtcpSentTime = now; this->lastRtcpSentTime = now;
} }
} }
}
}; };
void RtpSender::ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket) void RtpSender::ReceiveNack(RTC::RTCP::FeedbackRtpNackPacket* nackPacket)
......
...@@ -3,6 +3,8 @@ ...@@ -3,6 +3,8 @@
#include "RTC/RtpStreamSend.h" #include "RTC/RtpStreamSend.h"
#include "Logger.h" #include "Logger.h"
#include "DepLibUV.h"
#include "Utils.h" // CurrentTimeNtp()
#define RTP_SEQ_MOD (1<<16) #define RTP_SEQ_MOD (1<<16)
#define MAX_RETRANSMISSION_AGE 200 // Don't retransmit packets older than this (ms). #define MAX_RETRANSMISSION_AGE 200 // Don't retransmit packets older than this (ms).
...@@ -59,6 +61,13 @@ namespace RTC ...@@ -59,6 +61,13 @@ namespace RTC
if (this->storage.size() > 0) if (this->storage.size() > 0)
StorePacket(packet); StorePacket(packet);
// Increase packet counters.
this->receivedBytes += packet->GetPayloadLength();
// Record current time and RTP timestamp.
this->lastPacketTimeMs = DepLibUV::GetTime();
this->lastPacketRtpTimestamp = packet->GetTimestamp();
return true; return true;
} }
...@@ -314,4 +323,31 @@ namespace RTC ...@@ -314,4 +323,31 @@ namespace RTC
MS_DEBUG_TAG(rtp, "</RtpStreamSend>"); MS_DEBUG_TAG(rtp, "</RtpStreamSend>");
} }
RTC::RTCP::SenderReport* RtpStreamSend::GetRtcpSenderReport(uint64_t now)
{
MS_TRACE();
if (!received)
return nullptr;
RTC::RTCP::SenderReport* report = new RTC::RTCP::SenderReport();
report->SetPacketCount(this->received);
report->SetOctetCount(this->receivedBytes);
Utils::Time::Ntp ntp;
Utils::Time::CurrentTimeNtp(ntp);
report->SetNtpSec(ntp.seconds);
report->SetNtpFrac(ntp.fractions);
// Calculate RTP timestamp diff between now and last received RTP packet.
uint32_t diffMs = now - this->lastPacketTimeMs;
uint32_t diffRtpTimestamp = diffMs * this->clockRate / 1000;
report->SetRtpTs(this->lastPacketRtpTimestamp + diffRtpTimestamp);
return report;
}
} }
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论