blob: 54b571e96ebb28edb6c70328679df9bcf24e1bb4 [file] [log] [blame]
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +00001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020013#ifndef MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_
14#define MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000015
andresp@webrtc.org44caf012014-03-26 21:00:21 +000016#include <deque>
jbauchf91e6d02016-01-24 23:05:21 -080017#include <utility>
18#include <vector>
andresp@webrtc.org44caf012014-03-26 21:00:21 +000019
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000021
22namespace webrtc {
terelius006d93d2015-11-05 12:02:15 -080023
24class RtcEventLog;
25
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000026class SendSideBandwidthEstimation {
27 public:
ivoc14d5dbe2016-07-04 07:06:55 -070028 SendSideBandwidthEstimation() = delete;
29 explicit SendSideBandwidthEstimation(RtcEventLog* event_log);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000030 virtual ~SendSideBandwidthEstimation();
31
Stefan Holmere5904162015-03-26 11:11:06 +010032 void CurrentEstimate(int* bitrate, uint8_t* loss, int64_t* rtt) const;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000033
andresp@webrtc.org44caf012014-03-26 21:00:21 +000034 // Call periodically to update estimate.
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000035 void UpdateEstimate(int64_t now_ms);
andresp@webrtc.org44caf012014-03-26 21:00:21 +000036
andresp@webrtc.org07bc7342014-03-21 16:51:01 +000037 // Call when we receive a RTCP message with TMMBR or REMB.
stefanb6b0b922015-09-04 03:04:56 -070038 void UpdateReceiverEstimate(int64_t now_ms, uint32_t bandwidth);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000039
stefan32f81542016-01-20 07:13:58 -080040 // Call when a new delay-based estimate is available.
41 void UpdateDelayBasedEstimate(int64_t now_ms, uint32_t bitrate_bps);
42
andresp@webrtc.org07bc7342014-03-21 16:51:01 +000043 // Call when we receive a RTCP message with a ReceiveBlock.
44 void UpdateReceiverBlock(uint8_t fraction_loss,
Sebastian Jansson439f0bc2018-02-20 10:46:39 +010045 int64_t rtt_ms,
andresp@webrtc.org07bc7342014-03-21 16:51:01 +000046 int number_of_packets,
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000047 int64_t now_ms);
andresp@webrtc.org07bc7342014-03-21 16:51:01 +000048
Sebastian Jansson439f0bc2018-02-20 10:46:39 +010049 // 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 Gerey665174f2018-06-19 15:03:05 +020057 void SetBitrates(int send_bitrate, int min_bitrate, int max_bitrate);
Stefan Holmere5904162015-03-26 11:11:06 +010058 void SetSendBitrate(int bitrate);
59 void SetMinMaxBitrate(int min_bitrate, int max_bitrate);
60 int GetMinBitrate() const;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000061
62 private:
stefan@webrtc.orgdb262472014-11-04 19:32:10 +000063 enum UmaState { kNoUpdate, kFirstDone, kDone };
64
stefan@webrtc.org548b2282014-11-03 14:42:43 +000065 bool IsInStartPhase(int64_t now_ms) const;
66
Sebastian Jansson439f0bc2018-02-20 10:46:39 +010067 void UpdateUmaStatsPacketsLost(int64_t now_ms, int packets_lost);
stefan@webrtc.orgdb262472014-11-04 19:32:10 +000068
andresp@webrtc.org44caf012014-03-26 21:00:21 +000069 // 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.orgedeea912014-12-08 19:46:23 +000072 void UpdateMinHistory(int64_t now_ms);
andresp@webrtc.org44caf012014-03-26 21:00:21 +000073
philipel1b965312017-04-18 06:55:32 -070074 // 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.orgedeea912014-12-08 19:46:23 +000078 std::deque<std::pair<int64_t, uint32_t> > min_bitrate_history_;
andresp@webrtc.org44caf012014-03-26 21:00:21 +000079
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000080 // incoming filters
Sebastian Jansson439f0bc2018-02-20 10:46:39 +010081 int lost_packets_since_last_loss_update_;
pbosb7edb882015-10-22 08:52:20 -070082 int expected_packets_since_last_loss_update_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000083
philipel1b965312017-04-18 06:55:32 -070084 uint32_t current_bitrate_bps_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000085 uint32_t min_bitrate_configured_;
86 uint32_t max_bitrate_configured_;
stefanb6b0b922015-09-04 03:04:56 -070087 int64_t last_low_bitrate_log_ms_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000088
pbosb7edb882015-10-22 08:52:20 -070089 bool has_decreased_since_last_fraction_loss_;
Stefan Holmer52200d02016-09-20 14:14:23 +020090 int64_t last_feedback_ms_;
91 int64_t last_packet_report_ms_;
92 int64_t last_timeout_ms_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000093 uint8_t last_fraction_loss_;
stefan3821ff82016-09-04 05:07:26 -070094 uint8_t last_logged_fraction_loss_;
pkasting@chromium.org16825b12015-01-12 21:51:21 +000095 int64_t last_round_trip_time_ms_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000096
97 uint32_t bwe_incoming_;
stefan32f81542016-01-20 07:13:58 -080098 uint32_t delay_based_bitrate_bps_;
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000099 int64_t time_last_decrease_ms_;
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000100 int64_t first_report_time_ms_;
stefan@webrtc.org548b2282014-11-03 14:42:43 +0000101 int initially_lost_packets_;
stefan@webrtc.orgdb262472014-11-04 19:32:10 +0000102 int bitrate_at_2_seconds_kbps_;
103 UmaState uma_update_state_;
Sebastian Jansson439f0bc2018-02-20 10:46:39 +0100104 UmaState uma_rtt_state_;
stefan@webrtc.org474e36e2015-01-19 15:44:47 +0000105 std::vector<bool> rampup_uma_stats_updated_;
terelius006d93d2015-11-05 12:02:15 -0800106 RtcEventLog* event_log_;
stefan3821ff82016-09-04 05:07:26 -0700107 int64_t last_rtc_event_log_ms_;
Stefan Holmer52200d02016-09-20 14:14:23 +0200108 bool in_timeout_experiment_;
Stefan Holmer9c79ed92017-03-31 15:53:27 +0200109 float low_loss_threshold_;
110 float high_loss_threshold_;
111 uint32_t bitrate_threshold_bps_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000112};
113} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200114#endif // MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_