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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 : pacer_(pacer), | 51 : pacer_(pacer), |
52 clock_(clock), | 52 clock_(clock), |
53 network_state_(kNetworkUp), | 53 network_state_(kNetworkUp), |
54 state_(State::kInit), | 54 state_(State::kInit), |
55 min_bitrate_to_probe_further_bps_(kExponentialProbingDisabled), | 55 min_bitrate_to_probe_further_bps_(kExponentialProbingDisabled), |
56 time_last_probing_initiated_ms_(0), | 56 time_last_probing_initiated_ms_(0), |
57 estimated_bitrate_bps_(0), | 57 estimated_bitrate_bps_(0), |
58 start_bitrate_bps_(0), | 58 start_bitrate_bps_(0), |
59 max_bitrate_bps_(0), | 59 max_bitrate_bps_(0), |
60 last_alr_probing_time_(clock_->TimeInMilliseconds()), | 60 last_alr_probing_time_(clock_->TimeInMilliseconds()), |
61 enable_periodic_alr_probing_(false) {} | 61 enable_periodic_alr_probing_(false), |
62 mid_call_probing_waiting_for_result_(false) {} | |
62 | 63 |
63 void ProbeController::SetBitrates(int64_t min_bitrate_bps, | 64 void ProbeController::SetBitrates(int64_t min_bitrate_bps, |
64 int64_t start_bitrate_bps, | 65 int64_t start_bitrate_bps, |
65 int64_t max_bitrate_bps) { | 66 int64_t max_bitrate_bps) { |
66 rtc::CritScope cs(&critsect_); | 67 rtc::CritScope cs(&critsect_); |
67 | 68 |
68 if (start_bitrate_bps > 0) { | 69 if (start_bitrate_bps > 0) { |
69 start_bitrate_bps_ = start_bitrate_bps; | 70 start_bitrate_bps_ = start_bitrate_bps; |
70 } else if (start_bitrate_bps_ == 0) { | 71 } else if (start_bitrate_bps_ == 0) { |
71 start_bitrate_bps_ = min_bitrate_bps; | 72 start_bitrate_bps_ = min_bitrate_bps; |
72 } | 73 } |
73 | 74 |
74 int64_t old_max_bitrate_bps = max_bitrate_bps_; | 75 int64_t old_max_bitrate_bps = max_bitrate_bps_; |
75 max_bitrate_bps_ = max_bitrate_bps; | 76 max_bitrate_bps_ = max_bitrate_bps; |
76 | 77 |
77 switch (state_) { | 78 switch (state_) { |
78 case State::kInit: | 79 case State::kInit: |
79 if (network_state_ == kNetworkUp) | 80 if (network_state_ == kNetworkUp) |
80 InitiateExponentialProbing(); | 81 InitiateExponentialProbing(); |
81 break; | 82 break; |
82 | 83 |
83 case State::kWaitingForProbingResult: | 84 case State::kWaitingForProbingResult: |
84 break; | 85 break; |
85 | 86 |
86 case State::kProbingComplete: | 87 case State::kProbingComplete: |
87 // Initiate probing when |max_bitrate_| was increased mid-call. | 88 // Initiate probing when |max_bitrate_| was increased mid-call. |
88 if (estimated_bitrate_bps_ != kExponentialProbingDisabled && | 89 if (estimated_bitrate_bps_ != kExponentialProbingDisabled && |
89 estimated_bitrate_bps_ < old_max_bitrate_bps && | 90 estimated_bitrate_bps_ < old_max_bitrate_bps && |
90 max_bitrate_bps_ > old_max_bitrate_bps) { | 91 max_bitrate_bps_ > old_max_bitrate_bps) { |
92 // The assumption is that if we jump more than 20% in the bandwidth | |
93 // estimate or if the bandwidth estimate is within 90% of the new | |
94 // max bitrate then the probing attempt was successful. | |
terelius
2017/01/16 13:48:01
I'd like to unify this class with the ProbeBitrate
philipel
2017/01/16 13:56:20
I agree that we could change the structure of the
| |
95 mid_call_probing_succcess_threshold_ = | |
96 std::min(estimated_bitrate_bps_ * 1.2, max_bitrate_bps_ * 0.9); | |
97 mid_call_probing_waiting_for_result_ = true; | |
98 mid_call_probing_bitrate_bps_ = max_bitrate_bps_; | |
99 | |
100 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.MidCallProbing.Initiated", | |
101 max_bitrate_bps_ / 1000); | |
102 | |
91 InitiateProbing(clock_->TimeInMilliseconds(), {max_bitrate_bps}, false); | 103 InitiateProbing(clock_->TimeInMilliseconds(), {max_bitrate_bps}, false); |
92 } | 104 } |
93 break; | 105 break; |
94 } | 106 } |
95 } | 107 } |
96 | 108 |
97 void ProbeController::OnNetworkStateChanged(NetworkState network_state) { | 109 void ProbeController::OnNetworkStateChanged(NetworkState network_state) { |
98 rtc::CritScope cs(&critsect_); | 110 rtc::CritScope cs(&critsect_); |
99 network_state_ = network_state; | 111 network_state_ = network_state; |
100 if (network_state_ == kNetworkUp && state_ == State::kInit) | 112 if (network_state_ == kNetworkUp && state_ == State::kInit) |
101 InitiateExponentialProbing(); | 113 InitiateExponentialProbing(); |
102 } | 114 } |
103 | 115 |
104 void ProbeController::InitiateExponentialProbing() { | 116 void ProbeController::InitiateExponentialProbing() { |
105 RTC_DCHECK(network_state_ == kNetworkUp); | 117 RTC_DCHECK(network_state_ == kNetworkUp); |
106 RTC_DCHECK(state_ == State::kInit); | 118 RTC_DCHECK(state_ == State::kInit); |
107 RTC_DCHECK_GT(start_bitrate_bps_, 0); | 119 RTC_DCHECK_GT(start_bitrate_bps_, 0); |
108 | 120 |
109 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of | 121 // When probing at 1.8 Mbps ( 6x 300), this represents a threshold of |
110 // 1.2 Mbps to continue probing. | 122 // 1.2 Mbps to continue probing. |
111 InitiateProbing(clock_->TimeInMilliseconds(), | 123 InitiateProbing(clock_->TimeInMilliseconds(), |
112 {3 * start_bitrate_bps_, 6 * start_bitrate_bps_}, true); | 124 {3 * start_bitrate_bps_, 6 * start_bitrate_bps_}, true); |
113 } | 125 } |
114 | 126 |
115 void ProbeController::SetEstimatedBitrate(int64_t bitrate_bps) { | 127 void ProbeController::SetEstimatedBitrate(int64_t bitrate_bps) { |
116 rtc::CritScope cs(&critsect_); | 128 rtc::CritScope cs(&critsect_); |
117 int64_t now_ms = clock_->TimeInMilliseconds(); | 129 int64_t now_ms = clock_->TimeInMilliseconds(); |
118 | 130 |
131 if (mid_call_probing_waiting_for_result_ && | |
132 bitrate_bps >= mid_call_probing_succcess_threshold_) { | |
133 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.MidCallProbing.Success", | |
134 mid_call_probing_bitrate_bps_ / 1000); | |
135 RTC_HISTOGRAM_COUNTS_10000("WebRTC.BWE.MidCallProbing.ProbedKbps", | |
136 bitrate_bps / 1000); | |
137 mid_call_probing_waiting_for_result_ = false; | |
138 } | |
139 | |
119 if (state_ == State::kWaitingForProbingResult) { | 140 if (state_ == State::kWaitingForProbingResult) { |
120 // Continue probing if probing results indicate channel has greater | 141 // Continue probing if probing results indicate channel has greater |
121 // capacity. | 142 // capacity. |
122 LOG(LS_INFO) << "Measured bitrate: " << bitrate_bps | 143 LOG(LS_INFO) << "Measured bitrate: " << bitrate_bps |
123 << " Minimum to probe further: " | 144 << " Minimum to probe further: " |
124 << min_bitrate_to_probe_further_bps_; | 145 << min_bitrate_to_probe_further_bps_; |
146 | |
125 if (min_bitrate_to_probe_further_bps_ != kExponentialProbingDisabled && | 147 if (min_bitrate_to_probe_further_bps_ != kExponentialProbingDisabled && |
126 bitrate_bps > min_bitrate_to_probe_further_bps_) { | 148 bitrate_bps > min_bitrate_to_probe_further_bps_) { |
127 // Double the probing bitrate. | 149 // Double the probing bitrate. |
128 InitiateProbing(now_ms, {2 * bitrate_bps}, true); | 150 InitiateProbing(now_ms, {2 * bitrate_bps}, true); |
129 } | 151 } |
130 } | 152 } |
131 | 153 |
132 // Detect a drop in estimated BW when operating in ALR and not already | 154 // Detect a drop in estimated BW when operating in ALR and not already |
133 // probing. The current response is to initiate a single probe session at the | 155 // probing. The current response is to initiate a single probe session at the |
134 // previous bitrate and immediately use the reported bitrate as the new | 156 // previous bitrate and immediately use the reported bitrate as the new |
(...skipping 24 matching lines...) Expand all Loading... | |
159 void ProbeController::EnablePeriodicAlrProbing(bool enable) { | 181 void ProbeController::EnablePeriodicAlrProbing(bool enable) { |
160 rtc::CritScope cs(&critsect_); | 182 rtc::CritScope cs(&critsect_); |
161 enable_periodic_alr_probing_ = enable; | 183 enable_periodic_alr_probing_ = enable; |
162 } | 184 } |
163 | 185 |
164 void ProbeController::Process() { | 186 void ProbeController::Process() { |
165 rtc::CritScope cs(&critsect_); | 187 rtc::CritScope cs(&critsect_); |
166 | 188 |
167 int64_t now_ms = clock_->TimeInMilliseconds(); | 189 int64_t now_ms = clock_->TimeInMilliseconds(); |
168 | 190 |
169 if (state_ == State::kWaitingForProbingResult && | 191 if (now_ms - time_last_probing_initiated_ms_ > |
170 (now_ms - time_last_probing_initiated_ms_) > | 192 kMaxWaitingTimeForProbingResultMs) { |
171 kMaxWaitingTimeForProbingResultMs) { | 193 mid_call_probing_waiting_for_result_ = false; |
172 LOG(LS_INFO) << "kWaitingForProbingResult: timeout"; | 194 |
173 state_ = State::kProbingComplete; | 195 if (state_ == State::kWaitingForProbingResult) { |
terelius
2017/01/16 13:48:01
Can you be in mid_call_probing_waiting_for_result_
philipel
2017/01/16 13:56:20
The only time we are in State::kWaitingForProbingR
terelius
2017/01/16 14:07:43
Acknowledged.
| |
174 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; | 196 LOG(LS_INFO) << "kWaitingForProbingResult: timeout"; |
197 state_ = State::kProbingComplete; | |
198 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; | |
199 } | |
175 } | 200 } |
176 | 201 |
177 if (state_ != State::kProbingComplete || !enable_periodic_alr_probing_) | 202 if (state_ != State::kProbingComplete || !enable_periodic_alr_probing_) |
178 return; | 203 return; |
179 | 204 |
180 // Probe bandwidth periodically when in ALR state. | 205 // Probe bandwidth periodically when in ALR state. |
181 rtc::Optional<int64_t> alr_start_time = | 206 rtc::Optional<int64_t> alr_start_time = |
182 pacer_->GetApplicationLimitedRegionStartTime(); | 207 pacer_->GetApplicationLimitedRegionStartTime(); |
183 if (alr_start_time) { | 208 if (alr_start_time) { |
184 int64_t next_probe_time_ms = | 209 int64_t next_probe_time_ms = |
(...skipping 23 matching lines...) Expand all Loading... | |
208 state_ = State::kWaitingForProbingResult; | 233 state_ = State::kWaitingForProbingResult; |
209 min_bitrate_to_probe_further_bps_ = | 234 min_bitrate_to_probe_further_bps_ = |
210 (*(bitrates_to_probe.end() - 1)) * kRepeatedProbeMinPercentage / 100; | 235 (*(bitrates_to_probe.end() - 1)) * kRepeatedProbeMinPercentage / 100; |
211 } else { | 236 } else { |
212 state_ = State::kProbingComplete; | 237 state_ = State::kProbingComplete; |
213 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; | 238 min_bitrate_to_probe_further_bps_ = kExponentialProbingDisabled; |
214 } | 239 } |
215 } | 240 } |
216 | 241 |
217 } // namespace webrtc | 242 } // namespace webrtc |
OLD | NEW |