Revert 224458 "Enabling MediaStreamInfoBarTest.DenyingCameraDoes..."
[chromium-blink-merge.git] / media / cast / cast_defines.h
blob13717323405e50eaf4a3e578fca96a0c945bbd8d
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_
8 #include <map>
9 #include <set>
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/time/time.h"
15 namespace media {
16 namespace cast {
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 {
32 kDefaultMaxQp = 56,
33 kDefaultMinQp = 4,
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
49 // methods.
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
56 // 1 January 1900.
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;
90 delay_ms >>= 16;
91 delay_ms += ((ntp_delay & 0xffff0000) >> 16) * 1000;
92 return base::TimeDelta::FromMilliseconds(delay_ms);
95 inline void ConvertTimeToFractions(int64 time_us,
96 uint32* seconds,
97 uint32* fractions) {
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,
104 uint32* ntp_seconds,
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);
119 } // namespace cast
120 } // namespace media
122 #endif // MEDIA_CAST_CAST_DEFINES_H_