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 | #ifndef WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_ |
| 12 | #define WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_ |
| 13 | |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 14 | #include <memory> |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 15 | #include <utility> |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 16 | #include <vector> |
| 17 | |
| 18 | #include "webrtc/base/checks.h" |
| 19 | #include "webrtc/base/constructormagic.h" |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 20 | #include "webrtc/base/rate_statistics.h" |
| 21 | #include "webrtc/base/thread_checker.h" |
terelius | 5a38836 | 2016-12-09 05:50:01 -0800 | [diff] [blame] | 22 | #include "webrtc/modules/congestion_controller/median_slope_estimator.h" |
philipel | 7522a28 | 2016-08-16 10:59:36 +0200 | [diff] [blame] | 23 | #include "webrtc/modules/congestion_controller/probe_bitrate_estimator.h" |
minyue | 78b4d56 | 2016-11-30 04:47:39 -0800 | [diff] [blame] | 24 | #include "webrtc/modules/congestion_controller/probing_interval_estimator.h" |
terelius | afaef8b | 2016-11-17 03:48:18 -0800 | [diff] [blame] | 25 | #include "webrtc/modules/congestion_controller/trendline_estimator.h" |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 26 | #include "webrtc/modules/remote_bitrate_estimator/aimd_rate_control.h" |
| 27 | #include "webrtc/modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h" |
| 28 | #include "webrtc/modules/remote_bitrate_estimator/inter_arrival.h" |
| 29 | #include "webrtc/modules/remote_bitrate_estimator/overuse_detector.h" |
| 30 | #include "webrtc/modules/remote_bitrate_estimator/overuse_estimator.h" |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 31 | |
| 32 | namespace webrtc { |
| 33 | |
terelius | 0baf55d | 2017-02-17 03:38:28 -0800 | [diff] [blame] | 34 | class RtcEventLog; |
| 35 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 36 | class DelayBasedBwe { |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 37 | public: |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 38 | static const int64_t kStreamTimeOutMs = 2000; |
| 39 | |
| 40 | struct Result { |
| 41 | Result() : updated(false), probe(false), target_bitrate_bps(0) {} |
| 42 | Result(bool probe, uint32_t target_bitrate_bps) |
| 43 | : updated(true), probe(probe), target_bitrate_bps(target_bitrate_bps) {} |
| 44 | bool updated; |
| 45 | bool probe; |
| 46 | uint32_t target_bitrate_bps; |
| 47 | }; |
| 48 | |
terelius | 0baf55d | 2017-02-17 03:38:28 -0800 | [diff] [blame] | 49 | DelayBasedBwe(RtcEventLog* event_log, Clock* clock); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 50 | virtual ~DelayBasedBwe() {} |
| 51 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 52 | Result IncomingPacketFeedbackVector( |
elad.alon | f949000 | 2017-03-06 05:32:21 -0800 | [diff] [blame^] | 53 | const std::vector<PacketFeedback>& packet_feedback_vector); |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 54 | void OnRttUpdate(int64_t avg_rtt_ms, int64_t max_rtt_ms); |
philipel | 7522a28 | 2016-08-16 10:59:36 +0200 | [diff] [blame] | 55 | bool LatestEstimate(std::vector<uint32_t>* ssrcs, |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 56 | uint32_t* bitrate_bps) const; |
stefan | 5a2c506 | 2017-01-27 06:43:18 -0800 | [diff] [blame] | 57 | void SetStartBitrate(int start_bitrate_bps); |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 58 | void SetMinBitrate(int min_bitrate_bps); |
minyue | 78b4d56 | 2016-11-30 04:47:39 -0800 | [diff] [blame] | 59 | int64_t GetProbingIntervalMs() const; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 60 | |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 61 | private: |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 62 | // Computes a bayesian estimate of the throughput given acks containing |
| 63 | // the arrival time and payload size. Samples which are far from the current |
| 64 | // estimate or are based on few packets are given a smaller weight, as they |
| 65 | // are considered to be more likely to have been caused by, e.g., delay spikes |
| 66 | // unrelated to congestion. |
| 67 | class BitrateEstimator { |
| 68 | public: |
| 69 | BitrateEstimator(); |
| 70 | void Update(int64_t now_ms, int bytes); |
| 71 | rtc::Optional<uint32_t> bitrate_bps() const; |
| 72 | |
| 73 | private: |
| 74 | float UpdateWindow(int64_t now_ms, int bytes, int rate_window_ms); |
| 75 | int sum_; |
| 76 | int64_t current_win_ms_; |
| 77 | int64_t prev_time_ms_; |
| 78 | float bitrate_estimate_; |
| 79 | float bitrate_estimate_var_; |
| 80 | RateStatistics old_estimator_; |
| 81 | const bool in_experiment_; |
| 82 | }; |
| 83 | |
elad.alon | f949000 | 2017-03-06 05:32:21 -0800 | [diff] [blame^] | 84 | Result IncomingPacketFeedback(const PacketFeedback& packet_feedback); |
stefan | e3a5567 | 2017-02-13 09:08:22 -0800 | [diff] [blame] | 85 | Result OnLongFeedbackDelay(int64_t arrival_time_ms); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 86 | // Updates the current remote rate estimate and returns true if a valid |
| 87 | // estimate exists. |
| 88 | bool UpdateEstimate(int64_t packet_arrival_time_ms, |
| 89 | int64_t now_ms, |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 90 | rtc::Optional<uint32_t> acked_bitrate_bps, |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 91 | uint32_t* target_bitrate_bps); |
terelius | 5a38836 | 2016-12-09 05:50:01 -0800 | [diff] [blame] | 92 | const bool in_trendline_experiment_; |
| 93 | const bool in_median_slope_experiment_; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 94 | |
| 95 | rtc::ThreadChecker network_thread_; |
terelius | 0baf55d | 2017-02-17 03:38:28 -0800 | [diff] [blame] | 96 | RtcEventLog* const event_log_; |
stefan | 5e12d36 | 2016-07-11 01:44:02 -0700 | [diff] [blame] | 97 | Clock* const clock_; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 98 | std::unique_ptr<InterArrival> inter_arrival_; |
terelius | afaef8b | 2016-11-17 03:48:18 -0800 | [diff] [blame] | 99 | std::unique_ptr<OveruseEstimator> kalman_estimator_; |
| 100 | std::unique_ptr<TrendlineEstimator> trendline_estimator_; |
terelius | 5a38836 | 2016-12-09 05:50:01 -0800 | [diff] [blame] | 101 | std::unique_ptr<MedianSlopeEstimator> median_slope_estimator_; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 102 | OveruseDetector detector_; |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 103 | BitrateEstimator receiver_incoming_bitrate_; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 104 | int64_t last_update_ms_; |
philipel | 7522a28 | 2016-08-16 10:59:36 +0200 | [diff] [blame] | 105 | int64_t last_seen_packet_ms_; |
stefan | 64636dd | 2016-08-03 00:29:03 -0700 | [diff] [blame] | 106 | bool uma_recorded_; |
terelius | 6ed592d | 2016-10-18 05:55:30 -0700 | [diff] [blame] | 107 | AimdRateControl rate_control_; |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 108 | ProbeBitrateEstimator probe_bitrate_estimator_; |
terelius | afaef8b | 2016-11-17 03:48:18 -0800 | [diff] [blame] | 109 | size_t trendline_window_size_; |
| 110 | double trendline_smoothing_coeff_; |
| 111 | double trendline_threshold_gain_; |
minyue | 78b4d56 | 2016-11-30 04:47:39 -0800 | [diff] [blame] | 112 | ProbingIntervalEstimator probing_interval_estimator_; |
terelius | 5a38836 | 2016-12-09 05:50:01 -0800 | [diff] [blame] | 113 | size_t median_slope_window_size_; |
| 114 | double median_slope_threshold_gain_; |
stefan | e3a5567 | 2017-02-13 09:08:22 -0800 | [diff] [blame] | 115 | int consecutive_delayed_feedbacks_; |
terelius | 0baf55d | 2017-02-17 03:38:28 -0800 | [diff] [blame] | 116 | uint32_t last_logged_bitrate_; |
| 117 | BandwidthUsage last_logged_state_; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 118 | |
| 119 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(DelayBasedBwe); |
| 120 | }; |
| 121 | |
| 122 | } // namespace webrtc |
| 123 | |
| 124 | #endif // WEBRTC_MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_ |