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