Unverified 提交 908a9ab8 authored 作者: Dmitry Dolzhenko's avatar Dmitry Dolzhenko 提交者: GitHub

Fix old buffer items cleanup in `RTC::RateCalculator` (#830)

上级 89a6c5c2
...@@ -29,22 +29,9 @@ namespace RTC ...@@ -29,22 +29,9 @@ namespace RTC
if (this->newestItemIndex >= this->windowItems) if (this->newestItemIndex >= this->windowItems)
this->newestItemIndex = 0; this->newestItemIndex = 0;
// Newest index overlaps with the oldest one, remove it. MS_ASSERT(
if (this->newestItemIndex == this->oldestItemIndex && this->oldestItemIndex != -1) this->newestItemIndex != this->oldestItemIndex || this->oldestItemIndex == -1,
{ "newest index overlaps with the oldest one");
MS_WARN_TAG(
info,
"calculation buffer full, windowSizeMs:%zu ms windowItems:%" PRIu16,
this->windowSizeMs,
this->windowItems);
BufferItem& oldestItem = this->buffer[this->oldestItemIndex];
this->totalCount -= oldestItem.count;
oldestItem.count = 0u;
oldestItem.time = 0u;
if (++this->oldestItemIndex >= this->windowItems)
this->oldestItemIndex = 0;
}
// Set the newest item. // Set the newest item.
BufferItem& item = this->buffer[this->newestItemIndex]; BufferItem& item = this->buffer[this->newestItemIndex];
...@@ -98,21 +85,21 @@ namespace RTC ...@@ -98,21 +85,21 @@ namespace RTC
if (this->newestItemIndex < 0 || this->oldestItemIndex < 0) if (this->newestItemIndex < 0 || this->oldestItemIndex < 0)
return; return;
uint64_t newoldestTime = nowMs - this->windowSizeMs; uint64_t newOldestTime = nowMs - this->windowSizeMs;
// Oldest item already removed. // Oldest item already removed.
if (newoldestTime <= this->oldestItemStartTime) if (newOldestTime < this->oldestItemStartTime)
return; return;
// A whole window size time has elapsed since last entry. Reset the buffer. // A whole window size time has elapsed since last entry. Reset the buffer.
if (newoldestTime > this->newestItemStartTime) if (newOldestTime >= this->newestItemStartTime)
{ {
Reset(); Reset();
return; return;
} }
while (this->oldestItemStartTime < newoldestTime) while (newOldestTime >= this->oldestItemStartTime)
{ {
BufferItem& oldestItem = this->buffer[this->oldestItemIndex]; BufferItem& oldestItem = this->buffer[this->oldestItemIndex];
this->totalCount -= oldestItem.count; this->totalCount -= oldestItem.count;
......
...@@ -59,6 +59,22 @@ SCENARIO("Bitrate calculator", "[rtp][bitrate]") ...@@ -59,6 +59,22 @@ SCENARIO("Bitrate calculator", "[rtp][bitrate]")
validate(rate, nowMs, input); validate(rate, nowMs, input);
} }
SECTION("receive item every 1000 ms")
{
RateCalculator rate(1000, 8000, 100);
// clang-format off
std::vector<data> input =
{
{ 0, 5, 40 },
{ 1000, 5, 40 },
{ 2000, 5, 40 }
};
// clang-format on
validate(rate, nowMs, input);
}
SECTION("slide") SECTION("slide")
{ {
RateCalculator rate(1000, 8000, 1000); RateCalculator rate(1000, 8000, 1000);
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论