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

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 a mistake and put overusing time threshold change under the experiment as well. 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/common.h"
17 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h" 19 #include "webrtc/modules/remote_bitrate_estimator/include/bwe_defines.h"
18 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h" 20 #include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h"
19 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" 21 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
22 #include "webrtc/system_wrappers/interface/field_trial.h"
20 #include "webrtc/system_wrappers/interface/trace.h" 23 #include "webrtc/system_wrappers/interface/trace.h"
21 24
22 namespace webrtc { 25 namespace webrtc {
23 26
24 enum { kOverUsingTimeThreshold = 100 }; 27 const char* kAdaptiveThresholdExperiment = "WebRTC-AdaptiveBweThreshold";
28 const char* kEnabledPrefix = "Enabled";
29 const size_t kEnabledPrefixLength = sizeof(kEnabledPrefix) - 1;
30 const size_t kMinExperimentLength = kEnabledPrefixLength + 3;
31
32 const double kMaxAdaptOffsetMs = 15.0;
33 const double kOverUsingTimeThreshold = 10;
34
35 bool AdaptiveThresholdExperimentIsEnabled() {
36 std::string experiment_string =
37 webrtc::field_trial::FindFullName(kAdaptiveThresholdExperiment);
38 if (experiment_string.length() < kMinExperimentLength)
39 return false;
40 return experiment_string.substr(0, kEnabledPrefixLength) == kEnabledPrefix;
41 }
25 42
26 OveruseDetector::OveruseDetector(const OverUseDetectorOptions& options) 43 OveruseDetector::OveruseDetector(const OverUseDetectorOptions& options)
27 : options_(options), 44 : k_up_(0.01),
28 threshold_(options_.initial_threshold), 45 k_down_(0.00018),
46 overusing_time_threshold_(100),
47 in_experiment_(AdaptiveThresholdExperimentIsEnabled()),
48 options_(options),
49 threshold_(12.5),
50 last_update_ms_(-1),
29 prev_offset_(0.0), 51 prev_offset_(0.0),
30 time_over_using_(-1), 52 time_over_using_(-1),
31 overuse_counter_(0), 53 overuse_counter_(0),
32 hypothesis_(kBwNormal) {} 54 hypothesis_(kBwNormal) {
55 InitializeExperiment();
pbos-webrtc 2015/07/06 11:14:23 Only call under in_experiment_?
stefan-webrtc 2015/07/06 12:16:13 Done.
56 }
33 57
34 OveruseDetector::~OveruseDetector() {} 58 OveruseDetector::~OveruseDetector() {}
35 59
36 BandwidthUsage OveruseDetector::State() const { 60 BandwidthUsage OveruseDetector::State() const {
37 return hypothesis_; 61 return hypothesis_;
38 } 62 }
39 63
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, 64 BandwidthUsage OveruseDetector::Detect(double offset,
56 double ts_delta, 65 double ts_delta,
57 int num_of_deltas, 66 int num_of_deltas,
58 int64_t now_ms) { 67 int64_t now_ms) {
59 if (num_of_deltas < 2) { 68 if (num_of_deltas < 2) {
60 return kBwNormal; 69 return kBwNormal;
61 } 70 }
62 const double prev_offset = prev_offset_; 71 const double prev_offset = prev_offset_;
63 prev_offset_ = offset; 72 prev_offset_ = offset;
64 const double T = std::min(num_of_deltas, 60) * offset; 73 const double T = std::min(num_of_deltas, 60) * offset;
65 BWE_TEST_LOGGING_PLOT(1, "offset", now_ms, T); 74 BWE_TEST_LOGGING_PLOT(1, "offset", now_ms, T);
66 BWE_TEST_LOGGING_PLOT(1, "threshold", now_ms, threshold_); 75 BWE_TEST_LOGGING_PLOT(1, "threshold", now_ms, threshold_);
67
68 if (T > threshold_) { 76 if (T > threshold_) {
69 if (time_over_using_ == -1) { 77 if (time_over_using_ == -1) {
70 // Initialize the timer. Assume that we've been 78 // Initialize the timer. Assume that we've been
71 // over-using half of the time since the previous 79 // over-using half of the time since the previous
72 // sample. 80 // sample.
73 time_over_using_ = ts_delta / 2; 81 time_over_using_ = ts_delta / 2;
74 } else { 82 } else {
75 // Increment timer 83 // Increment timer
76 time_over_using_ += ts_delta; 84 time_over_using_ += ts_delta;
77 } 85 }
78 overuse_counter_++; 86 overuse_counter_++;
79 if (time_over_using_ > kOverUsingTimeThreshold 87 if (time_over_using_ > kOverUsingTimeThreshold
80 && overuse_counter_ > 1) { 88 && overuse_counter_ > 1) {
81 if (offset >= prev_offset) { 89 if (offset >= prev_offset) {
82 time_over_using_ = 0; 90 time_over_using_ = 0;
83 overuse_counter_ = 0; 91 overuse_counter_ = 0;
84 hypothesis_ = kBwOverusing; 92 hypothesis_ = kBwOverusing;
85 } 93 }
86 } 94 }
87 } else if (T < -threshold_) { 95 } else if (T < -threshold_) {
88 time_over_using_ = -1; 96 time_over_using_ = -1;
89 overuse_counter_ = 0; 97 overuse_counter_ = 0;
90 hypothesis_ = kBwUnderusing; 98 hypothesis_ = kBwUnderusing;
91 } else { 99 } else {
92 time_over_using_ = -1; 100 time_over_using_ = -1;
93 overuse_counter_ = 0; 101 overuse_counter_ = 0;
94 hypothesis_ = kBwNormal; 102 hypothesis_ = kBwNormal;
95 } 103 }
104
105 UpdateThreshold(T, now_ms);
106
96 return hypothesis_; 107 return hypothesis_;
97 } 108 }
109
110 void OveruseDetector::UpdateThreshold(double modified_offset, int64_t now_ms) {
111 if (!in_experiment_)
112 return;
113
114 if (last_update_ms_ == -1)
115 last_update_ms_ = now_ms;
116
117 if (fabs(modified_offset) > threshold_ + kMaxAdaptOffsetMs) {
118 // Avoid adapting the threshold to big latency spikes, caused e.g.,
119 // by a sudden capacity drop.
120 last_update_ms_ = now_ms;
121 return;
122 }
123
124 const double k = fabs(modified_offset) < threshold_ ? k_down_ : k_up_;
125 threshold_ +=
126 k * (fabs(modified_offset) - threshold_) * (now_ms - last_update_ms_);
127
128 const double kMinThreshold = 6;
129 const double kMaxThreshold = 600;
130 threshold_ = std::min(std::max(threshold_, kMinThreshold), kMaxThreshold);
131
132 last_update_ms_ = now_ms;
133 }
134
135 // Gets thresholds from the experiment name following the format
136 // "WebRTC-AdaptiveBweThreshold/Enabled-0.5,0.002/".
137 void OveruseDetector::InitializeExperiment() {
pbos-webrtc 2015/07/06 11:14:23 DCHECK(in_experiment_);
stefan-webrtc 2015/07/06 12:16:13 Done.
138 if (in_experiment_) {
139 double k_up = 0.0;
140 double k_down = 0.0;
141 overusing_time_threshold_ = kOverUsingTimeThreshold;
142 if (ReadExperimentConstants(&k_up, &k_down)) {
143 k_up_ = k_up;
144 k_down_ = k_down;
145 }
146 }
147 }
148
149 bool OveruseDetector::ReadExperimentConstants(double* k_up,
150 double* k_down) const {
151 std::string experiment_string =
152 webrtc::field_trial::FindFullName(kAdaptiveThresholdExperiment);
153 std::stringstream ss(experiment_string.substr(kEnabledPrefixLength + 1));
154 ss >> *k_up;
155 if (ss.peek() != ',')
156 return false;
157 ss.ignore();
158 ss >> *k_down;
159 if (ss.rdbuf()->in_avail() > 0)
160 return false;
161 return true;
162 }
98 } // namespace webrtc 163 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698