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 11 #ifndef MODULES_VIDEO_CODING_TIMING_TIMESTAMP_EXTRAPOLATOR_H_ 12 #define MODULES_VIDEO_CODING_TIMING_TIMESTAMP_EXTRAPOLATOR_H_ 13 14 #include <stdint.h> 15 16 #include "absl/types/optional.h" 17 #include "api/units/timestamp.h" 18 #include "modules/include/module_common_types_public.h" 19 20 namespace webrtc { 21 22 // Not thread safe. 23 class TimestampExtrapolator { 24 public: 25 explicit TimestampExtrapolator(Timestamp start); 26 void Update(Timestamp now, uint32_t ts90khz); 27 absl::optional<Timestamp> ExtrapolateLocalTime(uint32_t timestamp90khz) const; 28 void Reset(Timestamp start); 29 30 private: 31 void CheckForWrapArounds(uint32_t ts90khz); 32 bool DelayChangeDetection(double error); 33 34 double w_[2]; 35 double p_[2][2]; 36 Timestamp start_; 37 Timestamp prev_; 38 absl::optional<int64_t> first_unwrapped_timestamp_; 39 TimestampUnwrapper unwrapper_; 40 absl::optional<int64_t> prev_unwrapped_timestamp_; 41 uint32_t packet_count_; 42 double detector_accumulator_pos_; 43 double detector_accumulator_neg_; 44 }; 45 46 } // namespace webrtc 47 48 #endif // MODULES_VIDEO_CODING_TIMING_TIMESTAMP_EXTRAPOLATOR_H_ 49