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

Fix video lag after a long time (#373)

This issue produced video lag when using simulcast/SVC when staying at the low streams for 10-20 minutes.

A big thanks to @penguinol for reporting it and giving the solution in #372.
上级 c69caa74
...@@ -56,7 +56,9 @@ namespace RTC ...@@ -56,7 +56,9 @@ namespace RTC
{ {
// Mark as dropped if 'input' is higher than anyone already processed. // Mark as dropped if 'input' is higher than anyone already processed.
if (SeqManager<T>::IsSeqHigherThan(input, this->maxInput)) if (SeqManager<T>::IsSeqHigherThan(input, this->maxInput))
{
this->dropped.insert(input); this->dropped.insert(input);
}
} }
template<typename T> template<typename T>
...@@ -74,8 +76,12 @@ namespace RTC ...@@ -74,8 +76,12 @@ namespace RTC
if (!this->dropped.empty()) if (!this->dropped.empty())
{ {
// Delete dropped inputs older than input - MaxValue/2. // Delete dropped inputs older than input - MaxValue/2.
auto it = this->dropped.lower_bound(input - MaxValue / 2); size_t droppedSize = this->dropped.size();
auto it = this->dropped.lower_bound(input - MaxValue / 2);
this->dropped.erase(this->dropped.begin(), it); this->dropped.erase(this->dropped.begin(), it);
this->base -= (droppedSize - this->dropped.size());
base = this->base;
// Check whether this input was dropped. // Check whether this input was dropped.
it = this->dropped.find(input); it = this->dropped.find(input);
......
#include "common.hpp" #include "common.hpp"
#include "RTC/SeqManager.hpp" #include "RTC/SeqManager.hpp"
#include <catch.hpp> #include <catch.hpp>
#include <string>
#include <vector> #include <vector>
using namespace RTC; using namespace RTC;
template<typename T>
struct TestSeqManagerInput struct TestSeqManagerInput
{ {
TestSeqManagerInput( TestSeqManagerInput(T input, T output, bool sync = false, bool drop = false, T offset = 0)
uint16_t input, uint16_t output, bool sync = false, bool drop = false, uint16_t offset = 0)
: input(input), output(output), sync(sync), drop(drop), offset(offset) : input(input), output(output), sync(sync), drop(drop), offset(offset)
{ {
} }
uint16_t input{ 0 }; T input{ 0 };
uint16_t output{ 0 }; T output{ 0 };
bool sync{ false }; bool sync{ false };
bool drop{ false }; bool drop{ false };
uint16_t offset{ 0 }; T offset{ 0 };
}; };
void validate(SeqManager<uint16_t>& seqManager, std::vector<TestSeqManagerInput>& inputs) template<typename T>
void validate(SeqManager<T>& seqManager, std::vector<TestSeqManagerInput<T>>& inputs)
{ {
for (auto& element : inputs) for (auto& element : inputs)
{ {
...@@ -36,10 +38,12 @@ void validate(SeqManager<uint16_t>& seqManager, std::vector<TestSeqManagerInput> ...@@ -36,10 +38,12 @@ void validate(SeqManager<uint16_t>& seqManager, std::vector<TestSeqManagerInput>
} }
else else
{ {
uint16_t output; T output;
seqManager.Input(element.input, output); seqManager.Input(element.input, output);
REQUIRE(output == element.output);
// Covert to string because otherwise Catch will print uint8_t as char.
REQUIRE(std::to_string(output) == std::to_string(element.output));
} }
} }
} }
...@@ -54,7 +58,7 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -54,7 +58,7 @@ SCENARIO("SeqManager", "[rtc]")
SECTION("receive ordered numbers, no sync, no drop") SECTION("receive ordered numbers, no sync, no drop")
{ {
// clang-format off // clang-format off
std::vector<TestSeqManagerInput> inputs = std::vector<TestSeqManagerInput<uint16_t>> inputs =
{ {
{ 0, 0, false, false }, { 0, 0, false, false },
{ 1, 1, false, false }, { 1, 1, false, false },
...@@ -78,12 +82,12 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -78,12 +82,12 @@ SCENARIO("SeqManager", "[rtc]")
SECTION("receive ordered numbers, sync, no drop") SECTION("receive ordered numbers, sync, no drop")
{ {
// clang-format off // clang-format off
std::vector<TestSeqManagerInput> inputs = std::vector<TestSeqManagerInput<uint16_t>> inputs =
{ {
{ 0, 0, false, false }, { 0, 0, false, false },
{ 1, 1, false, false }, { 1, 1, false, false },
{ 2, 2, false, false }, { 2, 2, false, false },
{ 80, 3, true, false }, { 80, 3, true, false },
{ 81, 4, false, false }, { 81, 4, false, false },
{ 82, 5, false, false }, { 82, 5, false, false },
{ 83, 6, false, false }, { 83, 6, false, false },
...@@ -98,7 +102,7 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -98,7 +102,7 @@ SCENARIO("SeqManager", "[rtc]")
SECTION("receive ordered numbers, sync, drop") SECTION("receive ordered numbers, sync, drop")
{ {
// clang-format off // clang-format off
std::vector<TestSeqManagerInput> inputs = std::vector<TestSeqManagerInput<uint16_t>> inputs =
{ {
{ 0, 0, false, false }, { 0, 0, false, false },
{ 1, 1, false, false }, { 1, 1, false, false },
...@@ -123,7 +127,7 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -123,7 +127,7 @@ SCENARIO("SeqManager", "[rtc]")
SECTION("receive ordered wrapped numbers") SECTION("receive ordered wrapped numbers")
{ {
// clang-format off // clang-format off
std::vector<TestSeqManagerInput> inputs = std::vector<TestSeqManagerInput<uint16_t>> inputs =
{ {
{ 65533, 65533, false, false }, { 65533, 65533, false, false },
{ 65534, 65534, false, false }, { 65534, 65534, false, false },
...@@ -140,10 +144,10 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -140,10 +144,10 @@ SCENARIO("SeqManager", "[rtc]")
SECTION("receive sequence numbers with a big jump") SECTION("receive sequence numbers with a big jump")
{ {
// clang-format off // clang-format off
std::vector<TestSeqManagerInput> inputs = std::vector<TestSeqManagerInput<uint16_t>> inputs =
{ {
{ 0, 0, false, false }, { 0, 0, false, false },
{ 1, 1, false, false }, { 1, 1, false, false },
{ 1000, 1000, false, false }, { 1000, 1000, false, false },
{ 1001, 1001, false, false } { 1001, 1001, false, false }
}; };
...@@ -156,7 +160,7 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -156,7 +160,7 @@ SCENARIO("SeqManager", "[rtc]")
SECTION("receive mixed numbers with a big jump, drop before jump") SECTION("receive mixed numbers with a big jump, drop before jump")
{ {
// clang-format off // clang-format off
std::vector<TestSeqManagerInput> inputs = std::vector<TestSeqManagerInput<uint16_t>> inputs =
{ {
{ 0, 0, false, false }, { 0, 0, false, false },
{ 1, 0, false, true }, // drop. { 1, 0, false, true }, // drop.
...@@ -174,7 +178,7 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -174,7 +178,7 @@ SCENARIO("SeqManager", "[rtc]")
SECTION("receive mixed numbers with a big jump, drop after jump") SECTION("receive mixed numbers with a big jump, drop after jump")
{ {
// clang-format off // clang-format off
std::vector<TestSeqManagerInput> inputs = std::vector<TestSeqManagerInput<uint16_t>> inputs =
{ {
{ 0, 0, false, false }, { 0, 0, false, false },
{ 1, 1, false, false }, { 1, 1, false, false },
...@@ -191,7 +195,7 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -191,7 +195,7 @@ SCENARIO("SeqManager", "[rtc]")
SECTION("drop, receive numbers newer and older than the one dropped") SECTION("drop, receive numbers newer and older than the one dropped")
{ {
// clang-format off // clang-format off
std::vector<TestSeqManagerInput> inputs = std::vector<TestSeqManagerInput<uint16_t>> inputs =
{ {
{ 0, 0, false, false }, { 0, 0, false, false },
{ 2, 0, false, true }, // drop. { 2, 0, false, true }, // drop.
...@@ -208,7 +212,7 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -208,7 +212,7 @@ SCENARIO("SeqManager", "[rtc]")
SECTION("receive mixed numbers, sync, drop") SECTION("receive mixed numbers, sync, drop")
{ {
// clang-format off // clang-format off
std::vector<TestSeqManagerInput> inputs = std::vector<TestSeqManagerInput<uint16_t>> inputs =
{ {
{ 0, 0, false, false }, { 0, 0, false, false },
{ 1, 1, false, false }, { 1, 1, false, false },
...@@ -266,7 +270,7 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -266,7 +270,7 @@ SCENARIO("SeqManager", "[rtc]")
SECTION("receive ordered numbers, sync, no drop, increase input") SECTION("receive ordered numbers, sync, no drop, increase input")
{ {
// clang-format off // clang-format off
std::vector<TestSeqManagerInput> inputs = std::vector<TestSeqManagerInput<uint16_t>> inputs =
{ {
{ 0, 0, false, false }, { 0, 0, false, false },
{ 1, 1, false, false }, { 1, 1, false, false },
...@@ -282,4 +286,120 @@ SCENARIO("SeqManager", "[rtc]") ...@@ -282,4 +286,120 @@ SCENARIO("SeqManager", "[rtc]")
SeqManager<uint16_t> seqManager; SeqManager<uint16_t> seqManager;
validate(seqManager, inputs); validate(seqManager, inputs);
} }
SECTION("drop many inputs at the beginning (using uint16_t)")
{
// clang-format off
std::vector<TestSeqManagerInput<uint16_t>> inputs =
{
{ 1, 1, false, false },
{ 2, 0, false, true }, // drop.
{ 3, 0, false, true }, // drop.
{ 4, 0, false, true }, // drop.
{ 5, 0, false, true }, // drop.
{ 6, 0, false, true }, // drop.
{ 7, 0, false, true }, // drop.
{ 8, 0, false, true }, // drop.
{ 9, 0, false, true }, // drop.
{ 120, 112, false, false },
{ 121, 113, false, false },
{ 122, 114, false, false },
{ 123, 115, false, false },
{ 124, 116, false, false },
{ 125, 117, false, false },
{ 126, 118, false, false },
{ 127, 119, false, false },
{ 128, 120, false, false },
{ 129, 121, false, false },
{ 130, 122, false, false },
{ 131, 123, false, false },
{ 132, 124, false, false },
{ 133, 125, false, false },
{ 134, 126, false, false },
{ 135, 127, false, false },
{ 136, 128, false, false },
{ 137, 129, false, false },
{ 138, 130, false, false },
{ 139, 131, false, false }
};
// clang-format on
SeqManager<uint16_t> seqManager;
validate(seqManager, inputs);
}
SECTION("drop many inputs at the beginning (using uint8_t)")
{
// clang-format off
std::vector<TestSeqManagerInput<uint8_t>> inputs =
{
{ 1, 1, false, false },
{ 2, 0, false, true }, // drop.
{ 3, 0, false, true }, // drop.
{ 4, 0, false, true }, // drop.
{ 5, 0, false, true }, // drop.
{ 6, 0, false, true }, // drop.
{ 7, 0, false, true }, // drop.
{ 8, 0, false, true }, // drop.
{ 9, 0, false, true }, // drop.
{ 120, 112, false, false },
{ 121, 113, false, false },
{ 122, 114, false, false },
{ 123, 115, false, false },
{ 124, 116, false, false },
{ 125, 117, false, false },
{ 126, 118, false, false },
{ 127, 119, false, false },
{ 128, 120, false, false },
{ 129, 121, false, false },
{ 130, 122, false, false },
{ 131, 123, false, false },
{ 132, 124, false, false },
{ 133, 125, false, false },
{ 134, 126, false, false },
{ 135, 127, false, false },
{ 136, 128, false, false },
{ 137, 129, false, false },
{ 138, 130, false, false },
{ 139, 131, false, false }
};
// clang-format on
SeqManager<uint8_t> seqManager;
validate(seqManager, inputs);
}
SECTION("drop many inputs at the beginning (using uint16_t with high values)")
{
// clang-format off
std::vector<TestSeqManagerInput<uint16_t>> inputs =
{
{ 1, 1, false, false },
{ 2, 0, false, true }, // drop.
{ 3, 0, false, true }, // drop.
{ 4, 0, false, true }, // drop.
{ 5, 0, false, true }, // drop.
{ 6, 0, false, true }, // drop.
{ 7, 0, false, true }, // drop.
{ 8, 0, false, true }, // drop.
{ 9, 0, false, true }, // drop.
{ 32768, 32760, false, false },
{ 32769, 32761, false, false },
{ 32770, 32762, false, false },
{ 32771, 32763, false, false },
{ 32772, 32764, false, false },
{ 32773, 32765, false, false },
{ 32774, 32766, false, false },
{ 32775, 32767, false, false },
{ 32776, 32768, false, false },
{ 32777, 32769, false, false },
{ 32778, 32770, false, false },
{ 32779, 32771, false, false },
{ 32780, 32772, false, false }
};
// clang-format on
SeqManager<uint16_t> seqManager;
validate(seqManager, inputs);
}
} }
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论