1 /* 2 * Copyright (c) 2013 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 #ifndef MODULES_REMOTE_BITRATE_ESTIMATOR_OVERUSE_ESTIMATOR_H_ 11 #define MODULES_REMOTE_BITRATE_ESTIMATOR_OVERUSE_ESTIMATOR_H_ 12 13 #include <stdint.h> 14 15 #include <deque> 16 17 #include "api/network_state_predictor.h" 18 19 namespace webrtc { 20 21 // Bandwidth over-use detector options. These are used to drive 22 // experimentation with bandwidth estimation parameters. 23 // TODO(terelius): This is only used in overuse_estimator.cc, and only in the 24 // default constructed state. Can we move the relevant variables into that 25 // class and delete this? 26 struct OverUseDetectorOptions { 27 OverUseDetectorOptions() = default; 28 double initial_slope = 8.0 / 512.0; 29 double initial_offset = 0; 30 double initial_e[2][2] = {{100.0, 0.0}, {0.0, 1e-1}}; 31 double initial_process_noise[2] = {1e-13, 1e-3}; 32 double initial_avg_noise = 0.0; 33 double initial_var_noise = 50.0; 34 }; 35 36 class OveruseEstimator { 37 public: 38 explicit OveruseEstimator(const OverUseDetectorOptions& options); 39 ~OveruseEstimator(); 40 41 OveruseEstimator(const OveruseEstimator&) = delete; 42 OveruseEstimator& operator=(const OveruseEstimator&) = delete; 43 44 // Update the estimator with a new sample. The deltas should represent deltas 45 // between timestamp groups as defined by the InterArrival class. 46 // `current_hypothesis` should be the hypothesis of the over-use detector at 47 // this time. 48 void Update(int64_t t_delta, 49 double ts_delta, 50 int size_delta, 51 BandwidthUsage current_hypothesis, 52 int64_t now_ms); 53 54 // Returns the estimated noise/jitter variance in ms^2. var_noise()55 double var_noise() const { return var_noise_; } 56 57 // Returns the estimated inter-arrival time delta offset in ms. offset()58 double offset() const { return offset_; } 59 60 // Returns the number of deltas which the current over-use estimator state is 61 // based on. num_of_deltas()62 unsigned int num_of_deltas() const { return num_of_deltas_; } 63 64 private: 65 double UpdateMinFramePeriod(double ts_delta); 66 void UpdateNoiseEstimate(double residual, double ts_delta, bool stable_state); 67 68 // Must be first member variable. Cannot be const because we need to be 69 // copyable. 70 OverUseDetectorOptions options_; 71 uint16_t num_of_deltas_; 72 double slope_; 73 double offset_; 74 double prev_offset_; 75 double E_[2][2]; 76 double process_noise_[2]; 77 double avg_noise_; 78 double var_noise_; 79 std::deque<double> ts_delta_hist_; 80 }; 81 } // namespace webrtc 82 83 #endif // MODULES_REMOTE_BITRATE_ESTIMATOR_OVERUSE_ESTIMATOR_H_ 84