blob: d09184c0bf2c72c2174166f9ee3a1eb5ba2a39a0 [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
philipelc6957c72016-04-28 15:52:49 +020057 void SetBitrates(int send_bitrate,
58 int min_bitrate,
59 int max_bitrate);
Stefan Holmere5904162015-03-26 11:11:06 +010060 void SetSendBitrate(int bitrate);
61 void SetMinMaxBitrate(int min_bitrate, int max_bitrate);
62 int GetMinBitrate() const;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000063
64 private:
stefan@webrtc.orgdb262472014-11-04 19:32:10 +000065 enum UmaState { kNoUpdate, kFirstDone, kDone };
66
stefan@webrtc.org548b2282014-11-03 14:42:43 +000067 bool IsInStartPhase(int64_t now_ms) const;
68
Sebastian Jansson439f0bc2018-02-20 10:46:39 +010069 void UpdateUmaStatsPacketsLost(int64_t now_ms, int packets_lost);
stefan@webrtc.orgdb262472014-11-04 19:32:10 +000070
andresp@webrtc.org44caf012014-03-26 21:00:21 +000071 // Updates history of min bitrates.
72 // After this method returns min_bitrate_history_.front().second contains the
73 // min bitrate used during last kBweIncreaseIntervalMs.
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000074 void UpdateMinHistory(int64_t now_ms);
andresp@webrtc.org44caf012014-03-26 21:00:21 +000075
philipel1b965312017-04-18 06:55:32 -070076 // Cap |bitrate_bps| to [min_bitrate_configured_, max_bitrate_configured_] and
77 // set |current_bitrate_bps_| to the capped value and updates the event log.
78 void CapBitrateToThresholds(int64_t now_ms, uint32_t bitrate_bps);
79
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000080 std::deque<std::pair<int64_t, uint32_t> > min_bitrate_history_;
andresp@webrtc.org44caf012014-03-26 21:00:21 +000081
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000082 // incoming filters
Sebastian Jansson439f0bc2018-02-20 10:46:39 +010083 int lost_packets_since_last_loss_update_;
pbosb7edb882015-10-22 08:52:20 -070084 int expected_packets_since_last_loss_update_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000085
philipel1b965312017-04-18 06:55:32 -070086 uint32_t current_bitrate_bps_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000087 uint32_t min_bitrate_configured_;
88 uint32_t max_bitrate_configured_;
stefanb6b0b922015-09-04 03:04:56 -070089 int64_t last_low_bitrate_log_ms_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000090
pbosb7edb882015-10-22 08:52:20 -070091 bool has_decreased_since_last_fraction_loss_;
Stefan Holmer52200d02016-09-20 14:14:23 +020092 int64_t last_feedback_ms_;
93 int64_t last_packet_report_ms_;
94 int64_t last_timeout_ms_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000095 uint8_t last_fraction_loss_;
stefan3821ff82016-09-04 05:07:26 -070096 uint8_t last_logged_fraction_loss_;
pkasting@chromium.org16825b12015-01-12 21:51:21 +000097 int64_t last_round_trip_time_ms_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000098
99 uint32_t bwe_incoming_;
stefan32f81542016-01-20 07:13:58 -0800100 uint32_t delay_based_bitrate_bps_;
stefan@webrtc.orgedeea912014-12-08 19:46:23 +0000101 int64_t time_last_decrease_ms_;
stefan@webrtc.org82462aa2014-10-23 11:57:05 +0000102 int64_t first_report_time_ms_;
stefan@webrtc.org548b2282014-11-03 14:42:43 +0000103 int initially_lost_packets_;
stefan@webrtc.orgdb262472014-11-04 19:32:10 +0000104 int bitrate_at_2_seconds_kbps_;
105 UmaState uma_update_state_;
Sebastian Jansson439f0bc2018-02-20 10:46:39 +0100106 UmaState uma_rtt_state_;
stefan@webrtc.org474e36e2015-01-19 15:44:47 +0000107 std::vector<bool> rampup_uma_stats_updated_;
terelius006d93d2015-11-05 12:02:15 -0800108 RtcEventLog* event_log_;
stefan3821ff82016-09-04 05:07:26 -0700109 int64_t last_rtc_event_log_ms_;
Stefan Holmer52200d02016-09-20 14:14:23 +0200110 bool in_timeout_experiment_;
Stefan Holmer9c79ed92017-03-31 15:53:27 +0200111 float low_loss_threshold_;
112 float high_loss_threshold_;
113 uint32_t bitrate_threshold_bps_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000114};
115} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200116#endif // MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_