Chromium Code Reviews| 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 21 matching lines...) Expand all Loading... | |
| 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 region. |
| 42 constexpr int kAlrProbingIntervalLimitMs = 5000; | 42 constexpr int64_t kAlrProbingIntervalMinMs = 5000; |
| 43 | |
| 44 // Increase periodic probes intervals up to 2 minutes. | |
| 45 constexpr int64_t kAlrProbingIntervalMaxMs = 120000; | |
| 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_probing_(false), | |
| 61 last_periodic_probing_time_(clock_->TimeInMilliseconds()) {} | |
| 57 | 62 |
| 58 void ProbeController::SetBitrates(int min_bitrate_bps, | 63 void ProbeController::SetBitrates(int min_bitrate_bps, |
| 59 int start_bitrate_bps, | 64 int start_bitrate_bps, |
| 60 int max_bitrate_bps) { | 65 int max_bitrate_bps) { |
| 61 rtc::CritScope cs(&critsect_); | 66 rtc::CritScope cs(&critsect_); |
| 62 | 67 |
| 63 start_bitrate_bps_ = | 68 start_bitrate_bps_ = |
| 64 start_bitrate_bps > 0 ? start_bitrate_bps : min_bitrate_bps; | 69 start_bitrate_bps > 0 ? start_bitrate_bps : min_bitrate_bps; |
| 65 | 70 |
| 66 int old_max_bitrate_bps = max_bitrate_bps_; | 71 int old_max_bitrate_bps = max_bitrate_bps_; |
| 67 max_bitrate_bps_ = max_bitrate_bps; | 72 max_bitrate_bps_ = max_bitrate_bps; |
| 68 | 73 |
| 69 switch (state_) { | 74 switch (state_) { |
| 70 case State::kInit: | 75 case State::kInit: |
| 71 if (network_state_ == kNetworkUp) | 76 if (network_state_ == kNetworkUp) |
| 72 InitiateExponentialProbing(); | 77 InitiateExponentialProbing(); |
| 73 break; | 78 break; |
| 74 | 79 |
| 75 case State::kWaitingForProbingResult: | 80 case State::kWaitingForProbingResult: |
| 76 break; | 81 break; |
| 77 | 82 |
| 78 case State::kProbingComplete: | 83 case State::kProbingComplete: |
| 79 // Initiate probing when |max_bitrate_| was increased mid-call. | 84 // Initiate probing when |max_bitrate_| was increased mid-call. |
| 80 if (estimated_bitrate_bps_ != 0 && | 85 if (estimated_bitrate_bps_ != 0 && |
| 81 estimated_bitrate_bps_ < old_max_bitrate_bps && | 86 estimated_bitrate_bps_ < old_max_bitrate_bps && |
| 82 max_bitrate_bps_ > old_max_bitrate_bps) { | 87 max_bitrate_bps_ > old_max_bitrate_bps) { |
| 83 InitiateProbing({max_bitrate_bps}, kExponentialProbingDisabled); | 88 InitiateProbing(clock_->TimeInMilliseconds(), {max_bitrate_bps}, |
| 89 kExponentialProbingDisabled); | |
| 84 } | 90 } |
| 85 break; | 91 break; |
| 86 } | 92 } |
| 87 } | 93 } |
| 88 | 94 |
| 89 void ProbeController::OnNetworkStateChanged(NetworkState network_state) { | 95 void ProbeController::OnNetworkStateChanged(NetworkState network_state) { |
| 90 rtc::CritScope cs(&critsect_); | 96 rtc::CritScope cs(&critsect_); |
| 91 network_state_ = network_state; | 97 network_state_ = network_state; |
| 92 if (network_state_ == kNetworkUp && state_ == State::kInit) | 98 if (network_state_ == kNetworkUp && state_ == State::kInit) |
| 93 InitiateExponentialProbing(); | 99 InitiateExponentialProbing(); |
| 94 } | 100 } |
| 95 | 101 |
| 96 void ProbeController::InitiateExponentialProbing() { | 102 void ProbeController::InitiateExponentialProbing() { |
| 97 RTC_DCHECK(network_state_ == kNetworkUp); | 103 RTC_DCHECK(network_state_ == kNetworkUp); |
| 98 RTC_DCHECK(state_ == State::kInit); | 104 RTC_DCHECK(state_ == State::kInit); |
| 99 RTC_DCHECK_GT(start_bitrate_bps_, 0); | 105 RTC_DCHECK_GT(start_bitrate_bps_, 0); |
| 100 | 106 |
| 101 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of | 107 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of |
| 102 // 1.2 Mbps to continue probing. | 108 // 1.2 Mbps to continue probing. |
| 103 InitiateProbing({3 * start_bitrate_bps_, 6 * start_bitrate_bps_}, | 109 InitiateProbing(clock_->TimeInMilliseconds(), |
| 110 {3 * start_bitrate_bps_, 6 * start_bitrate_bps_}, | |
| 104 4 * start_bitrate_bps_); | 111 4 * start_bitrate_bps_); |
| 105 } | 112 } |
| 106 | 113 |
| 107 void ProbeController::SetEstimatedBitrate(int bitrate_bps) { | 114 void ProbeController::SetEstimatedBitrate(int bitrate_bps) { |
| 108 rtc::CritScope cs(&critsect_); | 115 rtc::CritScope cs(&critsect_); |
| 116 int64_t now_ms = clock_->TimeInMilliseconds(); | |
| 117 | |
| 109 if (state_ == State::kWaitingForProbingResult) { | 118 if (state_ == State::kWaitingForProbingResult) { |
| 110 if ((clock_->TimeInMilliseconds() - time_last_probing_initiated_ms_) > | 119 if ((now_ms - time_last_probing_initiated_ms_) > |
| 111 kMaxWaitingTimeForProbingResultMs) { | 120 kMaxWaitingTimeForProbingResultMs) { |
| 112 LOG(LS_INFO) << "kWaitingForProbingResult: timeout"; | 121 LOG(LS_INFO) << "kWaitingForProbingResult: timeout"; |
| 113 state_ = State::kProbingComplete; | 122 state_ = State::kProbingComplete; |
| 114 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; | 123 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; |
| 115 } else { | 124 } else { |
| 116 // Continue probing if probing results indicate channel has greater | 125 // Continue probing if probing results indicate channel has greater |
| 117 // capacity. | 126 // capacity. |
| 118 LOG(LS_INFO) << "Measured bitrate: " << bitrate_bps | 127 LOG(LS_INFO) << "Measured bitrate: " << bitrate_bps |
| 119 << " Minimum to probe further: " | 128 << " Minimum to probe further: " |
| 120 << min_bitrate_to_probe_further_bps_; | 129 << min_bitrate_to_probe_further_bps_; |
| 121 if (min_bitrate_to_probe_further_bps_ != kExponentialProbingDisabled && | 130 if (min_bitrate_to_probe_further_bps_ != kExponentialProbingDisabled && |
| 122 bitrate_bps > min_bitrate_to_probe_further_bps_) { | 131 bitrate_bps > min_bitrate_to_probe_further_bps_) { |
| 123 // Double the probing bitrate and expect a minimum of 25% gain to | 132 // Double the probing bitrate and expect a minimum of 25% gain to |
| 124 // continue probing. | 133 // continue probing. |
| 125 InitiateProbing({2 * bitrate_bps}, 1.25 * bitrate_bps); | 134 InitiateProbing(now_ms, {2 * bitrate_bps}, bitrate_bps * 5 / 4); |
| 135 } else { | |
| 136 // Stop exponential probing. | |
| 137 state_ = State::kProbingComplete; | |
| 138 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; | |
| 126 } | 139 } |
| 127 } | 140 } |
| 128 } else { | 141 } |
| 129 // A drop in estimated BW when operating in ALR and not already probing. | 142 |
| 130 // The current response is to initiate a single probe session at the | 143 // Detect a drop in estimated BW when operating in ALR and not already |
| 131 // previous bitrate and immediately use the reported bitrate as the new | 144 // probing. The current response is to initiate a single probe session at the |
| 132 // bitrate. | 145 // previous bitrate and immediately use the reported bitrate as the new |
| 133 // | 146 // bitrate. |
| 134 // If the probe session fails, the assumption is that this drop was a | 147 // |
| 135 // real one from a competing flow or something else on the network and | 148 // If the probe session fails, the assumption is that this drop was a |
| 136 // it ramps up from bitrate_bps. | 149 // real one from a competing flow or something else on the network and |
| 137 if (pacer_->InApplicationLimitedRegion() && | 150 // it ramps up from bitrate_bps. |
| 138 bitrate_bps < 0.5 * estimated_bitrate_bps_) { | 151 if (state_ == State::kProbingComplete && |
| 139 int64_t now_ms = clock_->TimeInMilliseconds(); | 152 pacer_->GetApplicationLimitedRegionStartTime() && |
|
philipel
2016/11/16 14:59:15
I think it's cleaner to keep the InApplicationLimi
Sergey Ulanov
2016/11/21 09:06:03
I don't think keeping InApplicationLimitedRegion()
philipel
2016/11/21 12:05:42
I see what you mean about having both InApplicatio
Sergey Ulanov
2016/11/21 19:28:18
Done.
| |
| 140 if ((now_ms - last_alr_probing_time_) > kAlrProbingIntervalLimitMs) { | 153 bitrate_bps < estimated_bitrate_bps_ / 2 && |
| 141 LOG(LS_INFO) << "Detected big BW drop in ALR, start probe."; | 154 (now_ms - last_alr_probing_time_) > kAlrProbingIntervalMinMs) { |
| 142 // Track how often we probe in response to BW drop in ALR. | 155 LOG(LS_INFO) << "Detected big BW drop in ALR, start probe."; |
| 143 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.AlrProbingIntervalInS", | 156 // Track how often we probe in response to BW drop in ALR. |
| 144 (now_ms - last_alr_probing_time_) / 1000); | 157 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.AlrProbingIntervalInS", |
| 145 InitiateProbing({estimated_bitrate_bps_}, kExponentialProbingDisabled); | 158 (now_ms - last_alr_probing_time_) / 1000); |
| 146 last_alr_probing_time_ = now_ms; | 159 InitiateProbing(now_ms, {estimated_bitrate_bps_}, |
| 147 } | 160 kExponentialProbingDisabled); |
| 148 } | 161 last_alr_probing_time_ = now_ms; |
| 162 | |
| 149 // TODO(isheriff): May want to track when we did ALR probing in order | 163 // TODO(isheriff): May want to track when we did ALR probing in order |
| 150 // to reset |last_alr_probing_time_| if we validate that it was a | 164 // to reset |last_alr_probing_time_| if we validate that it was a |
| 151 // drop due to exogenous event. | 165 // drop due to exogenous event. |
| 152 } | 166 } |
| 167 | |
| 153 estimated_bitrate_bps_ = bitrate_bps; | 168 estimated_bitrate_bps_ = bitrate_bps; |
| 154 } | 169 } |
| 155 | 170 |
| 171 void ProbeController::EnablePeriodicProbing(bool enable) { | |
| 172 rtc::CritScope cs(&critsect_); | |
| 173 enable_periodic_probing_ = enable; | |
| 174 } | |
| 175 | |
| 176 void ProbeController::Process() { | |
| 177 rtc::CritScope cs(&critsect_); | |
| 178 | |
| 179 if (state_ != State::kProbingComplete || !enable_periodic_probing_) | |
| 180 return; | |
| 181 | |
| 182 // Probe bandwidth periodically when in ALR state. | |
| 183 int64_t alr_start_time = pacer_->GetApplicationLimitedRegionStartTime(); | |
| 184 if (alr_start_time > 0) { | |
| 185 int64_t now_ms = clock_->TimeInMilliseconds(); | |
| 186 int64_t time_in_alr_ms = now_ms - alr_start_time; | |
| 187 | |
| 188 // Calculate probing period as half of the time passed since ALR started, | |
| 189 // clamped between min and max values. This results in the interval | |
| 190 // increasing from the minimum exponentially until it reaches the maximum. | |
| 191 // With min and max values set to 5s and 2m the probes are sent at 5s, 10s, | |
| 192 // 20s, 40s, 80s, 160s and every 2 minutes after that. | |
| 193 int alr_probe_period_ms = | |
|
philipel
2016/11/16 14:59:15
Probing is very cheap (but jittery) so I don't thi
Sergey Ulanov
2016/11/21 09:06:03
The idea here was that the longer the sender stays
philipel
2016/11/21 12:05:42
Lets say we have a stable link that does not chang
Sergey Ulanov
2016/11/21 19:28:18
Right, there is a lot of noise in the probes resul
| |
| 194 std::min(std::max(kAlrProbingIntervalMinMs, time_in_alr_ms / 2), | |
| 195 kAlrProbingIntervalMaxMs); | |
| 196 | |
| 197 int time_since_last_probe_ms = | |
|
philipel
2016/11/16 14:59:15
I'm not sure why you added the |now_ms| argument t
Sergey Ulanov
2016/11/21 09:06:03
That was a mistake, fixed that function to use now
| |
| 198 std::min(time_in_alr_ms, now_ms - last_periodic_probing_time_); | |
| 199 if (time_since_last_probe_ms >= alr_probe_period_ms) { | |
| 200 InitiateProbing(now_ms, {estimated_bitrate_bps_ * 2}, | |
| 201 estimated_bitrate_bps_ * 5 / 4); | |
| 202 last_periodic_probing_time_ = now_ms; | |
| 203 } | |
| 204 } | |
| 205 } | |
| 206 | |
| 156 void ProbeController::InitiateProbing( | 207 void ProbeController::InitiateProbing( |
| 208 int64_t now_ms, | |
|
philipel
2016/11/16 14:59:15
Not used?
Sergey Ulanov
2016/11/21 09:06:03
Done.
| |
| 157 std::initializer_list<int> bitrates_to_probe, | 209 std::initializer_list<int> bitrates_to_probe, |
| 158 int min_bitrate_to_probe_further_bps) { | 210 int min_bitrate_to_probe_further_bps) { |
| 159 bool first_cluster = true; | 211 bool first_cluster = true; |
| 160 for (int bitrate : bitrates_to_probe) { | 212 for (int bitrate : bitrates_to_probe) { |
| 161 int max_probe_bitrate_bps = | 213 int max_probe_bitrate_bps = |
| 162 max_bitrate_bps_ > 0 ? max_bitrate_bps_ : kDefaultMaxProbingBitrateBps; | 214 max_bitrate_bps_ > 0 ? max_bitrate_bps_ : kDefaultMaxProbingBitrateBps; |
| 163 bitrate = std::min(bitrate, max_probe_bitrate_bps); | 215 bitrate = std::min(bitrate, max_probe_bitrate_bps); |
| 164 if (first_cluster) { | 216 if (first_cluster) { |
| 165 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster + 1); | 217 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster + 1); |
| 166 first_cluster = false; | 218 first_cluster = false; |
| 167 } else { | 219 } else { |
| 168 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster); | 220 pacer_->CreateProbeCluster(bitrate, kProbeDeltasPerCluster); |
| 169 } | 221 } |
| 170 } | 222 } |
| 171 min_bitrate_to_probe_further_bps_ = min_bitrate_to_probe_further_bps; | 223 min_bitrate_to_probe_further_bps_ = min_bitrate_to_probe_further_bps; |
| 172 time_last_probing_initiated_ms_ = clock_->TimeInMilliseconds(); | 224 time_last_probing_initiated_ms_ = clock_->TimeInMilliseconds(); |
| 173 if (min_bitrate_to_probe_further_bps == kExponentialProbingDisabled) | 225 if (min_bitrate_to_probe_further_bps == kExponentialProbingDisabled) |
| 174 state_ = State::kProbingComplete; | 226 state_ = State::kProbingComplete; |
| 175 else | 227 else |
| 176 state_ = State::kWaitingForProbingResult; | 228 state_ = State::kWaitingForProbingResult; |
| 177 } | 229 } |
| 178 | 230 |
| 179 } // namespace webrtc | 231 } // namespace webrtc |
| OLD | NEW |