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 | |
| 13 | #ifndef WEBRTC_MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_ |
| 14 | #define WEBRTC_MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_ |
| 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 | |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 20 | #include "webrtc/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, |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 45 | int64_t rtt, |
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 | |
philipel | c6957c7 | 2016-04-28 15:52:49 +0200 | [diff] [blame] | 49 | void SetBitrates(int send_bitrate, |
| 50 | int min_bitrate, |
| 51 | int max_bitrate); |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 52 | void SetSendBitrate(int bitrate); |
| 53 | void SetMinMaxBitrate(int min_bitrate, int max_bitrate); |
| 54 | int GetMinBitrate() const; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 55 | |
| 56 | private: |
stefan@webrtc.org | db26247 | 2014-11-04 19:32:10 +0000 | [diff] [blame] | 57 | enum UmaState { kNoUpdate, kFirstDone, kDone }; |
| 58 | |
stefan@webrtc.org | 548b228 | 2014-11-03 14:42:43 +0000 | [diff] [blame] | 59 | bool IsInStartPhase(int64_t now_ms) const; |
| 60 | |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 61 | void UpdateUmaStats(int64_t now_ms, int64_t rtt, int lost_packets); |
stefan@webrtc.org | db26247 | 2014-11-04 19:32:10 +0000 | [diff] [blame] | 62 | |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 63 | // Updates history of min bitrates. |
| 64 | // After this method returns min_bitrate_history_.front().second contains the |
| 65 | // min bitrate used during last kBweIncreaseIntervalMs. |
stefan@webrtc.org | edeea91 | 2014-12-08 19:46:23 +0000 | [diff] [blame] | 66 | void UpdateMinHistory(int64_t now_ms); |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 67 | |
philipel | 1b96531 | 2017-04-18 06:55:32 -0700 | [diff] [blame] | 68 | // Cap |bitrate_bps| to [min_bitrate_configured_, max_bitrate_configured_] and |
| 69 | // set |current_bitrate_bps_| to the capped value and updates the event log. |
| 70 | void CapBitrateToThresholds(int64_t now_ms, uint32_t bitrate_bps); |
| 71 | |
stefan@webrtc.org | edeea91 | 2014-12-08 19:46:23 +0000 | [diff] [blame] | 72 | std::deque<std::pair<int64_t, uint32_t> > min_bitrate_history_; |
andresp@webrtc.org | 44caf01 | 2014-03-26 21:00:21 +0000 | [diff] [blame] | 73 | |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 74 | // incoming filters |
pbos | b7edb88 | 2015-10-22 08:52:20 -0700 | [diff] [blame] | 75 | int lost_packets_since_last_loss_update_Q8_; |
| 76 | int expected_packets_since_last_loss_update_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 77 | |
philipel | 1b96531 | 2017-04-18 06:55:32 -0700 | [diff] [blame] | 78 | uint32_t current_bitrate_bps_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 79 | uint32_t min_bitrate_configured_; |
| 80 | uint32_t max_bitrate_configured_; |
stefan | b6b0b92 | 2015-09-04 03:04:56 -0700 | [diff] [blame] | 81 | int64_t last_low_bitrate_log_ms_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 82 | |
pbos | b7edb88 | 2015-10-22 08:52:20 -0700 | [diff] [blame] | 83 | bool has_decreased_since_last_fraction_loss_; |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 84 | int64_t last_feedback_ms_; |
| 85 | int64_t last_packet_report_ms_; |
| 86 | int64_t last_timeout_ms_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 87 | uint8_t last_fraction_loss_; |
stefan | 3821ff8 | 2016-09-04 05:07:26 -0700 | [diff] [blame] | 88 | uint8_t last_logged_fraction_loss_; |
pkasting@chromium.org | 16825b1 | 2015-01-12 21:51:21 +0000 | [diff] [blame] | 89 | int64_t last_round_trip_time_ms_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 90 | |
| 91 | uint32_t bwe_incoming_; |
stefan | 32f8154 | 2016-01-20 07:13:58 -0800 | [diff] [blame] | 92 | uint32_t delay_based_bitrate_bps_; |
stefan@webrtc.org | edeea91 | 2014-12-08 19:46:23 +0000 | [diff] [blame] | 93 | int64_t time_last_decrease_ms_; |
stefan@webrtc.org | 82462aa | 2014-10-23 11:57:05 +0000 | [diff] [blame] | 94 | int64_t first_report_time_ms_; |
stefan@webrtc.org | 548b228 | 2014-11-03 14:42:43 +0000 | [diff] [blame] | 95 | int initially_lost_packets_; |
stefan@webrtc.org | db26247 | 2014-11-04 19:32:10 +0000 | [diff] [blame] | 96 | int bitrate_at_2_seconds_kbps_; |
| 97 | UmaState uma_update_state_; |
stefan@webrtc.org | 474e36e | 2015-01-19 15:44:47 +0000 | [diff] [blame] | 98 | std::vector<bool> rampup_uma_stats_updated_; |
terelius | 006d93d | 2015-11-05 12:02:15 -0800 | [diff] [blame] | 99 | RtcEventLog* event_log_; |
stefan | 3821ff8 | 2016-09-04 05:07:26 -0700 | [diff] [blame] | 100 | int64_t last_rtc_event_log_ms_; |
Stefan Holmer | 52200d0 | 2016-09-20 14:14:23 +0200 | [diff] [blame] | 101 | bool in_timeout_experiment_; |
Stefan Holmer | 9c79ed9 | 2017-03-31 15:53:27 +0200 | [diff] [blame] | 102 | float low_loss_threshold_; |
| 103 | float high_loss_threshold_; |
| 104 | uint32_t bitrate_threshold_bps_; |
pwestin@webrtc.org | 1cd1162 | 2012-04-19 12:13:52 +0000 | [diff] [blame] | 105 | }; |
| 106 | } // namespace webrtc |
| 107 | #endif // WEBRTC_MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_ |