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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 | 124 |
125 namespace webrtc { | 125 namespace webrtc { |
126 | 126 |
127 DelayBasedBwe::BitrateEstimator::BitrateEstimator() | 127 DelayBasedBwe::BitrateEstimator::BitrateEstimator() |
128 : sum_(0), | 128 : sum_(0), |
129 current_win_ms_(0), | 129 current_win_ms_(0), |
130 prev_time_ms_(-1), | 130 prev_time_ms_(-1), |
131 bitrate_estimate_(-1.0f), | 131 bitrate_estimate_(-1.0f), |
132 bitrate_estimate_var_(50.0f), | 132 bitrate_estimate_var_(50.0f), |
133 old_estimator_(kBitrateWindowMs, 8000), | 133 old_estimator_(kBitrateWindowMs, 8000), |
134 in_experiment_(BitrateEstimateExperimentIsEnabled()) {} | 134 in_experiment_(BitrateEstimateExperimentIsEnabled()), |
135 last_result_was_valid_(false) {} | |
135 | 136 |
136 void DelayBasedBwe::BitrateEstimator::Update(int64_t now_ms, int bytes) { | 137 void DelayBasedBwe::BitrateEstimator::Update(int64_t now_ms, int bytes) { |
137 if (!in_experiment_) { | 138 if (!in_experiment_) { |
138 old_estimator_.Update(bytes, now_ms); | 139 old_estimator_.Update(bytes, now_ms); |
139 rtc::Optional<uint32_t> rate = old_estimator_.Rate(now_ms); | 140 rtc::Optional<uint32_t> rate = old_estimator_.Rate(now_ms); |
140 bitrate_estimate_ = -1.0f; | 141 bitrate_estimate_ = -1.0f; |
141 if (rate) | 142 if (rate) { |
142 bitrate_estimate_ = *rate / 1000.0f; | 143 bitrate_estimate_ = *rate / 1000.0f; |
144 last_result_was_valid_ = true; | |
terelius
2017/02/07 15:35:28
Please be aware that the "!in_experiment"-path wil
michaelt
2017/02/08 12:05:32
This just e fix for the old bitrate_estimate_. It
| |
145 } else if (last_result_was_valid_) { | |
146 old_estimator_.Reset(); | |
147 last_result_was_valid_ = false; | |
148 } | |
143 return; | 149 return; |
144 } | 150 } |
145 int rate_window_ms = kRateWindowMs; | 151 int rate_window_ms = kRateWindowMs; |
146 // We use a larger window at the beginning to get a more stable sample that | 152 // We use a larger window at the beginning to get a more stable sample that |
147 // we can use to initialize the estimate. | 153 // we can use to initialize the estimate. |
148 if (bitrate_estimate_ < 0.f) | 154 if (bitrate_estimate_ < 0.f) |
149 rate_window_ms = kInitialRateWindowMs; | 155 rate_window_ms = kInitialRateWindowMs; |
150 float bitrate_sample = UpdateWindow(now_ms, bytes, rate_window_ms); | 156 float bitrate_sample = UpdateWindow(now_ms, bytes, rate_window_ms); |
151 if (bitrate_sample < 0.0f) | 157 if (bitrate_sample < 0.0f) |
152 return; | 158 return; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 | 214 |
209 DelayBasedBwe::DelayBasedBwe(Clock* clock) | 215 DelayBasedBwe::DelayBasedBwe(Clock* clock) |
210 : in_trendline_experiment_(TrendlineFilterExperimentIsEnabled()), | 216 : in_trendline_experiment_(TrendlineFilterExperimentIsEnabled()), |
211 in_median_slope_experiment_(MedianSlopeFilterExperimentIsEnabled()), | 217 in_median_slope_experiment_(MedianSlopeFilterExperimentIsEnabled()), |
212 clock_(clock), | 218 clock_(clock), |
213 inter_arrival_(), | 219 inter_arrival_(), |
214 kalman_estimator_(), | 220 kalman_estimator_(), |
215 trendline_estimator_(), | 221 trendline_estimator_(), |
216 detector_(), | 222 detector_(), |
217 receiver_incoming_bitrate_(), | 223 receiver_incoming_bitrate_(), |
218 last_update_ms_(-1), | |
219 last_seen_packet_ms_(-1), | 224 last_seen_packet_ms_(-1), |
220 uma_recorded_(false), | 225 uma_recorded_(false), |
221 trendline_window_size_(kDefaultTrendlineWindowSize), | 226 trendline_window_size_(kDefaultTrendlineWindowSize), |
222 trendline_smoothing_coeff_(kDefaultTrendlineSmoothingCoeff), | 227 trendline_smoothing_coeff_(kDefaultTrendlineSmoothingCoeff), |
223 trendline_threshold_gain_(kDefaultTrendlineThresholdGain), | 228 trendline_threshold_gain_(kDefaultTrendlineThresholdGain), |
224 probing_interval_estimator_(&rate_control_), | 229 probing_interval_estimator_(&rate_control_), |
225 median_slope_window_size_(kDefaultMedianSlopeWindowSize), | 230 median_slope_window_size_(kDefaultMedianSlopeWindowSize), |
226 median_slope_threshold_gain_(kDefaultMedianSlopeThresholdGain) { | 231 median_slope_threshold_gain_(kDefaultMedianSlopeThresholdGain) { |
227 if (in_trendline_experiment_) { | 232 if (in_trendline_experiment_) { |
228 ReadTrendlineFilterExperimentParameters(&trendline_window_size_, | 233 ReadTrendlineFilterExperimentParameters(&trendline_window_size_, |
(...skipping 16 matching lines...) Expand all Loading... | |
245 BweNames::kSendSideTransportSeqNum, | 250 BweNames::kSendSideTransportSeqNum, |
246 BweNames::kBweNamesMax); | 251 BweNames::kBweNamesMax); |
247 uma_recorded_ = true; | 252 uma_recorded_ = true; |
248 } | 253 } |
249 Result aggregated_result; | 254 Result aggregated_result; |
250 for (const auto& packet_info : packet_feedback_vector) { | 255 for (const auto& packet_info : packet_feedback_vector) { |
251 Result result = IncomingPacketInfo(packet_info); | 256 Result result = IncomingPacketInfo(packet_info); |
252 if (result.updated) | 257 if (result.updated) |
253 aggregated_result = result; | 258 aggregated_result = result; |
254 } | 259 } |
260 | |
terelius
2017/02/07 15:35:28
I like the idea of checking for overuse once per R
michaelt
2017/02/08 12:05:32
I hope my impl. change will not influence the beha
terelius
2017/02/08 12:19:52
Yes, it will get the same input and the detector w
| |
261 rtc::Optional<uint32_t> acked_bitrate_bps = | |
262 receiver_incoming_bitrate_.bitrate_bps(); | |
263 int64_t now_ms = clock_->TimeInMilliseconds(); | |
264 // Currently overusing the bandwidth. | |
265 if (detector_.State() == kBwOverusing) { | |
stefan-webrtc
2017/02/07 14:43:13
Given that you have to check the state also in Inc
michaelt
2017/02/07 15:07:07
The idea was to split the Update in two parts.
1.
stefan-webrtc
2017/02/07 15:10:42
Yes, I think that might be a good idea. It however
michaelt
2017/02/07 15:12:56
Ok will try to clean this up :)
| |
266 if (acked_bitrate_bps && | |
267 rate_control_.TimeToReduceFurther(now_ms, *acked_bitrate_bps)) { | |
268 aggregated_result.updated = UpdateEstimate( | |
269 now_ms, acked_bitrate_bps, &aggregated_result.target_bitrate_bps); | |
270 } | |
271 } else { | |
272 if (!aggregated_result.updated) { | |
273 aggregated_result.updated = UpdateEstimate( | |
274 now_ms, acked_bitrate_bps, &aggregated_result.target_bitrate_bps); | |
275 } | |
276 } | |
277 if (aggregated_result.updated) { | |
278 BWE_TEST_LOGGING_PLOT(1, "target_bitrate_bps", now_ms, | |
279 aggregated_result.target_bitrate_bps); | |
280 } | |
255 return aggregated_result; | 281 return aggregated_result; |
256 } | 282 } |
257 | 283 |
258 DelayBasedBwe::Result DelayBasedBwe::IncomingPacketInfo( | 284 DelayBasedBwe::Result DelayBasedBwe::IncomingPacketInfo( |
259 const PacketInfo& info) { | 285 const PacketInfo& info) { |
260 int64_t now_ms = clock_->TimeInMilliseconds(); | 286 int64_t now_ms = clock_->TimeInMilliseconds(); |
261 | 287 |
262 receiver_incoming_bitrate_.Update(info.arrival_time_ms, info.payload_size); | 288 receiver_incoming_bitrate_.Update(info.arrival_time_ms, info.payload_size); |
263 Result result; | 289 Result result; |
264 // Reset if the stream has timed out. | 290 // Reset if the stream has timed out. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 info.arrival_time_ms); | 332 info.arrival_time_ms); |
307 } else { | 333 } else { |
308 kalman_estimator_->Update(t_delta, ts_delta_ms, size_delta, | 334 kalman_estimator_->Update(t_delta, ts_delta_ms, size_delta, |
309 detector_.State(), info.arrival_time_ms); | 335 detector_.State(), info.arrival_time_ms); |
310 detector_.Detect(kalman_estimator_->offset(), ts_delta_ms, | 336 detector_.Detect(kalman_estimator_->offset(), ts_delta_ms, |
311 kalman_estimator_->num_of_deltas(), | 337 kalman_estimator_->num_of_deltas(), |
312 info.arrival_time_ms); | 338 info.arrival_time_ms); |
313 } | 339 } |
314 } | 340 } |
315 | 341 |
316 int probing_bps = 0; | |
317 if (info.probe_cluster_id != PacketInfo::kNotAProbe) { | 342 if (info.probe_cluster_id != PacketInfo::kNotAProbe) { |
318 probing_bps = probe_bitrate_estimator_.HandleProbeAndEstimateBitrate(info); | 343 int probing_bps = |
319 } | 344 probe_bitrate_estimator_.HandleProbeAndEstimateBitrate(info); |
320 rtc::Optional<uint32_t> acked_bitrate_bps = | 345 if (probing_bps > 0) { |
321 receiver_incoming_bitrate_.bitrate_bps(); | 346 // No overuse, but probing measured a bitrate. |
stefan-webrtc
2017/02/07 14:43:13
You have to check for overuse. Maybe you should mo
michaelt
2017/02/08 12:05:32
I used now the target_bitrate_bps to pass the prob
stefan-webrtc
2017/02/08 12:16:03
I don't see the change, did you forgot to upload?
| |
322 // Currently overusing the bandwidth. | 347 rate_control_.SetEstimate(probing_bps, info.arrival_time_ms); |
323 if (detector_.State() == kBwOverusing) { | 348 result.probe = true; |
324 if (acked_bitrate_bps && | |
325 rate_control_.TimeToReduceFurther(now_ms, *acked_bitrate_bps)) { | |
326 result.updated = | 349 result.updated = |
327 UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps, | 350 UpdateEstimate(now_ms, receiver_incoming_bitrate_.bitrate_bps(), |
328 &result.target_bitrate_bps); | 351 &result.target_bitrate_bps); |
329 } | 352 } |
330 } else if (probing_bps > 0) { | |
331 // No overuse, but probing measured a bitrate. | |
332 rate_control_.SetEstimate(probing_bps, info.arrival_time_ms); | |
333 result.probe = true; | |
334 result.updated = | |
335 UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps, | |
336 &result.target_bitrate_bps); | |
337 } | |
338 if (!result.updated && | |
339 (last_update_ms_ == -1 || | |
340 now_ms - last_update_ms_ > rate_control_.GetFeedbackInterval())) { | |
341 result.updated = | |
342 UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps, | |
343 &result.target_bitrate_bps); | |
344 } | |
345 if (result.updated) { | |
346 last_update_ms_ = now_ms; | |
347 BWE_TEST_LOGGING_PLOT(1, "target_bitrate_bps", now_ms, | |
348 result.target_bitrate_bps); | |
349 } | 353 } |
350 | 354 |
351 return result; | 355 return result; |
352 } | 356 } |
353 | 357 |
354 bool DelayBasedBwe::UpdateEstimate(int64_t arrival_time_ms, | 358 bool DelayBasedBwe::UpdateEstimate(int64_t now_ms, |
355 int64_t now_ms, | |
356 rtc::Optional<uint32_t> acked_bitrate_bps, | 359 rtc::Optional<uint32_t> acked_bitrate_bps, |
357 uint32_t* target_bitrate_bps) { | 360 uint32_t* target_bitrate_bps) { |
358 // TODO(terelius): RateControlInput::noise_var is deprecated and will be | 361 // TODO(terelius): RateControlInput::noise_var is deprecated and will be |
359 // removed. In the meantime, we set it to zero. | 362 // removed. In the meantime, we set it to zero. |
360 const RateControlInput input(detector_.State(), acked_bitrate_bps, 0); | 363 const RateControlInput input(detector_.State(), acked_bitrate_bps, 0); |
361 rate_control_.Update(&input, now_ms); | 364 rate_control_.Update(&input, now_ms); |
362 *target_bitrate_bps = rate_control_.UpdateBandwidthEstimate(now_ms); | 365 *target_bitrate_bps = rate_control_.UpdateBandwidthEstimate(now_ms); |
363 return rate_control_.ValidEstimate(); | 366 return rate_control_.ValidEstimate(); |
364 } | 367 } |
365 | 368 |
(...skipping 20 matching lines...) Expand all Loading... | |
386 void DelayBasedBwe::SetMinBitrate(int min_bitrate_bps) { | 389 void DelayBasedBwe::SetMinBitrate(int min_bitrate_bps) { |
387 // Called from both the configuration thread and the network thread. Shouldn't | 390 // Called from both the configuration thread and the network thread. Shouldn't |
388 // be called from the network thread in the future. | 391 // be called from the network thread in the future. |
389 rate_control_.SetMinBitrate(min_bitrate_bps); | 392 rate_control_.SetMinBitrate(min_bitrate_bps); |
390 } | 393 } |
391 | 394 |
392 int64_t DelayBasedBwe::GetProbingIntervalMs() const { | 395 int64_t DelayBasedBwe::GetProbingIntervalMs() const { |
393 return probing_interval_estimator_.GetIntervalMs(); | 396 return probing_interval_estimator_.GetIntervalMs(); |
394 } | 397 } |
395 } // namespace webrtc | 398 } // namespace webrtc |
OLD | NEW |