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

NackGenerator: fix AddPacketsToNackList() method

上级 4b06142a
# 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.
* Set a proper value for Producer::FullFrameRequestBlockTimeout (currently 1 second).
......
......@@ -65,12 +65,13 @@ namespace RTC
// Whether at least a RTP packet has been received.
// https://tools.ietf.org/html/rfc3550#appendix-A.1 stuff.
bool started{ false };
uint16_t maxSeq{ 0 }; // Highest seq. number seen.
uint32_t cycles{ 0 }; // Shifted count of seq. number cycles.
uint32_t baseSeq{ 0 }; // Base seq number.
uint32_t badSeq{ 0 }; // Last 'bad' seq number + 1.
uint16_t maxSeq{ 0 }; // Highest seq. number seen.
uint32_t cycles{ 0 }; // Shifted count of seq. number cycles.
uint32_t baseSeq{ 0 }; // Base seq number.
uint32_t badSeq{ 0 }; // Last 'bad' seq number + 1.
// 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 };
bool healthy{ true };
uint32_t totalLost{ 0 };
......
......@@ -46,8 +46,8 @@ namespace RTC
// Passed by argument.
Listener* listener{ nullptr };
// Others.
uint32_t expectedPrior{ 0 }; // Packet expected at last interval.
uint32_t receivedPrior{ 0 }; // Packet received at last interval.
uint32_t expectedPrior{ 0 }; // Packet expected at last interval.
uint32_t receivedPrior{ 0 }; // Packet received at last interval.
uint32_t lastSrTimestamp{ 0 }; // The middle 32 bits out of 64 in the NTP timestamp received in
// the most recent sender report.
uint64_t lastSrReceived{ 0 }; // Wallclock time representing the most recent sender report
......
......@@ -52,10 +52,7 @@ namespace RTC
Buffer buffer;
private:
uint64_t lastPacketTimeMs{ 0 }; // Time (MS) when the last packet was received.
uint32_t lastPacketRtpTimestamp{ 0 }; // RTP Timestamp of the last packet.
// RTX related.
// Retransmittion related.
bool hasRtx{ false };
uint8_t rtxPayloadType{ 0 };
uint32_t rtxSsrc{ 0 };
......
......@@ -9,10 +9,10 @@ namespace RTC
{
/* Static. */
constexpr uint32_t MaxPacketAge{ 1500 };
constexpr size_t MaxNackPackets{ 500 };
constexpr uint32_t MaxPacketAge{ 10000 };
constexpr size_t MaxNackPackets{ 1000 };
constexpr uint32_t DefaultRtt{ 100 };
constexpr uint8_t MaxNackRetries{ 8 };
constexpr uint8_t MaxNackRetries{ 10 };
constexpr uint64_t TimerInterval{ 50 };
/* Instance methods. */
......@@ -111,22 +111,25 @@ namespace RTC
{
MS_TRACE();
uint32_t numItemsBefore = this->nackList.size();
if (seq32End > MaxPacketAge)
{
uint32_t numItemsBefore = this->nackList.size();
// Remove old packets.
auto it = this->nackList.lower_bound(seq32End - MaxPacketAge);
// Remove old packets.
auto it = this->nackList.lower_bound(seq32End - MaxPacketAge);
this->nackList.erase(this->nackList.begin(), it);
this->nackList.erase(this->nackList.begin(), it);
uint32_t numItemsRemoved = numItemsBefore - this->nackList.size();
uint32_t numItemsRemoved = numItemsBefore - this->nackList.size();
if (numItemsRemoved > 0)
{
MS_DEBUG_TAG(
rtx,
"removed %" PRIu32 " NACK items due to too old seq number [seq32End:%" PRIu32 "]",
numItemsRemoved,
seq32End);
if (numItemsRemoved > 0)
{
MS_DEBUG_TAG(
rtx,
"removed %" PRIu32 " NACK items due to too old seq number [seq32End:%" PRIu32 "]",
numItemsRemoved,
seq32End);
}
}
// If the nack list is too large, clear it and request a key frame.
......
......@@ -43,7 +43,6 @@ namespace RTC
static const Json::StaticString JsonStringBitRate{ "bitrate" };
static const Json::StaticString JsonStringJitter{ "jitter" };
static const Json::StaticString JsonStringMaxTimestamp{ "maxTimestamp" };
static const Json::StaticString JsonStringParams{ "params" };
static const Json::StaticString JsonStringPacketCount{ "packetCount" };
static const Json::StaticString JsonStringOctetCount{ "octetCount" };
......@@ -55,7 +54,6 @@ namespace RTC
json[JsonStringBitRate] = Json::UInt{ GetBitRate() };
json[JsonStringJitter] = Json::UInt{ this->jitter };
json[JsonStringMaxTimestamp] = Json::UInt{ this->maxTimestamp };
json[JsonStringParams] = this->params.ToJson();
json[JsonStringPacketCount] = static_cast<Json::UInt>(this->counter.GetPacketCount());
json[JsonStringOctetCount] = static_cast<Json::UInt>(this->counter.GetBytes());
......@@ -101,8 +99,11 @@ namespace RTC
this->cycles + static_cast<uint32_t>(packet->GetSequenceNumber()));
// Update highest seen RTP timestamp.
if (packet->GetTimestamp() > this->maxTimestamp)
this->maxTimestamp = packet->GetTimestamp();
if (packet->GetTimestamp() > this->maxPacketTs)
{
this->maxPacketTs = packet->GetTimestamp();
this->maxPacketMs = DepLibUV::GetTime();
}
return true;
}
......@@ -119,10 +120,10 @@ namespace RTC
MS_TRACE();
// Initialize/reset RTP counters.
this->baseSeq = seq;
this->maxSeq = seq;
this->badSeq = RtpSeqMod + 1; // So seq == badSeq is false.
this->maxTimestamp = 0; // Also reset the highest seen RTP timestamp.
this->baseSeq = seq;
this->maxSeq = seq;
this->badSeq = RtpSeqMod + 1; // So seq == badSeq is false.
this->maxPacketTs = 0; // Also reset the highest seen RTP timestamp.
}
bool RtpStream::UpdateSeq(RTC::RtpPacket* packet)
......
......@@ -12,7 +12,8 @@ namespace RTC
static constexpr uint32_t RtpSeqMod{ 1 << 16 };
// 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 };
/* Instance methods. */
......@@ -43,10 +44,6 @@ namespace RTC
if (!this->storage.empty())
StorePacket(packet);
// Record current time and RTP timestamp.
this->lastPacketTimeMs = DepLibUV::GetTime();
this->lastPacketRtpTimestamp = packet->GetTimestamp();
return true;
}
......@@ -182,13 +179,18 @@ namespace RTC
if (currentSeq32 == seq32)
{
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.
if (diffMs > MaxRetransmissionDelay)
{
if (!tooOldPacketFound)
{
// TODO: May we ask for a key frame in this case?
MS_WARN_TAG(
rtx,
"ignoring retransmission for too old packet "
......@@ -230,6 +232,7 @@ namespace RTC
break;
}
// It can not be after this packet.
if (currentSeq32 > seq32)
break;
......@@ -296,10 +299,10 @@ namespace RTC
report->SetNtpFrac(ntp.fractions);
// Calculate RTP timestamp diff between now and last received RTP packet.
uint32_t diffMs = now - this->lastPacketTimeMs;
uint32_t diffRtpTimestamp = diffMs * this->params.clockRate / 1000;
auto diffMs = static_cast<uint32_t>(now - this->maxPacketMs);
uint32_t diffTs = diffMs * this->params.clockRate / 1000;
report->SetRtpTs(this->lastPacketRtpTimestamp + diffRtpTimestamp);
report->SetRtpTs(this->maxPacketTs + diffTs);
return report;
}
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论