提交 0bc5513d authored 作者: José Luis Millán's avatar José Luis Millán

Rtt calculation. Closes #73

上级 f4dcdc1f
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
#include "RTC/RtpDataCounter.hpp" #include "RTC/RtpDataCounter.hpp"
#include "RTC/RTCP/Sdes.hpp" #include "RTC/RTCP/Sdes.hpp"
#include "RTC/RTCP/ReceiverReport.hpp"
#include "RTC/RTCP/FeedbackRtpNack.hpp" #include "RTC/RTCP/FeedbackRtpNack.hpp"
#include "RTC/RTCP/CompoundPacket.hpp" #include "RTC/RTCP/CompoundPacket.hpp"
#include "Channel/Request.hpp" #include "Channel/Request.hpp"
...@@ -61,6 +62,7 @@ namespace RTC ...@@ -61,6 +62,7 @@ namespace RTC
void SendRtpPacket(RTC::RtpPacket* packet); void SendRtpPacket(RTC::RtpPacket* packet);
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);
void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report);
uint32_t GetTransmissionRate(uint64_t now); uint32_t GetTransmissionRate(uint64_t now);
private: private:
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include "RTC/RtpStream.hpp" #include "RTC/RtpStream.hpp"
#include "RTC/RTCP/SenderReport.hpp" #include "RTC/RTCP/SenderReport.hpp"
#include "RTC/RTCP/ReceiverReport.hpp"
#include <vector> #include <vector>
#include <list> #include <list>
...@@ -30,8 +31,10 @@ namespace RTC ...@@ -30,8 +31,10 @@ namespace RTC
virtual Json::Value toJson() const override; virtual Json::Value toJson() const override;
bool ReceivePacket(RTC::RtpPacket* packet) override; bool ReceivePacket(RTC::RtpPacket* packet) override;
void ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report);
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); RTC::RTCP::SenderReport* GetRtcpSenderReport(uint64_t now);
uint32_t GetRtt() const;
private: private:
void ClearBuffer(); void ClearBuffer();
...@@ -50,7 +53,14 @@ namespace RTC ...@@ -50,7 +53,14 @@ namespace RTC
size_t receivedBytes = 0; // Bytes received. size_t receivedBytes = 0; // Bytes received.
uint64_t lastPacketTimeMs = 0; // Time (MS) when the last packet was received. uint64_t lastPacketTimeMs = 0; // Time (MS) when the last packet was received.
uint32_t lastPacketRtpTimestamp = 0; // RTP Timestamp of the last packet. uint32_t lastPacketRtpTimestamp = 0; // RTP Timestamp of the last packet.
uint32_t rtt; // Round trip time.
}; };
inline
uint32_t RtpStreamSend::GetRtt() const
{
return this->rtt;
}
} }
#endif #endif
...@@ -624,8 +624,7 @@ namespace RTC ...@@ -624,8 +624,7 @@ namespace RTC
MS_ASSERT(this->mapRtpSenderRtpReceiver.find(rtpSender) != this->mapRtpSenderRtpReceiver.end(), "RtpSender not present in the map"); MS_ASSERT(this->mapRtpSenderRtpReceiver.find(rtpSender) != this->mapRtpSenderRtpReceiver.end(), "RtpSender not present in the map");
// TODO: Calculate real downstream stats for the given RtpSender, rtpSender->ReceiveRtcpReceiverReport(report);
// considering the ReceiverReport generated locally and this one.
} }
void Room::onPeerRtcpFeedback(RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackPsPacket* packet) void Room::onPeerRtcpFeedback(RTC::Peer* peer, RTC::RtpSender* rtpSender, RTC::RTCP::FeedbackPsPacket* packet)
......
...@@ -385,6 +385,20 @@ namespace RTC ...@@ -385,6 +385,20 @@ namespace RTC
} }
} }
void RtpSender::ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report)
{
MS_TRACE();
if (!this->rtpStream)
{
MS_WARN_TAG(rtp, "no RtpStreamSend");
return;
}
this->rtpStream->ReceiveRtcpReceiverReport(report);
}
void RtpSender::CreateRtpStream(RTC::RtpEncodingParameters& encoding) void RtpSender::CreateRtpStream(RTC::RtpEncodingParameters& encoding)
{ {
MS_TRACE(); MS_TRACE();
......
...@@ -36,6 +36,7 @@ namespace RTC ...@@ -36,6 +36,7 @@ namespace RTC
static const Json::StaticString k_received("received"); static const Json::StaticString k_received("received");
static const Json::StaticString k_maxTimestamp("maxTimestamp"); static const Json::StaticString k_maxTimestamp("maxTimestamp");
static const Json::StaticString k_receivedBytes("receivedBytes"); static const Json::StaticString k_receivedBytes("receivedBytes");
static const Json::StaticString k_rtt("rtt");
Json::Value json(Json::objectValue); Json::Value json(Json::objectValue);
...@@ -43,6 +44,7 @@ namespace RTC ...@@ -43,6 +44,7 @@ namespace RTC
json[k_received] = (Json::UInt)this->received; json[k_received] = (Json::UInt)this->received;
json[k_maxTimestamp] = (Json::UInt)this->max_timestamp; json[k_maxTimestamp] = (Json::UInt)this->max_timestamp;
json[k_receivedBytes] = (Json::UInt)this->receivedBytes; json[k_receivedBytes] = (Json::UInt)this->receivedBytes;
json[k_rtt] = (Json::UInt)this->rtt;
return json; return json;
} }
...@@ -69,6 +71,38 @@ namespace RTC ...@@ -69,6 +71,38 @@ namespace RTC
return true; return true;
} }
void RtpStreamSend::ReceiveRtcpReceiverReport(RTC::RTCP::ReceiverReport* report)
{
MS_TRACE();
/* Calculate RTT. */
// If no SR has been received yet, Last Sender Timestamp is set to zero.
if (report->GetLastSenderReport() == 0)
{
// TODO: Remove.
MS_DEBUG_TAG(rtp, "report->GetLastSenderReport() == 0");
report->Dump();
return;
}
// Get the compact NTP representation of the current timestamp.
Utils::Time::Ntp nowNtp;
Utils::Time::CurrentTimeNtp(nowNtp);
uint32_t nowCompactNtp = (nowNtp.seconds & 0x0000FFFF) << 16;
nowCompactNtp |= (nowNtp.fractions & 0xFFFF0000) >> 16;
uint32_t lastSr = report->GetLastSenderReport();
uint32_t dlsr = report->GetDelaySinceLastSenderReport();
// RTT in 1/2^16 seconds.
uint32_t rtt = nowCompactNtp - dlsr - lastSr;
// RTT in milliseconds.
this->rtt = ((rtt >> 16) * 1000);
this->rtt += (static_cast<float>(rtt & 0x0000FFFF) / 65536) * 1000;
}
// This method looks for the requested RTP packets and inserts them into the // This method looks for the requested RTP packets and inserts them into the
// given container (and set to null the next container position). // given container (and set to null the next container position).
void RtpStreamSend::RequestRtpRetransmission(uint16_t seq, uint16_t bitmask, std::vector<RTC::RtpPacket*>& container) void RtpStreamSend::RequestRtpRetransmission(uint16_t seq, uint16_t bitmask, std::vector<RTC::RtpPacket*>& container)
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论