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 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 << median_slope_threshold_gain_; | 247 << median_slope_threshold_gain_; |
248 } | 248 } |
249 if (!in_trendline_experiment_ && !in_median_slope_experiment_) { | 249 if (!in_trendline_experiment_ && !in_median_slope_experiment_) { |
250 LOG(LS_INFO) << "No overuse experiment enabled. Using Kalman filter."; | 250 LOG(LS_INFO) << "No overuse experiment enabled. Using Kalman filter."; |
251 } | 251 } |
252 | 252 |
253 network_thread_.DetachFromThread(); | 253 network_thread_.DetachFromThread(); |
254 } | 254 } |
255 | 255 |
256 DelayBasedBwe::Result DelayBasedBwe::IncomingPacketFeedbackVector( | 256 DelayBasedBwe::Result DelayBasedBwe::IncomingPacketFeedbackVector( |
257 const std::vector<PacketInfo>& packet_feedback_vector) { | 257 const std::vector<PacketFeedback>& packet_feedback_vector) { |
258 RTC_DCHECK(network_thread_.CalledOnValidThread()); | 258 RTC_DCHECK(network_thread_.CalledOnValidThread()); |
259 if (!uma_recorded_) { | 259 if (!uma_recorded_) { |
260 RTC_HISTOGRAM_ENUMERATION(kBweTypeHistogram, | 260 RTC_HISTOGRAM_ENUMERATION(kBweTypeHistogram, |
261 BweNames::kSendSideTransportSeqNum, | 261 BweNames::kSendSideTransportSeqNum, |
262 BweNames::kBweNamesMax); | 262 BweNames::kBweNamesMax); |
263 uma_recorded_ = true; | 263 uma_recorded_ = true; |
264 } | 264 } |
265 Result aggregated_result; | 265 Result aggregated_result; |
266 bool delayed_feedback = true; | 266 bool delayed_feedback = true; |
267 for (const auto& packet_info : packet_feedback_vector) { | 267 for (const auto& packet_feedback : packet_feedback_vector) { |
268 if (packet_info.send_time_ms < 0) | 268 if (packet_feedback.send_time_ms < 0) |
269 continue; | 269 continue; |
270 delayed_feedback = false; | 270 delayed_feedback = false; |
271 Result result = IncomingPacketInfo(packet_info); | 271 Result result = IncomingPacketFeedback(packet_feedback); |
272 if (result.updated) | 272 if (result.updated) |
273 aggregated_result = result; | 273 aggregated_result = result; |
274 } | 274 } |
275 if (delayed_feedback) { | 275 if (delayed_feedback) { |
276 ++consecutive_delayed_feedbacks_; | 276 ++consecutive_delayed_feedbacks_; |
277 } else { | 277 } else { |
278 consecutive_delayed_feedbacks_ = 0; | 278 consecutive_delayed_feedbacks_ = 0; |
279 } | 279 } |
280 if (consecutive_delayed_feedbacks_ >= kMaxConsecutiveFailedLookups) { | 280 if (consecutive_delayed_feedbacks_ >= kMaxConsecutiveFailedLookups) { |
281 aggregated_result = | 281 aggregated_result = |
(...skipping 13 matching lines...) Expand all Loading... |
295 arrival_time_ms); | 295 arrival_time_ms); |
296 Result result; | 296 Result result; |
297 result.updated = true; | 297 result.updated = true; |
298 result.probe = false; | 298 result.probe = false; |
299 result.target_bitrate_bps = rate_control_.LatestEstimate(); | 299 result.target_bitrate_bps = rate_control_.LatestEstimate(); |
300 LOG(LS_WARNING) << "Long feedback delay detected, reducing BWE to " | 300 LOG(LS_WARNING) << "Long feedback delay detected, reducing BWE to " |
301 << result.target_bitrate_bps; | 301 << result.target_bitrate_bps; |
302 return result; | 302 return result; |
303 } | 303 } |
304 | 304 |
305 DelayBasedBwe::Result DelayBasedBwe::IncomingPacketInfo( | 305 DelayBasedBwe::Result DelayBasedBwe::IncomingPacketFeedback( |
306 const PacketInfo& info) { | 306 const PacketFeedback& packet_feedback) { |
307 int64_t now_ms = clock_->TimeInMilliseconds(); | 307 int64_t now_ms = clock_->TimeInMilliseconds(); |
308 | 308 |
309 receiver_incoming_bitrate_.Update(info.arrival_time_ms, info.payload_size); | 309 receiver_incoming_bitrate_.Update(packet_feedback.arrival_time_ms, |
| 310 packet_feedback.payload_size); |
310 Result result; | 311 Result result; |
311 // Reset if the stream has timed out. | 312 // Reset if the stream has timed out. |
312 if (last_seen_packet_ms_ == -1 || | 313 if (last_seen_packet_ms_ == -1 || |
313 now_ms - last_seen_packet_ms_ > kStreamTimeOutMs) { | 314 now_ms - last_seen_packet_ms_ > kStreamTimeOutMs) { |
314 inter_arrival_.reset( | 315 inter_arrival_.reset( |
315 new InterArrival((kTimestampGroupLengthMs << kInterArrivalShift) / 1000, | 316 new InterArrival((kTimestampGroupLengthMs << kInterArrivalShift) / 1000, |
316 kTimestampToMs, true)); | 317 kTimestampToMs, true)); |
317 kalman_estimator_.reset(new OveruseEstimator(OverUseDetectorOptions())); | 318 kalman_estimator_.reset(new OveruseEstimator(OverUseDetectorOptions())); |
318 trendline_estimator_.reset(new TrendlineEstimator( | 319 trendline_estimator_.reset(new TrendlineEstimator( |
319 trendline_window_size_, trendline_smoothing_coeff_, | 320 trendline_window_size_, trendline_smoothing_coeff_, |
320 trendline_threshold_gain_)); | 321 trendline_threshold_gain_)); |
321 median_slope_estimator_.reset(new MedianSlopeEstimator( | 322 median_slope_estimator_.reset(new MedianSlopeEstimator( |
322 median_slope_window_size_, median_slope_threshold_gain_)); | 323 median_slope_window_size_, median_slope_threshold_gain_)); |
323 } | 324 } |
324 last_seen_packet_ms_ = now_ms; | 325 last_seen_packet_ms_ = now_ms; |
325 | 326 |
326 uint32_t send_time_24bits = | 327 uint32_t send_time_24bits = |
327 static_cast<uint32_t>( | 328 static_cast<uint32_t>( |
328 ((static_cast<uint64_t>(info.send_time_ms) << kAbsSendTimeFraction) + | 329 ((static_cast<uint64_t>(packet_feedback.send_time_ms) |
| 330 << kAbsSendTimeFraction) + |
329 500) / | 331 500) / |
330 1000) & | 332 1000) & |
331 0x00FFFFFF; | 333 0x00FFFFFF; |
332 // Shift up send time to use the full 32 bits that inter_arrival works with, | 334 // Shift up send time to use the full 32 bits that inter_arrival works with, |
333 // so wrapping works properly. | 335 // so wrapping works properly. |
334 uint32_t timestamp = send_time_24bits << kAbsSendTimeInterArrivalUpshift; | 336 uint32_t timestamp = send_time_24bits << kAbsSendTimeInterArrivalUpshift; |
335 | 337 |
336 uint32_t ts_delta = 0; | 338 uint32_t ts_delta = 0; |
337 int64_t t_delta = 0; | 339 int64_t t_delta = 0; |
338 int size_delta = 0; | 340 int size_delta = 0; |
339 if (inter_arrival_->ComputeDeltas(timestamp, info.arrival_time_ms, now_ms, | 341 if (inter_arrival_->ComputeDeltas(timestamp, packet_feedback.arrival_time_ms, |
340 info.payload_size, &ts_delta, &t_delta, | 342 now_ms, packet_feedback.payload_size, |
341 &size_delta)) { | 343 &ts_delta, &t_delta, &size_delta)) { |
342 double ts_delta_ms = (1000.0 * ts_delta) / (1 << kInterArrivalShift); | 344 double ts_delta_ms = (1000.0 * ts_delta) / (1 << kInterArrivalShift); |
343 if (in_trendline_experiment_) { | 345 if (in_trendline_experiment_) { |
344 trendline_estimator_->Update(t_delta, ts_delta_ms, info.arrival_time_ms); | 346 trendline_estimator_->Update(t_delta, ts_delta_ms, |
| 347 packet_feedback.arrival_time_ms); |
345 detector_.Detect(trendline_estimator_->trendline_slope(), ts_delta_ms, | 348 detector_.Detect(trendline_estimator_->trendline_slope(), ts_delta_ms, |
346 trendline_estimator_->num_of_deltas(), | 349 trendline_estimator_->num_of_deltas(), |
347 info.arrival_time_ms); | 350 packet_feedback.arrival_time_ms); |
348 } else if (in_median_slope_experiment_) { | 351 } else if (in_median_slope_experiment_) { |
349 median_slope_estimator_->Update(t_delta, ts_delta_ms, | 352 median_slope_estimator_->Update(t_delta, ts_delta_ms, |
350 info.arrival_time_ms); | 353 packet_feedback.arrival_time_ms); |
351 detector_.Detect(median_slope_estimator_->trendline_slope(), ts_delta_ms, | 354 detector_.Detect(median_slope_estimator_->trendline_slope(), ts_delta_ms, |
352 median_slope_estimator_->num_of_deltas(), | 355 median_slope_estimator_->num_of_deltas(), |
353 info.arrival_time_ms); | 356 packet_feedback.arrival_time_ms); |
354 } else { | 357 } else { |
355 kalman_estimator_->Update(t_delta, ts_delta_ms, size_delta, | 358 kalman_estimator_->Update(t_delta, ts_delta_ms, size_delta, |
356 detector_.State(), info.arrival_time_ms); | 359 detector_.State(), |
| 360 packet_feedback.arrival_time_ms); |
357 detector_.Detect(kalman_estimator_->offset(), ts_delta_ms, | 361 detector_.Detect(kalman_estimator_->offset(), ts_delta_ms, |
358 kalman_estimator_->num_of_deltas(), | 362 kalman_estimator_->num_of_deltas(), |
359 info.arrival_time_ms); | 363 packet_feedback.arrival_time_ms); |
360 } | 364 } |
361 } | 365 } |
362 | 366 |
363 int probing_bps = 0; | 367 int probing_bps = 0; |
364 if (info.pacing_info.probe_cluster_id != PacedPacketInfo::kNotAProbe) { | 368 if (packet_feedback.pacing_info.probe_cluster_id != |
365 probing_bps = probe_bitrate_estimator_.HandleProbeAndEstimateBitrate(info); | 369 PacedPacketInfo::kNotAProbe) { |
| 370 probing_bps = |
| 371 probe_bitrate_estimator_.HandleProbeAndEstimateBitrate(packet_feedback); |
366 } | 372 } |
367 rtc::Optional<uint32_t> acked_bitrate_bps = | 373 rtc::Optional<uint32_t> acked_bitrate_bps = |
368 receiver_incoming_bitrate_.bitrate_bps(); | 374 receiver_incoming_bitrate_.bitrate_bps(); |
369 // Currently overusing the bandwidth. | 375 // Currently overusing the bandwidth. |
370 if (detector_.State() == kBwOverusing) { | 376 if (detector_.State() == kBwOverusing) { |
371 if (acked_bitrate_bps && | 377 if (acked_bitrate_bps && |
372 rate_control_.TimeToReduceFurther(now_ms, *acked_bitrate_bps)) { | 378 rate_control_.TimeToReduceFurther(now_ms, *acked_bitrate_bps)) { |
373 result.updated = | 379 result.updated = |
374 UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps, | 380 UpdateEstimate(packet_feedback.arrival_time_ms, now_ms, |
375 &result.target_bitrate_bps); | 381 acked_bitrate_bps, &result.target_bitrate_bps); |
376 } | 382 } |
377 } else if (probing_bps > 0) { | 383 } else if (probing_bps > 0) { |
378 // No overuse, but probing measured a bitrate. | 384 // No overuse, but probing measured a bitrate. |
379 rate_control_.SetEstimate(probing_bps, info.arrival_time_ms); | 385 rate_control_.SetEstimate(probing_bps, packet_feedback.arrival_time_ms); |
380 result.probe = true; | 386 result.probe = true; |
381 result.updated = | 387 result.updated = |
382 UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps, | 388 UpdateEstimate(packet_feedback.arrival_time_ms, now_ms, |
383 &result.target_bitrate_bps); | 389 acked_bitrate_bps, &result.target_bitrate_bps); |
384 } | 390 } |
385 if (!result.updated && | 391 if (!result.updated && |
386 (last_update_ms_ == -1 || | 392 (last_update_ms_ == -1 || |
387 now_ms - last_update_ms_ > rate_control_.GetFeedbackInterval())) { | 393 now_ms - last_update_ms_ > rate_control_.GetFeedbackInterval())) { |
388 result.updated = | 394 result.updated = |
389 UpdateEstimate(info.arrival_time_ms, now_ms, acked_bitrate_bps, | 395 UpdateEstimate(packet_feedback.arrival_time_ms, now_ms, |
390 &result.target_bitrate_bps); | 396 acked_bitrate_bps, &result.target_bitrate_bps); |
391 } | 397 } |
392 if (result.updated) { | 398 if (result.updated) { |
393 last_update_ms_ = now_ms; | 399 last_update_ms_ = now_ms; |
394 BWE_TEST_LOGGING_PLOT(1, "target_bitrate_bps", now_ms, | 400 BWE_TEST_LOGGING_PLOT(1, "target_bitrate_bps", now_ms, |
395 result.target_bitrate_bps); | 401 result.target_bitrate_bps); |
396 if (event_log_ && (result.target_bitrate_bps != last_logged_bitrate_ || | 402 if (event_log_ && (result.target_bitrate_bps != last_logged_bitrate_ || |
397 detector_.State() != last_logged_state_)) { | 403 detector_.State() != last_logged_state_)) { |
398 event_log_->LogDelayBasedBweUpdate(result.target_bitrate_bps, | 404 event_log_->LogDelayBasedBweUpdate(result.target_bitrate_bps, |
399 detector_.State()); | 405 detector_.State()); |
400 last_logged_bitrate_ = result.target_bitrate_bps; | 406 last_logged_bitrate_ = result.target_bitrate_bps; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 void DelayBasedBwe::SetMinBitrate(int min_bitrate_bps) { | 451 void DelayBasedBwe::SetMinBitrate(int min_bitrate_bps) { |
446 // Called from both the configuration thread and the network thread. Shouldn't | 452 // Called from both the configuration thread and the network thread. Shouldn't |
447 // be called from the network thread in the future. | 453 // be called from the network thread in the future. |
448 rate_control_.SetMinBitrate(min_bitrate_bps); | 454 rate_control_.SetMinBitrate(min_bitrate_bps); |
449 } | 455 } |
450 | 456 |
451 int64_t DelayBasedBwe::GetProbingIntervalMs() const { | 457 int64_t DelayBasedBwe::GetProbingIntervalMs() const { |
452 return probing_interval_estimator_.GetIntervalMs(); | 458 return probing_interval_estimator_.GetIntervalMs(); |
453 } | 459 } |
454 } // namespace webrtc | 460 } // namespace webrtc |
OLD | NEW |