Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### NEXT

- Node: Update TypeScript to v6 ([PR #1790](https://github.com/versatica/mediasoup/pull/1790)).
- Worker: SeqManager, use std::vector rather than std::set ([1807](https://github.com/versatica/mediasoup/pull/1807)).
Comment thread
jmillan marked this conversation as resolved.
Outdated

### 3.19.22

Expand Down
7 changes: 4 additions & 3 deletions worker/include/RTC/SeqManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
#define RTC_SEQ_MANAGER_HPP

#include "common.hpp"
#include <limits> // std::numeric_limits
#include <set>
#include <algorithm> // for lower_bound, binary_search, distance, find_if
Comment thread
jmillan marked this conversation as resolved.
Outdated
#include <limits> // std::numeric_limits
#include <vector>

namespace RTC
{
Expand Down Expand Up @@ -53,7 +54,7 @@ namespace RTC
T maxInput{ 0 };
T maxDropped{ 0 };
T maxForwarded{ 0 };
std::set<T, SeqLowerThan> dropped;
std::vector<T> dropped;
};
} // namespace RTC

Expand Down
53 changes: 29 additions & 24 deletions worker/src/RTC/SeqManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,13 @@ namespace RTC
{
this->maxInput = input;
this->maxDropped = input;
// Insert input in the last position.
// Explicitly insert at the end, which is more performant.
this->dropped.insert(this->dropped.end(), input);
// Insert input in sorted order, if not present.
SeqLowerThan seqLowerThan;
Comment thread
jmillan marked this conversation as resolved.
Outdated
Comment thread
jmillan marked this conversation as resolved.
Outdated
auto it = std::lower_bound(this->dropped.begin(), this->dropped.end(), input, seqLowerThan);
Comment thread
jmillan marked this conversation as resolved.
Outdated
if (it == this->dropped.end() || *it != input)
{
this->dropped.insert(it, input);
}

ClearDropped();
}
Expand All @@ -74,7 +78,13 @@ namespace RTC
// Allows for properly accounting for out of order drops until an input is forwarded.
else if (this->maxInput == this->maxDropped && SeqManager<T, N>::IsSeqHigherThan(input, this->maxForwarded))
{
this->dropped.insert(input);
// Insert input in sorted order, if not present.
SeqLowerThan seqLowerThan;
Comment thread
jmillan marked this conversation as resolved.
Outdated
auto it = std::lower_bound(this->dropped.begin(), this->dropped.end(), input, seqLowerThan);
if (it == this->dropped.end() || *it != input)
{
this->dropped.insert(it, input);
}

ClearDropped();
}
Expand Down Expand Up @@ -113,7 +123,7 @@ namespace RTC
goto done;
}
// This input was dropped.
else if (this->dropped.find(input) != this->dropped.end())
else if (std::binary_search(this->dropped.begin(), this->dropped.end(), input, SeqLowerThan()))
{
MS_DEBUG_DEV("trying to send a dropped input");

Expand All @@ -122,12 +132,10 @@ namespace RTC
// There are dropped inputs, calculate 'base' for this input.
else
{
auto droppedCount = this->dropped.size();

// Get the first dropped input which is higher than or equal 'input'.
auto it = this->dropped.lower_bound(input);

droppedCount -= std::distance(it, this->dropped.end());
// Count dropped numbers less than input.
auto droppedCount = std::distance(
Comment thread
jmillan marked this conversation as resolved.
this->dropped.begin(),
std::lower_bound(this->dropped.begin(), this->dropped.end(), input, SeqLowerThan()));
base = (this->base - droppedCount) & SeqManager::MaxValue;
}

Expand Down Expand Up @@ -191,19 +199,16 @@ namespace RTC

const size_t previousDroppedSize = this->dropped.size();

for (auto it = this->dropped.begin(); it != this->dropped.end();)
{
auto value = *it;

if (SeqManager<T, N>::IsSeqHigherThan(value, this->maxInput))
{
it = this->dropped.erase(it);
}
else
{
break;
}
}
// Cleanup dropped values.
this->dropped.erase(
this->dropped.begin(),
std::find_if(
this->dropped.begin(),
this->dropped.end(),
[this](T value)
{
return !SeqManager<T, N>::IsSeqHigherThan(value, this->maxInput);
}));

// Adapt base.
this->base = (this->base - (previousDroppedSize - this->dropped.size())) & SeqManager::MaxValue;
Expand Down
Loading