tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

bitrate_estimator.h (2304B)


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