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

NackGenerator: fix AddPacketsToNackList() method

上级 4b06142a
# TODO in mediasoup v2 (server-side) # TODO in mediasoup v2 (server-side)
* In `RtpStreamSend::StorePacket()` we should remove old packets (as `NackGenerator` does).
* Remove `producer.on('rtprawpacket')` and, instead, create a special `RtpConsumer` or something like that. * Remove `producer.on('rtprawpacket')` and, instead, create a special `RtpConsumer` or something like that.
* Set a proper value for Producer::FullFrameRequestBlockTimeout (currently 1 second). * Set a proper value for Producer::FullFrameRequestBlockTimeout (currently 1 second).
......
...@@ -70,7 +70,8 @@ namespace RTC ...@@ -70,7 +70,8 @@ namespace RTC
uint32_t baseSeq{ 0 }; // Base seq number. uint32_t baseSeq{ 0 }; // Base seq number.
uint32_t badSeq{ 0 }; // Last 'bad' seq number + 1. uint32_t badSeq{ 0 }; // Last 'bad' seq number + 1.
// Others. // Others.
uint32_t maxTimestamp{ 0 }; // Highest timestamp seen. uint32_t maxPacketTs{ 0 }; // Highest timestamp seen.
uint64_t maxPacketMs{ 0 }; // When the packet with highest timestammp was seen.
Timer* healthCheckTimer{ nullptr }; Timer* healthCheckTimer{ nullptr };
bool healthy{ true }; bool healthy{ true };
uint32_t totalLost{ 0 }; uint32_t totalLost{ 0 };
......
...@@ -52,10 +52,7 @@ namespace RTC ...@@ -52,10 +52,7 @@ namespace RTC
Buffer buffer; Buffer buffer;
private: private:
uint64_t lastPacketTimeMs{ 0 }; // Time (MS) when the last packet was received. // Retransmittion related.
uint32_t lastPacketRtpTimestamp{ 0 }; // RTP Timestamp of the last packet.
// RTX related.
bool hasRtx{ false }; bool hasRtx{ false };
uint8_t rtxPayloadType{ 0 }; uint8_t rtxPayloadType{ 0 };
uint32_t rtxSsrc{ 0 }; uint32_t rtxSsrc{ 0 };
......
...@@ -9,10 +9,10 @@ namespace RTC ...@@ -9,10 +9,10 @@ namespace RTC
{ {
/* Static. */ /* Static. */
constexpr uint32_t MaxPacketAge{ 1500 }; constexpr uint32_t MaxPacketAge{ 10000 };
constexpr size_t MaxNackPackets{ 500 }; constexpr size_t MaxNackPackets{ 1000 };
constexpr uint32_t DefaultRtt{ 100 }; constexpr uint32_t DefaultRtt{ 100 };
constexpr uint8_t MaxNackRetries{ 8 }; constexpr uint8_t MaxNackRetries{ 10 };
constexpr uint64_t TimerInterval{ 50 }; constexpr uint64_t TimerInterval{ 50 };
/* Instance methods. */ /* Instance methods. */
...@@ -111,6 +111,8 @@ namespace RTC ...@@ -111,6 +111,8 @@ namespace RTC
{ {
MS_TRACE(); MS_TRACE();
if (seq32End > MaxPacketAge)
{
uint32_t numItemsBefore = this->nackList.size(); uint32_t numItemsBefore = this->nackList.size();
// Remove old packets. // Remove old packets.
...@@ -128,6 +130,7 @@ namespace RTC ...@@ -128,6 +130,7 @@ namespace RTC
numItemsRemoved, numItemsRemoved,
seq32End); seq32End);
} }
}
// If the nack list is too large, clear it and request a key frame. // If the nack list is too large, clear it and request a key frame.
uint32_t numNewNacks = seq32End - seq32Start; uint32_t numNewNacks = seq32End - seq32Start;
......
...@@ -43,7 +43,6 @@ namespace RTC ...@@ -43,7 +43,6 @@ namespace RTC
static const Json::StaticString JsonStringBitRate{ "bitrate" }; static const Json::StaticString JsonStringBitRate{ "bitrate" };
static const Json::StaticString JsonStringJitter{ "jitter" }; static const Json::StaticString JsonStringJitter{ "jitter" };
static const Json::StaticString JsonStringMaxTimestamp{ "maxTimestamp" };
static const Json::StaticString JsonStringParams{ "params" }; static const Json::StaticString JsonStringParams{ "params" };
static const Json::StaticString JsonStringPacketCount{ "packetCount" }; static const Json::StaticString JsonStringPacketCount{ "packetCount" };
static const Json::StaticString JsonStringOctetCount{ "octetCount" }; static const Json::StaticString JsonStringOctetCount{ "octetCount" };
...@@ -55,7 +54,6 @@ namespace RTC ...@@ -55,7 +54,6 @@ namespace RTC
json[JsonStringBitRate] = Json::UInt{ GetBitRate() }; json[JsonStringBitRate] = Json::UInt{ GetBitRate() };
json[JsonStringJitter] = Json::UInt{ this->jitter }; json[JsonStringJitter] = Json::UInt{ this->jitter };
json[JsonStringMaxTimestamp] = Json::UInt{ this->maxTimestamp };
json[JsonStringParams] = this->params.ToJson(); json[JsonStringParams] = this->params.ToJson();
json[JsonStringPacketCount] = static_cast<Json::UInt>(this->counter.GetPacketCount()); json[JsonStringPacketCount] = static_cast<Json::UInt>(this->counter.GetPacketCount());
json[JsonStringOctetCount] = static_cast<Json::UInt>(this->counter.GetBytes()); json[JsonStringOctetCount] = static_cast<Json::UInt>(this->counter.GetBytes());
...@@ -101,8 +99,11 @@ namespace RTC ...@@ -101,8 +99,11 @@ namespace RTC
this->cycles + static_cast<uint32_t>(packet->GetSequenceNumber())); this->cycles + static_cast<uint32_t>(packet->GetSequenceNumber()));
// Update highest seen RTP timestamp. // Update highest seen RTP timestamp.
if (packet->GetTimestamp() > this->maxTimestamp) if (packet->GetTimestamp() > this->maxPacketTs)
this->maxTimestamp = packet->GetTimestamp(); {
this->maxPacketTs = packet->GetTimestamp();
this->maxPacketMs = DepLibUV::GetTime();
}
return true; return true;
} }
...@@ -122,7 +123,7 @@ namespace RTC ...@@ -122,7 +123,7 @@ namespace RTC
this->baseSeq = seq; this->baseSeq = seq;
this->maxSeq = seq; this->maxSeq = seq;
this->badSeq = RtpSeqMod + 1; // So seq == badSeq is false. this->badSeq = RtpSeqMod + 1; // So seq == badSeq is false.
this->maxTimestamp = 0; // Also reset the highest seen RTP timestamp. this->maxPacketTs = 0; // Also reset the highest seen RTP timestamp.
} }
bool RtpStream::UpdateSeq(RTC::RtpPacket* packet) bool RtpStream::UpdateSeq(RTC::RtpPacket* packet)
......
...@@ -12,7 +12,8 @@ namespace RTC ...@@ -12,7 +12,8 @@ namespace RTC
static constexpr uint32_t RtpSeqMod{ 1 << 16 }; static constexpr uint32_t RtpSeqMod{ 1 << 16 };
// Don't retransmit packets older than this (ms). // Don't retransmit packets older than this (ms).
static constexpr uint32_t MaxRetransmissionDelay{ 250 }; // TODO: This must be tunned.
static constexpr uint32_t MaxRetransmissionDelay{ 1000 };
static constexpr uint32_t DefaultRtt{ 100 }; static constexpr uint32_t DefaultRtt{ 100 };
/* Instance methods. */ /* Instance methods. */
...@@ -43,10 +44,6 @@ namespace RTC ...@@ -43,10 +44,6 @@ namespace RTC
if (!this->storage.empty()) if (!this->storage.empty())
StorePacket(packet); StorePacket(packet);
// Record current time and RTP timestamp.
this->lastPacketTimeMs = DepLibUV::GetTime();
this->lastPacketRtpTimestamp = packet->GetTimestamp();
return true; return true;
} }
...@@ -182,13 +179,18 @@ namespace RTC ...@@ -182,13 +179,18 @@ namespace RTC
if (currentSeq32 == seq32) if (currentSeq32 == seq32)
{ {
auto currentPacket = (*bufferIt).packet; auto currentPacket = (*bufferIt).packet;
uint32_t diffMs = now - this->lastPacketTimeMs; // Calculate how the elapsed time between the max timestampt seen and
// the requested packet's timestampt (in ms).
uint32_t diffTs = this->maxPacketTs - currentPacket->GetTimestamp();
uint32_t diffMs = diffTs * 1000 / this->params.clockRate;
// Just provide the packet if no older than MaxRetransmissionDelay ms. // Just provide the packet if no older than MaxRetransmissionDelay ms.
if (diffMs > MaxRetransmissionDelay) if (diffMs > MaxRetransmissionDelay)
{ {
if (!tooOldPacketFound) if (!tooOldPacketFound)
{ {
// TODO: May we ask for a key frame in this case?
MS_WARN_TAG( MS_WARN_TAG(
rtx, rtx,
"ignoring retransmission for too old packet " "ignoring retransmission for too old packet "
...@@ -230,6 +232,7 @@ namespace RTC ...@@ -230,6 +232,7 @@ namespace RTC
break; break;
} }
// It can not be after this packet. // It can not be after this packet.
if (currentSeq32 > seq32) if (currentSeq32 > seq32)
break; break;
...@@ -296,10 +299,10 @@ namespace RTC ...@@ -296,10 +299,10 @@ namespace RTC
report->SetNtpFrac(ntp.fractions); report->SetNtpFrac(ntp.fractions);
// Calculate RTP timestamp diff between now and last received RTP packet. // Calculate RTP timestamp diff between now and last received RTP packet.
uint32_t diffMs = now - this->lastPacketTimeMs; auto diffMs = static_cast<uint32_t>(now - this->maxPacketMs);
uint32_t diffRtpTimestamp = diffMs * this->params.clockRate / 1000; uint32_t diffTs = diffMs * this->params.clockRate / 1000;
report->SetRtpTs(this->lastPacketRtpTimestamp + diffRtpTimestamp); report->SetRtpTs(this->maxPacketTs + diffTs);
return report; return report;
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论