• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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_CONGESTION_CONTROLLER_GOOG_CC_LOSS_BASED_BANDWIDTH_ESTIMATION_H_
12 #define MODULES_CONGESTION_CONTROLLER_GOOG_CC_LOSS_BASED_BANDWIDTH_ESTIMATION_H_
13 
14 #include <vector>
15 
16 #include "api/field_trials_view.h"
17 #include "api/transport/network_types.h"
18 #include "api/units/data_rate.h"
19 #include "api/units/time_delta.h"
20 #include "api/units/timestamp.h"
21 #include "rtc_base/experiments/field_trial_parser.h"
22 
23 namespace webrtc {
24 
25 struct LossBasedControlConfig {
26   explicit LossBasedControlConfig(const FieldTrialsView* key_value_config);
27   LossBasedControlConfig(const LossBasedControlConfig&);
28   LossBasedControlConfig& operator=(const LossBasedControlConfig&) = default;
29   ~LossBasedControlConfig();
30   bool enabled;
31   FieldTrialParameter<double> min_increase_factor;
32   FieldTrialParameter<double> max_increase_factor;
33   FieldTrialParameter<TimeDelta> increase_low_rtt;
34   FieldTrialParameter<TimeDelta> increase_high_rtt;
35   FieldTrialParameter<double> decrease_factor;
36   FieldTrialParameter<TimeDelta> loss_window;
37   FieldTrialParameter<TimeDelta> loss_max_window;
38   FieldTrialParameter<TimeDelta> acknowledged_rate_max_window;
39   FieldTrialParameter<DataRate> increase_offset;
40   FieldTrialParameter<DataRate> loss_bandwidth_balance_increase;
41   FieldTrialParameter<DataRate> loss_bandwidth_balance_decrease;
42   FieldTrialParameter<DataRate> loss_bandwidth_balance_reset;
43   FieldTrialParameter<double> loss_bandwidth_balance_exponent;
44   FieldTrialParameter<bool> allow_resets;
45   FieldTrialParameter<TimeDelta> decrease_interval;
46   FieldTrialParameter<TimeDelta> loss_report_timeout;
47 };
48 
49 // Estimates an upper BWE limit based on loss.
50 // It requires knowledge about lost packets and acknowledged bitrate.
51 // Ie, this class require transport feedback.
52 class LossBasedBandwidthEstimation {
53  public:
54   explicit LossBasedBandwidthEstimation(
55       const FieldTrialsView* key_value_config);
56   // Returns the new estimate.
57   DataRate Update(Timestamp at_time,
58                   DataRate min_bitrate,
59                   DataRate wanted_bitrate,
60                   TimeDelta last_round_trip_time);
61   void UpdateAcknowledgedBitrate(DataRate acknowledged_bitrate,
62                                  Timestamp at_time);
63   void Initialize(DataRate bitrate);
Enabled()64   bool Enabled() const { return config_.enabled; }
65   // Returns true if LossBasedBandwidthEstimation is enabled and have
66   // received loss statistics. Ie, this class require transport feedback.
InUse()67   bool InUse() const {
68     return Enabled() && last_loss_packet_report_.IsFinite();
69   }
70   void UpdateLossStatistics(const std::vector<PacketResult>& packet_results,
71                             Timestamp at_time);
GetEstimate()72   DataRate GetEstimate() const { return loss_based_bitrate_; }
73 
74  private:
75   friend class GoogCcStatePrinter;
76   void Reset(DataRate bitrate);
77   double loss_increase_threshold() const;
78   double loss_decrease_threshold() const;
79   double loss_reset_threshold() const;
80 
81   DataRate decreased_bitrate() const;
82 
83   const LossBasedControlConfig config_;
84   double average_loss_;
85   double average_loss_max_;
86   DataRate loss_based_bitrate_;
87   DataRate acknowledged_bitrate_max_;
88   Timestamp acknowledged_bitrate_last_update_;
89   Timestamp time_last_decrease_;
90   bool has_decreased_since_last_loss_report_;
91   Timestamp last_loss_packet_report_;
92   double last_loss_ratio_;
93 };
94 
95 }  // namespace webrtc
96 
97 #endif  // MODULES_CONGESTION_CONTROLLER_GOOG_CC_LOSS_BASED_BANDWIDTH_ESTIMATION_H_
98