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/transport/network_types.h" 17 #include "api/units/data_rate.h" 18 #include "api/units/time_delta.h" 19 #include "api/units/timestamp.h" 20 #include "rtc_base/experiments/field_trial_parser.h" 21 22 namespace webrtc { 23 24 struct 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 47 class 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 void SetInitialBitrate(DataRate bitrate); Enabled()57 bool Enabled() const { return config_.enabled; } 58 void UpdateLossStatistics(const std::vector<PacketResult>& packet_results, 59 Timestamp at_time); GetEstimate()60 DataRate GetEstimate() const { return loss_based_bitrate_; } 61 62 private: 63 friend class GoogCcStatePrinter; 64 void Reset(DataRate bitrate); 65 double loss_increase_threshold() const; 66 double loss_decrease_threshold() const; 67 DataRate decreased_bitrate() const; 68 69 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_CONGESTION_CONTROLLER_GOOG_CC_LOSS_BASED_BANDWIDTH_ESTIMATION_H_ 84