philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "webrtc/modules/congestion_controller/delay_based_bwe.h" |
| 12 | |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 13 | #include <algorithm> |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 14 | #include <cmath> |
terelius | afaef8b | 2016-11-17 03:48:18 -0800 | [diff] [blame^] | 15 | #include <string> |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 16 | |
| 17 | #include "webrtc/base/checks.h" |
| 18 | #include "webrtc/base/constructormagic.h" |
| 19 | #include "webrtc/base/logging.h" |
| 20 | #include "webrtc/base/thread_annotations.h" |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 21 | #include "webrtc/modules/congestion_controller/include/congestion_controller.h" |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 22 | #include "webrtc/modules/pacing/paced_sender.h" |
| 23 | #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h" |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 24 | #include "webrtc/system_wrappers/include/field_trial.h" |
stefan | 64636dd | 2016-08-03 00:29:03 -0700 | [diff] [blame] | 25 | #include "webrtc/system_wrappers/include/metrics.h" |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 26 | #include "webrtc/typedefs.h" |
| 27 | |
| 28 | namespace { |
philipel | 7522a28 | 2016-08-16 10:59:36 +0200 | [diff] [blame] | 29 | constexpr int kTimestampGroupLengthMs = 5; |
| 30 | constexpr int kAbsSendTimeFraction = 18; |
| 31 | constexpr int kAbsSendTimeInterArrivalUpshift = 8; |
| 32 | constexpr int kInterArrivalShift = |
| 33 | kAbsSendTimeFraction + kAbsSendTimeInterArrivalUpshift; |
| 34 | constexpr double kTimestampToMs = |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 35 | 1000.0 / static_cast<double>(1 << kInterArrivalShift); |
philipel | 7522a28 | 2016-08-16 10:59:36 +0200 | [diff] [blame] | 36 | // This ssrc is used to fulfill the current API but will be removed |
| 37 | // after the API has been changed. |
| 38 | constexpr uint32_t kFixedSsrc = 0; |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 39 | constexpr int kInitialRateWindowMs = 500; |
| 40 | constexpr int kRateWindowMs = 150; |
| 41 | |
terelius | afaef8b | 2016-11-17 03:48:18 -0800 | [diff] [blame^] | 42 | constexpr size_t kDefaultTrendlineWindowSize = 15; |
| 43 | constexpr double kDefaultTrendlineSmoothingCoeff = 0.9; |
| 44 | constexpr double kDefaultTrendlineThresholdGain = 4.0; |
| 45 | |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 46 | const char kBitrateEstimateExperiment[] = "WebRTC-ImprovedBitrateEstimate"; |
terelius | afaef8b | 2016-11-17 03:48:18 -0800 | [diff] [blame^] | 47 | const char kBweTrendlineFilterExperiment[] = "WebRTC-BweTrendlineFilter"; |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 48 | |
| 49 | bool BitrateEstimateExperimentIsEnabled() { |
| 50 | return webrtc::field_trial::FindFullName(kBitrateEstimateExperiment) == |
| 51 | "Enabled"; |
| 52 | } |
terelius | afaef8b | 2016-11-17 03:48:18 -0800 | [diff] [blame^] | 53 | |
| 54 | bool TrendlineFilterExperimentIsEnabled() { |
| 55 | std::string experiment_string = |
| 56 | webrtc::field_trial::FindFullName(kBweTrendlineFilterExperiment); |
| 57 | // The experiment is enabled iff the field trial string begins with "Enabled". |
| 58 | return experiment_string.find("Enabled") == 0; |
| 59 | } |
| 60 | |
| 61 | bool ReadTrendlineFilterExperimentParameters(size_t* window_points, |
| 62 | double* smoothing_coef, |
| 63 | double* threshold_gain) { |
| 64 | RTC_DCHECK(TrendlineFilterExperimentIsEnabled()); |
| 65 | std::string experiment_string = |
| 66 | webrtc::field_trial::FindFullName(kBweTrendlineFilterExperiment); |
| 67 | int parsed_values = sscanf(experiment_string.c_str(), "Enabled-%zu,%lf,%lf", |
| 68 | window_points, smoothing_coef, threshold_gain); |
| 69 | if (parsed_values == 3) { |
| 70 | RTC_CHECK_GT(*window_points, 1) << "Need at least 2 points to fit a line."; |
| 71 | RTC_CHECK(0 <= *smoothing_coef && *smoothing_coef <= 1) |
| 72 | << "Coefficient needs to be between 0 and 1 for weighted average."; |
| 73 | RTC_CHECK_GT(*threshold_gain, 0) << "Threshold gain needs to be positive."; |
| 74 | return true; |
| 75 | } |
| 76 | LOG(LS_WARNING) << "Failed to parse parameters for BweTrendlineFilter " |
| 77 | "experiment from field trial string. Using default."; |
| 78 | *window_points = kDefaultTrendlineWindowSize; |
| 79 | *smoothing_coef = kDefaultTrendlineSmoothingCoeff; |
| 80 | *threshold_gain = kDefaultTrendlineThresholdGain; |
| 81 | return false; |
| 82 | } |
| 83 | |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 84 | } // namespace |
| 85 | |
| 86 | namespace webrtc { |
terelius | afaef8b | 2016-11-17 03:48:18 -0800 | [diff] [blame^] | 87 | |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 88 | DelayBasedBwe::BitrateEstimator::BitrateEstimator() |
| 89 | : sum_(0), |
| 90 | current_win_ms_(0), |
| 91 | prev_time_ms_(-1), |
| 92 | bitrate_estimate_(-1.0f), |
| 93 | bitrate_estimate_var_(50.0f), |
| 94 | old_estimator_(kBitrateWindowMs, 8000), |
| 95 | in_experiment_(BitrateEstimateExperimentIsEnabled()) {} |
| 96 | |
| 97 | void DelayBasedBwe::BitrateEstimator::Update(int64_t now_ms, int bytes) { |
| 98 | if (!in_experiment_) { |
| 99 | old_estimator_.Update(bytes, now_ms); |
| 100 | rtc::Optional<uint32_t> rate = old_estimator_.Rate(now_ms); |
| 101 | bitrate_estimate_ = -1.0f; |
| 102 | if (rate) |
| 103 | bitrate_estimate_ = *rate / 1000.0f; |
| 104 | return; |
| 105 | } |
| 106 | int rate_window_ms = kRateWindowMs; |
| 107 | // We use a larger window at the beginning to get a more stable sample that |
| 108 | // we can use to initialize the estimate. |
| 109 | if (bitrate_estimate_ < 0.f) |
| 110 | rate_window_ms = kInitialRateWindowMs; |
| 111 | float bitrate_sample = UpdateWindow(now_ms, bytes, rate_window_ms); |
| 112 | if (bitrate_sample < 0.0f) |
| 113 | return; |
| 114 | if (bitrate_estimate_ < 0.0f) { |
| 115 | // This is the very first sample we get. Use it to initialize the estimate. |
| 116 | bitrate_estimate_ = bitrate_sample; |
| 117 | return; |
| 118 | } |
| 119 | // Define the sample uncertainty as a function of how far away it is from the |
| 120 | // current estimate. |
| 121 | float sample_uncertainty = |
| 122 | 10.0f * std::abs(bitrate_estimate_ - bitrate_sample) / bitrate_estimate_; |
| 123 | float sample_var = sample_uncertainty * sample_uncertainty; |
| 124 | // Update a bayesian estimate of the rate, weighting it lower if the sample |
| 125 | // uncertainty is large. |
| 126 | // The bitrate estimate uncertainty is increased with each update to model |
| 127 | // that the bitrate changes over time. |
| 128 | float pred_bitrate_estimate_var = bitrate_estimate_var_ + 5.f; |
| 129 | bitrate_estimate_ = (sample_var * bitrate_estimate_ + |
| 130 | pred_bitrate_estimate_var * bitrate_sample) / |
| 131 | (sample_var + pred_bitrate_estimate_var); |
| 132 | bitrate_estimate_var_ = sample_var * pred_bitrate_estimate_var / |
| 133 | (sample_var + pred_bitrate_estimate_var); |
| 134 | } |
| 135 | |
| 136 | float DelayBasedBwe::BitrateEstimator::UpdateWindow(int64_t now_ms, |
| 137 | int bytes, |
| 138 | int rate_window_ms) { |
| 139 | // Reset if time moves backwards. |
| 140 | if (now_ms < prev_time_ms_) { |
| 141 | prev_time_ms_ = -1; |
| 142 | sum_ = 0; |
| 143 | current_win_ms_ = 0; |
| 144 | } |
| 145 | if (prev_time_ms_ >= 0) { |
| 146 | current_win_ms_ += now_ms - prev_time_ms_; |
| 147 | // Reset if nothing has been received for more than a full window. |
| 148 | if (now_ms - prev_time_ms_ > rate_window_ms) { |
| 149 | sum_ = 0; |
| 150 | current_win_ms_ %= rate_window_ms; |
| 151 | } |
| 152 | } |
| 153 | prev_time_ms_ = now_ms; |
| 154 | float bitrate_sample = -1.0f; |
| 155 | if (current_win_ms_ >= rate_window_ms) { |
| 156 | bitrate_sample = 8.0f * sum_ / static_cast<float>(rate_window_ms); |
| 157 | current_win_ms_ -= rate_window_ms; |
| 158 | sum_ = 0; |
| 159 | } |
| 160 | sum_ += bytes; |
| 161 | return bitrate_sample; |
| 162 | } |
| 163 | |
| 164 | rtc::Optional<uint32_t> DelayBasedBwe::BitrateEstimator::bitrate_bps() const { |
| 165 | if (bitrate_estimate_ < 0.f) |
| 166 | return rtc::Optional<uint32_t>(); |
| 167 | return rtc::Optional<uint32_t>(bitrate_estimate_ * 1000); |
| 168 | } |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 169 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 170 | DelayBasedBwe::DelayBasedBwe(Clock* clock) |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 171 | : clock_(clock), |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 172 | inter_arrival_(), |
terelius | afaef8b | 2016-11-17 03:48:18 -0800 | [diff] [blame^] | 173 | kalman_estimator_(), |
| 174 | trendline_estimator_(), |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 175 | detector_(OverUseDetectorOptions()), |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 176 | receiver_incoming_bitrate_(), |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 177 | last_update_ms_(-1), |
philipel | 7522a28 | 2016-08-16 10:59:36 +0200 | [diff] [blame] | 178 | last_seen_packet_ms_(-1), |
terelius | afaef8b | 2016-11-17 03:48:18 -0800 | [diff] [blame^] | 179 | uma_recorded_(false), |
| 180 | trendline_window_size_(kDefaultTrendlineWindowSize), |
| 181 | trendline_smoothing_coeff_(kDefaultTrendlineSmoothingCoeff), |
| 182 | trendline_threshold_gain_(kDefaultTrendlineThresholdGain), |
| 183 | in_trendline_experiment_(TrendlineFilterExperimentIsEnabled()) { |
| 184 | if (in_trendline_experiment_) { |
| 185 | ReadTrendlineFilterExperimentParameters(&trendline_window_size_, |
| 186 | &trendline_smoothing_coeff_, |
| 187 | &trendline_threshold_gain_); |
| 188 | } |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 189 | network_thread_.DetachFromThread(); |
| 190 | } |
| 191 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 192 | DelayBasedBwe::Result DelayBasedBwe::IncomingPacketFeedbackVector( |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 193 | const std::vector<PacketInfo>& packet_feedback_vector) { |
| 194 | RTC_DCHECK(network_thread_.CalledOnValidThread()); |
stefan | 64636dd | 2016-08-03 00:29:03 -0700 | [diff] [blame] | 195 | if (!uma_recorded_) { |
asapersson | 1d02d3e | 2016-09-09 22:40:25 -0700 | [diff] [blame] | 196 | RTC_HISTOGRAM_ENUMERATION(kBweTypeHistogram, |
| 197 | BweNames::kSendSideTransportSeqNum, |
| 198 | BweNames::kBweNamesMax); |
stefan | 64636dd | 2016-08-03 00:29:03 -0700 | [diff] [blame] | 199 | uma_recorded_ = true; |
| 200 | } |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 201 | Result aggregated_result; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 202 | for (const auto& packet_info : packet_feedback_vector) { |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 203 | Result result = IncomingPacketInfo(packet_info); |
| 204 | if (result.updated) |
| 205 | aggregated_result = result; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 206 | } |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 207 | return aggregated_result; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 210 | DelayBasedBwe::Result DelayBasedBwe::IncomingPacketInfo( |
| 211 | const PacketInfo& info) { |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 212 | int64_t now_ms = clock_->TimeInMilliseconds(); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 213 | |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 214 | receiver_incoming_bitrate_.Update(info.arrival_time_ms, info.payload_size); |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 215 | Result result; |
| 216 | // Reset if the stream has timed out. |
| 217 | if (last_seen_packet_ms_ == -1 || |
| 218 | now_ms - last_seen_packet_ms_ > kStreamTimeOutMs) { |
| 219 | inter_arrival_.reset( |
| 220 | new InterArrival((kTimestampGroupLengthMs << kInterArrivalShift) / 1000, |
| 221 | kTimestampToMs, true)); |
terelius | afaef8b | 2016-11-17 03:48:18 -0800 | [diff] [blame^] | 222 | kalman_estimator_.reset(new OveruseEstimator(OverUseDetectorOptions())); |
| 223 | trendline_estimator_.reset(new TrendlineEstimator( |
| 224 | trendline_window_size_, trendline_smoothing_coeff_, |
| 225 | trendline_threshold_gain_)); |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 226 | } |
| 227 | last_seen_packet_ms_ = now_ms; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 228 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 229 | uint32_t send_time_24bits = |
| 230 | static_cast<uint32_t>( |
| 231 | ((static_cast<uint64_t>(info.send_time_ms) << kAbsSendTimeFraction) + |
| 232 | 500) / |
| 233 | 1000) & |
| 234 | 0x00FFFFFF; |
| 235 | // Shift up send time to use the full 32 bits that inter_arrival works with, |
| 236 | // so wrapping works properly. |
| 237 | uint32_t timestamp = send_time_24bits << kAbsSendTimeInterArrivalUpshift; |
stefan | fd0d426 | 2016-09-29 02:44:31 -0700 | [diff] [blame] | 238 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 239 | uint32_t ts_delta = 0; |
| 240 | int64_t t_delta = 0; |
| 241 | int size_delta = 0; |
| 242 | if (inter_arrival_->ComputeDeltas(timestamp, info.arrival_time_ms, now_ms, |
| 243 | info.payload_size, &ts_delta, &t_delta, |
| 244 | &size_delta)) { |
| 245 | double ts_delta_ms = (1000.0 * ts_delta) / (1 << kInterArrivalShift); |
terelius | afaef8b | 2016-11-17 03:48:18 -0800 | [diff] [blame^] | 246 | if (in_trendline_experiment_) { |
| 247 | trendline_estimator_->Update(t_delta, ts_delta_ms, info.arrival_time_ms); |
| 248 | detector_.Detect(trendline_estimator_->trendline_slope(), ts_delta_ms, |
| 249 | trendline_estimator_->num_of_deltas(), |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 250 | info.arrival_time_ms); |
terelius | afaef8b | 2016-11-17 03:48:18 -0800 | [diff] [blame^] | 251 | |
| 252 | } else { |
| 253 | kalman_estimator_->Update(t_delta, ts_delta_ms, size_delta, |
| 254 | detector_.State(), info.arrival_time_ms); |
| 255 | detector_.Detect(kalman_estimator_->offset(), ts_delta_ms, |
| 256 | kalman_estimator_->num_of_deltas(), |
| 257 | info.arrival_time_ms); |
| 258 | } |
stefan | 5ec85fb | 2016-09-29 04:19:38 -0700 | [diff] [blame] | 259 | } |
| 260 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 261 | int probing_bps = 0; |
| 262 | if (info.probe_cluster_id != PacketInfo::kNotAProbe) { |
| 263 | probing_bps = probe_bitrate_estimator_.HandleProbeAndEstimateBitrate(info); |
| 264 | } |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 265 | rtc::Optional<uint32_t> acked_bitrate_bps = |
| 266 | receiver_incoming_bitrate_.bitrate_bps(); |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 267 | // Currently overusing the bandwidth. |
| 268 | if (detector_.State() == kBwOverusing) { |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 269 | if (acked_bitrate_bps && |
| 270 | rate_control_.TimeToReduceFurther(now_ms, *acked_bitrate_bps)) { |
| 271 | result.updated = |
| 272 | UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps, |
| 273 | &result.target_bitrate_bps); |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 274 | } |
| 275 | } else if (probing_bps > 0) { |
| 276 | // No overuse, but probing measured a bitrate. |
terelius | 6ed592d | 2016-10-18 05:55:30 -0700 | [diff] [blame] | 277 | rate_control_.SetEstimate(probing_bps, info.arrival_time_ms); |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 278 | result.probe = true; |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 279 | result.updated = |
| 280 | UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps, |
| 281 | &result.target_bitrate_bps); |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 282 | } |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 283 | if (!result.updated && |
| 284 | (last_update_ms_ == -1 || |
terelius | 6ed592d | 2016-10-18 05:55:30 -0700 | [diff] [blame] | 285 | now_ms - last_update_ms_ > rate_control_.GetFeedbackInterval())) { |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 286 | result.updated = |
| 287 | UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps, |
| 288 | &result.target_bitrate_bps); |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 289 | } |
| 290 | if (result.updated) |
stefan | 5ec85fb | 2016-09-29 04:19:38 -0700 | [diff] [blame] | 291 | last_update_ms_ = now_ms; |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 292 | |
| 293 | return result; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 296 | bool DelayBasedBwe::UpdateEstimate(int64_t arrival_time_ms, |
| 297 | int64_t now_ms, |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 298 | rtc::Optional<uint32_t> acked_bitrate_bps, |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 299 | uint32_t* target_bitrate_bps) { |
terelius | afaef8b | 2016-11-17 03:48:18 -0800 | [diff] [blame^] | 300 | // TODO(terelius): RateControlInput::noise_var is deprecated and will be |
| 301 | // removed. In the meantime, we set it to zero. |
| 302 | const RateControlInput input(detector_.State(), acked_bitrate_bps, 0); |
terelius | 6ed592d | 2016-10-18 05:55:30 -0700 | [diff] [blame] | 303 | rate_control_.Update(&input, now_ms); |
| 304 | *target_bitrate_bps = rate_control_.UpdateBandwidthEstimate(now_ms); |
| 305 | return rate_control_.ValidEstimate(); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 306 | } |
| 307 | |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 308 | void DelayBasedBwe::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
terelius | 6ed592d | 2016-10-18 05:55:30 -0700 | [diff] [blame] | 309 | rate_control_.SetRtt(avg_rtt_ms); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 310 | } |
| 311 | |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 312 | bool DelayBasedBwe::LatestEstimate(std::vector<uint32_t>* ssrcs, |
| 313 | uint32_t* bitrate_bps) const { |
| 314 | // Currently accessed from both the process thread (see |
| 315 | // ModuleRtpRtcpImpl::Process()) and the configuration thread (see |
| 316 | // Call::GetStats()). Should in the future only be accessed from a single |
| 317 | // thread. |
| 318 | RTC_DCHECK(ssrcs); |
| 319 | RTC_DCHECK(bitrate_bps); |
terelius | 6ed592d | 2016-10-18 05:55:30 -0700 | [diff] [blame] | 320 | if (!rate_control_.ValidEstimate()) |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 321 | return false; |
philipel | 7522a28 | 2016-08-16 10:59:36 +0200 | [diff] [blame] | 322 | |
| 323 | *ssrcs = {kFixedSsrc}; |
terelius | 6ed592d | 2016-10-18 05:55:30 -0700 | [diff] [blame] | 324 | *bitrate_bps = rate_control_.LatestEstimate(); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 325 | return true; |
| 326 | } |
| 327 | |
| 328 | void DelayBasedBwe::SetMinBitrate(int min_bitrate_bps) { |
| 329 | // Called from both the configuration thread and the network thread. Shouldn't |
| 330 | // be called from the network thread in the future. |
terelius | 6ed592d | 2016-10-18 05:55:30 -0700 | [diff] [blame] | 331 | rate_control_.SetMinBitrate(min_bitrate_bps); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 332 | } |
| 333 | } // namespace webrtc |