Christoffer Rodbro | 3a83748 | 2018-11-19 15:30:23 +0100 | [diff] [blame] | 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_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 | |
| 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); |
Christoffer Rodbro | 982639c | 2019-01-18 15:34:59 +0100 | [diff] [blame^] | 55 | void MaybeReset(DataRate bitrate); |
| 56 | void SetInitialBitrate(DataRate bitrate); |
Christoffer Rodbro | 3a83748 | 2018-11-19 15:30:23 +0100 | [diff] [blame] | 57 | 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: |
Christoffer Rodbro | 982639c | 2019-01-18 15:34:59 +0100 | [diff] [blame^] | 63 | void Reset(DataRate bitrate); |
| 64 | |
Christoffer Rodbro | 3a83748 | 2018-11-19 15:30:23 +0100 | [diff] [blame] | 65 | LossBasedControlConfig config_; |
| 66 | double average_loss_; |
| 67 | double average_loss_max_; |
| 68 | DataRate loss_based_bitrate_; |
| 69 | DataRate acknowledged_bitrate_max_; |
| 70 | Timestamp acknowledged_bitrate_last_update_; |
| 71 | Timestamp time_last_decrease_; |
| 72 | bool has_decreased_since_last_loss_report_; |
| 73 | Timestamp last_loss_packet_report_; |
| 74 | double last_loss_ratio_; |
| 75 | }; |
| 76 | |
| 77 | } // namespace webrtc |
| 78 | |
| 79 | #endif // MODULES_BITRATE_CONTROLLER_LOSS_BASED_BANDWIDTH_ESTIMATION_H_ |