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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 | 124 |
125 namespace webrtc { | 125 namespace webrtc { |
126 | 126 |
127 DelayBasedBwe::BitrateEstimator::BitrateEstimator() | 127 DelayBasedBwe::BitrateEstimator::BitrateEstimator() |
128 : sum_(0), | 128 : sum_(0), |
129 current_win_ms_(0), | 129 current_win_ms_(0), |
130 prev_time_ms_(-1), | 130 prev_time_ms_(-1), |
131 bitrate_estimate_(-1.0f), | 131 bitrate_estimate_(-1.0f), |
132 bitrate_estimate_var_(50.0f), | 132 bitrate_estimate_var_(50.0f), |
133 old_estimator_(kBitrateWindowMs, 8000), | 133 old_estimator_(kBitrateWindowMs, 8000), |
134 in_experiment_(BitrateEstimateExperimentIsEnabled()) {} | 134 in_experiment_(BitrateEstimateExperimentIsEnabled()), |
135 last_result_was_valid_(false) {} | |
135 | 136 |
136 void DelayBasedBwe::BitrateEstimator::Update(int64_t now_ms, int bytes) { | 137 void DelayBasedBwe::BitrateEstimator::Update(int64_t now_ms, int bytes) { |
137 if (!in_experiment_) { | 138 if (!in_experiment_) { |
138 old_estimator_.Update(bytes, now_ms); | 139 old_estimator_.Update(bytes, now_ms); |
139 rtc::Optional<uint32_t> rate = old_estimator_.Rate(now_ms); | 140 rtc::Optional<uint32_t> rate = old_estimator_.Rate(now_ms); |
140 bitrate_estimate_ = -1.0f; | 141 bitrate_estimate_ = -1.0f; |
141 if (rate) | 142 if (rate) { |
142 bitrate_estimate_ = *rate / 1000.0f; | 143 bitrate_estimate_ = *rate / 1000.0f; |
144 last_result_was_valid_ = true; | |
145 } else if (last_result_was_valid_) { | |
146 old_estimator_.Reset(); | |
147 last_result_was_valid_ = false; | |
148 } | |
143 return; | 149 return; |
144 } | 150 } |
145 int rate_window_ms = kRateWindowMs; | 151 int rate_window_ms = kRateWindowMs; |
146 // We use a larger window at the beginning to get a more stable sample that | 152 // We use a larger window at the beginning to get a more stable sample that |
147 // we can use to initialize the estimate. | 153 // we can use to initialize the estimate. |
148 if (bitrate_estimate_ < 0.f) | 154 if (bitrate_estimate_ < 0.f) |
149 rate_window_ms = kInitialRateWindowMs; | 155 rate_window_ms = kInitialRateWindowMs; |
150 float bitrate_sample = UpdateWindow(now_ms, bytes, rate_window_ms); | 156 float bitrate_sample = UpdateWindow(now_ms, bytes, rate_window_ms); |
151 if (bitrate_sample < 0.0f) | 157 if (bitrate_sample < 0.0f) |
152 return; | 158 return; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 | 214 |
209 DelayBasedBwe::DelayBasedBwe(Clock* clock) | 215 DelayBasedBwe::DelayBasedBwe(Clock* clock) |
210 : in_trendline_experiment_(TrendlineFilterExperimentIsEnabled()), | 216 : in_trendline_experiment_(TrendlineFilterExperimentIsEnabled()), |
211 in_median_slope_experiment_(MedianSlopeFilterExperimentIsEnabled()), | 217 in_median_slope_experiment_(MedianSlopeFilterExperimentIsEnabled()), |
212 clock_(clock), | 218 clock_(clock), |
213 inter_arrival_(), | 219 inter_arrival_(), |
214 kalman_estimator_(), | 220 kalman_estimator_(), |
215 trendline_estimator_(), | 221 trendline_estimator_(), |
216 detector_(), | 222 detector_(), |
217 receiver_incoming_bitrate_(), | 223 receiver_incoming_bitrate_(), |
218 last_update_ms_(-1), | |
219 last_seen_packet_ms_(-1), | 224 last_seen_packet_ms_(-1), |
220 uma_recorded_(false), | 225 uma_recorded_(false), |
221 trendline_window_size_(kDefaultTrendlineWindowSize), | 226 trendline_window_size_(kDefaultTrendlineWindowSize), |
222 trendline_smoothing_coeff_(kDefaultTrendlineSmoothingCoeff), | 227 trendline_smoothing_coeff_(kDefaultTrendlineSmoothingCoeff), |
223 trendline_threshold_gain_(kDefaultTrendlineThresholdGain), | 228 trendline_threshold_gain_(kDefaultTrendlineThresholdGain), |
224 probing_interval_estimator_(&rate_control_), | 229 probing_interval_estimator_(&rate_control_), |
225 median_slope_window_size_(kDefaultMedianSlopeWindowSize), | 230 median_slope_window_size_(kDefaultMedianSlopeWindowSize), |
226 median_slope_threshold_gain_(kDefaultMedianSlopeThresholdGain) { | 231 median_slope_threshold_gain_(kDefaultMedianSlopeThresholdGain) { |
227 if (in_trendline_experiment_) { | 232 if (in_trendline_experiment_) { |
228 ReadTrendlineFilterExperimentParameters(&trendline_window_size_, | 233 ReadTrendlineFilterExperimentParameters(&trendline_window_size_, |
(...skipping 13 matching lines...) Expand all Loading... | |
242 RTC_DCHECK(network_thread_.CalledOnValidThread()); | 247 RTC_DCHECK(network_thread_.CalledOnValidThread()); |
243 if (!uma_recorded_) { | 248 if (!uma_recorded_) { |
244 RTC_HISTOGRAM_ENUMERATION(kBweTypeHistogram, | 249 RTC_HISTOGRAM_ENUMERATION(kBweTypeHistogram, |
245 BweNames::kSendSideTransportSeqNum, | 250 BweNames::kSendSideTransportSeqNum, |
246 BweNames::kBweNamesMax); | 251 BweNames::kBweNamesMax); |
247 uma_recorded_ = true; | 252 uma_recorded_ = true; |
248 } | 253 } |
249 Result aggregated_result; | 254 Result aggregated_result; |
250 for (const auto& packet_info : packet_feedback_vector) { | 255 for (const auto& packet_info : packet_feedback_vector) { |
251 Result result = IncomingPacketInfo(packet_info); | 256 Result result = IncomingPacketInfo(packet_info); |
252 if (result.updated) | 257 aggregated_result.overusing |= result.overusing; |
253 aggregated_result = result; | 258 if (result.probe) { |
259 aggregated_result.probe = true; | |
260 aggregated_result.target_bitrate_bps = result.target_bitrate_bps; | |
261 } | |
254 } | 262 } |
263 MaybeUpdateEstimate(&aggregated_result); | |
255 return aggregated_result; | 264 return aggregated_result; |
256 } | 265 } |
257 | 266 |
258 DelayBasedBwe::Result DelayBasedBwe::IncomingPacketInfo( | 267 DelayBasedBwe::Result DelayBasedBwe::IncomingPacketInfo( |
259 const PacketInfo& info) { | 268 const PacketInfo& info) { |
260 int64_t now_ms = clock_->TimeInMilliseconds(); | 269 int64_t now_ms = clock_->TimeInMilliseconds(); |
261 | 270 |
262 receiver_incoming_bitrate_.Update(info.arrival_time_ms, info.payload_size); | 271 receiver_incoming_bitrate_.Update(info.arrival_time_ms, info.payload_size); |
263 Result result; | 272 Result result; |
264 // Reset if the stream has timed out. | 273 // Reset if the stream has timed out. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
306 info.arrival_time_ms); | 315 info.arrival_time_ms); |
307 } else { | 316 } else { |
308 kalman_estimator_->Update(t_delta, ts_delta_ms, size_delta, | 317 kalman_estimator_->Update(t_delta, ts_delta_ms, size_delta, |
309 detector_.State(), info.arrival_time_ms); | 318 detector_.State(), info.arrival_time_ms); |
310 detector_.Detect(kalman_estimator_->offset(), ts_delta_ms, | 319 detector_.Detect(kalman_estimator_->offset(), ts_delta_ms, |
311 kalman_estimator_->num_of_deltas(), | 320 kalman_estimator_->num_of_deltas(), |
312 info.arrival_time_ms); | 321 info.arrival_time_ms); |
313 } | 322 } |
314 } | 323 } |
315 | 324 |
316 int probing_bps = 0; | |
317 if (info.probe_cluster_id != PacketInfo::kNotAProbe) { | 325 if (info.probe_cluster_id != PacketInfo::kNotAProbe) { |
318 probing_bps = probe_bitrate_estimator_.HandleProbeAndEstimateBitrate(info); | 326 int probing_bps = |
319 } | 327 probe_bitrate_estimator_.HandleProbeAndEstimateBitrate(info); |
stefan-webrtc
2017/02/24 14:25:26
I wonder if it makes sense to also split this up,
michaelt
2017/02/27 10:45:41
In general I like the idea.
I took a look how we c
stefan-webrtc
2017/03/07 12:09:33
Now you lost me, which GetEstimateBitrate? Are we
michaelt
2017/03/07 14:35:53
Yea exactly. Sorry if i was not clear enough.
void
stefan-webrtc
2017/03/07 15:56:06
But can't we just get the last probe estimation wi
stefan-webrtc
2017/03/07 15:57:30
I'm thinking basically to have HandleProbeAndEstim
| |
320 rtc::Optional<uint32_t> acked_bitrate_bps = | 328 if (probing_bps > 0) { |
321 receiver_incoming_bitrate_.bitrate_bps(); | 329 result.target_bitrate_bps = probing_bps; |
322 // Currently overusing the bandwidth. | 330 result.probe = true; |
323 if (detector_.State() == kBwOverusing) { | |
324 if (acked_bitrate_bps && | |
325 rate_control_.TimeToReduceFurther(now_ms, *acked_bitrate_bps)) { | |
326 result.updated = | |
327 UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps, | |
328 &result.target_bitrate_bps); | |
329 } | 331 } |
330 } else if (probing_bps > 0) { | |
331 // No overuse, but probing measured a bitrate. | |
332 rate_control_.SetEstimate(probing_bps, info.arrival_time_ms); | |
333 result.probe = true; | |
334 result.updated = | |
335 UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps, | |
336 &result.target_bitrate_bps); | |
337 } | |
338 if (!result.updated && | |
339 (last_update_ms_ == -1 || | |
340 now_ms - last_update_ms_ > rate_control_.GetFeedbackInterval())) { | |
341 result.updated = | |
342 UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps, | |
343 &result.target_bitrate_bps); | |
344 } | |
345 if (result.updated) { | |
346 last_update_ms_ = now_ms; | |
347 BWE_TEST_LOGGING_PLOT(1, "target_bitrate_bps", now_ms, | |
348 result.target_bitrate_bps); | |
349 } | 332 } |
350 | 333 |
334 result.overusing = detector_.State() == kBwOverusing; | |
351 return result; | 335 return result; |
352 } | 336 } |
353 | 337 |
354 bool DelayBasedBwe::UpdateEstimate(int64_t arrival_time_ms, | 338 void DelayBasedBwe::MaybeUpdateEstimate(Result* result) { |
355 int64_t now_ms, | 339 RTC_DCHECK(result); |
340 rtc::Optional<uint32_t> acked_bitrate_bps = | |
341 receiver_incoming_bitrate_.bitrate_bps(); | |
342 int64_t now_ms = clock_->TimeInMilliseconds(); | |
343 // Currently overusing the bandwidth. | |
344 if (result->overusing) { | |
345 if (acked_bitrate_bps && | |
346 rate_control_.TimeToReduceFurther(now_ms, *acked_bitrate_bps)) { | |
347 result->updated = UpdateEstimate(now_ms, acked_bitrate_bps, result); | |
348 } | |
349 } else { | |
350 if (result->probe) { | |
351 rate_control_.SetEstimate(result->target_bitrate_bps, now_ms); | |
352 } | |
353 result->updated = UpdateEstimate(now_ms, acked_bitrate_bps, result); | |
354 } | |
355 } | |
356 | |
357 bool DelayBasedBwe::UpdateEstimate(int64_t now_ms, | |
356 rtc::Optional<uint32_t> acked_bitrate_bps, | 358 rtc::Optional<uint32_t> acked_bitrate_bps, |
357 uint32_t* target_bitrate_bps) { | 359 Result* result) { |
358 // TODO(terelius): RateControlInput::noise_var is deprecated and will be | 360 // TODO(terelius): RateControlInput::noise_var is deprecated and will be |
359 // removed. In the meantime, we set it to zero. | 361 // removed. In the meantime, we set it to zero. |
360 const RateControlInput input(detector_.State(), acked_bitrate_bps, 0); | 362 const RateControlInput input( |
363 result->overusing ? kBwOverusing : detector_.State(), acked_bitrate_bps, | |
364 0); | |
361 rate_control_.Update(&input, now_ms); | 365 rate_control_.Update(&input, now_ms); |
362 *target_bitrate_bps = rate_control_.UpdateBandwidthEstimate(now_ms); | 366 result->target_bitrate_bps = rate_control_.UpdateBandwidthEstimate(now_ms); |
367 BWE_TEST_LOGGING_PLOT(1, "target_bitrate_bps", now_ms, *target_bitrate_bps); | |
363 return rate_control_.ValidEstimate(); | 368 return rate_control_.ValidEstimate(); |
364 } | 369 } |
365 | 370 |
366 void DelayBasedBwe::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { | 371 void DelayBasedBwe::OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms) { |
367 rate_control_.SetRtt(avg_rtt_ms); | 372 rate_control_.SetRtt(avg_rtt_ms); |
368 } | 373 } |
369 | 374 |
370 bool DelayBasedBwe::LatestEstimate(std::vector<uint32_t>* ssrcs, | 375 bool DelayBasedBwe::LatestEstimate(std::vector<uint32_t>* ssrcs, |
371 uint32_t* bitrate_bps) const { | 376 uint32_t* bitrate_bps) const { |
372 // Currently accessed from both the process thread (see | 377 // Currently accessed from both the process thread (see |
(...skipping 13 matching lines...) Expand all Loading... | |
386 void DelayBasedBwe::SetMinBitrate(int min_bitrate_bps) { | 391 void DelayBasedBwe::SetMinBitrate(int min_bitrate_bps) { |
387 // Called from both the configuration thread and the network thread. Shouldn't | 392 // Called from both the configuration thread and the network thread. Shouldn't |
388 // be called from the network thread in the future. | 393 // be called from the network thread in the future. |
389 rate_control_.SetMinBitrate(min_bitrate_bps); | 394 rate_control_.SetMinBitrate(min_bitrate_bps); |
390 } | 395 } |
391 | 396 |
392 int64_t DelayBasedBwe::GetProbingIntervalMs() const { | 397 int64_t DelayBasedBwe::GetProbingIntervalMs() const { |
393 return probing_interval_estimator_.GetIntervalMs(); | 398 return probing_interval_estimator_.GetIntervalMs(); |
394 } | 399 } |
395 } // namespace webrtc | 400 } // namespace webrtc |
OLD | NEW |