Index: media/cast/cast_defines.h |
diff --git a/media/cast/cast_defines.h b/media/cast/cast_defines.h |
index b0f9370186e9e60e2cd0a7dc0f8032d603ea4e4a..2084e1c743c3f41edf7a5eaaf06cc1a1bcbb4ebe 100644 |
--- a/media/cast/cast_defines.h |
+++ b/media/cast/cast_defines.h |
@@ -7,6 +7,7 @@ |
#include <stdint.h> |
+#include <limits> |
#include <map> |
#include <set> |
@@ -135,13 +136,21 @@ inline base::TimeDelta ConvertFromNtpDiff(uint32 ntp_delay) { |
return base::TimeDelta::FromMilliseconds(delay_ms); |
} |
-inline void ConvertTimeToFractions(int64 time_us, |
+inline void ConvertTimeToFractions(int64 ntp_time_us, |
uint32* seconds, |
uint32* fractions) { |
- DCHECK_GE(time_us, 0) << "Time must NOT be negative"; |
- *seconds = static_cast<uint32>(time_us / base::Time::kMicrosecondsPerSecond); |
+ DCHECK_GE(ntp_time_us, 0) << "Time must NOT be negative"; |
+ const int64 seconds_component = |
+ ntp_time_us / base::Time::kMicrosecondsPerSecond; |
+ // NTP time will overflow in the year 2036. Also, make sure unit tests don't |
+ // regress and use an origin past the year 2036. If this overflows here, the |
+ // inverse calculation fails to compute the correct TimeTicks value, throwing |
+ // 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.
|
+ CHECK(seconds_component <= std::numeric_limits<uint32>::max()); |
+ *seconds = static_cast<uint32>(seconds_component); |
*fractions = static_cast<uint32>( |
- (time_us % base::Time::kMicrosecondsPerSecond) * kMagicFractionalUnit); |
+ (ntp_time_us % base::Time::kMicrosecondsPerSecond) * |
+ kMagicFractionalUnit); |
} |
inline void ConvertTimeTicksToNtp(const base::TimeTicks& time, |