Let a minimum time interval pass (one bucket size) after initialization before reporting rates (to avoid rates being based on too short time intervals).

BUG=chromium:570038

Review URL: https://codereview.webrtc.org/1582333008

Cr-Commit-Position: refs/heads/master@{#11455}
This commit is contained in:
asapersson 2016-02-02 01:46:53 -08:00 committed by Commit bot
parent 6fd26b6ec8
commit 799379e8c2
2 changed files with 13 additions and 3 deletions

View File

@ -63,6 +63,10 @@ double RateTracker::ComputeRateForInterval(
milliseconds_to_skip = 0u;
available_interval_milliseconds =
TimeDiff(current_time, initialization_time_milliseconds_);
// Let one bucket interval pass after initialization before reporting.
if (available_interval_milliseconds < bucket_milliseconds_) {
return 0.0;
}
}
// If we're skipping all buckets that means that there have been no samples
// within the sampling interval so report 0.

View File

@ -12,10 +12,13 @@
#include "webrtc/base/ratetracker.h"
namespace rtc {
namespace {
const uint32_t kBucketIntervalMs = 100;
} // namespace
class RateTrackerForTest : public RateTracker {
public:
RateTrackerForTest() : RateTracker(100u, 10u), time_(0) {}
RateTrackerForTest() : RateTracker(kBucketIntervalMs, 10u), time_(0) {}
virtual uint32_t Time() const { return time_; }
void AdvanceTime(uint32_t delta) { time_ += delta; }
@ -55,8 +58,11 @@ TEST(RateTrackerTest, TestRateTrackerBasics) {
// Add a sample.
tracker.AddSamples(1234);
// Advance the clock by 100 ms.
tracker.AdvanceTime(100);
// Advance the clock by less than one bucket interval (no rate returned).
tracker.AdvanceTime(kBucketIntervalMs - 1);
EXPECT_DOUBLE_EQ(0.0, tracker.ComputeRate());
// Advance the clock by 100 ms (one bucket interval).
tracker.AdvanceTime(1);
EXPECT_DOUBLE_EQ(12340.0, tracker.ComputeRateForInterval(1000u));
EXPECT_DOUBLE_EQ(12340.0, tracker.ComputeRate());
EXPECT_EQ(1234U, tracker.TotalSampleCount());