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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 RTC_CHECK_GT(*window_size, 1) << "Need at least 2 points to fit a line."; | 115 RTC_CHECK_GT(*window_size, 1) << "Need at least 2 points to fit a line."; |
| 116 RTC_CHECK_GT(*threshold_gain, 0) << "Threshold gain needs to be positive."; | 116 RTC_CHECK_GT(*threshold_gain, 0) << "Threshold gain needs to be positive."; |
| 117 return true; | 117 return true; |
| 118 } | 118 } |
| 119 LOG(LS_WARNING) << "Failed to parse parameters for BweMedianSlopeFilter " | 119 LOG(LS_WARNING) << "Failed to parse parameters for BweMedianSlopeFilter " |
| 120 "experiment from field trial string. Using default."; | 120 "experiment from field trial string. Using default."; |
| 121 *window_size = kDefaultMedianSlopeWindowSize; | 121 *window_size = kDefaultMedianSlopeWindowSize; |
| 122 *threshold_gain = kDefaultMedianSlopeThresholdGain; | 122 *threshold_gain = kDefaultMedianSlopeThresholdGain; |
| 123 return false; | 123 return false; |
| 124 } | 124 } |
| 125 | |
| 126 class PacketFeedbackComparator { | |
| 127 public: | |
| 128 inline bool operator()(const webrtc::PacketFeedback& lhs, | |
| 129 const webrtc::PacketFeedback& rhs) { | |
| 130 if (lhs.arrival_time_ms != rhs.arrival_time_ms) | |
| 131 return lhs.arrival_time_ms < rhs.arrival_time_ms; | |
| 132 if (lhs.send_time_ms != rhs.send_time_ms) | |
| 133 return lhs.send_time_ms < rhs.send_time_ms; | |
| 134 return lhs.sequence_number < rhs.sequence_number; | |
| 135 } | |
| 136 }; | |
| 125 } // namespace | 137 } // namespace |
| 126 | 138 |
| 127 namespace webrtc { | 139 namespace webrtc { |
| 128 | 140 |
| 129 DelayBasedBwe::BitrateEstimator::BitrateEstimator() | 141 DelayBasedBwe::BitrateEstimator::BitrateEstimator() |
| 130 : sum_(0), | 142 : sum_(0), |
| 131 current_win_ms_(0), | 143 current_win_ms_(0), |
| 132 prev_time_ms_(-1), | 144 prev_time_ms_(-1), |
| 133 bitrate_estimate_(-1.0f), | 145 bitrate_estimate_(-1.0f), |
| 134 bitrate_estimate_var_(50.0f), | 146 bitrate_estimate_var_(50.0f), |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 if (!in_trendline_experiment_ && !in_median_slope_experiment_) { | 260 if (!in_trendline_experiment_ && !in_median_slope_experiment_) { |
| 249 LOG(LS_INFO) << "No overuse experiment enabled. Using Kalman filter."; | 261 LOG(LS_INFO) << "No overuse experiment enabled. Using Kalman filter."; |
| 250 } | 262 } |
| 251 | 263 |
| 252 network_thread_.DetachFromThread(); | 264 network_thread_.DetachFromThread(); |
| 253 } | 265 } |
| 254 | 266 |
| 255 DelayBasedBwe::Result DelayBasedBwe::IncomingPacketFeedbackVector( | 267 DelayBasedBwe::Result DelayBasedBwe::IncomingPacketFeedbackVector( |
| 256 const std::vector<PacketFeedback>& packet_feedback_vector) { | 268 const std::vector<PacketFeedback>& packet_feedback_vector) { |
| 257 RTC_DCHECK(network_thread_.CalledOnValidThread()); | 269 RTC_DCHECK(network_thread_.CalledOnValidThread()); |
| 270 | |
| 271 std::vector<PacketFeedback> sorted_packet_feedback_vector; | |
| 272 SortPacketFeedbackVector(packet_feedback_vector, | |
| 273 &sorted_packet_feedback_vector); | |
| 274 | |
| 258 if (!uma_recorded_) { | 275 if (!uma_recorded_) { |
| 259 RTC_HISTOGRAM_ENUMERATION(kBweTypeHistogram, | 276 RTC_HISTOGRAM_ENUMERATION(kBweTypeHistogram, |
| 260 BweNames::kSendSideTransportSeqNum, | 277 BweNames::kSendSideTransportSeqNum, |
| 261 BweNames::kBweNamesMax); | 278 BweNames::kBweNamesMax); |
| 262 uma_recorded_ = true; | 279 uma_recorded_ = true; |
| 263 } | 280 } |
| 264 Result aggregated_result; | 281 Result aggregated_result; |
| 265 bool delayed_feedback = true; | 282 bool delayed_feedback = true; |
| 266 for (const auto& packet_feedback : packet_feedback_vector) { | 283 for (const auto& packet_feedback : sorted_packet_feedback_vector) { |
| 267 if (packet_feedback.send_time_ms < 0) | 284 if (packet_feedback.send_time_ms < 0) |
| 268 continue; | 285 continue; |
| 269 delayed_feedback = false; | 286 delayed_feedback = false; |
| 270 Result result = IncomingPacketFeedback(packet_feedback); | 287 Result result = IncomingPacketFeedback(packet_feedback); |
| 271 if (result.updated) | 288 if (result.updated) |
| 272 aggregated_result = result; | 289 aggregated_result = result; |
| 273 } | 290 } |
| 274 if (delayed_feedback) { | 291 if (delayed_feedback) { |
| 275 ++consecutive_delayed_feedbacks_; | 292 ++consecutive_delayed_feedbacks_; |
| 276 } else { | 293 } else { |
| 277 consecutive_delayed_feedbacks_ = 0; | 294 consecutive_delayed_feedbacks_ = 0; |
| 278 } | 295 } |
| 279 if (consecutive_delayed_feedbacks_ >= kMaxConsecutiveFailedLookups) { | 296 if (consecutive_delayed_feedbacks_ >= kMaxConsecutiveFailedLookups) { |
| 280 aggregated_result = | 297 aggregated_result = OnLongFeedbackDelay( |
| 281 OnLongFeedbackDelay(packet_feedback_vector.back().arrival_time_ms); | 298 sorted_packet_feedback_vector.back().arrival_time_ms); |
| 282 consecutive_delayed_feedbacks_ = 0; | 299 consecutive_delayed_feedbacks_ = 0; |
| 283 } | 300 } |
| 284 return aggregated_result; | 301 return aggregated_result; |
| 285 } | 302 } |
| 286 | 303 |
| 287 DelayBasedBwe::Result DelayBasedBwe::OnLongFeedbackDelay( | 304 DelayBasedBwe::Result DelayBasedBwe::OnLongFeedbackDelay( |
| 288 int64_t arrival_time_ms) { | 305 int64_t arrival_time_ms) { |
| 289 // Estimate should always be valid since a start bitrate always is set in the | 306 // Estimate should always be valid since a start bitrate always is set in the |
| 290 // Call constructor. An alternative would be to return an empty Result here, | 307 // Call constructor. An alternative would be to return an empty Result here, |
| 291 // or to estimate the throughput based on the feedback we received. | 308 // or to estimate the throughput based on the feedback we received. |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 rtc::Optional<uint32_t> acked_bitrate_bps, | 432 rtc::Optional<uint32_t> acked_bitrate_bps, |
| 416 uint32_t* target_bitrate_bps) { | 433 uint32_t* target_bitrate_bps) { |
| 417 // TODO(terelius): RateControlInput::noise_var is deprecated and will be | 434 // TODO(terelius): RateControlInput::noise_var is deprecated and will be |
| 418 // removed. In the meantime, we set it to zero. | 435 // removed. In the meantime, we set it to zero. |
| 419 const RateControlInput input(detector_.State(), acked_bitrate_bps, 0); | 436 const RateControlInput input(detector_.State(), acked_bitrate_bps, 0); |
| 420 rate_control_.Update(&input, now_ms); | 437 rate_control_.Update(&input, now_ms); |
| 421 *target_bitrate_bps = rate_control_.UpdateBandwidthEstimate(now_ms); | 438 *target_bitrate_bps = rate_control_.UpdateBandwidthEstimate(now_ms); |
| 422 return rate_control_.ValidEstimate(); | 439 return rate_control_.ValidEstimate(); |
| 423 } | 440 } |
| 424 | 441 |
| 442 void DelayBasedBwe::SortPacketFeedbackVector( | |
|
stefan-webrtc
2017/03/07 12:04:18
This should be in the anonymous namespace and not
elad.alon_webrtc.org
2017/03/07 12:11:07
Done.
| |
| 443 const std::vector<PacketFeedback>& input, | |
| 444 std::vector<PacketFeedback>* output) { | |
| 445 auto pred = [](const PacketFeedback& packet_feedback) { | |
| 446 return packet_feedback.arrival_time_ms != PacketFeedback::kNotReceived; | |
| 447 }; | |
| 448 std::copy_if(input.begin(), input.end(), std::back_inserter(*output), pred); | |
| 449 std::sort(output->begin(), output->end(), PacketFeedbackComparator()); | |
| 450 } | |
| 451 | |
| 425 void DelayBasedBwe::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | 452 void DelayBasedBwe::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
| 426 rate_control_.SetRtt(avg_rtt_ms); | 453 rate_control_.SetRtt(avg_rtt_ms); |
| 427 } | 454 } |
| 428 | 455 |
| 429 bool DelayBasedBwe::LatestEstimate(std::vector<uint32_t>* ssrcs, | 456 bool DelayBasedBwe::LatestEstimate(std::vector<uint32_t>* ssrcs, |
| 430 uint32_t* bitrate_bps) const { | 457 uint32_t* bitrate_bps) const { |
| 431 // Currently accessed from both the process thread (see | 458 // Currently accessed from both the process thread (see |
| 432 // ModuleRtpRtcpImpl::Process()) and the configuration thread (see | 459 // ModuleRtpRtcpImpl::Process()) and the configuration thread (see |
| 433 // Call::GetStats()). Should in the future only be accessed from a single | 460 // Call::GetStats()). Should in the future only be accessed from a single |
| 434 // thread. | 461 // thread. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 450 void DelayBasedBwe::SetMinBitrate(int min_bitrate_bps) { | 477 void DelayBasedBwe::SetMinBitrate(int min_bitrate_bps) { |
| 451 // Called from both the configuration thread and the network thread. Shouldn't | 478 // Called from both the configuration thread and the network thread. Shouldn't |
| 452 // be called from the network thread in the future. | 479 // be called from the network thread in the future. |
| 453 rate_control_.SetMinBitrate(min_bitrate_bps); | 480 rate_control_.SetMinBitrate(min_bitrate_bps); |
| 454 } | 481 } |
| 455 | 482 |
| 456 int64_t DelayBasedBwe::GetProbingIntervalMs() const { | 483 int64_t DelayBasedBwe::GetProbingIntervalMs() const { |
| 457 return probing_interval_estimator_.GetIntervalMs(); | 484 return probing_interval_estimator_.GetIntervalMs(); |
| 458 } | 485 } |
| 459 } // namespace webrtc | 486 } // namespace webrtc |
| OLD | NEW |