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