| 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 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 | 15 |
| 16 namespace media { | 16 namespace media { |
| 17 namespace cast { | 17 namespace cast { |
| 18 | 18 |
| 19 const int64 kDontShowTimeoutMs = 33; | 19 const int64 kDontShowTimeoutMs = 33; |
| 20 const float kDefaultCongestionControlBackOff = 0.875f; | 20 const float kDefaultCongestionControlBackOff = 0.875f; |
| 21 const uint32 kStartFrameId = GG_UINT32_C(0xffffffff); | |
| 22 const uint32 kVideoFrequency = 90000; | 21 const uint32 kVideoFrequency = 90000; |
| 23 const int64 kSkippedFramesCheckPeriodkMs = 10000; | 22 const int64 kSkippedFramesCheckPeriodkMs = 10000; |
| 23 const uint32 kStartFrameId = GG_UINT32_C(0xffffffff); |
| 24 | 24 |
| 25 // Number of skipped frames threshold in fps (as configured) per period above. | 25 // Number of skipped frames threshold in fps (as configured) per period above. |
| 26 const int kSkippedFramesThreshold = 3; | 26 const int kSkippedFramesThreshold = 3; |
| 27 const size_t kIpPacketSize = 1500; | 27 const size_t kIpPacketSize = 1500; |
| 28 const int kStartRttMs = 20; | 28 const int kStartRttMs = 20; |
| 29 const int64 kCastMessageUpdateIntervalMs = 33; | 29 const int64 kCastMessageUpdateIntervalMs = 33; |
| 30 const int64 kNackRepeatIntervalMs = 30; | 30 const int64 kNackRepeatIntervalMs = 30; |
| 31 | 31 |
| 32 enum DefaultSettings { | 32 enum DefaultSettings { |
| 33 kDefaultAudioEncoderBitrate = 0, // This means "auto," and may mean VBR. | 33 kDefaultAudioEncoderBitrate = 0, // This means "auto," and may mean VBR. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 int64 ntp_time_us = static_cast<int64>(ntp_seconds) * | 133 int64 ntp_time_us = static_cast<int64>(ntp_seconds) * |
| 134 base::Time::kMicrosecondsPerSecond + | 134 base::Time::kMicrosecondsPerSecond + |
| 135 static_cast<int64>(ntp_fractions) / kMagicFractionalUnit; | 135 static_cast<int64>(ntp_fractions) / kMagicFractionalUnit; |
| 136 | 136 |
| 137 base::TimeDelta elapsed_since_unix_epoch = | 137 base::TimeDelta elapsed_since_unix_epoch = |
| 138 base::TimeDelta::FromMicroseconds(ntp_time_us - | 138 base::TimeDelta::FromMicroseconds(ntp_time_us - |
| 139 (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond)); | 139 (kUnixEpochInNtpSeconds * base::Time::kMicrosecondsPerSecond)); |
| 140 return base::TimeTicks::UnixEpoch() + elapsed_since_unix_epoch; | 140 return base::TimeTicks::UnixEpoch() + elapsed_since_unix_epoch; |
| 141 } | 141 } |
| 142 | 142 |
| 143 class FrameIdWrapHelper { | |
| 144 public: | |
| 145 FrameIdWrapHelper() | |
| 146 : first_(true), | |
| 147 frame_id_wrap_count_(0), | |
| 148 range_(kLowRange) {} | |
| 149 | |
| 150 uint32 MapTo32bitsFrameId(const uint8 over_the_wire_frame_id) { | |
| 151 if (first_) { | |
| 152 first_ = false; | |
| 153 if (over_the_wire_frame_id == 0xff) { | |
| 154 // Special case for startup. | |
| 155 return kStartFrameId; | |
| 156 } | |
| 157 } | |
| 158 | |
| 159 uint32 wrap_count = frame_id_wrap_count_; | |
| 160 switch (range_) { | |
| 161 case kLowRange: | |
| 162 if (over_the_wire_frame_id > kLowRangeThreshold && | |
| 163 over_the_wire_frame_id < kHighRangeThreshold) { | |
| 164 range_ = kMiddleRange; | |
| 165 } | |
| 166 if (over_the_wire_frame_id > kHighRangeThreshold) { | |
| 167 // Wrap count was incremented in High->Low transition, but this frame | |
| 168 // is 'old', actually from before the wrap count got incremented. | |
| 169 --wrap_count; | |
| 170 } | |
| 171 break; | |
| 172 case kMiddleRange: | |
| 173 if (over_the_wire_frame_id > kHighRangeThreshold) { | |
| 174 range_ = kHighRange; | |
| 175 } | |
| 176 break; | |
| 177 case kHighRange: | |
| 178 if (over_the_wire_frame_id < kLowRangeThreshold) { | |
| 179 // Wrap-around detected. | |
| 180 range_ = kLowRange; | |
| 181 ++frame_id_wrap_count_; | |
| 182 // Frame triggering wrap-around so wrap count should be incremented as | |
| 183 // as well to match |frame_id_wrap_count_|. | |
| 184 ++wrap_count; | |
| 185 } | |
| 186 break; | |
| 187 } | |
| 188 return (wrap_count << 8) + over_the_wire_frame_id; | |
| 189 } | |
| 190 | |
| 191 private: | |
| 192 enum Range { | |
| 193 kLowRange, | |
| 194 kMiddleRange, | |
| 195 kHighRange, | |
| 196 }; | |
| 197 | |
| 198 static const uint8 kLowRangeThreshold = 0x0f; | |
| 199 static const uint8 kHighRangeThreshold = 0xf0; | |
| 200 | |
| 201 bool first_; | |
| 202 uint32 frame_id_wrap_count_; | |
| 203 Range range_; | |
| 204 }; | |
| 205 | |
| 206 inline std::string GetAesNonce(uint32 frame_id, const std::string& iv_mask) { | 143 inline std::string GetAesNonce(uint32 frame_id, const std::string& iv_mask) { |
| 207 std::string aes_nonce(kAesBlockSize, 0); | 144 std::string aes_nonce(kAesBlockSize, 0); |
| 208 | 145 |
| 209 // Serializing frame_id in big-endian order (aes_nonce[8] is the most | 146 // Serializing frame_id in big-endian order (aes_nonce[8] is the most |
| 210 // significant byte of frame_id). | 147 // significant byte of frame_id). |
| 211 aes_nonce[11] = frame_id & 0xff; | 148 aes_nonce[11] = frame_id & 0xff; |
| 212 aes_nonce[10] = (frame_id >> 8) & 0xff; | 149 aes_nonce[10] = (frame_id >> 8) & 0xff; |
| 213 aes_nonce[9] = (frame_id >> 16) & 0xff; | 150 aes_nonce[9] = (frame_id >> 16) & 0xff; |
| 214 aes_nonce[8] = (frame_id >> 24) & 0xff; | 151 aes_nonce[8] = (frame_id >> 24) & 0xff; |
| 215 | 152 |
| 216 for (size_t i = 0; i < kAesBlockSize; ++i) { | 153 for (size_t i = 0; i < kAesBlockSize; ++i) { |
| 217 aes_nonce[i] ^= iv_mask[i]; | 154 aes_nonce[i] ^= iv_mask[i]; |
| 218 } | 155 } |
| 219 return aes_nonce; | 156 return aes_nonce; |
| 220 } | 157 } |
| 221 | 158 |
| 222 inline uint32 GetVideoRtpTimestamp(const base::TimeTicks& time_ticks) { | 159 inline uint32 GetVideoRtpTimestamp(const base::TimeTicks& time_ticks) { |
| 223 base::TimeTicks zero_time; | 160 base::TimeTicks zero_time; |
| 224 base::TimeDelta recorded_delta = time_ticks - zero_time; | 161 base::TimeDelta recorded_delta = time_ticks - zero_time; |
| 225 // Timestamp is in 90 KHz for video. | 162 // Timestamp is in 90 KHz for video. |
| 226 return static_cast<uint32>(recorded_delta.InMilliseconds() * 90); | 163 return static_cast<uint32>(recorded_delta.InMilliseconds() * 90); |
| 227 } | 164 } |
| 228 | 165 |
| 229 } // namespace cast | 166 } // namespace cast |
| 230 } // namespace media | 167 } // namespace media |
| 231 | 168 |
| 232 #endif // MEDIA_CAST_CAST_DEFINES_H_ | 169 #endif // MEDIA_CAST_CAST_DEFINES_H_ |
| OLD | NEW |