niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | |
Karl Wiberg | 76b7f51 | 2018-03-22 15:29:03 +0100 | [diff] [blame] | 11 | #ifndef RTC_BASE_TIME_TIMESTAMP_EXTRAPOLATOR_H_ |
| 12 | #define RTC_BASE_TIME_TIMESTAMP_EXTRAPOLATOR_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
Karl Wiberg | 2b85792 | 2018-03-23 14:53:54 +0100 | [diff] [blame] | 14 | #include "rtc_base/synchronization/rw_lock_wrapper.h" |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 15 | #include "typedefs.h" // NOLINT(build/include) |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 16 | |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 17 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 18 | |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 19 | class TimestampExtrapolator { |
| 20 | public: |
| 21 | explicit TimestampExtrapolator(int64_t start_ms); |
| 22 | ~TimestampExtrapolator(); |
| 23 | void Update(int64_t tMs, uint32_t ts90khz); |
| 24 | int64_t ExtrapolateLocalTime(uint32_t timestamp90khz); |
| 25 | void Reset(int64_t start_ms); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 27 | private: |
| 28 | void CheckForWrapArounds(uint32_t ts90khz); |
| 29 | bool DelayChangeDetection(double error); |
| 30 | RWLockWrapper* _rwLock; |
| 31 | double _w[2]; |
| 32 | double _pP[2][2]; |
| 33 | int64_t _startMs; |
| 34 | int64_t _prevMs; |
| 35 | uint32_t _firstTimestamp; |
| 36 | int32_t _wrapArounds; |
| 37 | int64_t _prevUnwrappedTimestamp; |
| 38 | int64_t _prevWrapTimestamp; |
| 39 | const double _lambda; |
| 40 | bool _firstAfterReset; |
| 41 | uint32_t _packetCount; |
| 42 | const uint32_t _startUpFilterDelayInPackets; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | |
Karl Wiberg | 79eb1d9 | 2017-11-08 12:26:07 +0100 | [diff] [blame] | 44 | double _detectorAccumulatorPos; |
| 45 | double _detectorAccumulatorNeg; |
| 46 | const double _alarmThreshold; |
| 47 | const double _accDrift; |
| 48 | const double _accMaxError; |
| 49 | const double _pP11; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 50 | }; |
| 51 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 52 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | |
Karl Wiberg | 76b7f51 | 2018-03-22 15:29:03 +0100 | [diff] [blame] | 54 | #endif // RTC_BASE_TIME_TIMESTAMP_EXTRAPOLATOR_H_ |