| 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 <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 // Each uint8 represents one cast frame. | 51 // Each uint8 represents one cast frame. |
| 52 typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap; | 52 typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap; |
| 53 | 53 |
| 54 // TODO(pwestin): Re-factor the functions bellow into a class with static | 54 // TODO(pwestin): Re-factor the functions bellow into a class with static |
| 55 // methods. | 55 // methods. |
| 56 | 56 |
| 57 // Magic fractional unit. Used to convert time (in microseconds) to/from | 57 // Magic fractional unit. Used to convert time (in microseconds) to/from |
| 58 // fractional NTP seconds. | 58 // fractional NTP seconds. |
| 59 static const double kMagicFractionalUnit = 4.294967296E3; | 59 static const double kMagicFractionalUnit = 4.294967296E3; |
| 60 | 60 |
| 61 // Network Time Protocol (NTP), which is in seconds relative to 0h UTC on | |
| 62 // 1 January 1900. | |
| 63 static const int64 kNtpEpochDeltaSeconds = GG_INT64_C(9435484800); | |
| 64 static const int64 kNtpEpochDeltaMicroseconds = | |
| 65 kNtpEpochDeltaSeconds * base::Time::kMicrosecondsPerSecond; | |
| 66 | |
| 67 inline bool IsNewerFrameId(uint8 frame_id, uint8 prev_frame_id) { | 61 inline bool IsNewerFrameId(uint8 frame_id, uint8 prev_frame_id) { |
| 68 return (frame_id != prev_frame_id) && | 62 return (frame_id != prev_frame_id) && |
| 69 static_cast<uint8>(frame_id - prev_frame_id) < 0x80; | 63 static_cast<uint8>(frame_id - prev_frame_id) < 0x80; |
| 70 } | 64 } |
| 71 | 65 |
| 72 inline bool IsOlderFrameId(uint8 frame_id, uint8 prev_frame_id) { | 66 inline bool IsOlderFrameId(uint8 frame_id, uint8 prev_frame_id) { |
| 73 return (frame_id == prev_frame_id) || IsNewerFrameId(prev_frame_id, frame_id); | 67 return (frame_id == prev_frame_id) || IsNewerFrameId(prev_frame_id, frame_id); |
| 74 } | 68 } |
| 75 | 69 |
| 76 inline bool IsNewerPacketId(uint16 packet_id, uint16 prev_packet_id) { | 70 inline bool IsNewerPacketId(uint16 packet_id, uint16 prev_packet_id) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 100 | 94 |
| 101 inline void ConvertTimeToFractions(int64 time_us, | 95 inline void ConvertTimeToFractions(int64 time_us, |
| 102 uint32* seconds, | 96 uint32* seconds, |
| 103 uint32* fractions) { | 97 uint32* fractions) { |
| 104 DCHECK_GE(time_us, 0) << "Time must NOT be negative"; | 98 DCHECK_GE(time_us, 0) << "Time must NOT be negative"; |
| 105 *seconds = static_cast<uint32>(time_us / base::Time::kMicrosecondsPerSecond); | 99 *seconds = static_cast<uint32>(time_us / base::Time::kMicrosecondsPerSecond); |
| 106 *fractions = static_cast<uint32>( | 100 *fractions = static_cast<uint32>( |
| 107 (time_us % base::Time::kMicrosecondsPerSecond) * kMagicFractionalUnit); | 101 (time_us % base::Time::kMicrosecondsPerSecond) * kMagicFractionalUnit); |
| 108 } | 102 } |
| 109 | 103 |
| 110 inline void ConvertTimeToNtp(const base::TimeTicks& time, | |
| 111 uint32* ntp_seconds, | |
| 112 uint32* ntp_fractions) { | |
| 113 int64 time_us = time.ToInternalValue() - kNtpEpochDeltaMicroseconds; | |
| 114 ConvertTimeToFractions(time_us, ntp_seconds, ntp_fractions); | |
| 115 } | |
| 116 | |
| 117 inline base::TimeTicks ConvertNtpToTime(uint32 ntp_seconds, | 104 inline base::TimeTicks ConvertNtpToTime(uint32 ntp_seconds, |
| 118 uint32 ntp_fractions) { | 105 uint32 ntp_fractions) { |
| 119 int64 ntp_time_us = static_cast<int64>(ntp_seconds) * | 106 int64 ntp_time_us = static_cast<int64>(ntp_seconds) * |
| 120 base::Time::kMicrosecondsPerSecond; | 107 base::Time::kMicrosecondsPerSecond; |
| 121 ntp_time_us += static_cast<int64>(ntp_fractions) / kMagicFractionalUnit; | 108 ntp_time_us += static_cast<int64>(ntp_fractions) / kMagicFractionalUnit; |
| 122 return base::TimeTicks::FromInternalValue(ntp_time_us + | 109 return base::TimeTicks::FromInternalValue(ntp_time_us); |
| 123 kNtpEpochDeltaMicroseconds); | |
| 124 } | 110 } |
| 125 | 111 |
| 126 } // namespace cast | 112 } // namespace cast |
| 127 } // namespace media | 113 } // namespace media |
| 128 | 114 |
| 129 #endif // MEDIA_CAST_CAST_DEFINES_H_ | 115 #endif // MEDIA_CAST_CAST_DEFINES_H_ |
| OLD | NEW |