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
3 // found in the LICENSE file.
5 #ifndef MEDIA_CAST_CAST_DEFINES_H_
6 #define MEDIA_CAST_CAST_DEFINES_H_
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/time/time.h"
18 const int64 kDontShowTimeoutMs
= 33;
19 const float kDefaultCongestionControlBackOff
= 0.875f
;
20 const uint8 kStartFrameId
= 255;
21 const uint32 kVideoFrequency
= 90000;
22 const int64 kSkippedFramesCheckPeriodkMs
= 10000;
24 // Number of skipped frames threshold in fps (as configured) per period above.
25 const int kSkippedFramesThreshold
= 3;
26 const size_t kIpPacketSize
= 1500;
27 const int kStartRttMs
= 20;
28 const int64 kCastMessageUpdateIntervalMs
= 33;
29 const int64 kNackRepeatIntervalMs
= 30;
31 enum DefaultSettings
{
34 kDefaultMaxFrameRate
= 30,
35 kDefaultNumberOfVideoBuffers
= 1,
36 kDefaultRtcpIntervalMs
= 500,
37 kDefaultRtpHistoryMs
= 1000,
38 kDefaultRtpMaxDelayMs
= 100,
41 const uint16 kRtcpCastAllPacketsLost
= 0xffff;
43 // Each uint16 represents one packet id within a cast frame.
44 typedef std::set
<uint16
> PacketIdSet
;
45 // Each uint8 represents one cast frame.
46 typedef std::map
<uint8
, PacketIdSet
> MissingFramesAndPacketsMap
;
48 // TODO(pwestin): Re-factor the functions bellow into a class with static
51 // Magic fractional unit. Used to convert time (in microseconds) to/from
52 // fractional NTP seconds.
53 static const double kMagicFractionalUnit
= 4.294967296E3
;
55 // Network Time Protocol (NTP), which is in seconds relative to 0h UTC on
57 static const int64 kNtpEpochDeltaSeconds
= GG_INT64_C(9435484800);
58 static const int64 kNtpEpochDeltaMicroseconds
=
59 kNtpEpochDeltaSeconds
* base::Time::kMicrosecondsPerSecond
;
61 inline bool IsNewerFrameId(uint8 frame_id
, uint8 prev_frame_id
) {
62 return (frame_id
!= prev_frame_id
) &&
63 static_cast<uint8
>(frame_id
- prev_frame_id
) < 0x80;
66 inline bool IsOlderFrameId(uint8 frame_id
, uint8 prev_frame_id
) {
67 return (frame_id
== prev_frame_id
) || IsNewerFrameId(prev_frame_id
, frame_id
);
70 inline bool IsNewerPacketId(uint16 packet_id
, uint16 prev_packet_id
) {
71 return (packet_id
!= prev_packet_id
) &&
72 static_cast<uint16
>(packet_id
- prev_packet_id
) < 0x8000;
75 inline bool IsNewerSequenceNumber(uint16 sequence_number
,
76 uint16 prev_sequence_number
) {
77 // Same function as IsNewerPacketId just different data and name.
78 return IsNewerPacketId(sequence_number
, prev_sequence_number
);
81 // Create a NTP diff from seconds and fractions of seconds; delay_fraction is
82 // fractions of a second where 0x80000000 is half a second.
83 inline uint32
ConvertToNtpDiff(uint32 delay_seconds
, uint32 delay_fraction
) {
84 return ((delay_seconds
& 0x0000FFFF) << 16) +
85 ((delay_fraction
& 0xFFFF0000) >> 16);
88 inline base::TimeDelta
ConvertFromNtpDiff(uint32 ntp_delay
) {
89 uint32 delay_ms
= (ntp_delay
& 0x0000ffff) * 1000;
91 delay_ms
+= ((ntp_delay
& 0xffff0000) >> 16) * 1000;
92 return base::TimeDelta::FromMilliseconds(delay_ms
);
95 inline void ConvertTimeToFractions(int64 time_us
,
98 *seconds
= static_cast<uint32
>(time_us
/ base::Time::kMicrosecondsPerSecond
);
99 *fractions
= static_cast<uint32
>(
100 (time_us
% base::Time::kMicrosecondsPerSecond
) * kMagicFractionalUnit
);
103 inline void ConvertTimeToNtp(const base::TimeTicks
& time
,
105 uint32
* ntp_fractions
) {
106 int64 time_us
= time
.ToInternalValue() - kNtpEpochDeltaMicroseconds
;
107 ConvertTimeToFractions(time_us
, ntp_seconds
, ntp_fractions
);
110 inline base::TimeTicks
ConvertNtpToTime(uint32 ntp_seconds
,
111 uint32 ntp_fractions
) {
112 int64 ntp_time_us
= static_cast<int64
>(ntp_seconds
) *
113 base::Time::kMicrosecondsPerSecond
;
114 ntp_time_us
+= static_cast<int64
>(ntp_fractions
) / kMagicFractionalUnit
;
115 return base::TimeTicks::FromInternalValue(ntp_time_us
+
116 kNtpEpochDeltaMicroseconds
);
122 #endif // MEDIA_CAST_CAST_DEFINES_H_