提交 a804ea36 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

Improve NACK/PLI

* Improve some RTP logs.
* Trigger PLI if RTP goes out of sync.
上级 d906109a
......@@ -34,7 +34,7 @@ namespace RTC
private:
void InitSeq(uint16_t seq);
bool UpdateSeq(uint16_t seq);
bool UpdateSeq(RTC::RtpPacket* packet);
/* Pure virtual methods that must be implemented by the subclass. */
protected:
......
......@@ -35,19 +35,20 @@ namespace RTC
// If this is the first packet seen, initialize stuff.
if (!this->started)
{
this->started = true;
InitSeq(seq);
this->started = true;
this->max_seq = seq - 1;
this->probation = MIN_SEQUENTIAL;
}
// If not a valid packet ignore it.
if (!UpdateSeq(seq))
if (!UpdateSeq(packet))
{
if (!this->probation)
{
MS_WARN_TAG(rtp, "invalid packet [ssrc:%" PRIu32 ", seq:%" PRIu16 "]", packet->GetSsrc(), packet->GetSequenceNumber());
MS_WARN_TAG(rtp,
"invalid packet [ssrc:%" PRIu32 ", seq:%" PRIu16 "]",
packet->GetSsrc(), packet->GetSequenceNumber());
}
return false;
......@@ -83,10 +84,11 @@ namespace RTC
onInitSeq();
}
bool RtpStream::UpdateSeq(uint16_t seq)
bool RtpStream::UpdateSeq(RTC::RtpPacket* packet)
{
MS_TRACE();
uint16_t seq = packet->GetSequenceNumber();
uint16_t udelta = seq - this->max_seq;
/*
......@@ -138,20 +140,23 @@ namespace RTC
* restarted without telling us so just re-sync
* (i.e., pretend this was the first packet).
*/
MS_WARN_TAG(rtp,
"too bad sequence number, re-syncing RTP [ssrc:%" PRIu32 ", seq:%" PRIu16 "]",
packet->GetSsrc(), packet->GetSequenceNumber());
InitSeq(seq);
}
else
{
MS_WARN_TAG(rtp,
"bad sequence number, ignoring packet [ssrc:%" PRIu32 ", seq:%" PRIu16 "]",
packet->GetSsrc(), packet->GetSequenceNumber());
this->bad_seq = (seq + 1) & (RTP_SEQ_MOD - 1);
return false;
}
}
else
{
// Duplicate or reordered packet.
// NOTE: This would never happen because libsrtp rejects duplicated packets.
}
this->received++;
......
......@@ -148,6 +148,15 @@ namespace RTC
// Reset NackGenerator.
if (this->params.useNack)
this->nackGenerator.reset(new RTC::NackGenerator(this));
// If we got out of sync, request a full frame.
if (this->started && this->params.usePli)
{
MS_DEBUG_TAG(rtx, "triggering PLI [ssrc:%" PRIu32 "]",
this->params.ssrc);
this->listener->onPliRequired(this);
}
}
void RtpStreamRecv::onNackRequired(const std::vector<uint16_t>& seq_numbers)
......@@ -156,8 +165,8 @@ namespace RTC
MS_ASSERT(this->params.useNack, "NACK required but not supported");
MS_DEBUG_TAG(rtx,
"RTP retransmission required [ssrc:%" PRIu32 ", first_seq:%" PRIu16 ", num_packets:%zu]",
MS_WARN_TAG(rtx,
"triggering NACK [ssrc:%" PRIu32 ", first_seq:%" PRIu16 ", num_packets:%zu]",
this->params.ssrc, seq_numbers[0], seq_numbers.size());
this->listener->onNackRequired(this, seq_numbers);
......@@ -170,10 +179,12 @@ namespace RTC
if (!this->params.usePli)
{
MS_WARN_TAG(rtx, "PLI required but not supported by the endpoint");
return;
}
MS_DEBUG_TAG(rtx, "PLI triggered [ssrc:%" PRIu32 "]", this->params.ssrc);
MS_DEBUG_TAG(rtx,
"triggering PLI [ssrc:%" PRIu32 "]", this->params.ssrc);
this->listener->onPliRequired(this);
}
......
......@@ -173,8 +173,6 @@ namespace RTC
uint8_t bitmask_counter = 0;
bool too_old_packet_found = false;
MS_DEBUG_DEV("loop [bitmask:" MS_UINT16_TO_BINARY_PATTERN "]", MS_UINT16_TO_BINARY(bitmask));
while (requested || bitmask != 0)
{
bool sent = false;
......@@ -196,7 +194,7 @@ namespace RTC
{
if (!too_old_packet_found)
{
MS_DEBUG_TAG(rtx,
MS_WARN_TAG(rtx,
"ignoring retransmission for too old packet [seq:%" PRIu16 ", max_age:%" PRIu32 "ms, packet_age:%" PRIu32 "ms]",
current_packet->GetSequenceNumber(), MAX_RETRANSMISSION_AGE, diff);
......@@ -213,7 +211,7 @@ namespace RTC
resent_at_time &&
now - resent_at_time < static_cast<uint64_t>(rtt))
{
MS_DEBUG_TAG(rtx,
MS_WARN_TAG(rtx,
"ignoring retransmission for a packet already resent in the last RTT ms [seq:%" PRIu16 ", rtt:%" PRIu32 "]",
current_packet->GetSequenceNumber(), rtt);
......
......@@ -15,8 +15,6 @@ static void destroy();
int main(int argc, char* argv[])
{
Settings::configuration.logLevel = LogLevel::LOG_DEBUG;
Settings::configuration.logTags.rtp = true;
Settings::configuration.logTags.rtcp = true;
std::string loggerId = "tests";
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论