blob: 63af57b2275a688a8bb8ee49c40d0e29c974517e [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
Niels Möllera12c42a2018-07-25 16:05:48 +020014#include <stdint.h>
15
Karl Wiberg2b857922018-03-23 14:53:54 +010016#include "rtc_base/synchronization/rw_lock_wrapper.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000017
Karl Wiberg79eb1d92017-11-08 12:26:07 +010018namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000019
Karl Wiberg79eb1d92017-11-08 12:26:07 +010020class 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.com470e71d2011-07-07 08:21:25 +000027
Karl Wiberg79eb1d92017-11-08 12:26:07 +010028 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.com470e71d2011-07-07 08:21:25 +000044
Karl Wiberg79eb1d92017-11-08 12:26:07 +010045 double _detectorAccumulatorPos;
46 double _detectorAccumulatorNeg;
47 const double _alarmThreshold;
48 const double _accDrift;
49 const double _accMaxError;
50 const double _pP11;
niklase@google.com470e71d2011-07-07 08:21:25 +000051};
52
pbos@webrtc.orgd900e8b2013-07-03 15:12:26 +000053} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +000054
Karl Wiberg76b7f512018-03-22 15:29:03 +010055#endif // RTC_BASE_TIME_TIMESTAMP_EXTRAPOLATOR_H_