pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 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 | * FEC and NACK added bitrate is handled outside class |
| 11 | */ |
| 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #ifndef MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_ |
| 14 | #define MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_ |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 15 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 16 | #include <stdint.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 17 | |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 18 | #include <deque> |
jbauch | f91e6d0 | 2016-01-24 23:05:21 -0800 | [diff] [blame] | 19 | #include <utility> |
| 20 | #include <vector> |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 21 | |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 22 | #include "absl/types/optional.h" |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 23 | #include "api/transport/network_types.h" |
| 24 | #include "api/units/data_rate.h" |
| 25 | #include "api/units/time_delta.h" |
| 26 | #include "api/units/timestamp.h" |
Christoffer Rodbro | 3a83748 | 2018-11-19 15:30:23 +0100 | [diff] [blame] | 27 | #include "modules/bitrate_controller/loss_based_bandwidth_estimation.h" |
Sebastian Jansson | 2e068e8 | 2018-10-08 12:49:53 +0200 | [diff] [blame] | 28 | #include "rtc_base/experiments/field_trial_parser.h" |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 29 | |
| 30 | namespace webrtc { |
terelius | 006d93d | 2015-11-05 12:02:15 -0800 | [diff] [blame] | 31 | |
| 32 | class RtcEventLog; |
| 33 | |
Sebastian Jansson | 57f3ad0 | 2018-11-23 14:49:18 +0100 | [diff] [blame] | 34 | class LinkCapacityTracker { |
| 35 | public: |
| 36 | LinkCapacityTracker(); |
| 37 | ~LinkCapacityTracker(); |
| 38 | void OnOveruse(DataRate acknowledged_rate, Timestamp at_time); |
| 39 | void OnStartingRate(DataRate start_rate); |
| 40 | void OnRateUpdate(DataRate acknowledged, Timestamp at_time); |
| 41 | void OnRttBackoff(DataRate backoff_rate, Timestamp at_time); |
| 42 | DataRate estimate() const; |
| 43 | |
| 44 | private: |
| 45 | FieldTrialParameter<TimeDelta> tracking_rate; |
| 46 | double capacity_estimate_bps_ = 0; |
| 47 | Timestamp last_link_capacity_update_ = Timestamp::MinusInfinity(); |
| 48 | }; |
| 49 | |
Sebastian Jansson | 2464348 | 2018-11-14 14:19:45 +0100 | [diff] [blame] | 50 | class RttBasedBackoff { |
| 51 | public: |
| 52 | RttBasedBackoff(); |
| 53 | ~RttBasedBackoff(); |
| 54 | void OnRouteChange(); |
| 55 | void UpdatePropagationRtt(Timestamp at_time, TimeDelta propagation_rtt); |
Christoffer Rodbro | 5f6abcf | 2019-02-08 11:00:10 +0100 | [diff] [blame] | 56 | TimeDelta CorrectedRtt(Timestamp at_time) const; |
Sebastian Jansson | 2464348 | 2018-11-14 14:19:45 +0100 | [diff] [blame] | 57 | |
| 58 | FieldTrialParameter<TimeDelta> rtt_limit_; |
| 59 | FieldTrialParameter<double> drop_fraction_; |
| 60 | FieldTrialParameter<TimeDelta> drop_interval_; |
| 61 | FieldTrialFlag persist_on_route_change_; |
Christoffer Rodbro | 5f6abcf | 2019-02-08 11:00:10 +0100 | [diff] [blame] | 62 | FieldTrialParameter<bool> safe_timeout_; |
Christoffer Rodbro | 8ea0238 | 2019-02-28 15:15:35 +0100 | [diff] [blame] | 63 | FieldTrialParameter<DataRate> bandwidth_floor_; |
Sebastian Jansson | 2464348 | 2018-11-14 14:19:45 +0100 | [diff] [blame] | 64 | |
| 65 | public: |
| 66 | Timestamp last_propagation_rtt_update_; |
| 67 | TimeDelta last_propagation_rtt_; |
Christoffer Rodbro | 5f6abcf | 2019-02-08 11:00:10 +0100 | [diff] [blame] | 68 | Timestamp last_packet_sent_; |
Sebastian Jansson | 2e068e8 | 2018-10-08 12:49:53 +0200 | [diff] [blame] | 69 | }; |
| 70 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 71 | class SendSideBandwidthEstimation { |
| 72 | public: |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 73 | SendSideBandwidthEstimation() = delete; |
| 74 | explicit SendSideBandwidthEstimation(RtcEventLog* event_log); |
Sebastian Jansson | 2e068e8 | 2018-10-08 12:49:53 +0200 | [diff] [blame] | 75 | ~SendSideBandwidthEstimation(); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 76 | |
Sebastian Jansson | 2464348 | 2018-11-14 14:19:45 +0100 | [diff] [blame] | 77 | void OnRouteChange(); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 78 | void CurrentEstimate(int* bitrate, uint8_t* loss, int64_t* rtt) const; |
Sebastian Jansson | 57f3ad0 | 2018-11-23 14:49:18 +0100 | [diff] [blame] | 79 | DataRate GetEstimatedLinkCapacity() const; |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 80 | // Call periodically to update estimate. |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 81 | void UpdateEstimate(Timestamp at_time); |
Christoffer Rodbro | 5f6abcf | 2019-02-08 11:00:10 +0100 | [diff] [blame] | 82 | void OnSentPacket(const SentPacket& sent_packet); |
Sebastian Jansson | 2464348 | 2018-11-14 14:19:45 +0100 | [diff] [blame] | 83 | void UpdatePropagationRtt(Timestamp at_time, TimeDelta propagation_rtt); |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 84 | |
andresp@webrtc.org | 07bc734 | 2014-03-21 16:51:01 +0000 | [diff] [blame] | 85 | // Call when we receive a RTCP message with TMMBR or REMB. |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 86 | void UpdateReceiverEstimate(Timestamp at_time, DataRate bandwidth); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 87 | |
stefan | 32f8154 | 2016-01-20 07:13:58 -0800 | [diff] [blame] | 88 | // Call when a new delay-based estimate is available. |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 89 | void UpdateDelayBasedEstimate(Timestamp at_time, DataRate bitrate); |
stefan | 32f8154 | 2016-01-20 07:13:58 -0800 | [diff] [blame] | 90 | |
andresp@webrtc.org | 07bc734 | 2014-03-21 16:51:01 +0000 | [diff] [blame] | 91 | // Call when we receive a RTCP message with a ReceiveBlock. |
| 92 | void UpdateReceiverBlock(uint8_t fraction_loss, |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 93 | TimeDelta rtt_ms, |
andresp@webrtc.org | 07bc734 | 2014-03-21 16:51:01 +0000 | [diff] [blame] | 94 | int number_of_packets, |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 95 | Timestamp at_time); |
andresp@webrtc.org | 07bc734 | 2014-03-21 16:51:01 +0000 | [diff] [blame] | 96 | |
Sebastian Jansson | 439f0bc | 2018-02-20 10:46:39 +0100 | [diff] [blame] | 97 | // Call when we receive a RTCP message with a ReceiveBlock. |
| 98 | void UpdatePacketsLost(int packets_lost, |
| 99 | int number_of_packets, |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 100 | Timestamp at_time); |
Sebastian Jansson | 439f0bc | 2018-02-20 10:46:39 +0100 | [diff] [blame] | 101 | |
| 102 | // Call when we receive a RTCP message with a ReceiveBlock. |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 103 | void UpdateRtt(TimeDelta rtt, Timestamp at_time); |
Sebastian Jansson | 439f0bc | 2018-02-20 10:46:39 +0100 | [diff] [blame] | 104 | |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 105 | void SetBitrates(absl::optional<DataRate> send_bitrate, |
| 106 | DataRate min_bitrate, |
| 107 | DataRate max_bitrate, |
| 108 | Timestamp at_time); |
| 109 | void SetSendBitrate(DataRate bitrate, Timestamp at_time); |
| 110 | void SetMinMaxBitrate(DataRate min_bitrate, DataRate max_bitrate); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 111 | int GetMinBitrate() const; |
Sebastian Jansson | 57f3ad0 | 2018-11-23 14:49:18 +0100 | [diff] [blame] | 112 | void SetAcknowledgedRate(absl::optional<DataRate> acknowledged_rate, |
| 113 | Timestamp at_time); |
| 114 | void IncomingPacketFeedbackVector(const TransportPacketsFeedback& report); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 115 | |
| 116 | private: |
Sebastian Jansson | 28aced5 | 2019-06-11 11:08:20 +0200 | [diff] [blame] | 117 | friend class GoogCcStatePrinter; |
| 118 | |
stefan@webrtc.org | db26247 | 2014-11-04 19:32:10 +0000 | [diff] [blame] | 119 | enum UmaState { kNoUpdate, kFirstDone, kDone }; |
| 120 | |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 121 | bool IsInStartPhase(Timestamp at_time) const; |
stefan@webrtc.org | 548b228 | 2014-11-03 14:42:43 +0000 | [diff] [blame] | 122 | |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 123 | void UpdateUmaStatsPacketsLost(Timestamp at_time, int packets_lost); |
stefan@webrtc.org | db26247 | 2014-11-04 19:32:10 +0000 | [diff] [blame] | 124 | |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 125 | // Updates history of min bitrates. |
| 126 | // After this method returns min_bitrate_history_.front().second contains the |
| 127 | // min bitrate used during last kBweIncreaseIntervalMs. |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 128 | void UpdateMinHistory(Timestamp at_time); |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 129 | |
Christoffer Rodbro | 3a83748 | 2018-11-19 15:30:23 +0100 | [diff] [blame] | 130 | DataRate MaybeRampupOrBackoff(DataRate new_bitrate, Timestamp at_time); |
| 131 | |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 132 | // Cap |bitrate| to [min_bitrate_configured_, max_bitrate_configured_] and |
| 133 | // set |current_bitrate_| to the capped value and updates the event log. |
| 134 | void CapBitrateToThresholds(Timestamp at_time, DataRate bitrate); |
philipel | 1b96531 | 2017-04-18 06:55:32 -0700 | [diff] [blame] | 135 | |
Sebastian Jansson | 2464348 | 2018-11-14 14:19:45 +0100 | [diff] [blame] | 136 | RttBasedBackoff rtt_backoff_; |
Sebastian Jansson | 57f3ad0 | 2018-11-23 14:49:18 +0100 | [diff] [blame] | 137 | LinkCapacityTracker link_capacity_; |
Sebastian Jansson | 2e068e8 | 2018-10-08 12:49:53 +0200 | [diff] [blame] | 138 | |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 139 | std::deque<std::pair<Timestamp, DataRate> > min_bitrate_history_; |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 140 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 141 | // incoming filters |
Sebastian Jansson | 439f0bc | 2018-02-20 10:46:39 +0100 | [diff] [blame] | 142 | int lost_packets_since_last_loss_update_; |
pbos | b7edb88 | 2015-10-22 08:52:20 -0700 | [diff] [blame] | 143 | int expected_packets_since_last_loss_update_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 144 | |
Sebastian Jansson | 57f3ad0 | 2018-11-23 14:49:18 +0100 | [diff] [blame] | 145 | absl::optional<DataRate> acknowledged_rate_; |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 146 | DataRate current_bitrate_; |
| 147 | DataRate min_bitrate_configured_; |
| 148 | DataRate max_bitrate_configured_; |
| 149 | Timestamp last_low_bitrate_log_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 150 | |
pbos | b7edb88 | 2015-10-22 08:52:20 -0700 | [diff] [blame] | 151 | bool has_decreased_since_last_fraction_loss_; |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 152 | Timestamp last_loss_feedback_; |
| 153 | Timestamp last_loss_packet_report_; |
| 154 | Timestamp last_timeout_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 155 | uint8_t last_fraction_loss_; |
stefan | 3821ff8 | 2016-09-04 05:07:26 -0700 | [diff] [blame] | 156 | uint8_t last_logged_fraction_loss_; |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 157 | TimeDelta last_round_trip_time_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 158 | |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 159 | DataRate bwe_incoming_; |
| 160 | DataRate delay_based_bitrate_; |
| 161 | Timestamp time_last_decrease_; |
| 162 | Timestamp first_report_time_; |
stefan@webrtc.org | 548b228 | 2014-11-03 14:42:43 +0000 | [diff] [blame] | 163 | int initially_lost_packets_; |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 164 | DataRate bitrate_at_2_seconds_; |
stefan@webrtc.org | db26247 | 2014-11-04 19:32:10 +0000 | [diff] [blame] | 165 | UmaState uma_update_state_; |
Sebastian Jansson | 439f0bc | 2018-02-20 10:46:39 +0100 | [diff] [blame] | 166 | UmaState uma_rtt_state_; |
stefan@webrtc.org | 474e36e | 2015-01-19 15:44:47 +0000 | [diff] [blame] | 167 | std::vector<bool> rampup_uma_stats_updated_; |
terelius | 006d93d | 2015-11-05 12:02:15 -0800 | [diff] [blame] | 168 | RtcEventLog* event_log_; |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 169 | Timestamp last_rtc_event_log_; |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 170 | bool in_timeout_experiment_; |
Stefan Holmer | 9c79ed9 | 2017-03-31 15:53:27 +0200 | [diff] [blame] | 171 | float low_loss_threshold_; |
| 172 | float high_loss_threshold_; |
Sebastian Jansson | 7c1744d | 2018-10-08 11:00:50 +0200 | [diff] [blame] | 173 | DataRate bitrate_threshold_; |
Christoffer Rodbro | 3a83748 | 2018-11-19 15:30:23 +0100 | [diff] [blame] | 174 | LossBasedBandwidthEstimation loss_based_bandwidth_estimation_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 175 | }; |
| 176 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 177 | #endif // MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_ |