Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / media / cast / net / cast_transport_defines.h
1 // Copyright 2014 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.
4
5 #ifndef MEDIA_CAST_NET_CAST_TRANSPORT_DEFINES_H_
6 #define MEDIA_CAST_NET_CAST_TRANSPORT_DEFINES_H_
7
8 #include <stdint.h>
9
10 #include <map>
11 #include <set>
12 #include <string>
13
14 #include "base/basictypes.h"
15 #include "base/time/time.h"
16
17 namespace media {
18 namespace cast {
19
20 // TODO(mikhal): Implement and add more types.
21 enum CastTransportStatus {
22   TRANSPORT_AUDIO_UNINITIALIZED = 0,
23   TRANSPORT_VIDEO_UNINITIALIZED,
24   TRANSPORT_AUDIO_INITIALIZED,
25   TRANSPORT_VIDEO_INITIALIZED,
26   TRANSPORT_INVALID_CRYPTO_CONFIG,
27   TRANSPORT_SOCKET_ERROR,
28   CAST_TRANSPORT_STATUS_LAST = TRANSPORT_SOCKET_ERROR
29 };
30
31 const size_t kMaxIpPacketSize = 1500;
32 // Each uint16 represents one packet id within a cast frame.
33 typedef std::set<uint16> PacketIdSet;
34 // Each uint8 represents one cast frame.
35 typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap;
36
37 // Rtcp defines.
38
39 enum RtcpPacketFields {
40   kPacketTypeLow = 194,  // SMPTE time-code mapping.
41   kPacketTypeSenderReport = 200,
42   kPacketTypeReceiverReport = 201,
43   kPacketTypeApplicationDefined = 204,
44   kPacketTypeGenericRtpFeedback = 205,
45   kPacketTypePayloadSpecific = 206,
46   kPacketTypeXr = 207,
47   kPacketTypeHigh = 210,  // Port Mapping.
48 };
49
50 enum RtcpPacketField {
51     kRtcpSr     = 0x0002,
52     kRtcpRr     = 0x0004,
53     kRtcpDlrr   = 0x0400,
54     kRtcpRrtr   = 0x0800,
55     kRtcpCast   = 0x20000,
56     kRtcpReceiverLog = 0x80000,
57   };
58
59 // Each uint16 represents one packet id within a cast frame.
60 typedef std::set<uint16> PacketIdSet;
61 // Each uint8 represents one cast frame.
62 typedef std::map<uint8, PacketIdSet> MissingFramesAndPacketsMap;
63
64 class FrameIdWrapHelperTest;
65
66 // TODO(miu): UGLY IN-LINE DEFINITION IN HEADER FILE!  Move to appropriate
67 // location, separated into .h and .cc files.
68 class FrameIdWrapHelper {
69  public:
70   FrameIdWrapHelper()
71       : largest_frame_id_seen_(kStartFrameId) {}
72
73   uint32 MapTo32bitsFrameId(const uint8 over_the_wire_frame_id) {
74     uint32 ret = (largest_frame_id_seen_ & ~0xff) | over_the_wire_frame_id;
75     // Add 1000 to both sides to avoid underflows.
76     if (1000 + ret - largest_frame_id_seen_ > 1000 + 127) {
77       ret -= 0x100;
78     } else if (1000 + ret - largest_frame_id_seen_ < 1000 - 128) {
79       ret += 0x100;
80     }
81     if (1000 + ret - largest_frame_id_seen_ > 1000) {
82       largest_frame_id_seen_ = ret;
83     }
84     return ret;
85   }
86
87  private:
88   friend class FrameIdWrapHelperTest;
89   static const uint32 kStartFrameId = UINT32_C(0xffffffff);
90
91   uint32 largest_frame_id_seen_;
92
93   DISALLOW_COPY_AND_ASSIGN(FrameIdWrapHelper);
94 };
95
96 inline uint32 GetVideoRtpTimestamp(const base::TimeTicks& time_ticks) {
97   base::TimeTicks zero_time;
98   base::TimeDelta recorded_delta = time_ticks - zero_time;
99   // Timestamp is in 90 KHz for video.
100   return static_cast<uint32>(recorded_delta.InMilliseconds() * 90);
101 }
102
103 }  // namespace cast
104 }  // namespace media
105
106 #endif  // MEDIA_CAST_NET_CAST_TRANSPORT_DEFINES_H_