blob: cd4f5f422fe62259e0c3201a3f2ed4351bb049c7 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
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 Wiberg76b7f512018-03-22 15:29:03 +010011#ifndef RTC_BASE_TIME_TIMESTAMP_EXTRAPOLATOR_H_
12#define RTC_BASE_TIME_TIMESTAMP_EXTRAPOLATOR_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "system_wrappers/include/rw_lock_wrapper.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020015#include "typedefs.h" // NOLINT(build/include)
niklase@google.com470e71d2011-07-07 08:21:25 +000016
Karl Wiberg79eb1d92017-11-08 12:26:07 +010017namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000018
Karl Wiberg79eb1d92017-11-08 12:26:07 +010019class 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.com470e71d2011-07-07 08:21:25 +000026
Karl Wiberg79eb1d92017-11-08 12:26:07 +010027 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.com470e71d2011-07-07 08:21:25 +000043
Karl Wiberg79eb1d92017-11-08 12:26:07 +010044 double _detectorAccumulatorPos;
45 double _detectorAccumulatorNeg;
46 const double _alarmThreshold;
47 const double _accDrift;
48 const double _accMaxError;
49 const double _pP11;
niklase@google.com470e71d2011-07-07 08:21:25 +000050};
51
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000052} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000053
Karl Wiberg76b7f512018-03-22 15:29:03 +010054#endif // RTC_BASE_TIME_TIMESTAMP_EXTRAPOLATOR_H_