提交 02b24000 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Do some RTCP handling (Receiver Report)

上级 df77ff1d
...@@ -61,7 +61,6 @@ namespace RTC ...@@ -61,7 +61,6 @@ namespace RTC
/* Pure virtual methods inherited from RTC::Transport::Listener. */ /* Pure virtual methods inherited from RTC::Transport::Listener. */
public: public:
void OnTransportClosed(RTC::Transport* transport) override; void OnTransportClosed(RTC::Transport* transport) override;
// TODO: RTCP listener to route RTCP feedback from Consumer to its Producer.
/* Pure virtual methods inherited from RTC::ProducerListener. */ /* Pure virtual methods inherited from RTC::ProducerListener. */
public: public:
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "RTC/ProducerListener.hpp" #include "RTC/ProducerListener.hpp"
#include "RTC/RTCP/CompoundPacket.hpp" #include "RTC/RTCP/CompoundPacket.hpp"
#include "RTC/RTCP/Packet.hpp" #include "RTC/RTCP/Packet.hpp"
#include "RTC/RTCP/ReceiverReport.hpp"
#include "RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorAbsSendTime.hpp" #include "RTC/RemoteBitrateEstimator/RemoteBitrateEstimatorAbsSendTime.hpp"
#include "RTC/RtpListener.hpp" #include "RTC/RtpListener.hpp"
#include "RTC/RtpPacket.hpp" #include "RTC/RtpPacket.hpp"
...@@ -69,6 +70,8 @@ namespace RTC ...@@ -69,6 +70,8 @@ namespace RTC
private: private:
void MayRunDtlsTransport(); void MayRunDtlsTransport();
void HandleRtcpPacket(RTC::RTCP::Packet* packet);
RTC::Consumer* GetConsumer(uint32_t ssrc) const;
/* Private methods to unify UDP and TCP behavior. */ /* Private methods to unify UDP and TCP behavior. */
private: private:
......
...@@ -404,11 +404,11 @@ namespace RTC ...@@ -404,11 +404,11 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
// TODO: This happens often for first RTX packets. May be the browser sends empty // Chrome sends some RTX packets with no payload when the stream is started.
// RTX packets (for any reason). If so, we should move this to MS_DEBUG_TAG. // Just ignore them.
if (this->payloadLength < 2) if (this->payloadLength < 2)
{ {
MS_WARN_TAG(rtx, "not enough space for a RTX header field"); MS_DEBUG_TAG(rtx, "ignoring RTX packet with empty payload");
return false; return false;
} }
......
...@@ -63,14 +63,14 @@ namespace RTC ...@@ -63,14 +63,14 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
MS_ASSERT(packet->GetSsrc() == this->rtxSsrc, "invalid ssrc on rtx packet"); MS_ASSERT(packet->GetSsrc() == this->rtxSsrc, "invalid ssrc on RTX packet");
// Check that the payload type corresponds to the one negotiated. // Check that the payload type corresponds to the one negotiated.
if (packet->GetPayloadType() != this->rtxPayloadType) if (packet->GetPayloadType() != this->rtxPayloadType)
{ {
MS_WARN_TAG( MS_WARN_TAG(
rtx, rtx,
"ignoring rtx packet with invalid payload type [ssrc: %" PRIu32 " seqnr: %" PRIu16 "ignoring RTX packet with invalid payload type [ssrc: %" PRIu32 " seqnr: %" PRIu16
" payload type: %" PRIu8 "]", " payload type: %" PRIu8 "]",
packet->GetSsrc(), packet->GetSsrc(),
packet->GetSequenceNumber(), packet->GetSequenceNumber(),
...@@ -79,15 +79,19 @@ namespace RTC ...@@ -79,15 +79,19 @@ namespace RTC
return false; return false;
} }
// Get the rtx packet sequence number for logging purposes. // Get the RTX packet sequence number for logging purposes.
auto rtxSeq = packet->GetSequenceNumber(); auto rtxSeq = packet->GetSequenceNumber();
// Get the original rtp packet. // Get the original RTP packet.
if (!packet->RtxDecode(this->params.payloadType, this->params.ssrc)) if (!packet->RtxDecode(this->params.payloadType, this->params.ssrc))
{ {
// Ignore RTX packets with no payload.
if (packet->GetPayloadLength() < 2)
return false;
MS_WARN_TAG( MS_WARN_TAG(
rtx, rtx,
"ignoring malformed rtx packet [ssrc: %" PRIu32 " seqnr: %" PRIu16 "ignoring malformed RTX packet [ssrc: %" PRIu32 " seqnr: %" PRIu16
" payload type: %" PRIu8 "]", " payload type: %" PRIu8 "]",
packet->GetSsrc(), packet->GetSsrc(),
packet->GetSequenceNumber(), packet->GetSequenceNumber(),
...@@ -98,7 +102,7 @@ namespace RTC ...@@ -98,7 +102,7 @@ namespace RTC
MS_DEBUG_TAG( MS_DEBUG_TAG(
rtx, rtx,
"received rtx packet [ssrc: %" PRIu32 " seqnr: %" PRIu16 "received RTX packet [ssrc: %" PRIu32 " seqnr: %" PRIu16
"] recovering original [ssrc: %" PRIu32 " seqnr: %" PRIu16 "]", "] recovering original [ssrc: %" PRIu32 " seqnr: %" PRIu16 "]",
this->rtxSsrc, this->rtxSsrc,
rtxSeq, rtxSeq,
......
...@@ -749,6 +749,75 @@ namespace RTC ...@@ -749,6 +749,75 @@ namespace RTC
} }
} }
inline void Transport::HandleRtcpPacket(RTC::RTCP::Packet* packet)
{
MS_TRACE();
switch (packet->GetType())
{
case RTCP::Type::RR:
{
auto* rr = dynamic_cast<RTCP::ReceiverReportPacket*>(packet);
auto it = rr->Begin();
for (; it != rr->End(); ++it)
{
auto& report = (*it);
auto* consumer = GetConsumer(report->GetSsrc());
if (consumer)
{
consumer->ReceiveRtcpReceiverReport(report);
}
else
{
MS_WARN_TAG(
rtcp,
"no Consumer found for received Receiver Report [ssrc:%" PRIu32 "]",
report->GetSsrc());
}
}
break;
}
default:
{
MS_WARN_TAG(
rtcp,
"unhandled RTCP type received [type:%" PRIu8 "]",
static_cast<uint8_t>(packet->GetType()));
}
}
}
inline RTC::Consumer* Transport::GetConsumer(uint32_t ssrc) const
{
MS_TRACE();
for (auto consumer : this->consumers)
{
// Ignore if not enabled.
if (!consumer->IsEnabled())
continue;
// NOTE: Use & since, otherwise, a full copy will be retrieved.
auto& rtpParameters = consumer->GetParameters();
for (auto& encoding : rtpParameters.encodings)
{
if (encoding.ssrc == ssrc)
return consumer;
if (encoding.hasFec && encoding.fec.ssrc == ssrc)
return consumer;
if (encoding.hasRtx && encoding.rtx.ssrc == ssrc)
return consumer;
}
}
return nullptr;
}
inline void Transport::OnPacketRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len) inline void Transport::OnPacketRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len)
{ {
MS_TRACE(); MS_TRACE();
...@@ -972,21 +1041,15 @@ namespace RTC ...@@ -972,21 +1041,15 @@ namespace RTC
return; return;
} }
// TODO: No. Instead, process here the packet, get corresponding producers/consumers // Handle each RTCP packet.
// and do stuff here. We may need another listener callback to forward certain
// RTCP messages between consumers and is producers. Let's see.
// this->listener->OnTransportRtcpPacket(this, packet);
// Trick for clients performing aggressive ICE regardless we are ICE-Lite.
// this->iceServer->ForceSelectedTuple(tuple);
// Delete the whole packet.
while (packet != nullptr) while (packet != nullptr)
{ {
RTC::RTCP::Packet* nextPacket = packet->GetNext(); HandleRtcpPacket(packet);
delete packet; RTC::RTCP::Packet* previousPacket = packet;
packet = nextPacket;
packet = packet->GetNext();
delete previousPacket;
} }
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论