| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 kTooOldPacket, | 48 kTooOldPacket, |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 const uint16 kRtcpCastAllPacketsLost = 0xffff; | 51 const uint16 kRtcpCastAllPacketsLost = 0xffff; |
| 52 | 52 |
| 53 const size_t kMinLengthOfRtcp = 8; | 53 const size_t kMinLengthOfRtcp = 8; |
| 54 | 54 |
| 55 // Basic RTP header + cast header. | 55 // Basic RTP header + cast header. |
| 56 const size_t kMinLengthOfRtp = 12 + 6; | 56 const size_t kMinLengthOfRtp = 12 + 6; |
| 57 | 57 |
| 58 const size_t kAesBlockSize = 16; | |
| 59 const size_t kAesKeySize = 16; | |
| 60 | |
| 61 // Each uint16 represents one packet id within a cast frame. | 58 // Each uint16 represents one packet id within a cast frame. |
| 62 typedef std::set<uint16> PacketIdSet; | 59 typedef std::set<uint16> PacketIdSet; |
| 63 // Each uint8 represents one cast frame. | 60 // Each uint8 represents one cast frame. |
| 64 typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap; | 61 typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap; |
| 65 | 62 |
| 66 // TODO(pwestin): Re-factor the functions bellow into a class with static | 63 // TODO(pwestin): Re-factor the functions bellow into a class with static |
| 67 // methods. | 64 // methods. |
| 68 | 65 |
| 69 // January 1970, in NTP seconds. | 66 // January 1970, in NTP seconds. |
| 70 // Network Time Protocol (NTP), which is in seconds relative to 0h UTC on | 67 // Network Time Protocol (NTP), which is in seconds relative to 0h UTC on |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 int64 ntp_time_us = static_cast<int64>(ntp_seconds) * | 137 int64 ntp_time_us = static_cast<int64>(ntp_seconds) * |
| 141 base::Time::kMicrosecondsPerSecond + | 138 base::Time::kMicrosecondsPerSecond + |
| 142 static_cast<int64>(ntp_fractions) / kMagicFractionalUnit; | 139 static_cast<int64>(ntp_fractions) / kMagicFractionalUnit; |
| 143 | 140 |
| 144 base::TimeDelta elapsed_since_unix_epoch = | 141 base::TimeDelta elapsed_since_unix_epoch = |
| 145 base::TimeDelta::FromMicroseconds(ntp_time_us - | 142 base::TimeDelta::FromMicroseconds(ntp_time_us - |
| 146 (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond)); | 143 (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond)); |
| 147 return base::TimeTicks::UnixEpoch() + elapsed_since_unix_epoch; | 144 return base::TimeTicks::UnixEpoch() + elapsed_since_unix_epoch; |
| 148 } | 145 } |
| 149 | 146 |
| 150 inline std::string GetAesNonce(uint32 frame_id, const std::string& iv_mask) { | |
| 151 std::string aes_nonce(kAesBlockSize, 0); | |
| 152 | |
| 153 // Serializing frame_id in big-endian order (aes_nonce[8] is the most | |
| 154 // significant byte of frame_id). | |
| 155 aes_nonce[11] = frame_id & 0xff; | |
| 156 aes_nonce[10] = (frame_id >> 8) & 0xff; | |
| 157 aes_nonce[9] = (frame_id >> 16) & 0xff; | |
| 158 aes_nonce[8] = (frame_id >> 24) & 0xff; | |
| 159 | |
| 160 for (size_t i = 0; i < kAesBlockSize; ++i) { | |
| 161 aes_nonce[i] ^= iv_mask[i]; | |
| 162 } | |
| 163 return aes_nonce; | |
| 164 } | |
| 165 | |
| 166 inline uint32 GetVideoRtpTimestamp(const base::TimeTicks& time_ticks) { | 147 inline uint32 GetVideoRtpTimestamp(const base::TimeTicks& time_ticks) { |
| 167 base::TimeTicks zero_time; | 148 base::TimeTicks zero_time; |
| 168 base::TimeDelta recorded_delta = time_ticks - zero_time; | 149 base::TimeDelta recorded_delta = time_ticks - zero_time; |
| 169 // Timestamp is in 90 KHz for video. | 150 // Timestamp is in 90 KHz for video. |
| 170 return static_cast<uint32>(recorded_delta.InMilliseconds() * 90); | 151 return static_cast<uint32>(recorded_delta.InMilliseconds() * 90); |
| 171 } | 152 } |
| 172 | 153 |
| 173 } // namespace cast | 154 } // namespace cast |
| 174 } // namespace media | 155 } // namespace media |
| 175 | 156 |
| 176 #endif // MEDIA_CAST_CAST_DEFINES_H_ | 157 #endif // MEDIA_CAST_CAST_DEFINES_H_ |
| OLD | NEW |