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 | |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 16 | #include <deque> |
jbauch | f91e6d0 | 2016-01-24 23:05:21 -0800 | [diff] [blame] | 17 | #include <utility> |
| 18 | #include <vector> |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 19 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
terelius | 006d93d | 2015-11-05 12:02:15 -0800 | [diff] [blame] | 23 | |
| 24 | class RtcEventLog; |
| 25 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 26 | class SendSideBandwidthEstimation { |
| 27 | public: |
ivoc | 14d5dbe | 2016-07-04 07:06:55 -0700 | [diff] [blame] | 28 | SendSideBandwidthEstimation() = delete; |
| 29 | explicit SendSideBandwidthEstimation(RtcEventLog* event_log); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 30 | virtual ~SendSideBandwidthEstimation(); |
| 31 | |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 32 | void CurrentEstimate(int* bitrate, uint8_t* loss, int64_t* rtt) const; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 33 | |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 34 | // Call periodically to update estimate. |
stefan@webrtc.org | edeea91 | 2014-12-08 19:46:23 +0000 | [diff] [blame] | 35 | void UpdateEstimate(int64_t now_ms); |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 36 | |
andresp@webrtc.org | 07bc734 | 2014-03-21 16:51:01 +0000 | [diff] [blame] | 37 | // Call when we receive a RTCP message with TMMBR or REMB. |
stefan | b6b0b92 | 2015-09-04 03:04:56 -0700 | [diff] [blame] | 38 | void UpdateReceiverEstimate(int64_t now_ms, uint32_t bandwidth); |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 39 | |
stefan | 32f8154 | 2016-01-20 07:13:58 -0800 | [diff] [blame] | 40 | // Call when a new delay-based estimate is available. |
| 41 | void UpdateDelayBasedEstimate(int64_t now_ms, uint32_t bitrate_bps); |
| 42 | |
andresp@webrtc.org | 07bc734 | 2014-03-21 16:51:01 +0000 | [diff] [blame] | 43 | // Call when we receive a RTCP message with a ReceiveBlock. |
| 44 | void UpdateReceiverBlock(uint8_t fraction_loss, |
Sebastian Jansson | 439f0bc | 2018-02-20 10:46:39 +0100 | [diff] [blame] | 45 | int64_t rtt_ms, |
andresp@webrtc.org | 07bc734 | 2014-03-21 16:51:01 +0000 | [diff] [blame] | 46 | int number_of_packets, |
stefan@webrtc.org | edeea91 | 2014-12-08 19:46:23 +0000 | [diff] [blame] | 47 | int64_t now_ms); |
andresp@webrtc.org | 07bc734 | 2014-03-21 16:51:01 +0000 | [diff] [blame] | 48 | |
Sebastian Jansson | 439f0bc | 2018-02-20 10:46:39 +0100 | [diff] [blame] | 49 | // Call when we receive a RTCP message with a ReceiveBlock. |
| 50 | void UpdatePacketsLost(int packets_lost, |
| 51 | int number_of_packets, |
| 52 | int64_t now_ms); |
| 53 | |
| 54 | // Call when we receive a RTCP message with a ReceiveBlock. |
| 55 | void UpdateRtt(int64_t rtt, int64_t now_ms); |
| 56 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame^] | 57 | void SetBitrates(int send_bitrate, int min_bitrate, int max_bitrate); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 58 | void SetSendBitrate(int bitrate); |
| 59 | void SetMinMaxBitrate(int min_bitrate, int max_bitrate); |
| 60 | int GetMinBitrate() const; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 61 | |
| 62 | private: |
stefan@webrtc.org | db26247 | 2014-11-04 19:32:10 +0000 | [diff] [blame] | 63 | enum UmaState { kNoUpdate, kFirstDone, kDone }; |
| 64 | |
stefan@webrtc.org | 548b228 | 2014-11-03 14:42:43 +0000 | [diff] [blame] | 65 | bool IsInStartPhase(int64_t now_ms) const; |
| 66 | |
Sebastian Jansson | 439f0bc | 2018-02-20 10:46:39 +0100 | [diff] [blame] | 67 | void UpdateUmaStatsPacketsLost(int64_t now_ms, int packets_lost); |
stefan@webrtc.org | db26247 | 2014-11-04 19:32:10 +0000 | [diff] [blame] | 68 | |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 69 | // Updates history of min bitrates. |
| 70 | // After this method returns min_bitrate_history_.front().second contains the |
| 71 | // min bitrate used during last kBweIncreaseIntervalMs. |
stefan@webrtc.org | edeea91 | 2014-12-08 19:46:23 +0000 | [diff] [blame] | 72 | void UpdateMinHistory(int64_t now_ms); |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 73 | |
philipel | 1b96531 | 2017-04-18 06:55:32 -0700 | [diff] [blame] | 74 | // Cap |bitrate_bps| to [min_bitrate_configured_, max_bitrate_configured_] and |
| 75 | // set |current_bitrate_bps_| to the capped value and updates the event log. |
| 76 | void CapBitrateToThresholds(int64_t now_ms, uint32_t bitrate_bps); |
| 77 | |
stefan@webrtc.org | edeea91 | 2014-12-08 19:46:23 +0000 | [diff] [blame] | 78 | std::deque<std::pair<int64_t, uint32_t> > min_bitrate_history_; |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 79 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 80 | // incoming filters |
Sebastian Jansson | 439f0bc | 2018-02-20 10:46:39 +0100 | [diff] [blame] | 81 | int lost_packets_since_last_loss_update_; |
pbos | b7edb88 | 2015-10-22 08:52:20 -0700 | [diff] [blame] | 82 | int expected_packets_since_last_loss_update_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 83 | |
philipel | 1b96531 | 2017-04-18 06:55:32 -0700 | [diff] [blame] | 84 | uint32_t current_bitrate_bps_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 85 | uint32_t min_bitrate_configured_; |
| 86 | uint32_t max_bitrate_configured_; |
stefan | b6b0b92 | 2015-09-04 03:04:56 -0700 | [diff] [blame] | 87 | int64_t last_low_bitrate_log_ms_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 88 | |
pbos | b7edb88 | 2015-10-22 08:52:20 -0700 | [diff] [blame] | 89 | bool has_decreased_since_last_fraction_loss_; |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 90 | int64_t last_feedback_ms_; |
| 91 | int64_t last_packet_report_ms_; |
| 92 | int64_t last_timeout_ms_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 93 | uint8_t last_fraction_loss_; |
stefan | 3821ff8 | 2016-09-04 05:07:26 -0700 | [diff] [blame] | 94 | uint8_t last_logged_fraction_loss_; |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 95 | int64_t last_round_trip_time_ms_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 96 | |
| 97 | uint32_t bwe_incoming_; |
stefan | 32f8154 | 2016-01-20 07:13:58 -0800 | [diff] [blame] | 98 | uint32_t delay_based_bitrate_bps_; |
stefan@webrtc.org | edeea91 | 2014-12-08 19:46:23 +0000 | [diff] [blame] | 99 | int64_t time_last_decrease_ms_; |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 100 | int64_t first_report_time_ms_; |
stefan@webrtc.org | 548b228 | 2014-11-03 14:42:43 +0000 | [diff] [blame] | 101 | int initially_lost_packets_; |
stefan@webrtc.org | db26247 | 2014-11-04 19:32:10 +0000 | [diff] [blame] | 102 | int bitrate_at_2_seconds_kbps_; |
| 103 | UmaState uma_update_state_; |
Sebastian Jansson | 439f0bc | 2018-02-20 10:46:39 +0100 | [diff] [blame] | 104 | UmaState uma_rtt_state_; |
stefan@webrtc.org | 474e36e | 2015-01-19 15:44:47 +0000 | [diff] [blame] | 105 | std::vector<bool> rampup_uma_stats_updated_; |
terelius | 006d93d | 2015-11-05 12:02:15 -0800 | [diff] [blame] | 106 | RtcEventLog* event_log_; |
stefan | 3821ff8 | 2016-09-04 05:07:26 -0700 | [diff] [blame] | 107 | int64_t last_rtc_event_log_ms_; |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 108 | bool in_timeout_experiment_; |
Stefan Holmer | 9c79ed9 | 2017-03-31 15:53:27 +0200 | [diff] [blame] | 109 | float low_loss_threshold_; |
| 110 | float high_loss_threshold_; |
| 111 | uint32_t bitrate_threshold_bps_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 112 | }; |
| 113 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 114 | #endif // MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_ |