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 SYSTEM_WRAPPERS_INCLUDE_TIMESTAMP_EXTRAPOLATOR_H_
12 #define SYSTEM_WRAPPERS_INCLUDE_TIMESTAMP_EXTRAPOLATOR_H_
13 
14 #include "webrtc/system_wrappers/include/rw_lock_wrapper.h"
15 #include "webrtc/typedefs.h"
16 
17 namespace webrtc
18 {
19 
20 class TimestampExtrapolator
21 {
22 public:
23     explicit TimestampExtrapolator(int64_t start_ms);
24     ~TimestampExtrapolator();
25     void Update(int64_t tMs, uint32_t ts90khz);
26     int64_t ExtrapolateLocalTime(uint32_t timestamp90khz);
27     void Reset(int64_t start_ms);
28 
29 private:
30     void CheckForWrapArounds(uint32_t ts90khz);
31     bool DelayChangeDetection(double error);
32     RWLockWrapper*        _rwLock;
33     double                _w[2];
34     double                _pP[2][2];
35     int64_t         _startMs;
36     int64_t         _prevMs;
37     uint32_t        _firstTimestamp;
38     int32_t         _wrapArounds;
39     int64_t         _prevUnwrappedTimestamp;
40     int64_t         _prevWrapTimestamp;
41     const double          _lambda;
42     bool                  _firstAfterReset;
43     uint32_t        _packetCount;
44     const uint32_t  _startUpFilterDelayInPackets;
45 
46     double              _detectorAccumulatorPos;
47     double              _detectorAccumulatorNeg;
48     const double        _alarmThreshold;
49     const double        _accDrift;
50     const double        _accMaxError;
51     const double        _pP11;
52 };
53 
54 }  // namespace webrtc
55 
56 #endif // SYSTEM_WRAPPERS_INCLUDE_TIMESTAMP_EXTRAPOLATOR_H_
57