Chromium Code Reviews| Index: webrtc/modules/congestion_controller/delay_based_bwe.cc |
| diff --git a/webrtc/modules/congestion_controller/delay_based_bwe.cc b/webrtc/modules/congestion_controller/delay_based_bwe.cc |
| index 7a20b3eedb4fea1556931d8935c5218591a71a8d..7adf97349010dd3ccbb25ba7913d6e0fc5279920 100644 |
| --- a/webrtc/modules/congestion_controller/delay_based_bwe.cc |
| +++ b/webrtc/modules/congestion_controller/delay_based_bwe.cc |
| @@ -131,15 +131,21 @@ DelayBasedBwe::BitrateEstimator::BitrateEstimator() |
| bitrate_estimate_(-1.0f), |
| bitrate_estimate_var_(50.0f), |
| old_estimator_(kBitrateWindowMs, 8000), |
| - in_experiment_(BitrateEstimateExperimentIsEnabled()) {} |
| + in_experiment_(BitrateEstimateExperimentIsEnabled()), |
| + last_result_was_valid_(false) {} |
| void DelayBasedBwe::BitrateEstimator::Update(int64_t now_ms, int bytes) { |
| if (!in_experiment_) { |
| old_estimator_.Update(bytes, now_ms); |
| rtc::Optional<uint32_t> rate = old_estimator_.Rate(now_ms); |
| bitrate_estimate_ = -1.0f; |
| - if (rate) |
| + if (rate) { |
| bitrate_estimate_ = *rate / 1000.0f; |
| + last_result_was_valid_ = true; |
| + } else if (last_result_was_valid_) { |
| + old_estimator_.Reset(); |
| + last_result_was_valid_ = false; |
| + } |
| return; |
| } |
| int rate_window_ms = kRateWindowMs; |
| @@ -215,7 +221,6 @@ DelayBasedBwe::DelayBasedBwe(Clock* clock) |
| trendline_estimator_(), |
| detector_(), |
| receiver_incoming_bitrate_(), |
| - last_update_ms_(-1), |
| last_seen_packet_ms_(-1), |
| uma_recorded_(false), |
| trendline_window_size_(kDefaultTrendlineWindowSize), |
| @@ -246,17 +251,15 @@ DelayBasedBwe::Result DelayBasedBwe::IncomingPacketFeedbackVector( |
| BweNames::kBweNamesMax); |
| uma_recorded_ = true; |
| } |
| - Result aggregated_result; |
| + bool overusing = false; |
| for (const auto& packet_info : packet_feedback_vector) { |
| - Result result = IncomingPacketInfo(packet_info); |
| - if (result.updated) |
| - aggregated_result = result; |
| + IncomingPacketInfo(packet_info); |
| + overusing |= detector_.State() == kBwOverusing; |
| } |
| - return aggregated_result; |
| + return MaybeUpdateEstimate(overusing); |
| } |
| -DelayBasedBwe::Result DelayBasedBwe::IncomingPacketInfo( |
| - const PacketInfo& info) { |
| +void DelayBasedBwe::IncomingPacketInfo(const PacketInfo& info) { |
| int64_t now_ms = clock_->TimeInMilliseconds(); |
| receiver_incoming_bitrate_.Update(info.arrival_time_ms, info.payload_size); |
| @@ -313,53 +316,48 @@ DelayBasedBwe::Result DelayBasedBwe::IncomingPacketInfo( |
| } |
| } |
| - int probing_bps = 0; |
| if (info.probe_cluster_id != PacketInfo::kNotAProbe) { |
| - probing_bps = probe_bitrate_estimator_.HandleProbeAndEstimateBitrate(info); |
| + probe_bitrate_estimator_.HandleProbeAndEstimateBitrate(info); |
| } |
| +} |
| + |
| +DelayBasedBwe::Result DelayBasedBwe::MaybeUpdateEstimate(bool overusing) { |
| + Result result; |
| rtc::Optional<uint32_t> acked_bitrate_bps = |
| receiver_incoming_bitrate_.bitrate_bps(); |
| + int64_t now_ms = clock_->TimeInMilliseconds(); |
| + 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.
|
| + probe_bitrate_estimator_.FetchLastEstimatedBitrateBps(); |
| // Currently overusing the bandwidth. |
| - if (detector_.State() == kBwOverusing) { |
| + if (overusing) { |
| if (acked_bitrate_bps && |
| rate_control_.TimeToReduceFurther(now_ms, *acked_bitrate_bps)) { |
| result.updated = |
| - UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps, |
| - &result.target_bitrate_bps); |
| + UpdateEstimate(now_ms, acked_bitrate_bps, overusing, &result); |
| + } |
| + } else { |
| + if (porbe_bitrate_bps) { |
| + rate_control_.SetEstimate(*porbe_bitrate_bps, now_ms); |
| + result.probe = true; |
| } |
| - } else if (probing_bps > 0) { |
| - // No overuse, but probing measured a bitrate. |
| - rate_control_.SetEstimate(probing_bps, info.arrival_time_ms); |
| - result.probe = true; |
| - result.updated = |
| - UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps, |
| - &result.target_bitrate_bps); |
| - } |
| - if (!result.updated && |
| - (last_update_ms_ == -1 || |
| - now_ms - last_update_ms_ > rate_control_.GetFeedbackInterval())) { |
| result.updated = |
| - UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps, |
| - &result.target_bitrate_bps); |
| + UpdateEstimate(now_ms, acked_bitrate_bps, overusing, &result); |
| } |
| - if (result.updated) { |
| - last_update_ms_ = now_ms; |
| - BWE_TEST_LOGGING_PLOT(1, "target_bitrate_bps", now_ms, |
| - result.target_bitrate_bps); |
| - } |
| - |
| return result; |
| } |
| -bool DelayBasedBwe::UpdateEstimate(int64_t arrival_time_ms, |
| - int64_t now_ms, |
| +bool DelayBasedBwe::UpdateEstimate(int64_t now_ms, |
| rtc::Optional<uint32_t> acked_bitrate_bps, |
| - uint32_t* target_bitrate_bps) { |
| + bool overusing, |
| + Result* result) { |
| // TODO(terelius): RateControlInput::noise_var is deprecated and will be |
| // removed. In the meantime, we set it to zero. |
| - const RateControlInput input(detector_.State(), acked_bitrate_bps, 0); |
| + const RateControlInput input(overusing ? kBwOverusing : detector_.State(), |
| + acked_bitrate_bps, 0); |
| rate_control_.Update(&input, now_ms); |
| - *target_bitrate_bps = rate_control_.UpdateBandwidthEstimate(now_ms); |
| + result->target_bitrate_bps = rate_control_.UpdateBandwidthEstimate(now_ms); |
| + BWE_TEST_LOGGING_PLOT(1, "target_bitrate_bps", now_ms, |
| + result->target_bitrate_bps); |
| return rate_control_.ValidEstimate(); |
| } |