diff options
author | pwestin@google.com <pwestin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-31 20:29:38 +0000 |
---|---|---|
committer | pwestin@google.com <pwestin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-10-31 20:29:38 +0000 |
commit | 6d06cb83f1a618fe58f55d70d5648b96dd5b73b8 (patch) | |
tree | 02e03b1de611efbc2eb10006246a451f0ce3b781 /media/cast/cast_defines.h | |
parent | 2ea434e38ee5cd52a5e1db5bb0024b152d78f796 (diff) | |
download | chromium_src-6d06cb83f1a618fe58f55d70d5648b96dd5b73b8.zip chromium_src-6d06cb83f1a618fe58f55d70d5648b96dd5b73b8.tar.gz chromium_src-6d06cb83f1a618fe58f55d70d5648b96dd5b73b8.tar.bz2 |
Change to calculate the real NTP in TimeTicks.
Added static method to correlate the TimeTicks to a real date and time; in this case UnixEpoch since that is a commonly known time/date.
Review URL: https://codereview.chromium.org/34623008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232194 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/cast/cast_defines.h')
-rw-r--r-- | media/cast/cast_defines.h | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/media/cast/cast_defines.h b/media/cast/cast_defines.h index 0778638..f44e5fb 100644 --- a/media/cast/cast_defines.h +++ b/media/cast/cast_defines.h @@ -54,16 +54,15 @@ typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap; // TODO(pwestin): Re-factor the functions bellow into a class with static // methods. +// January 1970, in NTP seconds. +// Network Time Protocol (NTP), which is in seconds relative to 0h UTC on +// 1 January 1900. +static const int64 kUnixEpochInNtpSeconds = GG_INT64_C(2208988800); + // Magic fractional unit. Used to convert time (in microseconds) to/from // fractional NTP seconds. static const double kMagicFractionalUnit = 4.294967296E3; -// Network Time Protocol (NTP), which is in seconds relative to 0h UTC on -// 1 January 1900. -static const int64 kNtpEpochDeltaSeconds = GG_INT64_C(9435484800); -static const int64 kNtpEpochDeltaMicroseconds = - kNtpEpochDeltaSeconds * base::Time::kMicrosecondsPerSecond; - inline bool IsNewerFrameId(uint8 frame_id, uint8 prev_frame_id) { return (frame_id != prev_frame_id) && static_cast<uint8>(frame_id - prev_frame_id) < 0x80; @@ -107,20 +106,28 @@ inline void ConvertTimeToFractions(int64 time_us, (time_us % base::Time::kMicrosecondsPerSecond) * kMagicFractionalUnit); } -inline void ConvertTimeToNtp(const base::TimeTicks& time, - uint32* ntp_seconds, - uint32* ntp_fractions) { - int64 time_us = time.ToInternalValue() - kNtpEpochDeltaMicroseconds; - ConvertTimeToFractions(time_us, ntp_seconds, ntp_fractions); +inline void ConvertTimeTicksToNtp(const base::TimeTicks& time, + uint32* ntp_seconds, + uint32* ntp_fractions) { + base::TimeDelta elapsed_since_unix_epoch = + time - base::TimeTicks::UnixEpoch(); + + int64 ntp_time_us = elapsed_since_unix_epoch.InMicroseconds() + + (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond); + + ConvertTimeToFractions(ntp_time_us, ntp_seconds, ntp_fractions); } -inline base::TimeTicks ConvertNtpToTime(uint32 ntp_seconds, - uint32 ntp_fractions) { +inline base::TimeTicks ConvertNtpToTimeTicks(uint32 ntp_seconds, + uint32 ntp_fractions) { int64 ntp_time_us = static_cast<int64>(ntp_seconds) * - base::Time::kMicrosecondsPerSecond; - ntp_time_us += static_cast<int64>(ntp_fractions) / kMagicFractionalUnit; - return base::TimeTicks::FromInternalValue(ntp_time_us + - kNtpEpochDeltaMicroseconds); + base::Time::kMicrosecondsPerSecond + + static_cast<int64>(ntp_fractions) / kMagicFractionalUnit; + + base::TimeDelta elapsed_since_unix_epoch = + base::TimeDelta::FromMicroseconds(ntp_time_us - + (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond)); + return base::TimeTicks::UnixEpoch() + elapsed_since_unix_epoch; } } // namespace cast |