Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 *low_loss_threshold = kDefaultLowLossThreshold; | 97 *low_loss_threshold = kDefaultLowLossThreshold; |
| 98 *high_loss_threshold = kDefaultHighLossThreshold; | 98 *high_loss_threshold = kDefaultHighLossThreshold; |
| 99 *bitrate_threshold_kbps = kDefaultBitrateThresholdKbps; | 99 *bitrate_threshold_kbps = kDefaultBitrateThresholdKbps; |
| 100 return false; | 100 return false; |
| 101 } | 101 } |
| 102 } // namespace | 102 } // namespace |
| 103 | 103 |
| 104 SendSideBandwidthEstimation::SendSideBandwidthEstimation(RtcEventLog* event_log) | 104 SendSideBandwidthEstimation::SendSideBandwidthEstimation(RtcEventLog* event_log) |
| 105 : lost_packets_since_last_loss_update_Q8_(0), | 105 : lost_packets_since_last_loss_update_Q8_(0), |
| 106 expected_packets_since_last_loss_update_(0), | 106 expected_packets_since_last_loss_update_(0), |
| 107 bitrate_(0), | 107 current_bitrate_bps_(0), |
| 108 min_bitrate_configured_(congestion_controller::GetMinBitrateBps()), | 108 min_bitrate_configured_(congestion_controller::GetMinBitrateBps()), |
| 109 max_bitrate_configured_(kDefaultMaxBitrateBps), | 109 max_bitrate_configured_(kDefaultMaxBitrateBps), |
| 110 last_low_bitrate_log_ms_(-1), | 110 last_low_bitrate_log_ms_(-1), |
| 111 has_decreased_since_last_fraction_loss_(false), | 111 has_decreased_since_last_fraction_loss_(false), |
| 112 last_feedback_ms_(-1), | 112 last_feedback_ms_(-1), |
| 113 last_packet_report_ms_(-1), | 113 last_packet_report_ms_(-1), |
| 114 last_timeout_ms_(-1), | 114 last_timeout_ms_(-1), |
| 115 last_fraction_loss_(0), | 115 last_fraction_loss_(0), |
| 116 last_logged_fraction_loss_(0), | 116 last_logged_fraction_loss_(0), |
| 117 last_round_trip_time_ms_(0), | 117 last_round_trip_time_ms_(0), |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 142 bitrate_threshold_bps_ = bitrate_threshold_kbps * 1000; | 142 bitrate_threshold_bps_ = bitrate_threshold_kbps * 1000; |
| 143 } | 143 } |
| 144 } | 144 } |
| 145 } | 145 } |
| 146 | 146 |
| 147 SendSideBandwidthEstimation::~SendSideBandwidthEstimation() {} | 147 SendSideBandwidthEstimation::~SendSideBandwidthEstimation() {} |
| 148 | 148 |
| 149 void SendSideBandwidthEstimation::SetBitrates(int send_bitrate, | 149 void SendSideBandwidthEstimation::SetBitrates(int send_bitrate, |
| 150 int min_bitrate, | 150 int min_bitrate, |
| 151 int max_bitrate) { | 151 int max_bitrate) { |
| 152 SetMinMaxBitrate(min_bitrate, max_bitrate); | |
| 152 if (send_bitrate > 0) | 153 if (send_bitrate > 0) |
| 153 SetSendBitrate(send_bitrate); | 154 SetSendBitrate(send_bitrate); |
| 154 SetMinMaxBitrate(min_bitrate, max_bitrate); | |
| 155 } | 155 } |
| 156 | 156 |
| 157 void SendSideBandwidthEstimation::SetSendBitrate(int bitrate) { | 157 void SendSideBandwidthEstimation::SetSendBitrate(int bitrate) { |
| 158 RTC_DCHECK_GT(bitrate, 0); | 158 RTC_DCHECK_GT(bitrate, 0); |
| 159 bitrate_ = bitrate; | 159 CapAndLogBitrate(Clock::GetRealTimeClock()->TimeInMilliseconds(), bitrate); |
| 160 | |
| 161 // Clear last sent bitrate history so the new value can be used directly | 160 // Clear last sent bitrate history so the new value can be used directly |
| 162 // and not capped. | 161 // and not capped. |
| 163 min_bitrate_history_.clear(); | 162 min_bitrate_history_.clear(); |
| 164 } | 163 } |
| 165 | 164 |
| 166 void SendSideBandwidthEstimation::SetMinMaxBitrate(int min_bitrate, | 165 void SendSideBandwidthEstimation::SetMinMaxBitrate(int min_bitrate, |
| 167 int max_bitrate) { | 166 int max_bitrate) { |
| 168 RTC_DCHECK_GE(min_bitrate, 0); | 167 RTC_DCHECK_GE(min_bitrate, 0); |
| 169 min_bitrate_configured_ = | 168 min_bitrate_configured_ = |
| 170 std::max(min_bitrate, congestion_controller::GetMinBitrateBps()); | 169 std::max(min_bitrate, congestion_controller::GetMinBitrateBps()); |
| 171 if (max_bitrate > 0) { | 170 if (max_bitrate > 0) { |
| 172 max_bitrate_configured_ = | 171 max_bitrate_configured_ = |
| 173 std::max<uint32_t>(min_bitrate_configured_, max_bitrate); | 172 std::max<uint32_t>(min_bitrate_configured_, max_bitrate); |
| 174 } else { | 173 } else { |
| 175 max_bitrate_configured_ = kDefaultMaxBitrateBps; | 174 max_bitrate_configured_ = kDefaultMaxBitrateBps; |
| 176 } | 175 } |
| 177 } | 176 } |
| 178 | 177 |
| 179 int SendSideBandwidthEstimation::GetMinBitrate() const { | 178 int SendSideBandwidthEstimation::GetMinBitrate() const { |
| 180 return min_bitrate_configured_; | 179 return min_bitrate_configured_; |
| 181 } | 180 } |
| 182 | 181 |
| 183 void SendSideBandwidthEstimation::CurrentEstimate(int* bitrate, | 182 void SendSideBandwidthEstimation::CurrentEstimate(int* bitrate, |
| 184 uint8_t* loss, | 183 uint8_t* loss, |
| 185 int64_t* rtt) const { | 184 int64_t* rtt) const { |
| 186 *bitrate = bitrate_; | 185 *bitrate = current_bitrate_bps_; |
| 187 *loss = last_fraction_loss_; | 186 *loss = last_fraction_loss_; |
| 188 *rtt = last_round_trip_time_ms_; | 187 *rtt = last_round_trip_time_ms_; |
| 189 } | 188 } |
| 190 | 189 |
| 191 void SendSideBandwidthEstimation::UpdateReceiverEstimate( | 190 void SendSideBandwidthEstimation::UpdateReceiverEstimate( |
| 192 int64_t now_ms, uint32_t bandwidth) { | 191 int64_t now_ms, uint32_t bandwidth) { |
| 193 bwe_incoming_ = bandwidth; | 192 bwe_incoming_ = bandwidth; |
| 194 bitrate_ = CapBitrateToThresholds(now_ms, bitrate_); | 193 CapAndLogBitrate(now_ms, current_bitrate_bps_); |
| 195 } | 194 } |
| 196 | 195 |
| 197 void SendSideBandwidthEstimation::UpdateDelayBasedEstimate( | 196 void SendSideBandwidthEstimation::UpdateDelayBasedEstimate( |
| 198 int64_t now_ms, | 197 int64_t now_ms, |
| 199 uint32_t bitrate_bps) { | 198 uint32_t bitrate_bps) { |
| 200 delay_based_bitrate_bps_ = bitrate_bps; | 199 delay_based_bitrate_bps_ = bitrate_bps; |
| 201 bitrate_ = CapBitrateToThresholds(now_ms, bitrate_); | 200 CapAndLogBitrate(now_ms, current_bitrate_bps_); |
| 202 } | 201 } |
| 203 | 202 |
| 204 void SendSideBandwidthEstimation::UpdateReceiverBlock(uint8_t fraction_loss, | 203 void SendSideBandwidthEstimation::UpdateReceiverBlock(uint8_t fraction_loss, |
| 205 int64_t rtt, | 204 int64_t rtt, |
| 206 int number_of_packets, | 205 int number_of_packets, |
| 207 int64_t now_ms) { | 206 int64_t now_ms) { |
| 208 last_feedback_ms_ = now_ms; | 207 last_feedback_ms_ = now_ms; |
| 209 if (first_report_time_ms_ == -1) | 208 if (first_report_time_ms_ == -1) |
| 210 first_report_time_ms_ = now_ms; | 209 first_report_time_ms_ = now_ms; |
| 211 | 210 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 233 expected_packets_since_last_loss_update_ = 0; | 232 expected_packets_since_last_loss_update_ = 0; |
| 234 last_packet_report_ms_ = now_ms; | 233 last_packet_report_ms_ = now_ms; |
| 235 UpdateEstimate(now_ms); | 234 UpdateEstimate(now_ms); |
| 236 } | 235 } |
| 237 UpdateUmaStats(now_ms, rtt, (fraction_loss * number_of_packets) >> 8); | 236 UpdateUmaStats(now_ms, rtt, (fraction_loss * number_of_packets) >> 8); |
| 238 } | 237 } |
| 239 | 238 |
| 240 void SendSideBandwidthEstimation::UpdateUmaStats(int64_t now_ms, | 239 void SendSideBandwidthEstimation::UpdateUmaStats(int64_t now_ms, |
| 241 int64_t rtt, | 240 int64_t rtt, |
| 242 int lost_packets) { | 241 int lost_packets) { |
| 243 int bitrate_kbps = static_cast<int>((bitrate_ + 500) / 1000); | 242 int bitrate_kbps = static_cast<int>((current_bitrate_bps_ + 500) / 1000); |
| 244 for (size_t i = 0; i < kNumUmaRampupMetrics; ++i) { | 243 for (size_t i = 0; i < kNumUmaRampupMetrics; ++i) { |
| 245 if (!rampup_uma_stats_updated_[i] && | 244 if (!rampup_uma_stats_updated_[i] && |
| 246 bitrate_kbps >= kUmaRampupMetrics[i].bitrate_kbps) { | 245 bitrate_kbps >= kUmaRampupMetrics[i].bitrate_kbps) { |
| 247 RTC_HISTOGRAMS_COUNTS_100000(i, kUmaRampupMetrics[i].metric_name, | 246 RTC_HISTOGRAMS_COUNTS_100000(i, kUmaRampupMetrics[i].metric_name, |
| 248 now_ms - first_report_time_ms_); | 247 now_ms - first_report_time_ms_); |
| 249 rampup_uma_stats_updated_[i] = true; | 248 rampup_uma_stats_updated_[i] = true; |
| 250 } | 249 } |
| 251 } | 250 } |
| 252 if (IsInStartPhase(now_ms)) { | 251 if (IsInStartPhase(now_ms)) { |
| 253 initially_lost_packets_ += lost_packets; | 252 initially_lost_packets_ += lost_packets; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 264 now_ms - first_report_time_ms_ >= kBweConverganceTimeMs) { | 263 now_ms - first_report_time_ms_ >= kBweConverganceTimeMs) { |
| 265 uma_update_state_ = kDone; | 264 uma_update_state_ = kDone; |
| 266 int bitrate_diff_kbps = | 265 int bitrate_diff_kbps = |
| 267 std::max(bitrate_at_2_seconds_kbps_ - bitrate_kbps, 0); | 266 std::max(bitrate_at_2_seconds_kbps_ - bitrate_kbps, 0); |
| 268 RTC_HISTOGRAM_COUNTS("WebRTC.BWE.InitialVsConvergedDiff", bitrate_diff_kbps, | 267 RTC_HISTOGRAM_COUNTS("WebRTC.BWE.InitialVsConvergedDiff", bitrate_diff_kbps, |
| 269 0, 2000, 50); | 268 0, 2000, 50); |
| 270 } | 269 } |
| 271 } | 270 } |
| 272 | 271 |
| 273 void SendSideBandwidthEstimation::UpdateEstimate(int64_t now_ms) { | 272 void SendSideBandwidthEstimation::UpdateEstimate(int64_t now_ms) { |
| 273 uint32_t new_bitrate = current_bitrate_bps_; | |
| 274 // We trust the REMB and/or delay-based estimate during the first 2 seconds if | 274 // We trust the REMB and/or delay-based estimate during the first 2 seconds if |
| 275 // we haven't had any packet loss reported, to allow startup bitrate probing. | 275 // we haven't had any packet loss reported, to allow startup bitrate probing. |
| 276 if (last_fraction_loss_ == 0 && IsInStartPhase(now_ms)) { | 276 if (last_fraction_loss_ == 0 && IsInStartPhase(now_ms)) { |
| 277 uint32_t prev_bitrate = bitrate_; | 277 new_bitrate = std::max(bwe_incoming_, new_bitrate); |
| 278 if (bwe_incoming_ > bitrate_) | 278 new_bitrate = std::max(delay_based_bitrate_bps_, new_bitrate); |
| 279 bitrate_ = CapBitrateToThresholds(now_ms, bwe_incoming_); | 279 |
| 280 if (delay_based_bitrate_bps_ > bitrate_) { | 280 if (new_bitrate != current_bitrate_bps_) { |
| 281 bitrate_ = CapBitrateToThresholds(now_ms, delay_based_bitrate_bps_); | |
| 282 } | |
| 283 if (bitrate_ != prev_bitrate) { | |
| 284 min_bitrate_history_.clear(); | 281 min_bitrate_history_.clear(); |
| 285 min_bitrate_history_.push_back(std::make_pair(now_ms, bitrate_)); | 282 min_bitrate_history_.push_back( |
| 283 std::make_pair(now_ms, current_bitrate_bps_)); | |
| 284 CapAndLogBitrate(now_ms, new_bitrate); | |
| 286 return; | 285 return; |
| 287 } | 286 } |
| 288 } | 287 } |
| 289 UpdateMinHistory(now_ms); | 288 UpdateMinHistory(now_ms); |
| 290 if (last_packet_report_ms_ == -1) { | 289 if (last_packet_report_ms_ == -1) { |
| 291 // No feedback received. | 290 // No feedback received. |
| 292 bitrate_ = CapBitrateToThresholds(now_ms, bitrate_); | 291 CapAndLogBitrate(now_ms, current_bitrate_bps_); |
| 293 return; | 292 return; |
| 294 } | 293 } |
| 295 int64_t time_since_packet_report_ms = now_ms - last_packet_report_ms_; | 294 int64_t time_since_packet_report_ms = now_ms - last_packet_report_ms_; |
| 296 int64_t time_since_feedback_ms = now_ms - last_feedback_ms_; | 295 int64_t time_since_feedback_ms = now_ms - last_feedback_ms_; |
| 297 if (time_since_packet_report_ms < 1.2 * kFeedbackIntervalMs) { | 296 if (time_since_packet_report_ms < 1.2 * kFeedbackIntervalMs) { |
| 298 // We only care about loss above a given bitrate threshold. | 297 // We only care about loss above a given bitrate threshold. |
| 299 float loss = last_fraction_loss_ / 256.0f; | 298 float loss = last_fraction_loss_ / 256.0f; |
| 300 // We only make decisions based on loss when the bitrate is above a | 299 // We only make decisions based on loss when the bitrate is above a |
| 301 // threshold. This is a crude way of handling loss which is uncorrelated | 300 // threshold. This is a crude way of handling loss which is uncorrelated |
| 302 // to congestion. | 301 // to congestion. |
| 303 if (bitrate_ < bitrate_threshold_bps_ || loss <= low_loss_threshold_) { | 302 if (current_bitrate_bps_ < bitrate_threshold_bps_ || |
| 303 loss <= low_loss_threshold_) { | |
| 304 // Loss < 2%: Increase rate by 8% of the min bitrate in the last | 304 // Loss < 2%: Increase rate by 8% of the min bitrate in the last |
| 305 // kBweIncreaseIntervalMs. | 305 // kBweIncreaseIntervalMs. |
| 306 // Note that by remembering the bitrate over the last second one can | 306 // Note that by remembering the bitrate over the last second one can |
| 307 // rampup up one second faster than if only allowed to start ramping | 307 // rampup up one second faster than if only allowed to start ramping |
| 308 // at 8% per second rate now. E.g.: | 308 // at 8% per second rate now. E.g.: |
| 309 // If sending a constant 100kbps it can rampup immediatly to 108kbps | 309 // If sending a constant 100kbps it can rampup immediatly to 108kbps |
| 310 // whenever a receiver report is received with lower packet loss. | 310 // whenever a receiver report is received with lower packet loss. |
| 311 // If instead one would do: bitrate_ *= 1.08^(delta time), it would | 311 // If instead one would do: current_bitrate_bps_ *= 1.08^(delta time), |
| 312 // take over one second since the lower packet loss to achieve | 312 // it would take over one second since the lower packet loss to achieve |
| 313 // 108kbps. | 313 // 108kbps. |
| 314 bitrate_ = static_cast<uint32_t>( | 314 new_bitrate = static_cast<uint32_t>( |
| 315 min_bitrate_history_.front().second * 1.08 + 0.5); | 315 min_bitrate_history_.front().second * 1.08 + 0.5); |
| 316 | 316 |
| 317 // Add 1 kbps extra, just to make sure that we do not get stuck | 317 // Add 1 kbps extra, just to make sure that we do not get stuck |
| 318 // (gives a little extra increase at low rates, negligible at higher | 318 // (gives a little extra increase at low rates, negligible at higher |
| 319 // rates). | 319 // rates). |
| 320 bitrate_ += 1000; | 320 new_bitrate += 1000; |
| 321 } else if (bitrate_ > bitrate_threshold_bps_) { | 321 } else if (current_bitrate_bps_ > bitrate_threshold_bps_) { |
| 322 if (loss <= high_loss_threshold_) { | 322 if (loss <= high_loss_threshold_) { |
| 323 // Loss between 2% - 10%: Do nothing. | 323 // Loss between 2% - 10%: Do nothing. |
| 324 } else { | 324 } else { |
| 325 // Loss > 10%: Limit the rate decreases to once a kBweDecreaseIntervalMs | 325 // Loss > 10%: Limit the rate decreases to once a kBweDecreaseIntervalMs |
| 326 // + rtt. | 326 // + rtt. |
| 327 if (!has_decreased_since_last_fraction_loss_ && | 327 if (!has_decreased_since_last_fraction_loss_ && |
| 328 (now_ms - time_last_decrease_ms_) >= | 328 (now_ms - time_last_decrease_ms_) >= |
| 329 (kBweDecreaseIntervalMs + last_round_trip_time_ms_)) { | 329 (kBweDecreaseIntervalMs + last_round_trip_time_ms_)) { |
| 330 time_last_decrease_ms_ = now_ms; | 330 time_last_decrease_ms_ = now_ms; |
| 331 | 331 |
| 332 // Reduce rate: | 332 // Reduce rate: |
| 333 // newRate = rate * (1 - 0.5*lossRate); | 333 // newRate = rate * (1 - 0.5*lossRate); |
| 334 // where packetLoss = 256*lossRate; | 334 // where packetLoss = 256*lossRate; |
| 335 bitrate_ = static_cast<uint32_t>( | 335 new_bitrate = static_cast<uint32_t>( |
| 336 (bitrate_ * static_cast<double>(512 - last_fraction_loss_)) / | 336 (current_bitrate_bps_ * |
| 337 static_cast<double>(512 - last_fraction_loss_)) / | |
| 337 512.0); | 338 512.0); |
| 338 has_decreased_since_last_fraction_loss_ = true; | 339 has_decreased_since_last_fraction_loss_ = true; |
| 339 } | 340 } |
| 340 } | 341 } |
| 341 } | 342 } |
| 342 } else if (time_since_feedback_ms > | 343 } else if (time_since_feedback_ms > |
| 343 kFeedbackTimeoutIntervals * kFeedbackIntervalMs && | 344 kFeedbackTimeoutIntervals * kFeedbackIntervalMs && |
| 344 (last_timeout_ms_ == -1 || | 345 (last_timeout_ms_ == -1 || |
| 345 now_ms - last_timeout_ms_ > kTimeoutIntervalMs)) { | 346 now_ms - last_timeout_ms_ > kTimeoutIntervalMs)) { |
| 346 if (in_timeout_experiment_) { | 347 if (in_timeout_experiment_) { |
| 347 LOG(LS_WARNING) << "Feedback timed out (" << time_since_feedback_ms | 348 LOG(LS_WARNING) << "Feedback timed out (" << time_since_feedback_ms |
| 348 << " ms), reducing bitrate."; | 349 << " ms), reducing bitrate."; |
| 349 bitrate_ *= 0.8; | 350 new_bitrate *= 0.8; |
| 350 // Reset accumulators since we've already acted on missing feedback and | 351 // Reset accumulators since we've already acted on missing feedback and |
| 351 // shouldn't to act again on these old lost packets. | 352 // shouldn't to act again on these old lost packets. |
| 352 lost_packets_since_last_loss_update_Q8_ = 0; | 353 lost_packets_since_last_loss_update_Q8_ = 0; |
| 353 expected_packets_since_last_loss_update_ = 0; | 354 expected_packets_since_last_loss_update_ = 0; |
| 354 last_timeout_ms_ = now_ms; | 355 last_timeout_ms_ = now_ms; |
| 355 } | 356 } |
| 356 } | 357 } |
| 357 uint32_t capped_bitrate = CapBitrateToThresholds(now_ms, bitrate_); | 358 |
| 358 if (capped_bitrate != bitrate_ || | 359 CapAndLogBitrate(now_ms, new_bitrate); |
| 359 last_fraction_loss_ != last_logged_fraction_loss_ || | |
| 360 last_rtc_event_log_ms_ == -1 || | |
| 361 now_ms - last_rtc_event_log_ms_ > kRtcEventLogPeriodMs) { | |
| 362 event_log_->LogLossBasedBweUpdate(capped_bitrate, last_fraction_loss_, | |
| 363 expected_packets_since_last_loss_update_); | |
| 364 last_logged_fraction_loss_ = last_fraction_loss_; | |
| 365 last_rtc_event_log_ms_ = now_ms; | |
| 366 } | |
| 367 bitrate_ = capped_bitrate; | |
| 368 } | 360 } |
| 369 | 361 |
| 370 bool SendSideBandwidthEstimation::IsInStartPhase(int64_t now_ms) const { | 362 bool SendSideBandwidthEstimation::IsInStartPhase(int64_t now_ms) const { |
| 371 return first_report_time_ms_ == -1 || | 363 return first_report_time_ms_ == -1 || |
| 372 now_ms - first_report_time_ms_ < kStartPhaseMs; | 364 now_ms - first_report_time_ms_ < kStartPhaseMs; |
| 373 } | 365 } |
| 374 | 366 |
| 375 void SendSideBandwidthEstimation::UpdateMinHistory(int64_t now_ms) { | 367 void SendSideBandwidthEstimation::UpdateMinHistory(int64_t now_ms) { |
| 376 // Remove old data points from history. | 368 // Remove old data points from history. |
| 377 // Since history precision is in ms, add one so it is able to increase | 369 // Since history precision is in ms, add one so it is able to increase |
| 378 // bitrate if it is off by as little as 0.5ms. | 370 // bitrate if it is off by as little as 0.5ms. |
| 379 while (!min_bitrate_history_.empty() && | 371 while (!min_bitrate_history_.empty() && |
| 380 now_ms - min_bitrate_history_.front().first + 1 > | 372 now_ms - min_bitrate_history_.front().first + 1 > |
| 381 kBweIncreaseIntervalMs) { | 373 kBweIncreaseIntervalMs) { |
| 382 min_bitrate_history_.pop_front(); | 374 min_bitrate_history_.pop_front(); |
| 383 } | 375 } |
| 384 | 376 |
| 385 // Typical minimum sliding-window algorithm: Pop values higher than current | 377 // Typical minimum sliding-window algorithm: Pop values higher than current |
| 386 // bitrate before pushing it. | 378 // bitrate before pushing it. |
| 387 while (!min_bitrate_history_.empty() && | 379 while (!min_bitrate_history_.empty() && |
| 388 bitrate_ <= min_bitrate_history_.back().second) { | 380 current_bitrate_bps_ <= min_bitrate_history_.back().second) { |
| 389 min_bitrate_history_.pop_back(); | 381 min_bitrate_history_.pop_back(); |
| 390 } | 382 } |
| 391 | 383 |
| 392 min_bitrate_history_.push_back(std::make_pair(now_ms, bitrate_)); | 384 min_bitrate_history_.push_back(std::make_pair(now_ms, current_bitrate_bps_)); |
| 393 } | 385 } |
| 394 | 386 |
| 395 uint32_t SendSideBandwidthEstimation::CapBitrateToThresholds( | 387 void SendSideBandwidthEstimation::CapAndLogBitrate(int64_t now_ms, |
|
terelius
2017/04/18 12:09:58
nit: I would actually prefer to keep the old funct
philipel
2017/04/18 12:55:12
Done.
| |
| 396 int64_t now_ms, uint32_t bitrate) { | 388 uint32_t bitrate_bps) { |
| 397 if (bwe_incoming_ > 0 && bitrate > bwe_incoming_) { | 389 if (bwe_incoming_ > 0 && bitrate_bps > bwe_incoming_) { |
| 398 bitrate = bwe_incoming_; | 390 bitrate_bps = bwe_incoming_; |
| 399 } | 391 } |
| 400 if (delay_based_bitrate_bps_ > 0 && bitrate > delay_based_bitrate_bps_) { | 392 if (delay_based_bitrate_bps_ > 0 && bitrate_bps > delay_based_bitrate_bps_) { |
| 401 bitrate = delay_based_bitrate_bps_; | 393 bitrate_bps = delay_based_bitrate_bps_; |
| 402 } | 394 } |
| 403 if (bitrate > max_bitrate_configured_) { | 395 if (bitrate_bps > max_bitrate_configured_) { |
| 404 bitrate = max_bitrate_configured_; | 396 bitrate_bps = max_bitrate_configured_; |
| 405 } | 397 } |
| 406 if (bitrate < min_bitrate_configured_) { | 398 if (bitrate_bps < min_bitrate_configured_) { |
| 407 if (last_low_bitrate_log_ms_ == -1 || | 399 if (last_low_bitrate_log_ms_ == -1 || |
| 408 now_ms - last_low_bitrate_log_ms_ > kLowBitrateLogPeriodMs) { | 400 now_ms - last_low_bitrate_log_ms_ > kLowBitrateLogPeriodMs) { |
| 409 LOG(LS_WARNING) << "Estimated available bandwidth " << bitrate / 1000 | 401 LOG(LS_WARNING) << "Estimated available bandwidth " << bitrate_bps / 1000 |
| 410 << " kbps is below configured min bitrate " | 402 << " kbps is below configured min bitrate " |
| 411 << min_bitrate_configured_ / 1000 << " kbps."; | 403 << min_bitrate_configured_ / 1000 << " kbps."; |
| 412 last_low_bitrate_log_ms_ = now_ms; | 404 last_low_bitrate_log_ms_ = now_ms; |
| 413 } | 405 } |
| 414 bitrate = min_bitrate_configured_; | 406 bitrate_bps = min_bitrate_configured_; |
| 415 } | 407 } |
| 416 return bitrate; | 408 |
| 409 if (bitrate_bps != current_bitrate_bps_ || | |
| 410 last_fraction_loss_ != last_logged_fraction_loss_ || | |
| 411 now_ms - last_rtc_event_log_ms_ > kRtcEventLogPeriodMs) { | |
| 412 event_log_->LogLossBasedBweUpdate(bitrate_bps, last_fraction_loss_, | |
| 413 expected_packets_since_last_loss_update_); | |
| 414 last_logged_fraction_loss_ = last_fraction_loss_; | |
| 415 last_rtc_event_log_ms_ = now_ms; | |
| 416 } | |
| 417 current_bitrate_bps_ = bitrate_bps; | |
| 417 } | 418 } |
| 418 } // namespace webrtc | 419 } // namespace webrtc |
| OLD | NEW |