blob: e00726b1ff665a638a5a57d6bfce1e08727ead91 [file] [log] [blame]
Christoffer Rodbro3a837482018-11-19 15:30:23 +01001/*
2 * Copyright (c) 2018 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
11#ifndef MODULES_BITRATE_CONTROLLER_LOSS_BASED_BANDWIDTH_ESTIMATION_H_
12#define MODULES_BITRATE_CONTROLLER_LOSS_BASED_BANDWIDTH_ESTIMATION_H_
13
14#include <vector>
15
Sebastian Jansson0f557fe2019-06-17 10:14:16 +020016#include "api/transport/network_types.h"
Christoffer Rodbro3a837482018-11-19 15:30:23 +010017#include "api/units/data_rate.h"
18#include "api/units/time_delta.h"
19#include "api/units/timestamp.h"
Christoffer Rodbro3a837482018-11-19 15:30:23 +010020#include "rtc_base/experiments/field_trial_parser.h"
21
22namespace webrtc {
23
24struct LossBasedControlConfig {
25 LossBasedControlConfig();
26 LossBasedControlConfig(const LossBasedControlConfig&);
27 LossBasedControlConfig& operator=(const LossBasedControlConfig&) = default;
28 ~LossBasedControlConfig();
29 bool enabled;
30 FieldTrialParameter<double> min_increase_factor;
31 FieldTrialParameter<double> max_increase_factor;
32 FieldTrialParameter<TimeDelta> increase_low_rtt;
33 FieldTrialParameter<TimeDelta> increase_high_rtt;
34 FieldTrialParameter<double> decrease_factor;
35 FieldTrialParameter<TimeDelta> loss_window;
36 FieldTrialParameter<TimeDelta> loss_max_window;
37 FieldTrialParameter<TimeDelta> acknowledged_rate_max_window;
38 FieldTrialParameter<DataRate> increase_offset;
39 FieldTrialParameter<DataRate> loss_bandwidth_balance_increase;
40 FieldTrialParameter<DataRate> loss_bandwidth_balance_decrease;
41 FieldTrialParameter<double> loss_bandwidth_balance_exponent;
42 FieldTrialParameter<bool> allow_resets;
43 FieldTrialParameter<TimeDelta> decrease_interval;
44 FieldTrialParameter<TimeDelta> loss_report_timeout;
45};
46
47class LossBasedBandwidthEstimation {
48 public:
49 LossBasedBandwidthEstimation();
50 void Update(Timestamp at_time,
51 DataRate min_bitrate,
52 TimeDelta last_round_trip_time);
53 void UpdateAcknowledgedBitrate(DataRate acknowledged_bitrate,
54 Timestamp at_time);
Christoffer Rodbro982639c2019-01-18 15:34:59 +010055 void MaybeReset(DataRate bitrate);
56 void SetInitialBitrate(DataRate bitrate);
Christoffer Rodbro3a837482018-11-19 15:30:23 +010057 bool Enabled() const { return config_.enabled; }
58 void UpdateLossStatistics(const std::vector<PacketResult>& packet_results,
59 Timestamp at_time);
60 DataRate GetEstimate() const { return loss_based_bitrate_; }
61
62 private:
Sebastian Jansson28aced52019-06-11 11:08:20 +020063 friend class GoogCcStatePrinter;
Christoffer Rodbro982639c2019-01-18 15:34:59 +010064 void Reset(DataRate bitrate);
Sebastian Jansson28aced52019-06-11 11:08:20 +020065 double loss_increase_threshold() const;
66 double loss_decrease_threshold() const;
67 DataRate decreased_bitrate() const;
Christoffer Rodbro982639c2019-01-18 15:34:59 +010068
Christoffer Rodbro3a837482018-11-19 15:30:23 +010069 LossBasedControlConfig config_;
70 double average_loss_;
71 double average_loss_max_;
72 DataRate loss_based_bitrate_;
73 DataRate acknowledged_bitrate_max_;
74 Timestamp acknowledged_bitrate_last_update_;
75 Timestamp time_last_decrease_;
76 bool has_decreased_since_last_loss_report_;
77 Timestamp last_loss_packet_report_;
78 double last_loss_ratio_;
79};
80
81} // namespace webrtc
82
83#endif // MODULES_BITRATE_CONTROLLER_LOSS_BASED_BANDWIDTH_ESTIMATION_H_