blob: 0f560769ba43c5d823fd56fbbc089e627c95e6f9 [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
16#include "api/units/data_rate.h"
17#include "api/units/time_delta.h"
18#include "api/units/timestamp.h"
19#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
20#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);
55 void MaybeReset(DataRate bitrate) {
56 if (config_.allow_resets)
57 loss_based_bitrate_ = bitrate;
58 }
59 void SetInitialBitrate(DataRate bitrate) { loss_based_bitrate_ = bitrate; }
60 bool Enabled() const { return config_.enabled; }
61 void UpdateLossStatistics(const std::vector<PacketResult>& packet_results,
62 Timestamp at_time);
63 DataRate GetEstimate() const { return loss_based_bitrate_; }
64
65 private:
66 LossBasedControlConfig config_;
67 double average_loss_;
68 double average_loss_max_;
69 DataRate loss_based_bitrate_;
70 DataRate acknowledged_bitrate_max_;
71 Timestamp acknowledged_bitrate_last_update_;
72 Timestamp time_last_decrease_;
73 bool has_decreased_since_last_loss_report_;
74 Timestamp last_loss_packet_report_;
75 double last_loss_ratio_;
76};
77
78} // namespace webrtc
79
80#endif // MODULES_BITRATE_CONTROLLER_LOSS_BASED_BANDWIDTH_ESTIMATION_H_