Delete bandwidthsmoother.h.
BUG=webrtc:6424 Review-Url: https://codereview.webrtc.org/2367213004 Cr-Commit-Position: refs/heads/master@{#14498}
This commit is contained in:
parent
7ba305111a
commit
312303340c
@ -336,7 +336,6 @@ if (rtc_include_tests) {
|
||||
"base/array_view_unittest.cc",
|
||||
"base/atomicops_unittest.cc",
|
||||
"base/autodetectproxy_unittest.cc",
|
||||
"base/bandwidthsmoother_unittest.cc",
|
||||
"base/base64_unittest.cc",
|
||||
"base/basictypes_unittest.cc",
|
||||
"base/bind_unittest.cc",
|
||||
|
||||
@ -447,8 +447,6 @@ rtc_static_library("rtc_base") {
|
||||
} else {
|
||||
configs += [ ":rtc_base_warnings_config" ]
|
||||
sources += [
|
||||
"bandwidthsmoother.cc",
|
||||
"bandwidthsmoother.h",
|
||||
"callback.h",
|
||||
"fileutils_mock.h",
|
||||
"httpserver.cc",
|
||||
|
||||
@ -1,86 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include "webrtc/base/bandwidthsmoother.h"
|
||||
|
||||
#include <limits.h>
|
||||
#include <algorithm>
|
||||
|
||||
namespace rtc {
|
||||
|
||||
BandwidthSmoother::BandwidthSmoother(int initial_bandwidth_guess,
|
||||
uint32_t time_between_increase,
|
||||
double percent_increase,
|
||||
size_t samples_count_to_average,
|
||||
double min_sample_count_percent)
|
||||
: time_between_increase_(time_between_increase),
|
||||
percent_increase_(std::max(1.0, percent_increase)),
|
||||
time_at_last_change_(0),
|
||||
bandwidth_estimation_(initial_bandwidth_guess),
|
||||
accumulator_(samples_count_to_average),
|
||||
min_sample_count_percent_(
|
||||
std::min(1.0, std::max(0.0, min_sample_count_percent))) {
|
||||
}
|
||||
|
||||
BandwidthSmoother::~BandwidthSmoother() = default;
|
||||
|
||||
// Samples a new bandwidth measurement
|
||||
// returns true if the bandwidth estimation changed
|
||||
bool BandwidthSmoother::Sample(uint32_t sample_time, int bandwidth) {
|
||||
if (bandwidth < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
accumulator_.AddSample(bandwidth);
|
||||
|
||||
if (accumulator_.count() < static_cast<size_t>(
|
||||
accumulator_.max_count() * min_sample_count_percent_)) {
|
||||
// We have not collected enough samples yet.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Replace bandwidth with the mean of sampled bandwidths.
|
||||
const int mean_bandwidth = static_cast<int>(accumulator_.ComputeMean());
|
||||
|
||||
if (mean_bandwidth < bandwidth_estimation_) {
|
||||
time_at_last_change_ = sample_time;
|
||||
bandwidth_estimation_ = mean_bandwidth;
|
||||
return true;
|
||||
}
|
||||
|
||||
const int old_bandwidth_estimation = bandwidth_estimation_;
|
||||
const double increase_threshold_d = percent_increase_ * bandwidth_estimation_;
|
||||
if (increase_threshold_d > INT_MAX) {
|
||||
// If bandwidth goes any higher we would overflow.
|
||||
return false;
|
||||
}
|
||||
|
||||
const int increase_threshold = static_cast<int>(increase_threshold_d);
|
||||
if (mean_bandwidth < increase_threshold) {
|
||||
time_at_last_change_ = sample_time;
|
||||
// The value of bandwidth_estimation remains the same if we don't exceed
|
||||
// percent_increase_ * bandwidth_estimation_ for at least
|
||||
// time_between_increase_ time.
|
||||
} else if (sample_time >= time_at_last_change_ + time_between_increase_) {
|
||||
time_at_last_change_ = sample_time;
|
||||
if (increase_threshold == 0) {
|
||||
// Bandwidth_estimation_ must be zero. Assume a jump from zero to a
|
||||
// positive bandwidth means we have regained connectivity.
|
||||
bandwidth_estimation_ = mean_bandwidth;
|
||||
} else {
|
||||
bandwidth_estimation_ = increase_threshold;
|
||||
}
|
||||
}
|
||||
// Else don't make a change.
|
||||
|
||||
return old_bandwidth_estimation != bandwidth_estimation_;
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#ifndef WEBRTC_BASE_BANDWIDTHSMOOTHER_H_
|
||||
#define WEBRTC_BASE_BANDWIDTHSMOOTHER_H_
|
||||
|
||||
#include "webrtc/base/rollingaccumulator.h"
|
||||
#include "webrtc/base/timeutils.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
// The purpose of BandwidthSmoother is to smooth out bandwidth
|
||||
// estimations so that 'trstate' messages can be triggered when we
|
||||
// are "sure" there is sufficient bandwidth. To avoid frequent fluctuations,
|
||||
// we take a slightly pessimistic view of our bandwidth. We only increase
|
||||
// our estimation when we have sampled bandwidth measurements of values
|
||||
// at least as large as the current estimation * percent_increase
|
||||
// for at least time_between_increase time. If a sampled bandwidth
|
||||
// is less than our current estimation we immediately decrease our estimation
|
||||
// to that sampled value.
|
||||
// We retain the initial bandwidth guess as our current bandwidth estimation
|
||||
// until we have received (min_sample_count_percent * samples_count_to_average)
|
||||
// number of samples. Min_sample_count_percent must be in range [0, 1].
|
||||
class BandwidthSmoother {
|
||||
public:
|
||||
BandwidthSmoother(int initial_bandwidth_guess,
|
||||
uint32_t time_between_increase,
|
||||
double percent_increase,
|
||||
size_t samples_count_to_average,
|
||||
double min_sample_count_percent);
|
||||
~BandwidthSmoother();
|
||||
|
||||
// Samples a new bandwidth measurement.
|
||||
// bandwidth is expected to be non-negative.
|
||||
// returns true if the bandwidth estimation changed
|
||||
bool Sample(uint32_t sample_time, int bandwidth);
|
||||
|
||||
int get_bandwidth_estimation() const {
|
||||
return bandwidth_estimation_;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32_t time_between_increase_;
|
||||
double percent_increase_;
|
||||
uint32_t time_at_last_change_;
|
||||
int bandwidth_estimation_;
|
||||
RollingAccumulator<int> accumulator_;
|
||||
double min_sample_count_percent_;
|
||||
};
|
||||
|
||||
} // namespace rtc
|
||||
|
||||
#endif // WEBRTC_BASE_BANDWIDTHSMOOTHER_H_
|
||||
@ -1,122 +0,0 @@
|
||||
/*
|
||||
* Copyright 2011 The WebRTC Project Authors. All rights reserved.
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license
|
||||
* that can be found in the LICENSE file in the root of the source
|
||||
* tree. An additional intellectual property rights grant can be found
|
||||
* in the file PATENTS. All contributing project authors may
|
||||
* be found in the AUTHORS file in the root of the source tree.
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "webrtc/base/bandwidthsmoother.h"
|
||||
#include "webrtc/base/gunit.h"
|
||||
|
||||
namespace rtc {
|
||||
|
||||
static const int kTimeBetweenIncrease = 10;
|
||||
static const double kPercentIncrease = 1.1;
|
||||
static const size_t kSamplesCountToAverage = 2;
|
||||
static const double kMinSampleCountPercent = 1.0;
|
||||
|
||||
TEST(BandwidthSmootherTest, TestSampleIncrease) {
|
||||
BandwidthSmoother mon(1000, // initial_bandwidth_guess
|
||||
kTimeBetweenIncrease,
|
||||
kPercentIncrease,
|
||||
kSamplesCountToAverage,
|
||||
kMinSampleCountPercent);
|
||||
|
||||
int bandwidth_sample = 1000;
|
||||
EXPECT_EQ(bandwidth_sample, mon.get_bandwidth_estimation());
|
||||
bandwidth_sample =
|
||||
static_cast<int>(bandwidth_sample * kPercentIncrease);
|
||||
EXPECT_FALSE(mon.Sample(9, bandwidth_sample));
|
||||
EXPECT_TRUE(mon.Sample(10, bandwidth_sample));
|
||||
EXPECT_EQ(bandwidth_sample, mon.get_bandwidth_estimation());
|
||||
int next_expected_est =
|
||||
static_cast<int>(bandwidth_sample * kPercentIncrease);
|
||||
bandwidth_sample *= 2;
|
||||
EXPECT_TRUE(mon.Sample(20, bandwidth_sample));
|
||||
EXPECT_EQ(next_expected_est, mon.get_bandwidth_estimation());
|
||||
}
|
||||
|
||||
TEST(BandwidthSmootherTest, TestSampleIncreaseFromZero) {
|
||||
BandwidthSmoother mon(0, // initial_bandwidth_guess
|
||||
kTimeBetweenIncrease,
|
||||
kPercentIncrease,
|
||||
kSamplesCountToAverage,
|
||||
kMinSampleCountPercent);
|
||||
|
||||
const int kBandwidthSample = 1000;
|
||||
EXPECT_EQ(0, mon.get_bandwidth_estimation());
|
||||
EXPECT_FALSE(mon.Sample(9, kBandwidthSample));
|
||||
EXPECT_TRUE(mon.Sample(10, kBandwidthSample));
|
||||
EXPECT_EQ(kBandwidthSample, mon.get_bandwidth_estimation());
|
||||
}
|
||||
|
||||
TEST(BandwidthSmootherTest, TestSampleDecrease) {
|
||||
BandwidthSmoother mon(1000, // initial_bandwidth_guess
|
||||
kTimeBetweenIncrease,
|
||||
kPercentIncrease,
|
||||
kSamplesCountToAverage,
|
||||
kMinSampleCountPercent);
|
||||
|
||||
const int kBandwidthSample = 999;
|
||||
EXPECT_EQ(1000, mon.get_bandwidth_estimation());
|
||||
EXPECT_FALSE(mon.Sample(1, kBandwidthSample));
|
||||
EXPECT_EQ(1000, mon.get_bandwidth_estimation());
|
||||
EXPECT_TRUE(mon.Sample(2, kBandwidthSample));
|
||||
EXPECT_EQ(kBandwidthSample, mon.get_bandwidth_estimation());
|
||||
}
|
||||
|
||||
TEST(BandwidthSmootherTest, TestSampleTooFewSamples) {
|
||||
BandwidthSmoother mon(1000, // initial_bandwidth_guess
|
||||
kTimeBetweenIncrease,
|
||||
kPercentIncrease,
|
||||
10, // 10 samples.
|
||||
0.5); // 5 min samples.
|
||||
|
||||
const int kBandwidthSample = 500;
|
||||
EXPECT_EQ(1000, mon.get_bandwidth_estimation());
|
||||
EXPECT_FALSE(mon.Sample(1, kBandwidthSample));
|
||||
EXPECT_FALSE(mon.Sample(2, kBandwidthSample));
|
||||
EXPECT_FALSE(mon.Sample(3, kBandwidthSample));
|
||||
EXPECT_FALSE(mon.Sample(4, kBandwidthSample));
|
||||
EXPECT_EQ(1000, mon.get_bandwidth_estimation());
|
||||
EXPECT_TRUE(mon.Sample(5, kBandwidthSample));
|
||||
EXPECT_EQ(kBandwidthSample, mon.get_bandwidth_estimation());
|
||||
}
|
||||
|
||||
// Disabled for UBSan: https://bugs.chromium.org/p/webrtc/issues/detail?id=5491
|
||||
#ifdef UNDEFINED_SANITIZER
|
||||
#define MAYBE_TestSampleRollover DISABLED_TestSampleRollover
|
||||
#else
|
||||
#define MAYBE_TestSampleRollover TestSampleRollover
|
||||
#endif
|
||||
TEST(BandwidthSmootherTest, MAYBE_TestSampleRollover) {
|
||||
const int kHugeBandwidth = 2000000000; // > INT_MAX/1.1
|
||||
BandwidthSmoother mon(kHugeBandwidth,
|
||||
kTimeBetweenIncrease,
|
||||
kPercentIncrease,
|
||||
kSamplesCountToAverage,
|
||||
kMinSampleCountPercent);
|
||||
|
||||
EXPECT_FALSE(mon.Sample(10, INT_MAX));
|
||||
EXPECT_FALSE(mon.Sample(11, INT_MAX));
|
||||
EXPECT_EQ(kHugeBandwidth, mon.get_bandwidth_estimation());
|
||||
}
|
||||
|
||||
TEST(BandwidthSmootherTest, TestSampleNegative) {
|
||||
BandwidthSmoother mon(1000, // initial_bandwidth_guess
|
||||
kTimeBetweenIncrease,
|
||||
kPercentIncrease,
|
||||
kSamplesCountToAverage,
|
||||
kMinSampleCountPercent);
|
||||
|
||||
EXPECT_FALSE(mon.Sample(10, -1));
|
||||
EXPECT_FALSE(mon.Sample(11, -1));
|
||||
EXPECT_EQ(1000, mon.get_bandwidth_estimation());
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
@ -408,8 +408,6 @@
|
||||
},
|
||||
}, {
|
||||
'sources': [
|
||||
'bandwidthsmoother.cc',
|
||||
'bandwidthsmoother.h',
|
||||
'callback.h',
|
||||
'fileutils_mock.h',
|
||||
'httpserver.cc',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user