OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 |
(...skipping 20 matching lines...) Expand all Loading... | |
31 | 31 |
32 // Value of |min_bitrate_to_probe_further_bps_| that indicates | 32 // Value of |min_bitrate_to_probe_further_bps_| that indicates |
33 // further probing is disabled. | 33 // further probing is disabled. |
34 constexpr int kExponentialProbingDisabled = 0; | 34 constexpr int kExponentialProbingDisabled = 0; |
35 | 35 |
36 // Default probing bitrate limit. Applied only when the application didn't | 36 // Default probing bitrate limit. Applied only when the application didn't |
37 // specify max bitrate. | 37 // specify max bitrate. |
38 constexpr int kDefaultMaxProbingBitrateBps = 100000000; | 38 constexpr int kDefaultMaxProbingBitrateBps = 100000000; |
39 | 39 |
40 // This is a limit on how often probing can be done when there is a BW | 40 // This is a limit on how often probing can be done when there is a BW |
41 // drop detected in ALR region. | 41 // drop detected in ALR. |
42 constexpr int kAlrProbingIntervalLimitMs = 5000; | 42 constexpr int64_t kAlrProbingIntervalMinMs = 5000; |
43 | |
44 // Interval between probes when ALR periodic probing is enabled. | |
45 constexpr int64_t kAlrPeriodicProbingIntervalMs = 5000; | |
43 | 46 |
44 } // namespace | 47 } // namespace |
45 | 48 |
46 ProbeController::ProbeController(PacedSender* pacer, Clock* clock) | 49 ProbeController::ProbeController(PacedSender* pacer, Clock* clock) |
47 : pacer_(pacer), | 50 : pacer_(pacer), |
48 clock_(clock), | 51 clock_(clock), |
49 network_state_(kNetworkUp), | 52 network_state_(kNetworkUp), |
50 state_(State::kInit), | 53 state_(State::kInit), |
51 min_bitrate_to_probe_further_bps_(kExponentialProbingDisabled), | 54 min_bitrate_to_probe_further_bps_(kExponentialProbingDisabled), |
52 time_last_probing_initiated_ms_(0), | 55 time_last_probing_initiated_ms_(0), |
53 estimated_bitrate_bps_(0), | 56 estimated_bitrate_bps_(0), |
54 start_bitrate_bps_(0), | 57 start_bitrate_bps_(0), |
55 max_bitrate_bps_(0), | 58 max_bitrate_bps_(0), |
56 last_alr_probing_time_(clock_->TimeInMilliseconds()) {} | 59 last_alr_probing_time_(clock_->TimeInMilliseconds()), |
60 enable_periodic_alr_probing_(false) {} | |
57 | 61 |
58 void ProbeController::SetBitrates(int min_bitrate_bps, | 62 void ProbeController::SetBitrates(int min_bitrate_bps, |
59 int start_bitrate_bps, | 63 int start_bitrate_bps, |
60 int max_bitrate_bps) { | 64 int max_bitrate_bps) { |
61 rtc::CritScope cs(&critsect_); | 65 rtc::CritScope cs(&critsect_); |
62 | 66 |
63 if (start_bitrate_bps > 0) { | 67 if (start_bitrate_bps > 0) { |
64 start_bitrate_bps_ = start_bitrate_bps; | 68 start_bitrate_bps_ = start_bitrate_bps; |
65 } else if (start_bitrate_bps_ == 0) { | 69 } else if (start_bitrate_bps_ == 0) { |
66 start_bitrate_bps_ = min_bitrate_bps; | 70 start_bitrate_bps_ = min_bitrate_bps; |
67 } | 71 } |
68 | 72 |
69 int old_max_bitrate_bps = max_bitrate_bps_; | 73 int old_max_bitrate_bps = max_bitrate_bps_; |
70 max_bitrate_bps_ = max_bitrate_bps; | 74 max_bitrate_bps_ = max_bitrate_bps; |
71 | 75 |
72 switch (state_) { | 76 switch (state_) { |
73 case State::kInit: | 77 case State::kInit: |
74 if (network_state_ == kNetworkUp) | 78 if (network_state_ == kNetworkUp) |
75 InitiateExponentialProbing(); | 79 InitiateExponentialProbing(); |
76 break; | 80 break; |
77 | 81 |
78 case State::kWaitingForProbingResult: | 82 case State::kWaitingForProbingResult: |
79 break; | 83 break; |
80 | 84 |
81 case State::kProbingComplete: | 85 case State::kProbingComplete: |
82 // Initiate probing when |max_bitrate_| was increased mid-call. | 86 // Initiate probing when |max_bitrate_| was increased mid-call. |
83 if (estimated_bitrate_bps_ != 0 && | 87 if (estimated_bitrate_bps_ != 0 && |
84 estimated_bitrate_bps_ < old_max_bitrate_bps && | 88 estimated_bitrate_bps_ < old_max_bitrate_bps && |
85 max_bitrate_bps_ > old_max_bitrate_bps) { | 89 max_bitrate_bps_ > old_max_bitrate_bps) { |
86 InitiateProbing({max_bitrate_bps}, kExponentialProbingDisabled); | 90 InitiateProbing(clock_->TimeInMilliseconds(), {max_bitrate_bps}, |
91 kExponentialProbingDisabled); | |
87 } | 92 } |
88 break; | 93 break; |
89 } | 94 } |
90 } | 95 } |
91 | 96 |
92 void ProbeController::OnNetworkStateChanged(NetworkState network_state) { | 97 void ProbeController::OnNetworkStateChanged(NetworkState network_state) { |
93 rtc::CritScope cs(&critsect_); | 98 rtc::CritScope cs(&critsect_); |
94 network_state_ = network_state; | 99 network_state_ = network_state; |
95 if (network_state_ == kNetworkUp && state_ == State::kInit) | 100 if (network_state_ == kNetworkUp && state_ == State::kInit) |
96 InitiateExponentialProbing(); | 101 InitiateExponentialProbing(); |
97 } | 102 } |
98 | 103 |
99 void ProbeController::InitiateExponentialProbing() { | 104 void ProbeController::InitiateExponentialProbing() { |
100 RTC_DCHECK(network_state_ == kNetworkUp); | 105 RTC_DCHECK(network_state_ == kNetworkUp); |
101 RTC_DCHECK(state_ == State::kInit); | 106 RTC_DCHECK(state_ == State::kInit); |
102 RTC_DCHECK_GT(start_bitrate_bps_, 0); | 107 RTC_DCHECK_GT(start_bitrate_bps_, 0); |
103 | 108 |
104 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of | 109 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of |
105 // 1.2 Mbps to continue probing. | 110 // 1.2 Mbps to continue probing. |
106 InitiateProbing({3 * start_bitrate_bps_, 6 * start_bitrate_bps_}, | 111 InitiateProbing(clock_->TimeInMilliseconds(), |
112 {3 * start_bitrate_bps_, 6 * start_bitrate_bps_}, | |
107 4 * start_bitrate_bps_); | 113 4 * start_bitrate_bps_); |
108 } | 114 } |
109 | 115 |
110 void ProbeController::SetEstimatedBitrate(int bitrate_bps) { | 116 void ProbeController::SetEstimatedBitrate(int bitrate_bps) { |
111 rtc::CritScope cs(&critsect_); | 117 rtc::CritScope cs(&critsect_); |
118 int64_t now_ms = clock_->TimeInMilliseconds(); | |
119 | |
112 if (state_ == State::kWaitingForProbingResult) { | 120 if (state_ == State::kWaitingForProbingResult) { |
113 if ((clock_->TimeInMilliseconds() - time_last_probing_initiated_ms_) > | 121 if ((now_ms - time_last_probing_initiated_ms_) > |
114 kMaxWaitingTimeForProbingResultMs) { | 122 kMaxWaitingTimeForProbingResultMs) { |
115 LOG(LS_INFO) << "kWaitingForProbingResult: timeout"; | 123 LOG(LS_INFO) << "kWaitingForProbingResult: timeout"; |
116 state_ = State::kProbingComplete; | 124 state_ = State::kProbingComplete; |
117 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; | 125 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; |
118 } else { | 126 } else { |
119 // Continue probing if probing results indicate channel has greater | 127 // Continue probing if probing results indicate channel has greater |
120 // capacity. | 128 // capacity. |
121 LOG(LS_INFO) << "Measured bitrate: " << bitrate_bps | 129 LOG(LS_INFO) << "Measured bitrate: " << bitrate_bps |
122 << " Minimum to probe further: " | 130 << " Minimum to probe further: " |
123 << min_bitrate_to_probe_further_bps_; | 131 << min_bitrate_to_probe_further_bps_; |
124 if (min_bitrate_to_probe_further_bps_ != kExponentialProbingDisabled && | 132 if (min_bitrate_to_probe_further_bps_ != kExponentialProbingDisabled && |
125 bitrate_bps > min_bitrate_to_probe_further_bps_) { | 133 bitrate_bps > min_bitrate_to_probe_further_bps_) { |
126 // Double the probing bitrate and expect a minimum of 25% gain to | 134 // Double the probing bitrate and expect a minimum of 25% gain to |
127 // continue probing. | 135 // continue probing. |
128 InitiateProbing({2 * bitrate_bps}, 1.25 * bitrate_bps); | 136 InitiateProbing(now_ms, {2 * bitrate_bps}, bitrate_bps * 5 / 4); |
137 } else { | |
138 // Stop exponential probing. | |
139 state_ = State::kProbingComplete; | |
140 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; | |
129 } | 141 } |
130 } | 142 } |
131 } else { | 143 } |
132 // A drop in estimated BW when operating in ALR and not already probing. | 144 |
133 // The current response is to initiate a single probe session at the | 145 // Detect a drop in estimated BW when operating in ALR and not already |
134 // previous bitrate and immediately use the reported bitrate as the new | 146 // probing. The current response is to initiate a single probe session at the |
135 // bitrate. | 147 // previous bitrate and immediately use the reported bitrate as the new |
136 // | 148 // bitrate. |
137 // If the probe session fails, the assumption is that this drop was a | 149 // |
138 // real one from a competing flow or something else on the network and | 150 // If the probe session fails, the assumption is that this drop was a |
139 // it ramps up from bitrate_bps. | 151 // real one from a competing flow or something else on the network and |
140 if (pacer_->InApplicationLimitedRegion() && | 152 // it ramps up from bitrate_bps. |
141 bitrate_bps < 0.5 * estimated_bitrate_bps_) { | 153 if (state_ == State::kProbingComplete && |
142 int64_t now_ms = clock_->TimeInMilliseconds(); | 154 pacer_->GetApplicationLimitedRegionStartTime() && |
143 if ((now_ms - last_alr_probing_time_) > kAlrProbingIntervalLimitMs) { | 155 bitrate_bps < estimated_bitrate_bps_ / 2 && |
144 LOG(LS_INFO) << "Detected big BW drop in ALR, start probe."; | 156 (now_ms - last_alr_probing_time_) > kAlrProbingIntervalMinMs) { |
145 // Track how often we probe in response to BW drop in ALR. | 157 LOG(LS_INFO) << "Detected big BW drop in ALR, start probe."; |
146 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.AlrProbingIntervalInS", | 158 // Track how often we probe in response to BW drop in ALR. |
147 (now_ms - last_alr_probing_time_) / 1000); | 159 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.AlrProbingIntervalInS", |
148 InitiateProbing({estimated_bitrate_bps_}, kExponentialProbingDisabled); | 160 (now_ms - last_alr_probing_time_) / 1000); |
149 last_alr_probing_time_ = now_ms; | 161 InitiateProbing(now_ms, {estimated_bitrate_bps_}, |
150 } | 162 kExponentialProbingDisabled); |
151 } | 163 last_alr_probing_time_ = now_ms; |
164 | |
152 // TODO(isheriff): May want to track when we did ALR probing in order | 165 // TODO(isheriff): May want to track when we did ALR probing in order |
153 // to reset |last_alr_probing_time_| if we validate that it was a | 166 // to reset |last_alr_probing_time_| if we validate that it was a |
154 // drop due to exogenous event. | 167 // drop due to exogenous event. |
155 } | 168 } |
169 | |
156 estimated_bitrate_bps_ = bitrate_bps; | 170 estimated_bitrate_bps_ = bitrate_bps; |
157 } | 171 } |
158 | 172 |
173 void ProbeController::EnablePeriodicAlrProbing(bool enable) { | |
174 rtc::CritScope cs(&critsect_); | |
175 enable_periodic_alr_probing_ = enable; | |
176 } | |
177 | |
178 void ProbeController::Process() { | |
179 rtc::CritScope cs(&critsect_); | |
180 | |
181 if (state_ != State::kProbingComplete || !enable_periodic_alr_probing_) | |
182 return; | |
183 | |
184 // Probe bandwidth periodically when in ALR state. | |
185 rtc::Optional<int64_t> alr_start_time = | |
186 pacer_->GetApplicationLimitedRegionStartTime(); | |
187 if (alr_start_time) { | |
188 int64_t now_ms = clock_->TimeInMilliseconds(); | |
189 int64_t next_probe_time_ms = | |
190 std::max(*alr_start_time, time_last_probing_initiated_ms_) + | |
191 kAlrPeriodicProbingIntervalMs; | |
192 if (now_ms >= next_probe_time_ms) { | |
193 InitiateProbing(now_ms, {estimated_bitrate_bps_ * 2}, | |
194 estimated_bitrate_bps_ * 5 / 4); | |
stefan-webrtc
2016/11/28 13:27:13
Make 5 / 4 a name constant and share on line 136.
Sergey Ulanov
2016/11/28 20:39:00
Done.
| |
195 } | |
196 } | |
197 } | |
198 | |
159 void ProbeController::InitiateProbing( | 199 void ProbeController::InitiateProbing( |
200 int64_t now_ms, | |
160 std::initializer_list<int> bitrates_to_probe, | 201 std::initializer_list<int> bitrates_to_probe, |
161 int min_bitrate_to_probe_further_bps) { | 202 int min_bitrate_to_probe_further_bps) { |
162 bool first_cluster = true; | 203 bool first_cluster = true; |
163 for (int bitrate : bitrates_to_probe) { | 204 for (int bitrate : bitrates_to_probe) { |
164 int max_probe_bitrate_bps = | 205 int max_probe_bitrate_bps = |
165 max_bitrate_bps_ > 0 ? max_bitrate_bps_ : kDefaultMaxProbingBitrateBps; | 206 max_bitrate_bps_ > 0 ? max_bitrate_bps_ : kDefaultMaxProbingBitrateBps; |
166 bitrate = std::min(bitrate, max_probe_bitrate_bps); | 207 bitrate = std::min(bitrate, max_probe_bitrate_bps); |
167 if (first_cluster) { | 208 if (first_cluster) { |
168 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster + 1); | 209 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster + 1); |
169 first_cluster = false; | 210 first_cluster = false; |
170 } else { | 211 } else { |
171 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster); | 212 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster); |
172 } | 213 } |
173 } | 214 } |
174 min_bitrate_to_probe_further_bps_ = min_bitrate_to_probe_further_bps; | 215 min_bitrate_to_probe_further_bps_ = min_bitrate_to_probe_further_bps; |
175 time_last_probing_initiated_ms_ = clock_->TimeInMilliseconds(); | 216 time_last_probing_initiated_ms_ = now_ms; |
176 if (min_bitrate_to_probe_further_bps == kExponentialProbingDisabled) | 217 if (min_bitrate_to_probe_further_bps == kExponentialProbingDisabled) |
177 state_ = State::kProbingComplete; | 218 state_ = State::kProbingComplete; |
178 else | 219 else |
179 state_ = State::kWaitingForProbingResult; | 220 state_ = State::kWaitingForProbingResult; |
180 } | 221 } |
181 | 222 |
182 } // namespace webrtc | 223 } // namespace webrtc |
OLD | NEW |