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

Side by Side Diff: webrtc/modules/remote_bitrate_estimator/overuse_detector.cc

Issue 1151603008: Make the BWE threshold adaptive. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix string length issue. Created 5 years, 5 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h" 11 #include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <sstream>
14 #include <math.h> 15 #include <math.h>
15 #include <stdlib.h> 16 #include <stdlib.h>
16 17
18 #include "webrtc/base/checks.h"
19 #include "webrtc/base/common.h"
17 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h" 20 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h"
18 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h" 21 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h"
19 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" 22 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
23 #include "webrtc/system_wrappers/interface/field_trial.h"
20 #include "webrtc/system_wrappers/interface/trace.h" 24 #include "webrtc/system_wrappers/interface/trace.h"
21 25
22 namespace webrtc { 26 namespace webrtc {
23 27
24 enum { kOverUsingTimeThreshold = 100 }; 28 const char kAdaptiveThresholdExperiment[] = "WebRTC-AdaptiveBweThreshold";
29 const char kEnabledPrefix[] = "Enabled";
30 const size_t kEnabledPrefixLength = sizeof(kEnabledPrefix) - 1;
31 const size_t kMinExperimentLength = kEnabledPrefixLength + 3;
32
33 const double kMaxAdaptOffsetMs = 15.0;
34 const double kOverUsingTimeThreshold = 10;
35
36 bool AdaptiveThresholdExperimentIsEnabled() {
37 std::string experiment_string =
38 webrtc::field_trial::FindFullName(kAdaptiveThresholdExperiment);
39 if (experiment_string.length() < kMinExperimentLength)
40 return false;
41 return experiment_string.substr(0, kEnabledPrefixLength) == kEnabledPrefix;
42 }
43
44 // Gets thresholds from the experiment name following the format
45 // "WebRTC-AdaptiveBweThreshold/Enabled-0.5,0.002/".
46 bool ReadExperimentConstants(double* k_up, double* k_down) {
47 std::string experiment_string =
48 webrtc::field_trial::FindFullName(kAdaptiveThresholdExperiment);
49 return sscanf(experiment_string.substr(kEnabledPrefixLength + 1).c_str(),
50 "%lf,%lf", k_up, k_down) == 2;
51 }
25 52
26 OveruseDetector::OveruseDetector(const OverUseDetectorOptions& options) 53 OveruseDetector::OveruseDetector(const OverUseDetectorOptions& options)
27 : options_(options), 54 : in_experiment_(AdaptiveThresholdExperimentIsEnabled()),
28 threshold_(options_.initial_threshold), 55 k_up_(0.01),
56 k_down_(0.00018),
57 overusing_time_threshold_(100),
58 options_(options),
59 threshold_(12.5),
60 last_update_ms_(-1),
29 prev_offset_(0.0), 61 prev_offset_(0.0),
30 time_over_using_(-1), 62 time_over_using_(-1),
31 overuse_counter_(0), 63 overuse_counter_(0),
32 hypothesis_(kBwNormal) {} 64 hypothesis_(kBwNormal) {
65 if (in_experiment_)
66 InitializeExperiment();
67 }
33 68
34 OveruseDetector::~OveruseDetector() {} 69 OveruseDetector::~OveruseDetector() {}
35 70
36 BandwidthUsage OveruseDetector::State() const { 71 BandwidthUsage OveruseDetector::State() const {
37 return hypothesis_; 72 return hypothesis_;
38 } 73 }
39 74
40
41 void OveruseDetector::SetRateControlRegion(RateControlRegion region) {
42 switch (region) {
43 case kRcMaxUnknown: {
44 threshold_ = options_.initial_threshold;
45 break;
46 }
47 case kRcAboveMax:
48 case kRcNearMax: {
49 threshold_ = options_.initial_threshold / 2;
50 break;
51 }
52 }
53 }
54
55 BandwidthUsage OveruseDetector::Detect(double offset, 75 BandwidthUsage OveruseDetector::Detect(double offset,
56 double ts_delta, 76 double ts_delta,
57 int num_of_deltas, 77 int num_of_deltas,
58 int64_t now_ms) { 78 int64_t now_ms) {
59 if (num_of_deltas < 2) { 79 if (num_of_deltas < 2) {
60 return kBwNormal; 80 return kBwNormal;
61 } 81 }
62 const double prev_offset = prev_offset_; 82 const double prev_offset = prev_offset_;
63 prev_offset_ = offset; 83 prev_offset_ = offset;
64 const double T = std::min(num_of_deltas, 60) * offset; 84 const double T = std::min(num_of_deltas, 60) * offset;
65 BWE_TEST_LOGGING_PLOT(1, "offset", now_ms, T); 85 BWE_TEST_LOGGING_PLOT(1, "offset", now_ms, T);
66 BWE_TEST_LOGGING_PLOT(1, "threshold", now_ms, threshold_); 86 BWE_TEST_LOGGING_PLOT(1, "threshold", now_ms, threshold_);
67
68 if (T > threshold_) { 87 if (T > threshold_) {
69 if (time_over_using_ == -1) { 88 if (time_over_using_ == -1) {
70 // Initialize the timer. Assume that we've been 89 // Initialize the timer. Assume that we've been
71 // over-using half of the time since the previous 90 // over-using half of the time since the previous
72 // sample. 91 // sample.
73 time_over_using_ = ts_delta / 2; 92 time_over_using_ = ts_delta / 2;
74 } else { 93 } else {
75 // Increment timer 94 // Increment timer
76 time_over_using_ += ts_delta; 95 time_over_using_ += ts_delta;
77 } 96 }
78 overuse_counter_++; 97 overuse_counter_++;
79 if (time_over_using_ > kOverUsingTimeThreshold 98 if (time_over_using_ > overusing_time_threshold_ && overuse_counter_ > 1) {
80 && overuse_counter_ > 1) {
81 if (offset >= prev_offset) { 99 if (offset >= prev_offset) {
82 time_over_using_ = 0; 100 time_over_using_ = 0;
83 overuse_counter_ = 0; 101 overuse_counter_ = 0;
84 hypothesis_ = kBwOverusing; 102 hypothesis_ = kBwOverusing;
85 } 103 }
86 } 104 }
87 } else if (T < -threshold_) { 105 } else if (T < -threshold_) {
88 time_over_using_ = -1; 106 time_over_using_ = -1;
89 overuse_counter_ = 0; 107 overuse_counter_ = 0;
90 hypothesis_ = kBwUnderusing; 108 hypothesis_ = kBwUnderusing;
91 } else { 109 } else {
92 time_over_using_ = -1; 110 time_over_using_ = -1;
93 overuse_counter_ = 0; 111 overuse_counter_ = 0;
94 hypothesis_ = kBwNormal; 112 hypothesis_ = kBwNormal;
95 } 113 }
114
115 UpdateThreshold(T, now_ms);
116
96 return hypothesis_; 117 return hypothesis_;
97 } 118 }
119
120 void OveruseDetector::UpdateThreshold(double modified_offset, int64_t now_ms) {
121 if (!in_experiment_)
122 return;
123
124 if (last_update_ms_ == -1)
125 last_update_ms_ = now_ms;
126
127 if (fabs(modified_offset) > threshold_ + kMaxAdaptOffsetMs) {
128 // Avoid adapting the threshold to big latency spikes, caused e.g.,
129 // by a sudden capacity drop.
130 last_update_ms_ = now_ms;
131 return;
132 }
133
134 const double k = fabs(modified_offset) < threshold_ ? k_down_ : k_up_;
135 threshold_ +=
136 k * (fabs(modified_offset) - threshold_) * (now_ms - last_update_ms_);
137
138 const double kMinThreshold = 6;
139 const double kMaxThreshold = 600;
140 threshold_ = std::min(std::max(threshold_, kMinThreshold), kMaxThreshold);
141
142 last_update_ms_ = now_ms;
143 }
144
145 void OveruseDetector::InitializeExperiment() {
146 DCHECK(in_experiment_);
147 double k_up = 0.0;
148 double k_down = 0.0;
149 overusing_time_threshold_ = kOverUsingTimeThreshold;
150 if (ReadExperimentConstants(&k_up, &k_down)) {
151 k_up_ = k_up;
152 k_down_ = k_down;
153 }
154 }
98 } // namespace webrtc 155 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698