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 <cmath> |
10 #include <map> | 11 #include <map> |
11 #include <set> | 12 #include <set> |
12 | 13 |
13 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
14 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/time/time.h" | 17 #include "base/time/time.h" |
17 #include "media/cast/net/cast_transport_config.h" | 18 #include "media/cast/net/cast_transport_config.h" |
18 | 19 |
19 namespace media { | 20 namespace media { |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 172 |
172 int64 ntp_time_us = | 173 int64 ntp_time_us = |
173 elapsed_since_unix_epoch.InMicroseconds() + | 174 elapsed_since_unix_epoch.InMicroseconds() + |
174 (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond); | 175 (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond); |
175 | 176 |
176 ConvertTimeToFractions(ntp_time_us, ntp_seconds, ntp_fractions); | 177 ConvertTimeToFractions(ntp_time_us, ntp_seconds, ntp_fractions); |
177 } | 178 } |
178 | 179 |
179 inline base::TimeTicks ConvertNtpToTimeTicks(uint32 ntp_seconds, | 180 inline base::TimeTicks ConvertNtpToTimeTicks(uint32 ntp_seconds, |
180 uint32 ntp_fractions) { | 181 uint32 ntp_fractions) { |
181 int64 ntp_time_us = | 182 // We need to ceil() here because the calculation of |fractions| in |
182 static_cast<int64>(ntp_seconds) * base::Time::kMicrosecondsPerSecond + | 183 // ConvertTimeToFractions() effectively does a floor(). |
183 static_cast<int64>(ntp_fractions) / kMagicFractionalUnit; | 184 int64 ntp_time_us = ntp_seconds * base::Time::kMicrosecondsPerSecond + |
| 185 static_cast<int64>(std::ceil(ntp_fractions / kMagicFractionalUnit)); |
184 | 186 |
185 base::TimeDelta elapsed_since_unix_epoch = base::TimeDelta::FromMicroseconds( | 187 base::TimeDelta elapsed_since_unix_epoch = base::TimeDelta::FromMicroseconds( |
186 ntp_time_us - | 188 ntp_time_us - |
187 (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond)); | 189 (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond)); |
188 return base::TimeTicks::UnixEpoch() + elapsed_since_unix_epoch; | 190 return base::TimeTicks::UnixEpoch() + elapsed_since_unix_epoch; |
189 } | 191 } |
190 | 192 |
191 inline base::TimeDelta RtpDeltaToTimeDelta(int64 rtp_delta, int rtp_timebase) { | 193 inline base::TimeDelta RtpDeltaToTimeDelta(int64 rtp_delta, int rtp_timebase) { |
192 DCHECK_GT(rtp_timebase, 0); | 194 DCHECK_GT(rtp_timebase, 0); |
193 return rtp_delta * base::TimeDelta::FromSeconds(1) / rtp_timebase; | 195 return rtp_delta * base::TimeDelta::FromSeconds(1) / rtp_timebase; |
194 } | 196 } |
195 | 197 |
196 inline int64 TimeDeltaToRtpDelta(base::TimeDelta delta, int rtp_timebase) { | 198 inline int64 TimeDeltaToRtpDelta(base::TimeDelta delta, int rtp_timebase) { |
197 DCHECK_GT(rtp_timebase, 0); | 199 DCHECK_GT(rtp_timebase, 0); |
198 return delta * rtp_timebase / base::TimeDelta::FromSeconds(1); | 200 return delta * rtp_timebase / base::TimeDelta::FromSeconds(1); |
199 } | 201 } |
200 | 202 |
201 } // namespace cast | 203 } // namespace cast |
202 } // namespace media | 204 } // namespace media |
203 | 205 |
204 #endif // MEDIA_CAST_CAST_DEFINES_H_ | 206 #endif // MEDIA_CAST_CAST_DEFINES_H_ |
OLD | NEW |