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