| 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 a7d2788ff862d56ad874ee4b4c77e162f0bd565f..1b6aa7f3ccc9fed5acb38dcee6310d60209cc54c 100644
|
| --- a/webrtc/modules/congestion_controller/delay_based_bwe.cc
|
| +++ b/webrtc/modules/congestion_controller/delay_based_bwe.cc
|
| @@ -18,6 +18,7 @@
|
| #include "webrtc/base/constructormagic.h"
|
| #include "webrtc/base/logging.h"
|
| #include "webrtc/base/thread_annotations.h"
|
| +#include "webrtc/modules/congestion_controller/include/congestion_controller.h"
|
| #include "webrtc/modules/pacing/paced_sender.h"
|
| #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h"
|
| #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
|
| @@ -40,18 +41,17 @@ constexpr uint32_t kFixedSsrc = 0;
|
|
|
| namespace webrtc {
|
|
|
| -DelayBasedBwe::DelayBasedBwe(RemoteBitrateObserver* observer, Clock* clock)
|
| +DelayBasedBwe::DelayBasedBwe(CongestionController* controller, Clock* clock)
|
| : clock_(clock),
|
| - observer_(observer),
|
| + controller_(controller),
|
| inter_arrival_(),
|
| estimator_(),
|
| detector_(OverUseDetectorOptions()),
|
| incoming_bitrate_(kBitrateWindowMs, 8000),
|
| - first_packet_time_ms_(-1),
|
| last_update_ms_(-1),
|
| last_seen_packet_ms_(-1),
|
| uma_recorded_(false) {
|
| - RTC_DCHECK(observer_);
|
| + RTC_DCHECK(controller_);
|
| network_thread_.DetachFromThread();
|
| }
|
|
|
| @@ -72,12 +72,9 @@ void DelayBasedBwe::IncomingPacketFeedbackVector(
|
| void DelayBasedBwe::IncomingPacketInfo(const PacketInfo& info) {
|
| int64_t now_ms = clock_->TimeInMilliseconds();
|
|
|
| - if (first_packet_time_ms_ == -1)
|
| - first_packet_time_ms_ = now_ms;
|
| -
|
| incoming_bitrate_.Update(info.payload_size, info.arrival_time_ms);
|
| - bool update_estimate = false;
|
| - uint32_t target_bitrate_bps = 0;
|
| + bool delay_based_bwe_changed = false;
|
| + int target_bitrate_bps = 0;
|
| {
|
| rtc::CritScope lock(&crit_);
|
|
|
| @@ -91,15 +88,6 @@ void DelayBasedBwe::IncomingPacketInfo(const PacketInfo& info) {
|
| }
|
| last_seen_packet_ms_ = now_ms;
|
|
|
| - if (info.probe_cluster_id != PacketInfo::kNotAProbe) {
|
| - ProbingResult probe_result =
|
| - probe_bitrate_estimator_.PacketFeedback(info);
|
| - if (probe_result.valid()) {
|
| - remote_rate_.SetEstimate(probe_result.bps, probe_result.timestamp);
|
| - update_estimate = true;
|
| - }
|
| - }
|
| -
|
| uint32_t send_time_24bits =
|
| static_cast<uint32_t>(((static_cast<uint64_t>(info.send_time_ms)
|
| << kAbsSendTimeFraction) +
|
| @@ -122,41 +110,63 @@ void DelayBasedBwe::IncomingPacketInfo(const PacketInfo& info) {
|
| estimator_->num_of_deltas(), info.arrival_time_ms);
|
| }
|
|
|
| - if (!update_estimate) {
|
| - // Check if it's time for a periodic update or if we should update because
|
| - // of an over-use.
|
| - if (last_update_ms_ == -1 ||
|
| - now_ms - last_update_ms_ > remote_rate_.GetFeedbackInterval()) {
|
| - update_estimate = true;
|
| - } else if (detector_.State() == kBwOverusing) {
|
| - rtc::Optional<uint32_t> incoming_rate =
|
| - incoming_bitrate_.Rate(info.arrival_time_ms);
|
| - if (incoming_rate &&
|
| - remote_rate_.TimeToReduceFurther(now_ms, *incoming_rate)) {
|
| - update_estimate = true;
|
| - }
|
| + int probing_bps = 0;
|
| + if (info.probe_cluster_id != PacketInfo::kNotAProbe &&
|
| + controller_->IsExpectingProbingResults()) {
|
| + // Without a valid estimate, we wait for two clusters and then later on
|
| + // wait on a single cluster to update probing bitrate.
|
| + if (!remote_rate_.ValidEstimate()) {
|
| + probing_bps =
|
| + probe_bitrate_estimator_.HandleProbeAndEstimateBitrate(info, 2);
|
| + } else {
|
| + probing_bps =
|
| + probe_bitrate_estimator_.HandleProbeAndEstimateBitrate(info, 1);
|
| }
|
| }
|
|
|
| - if (update_estimate) {
|
| - // The first overuse should immediately trigger a new estimate.
|
| - // We also have to update the estimate immediately if we are overusing
|
| - // and the target bitrate is too high compared to what we are receiving.
|
| - const RateControlInput input(detector_.State(),
|
| - incoming_bitrate_.Rate(info.arrival_time_ms),
|
| - estimator_->var_noise());
|
| - remote_rate_.Update(&input, now_ms);
|
| - target_bitrate_bps = remote_rate_.UpdateBandwidthEstimate(now_ms);
|
| - update_estimate = remote_rate_.ValidEstimate();
|
| + // Currently overusing the bandwidth.
|
| + if (detector_.State() == kBwOverusing) {
|
| + rtc::Optional<uint32_t> incoming_rate =
|
| + incoming_bitrate_.Rate(info.arrival_time_ms);
|
| + if (incoming_rate &&
|
| + remote_rate_.TimeToReduceFurther(now_ms, *incoming_rate)) {
|
| + delay_based_bwe_changed =
|
| + UpdateEstimate(info.arrival_time_ms, now_ms, &target_bitrate_bps);
|
| + }
|
| + } else if (probing_bps > 0) {
|
| + // No overuse, but probing measured a bitrate.
|
| + remote_rate_.SetEstimate(probing_bps, info.arrival_time_ms);
|
| + target_bitrate_bps = probing_bps;
|
| + delay_based_bwe_changed = true;
|
| + } else if (last_update_ms_ == -1 ||
|
| + now_ms - last_update_ms_ > remote_rate_.GetFeedbackInterval()) {
|
| + // Been a while since we updated estimate.
|
| + delay_based_bwe_changed =
|
| + UpdateEstimate(info.arrival_time_ms, now_ms, &target_bitrate_bps);
|
| }
|
| }
|
|
|
| - if (update_estimate) {
|
| + if (delay_based_bwe_changed) {
|
| last_update_ms_ = now_ms;
|
| - observer_->OnReceiveBitrateChanged({kFixedSsrc}, target_bitrate_bps);
|
| + controller_->OnDelayBasedBweChanged(target_bitrate_bps);
|
| }
|
| }
|
|
|
| +bool DelayBasedBwe::UpdateEstimate(int64_t arrival_time_ms,
|
| + int64_t now_ms,
|
| + int* target_bitrate_bps) {
|
| + rtc::CritScope lock(&crit_);
|
| + // The first overuse should immediately trigger a new estimate.
|
| + // We also have to update the estimate immediately if we are overusing
|
| + // and the target bitrate is too high compared to what we are receiving.
|
| + const RateControlInput input(detector_.State(),
|
| + incoming_bitrate_.Rate(arrival_time_ms),
|
| + estimator_->var_noise());
|
| + remote_rate_.Update(&input, now_ms);
|
| + *target_bitrate_bps = remote_rate_.UpdateBandwidthEstimate(now_ms);
|
| + return remote_rate_.ValidEstimate();
|
| +}
|
| +
|
| void DelayBasedBwe::Process() {}
|
|
|
| int64_t DelayBasedBwe::TimeUntilNextProcess() {
|
|
|