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

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

Issue 2325563002: New method TimestampAligner::TranslateTimestamp (Closed)
Patch Set: 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
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 offset_us_ += error_us / frames_seen_; 84 offset_us_ += error_us / frames_seen_;
85 return offset_us_; 85 return offset_us_;
86 } 86 }
87 87
88 int64_t TimestampAligner::ClipTimestamp(int64_t time_us, 88 int64_t TimestampAligner::ClipTimestamp(int64_t time_us,
89 int64_t system_time_us) { 89 int64_t system_time_us) {
90 // Make timestamps monotonic. 90 // Make timestamps monotonic.
91 if (!prev_translated_time_us_) { 91 if (!prev_translated_time_us_) {
92 // Initialize. 92 // Initialize.
93 clip_bias_us_ = 0; 93 clip_bias_us_ = 0;
94 } else if (time_us < *prev_translated_time_us_) { 94 // We expect that users always call ClipTimestamp together with
95 time_us = *prev_translated_time_us_; 95 // UpdateOffset. Then at reset, we always get the translated
96 // timestamp, time_us, equal to system_time_us. Which also ensures
perkj_webrtc 2016/09/08 07:25:23 nit: |time_us|
97 // that we get monotonous timestamps over a reset.
98 RTC_DCHECK_EQ(time_us, system_time_us);
nisse-webrtc 2016/09/08 08:14:09 On second look, it appears this expectation is not
99 } else if (time_us <= *prev_translated_time_us_) {
100 time_us = *prev_translated_time_us_ + 1;
96 } 101 }
97 102
98 // Clip to make sure we don't produce time stamps in the future. 103 // Clip to make sure we don't produce timestamps in the future. In
104 // the anomalous case that this function is called multiple times
105 // with exactly the same system_time_us, we may also output the same
106 // timestamp several times, violating strict monotonicity.
99 time_us -= clip_bias_us_; 107 time_us -= clip_bias_us_;
100 if (time_us > system_time_us) { 108 if (time_us > system_time_us) {
101 clip_bias_us_ += time_us - system_time_us; 109 clip_bias_us_ += time_us - system_time_us;
102 time_us = system_time_us; 110 time_us = system_time_us;
103 } 111 }
104 prev_translated_time_us_ = rtc::Optional<int64_t>(time_us); 112 prev_translated_time_us_ = rtc::Optional<int64_t>(time_us);
105 return time_us; 113 return time_us;
106 } 114 }
107 115
108 } // namespace rtc 116 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698