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