OLD | NEW |
---|---|
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 enum { kOverUsingTimeThreshold = 10 }; |
28 const char* kAdaptiveThresholdExperiment = "WebRTC-AdaptiveBweThreshold"; | |
29 const char* kEnabledPrefix = "Enabled"; | |
30 const size_t kEnabledPrefixLength = 7; | |
31 const char* kSubExperimentVariation2 = "Var2"; | |
32 const size_t kSubExperimentVariationLength = 4; | |
33 const size_t kMinExperimentLength = | |
34 kEnabledPrefixLength + kSubExperimentVariationLength + 3; | |
35 | |
36 const double kMaxAdaptOffsetMs = 15.0; | |
25 | 37 |
26 OveruseDetector::OveruseDetector(const OverUseDetectorOptions& options) | 38 OveruseDetector::OveruseDetector(const OverUseDetectorOptions& options) |
27 : options_(options), | 39 : options_(options), |
28 threshold_(options_.initial_threshold), | 40 threshold_(12.5), |
41 last_update_ms_(-1), | |
29 prev_offset_(0.0), | 42 prev_offset_(0.0), |
30 time_over_using_(-1), | 43 time_over_using_(-1), |
31 overuse_counter_(0), | 44 overuse_counter_(0), |
32 hypothesis_(kBwNormal) {} | 45 hypothesis_(kBwNormal), |
46 k_up_(0.006469), | |
47 k_down_(0.000175) { | |
Gaetano Carlucci
2015/06/25 11:58:36
We should Update the values of K_up_ and K_down_ a
stefan-webrtc
2015/06/25 12:37:12
Done.
| |
48 double k_up = 0.0; | |
49 double k_down = 0.0; | |
50 if (GetExperimentThresholds(&k_up, &k_down)) { | |
51 k_up_ = k_up; | |
52 k_down_ = k_down; | |
53 } | |
54 } | |
33 | 55 |
34 OveruseDetector::~OveruseDetector() {} | 56 OveruseDetector::~OveruseDetector() {} |
35 | 57 |
36 BandwidthUsage OveruseDetector::State() const { | 58 BandwidthUsage OveruseDetector::State() const { |
37 return hypothesis_; | 59 return hypothesis_; |
38 } | 60 } |
39 | 61 |
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, | 62 BandwidthUsage OveruseDetector::Detect(double offset, |
56 double ts_delta, | 63 double ts_delta, |
57 int num_of_deltas, | 64 int num_of_deltas, |
58 int64_t now_ms) { | 65 int64_t now_ms, |
66 int incoming_bitrate) { | |
Gaetano Carlucci
2015/06/25 11:58:36
remove incoming_bitrate
stefan-webrtc
2015/06/25 12:37:12
Done.
| |
59 if (num_of_deltas < 2) { | 67 if (num_of_deltas < 2) { |
60 return kBwNormal; | 68 return kBwNormal; |
61 } | 69 } |
62 const double prev_offset = prev_offset_; | 70 const double prev_offset = prev_offset_; |
63 prev_offset_ = offset; | 71 prev_offset_ = offset; |
64 const double T = std::min(num_of_deltas, 60) * offset; | 72 const double T = std::min(num_of_deltas, 60) * offset; |
65 BWE_TEST_LOGGING_PLOT(1, "offset", now_ms, T); | 73 BWE_TEST_LOGGING_PLOT(1, "offset", now_ms, T); |
66 BWE_TEST_LOGGING_PLOT(1, "threshold", now_ms, threshold_); | 74 BWE_TEST_LOGGING_PLOT(1, "threshold", now_ms, threshold_); |
67 | |
68 if (T > threshold_) { | 75 if (T > threshold_) { |
69 if (time_over_using_ == -1) { | 76 if (time_over_using_ == -1) { |
70 // Initialize the timer. Assume that we've been | 77 // Initialize the timer. Assume that we've been |
71 // over-using half of the time since the previous | 78 // over-using half of the time since the previous |
72 // sample. | 79 // sample. |
73 time_over_using_ = ts_delta / 2; | 80 time_over_using_ = ts_delta / 2; |
74 } else { | 81 } else { |
75 // Increment timer | 82 // Increment timer |
76 time_over_using_ += ts_delta; | 83 time_over_using_ += ts_delta; |
77 } | 84 } |
78 overuse_counter_++; | 85 overuse_counter_++; |
79 if (time_over_using_ > kOverUsingTimeThreshold | 86 if (time_over_using_ > kOverUsingTimeThreshold |
80 && overuse_counter_ > 1) { | 87 && overuse_counter_ > 1) { |
81 if (offset >= prev_offset) { | 88 if (offset >= prev_offset) { |
82 time_over_using_ = 0; | 89 time_over_using_ = 0; |
83 overuse_counter_ = 0; | 90 overuse_counter_ = 0; |
84 hypothesis_ = kBwOverusing; | 91 hypothesis_ = kBwOverusing; |
85 } | 92 } |
86 } | 93 } |
87 } else if (T < -threshold_) { | 94 } else if (T < -threshold_) { |
88 time_over_using_ = -1; | 95 time_over_using_ = -1; |
89 overuse_counter_ = 0; | 96 overuse_counter_ = 0; |
90 hypothesis_ = kBwUnderusing; | 97 hypothesis_ = kBwUnderusing; |
91 } else { | 98 } else { |
92 time_over_using_ = -1; | 99 time_over_using_ = -1; |
93 overuse_counter_ = 0; | 100 overuse_counter_ = 0; |
94 hypothesis_ = kBwNormal; | 101 hypothesis_ = kBwNormal; |
95 } | 102 } |
103 | |
104 UpdateThreshold(T, now_ms, incoming_bitrate); | |
105 | |
96 return hypothesis_; | 106 return hypothesis_; |
97 } | 107 } |
108 | |
109 void OveruseDetector::UpdateThreshold(double modified_offset, | |
110 int64_t now_ms, | |
111 int incoming_bitrate) { | |
Gaetano Carlucci
2015/06/25 11:58:36
remove incoming_bitrate
stefan-webrtc
2015/06/25 12:37:12
Done.
| |
112 if (!AdaptiveThresholdExperimentIsEnabled()) | |
113 return; | |
114 | |
115 const int kMaxBitrateBps = 2000000; | |
116 const int kMinBitrateBps = 500000; | |
117 incoming_bitrate = | |
118 std::max(std::min(incoming_bitrate, kMaxBitrateBps), kMinBitrateBps); | |
119 | |
Gaetano Carlucci
2015/06/25 11:58:36
remove kMaxBitrateBps and kMinBitrateBps
stefan-webrtc
2015/06/25 12:37:12
Done.
| |
120 if (last_update_ms_ == -1) | |
121 last_update_ms_ = now_ms; | |
122 | |
123 if (ExperimentVariationIsEnabled(kSubExperimentVariation2) && | |
124 fabs(modified_offset) > threshold_ + kMaxAdaptOffsetMs) { | |
125 // Avoid adapting the threshold to big latency spikes, caused e.g., | |
126 // by a sudden capacity drop. | |
127 last_update_ms_ = now_ms; | |
128 return; | |
129 } | |
130 | |
131 double k; | |
132 if (fabs(modified_offset) < threshold_) { | |
133 k = k_down_ + | |
134 k_down_ * static_cast<double>(incoming_bitrate - kMaxBitrateBps / 2) / | |
135 static_cast<double>(kMaxBitrateBps); | |
Gaetano Carlucci
2015/06/25 11:58:36
remove the fine tuning of k_down_
stefan-webrtc
2015/06/25 12:37:12
Done.
| |
136 } else { | |
137 k = k_up_ + | |
138 k_up_ * static_cast<double>(kMaxBitrateBps / 2 - incoming_bitrate) / | |
139 static_cast<double>(kMaxBitrateBps); | |
Gaetano Carlucci
2015/06/25 11:58:36
remove the fine tuning of k_up_
stefan-webrtc
2015/06/25 12:37:12
Done.
| |
140 } | |
141 | |
142 threshold_ += | |
143 k * (fabs(modified_offset) - threshold_) * (now_ms - last_update_ms_); | |
144 | |
145 const double kMinThreshold = 6; | |
146 const double kMaxThreshold = 600; | |
147 threshold_ = std::min(std::max(threshold_, kMinThreshold), kMaxThreshold); | |
148 | |
149 last_update_ms_ = now_ms; | |
150 } | |
151 | |
152 bool OveruseDetector::AdaptiveThresholdExperimentIsEnabled() const { | |
153 std::string experiment_string = | |
154 webrtc::field_trial::FindFullName(kAdaptiveThresholdExperiment); | |
155 if (experiment_string.length() < kMinExperimentLength) | |
156 return false; | |
157 return experiment_string.substr(0, kEnabledPrefixLength) == kEnabledPrefix; | |
158 } | |
159 | |
160 bool OveruseDetector::ExperimentVariationIsEnabled( | |
161 const char* variation) const { | |
162 std::string experiment_string = | |
163 webrtc::field_trial::FindFullName(kAdaptiveThresholdExperiment); | |
164 if (experiment_string.length() < kMinExperimentLength) | |
165 return false; | |
166 return experiment_string.substr(kEnabledPrefixLength, | |
167 kSubExperimentVariationLength) == variation; | |
168 } | |
169 | |
170 // Gets thresholds from the experiment name following the format | |
171 // "WebRTC-AdaptiveBweThreshold/Enabled-0.5,0.002/". | |
172 bool OveruseDetector::GetExperimentThresholds(double* k_up, | |
173 double* k_down) const { | |
174 if (!AdaptiveThresholdExperimentIsEnabled()) | |
175 return false; | |
176 std::string experiment_string = | |
177 webrtc::field_trial::FindFullName(kAdaptiveThresholdExperiment); | |
178 std::stringstream ss(experiment_string.substr( | |
179 kEnabledPrefixLength + kSubExperimentVariationLength + 1)); | |
180 ss >> *k_up; | |
181 if (ss.peek() != ',') | |
182 return false; | |
183 ss.ignore(); | |
184 ss >> *k_down; | |
185 if (ss.rdbuf()->in_avail() > 0) | |
186 return false; | |
187 return true; | |
188 } | |
98 } // namespace webrtc | 189 } // namespace webrtc |
OLD | NEW |