blob: 2c8b4ee3d5aba0463329d7c24b8200323b6e49b7 [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
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020020#include "absl/types/optional.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000022
23namespace webrtc {
terelius006d93d2015-11-05 12:02:15 -080024
25class RtcEventLog;
26
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000027class SendSideBandwidthEstimation {
28 public:
ivoc14d5dbe2016-07-04 07:06:55 -070029 SendSideBandwidthEstimation() = delete;
30 explicit SendSideBandwidthEstimation(RtcEventLog* event_log);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000031 virtual ~SendSideBandwidthEstimation();
32
Stefan Holmere5904162015-03-26 11:11:06 +010033 void CurrentEstimate(int* bitrate, uint8_t* loss, int64_t* rtt) const;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000034
andresp@webrtc.org44caf012014-03-26 21:00:21 +000035 // Call periodically to update estimate.
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020036 void UpdateEstimate(Timestamp at_time);
andresp@webrtc.org44caf012014-03-26 21:00:21 +000037
andresp@webrtc.org07bc7342014-03-21 16:51:01 +000038 // Call when we receive a RTCP message with TMMBR or REMB.
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020039 void UpdateReceiverEstimate(Timestamp at_time, DataRate bandwidth);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000040
stefan32f81542016-01-20 07:13:58 -080041 // Call when a new delay-based estimate is available.
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020042 void UpdateDelayBasedEstimate(Timestamp at_time, DataRate bitrate);
stefan32f81542016-01-20 07:13:58 -080043
andresp@webrtc.org07bc7342014-03-21 16:51:01 +000044 // Call when we receive a RTCP message with a ReceiveBlock.
45 void UpdateReceiverBlock(uint8_t fraction_loss,
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020046 TimeDelta rtt_ms,
andresp@webrtc.org07bc7342014-03-21 16:51:01 +000047 int number_of_packets,
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020048 Timestamp at_time);
andresp@webrtc.org07bc7342014-03-21 16:51:01 +000049
Sebastian Jansson439f0bc2018-02-20 10:46:39 +010050 // Call when we receive a RTCP message with a ReceiveBlock.
51 void UpdatePacketsLost(int packets_lost,
52 int number_of_packets,
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020053 Timestamp at_time);
Sebastian Jansson439f0bc2018-02-20 10:46:39 +010054
55 // Call when we receive a RTCP message with a ReceiveBlock.
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020056 void UpdateRtt(TimeDelta rtt, Timestamp at_time);
Sebastian Jansson439f0bc2018-02-20 10:46:39 +010057
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020058 void SetBitrates(absl::optional<DataRate> send_bitrate,
59 DataRate min_bitrate,
60 DataRate max_bitrate,
61 Timestamp at_time);
62 void SetSendBitrate(DataRate bitrate, Timestamp at_time);
63 void SetMinMaxBitrate(DataRate min_bitrate, DataRate max_bitrate);
Stefan Holmere5904162015-03-26 11:11:06 +010064 int GetMinBitrate() const;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000065
66 private:
stefan@webrtc.orgdb262472014-11-04 19:32:10 +000067 enum UmaState { kNoUpdate, kFirstDone, kDone };
68
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020069 bool IsInStartPhase(Timestamp at_time) const;
stefan@webrtc.org548b2282014-11-03 14:42:43 +000070
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020071 void UpdateUmaStatsPacketsLost(Timestamp at_time, int packets_lost);
stefan@webrtc.orgdb262472014-11-04 19:32:10 +000072
andresp@webrtc.org44caf012014-03-26 21:00:21 +000073 // Updates history of min bitrates.
74 // After this method returns min_bitrate_history_.front().second contains the
75 // min bitrate used during last kBweIncreaseIntervalMs.
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020076 void UpdateMinHistory(Timestamp at_time);
andresp@webrtc.org44caf012014-03-26 21:00:21 +000077
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020078 // Cap |bitrate| to [min_bitrate_configured_, max_bitrate_configured_] and
79 // set |current_bitrate_| to the capped value and updates the event log.
80 void CapBitrateToThresholds(Timestamp at_time, DataRate bitrate);
philipel1b965312017-04-18 06:55:32 -070081
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020082 std::deque<std::pair<Timestamp, DataRate> > min_bitrate_history_;
andresp@webrtc.org44caf012014-03-26 21:00:21 +000083
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000084 // incoming filters
Sebastian Jansson439f0bc2018-02-20 10:46:39 +010085 int lost_packets_since_last_loss_update_;
pbosb7edb882015-10-22 08:52:20 -070086 int expected_packets_since_last_loss_update_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000087
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020088 DataRate current_bitrate_;
89 DataRate min_bitrate_configured_;
90 DataRate max_bitrate_configured_;
91 Timestamp last_low_bitrate_log_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000092
pbosb7edb882015-10-22 08:52:20 -070093 bool has_decreased_since_last_fraction_loss_;
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020094 Timestamp last_loss_feedback_;
95 Timestamp last_loss_packet_report_;
96 Timestamp last_timeout_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000097 uint8_t last_fraction_loss_;
stefan3821ff82016-09-04 05:07:26 -070098 uint8_t last_logged_fraction_loss_;
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020099 TimeDelta last_round_trip_time_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000100
Sebastian Jansson7c1744d2018-10-08 11:00:50 +0200101 DataRate bwe_incoming_;
102 DataRate delay_based_bitrate_;
103 Timestamp time_last_decrease_;
104 Timestamp first_report_time_;
stefan@webrtc.org548b2282014-11-03 14:42:43 +0000105 int initially_lost_packets_;
Sebastian Jansson7c1744d2018-10-08 11:00:50 +0200106 DataRate bitrate_at_2_seconds_;
stefan@webrtc.orgdb262472014-11-04 19:32:10 +0000107 UmaState uma_update_state_;
Sebastian Jansson439f0bc2018-02-20 10:46:39 +0100108 UmaState uma_rtt_state_;
stefan@webrtc.org474e36e2015-01-19 15:44:47 +0000109 std::vector<bool> rampup_uma_stats_updated_;
terelius006d93d2015-11-05 12:02:15 -0800110 RtcEventLog* event_log_;
Sebastian Jansson7c1744d2018-10-08 11:00:50 +0200111 Timestamp last_rtc_event_log_;
Stefan Holmer52200d02016-09-20 14:14:23 +0200112 bool in_timeout_experiment_;
Stefan Holmer9c79ed92017-03-31 15:53:27 +0200113 float low_loss_threshold_;
114 float high_loss_threshold_;
Sebastian Jansson7c1744d2018-10-08 11:00:50 +0200115 DataRate bitrate_threshold_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000116};
117} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200118#endif // MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_