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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 11 | #ifndef MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_ |
| 12 | #define MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_ |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 18 | #include "modules/congestion_controller/median_slope_estimator.h" |
| 19 | #include "modules/congestion_controller/probe_bitrate_estimator.h" |
| 20 | #include "modules/congestion_controller/trendline_estimator.h" |
| 21 | #include "modules/remote_bitrate_estimator/aimd_rate_control.h" |
| 22 | #include "modules/remote_bitrate_estimator/include/remote_bitrate_estimator.h" |
| 23 | #include "modules/remote_bitrate_estimator/inter_arrival.h" |
| 24 | #include "modules/remote_bitrate_estimator/overuse_detector.h" |
| 25 | #include "modules/remote_bitrate_estimator/overuse_estimator.h" |
| 26 | #include "rtc_base/checks.h" |
| 27 | #include "rtc_base/constructormagic.h" |
| 28 | #include "rtc_base/race_checker.h" |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 29 | |
| 30 | namespace webrtc { |
| 31 | |
terelius | 0baf55d | 2017-02-17 03:38:28 -0800 | [diff] [blame] | 32 | class RtcEventLog; |
| 33 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 34 | class DelayBasedBwe { |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 35 | public: |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 36 | static const int64_t kStreamTimeOutMs = 2000; |
| 37 | |
| 38 | struct Result { |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 39 | Result(); |
| 40 | Result(bool probe, uint32_t target_bitrate_bps); |
| 41 | ~Result(); |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 42 | bool updated; |
| 43 | bool probe; |
| 44 | uint32_t target_bitrate_bps; |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 45 | bool recovered_from_overuse; |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 46 | }; |
| 47 | |
elad.alon | 61ce37e | 2017-03-09 07:09:31 -0800 | [diff] [blame] | 48 | DelayBasedBwe(RtcEventLog* event_log, const Clock* clock); |
nisse | 76e62b0 | 2017-05-31 02:24:52 -0700 | [diff] [blame] | 49 | virtual ~DelayBasedBwe(); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 50 | |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 51 | Result IncomingPacketFeedbackVector( |
tschumim | 3fae628 | 2017-06-11 23:57:17 -0700 | [diff] [blame] | 52 | const std::vector<PacketFeedback>& packet_feedback_vector, |
| 53 | rtc::Optional<uint32_t> acked_bitrate_bps); |
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); |
terelius | 6737045 | 2017-04-19 09:15:04 -0700 | [diff] [blame] | 59 | int64_t GetExpectedBwePeriodMs() 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: |
michaelt | 8490f8a | 2017-04-20 10:10:10 -0700 | [diff] [blame] | 62 | void IncomingPacketFeedback(const PacketFeedback& packet_feedback); |
stefan | e3a5567 | 2017-02-13 09:08:22 -0800 | [diff] [blame] | 63 | Result OnLongFeedbackDelay(int64_t arrival_time_ms); |
tschumim | 3fae628 | 2017-06-11 23:57:17 -0700 | [diff] [blame] | 64 | Result MaybeUpdateEstimate(bool overusing, |
terelius | 3376c84 | 2017-07-31 04:23:25 -0700 | [diff] [blame] | 65 | rtc::Optional<uint32_t> acked_bitrate_bps, |
| 66 | bool request_probe); |
Irfan Sheriff | b2540bb | 2016-09-12 12:28:54 -0700 | [diff] [blame] | 67 | // Updates the current remote rate estimate and returns true if a valid |
| 68 | // estimate exists. |
michaelt | 8490f8a | 2017-04-20 10:10:10 -0700 | [diff] [blame] | 69 | bool UpdateEstimate(int64_t now_ms, |
Stefan Holmer | 492ee28 | 2016-10-27 17:19:20 +0200 | [diff] [blame] | 70 | rtc::Optional<uint32_t> acked_bitrate_bps, |
michaelt | 8490f8a | 2017-04-20 10:10:10 -0700 | [diff] [blame] | 71 | bool overusing, |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 72 | uint32_t* target_bitrate_bps); |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 73 | |
erikvarga | bf5a2fc | 2017-06-16 05:02:05 -0700 | [diff] [blame] | 74 | rtc::RaceChecker network_race_; |
terelius | 0baf55d | 2017-02-17 03:38:28 -0800 | [diff] [blame] | 75 | RtcEventLog* const event_log_; |
elad.alon | 61ce37e | 2017-03-09 07:09:31 -0800 | [diff] [blame] | 76 | const Clock* const clock_; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 77 | std::unique_ptr<InterArrival> inter_arrival_; |
terelius | afaef8b | 2016-11-17 03:48:18 -0800 | [diff] [blame] | 78 | std::unique_ptr<TrendlineEstimator> trendline_estimator_; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 79 | OveruseDetector detector_; |
philipel | 7522a28 | 2016-08-16 10:59:36 +0200 | [diff] [blame] | 80 | int64_t last_seen_packet_ms_; |
stefan | 64636dd | 2016-08-03 00:29:03 -0700 | [diff] [blame] | 81 | bool uma_recorded_; |
terelius | 6ed592d | 2016-10-18 05:55:30 -0700 | [diff] [blame] | 82 | AimdRateControl rate_control_; |
Stefan Holmer | 280de9e | 2016-09-30 10:06:51 +0200 | [diff] [blame] | 83 | ProbeBitrateEstimator probe_bitrate_estimator_; |
terelius | afaef8b | 2016-11-17 03:48:18 -0800 | [diff] [blame] | 84 | size_t trendline_window_size_; |
| 85 | double trendline_smoothing_coeff_; |
| 86 | double trendline_threshold_gain_; |
stefan | e3a5567 | 2017-02-13 09:08:22 -0800 | [diff] [blame] | 87 | int consecutive_delayed_feedbacks_; |
terelius | 0baf55d | 2017-02-17 03:38:28 -0800 | [diff] [blame] | 88 | uint32_t last_logged_bitrate_; |
| 89 | BandwidthUsage last_logged_state_; |
terelius | bf2c049 | 2017-05-02 01:04:26 -0700 | [diff] [blame] | 90 | bool in_sparse_update_experiment_; |
philipel | 863a826 | 2016-06-17 09:21:34 -0700 | [diff] [blame] | 91 | |
| 92 | RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(DelayBasedBwe); |
| 93 | }; |
| 94 | |
| 95 | } // namespace webrtc |
| 96 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame^] | 97 | #endif // MODULES_CONGESTION_CONTROLLER_DELAY_BASED_BWE_H_ |