Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: webrtc/base/rate_statistics.cc

Issue 1908893003: Improve the behavior when the BWE times out and when we have too little data to determine the incom… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | webrtc/base/rate_statistics_unittest.cc » ('j') | webrtc/base/rate_statistics_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/base/rate_statistics.cc
diff --git a/webrtc/base/rate_statistics.cc b/webrtc/base/rate_statistics.cc
index 8db2851e682f3e152cced6a738eedb571d982c66..843eadbadacc22a9c131168b592b1cd2a86788f3 100644
--- a/webrtc/base/rate_statistics.cc
+++ b/webrtc/base/rate_statistics.cc
@@ -10,7 +10,7 @@
#include "webrtc/base/rate_statistics.h"
-#include <assert.h>
+#include <algorithm>
namespace webrtc {
@@ -20,7 +20,7 @@ RateStatistics::RateStatistics(uint32_t window_size_ms, float scale)
accumulated_count_(0),
oldest_time_(0),
oldest_index_(0),
- scale_(scale / (num_buckets_ - 1)) {}
+ scale_(scale) {}
RateStatistics::~RateStatistics() {}
@@ -53,15 +53,17 @@ void RateStatistics::Update(size_t count, int64_t now_ms) {
uint32_t RateStatistics::Rate(int64_t now_ms) {
EraseOld(now_ms);
- return static_cast<uint32_t>(accumulated_count_ * scale_ + 0.5f);
+ float scale = scale_ / (now_ms - oldest_time_ + 1);
+ return static_cast<uint32_t>(accumulated_count_ * scale + 0.5f);
}
void RateStatistics::EraseOld(int64_t now_ms) {
int64_t new_oldest_time = now_ms - num_buckets_ + 1;
if (new_oldest_time <= oldest_time_) {
+ if (accumulated_count_ == 0)
+ oldest_time_ = now_ms;
return;
}
-
while (oldest_time_ < new_oldest_time) {
size_t count_in_oldest_bucket = buckets_[oldest_index_];
assert(accumulated_count_ >= count_in_oldest_bucket);
@@ -74,6 +76,7 @@ void RateStatistics::EraseOld(int64_t now_ms) {
if (accumulated_count_ == 0) {
// This guarantees we go through all the buckets at most once, even if
// |new_oldest_time| is far greater than |oldest_time_|.
+ new_oldest_time = now_ms;
break;
}
}
« no previous file with comments | « no previous file | webrtc/base/rate_statistics_unittest.cc » ('j') | webrtc/base/rate_statistics_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698