• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2017 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_BITRATE_ESTIMATOR_H_
12 #define MODULES_CONGESTION_CONTROLLER_GOOG_CC_BITRATE_ESTIMATOR_H_
13 
14 #include <stdint.h>
15 
16 #include "absl/types/optional.h"
17 #include "api/transport/webrtc_key_value_config.h"
18 #include "api/units/data_rate.h"
19 #include "api/units/timestamp.h"
20 #include "rtc_base/experiments/field_trial_parser.h"
21 
22 namespace webrtc {
23 
24 // Computes a bayesian estimate of the throughput given acks containing
25 // the arrival time and payload size. Samples which are far from the current
26 // estimate or are based on few packets are given a smaller weight, as they
27 // are considered to be more likely to have been caused by, e.g., delay spikes
28 // unrelated to congestion.
29 class BitrateEstimator {
30  public:
31   explicit BitrateEstimator(const WebRtcKeyValueConfig* key_value_config);
32   virtual ~BitrateEstimator();
33   virtual void Update(Timestamp at_time, DataSize amount, bool in_alr);
34 
35   virtual absl::optional<DataRate> bitrate() const;
36   absl::optional<DataRate> PeekRate() const;
37 
38   virtual void ExpectFastRateChange();
39 
40  private:
41   float UpdateWindow(int64_t now_ms,
42                      int bytes,
43                      int rate_window_ms,
44                      bool* is_small_sample);
45   int sum_;
46   FieldTrialConstrained<int> initial_window_ms_;
47   FieldTrialConstrained<int> noninitial_window_ms_;
48   FieldTrialParameter<double> uncertainty_scale_;
49   FieldTrialParameter<double> uncertainty_scale_in_alr_;
50   FieldTrialParameter<double> small_sample_uncertainty_scale_;
51   FieldTrialParameter<DataSize> small_sample_threshold_;
52   FieldTrialParameter<DataRate> uncertainty_symmetry_cap_;
53   FieldTrialParameter<DataRate> estimate_floor_;
54   int64_t current_window_ms_;
55   int64_t prev_time_ms_;
56   float bitrate_estimate_kbps_;
57   float bitrate_estimate_var_;
58 };
59 
60 }  // namespace webrtc
61 
62 #endif  // MODULES_CONGESTION_CONTROLLER_GOOG_CC_BITRATE_ESTIMATOR_H_
63