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 WEBRTC_MODULES_VIDEO_CODING_RTT_FILTER_H_
12 #define WEBRTC_MODULES_VIDEO_CODING_RTT_FILTER_H_
13 
14 #include "webrtc/typedefs.h"
15 
16 namespace webrtc {
17 
18 class VCMRttFilter {
19  public:
20   VCMRttFilter();
21 
22   VCMRttFilter& operator=(const VCMRttFilter& rhs);
23 
24   // Resets the filter.
25   void Reset();
26   // Updates the filter with a new sample.
27   void Update(int64_t rttMs);
28   // A getter function for the current RTT level in ms.
29   int64_t RttMs() const;
30 
31  private:
32   // The size of the drift and jump memory buffers
33   // and thus also the detection threshold for these
34   // detectors in number of samples.
35   enum { kMaxDriftJumpCount = 5 };
36   // Detects RTT jumps by comparing the difference between
37   // samples and average to the standard deviation.
38   // Returns true if the long time statistics should be updated
39   // and false otherwise
40   bool JumpDetection(int64_t rttMs);
41   // Detects RTT drifts by comparing the difference between
42   // max and average to the standard deviation.
43   // Returns true if the long time statistics should be updated
44   // and false otherwise
45   bool DriftDetection(int64_t rttMs);
46   // Computes the short time average and maximum of the vector buf.
47   void ShortRttFilter(int64_t* buf, uint32_t length);
48 
49   bool _gotNonZeroUpdate;
50   double _avgRtt;
51   double _varRtt;
52   int64_t _maxRtt;
53   uint32_t _filtFactCount;
54   const uint32_t _filtFactMax;
55   const double _jumpStdDevs;
56   const double _driftStdDevs;
57   int32_t _jumpCount;
58   int32_t _driftCount;
59   const int32_t _detectThreshold;
60   int64_t _jumpBuf[kMaxDriftJumpCount];
61   int64_t _driftBuf[kMaxDriftJumpCount];
62 };
63 
64 }  // namespace webrtc
65 
66 #endif  // WEBRTC_MODULES_VIDEO_CODING_RTT_FILTER_H_
67