Skip to content

Commit

Permalink
Small tweaks and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Feb 21, 2022
1 parent 70b756d commit af3b681
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions worker/src/RTC/RtpStreamSend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace RTC
{
auto idx{ static_cast<uint16_t>(seq - this->startSeq) };

if (this->buffer.empty() || idx >= static_cast<uint16_t>(this->buffer.size()))
if (this->buffer.empty() || idx > static_cast<uint16_t>(this->buffer.size() - 1))
return nullptr;

return this->buffer.at(idx);
Expand All @@ -61,14 +61,18 @@ namespace RTC
return true;
}

auto idx{ static_cast<uint16_t>(seq - this->startSeq) };

if (idx < static_cast<uint16_t>(this->buffer.size()))
if (seq > this->startSeq)
{
MS_ASSERT(this->buffer[idx] == nullptr, "Must insert into empty slot");
this->buffer[idx] = storageItem;
auto idx{ static_cast<uint16_t>(seq - this->startSeq) };

return true;
// Packet arrived out of order, so we already have a slot allocated for it.
if (idx <= static_cast<uint16_t>(this->buffer.size() - 1))
{
MS_ASSERT(this->buffer[idx] == nullptr, "Must insert into empty slot");
this->buffer[idx] = storageItem;

return true;
}
}

// Calculate how many elements would it be necessary to add when pushing new item to the back of
Expand Down Expand Up @@ -442,7 +446,7 @@ namespace RTC

// Go through all buffer items starting with the first and free all storage
// items that contain packets older than `MaxRetransmissionDelay`.
for (uint16_t i{ 0 }; i <= MaxSeq; ++i)
for (uint32_t i{ 0 }; i <= static_cast<uint32_t>(MaxSeq); ++i)
{
auto* checkedStorageItem = this->storageItemBuffer.GetFirst();

Expand Down

0 comments on commit af3b681

Please sign in to comment.