提交 83c09a9d authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Generate PLI if more than 16 packets were lost

上级 594ffad3
...@@ -63,6 +63,7 @@ namespace RTC ...@@ -63,6 +63,7 @@ namespace RTC
/* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */ /* Pure virtual methods inherited from RTC::RtpStreamRecv::Listener. */
public: public:
virtual void onNackRequired(RTC::RtpStreamRecv* rtpStream, uint16_t seq, uint16_t bitmask) override; virtual void onNackRequired(RTC::RtpStreamRecv* rtpStream, uint16_t seq, uint16_t bitmask) override;
virtual void onPliRequired(RTC::RtpStreamRecv* rtpStream) override;
public: public:
// Passed by argument. // Passed by argument.
......
...@@ -22,6 +22,7 @@ namespace RTC ...@@ -22,6 +22,7 @@ namespace RTC
RTC::RtpCodecMime mime; RTC::RtpCodecMime mime;
uint32_t clockRate = 0; uint32_t clockRate = 0;
bool useNack = false; bool useNack = false;
bool usePli = false;
uint8_t absSendTimeId = 0; // 0 means no abs-send-time id. uint8_t absSendTimeId = 0; // 0 means no abs-send-time id.
}; };
......
...@@ -15,6 +15,7 @@ namespace RTC ...@@ -15,6 +15,7 @@ namespace RTC
{ {
public: public:
virtual void onNackRequired(RTC::RtpStreamRecv* rtpStream, uint16_t seq, uint16_t bitmask) = 0; virtual void onNackRequired(RTC::RtpStreamRecv* rtpStream, uint16_t seq, uint16_t bitmask) = 0;
virtual void onPliRequired(RTC::RtpStreamRecv* rtpStream) = 0;
}; };
public: public:
......
...@@ -316,40 +316,41 @@ namespace RTC ...@@ -316,40 +316,41 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (this->transport) if (!this->transport)
{ return;
// Ensure that the RTCP packet fits into the RTCP buffer.
if (packet->GetSize() > MS_RTCP_BUFFER_SIZE)
{
MS_WARN_TAG(rtcp, "cannot send RTCP packet, size too big (%zu bytes)",
packet->GetSize());
return;
}
packet->Serialize(RtpReceiver::rtcpBuffer); // Ensure that the RTCP packet fits into the RTCP buffer.
this->transport->SendRtcpPacket(packet); if (packet->GetSize() > MS_RTCP_BUFFER_SIZE)
{
MS_WARN_TAG(rtcp, "cannot send RTCP packet, size too big (%zu bytes)",
packet->GetSize());
return;
} }
packet->Serialize(RtpReceiver::rtcpBuffer);
this->transport->SendRtcpPacket(packet);
} }
void RtpReceiver::ReceiveRtcpFeedback(RTC::RTCP::FeedbackRtpPacket* packet) void RtpReceiver::ReceiveRtcpFeedback(RTC::RTCP::FeedbackRtpPacket* packet)
{ {
MS_TRACE(); MS_TRACE();
if (this->transport) if (!this->transport)
{ return;
// Ensure that the RTCP packet fits into the RTCP buffer.
if (packet->GetSize() > MS_RTCP_BUFFER_SIZE)
{
MS_WARN_TAG(rtcp, "cannot send RTCP packet, size too big (%zu bytes)",
packet->GetSize());
return; // Ensure that the RTCP packet fits into the RTCP buffer.
} if (packet->GetSize() > MS_RTCP_BUFFER_SIZE)
{
MS_WARN_TAG(rtcp, "cannot send RTCP packet, size too big (%zu bytes)",
packet->GetSize());
packet->Serialize(RtpReceiver::rtcpBuffer); return;
this->transport->SendRtcpPacket(packet);
} }
packet->Serialize(RtpReceiver::rtcpBuffer);
this->transport->SendRtcpPacket(packet);
} }
void RtpReceiver::CreateRtpStream(RTC::RtpEncodingParameters& encoding) void RtpReceiver::CreateRtpStream(RTC::RtpEncodingParameters& encoding)
...@@ -372,6 +373,7 @@ namespace RTC ...@@ -372,6 +373,7 @@ namespace RTC
// Get the codec of the stream/encoding. // Get the codec of the stream/encoding.
auto& codec = this->rtpParameters->GetCodecForEncoding(encoding); auto& codec = this->rtpParameters->GetCodecForEncoding(encoding);
bool useNack = false; bool useNack = false;
bool usePli = false;
bool useRemb = false; bool useRemb = false;
uint8_t absSendTimeId = 0; uint8_t absSendTimeId = 0;
...@@ -382,6 +384,11 @@ namespace RTC ...@@ -382,6 +384,11 @@ namespace RTC
MS_DEBUG_TAG(rtcp, "enabling NACK generation"); MS_DEBUG_TAG(rtcp, "enabling NACK generation");
useNack = true; useNack = true;
} }
if (!usePli && fb.type == "nack" && fb.parameter == "pli")
{
MS_DEBUG_TAG(rtcp, "enabling PLI generation");
usePli = true;
}
else if (!useRemb && fb.type == "goog-remb") else if (!useRemb && fb.type == "goog-remb")
{ {
MS_DEBUG_TAG(rbe, "enabling REMB"); MS_DEBUG_TAG(rbe, "enabling REMB");
...@@ -405,6 +412,7 @@ namespace RTC ...@@ -405,6 +412,7 @@ namespace RTC
params.mime = codec.mime; params.mime = codec.mime;
params.clockRate = codec.clockRate; params.clockRate = codec.clockRate;
params.useNack = useNack; params.useNack = useNack;
params.usePli = usePli;
params.absSendTimeId = absSendTimeId; params.absSendTimeId = absSendTimeId;
// Create a RtpStreamRecv for receiving a media stream. // Create a RtpStreamRecv for receiving a media stream.
...@@ -441,4 +449,12 @@ namespace RTC ...@@ -441,4 +449,12 @@ namespace RTC
packet.Serialize(RtpReceiver::rtcpBuffer); packet.Serialize(RtpReceiver::rtcpBuffer);
this->transport->SendRtcpPacket(&packet); this->transport->SendRtcpPacket(&packet);
} }
void RtpReceiver::onPliRequired(RTC::RtpStreamRecv* rtpStream)
{
if (!this->transport)
return;
// TODO
}
} }
...@@ -407,15 +407,21 @@ namespace RTC ...@@ -407,15 +407,21 @@ namespace RTC
// Get the codec of the stream/encoding. // Get the codec of the stream/encoding.
auto& codec = this->rtpParameters->GetCodecForEncoding(encoding); auto& codec = this->rtpParameters->GetCodecForEncoding(encoding);
bool useNack = false; bool useNack = false;
bool usePli = false;
uint8_t absSendTimeId = 0; // 0 means no abs-send-time id. uint8_t absSendTimeId = 0; // 0 means no abs-send-time id.
for (auto& fb : codec.rtcpFeedback) for (auto& fb : codec.rtcpFeedback)
{ {
if (!useNack && fb.type == "nack") if (!useNack && fb.type == "nack")
{ {
MS_DEBUG_TAG(rtcp, "enabling NACK processing"); MS_DEBUG_TAG(rtcp, "enabling NACK reception");
useNack = true; useNack = true;
} }
if (!usePli && fb.type == "nack" && fb.parameter == "pli")
{
MS_DEBUG_TAG(rtcp, "enabling PLI reception");
usePli = true;
}
} }
for (auto& exten : this->rtpParameters->headerExtensions) for (auto& exten : this->rtpParameters->headerExtensions)
...@@ -434,6 +440,7 @@ namespace RTC ...@@ -434,6 +440,7 @@ namespace RTC
params.mime = codec.mime; params.mime = codec.mime;
params.clockRate = codec.clockRate; params.clockRate = codec.clockRate;
params.useNack = useNack; params.useNack = useNack;
params.usePli = usePli;
params.absSendTimeId = absSendTimeId; params.absSendTimeId = absSendTimeId;
// Create a RtpStreamSend for sending a single media stream. // Create a RtpStreamSend for sending a single media stream.
......
...@@ -163,6 +163,7 @@ namespace RTC ...@@ -163,6 +163,7 @@ namespace RTC
static const Json::StaticString k_mime("mime"); static const Json::StaticString k_mime("mime");
static const Json::StaticString k_clockRate("clockRate"); static const Json::StaticString k_clockRate("clockRate");
static const Json::StaticString k_useNack("useNack"); static const Json::StaticString k_useNack("useNack");
static const Json::StaticString k_usePli("usePli");
static const Json::StaticString k_absSendTimeId("absSendTimeId"); static const Json::StaticString k_absSendTimeId("absSendTimeId");
Json::Value json(Json::objectValue); Json::Value json(Json::objectValue);
...@@ -172,6 +173,7 @@ namespace RTC ...@@ -172,6 +173,7 @@ namespace RTC
json[k_mime] = this->mime.name; json[k_mime] = this->mime.name;
json[k_clockRate] = (Json::UInt)this->clockRate; json[k_clockRate] = (Json::UInt)this->clockRate;
json[k_useNack] = this->useNack; json[k_useNack] = this->useNack;
json[k_usePli] = this->usePli;
json[k_absSendTimeId] = (Json::UInt)this->absSendTimeId; json[k_absSendTimeId] = (Json::UInt)this->absSendTimeId;
return json; return json;
......
...@@ -166,6 +166,20 @@ namespace RTC ...@@ -166,6 +166,20 @@ namespace RTC
if (diff_seq32 == 1) if (diff_seq32 == 1)
return; return;
// If 16 or more packets was lost, ask for a PLI (if supported).
if (diff_seq32 >= 16 && this->params.usePli)
{
MS_DEBUG_TAG(rtcp, "PLI triggered [ssrc:%" PRIu32 ", diff_seq32:%" PRIu32 "]",
this->params.ssrc, diff_seq32);
this->listener->onPliRequired(this);
// TODO: Now we should stop sending NACK for a while (ideally after a full keyframe
// is received...).
return;
}
// Some packet(s) is/are missing, trigger a NACK. // Some packet(s) is/are missing, trigger a NACK.
uint8_t nack_bitmask_count = std::min(diff_seq32 - 2, 16); uint8_t nack_bitmask_count = std::min(diff_seq32 - 2, 16);
uint32_t nack_seq32 = this->last_seq32 - nack_bitmask_count - 1; uint32_t nack_seq32 = this->last_seq32 - nack_bitmask_count - 1;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "Utils.hpp" #include "Utils.hpp"
#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 400 // Don't retransmit packets older than this (ms).
namespace RTC namespace RTC
{ {
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论