1 /* 2 * Copyright (c) 2011 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_VIDEO_CODING_TIMING_RTT_FILTER_H_ 12 #define MODULES_VIDEO_CODING_TIMING_RTT_FILTER_H_ 13 14 #include <stdint.h> 15 16 #include "absl/container/inlined_vector.h" 17 #include "api/units/time_delta.h" 18 19 namespace webrtc { 20 21 class RttFilter { 22 public: 23 RttFilter(); 24 RttFilter(const RttFilter&) = delete; 25 RttFilter& operator=(const RttFilter&) = delete; 26 27 // Resets the filter. 28 void Reset(); 29 // Updates the filter with a new sample. 30 void Update(TimeDelta rtt); 31 // A getter function for the current RTT level. 32 TimeDelta Rtt() const; 33 34 private: 35 // The size of the drift and jump memory buffers 36 // and thus also the detection threshold for these 37 // detectors in number of samples. 38 static constexpr int kMaxDriftJumpCount = 5; 39 using BufferList = absl::InlinedVector<TimeDelta, kMaxDriftJumpCount>; 40 41 // Detects RTT jumps by comparing the difference between 42 // samples and average to the standard deviation. 43 // Returns true if the long time statistics should be updated 44 // and false otherwise 45 bool JumpDetection(TimeDelta rtt); 46 47 // Detects RTT drifts by comparing the difference between 48 // max and average to the standard deviation. 49 // Returns true if the long time statistics should be updated 50 // and false otherwise 51 bool DriftDetection(TimeDelta rtt); 52 53 // Computes the short time average and maximum of the vector buf. 54 void ShortRttFilter(const BufferList& buf); 55 56 bool got_non_zero_update_; 57 TimeDelta avg_rtt_; 58 // Variance units are TimeDelta^2. Store as ms^2. 59 int64_t var_rtt_; 60 TimeDelta max_rtt_; 61 uint32_t filt_fact_count_; 62 bool last_jump_positive_ = false; 63 BufferList jump_buf_; 64 BufferList drift_buf_; 65 }; 66 67 } // namespace webrtc 68 69 #endif // MODULES_VIDEO_CODING_TIMING_RTT_FILTER_H_ 70