Unverified 提交 937bb6c8 authored 作者: José Luis Millán's avatar José Luis Millán 提交者: GitHub

SeqManager: Properly remove dropped entries (#1054)

* SeqManager: Properly remove dropped entries

Fixes #1037.

Keep dropped entries clean by removing those higher than this->maxInput.

* Set dropped input to 'maxInput' if needed

A dropped input is part of the same sequence, hence set it to 'maxInput'
if the dropped value is higher than the current 'maxInput'.

Without this consideration we would be wrongly erasing dropped inputs
that are legitimally just the maximum input of the sequence stream.

* Update CHANGELOG

* Input(): Performance, do not loop over every dropped inputs

Which has a linear complexity. Use lower_bound which has logarithmic
complexity.
上级 56eda745
# Changelog
### NEXT
* `SeqManager`: Properly remove old dropped entries ([PR #1054](https://github.com/versatica/mediasoup/pull/1054)).
### 3.11.21
* Fix check division by zero in transport congestion control ([PR #1049](https://github.com/versatica/mediasoup/pull/1049) by @ggarber).
......
......@@ -58,7 +58,10 @@ namespace RTC
// Mark as dropped if 'input' is higher than anyone already processed.
if (SeqManager<T, N>::IsSeqHigherThan(input, this->maxInput))
{
this->maxInput = input;
this->dropped.insert(input);
ClearDropped();
}
}
......@@ -67,44 +70,52 @@ namespace RTC
{
auto base = this->base;
// There are dropped inputs. Synchronize.
if (!this->dropped.empty())
// No dropped inputs to consider.
if (this->dropped.empty())
{
// Check whether this input was dropped.
if (this->dropped.find(input) != this->dropped.end())
goto done;
}
// Dropped inputs present, cleanup and update base.
else
{
// Set 'maxInput' here if needed before calling ClearDropped().
if (this->started && IsSeqHigherThan(input, this->maxInput))
{
MS_DEBUG_DEV("trying to send a dropped input");
return false;
this->maxInput = input;
}
// Dropped entries count that must be considered for the output.
size_t count{ 0 };
ClearDropped();
base = this->base;
}
// No dropped inputs to consider after cleanup.
if (this->dropped.empty())
{
goto done;
}
// This input was dropped.
else if (this->dropped.find(input) != this->dropped.end())
{
MS_DEBUG_DEV("trying to send a dropped input");
/*
* Consider values lower than input and those higher that input
* which belong to a previous cycle.
*/
for (const auto& value : this->dropped)
return false;
}
// There are dropped inputs, calculate 'base' for this input.
else
{
// Get the first dropped input which is higher than or equal 'input'.
auto it = this->dropped.lower_bound(input);
// There are dropped inputs lower than 'input'.
if (it != this->dropped.begin())
{
// clang-format off
if
(
IsSeqLowerThan(value, input) ||
(
(value > input && (value - input > MaxValue / 3)) ||
(value < input && (input - value > MaxValue / 3))
)
)
// clang-format on
{
count++;
}
auto count = std::distance(this->dropped.begin(), it);
base = (this->base - count) & MaxValue;
}
base = (this->base - count) & MaxValue;
}
done:
output = (input + base) & MaxValue;
if (!this->started)
......@@ -116,23 +127,19 @@ namespace RTC
}
else
{
// New input is higher than the maximum seen. But less than acceptable units higher.
// Keep it as the maximum seen. See Drop().
// New input is higher than the maximum seen.
if (IsSeqHigherThan(input, this->maxInput))
{
this->maxInput = input;
}
// New output is higher than the maximum seen. But less than acceptable units higher.
// Keep it as the maximum seen. See Sync().
// New output is higher than the maximum seen.
if (IsSeqHigherThan(output, this->maxOutput))
{
this->maxOutput = output;
}
}
ClearDropped();
return true;
}
......@@ -149,7 +156,7 @@ namespace RTC
}
/*
* Delete droped inputs greater than maxInput that belong to a previous
* Delete droped inputs greater than maxInput, which belong to a previous
* cycle.
*/
template<typename T, uint8_t N>
......@@ -161,37 +168,19 @@ namespace RTC
return;
}
const size_t threshold = (this->maxInput + MaxValue / 3) & MaxValue;
const size_t previousDroppedSize = this->dropped.size();
const auto it1 = this->dropped.upper_bound(this->maxInput);
const auto it2 = this->dropped.lower_bound(threshold);
// There is no dropped value greater than this->maxInput.
if (it1 == this->dropped.end())
{
return;
}
// There is a single value in the range.
if (it1 == it2)
{
this->dropped.erase(it1);
}
// There are many values in the range.
else
for (auto it = this->dropped.begin(); it != this->dropped.end();)
{
// Measure the distance of it1 and it2 to the beggining of dropped.
auto distanceIt1 = std::distance(this->dropped.begin(), it1);
auto distanceIt2 = std::distance(this->dropped.begin(), it2);
auto value = *it;
// it2 goes out of range, only it1 is within the range.
if (distanceIt2 < distanceIt1)
if (isSeqHigherThan(value, this->maxInput))
{
this->dropped.erase(it1);
it = this->dropped.erase(it);
}
else
{
this->dropped.erase(it1, it2);
break;
}
}
......
......@@ -666,19 +666,19 @@ SCENARIO("SeqManager", "[rtc][SeqMananger]")
{ 50886, 0, false, true }, // Drop.
{ 4806, 4805, false, false }, // Previously dropped.
{ 50774, 0, false, true }, // Drop.
{ 50886, 50884, false, false }, // Previously dropped.
{ 50886, 4805, false, false }, // Previously dropped.
{ 22136, 0, false, true }, // Drop.
{ 50774, 50884, false, false }, // Previously dropped.
{ 50774, 50773, false, false },
{ 30910, 0, false, true }, // Drop.
{ 22136, 22134, false, false },
{ 22136, 50773, false, false }, // Previously dropped.
{ 48862, 0, false, true }, // Drop.
{ 30910, 30909, false, false },
{ 56832, 0, false, true }, // Drop.
{ 48862, 48861, false, false },
{ 2, 0, false, true }, // Drop.
{ 56832, 56828, false, false },
{ 56832, 48861, false, false }, // Previously dropped.
{ 530, 0, false, true }, // Drop.
{ 2, 65534, false, false },
{ 2, 48861, false, false }, // Previously dropped.
};
// clang-format on
......@@ -695,9 +695,9 @@ SCENARIO("SeqManager", "[rtc][SeqMananger]")
{ 3328, 0, false, true }, // Drop.
{ 24589, 24588, false, false },
{ 120, 0, false, true }, // Drop.
{ 3328, 3326, false, false },
{ 3328, 24588, false, false }, // Previously dropped.
{ 30848, 0, false, true }, // Drop.
{ 120, 3326, false, false }, // Previously dropped.
{ 120, 120, false, false },
};
// clang-format on
......@@ -714,11 +714,11 @@ SCENARIO("SeqManager", "[rtc][SeqMananger]")
{ 65396 , 0, false, true }, // Drop.
{ 25855, 25854, false, false },
{ 29793 , 0, false, true }, // Drop.
{ 65396, 65395, false, false },
{ 65396, 25854, false, false }, // Previously dropped.
{ 25087, 0, false, true }, // Drop.
{ 29793, 29791, false, false },
{ 29793, 25854, false, false }, // Previously dropped.
{ 65535 , 0, false, true }, // Drop.
{ 25087, 29791, false, false }, // Previously dropped.
{ 25087, 25086, false, false },
};
// clang-format on
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论