OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_CAST_CAST_DEFINES_H_ | 5 #ifndef MEDIA_CAST_CAST_DEFINES_H_ |
6 #define MEDIA_CAST_CAST_DEFINES_H_ | 6 #define MEDIA_CAST_CAST_DEFINES_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 | 171 |
172 int64 ntp_time_us = | 172 int64 ntp_time_us = |
173 elapsed_since_unix_epoch.InMicroseconds() + | 173 elapsed_since_unix_epoch.InMicroseconds() + |
174 (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond); | 174 (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond); |
175 | 175 |
176 ConvertTimeToFractions(ntp_time_us, ntp_seconds, ntp_fractions); | 176 ConvertTimeToFractions(ntp_time_us, ntp_seconds, ntp_fractions); |
177 } | 177 } |
178 | 178 |
179 inline base::TimeTicks ConvertNtpToTimeTicks(uint32 ntp_seconds, | 179 inline base::TimeTicks ConvertNtpToTimeTicks(uint32 ntp_seconds, |
180 uint32 ntp_fractions) { | 180 uint32 ntp_fractions) { |
181 int64 ntp_time_us = | 181 // We need to ceil() here because the calculation of |fractions| in |
wolenetz
2014/10/21 19:15:15
nit: fix compilation by #including std::ceil
Peter Kasting
2014/10/21 19:34:47
Done.
| |
182 static_cast<int64>(ntp_seconds) * base::Time::kMicrosecondsPerSecond + | 182 // ConvertTimeToFractions() effectively does a floor(). |
183 static_cast<int64>(ntp_fractions) / kMagicFractionalUnit; | 183 int64 ntp_time_us = ntp_seconds * base::Time::kMicrosecondsPerSecond + |
184 static_cast<int64>(std::ceil(ntp_fractions / kMagicFractionalUnit)); | |
wolenetz
2014/10/21 19:15:15
Though this works for the unit tests' hardcoded ti
wolenetz
2014/10/21 19:22:00
From offline chat w/pkasting@, the behavior-invari
Peter Kasting
2014/10/21 19:34:47
More detail:
ceil() here is correct if we're tryi
| |
184 | 185 |
185 base::TimeDelta elapsed_since_unix_epoch = base::TimeDelta::FromMicroseconds( | 186 base::TimeDelta elapsed_since_unix_epoch = base::TimeDelta::FromMicroseconds( |
186 ntp_time_us - | 187 ntp_time_us - |
187 (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond)); | 188 (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond)); |
188 return base::TimeTicks::UnixEpoch() + elapsed_since_unix_epoch; | 189 return base::TimeTicks::UnixEpoch() + elapsed_since_unix_epoch; |
189 } | 190 } |
190 | 191 |
191 inline base::TimeDelta RtpDeltaToTimeDelta(int64 rtp_delta, int rtp_timebase) { | 192 inline base::TimeDelta RtpDeltaToTimeDelta(int64 rtp_delta, int rtp_timebase) { |
192 DCHECK_GT(rtp_timebase, 0); | 193 DCHECK_GT(rtp_timebase, 0); |
193 return rtp_delta * base::TimeDelta::FromSeconds(1) / rtp_timebase; | 194 return rtp_delta * base::TimeDelta::FromSeconds(1) / rtp_timebase; |
194 } | 195 } |
195 | 196 |
196 inline int64 TimeDeltaToRtpDelta(base::TimeDelta delta, int rtp_timebase) { | 197 inline int64 TimeDeltaToRtpDelta(base::TimeDelta delta, int rtp_timebase) { |
197 DCHECK_GT(rtp_timebase, 0); | 198 DCHECK_GT(rtp_timebase, 0); |
198 return delta * rtp_timebase / base::TimeDelta::FromSeconds(1); | 199 return delta * rtp_timebase / base::TimeDelta::FromSeconds(1); |
199 } | 200 } |
200 | 201 |
201 } // namespace cast | 202 } // namespace cast |
202 } // namespace media | 203 } // namespace media |
203 | 204 |
204 #endif // MEDIA_CAST_CAST_DEFINES_H_ | 205 #endif // MEDIA_CAST_CAST_DEFINES_H_ |
OLD | NEW |