blob: 59d1c3280d290011248ce26c200e1db6d6eadd58 [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 Janssonea86bb72018-02-14 16:53:38 +000045 int64_t rtt,
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
philipelc6957c72016-04-28 15:52:49 +020049 void SetBitrates(int send_bitrate,
50 int min_bitrate,
51 int max_bitrate);
Stefan Holmere5904162015-03-26 11:11:06 +010052 void SetSendBitrate(int bitrate);
53 void SetMinMaxBitrate(int min_bitrate, int max_bitrate);
54 int GetMinBitrate() const;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000055
56 private:
stefan@webrtc.orgdb262472014-11-04 19:32:10 +000057 enum UmaState { kNoUpdate, kFirstDone, kDone };
58
stefan@webrtc.org548b2282014-11-03 14:42:43 +000059 bool IsInStartPhase(int64_t now_ms) const;
60
Sebastian Janssonea86bb72018-02-14 16:53:38 +000061 void UpdateUmaStats(int64_t now_ms, int64_t rtt, int lost_packets);
stefan@webrtc.orgdb262472014-11-04 19:32:10 +000062
andresp@webrtc.org44caf012014-03-26 21:00:21 +000063 // 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.orgedeea912014-12-08 19:46:23 +000066 void UpdateMinHistory(int64_t now_ms);
andresp@webrtc.org44caf012014-03-26 21:00:21 +000067
philipel1b965312017-04-18 06:55:32 -070068 // 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.orgedeea912014-12-08 19:46:23 +000072 std::deque<std::pair<int64_t, uint32_t> > min_bitrate_history_;
andresp@webrtc.org44caf012014-03-26 21:00:21 +000073
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000074 // incoming filters
Sebastian Janssonea86bb72018-02-14 16:53:38 +000075 int lost_packets_since_last_loss_update_Q8_;
pbosb7edb882015-10-22 08:52:20 -070076 int expected_packets_since_last_loss_update_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000077
philipel1b965312017-04-18 06:55:32 -070078 uint32_t current_bitrate_bps_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000079 uint32_t min_bitrate_configured_;
80 uint32_t max_bitrate_configured_;
stefanb6b0b922015-09-04 03:04:56 -070081 int64_t last_low_bitrate_log_ms_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000082
pbosb7edb882015-10-22 08:52:20 -070083 bool has_decreased_since_last_fraction_loss_;
Stefan Holmer52200d02016-09-20 14:14:23 +020084 int64_t last_feedback_ms_;
85 int64_t last_packet_report_ms_;
86 int64_t last_timeout_ms_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000087 uint8_t last_fraction_loss_;
stefan3821ff82016-09-04 05:07:26 -070088 uint8_t last_logged_fraction_loss_;
pkasting@chromium.org16825b12015-01-12 21:51:21 +000089 int64_t last_round_trip_time_ms_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000090
91 uint32_t bwe_incoming_;
stefan32f81542016-01-20 07:13:58 -080092 uint32_t delay_based_bitrate_bps_;
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000093 int64_t time_last_decrease_ms_;
stefan@webrtc.org82462aa2014-10-23 11:57:05 +000094 int64_t first_report_time_ms_;
stefan@webrtc.org548b2282014-11-03 14:42:43 +000095 int initially_lost_packets_;
stefan@webrtc.orgdb262472014-11-04 19:32:10 +000096 int bitrate_at_2_seconds_kbps_;
97 UmaState uma_update_state_;
stefan@webrtc.org474e36e2015-01-19 15:44:47 +000098 std::vector<bool> rampup_uma_stats_updated_;
terelius006d93d2015-11-05 12:02:15 -080099 RtcEventLog* event_log_;
stefan3821ff82016-09-04 05:07:26 -0700100 int64_t last_rtc_event_log_ms_;
Stefan Holmer52200d02016-09-20 14:14:23 +0200101 bool in_timeout_experiment_;
Stefan Holmer9c79ed92017-03-31 15:53:27 +0200102 float low_loss_threshold_;
103 float high_loss_threshold_;
104 uint32_t bitrate_threshold_bps_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000105};
106} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200107#endif // MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_