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 10 matching lines...) Expand all Loading... | |
| 239 | 244 |
| 240 DelayBasedBwe::Result DelayBasedBwe::IncomingPacketFeedbackVector( | 245 DelayBasedBwe::Result DelayBasedBwe::IncomingPacketFeedbackVector( |
| 241 const std::vector<PacketInfo>& packet_feedback_vector) { | 246 const std::vector<PacketInfo>& packet_feedback_vector) { |
| 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 bool overusing = false; |
| 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 IncomingPacketInfo(packet_info); |
| 252 if (result.updated) | 257 overusing |= detector_.State() == kBwOverusing; |
| 253 aggregated_result = result; | |
| 254 } | 258 } |
| 255 return aggregated_result; | 259 return MaybeUpdateEstimate(overusing); |
| 256 } | 260 } |
| 257 | 261 |
| 258 DelayBasedBwe::Result DelayBasedBwe::IncomingPacketInfo( | 262 void DelayBasedBwe::IncomingPacketInfo(const PacketInfo& info) { |
| 259 const PacketInfo& info) { | |
| 260 int64_t now_ms = clock_->TimeInMilliseconds(); | 263 int64_t now_ms = clock_->TimeInMilliseconds(); |
| 261 | 264 |
| 262 receiver_incoming_bitrate_.Update(info.arrival_time_ms, info.payload_size); | 265 receiver_incoming_bitrate_.Update(info.arrival_time_ms, info.payload_size); |
| 263 Result result; | 266 Result result; |
| 264 // Reset if the stream has timed out. | 267 // Reset if the stream has timed out. |
| 265 if (last_seen_packet_ms_ == -1 || | 268 if (last_seen_packet_ms_ == -1 || |
| 266 now_ms - last_seen_packet_ms_ > kStreamTimeOutMs) { | 269 now_ms - last_seen_packet_ms_ > kStreamTimeOutMs) { |
| 267 inter_arrival_.reset( | 270 inter_arrival_.reset( |
| 268 new InterArrival((kTimestampGroupLengthMs << kInterArrivalShift) / 1000, | 271 new InterArrival((kTimestampGroupLengthMs << kInterArrivalShift) / 1000, |
| 269 kTimestampToMs, true)); | 272 kTimestampToMs, true)); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 306 info.arrival_time_ms); | 309 info.arrival_time_ms); |
| 307 } else { | 310 } else { |
| 308 kalman_estimator_->Update(t_delta, ts_delta_ms, size_delta, | 311 kalman_estimator_->Update(t_delta, ts_delta_ms, size_delta, |
| 309 detector_.State(), info.arrival_time_ms); | 312 detector_.State(), info.arrival_time_ms); |
| 310 detector_.Detect(kalman_estimator_->offset(), ts_delta_ms, | 313 detector_.Detect(kalman_estimator_->offset(), ts_delta_ms, |
| 311 kalman_estimator_->num_of_deltas(), | 314 kalman_estimator_->num_of_deltas(), |
| 312 info.arrival_time_ms); | 315 info.arrival_time_ms); |
| 313 } | 316 } |
| 314 } | 317 } |
| 315 | 318 |
| 316 int probing_bps = 0; | |
| 317 if (info.probe_cluster_id != PacketInfo::kNotAProbe) { | 319 if (info.probe_cluster_id != PacketInfo::kNotAProbe) { |
| 318 probing_bps = probe_bitrate_estimator_.HandleProbeAndEstimateBitrate(info); | 320 probe_bitrate_estimator_.HandleProbeAndEstimateBitrate(info); |
| 319 } | 321 } |
| 322 } | |
| 323 | |
| 324 DelayBasedBwe::Result DelayBasedBwe::MaybeUpdateEstimate(bool overusing) { | |
| 325 Result result; | |
| 320 rtc::Optional<uint32_t> acked_bitrate_bps = | 326 rtc::Optional<uint32_t> acked_bitrate_bps = |
| 321 receiver_incoming_bitrate_.bitrate_bps(); | 327 receiver_incoming_bitrate_.bitrate_bps(); |
| 328 int64_t now_ms = clock_->TimeInMilliseconds(); | |
| 329 rtc::Optional<int> porbe_bitrate_bps = | |
|
stefan-webrtc
2017/03/28 08:38:28
probe_bitrate_bps
michaelt
2017/03/28 09:59:13
Done.
| |
| 330 probe_bitrate_estimator_.FetchLastEstimatedBitrateBps(); | |
| 322 // Currently overusing the bandwidth. | 331 // Currently overusing the bandwidth. |
| 323 if (detector_.State() == kBwOverusing) { | 332 if (overusing) { |
| 324 if (acked_bitrate_bps && | 333 if (acked_bitrate_bps && |
| 325 rate_control_.TimeToReduceFurther(now_ms, *acked_bitrate_bps)) { | 334 rate_control_.TimeToReduceFurther(now_ms, *acked_bitrate_bps)) { |
| 326 result.updated = | 335 result.updated = |
| 327 UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps, | 336 UpdateEstimate(now_ms, acked_bitrate_bps, overusing, &result); |
| 328 &result.target_bitrate_bps); | |
| 329 } | 337 } |
| 330 } else if (probing_bps > 0) { | 338 } else { |
| 331 // No overuse, but probing measured a bitrate. | 339 if (porbe_bitrate_bps) { |
| 332 rate_control_.SetEstimate(probing_bps, info.arrival_time_ms); | 340 rate_control_.SetEstimate(*porbe_bitrate_bps, now_ms); |
| 333 result.probe = true; | 341 result.probe = true; |
| 342 } | |
| 334 result.updated = | 343 result.updated = |
| 335 UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps, | 344 UpdateEstimate(now_ms, acked_bitrate_bps, overusing, &result); |
| 336 &result.target_bitrate_bps); | |
| 337 } | 345 } |
| 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 } | |
| 350 | |
| 351 return result; | 346 return result; |
| 352 } | 347 } |
| 353 | 348 |
| 354 bool DelayBasedBwe::UpdateEstimate(int64_t arrival_time_ms, | 349 bool DelayBasedBwe::UpdateEstimate(int64_t now_ms, |
| 355 int64_t now_ms, | |
| 356 rtc::Optional<uint32_t> acked_bitrate_bps, | 350 rtc::Optional<uint32_t> acked_bitrate_bps, |
| 357 uint32_t* target_bitrate_bps) { | 351 bool overusing, |
| 352 Result* result) { | |
| 358 // TODO(terelius): RateControlInput::noise_var is deprecated and will be | 353 // TODO(terelius): RateControlInput::noise_var is deprecated and will be |
| 359 // removed. In the meantime, we set it to zero. | 354 // removed. In the meantime, we set it to zero. |
| 360 const RateControlInput input(detector_.State(), acked_bitrate_bps, 0); | 355 const RateControlInput input(overusing ? kBwOverusing : detector_.State(), |
| 356 acked_bitrate_bps, 0); | |
| 361 rate_control_.Update(&input, now_ms); | 357 rate_control_.Update(&input, now_ms); |
| 362 *target_bitrate_bps = rate_control_.UpdateBandwidthEstimate(now_ms); | 358 result->target_bitrate_bps = rate_control_.UpdateBandwidthEstimate(now_ms); |
| 359 BWE_TEST_LOGGING_PLOT(1, "target_bitrate_bps", now_ms, | |
| 360 result->target_bitrate_bps); | |
| 363 return rate_control_.ValidEstimate(); | 361 return rate_control_.ValidEstimate(); |
| 364 } | 362 } |
| 365 | 363 |
| 366 void DelayBasedBwe::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | 364 void DelayBasedBwe::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
| 367 rate_control_.SetRtt(avg_rtt_ms); | 365 rate_control_.SetRtt(avg_rtt_ms); |
| 368 } | 366 } |
| 369 | 367 |
| 370 bool DelayBasedBwe::LatestEstimate(std::vector<uint32_t>* ssrcs, | 368 bool DelayBasedBwe::LatestEstimate(std::vector<uint32_t>* ssrcs, |
| 371 uint32_t* bitrate_bps) const { | 369 uint32_t* bitrate_bps) const { |
| 372 // Currently accessed from both the process thread (see | 370 // Currently accessed from both the process thread (see |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 386 void DelayBasedBwe::SetMinBitrate(int min_bitrate_bps) { | 384 void DelayBasedBwe::SetMinBitrate(int min_bitrate_bps) { |
| 387 // Called from both the configuration thread and the network thread. Shouldn't | 385 // Called from both the configuration thread and the network thread. Shouldn't |
| 388 // be called from the network thread in the future. | 386 // be called from the network thread in the future. |
| 389 rate_control_.SetMinBitrate(min_bitrate_bps); | 387 rate_control_.SetMinBitrate(min_bitrate_bps); |
| 390 } | 388 } |
| 391 | 389 |
| 392 int64_t DelayBasedBwe::GetProbingIntervalMs() const { | 390 int64_t DelayBasedBwe::GetProbingIntervalMs() const { |
| 393 return probing_interval_estimator_.GetIntervalMs(); | 391 return probing_interval_estimator_.GetIntervalMs(); |
| 394 } | 392 } |
| 395 } // namespace webrtc | 393 } // namespace webrtc |
| OLD | NEW |