| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright (c) 2016 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_BASE_TIMESTAMPALIGNER_H_ | 11 #ifndef WEBRTC_BASE_TIMESTAMPALIGNER_H_ |
| 12 #define WEBRTC_BASE_TIMESTAMPALIGNER_H_ | 12 #define WEBRTC_BASE_TIMESTAMPALIGNER_H_ |
| 13 | 13 |
| 14 #include <stdint.h> | |
| 15 | 14 |
| 16 #include "webrtc/base/constructormagic.h" | 15 // This header is deprecated and is just left here temporarily during |
| 17 | 16 // refactoring. See https://bugs.webrtc.org/7634 for more details. |
| 18 namespace rtc { | 17 #include "webrtc/rtc_base/timestampaligner.h" |
| 19 | |
| 20 // The TimestampAligner class helps translating camera timestamps into | |
| 21 // the same timescale as is used by rtc::TimeMicros(). Some cameras | |
| 22 // have built in timestamping which is more accurate than reading the | |
| 23 // system clock, but using a different epoch and unknown clock drift. | |
| 24 // Frame timestamps in webrtc should use rtc::TimeMicros (system monotonic | |
| 25 // time), and this class provides a filter which lets us use the | |
| 26 // rtc::TimeMicros timescale, and at the same time take advantage of | |
| 27 // higher accuracy of the camera clock. | |
| 28 | |
| 29 // This class is not thread safe, so all calls to it must be synchronized | |
| 30 // externally. | |
| 31 class TimestampAligner { | |
| 32 public: | |
| 33 TimestampAligner(); | |
| 34 ~TimestampAligner(); | |
| 35 | |
| 36 public: | |
| 37 // Translates camera timestamps to the same timescale as is used by | |
| 38 // rtc::TimeMicros(). |camera_time_us| is assumed to be accurate, but | |
| 39 // with an unknown epoch and clock drift. |system_time_us| is | |
| 40 // time according to rtc::TimeMicros(), preferably read as soon as | |
| 41 // possible when the frame is captured. It may have poor accuracy | |
| 42 // due to poor resolution or scheduling delays. Returns the | |
| 43 // translated timestamp. | |
| 44 int64_t TranslateTimestamp(int64_t camera_time_us, int64_t system_time_us); | |
| 45 | |
| 46 protected: | |
| 47 // Update the estimated offset between camera time and system monotonic time. | |
| 48 int64_t UpdateOffset(int64_t camera_time_us, int64_t system_time_us); | |
| 49 | |
| 50 // Clip timestamp, return value is always | |
| 51 // <= |system_time_us|, and | |
| 52 // >= min(|prev_translated_time_us_| + |kMinFrameIntervalUs|, | |
| 53 // |system_time_us|). | |
| 54 int64_t ClipTimestamp(int64_t filtered_time_us, int64_t system_time_us); | |
| 55 | |
| 56 private: | |
| 57 // State for the timestamp translation. | |
| 58 int frames_seen_; | |
| 59 // Estimated offset between camera time and system monotonic time. | |
| 60 int64_t offset_us_; | |
| 61 | |
| 62 // State for the ClipTimestamp method, applied after the filter. | |
| 63 // A large negative camera clock drift tends to push translated | |
| 64 // timestamps into the future. |clip_bias_us_| is subtracted from the | |
| 65 // translated timestamps, to get them back from the future. | |
| 66 int64_t clip_bias_us_; | |
| 67 // Used to ensure that translated timestamps are monotonous. | |
| 68 int64_t prev_translated_time_us_; | |
| 69 RTC_DISALLOW_COPY_AND_ASSIGN(TimestampAligner); | |
| 70 }; | |
| 71 | |
| 72 } // namespace rtc | |
| 73 | 18 |
| 74 #endif // WEBRTC_BASE_TIMESTAMPALIGNER_H_ | 19 #endif // WEBRTC_BASE_TIMESTAMPALIGNER_H_ |
| OLD | NEW |