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