Unverified 提交 9ae56538 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo 提交者: GitHub

RtpRetransmissionBuffer: get rid of startSeq private member (#1029)

上级 5be8faa8
# Changelog
### NEXT
* `RtpRetransmissionBuffer`: Get rid of not necessary `startSeq` private member ([PR #1029](https://github.com/versatica/mediasoup/pull/1029).
### 3.11.15
* `RtpRetransmissionBuffer.cpp`: Fix crash and add fuzzer ([PR #1028](https://github.com/versatica/mediasoup/pull/1028).
* `RtpRetransmissionBuffer`: Fix crash and add fuzzer ([PR #1028](https://github.com/versatica/mediasoup/pull/1028).
* Update NPM deps.
......
......@@ -60,8 +60,6 @@ namespace RTC
uint16_t maxItems;
uint32_t maxRetransmissionDelayMs;
uint32_t clockRate;
// Others.
uint16_t startSeq{ 0u };
};
} // namespace RTC
......
......@@ -29,17 +29,19 @@ namespace RTC
{
MS_TRACE();
if (this->buffer.empty())
const auto* oldestItem = GetOldest();
if (!oldestItem)
{
return nullptr;
}
if (RTC::SeqManager<uint16_t>::IsSeqLowerThan(seq, this->startSeq))
if (RTC::SeqManager<uint16_t>::IsSeqLowerThan(seq, oldestItem->sequenceNumber))
{
return nullptr;
}
auto idx = static_cast<uint16_t>(seq - this->startSeq);
const auto idx = static_cast<uint16_t>(seq - oldestItem->sequenceNumber);
if (idx > static_cast<uint16_t>(this->buffer.size() - 1))
{
......@@ -61,9 +63,9 @@ namespace RTC
{
MS_TRACE();
auto ssrc = packet->GetSsrc();
auto seq = packet->GetSequenceNumber();
auto timestamp = packet->GetTimestamp();
const auto ssrc = packet->GetSsrc();
const auto seq = packet->GetSequenceNumber();
const auto timestamp = packet->GetTimestamp();
MS_DEBUG_DEV("packet [seq:%" PRIu16 ", timestamp:%" PRIu32 "]", seq, timestamp);
......@@ -76,17 +78,14 @@ namespace RTC
this->buffer.push_back(FillItem(item, packet, sharedPacket));
// Packet's seq number becomes startSeq.
this->startSeq = seq;
return;
}
// Clear too old packets in the buffer.
ClearTooOld();
auto* oldestItem = GetOldest();
auto* newestItem = GetNewest();
const auto* oldestItem = GetOldest();
const auto* newestItem = GetNewest();
MS_ASSERT(oldestItem != nullptr, "oldest item doesn't exist");
MS_ASSERT(newestItem != nullptr, "newest item doesn't exist");
......@@ -120,7 +119,7 @@ namespace RTC
// the buffer.
if (this->buffer.size() + numBlankSlots + 1 > this->maxItems)
{
auto numItemsToRemove =
const auto numItemsToRemove =
static_cast<uint16_t>(this->buffer.size() + numBlankSlots + 1 - this->maxItems);
// If num of items to be removed exceed buffer size minus one (needed to
......@@ -138,9 +137,6 @@ namespace RTC
numBlankSlots = 0u;
Clear();
// After clearing the buffer, update startSeq.
this->startSeq = seq;
}
else
{
......@@ -203,7 +199,7 @@ namespace RTC
// Calculate how many blank slots it would be necessary to add when
// pushing new item to the fton of the buffer.
auto numBlankSlots = static_cast<uint16_t>(oldestItem->sequenceNumber - seq - 1);
const auto numBlankSlots = static_cast<uint16_t>(oldestItem->sequenceNumber - seq - 1);
// If adding this packet (and needed blank slots) to the front makes the
// buffer exceed its max size, discard this packet.
......@@ -230,9 +226,6 @@ namespace RTC
auto* item = new Item();
this->buffer.push_front(FillItem(item, packet, sharedPacket));
// Packet's seq number becomes startSeq.
this->startSeq = seq;
}
// Otherwise packet must be inserted between oldest and newest stored items
// so there is already an allocated slot for it.
......@@ -259,13 +252,13 @@ namespace RTC
}
// idx is the intended position of the received packet in the buffer.
auto idx = static_cast<uint16_t>(seq - this->startSeq);
const auto idx = static_cast<uint16_t>(seq - oldestItem->sequenceNumber);
// Validate that packet timestamp is equal or higher than the timestamp of
// the immediate older packet (if any).
for (auto idx2 = static_cast<int32_t>(idx - 1); idx2 >= 0; --idx2)
{
auto* olderItem = this->buffer.at(idx2);
const auto* olderItem = this->buffer.at(idx2);
// Blank slot, continue.
if (!olderItem)
......@@ -296,7 +289,7 @@ namespace RTC
// the immediate newer packet (if any).
for (auto idx2 = static_cast<size_t>(idx + 1); idx2 < this->buffer.size(); ++idx2)
{
auto* newerItem = this->buffer.at(idx2);
const auto* newerItem = this->buffer.at(idx2);
// Blank slot, continue.
if (!newerItem)
......@@ -354,7 +347,6 @@ namespace RTC
}
this->buffer.clear();
this->startSeq = 0u;
}
void RtpRetransmissionBuffer::Dump() const
......@@ -362,11 +354,7 @@ namespace RTC
MS_TRACE();
MS_DUMP("<RtpRetransmissionBuffer>");
MS_DUMP(
" buffer [size:%zu, maxSize:%" PRIu16 ", startSeq:%" PRIu16 "]",
this->buffer.size(),
this->maxItems,
this->startSeq);
MS_DUMP(" buffer [size:%zu, maxSize:%" PRIu16 "]", this->buffer.size(), this->maxItems);
if (this->buffer.size() > 0)
{
const auto* oldestItem = GetOldest();
......@@ -392,14 +380,24 @@ namespace RTC
{
MS_TRACE();
return this->Get(this->startSeq);
if (this->buffer.empty())
{
return nullptr;
}
return this->buffer.front();
}
RtpRetransmissionBuffer::Item* RtpRetransmissionBuffer::GetNewest() const
{
MS_TRACE();
return this->Get(this->startSeq + this->buffer.size() - 1);
if (this->buffer.empty())
{
return nullptr;
}
return this->buffer.back();
}
void RtpRetransmissionBuffer::RemoveOldest()
......@@ -411,7 +409,7 @@ namespace RTC
return;
}
auto* item = this->buffer.at(0);
auto* item = this->buffer.front();
// Reset the stored item (decrease RTP packet shared pointer counter).
item->Reset();
......@@ -419,7 +417,6 @@ namespace RTC
delete item;
this->buffer.pop_front();
this->startSeq++;
MS_DEBUG_DEV("removed 1 item from the front");
......@@ -430,7 +427,6 @@ namespace RTC
while (!this->buffer.empty() && this->buffer.front() == nullptr)
{
this->buffer.pop_front();
this->startSeq++;
++numItemsRemoved;
}
......@@ -439,12 +435,6 @@ namespace RTC
{
MS_DEBUG_DEV("removed 1 blank slot from the front");
}
// If we emptied the full buffer, reset startSeq.
if (this->buffer.empty())
{
this->startSeq = 0u;
}
}
void RtpRetransmissionBuffer::RemoveOldest(uint16_t numItems)
......@@ -458,7 +448,7 @@ namespace RTC
numItems,
this->buffer.size());
auto intendedBufferSize = this->buffer.size() - numItems;
const auto intendedBufferSize = this->buffer.size() - numItems;
while (this->buffer.size() > intendedBufferSize)
{
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论