blob: 9ee43bbcdcdcd601d4685b21a4a25c331208eb72 [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
Yves Gerey988cc082018-10-23 12:03:01 +020016#include <stdint.h>
andresp@webrtc.org44caf012014-03-26 21:00:21 +000017#include <deque>
jbauchf91e6d02016-01-24 23:05:21 -080018#include <utility>
19#include <vector>
andresp@webrtc.org44caf012014-03-26 21:00:21 +000020
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020021#include "absl/types/optional.h"
Yves Gerey988cc082018-10-23 12:03:01 +020022#include "api/transport/network_types.h"
23#include "api/units/data_rate.h"
24#include "api/units/time_delta.h"
25#include "api/units/timestamp.h"
Sebastian Jansson2e068e82018-10-08 12:49:53 +020026#include "rtc_base/experiments/field_trial_parser.h"
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000027
28namespace webrtc {
terelius006d93d2015-11-05 12:02:15 -080029
30class RtcEventLog;
31
Sebastian Jansson2e068e82018-10-08 12:49:53 +020032struct RttBasedBackoffConfig {
33 RttBasedBackoffConfig();
34 RttBasedBackoffConfig(const RttBasedBackoffConfig&);
35 RttBasedBackoffConfig& operator=(const RttBasedBackoffConfig&) = default;
36 ~RttBasedBackoffConfig();
37 FieldTrialParameter<TimeDelta> rtt_limit;
38 FieldTrialParameter<double> drop_fraction;
39 FieldTrialParameter<TimeDelta> drop_interval;
40};
41
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000042class SendSideBandwidthEstimation {
43 public:
ivoc14d5dbe2016-07-04 07:06:55 -070044 SendSideBandwidthEstimation() = delete;
45 explicit SendSideBandwidthEstimation(RtcEventLog* event_log);
Sebastian Jansson2e068e82018-10-08 12:49:53 +020046 ~SendSideBandwidthEstimation();
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000047
Stefan Holmere5904162015-03-26 11:11:06 +010048 void CurrentEstimate(int* bitrate, uint8_t* loss, int64_t* rtt) const;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000049
andresp@webrtc.org44caf012014-03-26 21:00:21 +000050 // Call periodically to update estimate.
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020051 void UpdateEstimate(Timestamp at_time);
Sebastian Jansson2e068e82018-10-08 12:49:53 +020052 void OnSentPacket(SentPacket sent_packet);
53 void UpdatePropagationRtt(Timestamp at_time, TimeDelta feedback_rtt);
andresp@webrtc.org44caf012014-03-26 21:00:21 +000054
andresp@webrtc.org07bc7342014-03-21 16:51:01 +000055 // Call when we receive a RTCP message with TMMBR or REMB.
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020056 void UpdateReceiverEstimate(Timestamp at_time, DataRate bandwidth);
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000057
stefan32f81542016-01-20 07:13:58 -080058 // Call when a new delay-based estimate is available.
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020059 void UpdateDelayBasedEstimate(Timestamp at_time, DataRate bitrate);
stefan32f81542016-01-20 07:13:58 -080060
andresp@webrtc.org07bc7342014-03-21 16:51:01 +000061 // Call when we receive a RTCP message with a ReceiveBlock.
62 void UpdateReceiverBlock(uint8_t fraction_loss,
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020063 TimeDelta rtt_ms,
andresp@webrtc.org07bc7342014-03-21 16:51:01 +000064 int number_of_packets,
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020065 Timestamp at_time);
andresp@webrtc.org07bc7342014-03-21 16:51:01 +000066
Sebastian Jansson439f0bc2018-02-20 10:46:39 +010067 // Call when we receive a RTCP message with a ReceiveBlock.
68 void UpdatePacketsLost(int packets_lost,
69 int number_of_packets,
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020070 Timestamp at_time);
Sebastian Jansson439f0bc2018-02-20 10:46:39 +010071
72 // Call when we receive a RTCP message with a ReceiveBlock.
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020073 void UpdateRtt(TimeDelta rtt, Timestamp at_time);
Sebastian Jansson439f0bc2018-02-20 10:46:39 +010074
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020075 void SetBitrates(absl::optional<DataRate> send_bitrate,
76 DataRate min_bitrate,
77 DataRate max_bitrate,
78 Timestamp at_time);
79 void SetSendBitrate(DataRate bitrate, Timestamp at_time);
80 void SetMinMaxBitrate(DataRate min_bitrate, DataRate max_bitrate);
Stefan Holmere5904162015-03-26 11:11:06 +010081 int GetMinBitrate() const;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +000082
83 private:
stefan@webrtc.orgdb262472014-11-04 19:32:10 +000084 enum UmaState { kNoUpdate, kFirstDone, kDone };
85
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020086 bool IsInStartPhase(Timestamp at_time) const;
stefan@webrtc.org548b2282014-11-03 14:42:43 +000087
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020088 void UpdateUmaStatsPacketsLost(Timestamp at_time, int packets_lost);
stefan@webrtc.orgdb262472014-11-04 19:32:10 +000089
andresp@webrtc.org44caf012014-03-26 21:00:21 +000090 // Updates history of min bitrates.
91 // After this method returns min_bitrate_history_.front().second contains the
92 // min bitrate used during last kBweIncreaseIntervalMs.
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020093 void UpdateMinHistory(Timestamp at_time);
andresp@webrtc.org44caf012014-03-26 21:00:21 +000094
Sebastian Jansson7c1744d2018-10-08 11:00:50 +020095 // Cap |bitrate| to [min_bitrate_configured_, max_bitrate_configured_] and
96 // set |current_bitrate_| to the capped value and updates the event log.
97 void CapBitrateToThresholds(Timestamp at_time, DataRate bitrate);
philipel1b965312017-04-18 06:55:32 -070098
Sebastian Jansson2e068e82018-10-08 12:49:53 +020099 RttBasedBackoffConfig rtt_backoff_config_;
100
Sebastian Jansson7c1744d2018-10-08 11:00:50 +0200101 std::deque<std::pair<Timestamp, DataRate> > min_bitrate_history_;
andresp@webrtc.org44caf012014-03-26 21:00:21 +0000102
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000103 // incoming filters
Sebastian Jansson439f0bc2018-02-20 10:46:39 +0100104 int lost_packets_since_last_loss_update_;
pbosb7edb882015-10-22 08:52:20 -0700105 int expected_packets_since_last_loss_update_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000106
Sebastian Jansson7c1744d2018-10-08 11:00:50 +0200107 DataRate current_bitrate_;
108 DataRate min_bitrate_configured_;
109 DataRate max_bitrate_configured_;
110 Timestamp last_low_bitrate_log_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000111
pbosb7edb882015-10-22 08:52:20 -0700112 bool has_decreased_since_last_fraction_loss_;
Sebastian Jansson7c1744d2018-10-08 11:00:50 +0200113 Timestamp last_loss_feedback_;
114 Timestamp last_loss_packet_report_;
115 Timestamp last_timeout_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000116 uint8_t last_fraction_loss_;
stefan3821ff82016-09-04 05:07:26 -0700117 uint8_t last_logged_fraction_loss_;
Sebastian Jansson7c1744d2018-10-08 11:00:50 +0200118 TimeDelta last_round_trip_time_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000119
Sebastian Jansson2e068e82018-10-08 12:49:53 +0200120 Timestamp last_propagation_rtt_update_;
121 TimeDelta last_propagation_rtt_;
122
Sebastian Jansson7c1744d2018-10-08 11:00:50 +0200123 DataRate bwe_incoming_;
124 DataRate delay_based_bitrate_;
125 Timestamp time_last_decrease_;
126 Timestamp first_report_time_;
stefan@webrtc.org548b2282014-11-03 14:42:43 +0000127 int initially_lost_packets_;
Sebastian Jansson7c1744d2018-10-08 11:00:50 +0200128 DataRate bitrate_at_2_seconds_;
stefan@webrtc.orgdb262472014-11-04 19:32:10 +0000129 UmaState uma_update_state_;
Sebastian Jansson439f0bc2018-02-20 10:46:39 +0100130 UmaState uma_rtt_state_;
stefan@webrtc.org474e36e2015-01-19 15:44:47 +0000131 std::vector<bool> rampup_uma_stats_updated_;
terelius006d93d2015-11-05 12:02:15 -0800132 RtcEventLog* event_log_;
Sebastian Jansson7c1744d2018-10-08 11:00:50 +0200133 Timestamp last_rtc_event_log_;
Stefan Holmer52200d02016-09-20 14:14:23 +0200134 bool in_timeout_experiment_;
Stefan Holmer9c79ed92017-03-31 15:53:27 +0200135 float low_loss_threshold_;
136 float high_loss_threshold_;
Sebastian Jansson7c1744d2018-10-08 11:00:50 +0200137 DataRate bitrate_threshold_;
pwestin@webrtc.org1cd11622012-04-19 12:13:52 +0000138};
139} // namespace webrtc
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200140#endif // MODULES_BITRATE_CONTROLLER_SEND_SIDE_BANDWIDTH_ESTIMATION_H_