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/logging.h"
14 #include "base/time/time.h"
19 const int64 kDontShowTimeoutMs
= 33;
20 const float kDefaultCongestionControlBackOff
= 0.875f
;
21 const uint8 kStartFrameId
= 255;
22 const uint32 kVideoFrequency
= 90000;
23 const int64 kSkippedFramesCheckPeriodkMs
= 10000;
25 // Number of skipped frames threshold in fps (as configured) per period above.
26 const int kSkippedFramesThreshold
= 3;
27 const size_t kIpPacketSize
= 1500;
28 const int kStartRttMs
= 20;
29 const int64 kCastMessageUpdateIntervalMs
= 33;
30 const int64 kNackRepeatIntervalMs
= 30;
32 enum DefaultSettings
{
35 kDefaultMaxFrameRate
= 30,
36 kDefaultNumberOfVideoBuffers
= 1,
37 kDefaultRtcpIntervalMs
= 500,
38 kDefaultRtpHistoryMs
= 1000,
39 kDefaultRtpMaxDelayMs
= 100,
42 const uint16 kRtcpCastAllPacketsLost
= 0xffff;
44 // Each uint16 represents one packet id within a cast frame.
45 typedef std::set
<uint16
> PacketIdSet
;
46 // Each uint8 represents one cast frame.
47 typedef std::map
<uint8
, PacketIdSet
> MissingFramesAndPacketsMap
;
49 // TODO(pwestin): Re-factor the functions bellow into a class with static
52 // Magic fractional unit. Used to convert time (in microseconds) to/from
53 // fractional NTP seconds.
54 static const double kMagicFractionalUnit
= 4.294967296E3
;
56 // Network Time Protocol (NTP), which is in seconds relative to 0h UTC on
58 static const int64 kNtpEpochDeltaSeconds
= GG_INT64_C(9435484800);
59 static const int64 kNtpEpochDeltaMicroseconds
=
60 kNtpEpochDeltaSeconds
* base::Time::kMicrosecondsPerSecond
;
62 inline bool IsNewerFrameId(uint8 frame_id
, uint8 prev_frame_id
) {
63 return (frame_id
!= prev_frame_id
) &&
64 static_cast<uint8
>(frame_id
- prev_frame_id
) < 0x80;
67 inline bool IsOlderFrameId(uint8 frame_id
, uint8 prev_frame_id
) {
68 return (frame_id
== prev_frame_id
) || IsNewerFrameId(prev_frame_id
, frame_id
);
71 inline bool IsNewerPacketId(uint16 packet_id
, uint16 prev_packet_id
) {
72 return (packet_id
!= prev_packet_id
) &&
73 static_cast<uint16
>(packet_id
- prev_packet_id
) < 0x8000;
76 inline bool IsNewerSequenceNumber(uint16 sequence_number
,
77 uint16 prev_sequence_number
) {
78 // Same function as IsNewerPacketId just different data and name.
79 return IsNewerPacketId(sequence_number
, prev_sequence_number
);
82 // Create a NTP diff from seconds and fractions of seconds; delay_fraction is
83 // fractions of a second where 0x80000000 is half a second.
84 inline uint32
ConvertToNtpDiff(uint32 delay_seconds
, uint32 delay_fraction
) {
85 return ((delay_seconds
& 0x0000FFFF) << 16) +
86 ((delay_fraction
& 0xFFFF0000) >> 16);
89 inline base::TimeDelta
ConvertFromNtpDiff(uint32 ntp_delay
) {
90 uint32 delay_ms
= (ntp_delay
& 0x0000ffff) * 1000;
92 delay_ms
+= ((ntp_delay
& 0xffff0000) >> 16) * 1000;
93 return base::TimeDelta::FromMilliseconds(delay_ms
);
96 inline void ConvertTimeToFractions(int64 time_us
,
99 DCHECK_GE(time_us
, 0) << "Time must NOT be negative";
100 *seconds
= static_cast<uint32
>(time_us
/ base::Time::kMicrosecondsPerSecond
);
101 *fractions
= static_cast<uint32
>(
102 (time_us
% base::Time::kMicrosecondsPerSecond
) * kMagicFractionalUnit
);
105 inline void ConvertTimeToNtp(const base::TimeTicks
& time
,
107 uint32
* ntp_fractions
) {
108 int64 time_us
= time
.ToInternalValue() - kNtpEpochDeltaMicroseconds
;
109 ConvertTimeToFractions(time_us
, ntp_seconds
, ntp_fractions
);
112 inline base::TimeTicks
ConvertNtpToTime(uint32 ntp_seconds
,
113 uint32 ntp_fractions
) {
114 int64 ntp_time_us
= static_cast<int64
>(ntp_seconds
) *
115 base::Time::kMicrosecondsPerSecond
;
116 ntp_time_us
+= static_cast<int64
>(ntp_fractions
) / kMagicFractionalUnit
;
117 return base::TimeTicks::FromInternalValue(ntp_time_us
+
118 kNtpEpochDeltaMicroseconds
);
124 #endif // MEDIA_CAST_CAST_DEFINES_H_