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

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

Issue 2270773002: Add ThreadChecker to the TimestampAligner class. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 4 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
« no previous file with comments | « webrtc/base/timestampaligner.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "webrtc/base/logging.h" 11 #include "webrtc/base/logging.h"
12 #include "webrtc/base/timestampaligner.h" 12 #include "webrtc/base/timestampaligner.h"
13 13
14 namespace rtc { 14 namespace rtc {
15 15
16 TimestampAligner::TimestampAligner() : frames_seen_(0), offset_us_(0) {} 16 TimestampAligner::TimestampAligner() : frames_seen_(0), offset_us_(0) {
17 thread_checker_.DetachFromThread();
18 }
19
17 TimestampAligner::~TimestampAligner() {} 20 TimestampAligner::~TimestampAligner() {}
18 21
19 int64_t TimestampAligner::UpdateOffset(int64_t camera_time_us, 22 int64_t TimestampAligner::UpdateOffset(int64_t camera_time_us,
20 int64_t system_time_us) { 23 int64_t system_time_us) {
24 RTC_DCHECK(thread_checker_.CalledOnValidThread());
25
21 // Estimate the offset between system monotonic time and the capture 26 // Estimate the offset between system monotonic time and the capture
22 // time from the camera. The camera is assumed to provide more 27 // time from the camera. The camera is assumed to provide more
23 // accurate timestamps than we get from the system time. But the 28 // accurate timestamps than we get from the system time. But the
24 // camera may use its own free-running clock with a large offset and 29 // camera may use its own free-running clock with a large offset and
25 // a small drift compared to the system clock. So the model is 30 // a small drift compared to the system clock. So the model is
26 // basically 31 // basically
27 // 32 //
28 // y_k = c_0 + c_1 * x_k + v_k 33 // y_k = c_0 + c_1 * x_k + v_k
29 // 34 //
30 // where x_k is the camera timestamp, believed to be accurate in its 35 // where x_k is the camera timestamp, believed to be accurate in its
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 static const int kWindowSize = 100; 84 static const int kWindowSize = 100;
80 if (frames_seen_ < kWindowSize) { 85 if (frames_seen_ < kWindowSize) {
81 ++frames_seen_; 86 ++frames_seen_;
82 } 87 }
83 offset_us_ += error_us / frames_seen_; 88 offset_us_ += error_us / frames_seen_;
84 return offset_us_; 89 return offset_us_;
85 } 90 }
86 91
87 int64_t TimestampAligner::ClipTimestamp(int64_t time_us, 92 int64_t TimestampAligner::ClipTimestamp(int64_t time_us,
88 int64_t system_time_us) { 93 int64_t system_time_us) {
94 RTC_DCHECK(thread_checker_.CalledOnValidThread());
95
89 // Make timestamps monotonic. 96 // Make timestamps monotonic.
90 if (!prev_translated_time_us_) { 97 if (!prev_translated_time_us_) {
91 // Initialize. 98 // Initialize.
92 clip_bias_us_ = 0; 99 clip_bias_us_ = 0;
93 } else if (time_us < *prev_translated_time_us_) { 100 } else if (time_us < *prev_translated_time_us_) {
94 time_us = *prev_translated_time_us_; 101 time_us = *prev_translated_time_us_;
95 } 102 }
96 103
97 // Clip to make sure we don't produce time stamps in the future. 104 // Clip to make sure we don't produce time stamps in the future.
98 time_us -= clip_bias_us_; 105 time_us -= clip_bias_us_;
99 if (time_us > system_time_us) { 106 if (time_us > system_time_us) {
100 clip_bias_us_ += time_us - system_time_us; 107 clip_bias_us_ += time_us - system_time_us;
101 time_us = system_time_us; 108 time_us = system_time_us;
102 } 109 }
103 prev_translated_time_us_ = rtc::Optional<int64_t>(time_us); 110 prev_translated_time_us_ = rtc::Optional<int64_t>(time_us);
104 return time_us; 111 return time_us;
105 } 112 }
106 113
107 } // namespace rtc 114 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/base/timestampaligner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698