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 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; | |
| 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 13 matching lines...) Expand all Loading... | |
| 242 RTC_DCHECK(network_thread_.CalledOnValidThread()); | 247 RTC_DCHECK(network_thread_.CalledOnValidThread()); |
| 243 if (!uma_recorded_) { | 248 if (!uma_recorded_) { |
| 244 RTC_HISTOGRAM_ENUMERATION(kBweTypeHistogram, | 249 RTC_HISTOGRAM_ENUMERATION(kBweTypeHistogram, |
| 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.probe) { |
| 253 aggregated_result = result; | 258 aggregated_result.probe = true; |
| 259 aggregated_result.target_bitrate_bps = result.target_bitrate_bps; | |
| 260 } | |
| 254 } | 261 } |
| 262 MaybeUpdateEstimate(&aggregated_result); | |
|
terelius
2017/02/08 12:44:45
Yes, I think we should run some tests and/or monit
michaelt
2017/02/08 12:57:11
I'm a bit afraid that if we move the function in t
terelius
2017/02/21 13:51:48
Note that the current version of the code essentia
michaelt
2017/02/21 14:52:43
To me, it is cleaner when we feed the overused def
terelius
2017/02/21 15:10:09
I agree it is cleaner, but the rest of the code is
stefan-webrtc
2017/02/21 15:14:08
I don't think we should run a finch experiment sin
michaelt
2017/02/21 15:27:56
Sounds ok to me.
michaelt
2017/02/22 09:40:48
Done.
| |
| 255 return aggregated_result; | 263 return aggregated_result; |
| 256 } | 264 } |
| 257 | 265 |
| 258 DelayBasedBwe::Result DelayBasedBwe::IncomingPacketInfo( | 266 DelayBasedBwe::Result DelayBasedBwe::IncomingPacketInfo( |
| 259 const PacketInfo& info) { | 267 const PacketInfo& info) { |
| 260 int64_t now_ms = clock_->TimeInMilliseconds(); | 268 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 261 | 269 |
| 262 receiver_incoming_bitrate_.Update(info.arrival_time_ms, info.payload_size); | 270 receiver_incoming_bitrate_.Update(info.arrival_time_ms, info.payload_size); |
| 263 Result result; | 271 Result result; |
| 264 // Reset if the stream has timed out. | 272 // 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); | 314 info.arrival_time_ms); |
| 307 } else { | 315 } else { |
| 308 kalman_estimator_->Update(t_delta, ts_delta_ms, size_delta, | 316 kalman_estimator_->Update(t_delta, ts_delta_ms, size_delta, |
| 309 detector_.State(), info.arrival_time_ms); | 317 detector_.State(), info.arrival_time_ms); |
| 310 detector_.Detect(kalman_estimator_->offset(), ts_delta_ms, | 318 detector_.Detect(kalman_estimator_->offset(), ts_delta_ms, |
| 311 kalman_estimator_->num_of_deltas(), | 319 kalman_estimator_->num_of_deltas(), |
| 312 info.arrival_time_ms); | 320 info.arrival_time_ms); |
| 313 } | 321 } |
| 314 } | 322 } |
| 315 | 323 |
| 316 int probing_bps = 0; | |
| 317 if (info.probe_cluster_id != PacketInfo::kNotAProbe) { | 324 if (info.probe_cluster_id != PacketInfo::kNotAProbe) { |
| 318 probing_bps = probe_bitrate_estimator_.HandleProbeAndEstimateBitrate(info); | 325 int probing_bps = |
| 319 } | 326 probe_bitrate_estimator_.HandleProbeAndEstimateBitrate(info); |
| 320 rtc::Optional<uint32_t> acked_bitrate_bps = | 327 if (probing_bps > 0) { |
| 321 receiver_incoming_bitrate_.bitrate_bps(); | 328 result.target_bitrate_bps = probing_bps; |
| 322 // Currently overusing the bandwidth. | 329 result.probe = true; |
| 323 if (detector_.State() == kBwOverusing) { | |
| 324 if (acked_bitrate_bps && | |
| 325 rate_control_.TimeToReduceFurther(now_ms, *acked_bitrate_bps)) { | |
| 326 result.updated = | |
| 327 UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps, | |
| 328 &result.target_bitrate_bps); | |
| 329 } | 330 } |
| 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 } | 331 } |
| 350 | 332 |
| 351 return result; | 333 return result; |
| 352 } | 334 } |
| 353 | 335 |
| 354 bool DelayBasedBwe::UpdateEstimate(int64_t arrival_time_ms, | 336 void DelayBasedBwe::MaybeUpdateEstimate(Result* result) { |
| 355 int64_t now_ms, | 337 RTC_DCHECK(result); |
| 338 rtc::Optional<uint32_t> acked_bitrate_bps = | |
| 339 receiver_incoming_bitrate_.bitrate_bps(); | |
| 340 int64_t now_ms = clock_->TimeInMilliseconds(); | |
| 341 // Currently overusing the bandwidth. | |
| 342 if (detector_.State() == kBwOverusing) { | |
| 343 if (acked_bitrate_bps && | |
| 344 rate_control_.TimeToReduceFurther(now_ms, *acked_bitrate_bps)) { | |
| 345 result->updated = UpdateEstimate(now_ms, acked_bitrate_bps, | |
| 346 &result->target_bitrate_bps); | |
| 347 } | |
| 348 } else { | |
| 349 if (result->probe) { | |
| 350 rate_control_.SetEstimate(result->target_bitrate_bps, now_ms); | |
| 351 } | |
| 352 result->updated = | |
| 353 UpdateEstimate(now_ms, acked_bitrate_bps, &result->target_bitrate_bps); | |
| 354 } | |
| 355 } | |
| 356 | |
| 357 bool DelayBasedBwe::UpdateEstimate(int64_t now_ms, | |
| 356 rtc::Optional<uint32_t> acked_bitrate_bps, | 358 rtc::Optional<uint32_t> acked_bitrate_bps, |
| 357 uint32_t* target_bitrate_bps) { | 359 uint32_t* target_bitrate_bps) { |
| 358 // TODO(terelius): RateControlInput::noise_var is deprecated and will be | 360 // TODO(terelius): RateControlInput::noise_var is deprecated and will be |
| 359 // removed. In the meantime, we set it to zero. | 361 // removed. In the meantime, we set it to zero. |
| 360 const RateControlInput input(detector_.State(), acked_bitrate_bps, 0); | 362 const RateControlInput input(detector_.State(), acked_bitrate_bps, 0); |
| 361 rate_control_.Update(&input, now_ms); | 363 rate_control_.Update(&input, now_ms); |
| 362 *target_bitrate_bps = rate_control_.UpdateBandwidthEstimate(now_ms); | 364 *target_bitrate_bps = rate_control_.UpdateBandwidthEstimate(now_ms); |
| 365 BWE_TEST_LOGGING_PLOT(1, "target_bitrate_bps", now_ms, *target_bitrate_bps); | |
| 363 return rate_control_.ValidEstimate(); | 366 return rate_control_.ValidEstimate(); |
| 364 } | 367 } |
| 365 | 368 |
| 366 void DelayBasedBwe::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | 369 void DelayBasedBwe::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
| 367 rate_control_.SetRtt(avg_rtt_ms); | 370 rate_control_.SetRtt(avg_rtt_ms); |
| 368 } | 371 } |
| 369 | 372 |
| 370 bool DelayBasedBwe::LatestEstimate(std::vector<uint32_t>* ssrcs, | 373 bool DelayBasedBwe::LatestEstimate(std::vector<uint32_t>* ssrcs, |
| 371 uint32_t* bitrate_bps) const { | 374 uint32_t* bitrate_bps) const { |
| 372 // Currently accessed from both the process thread (see | 375 // Currently accessed from both the process thread (see |
| (...skipping 13 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 |