blob: d9c5c6fb37bdd96c1f750b825290765852e1b712 [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
kjellanderd56d68c2015-11-02 02:12:41 -080011#ifndef SYSTEM_WRAPPERS_INCLUDE_TIMESTAMP_EXTRAPOLATOR_H_
12#define SYSTEM_WRAPPERS_INCLUDE_TIMESTAMP_EXTRAPOLATOR_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
Henrik Kjellander98f53512015-10-28 18:17:40 +010014#include "webrtc/system_wrappers/include/rw_lock_wrapper.h"
pbos@webrtc.orga4407322013-07-16 12:32:05 +000015#include "webrtc/typedefs.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000016
17namespace webrtc
18{
19
wu@webrtc.org66773a02014-05-07 17:09:44 +000020class TimestampExtrapolator
niklase@google.com470e71d2011-07-07 08:21:25 +000021{
22public:
wu@webrtc.org66773a02014-05-07 17:09:44 +000023 explicit TimestampExtrapolator(int64_t start_ms);
24 ~TimestampExtrapolator();
stefan@webrtc.org34c5da62014-04-11 14:08:35 +000025 void Update(int64_t tMs, uint32_t ts90khz);
stefan@webrtc.org9f557c12013-05-17 12:55:07 +000026 int64_t ExtrapolateLocalTime(uint32_t timestamp90khz);
wu@webrtc.orged4cb562014-05-06 04:50:49 +000027 void Reset(int64_t start_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +000028
29private:
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000030 void CheckForWrapArounds(uint32_t ts90khz);
stefan@webrtc.org34c5da62014-04-11 14:08:35 +000031 bool DelayChangeDetection(double error);
stefan@webrtc.org7889a9b2011-12-12 08:18:24 +000032 RWLockWrapper* _rwLock;
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +000033 double _w[2];
andrew@webrtc.orgcc476aa2014-10-31 16:01:25 +000034 double _pP[2][2];
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000035 int64_t _startMs;
36 int64_t _prevMs;
37 uint32_t _firstTimestamp;
38 int32_t _wrapArounds;
stefan@webrtc.org9f557c12013-05-17 12:55:07 +000039 int64_t _prevUnwrappedTimestamp;
40 int64_t _prevWrapTimestamp;
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +000041 const double _lambda;
42 bool _firstAfterReset;
pbos@webrtc.org7b859cc2013-04-02 15:54:38 +000043 uint32_t _packetCount;
44 const uint32_t _startUpFilterDelayInPackets;
niklase@google.com470e71d2011-07-07 08:21:25 +000045
46 double _detectorAccumulatorPos;
47 double _detectorAccumulatorNeg;
48 const double _alarmThreshold;
49 const double _accDrift;
50 const double _accMaxError;
andrew@webrtc.orgcc476aa2014-10-31 16:01:25 +000051 const double _pP11;
niklase@google.com470e71d2011-07-07 08:21:25 +000052};
53
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000054} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000055
kjellanderd56d68c2015-11-02 02:12:41 -080056#endif // SYSTEM_WRAPPERS_INCLUDE_TIMESTAMP_EXTRAPOLATOR_H_