OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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_NET_CAST_TRANSPORT_DEFINES_H_ | 5 #ifndef MEDIA_CAST_NET_CAST_TRANSPORT_DEFINES_H_ |
6 #define MEDIA_CAST_NET_CAST_TRANSPORT_DEFINES_H_ | 6 #define MEDIA_CAST_NET_CAST_TRANSPORT_DEFINES_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/basictypes.h" | |
16 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
17 #include "base/time/time.h" | 16 #include "base/time/time.h" |
18 | 17 |
19 namespace media { | 18 namespace media { |
20 namespace cast { | 19 namespace cast { |
21 | 20 |
22 // Enums used to indicate transport readiness state. | 21 // Enums used to indicate transport readiness state. |
23 enum CastTransportStatus { | 22 enum CastTransportStatus { |
24 TRANSPORT_AUDIO_UNINITIALIZED = 0, | 23 TRANSPORT_AUDIO_UNINITIALIZED = 0, |
25 TRANSPORT_VIDEO_UNINITIALIZED, | 24 TRANSPORT_VIDEO_UNINITIALIZED, |
26 TRANSPORT_AUDIO_INITIALIZED, | 25 TRANSPORT_AUDIO_INITIALIZED, |
27 TRANSPORT_VIDEO_INITIALIZED, | 26 TRANSPORT_VIDEO_INITIALIZED, |
28 TRANSPORT_INVALID_CRYPTO_CONFIG, | 27 TRANSPORT_INVALID_CRYPTO_CONFIG, |
29 TRANSPORT_SOCKET_ERROR, | 28 TRANSPORT_SOCKET_ERROR, |
30 CAST_TRANSPORT_STATUS_LAST = TRANSPORT_SOCKET_ERROR | 29 CAST_TRANSPORT_STATUS_LAST = TRANSPORT_SOCKET_ERROR |
31 }; | 30 }; |
32 | 31 |
33 // kRtcpCastAllPacketsLost is used in PacketIDSet and | 32 // kRtcpCastAllPacketsLost is used in PacketIDSet and |
34 // on the wire to mean that ALL packets for a particular | 33 // on the wire to mean that ALL packets for a particular |
35 // frame are lost. | 34 // frame are lost. |
36 const uint16_t kRtcpCastAllPacketsLost = 0xffff; | 35 const uint16_t kRtcpCastAllPacketsLost = 0xffff; |
37 | 36 |
38 // kRtcpCastLastPacket is used in PacketIDSet to ask for | 37 // kRtcpCastLastPacket is used in PacketIDSet to ask for |
39 // the last packet of a frame to be retransmitted. | 38 // the last packet of a frame to be retransmitted. |
40 const uint16_t kRtcpCastLastPacket = 0xfffe; | 39 const uint16_t kRtcpCastLastPacket = 0xfffe; |
41 | 40 |
42 const size_t kMaxIpPacketSize = 1500; | 41 const size_t kMaxIpPacketSize = 1500; |
43 | 42 |
44 // Each uint16 represents one packet id within a cast frame. | 43 // Each uint16_t represents one packet id within a cast frame. |
45 // Can also contain kRtcpCastAllPacketsLost and kRtcpCastLastPacket. | 44 // Can also contain kRtcpCastAllPacketsLost and kRtcpCastLastPacket. |
46 using PacketIdSet = std::set<uint16_t>; | 45 using PacketIdSet = std::set<uint16_t>; |
47 // Each uint8 represents one cast frame. | 46 // Each uint8_t represents one cast frame. |
48 using MissingFramesAndPacketsMap = std::map<uint8_t, PacketIdSet>; | 47 using MissingFramesAndPacketsMap = std::map<uint8_t, PacketIdSet>; |
49 | 48 |
50 using Packet = std::vector<uint8_t>; | 49 using Packet = std::vector<uint8_t>; |
51 using PacketRef = scoped_refptr<base::RefCountedData<Packet>>; | 50 using PacketRef = scoped_refptr<base::RefCountedData<Packet>>; |
52 using PacketList = std::vector<PacketRef>; | 51 using PacketList = std::vector<PacketRef>; |
53 | 52 |
54 class FrameIdWrapHelperTest; | 53 class FrameIdWrapHelperTest; |
55 | 54 |
56 // TODO(miu): UGLY IN-LINE DEFINITION IN HEADER FILE! Move to appropriate | 55 // TODO(miu): UGLY IN-LINE DEFINITION IN HEADER FILE! Move to appropriate |
57 // location, separated into .h and .cc files. http://crbug.com/530839 | 56 // location, separated into .h and .cc files. http://crbug.com/530839 |
58 class FrameIdWrapHelper { | 57 class FrameIdWrapHelper { |
59 public: | 58 public: |
60 explicit FrameIdWrapHelper(uint32_t start_frame_id) | 59 explicit FrameIdWrapHelper(uint32_t start_frame_id) |
61 : largest_frame_id_seen_(start_frame_id) {} | 60 : largest_frame_id_seen_(start_frame_id) {} |
62 | 61 |
63 uint32 MapTo32bitsFrameId(const uint8 over_the_wire_frame_id) { | 62 uint32_t MapTo32bitsFrameId(const uint8_t over_the_wire_frame_id) { |
64 uint32 ret = (largest_frame_id_seen_ & ~0xff) | over_the_wire_frame_id; | 63 uint32_t ret = (largest_frame_id_seen_ & ~0xff) | over_the_wire_frame_id; |
65 // Add 1000 to both sides to avoid underflows. | 64 // Add 1000 to both sides to avoid underflows. |
66 if (1000 + ret - largest_frame_id_seen_ > 1000 + 127) { | 65 if (1000 + ret - largest_frame_id_seen_ > 1000 + 127) { |
67 ret -= 0x100; | 66 ret -= 0x100; |
68 } else if (1000 + ret - largest_frame_id_seen_ < 1000 - 128) { | 67 } else if (1000 + ret - largest_frame_id_seen_ < 1000 - 128) { |
69 ret += 0x100; | 68 ret += 0x100; |
70 } | 69 } |
71 if (1000 + ret - largest_frame_id_seen_ > 1000) { | 70 if (1000 + ret - largest_frame_id_seen_ > 1000) { |
72 largest_frame_id_seen_ = ret; | 71 largest_frame_id_seen_ = ret; |
73 } | 72 } |
74 return ret; | 73 return ret; |
75 } | 74 } |
76 | 75 |
77 private: | 76 private: |
78 friend class FrameIdWrapHelperTest; | 77 friend class FrameIdWrapHelperTest; |
79 | 78 |
80 uint32 largest_frame_id_seen_; | 79 uint32_t largest_frame_id_seen_; |
81 | 80 |
82 DISALLOW_COPY_AND_ASSIGN(FrameIdWrapHelper); | 81 DISALLOW_COPY_AND_ASSIGN(FrameIdWrapHelper); |
83 }; | 82 }; |
84 | 83 |
85 } // namespace cast | 84 } // namespace cast |
86 } // namespace media | 85 } // namespace media |
87 | 86 |
88 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_DEFINES_H_ | 87 #endif // MEDIA_CAST_NET_CAST_TRANSPORT_DEFINES_H_ |
OLD | NEW |