Chromium Code Reviews| 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 <limits> | |
| 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/transport/cast_transport_config.h" | 18 #include "media/cast/transport/cast_transport_config.h" |
| 18 | 19 |
| 19 namespace media { | 20 namespace media { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 ((delay_fraction & 0xFFFF0000) >> 16); | 129 ((delay_fraction & 0xFFFF0000) >> 16); |
| 129 } | 130 } |
| 130 | 131 |
| 131 inline base::TimeDelta ConvertFromNtpDiff(uint32 ntp_delay) { | 132 inline base::TimeDelta ConvertFromNtpDiff(uint32 ntp_delay) { |
| 132 uint32 delay_ms = (ntp_delay & 0x0000ffff) * 1000; | 133 uint32 delay_ms = (ntp_delay & 0x0000ffff) * 1000; |
| 133 delay_ms >>= 16; | 134 delay_ms >>= 16; |
| 134 delay_ms += ((ntp_delay & 0xffff0000) >> 16) * 1000; | 135 delay_ms += ((ntp_delay & 0xffff0000) >> 16) * 1000; |
| 135 return base::TimeDelta::FromMilliseconds(delay_ms); | 136 return base::TimeDelta::FromMilliseconds(delay_ms); |
| 136 } | 137 } |
| 137 | 138 |
| 138 inline void ConvertTimeToFractions(int64 time_us, | 139 inline void ConvertTimeToFractions(int64 ntp_time_us, |
| 139 uint32* seconds, | 140 uint32* seconds, |
| 140 uint32* fractions) { | 141 uint32* fractions) { |
| 141 DCHECK_GE(time_us, 0) << "Time must NOT be negative"; | 142 DCHECK_GE(ntp_time_us, 0) << "Time must NOT be negative"; |
| 142 *seconds = static_cast<uint32>(time_us / base::Time::kMicrosecondsPerSecond); | 143 const int64 seconds_component = |
| 144 ntp_time_us / base::Time::kMicrosecondsPerSecond; | |
| 145 // NTP time will overflow in the year 2036. Also, make sure unit tests don't | |
| 146 // regress and use an origin past the year 2036. If this overflows here, the | |
| 147 // inverse calculation fails to compute the correct TimeTicks value, throwing | |
| 148 // off the entire system. | |
|
hubbe
2014/05/19 17:52:20
Maybe put a DCHECK(ntp_time_us is less than the ye
miu
2014/05/23 03:09:01
Done.
| |
| 149 CHECK(seconds_component <= std::numeric_limits<uint32>::max()); | |
| 150 *seconds = static_cast<uint32>(seconds_component); | |
| 143 *fractions = static_cast<uint32>( | 151 *fractions = static_cast<uint32>( |
| 144 (time_us % base::Time::kMicrosecondsPerSecond) * kMagicFractionalUnit); | 152 (ntp_time_us % base::Time::kMicrosecondsPerSecond) * |
| 153 kMagicFractionalUnit); | |
| 145 } | 154 } |
| 146 | 155 |
| 147 inline void ConvertTimeTicksToNtp(const base::TimeTicks& time, | 156 inline void ConvertTimeTicksToNtp(const base::TimeTicks& time, |
| 148 uint32* ntp_seconds, | 157 uint32* ntp_seconds, |
| 149 uint32* ntp_fractions) { | 158 uint32* ntp_fractions) { |
| 150 base::TimeDelta elapsed_since_unix_epoch = | 159 base::TimeDelta elapsed_since_unix_epoch = |
| 151 time - base::TimeTicks::UnixEpoch(); | 160 time - base::TimeTicks::UnixEpoch(); |
| 152 | 161 |
| 153 int64 ntp_time_us = | 162 int64 ntp_time_us = |
| 154 elapsed_since_unix_epoch.InMicroseconds() + | 163 elapsed_since_unix_epoch.InMicroseconds() + |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 base::TimeTicks time_sent_; | 231 base::TimeTicks time_sent_; |
| 223 uint32 rtp_timestamp_; | 232 uint32 rtp_timestamp_; |
| 224 | 233 |
| 225 DISALLOW_COPY_AND_ASSIGN(RtpSenderStatistics); | 234 DISALLOW_COPY_AND_ASSIGN(RtpSenderStatistics); |
| 226 }; | 235 }; |
| 227 | 236 |
| 228 } // namespace cast | 237 } // namespace cast |
| 229 } // namespace media | 238 } // namespace media |
| 230 | 239 |
| 231 #endif // MEDIA_CAST_CAST_DEFINES_H_ | 240 #endif // MEDIA_CAST_CAST_DEFINES_H_ |
| OLD | NEW |