Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: webrtc/base/timestampaligner.h

Issue 2325563002: New method TimestampAligner::TranslateTimestamp (Closed)
Patch Set: Log (unlikely) duplicate timestamps. Improve comments. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "webrtc/base/basictypes.h" 14 #include "webrtc/base/basictypes.h"
15 #include "webrtc/base/constructormagic.h" 15 #include "webrtc/base/constructormagic.h"
16 #include "webrtc/base/optional.h"
17 16
18 namespace rtc { 17 namespace rtc {
19 18
19 // The TimestampAligner class helps translating camera timestamps into
20 // the same timescale as is used by rtc::TimeMicros(). Some cameras
21 // have built in timestamping which is more accurate than reading the
22 // system clock, but using a different epoch and unknown clock drift.
23 // Frame timestamps in webrtc should rtc::TimeMicros (system monotonic
perkj_webrtc 2016/09/12 09:33:46 should use
nisse-webrtc 2016/09/12 12:04:20 Done.
24 // time), and this class provides a filter which lets us use the
25 // rtc::TimeMicros timescale, and at the same time take advantage of
26 // higher accuracy of the camera clock.
27
20 // This class is not thread safe, so all calls to it must be synchronized 28 // This class is not thread safe, so all calls to it must be synchronized
21 // externally. 29 // externally.
22 class TimestampAligner { 30 class TimestampAligner {
23 public: 31 public:
24 TimestampAligner(); 32 TimestampAligner();
25 ~TimestampAligner(); 33 ~TimestampAligner();
26 34
27 public: 35 public:
36 // Translates camera timestamps to the same timescale as is used by
37 // rtc::TimeMicros(). |camera_time_us| is assumed to be accurate, but
38 // with an unknown epoch and clock drift. |system_time_us| is
39 // time according to rtc::TimeMicros(), preferably read as soon as
40 // possible when the frame is captured. It may have poor accuracy
41 // due to poor resolution or scheduling delays. Returns the
42 // translated timestamp.
43 int64_t TranslateTimestamp(int64_t camera_time_us, int64_t system_time_us);
44
45 protected:
28 // Update the estimated offset between camera time and system monotonic time. 46 // Update the estimated offset between camera time and system monotonic time.
29 int64_t UpdateOffset(int64_t camera_time_us, int64_t system_time_us); 47 int64_t UpdateOffset(int64_t camera_time_us, int64_t system_time_us);
30 48
49 // Clip timestamp, return value is larger than the previous
50 // timestamp but no larger than |system_time_us|.
perkj_webrtc 2016/09/12 09:33:46 nit: Can you refrase this to say that the return v
nisse-webrtc 2016/09/12 12:04:20 It's a bit more complicated than that, but I've gi
31 int64_t ClipTimestamp(int64_t filtered_time_us, int64_t system_time_us); 51 int64_t ClipTimestamp(int64_t filtered_time_us, int64_t system_time_us);
32 52
33 private: 53 private:
34 // State for the timestamp translation. 54 // State for the timestamp translation.
35 int frames_seen_; 55 int frames_seen_;
36 // Estimated offset between camera time and system monotonic time. 56 // Estimated offset between camera time and system monotonic time.
37 int64_t offset_us_; 57 int64_t offset_us_;
38 58
39 // State for timestamp clipping, applied after the filter, to ensure 59 // State for the ClipTimestamp method, applied after the filter.
40 // that translated timestamps are monotonic and not in the future. 60
perkj_webrtc 2016/09/12 09:33:46 nit: remove empty line.
nisse-webrtc 2016/09/12 12:04:20 Done. I was thinking of that line as a heading for
41 // Subtracted from the translated timestamps. 61 // A large negative camera clock drift tends to push translated
62 // timestamps into the future. |clip_bias_us_| is subtracted from the
63 // translated timestamps, to get them back from the future.
42 int64_t clip_bias_us_; 64 int64_t clip_bias_us_;
43 rtc::Optional<int64_t> prev_translated_time_us_; 65 // Used to ensure that translated timestamps are monotonous.
66 int64_t prev_translated_time_us_;
44 RTC_DISALLOW_COPY_AND_ASSIGN(TimestampAligner); 67 RTC_DISALLOW_COPY_AND_ASSIGN(TimestampAligner);
45 }; 68 };
46 69
47 } // namespace rtc 70 } // namespace rtc
48 71
49 #endif // WEBRTC_BASE_TIMESTAMPALIGNER_H_ 72 #endif // WEBRTC_BASE_TIMESTAMPALIGNER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698