Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: talk/media/base/rtputils.cc

Issue 1362503003: Use suffixed {uint,int}{8,16,32,64}_t types. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase + revert basictypes.h (to be landed separately just in case of a revert due to unexpected us… Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « talk/media/base/rtputils.h ('k') | talk/media/base/rtputils_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 23 matching lines...) Expand all
34 static const size_t kRtpPayloadTypeOffset = 1; 34 static const size_t kRtpPayloadTypeOffset = 1;
35 static const size_t kRtpSeqNumOffset = 2; 35 static const size_t kRtpSeqNumOffset = 2;
36 static const size_t kRtpTimestampOffset = 4; 36 static const size_t kRtpTimestampOffset = 4;
37 static const size_t kRtpSsrcOffset = 8; 37 static const size_t kRtpSsrcOffset = 8;
38 static const size_t kRtcpPayloadTypeOffset = 1; 38 static const size_t kRtcpPayloadTypeOffset = 1;
39 39
40 bool GetUint8(const void* data, size_t offset, int* value) { 40 bool GetUint8(const void* data, size_t offset, int* value) {
41 if (!data || !value) { 41 if (!data || !value) {
42 return false; 42 return false;
43 } 43 }
44 *value = *(static_cast<const uint8*>(data) + offset); 44 *value = *(static_cast<const uint8_t*>(data) + offset);
45 return true; 45 return true;
46 } 46 }
47 47
48 bool GetUint16(const void* data, size_t offset, int* value) { 48 bool GetUint16(const void* data, size_t offset, int* value) {
49 if (!data || !value) { 49 if (!data || !value) {
50 return false; 50 return false;
51 } 51 }
52 *value = static_cast<int>( 52 *value = static_cast<int>(
53 rtc::GetBE16(static_cast<const uint8*>(data) + offset)); 53 rtc::GetBE16(static_cast<const uint8_t*>(data) + offset));
54 return true; 54 return true;
55 } 55 }
56 56
57 bool GetUint32(const void* data, size_t offset, uint32* value) { 57 bool GetUint32(const void* data, size_t offset, uint32_t* value) {
58 if (!data || !value) { 58 if (!data || !value) {
59 return false; 59 return false;
60 } 60 }
61 *value = rtc::GetBE32(static_cast<const uint8*>(data) + offset); 61 *value = rtc::GetBE32(static_cast<const uint8_t*>(data) + offset);
62 return true; 62 return true;
63 } 63 }
64 64
65 bool SetUint8(void* data, size_t offset, uint8_t value) { 65 bool SetUint8(void* data, size_t offset, uint8_t value) {
66 if (!data) { 66 if (!data) {
67 return false; 67 return false;
68 } 68 }
69 rtc::Set8(data, offset, value); 69 rtc::Set8(data, offset, value);
70 return true; 70 return true;
71 } 71 }
72 72
73 bool SetUint16(void* data, size_t offset, uint16_t value) { 73 bool SetUint16(void* data, size_t offset, uint16_t value) {
74 if (!data) { 74 if (!data) {
75 return false; 75 return false;
76 } 76 }
77 rtc::SetBE16(static_cast<uint8*>(data) + offset, value); 77 rtc::SetBE16(static_cast<uint8_t*>(data) + offset, value);
78 return true; 78 return true;
79 } 79 }
80 80
81 bool SetUint32(void* data, size_t offset, uint32 value) { 81 bool SetUint32(void* data, size_t offset, uint32_t value) {
82 if (!data) { 82 if (!data) {
83 return false; 83 return false;
84 } 84 }
85 rtc::SetBE32(static_cast<uint8*>(data) + offset, value); 85 rtc::SetBE32(static_cast<uint8_t*>(data) + offset, value);
86 return true; 86 return true;
87 } 87 }
88 88
89 bool GetRtpFlags(const void* data, size_t len, int* value) { 89 bool GetRtpFlags(const void* data, size_t len, int* value) {
90 if (len < kMinRtpPacketLen) { 90 if (len < kMinRtpPacketLen) {
91 return false; 91 return false;
92 } 92 }
93 return GetUint8(data, kRtpFlagsOffset, value); 93 return GetUint8(data, kRtpFlagsOffset, value);
94 } 94 }
95 95
96 bool GetRtpPayloadType(const void* data, size_t len, int* value) { 96 bool GetRtpPayloadType(const void* data, size_t len, int* value) {
97 if (len < kMinRtpPacketLen) { 97 if (len < kMinRtpPacketLen) {
98 return false; 98 return false;
99 } 99 }
100 if (!GetUint8(data, kRtpPayloadTypeOffset, value)) { 100 if (!GetUint8(data, kRtpPayloadTypeOffset, value)) {
101 return false; 101 return false;
102 } 102 }
103 *value &= 0x7F; 103 *value &= 0x7F;
104 return true; 104 return true;
105 } 105 }
106 106
107 bool GetRtpSeqNum(const void* data, size_t len, int* value) { 107 bool GetRtpSeqNum(const void* data, size_t len, int* value) {
108 if (len < kMinRtpPacketLen) { 108 if (len < kMinRtpPacketLen) {
109 return false; 109 return false;
110 } 110 }
111 return GetUint16(data, kRtpSeqNumOffset, value); 111 return GetUint16(data, kRtpSeqNumOffset, value);
112 } 112 }
113 113
114 bool GetRtpTimestamp(const void* data, size_t len, uint32* value) { 114 bool GetRtpTimestamp(const void* data, size_t len, uint32_t* value) {
115 if (len < kMinRtpPacketLen) { 115 if (len < kMinRtpPacketLen) {
116 return false; 116 return false;
117 } 117 }
118 return GetUint32(data, kRtpTimestampOffset, value); 118 return GetUint32(data, kRtpTimestampOffset, value);
119 } 119 }
120 120
121 bool GetRtpSsrc(const void* data, size_t len, uint32* value) { 121 bool GetRtpSsrc(const void* data, size_t len, uint32_t* value) {
122 if (len < kMinRtpPacketLen) { 122 if (len < kMinRtpPacketLen) {
123 return false; 123 return false;
124 } 124 }
125 return GetUint32(data, kRtpSsrcOffset, value); 125 return GetUint32(data, kRtpSsrcOffset, value);
126 } 126 }
127 127
128 bool GetRtpHeaderLen(const void* data, size_t len, size_t* value) { 128 bool GetRtpHeaderLen(const void* data, size_t len, size_t* value) {
129 if (!data || len < kMinRtpPacketLen || !value) return false; 129 if (!data || len < kMinRtpPacketLen || !value) return false;
130 const uint8* header = static_cast<const uint8*>(data); 130 const uint8_t* header = static_cast<const uint8_t*>(data);
131 // Get base header size + length of CSRCs (not counting extension yet). 131 // Get base header size + length of CSRCs (not counting extension yet).
132 size_t header_size = kMinRtpPacketLen + (header[0] & 0xF) * sizeof(uint32); 132 size_t header_size = kMinRtpPacketLen + (header[0] & 0xF) * sizeof(uint32_t);
133 if (len < header_size) return false; 133 if (len < header_size) return false;
134 // If there's an extension, read and add in the extension size. 134 // If there's an extension, read and add in the extension size.
135 if (header[0] & 0x10) { 135 if (header[0] & 0x10) {
136 if (len < header_size + sizeof(uint32)) return false; 136 if (len < header_size + sizeof(uint32_t))
137 header_size += ((rtc::GetBE16(header + header_size + 2) + 1) * 137 return false;
138 sizeof(uint32)); 138 header_size +=
139 ((rtc::GetBE16(header + header_size + 2) + 1) * sizeof(uint32_t));
139 if (len < header_size) return false; 140 if (len < header_size) return false;
140 } 141 }
141 *value = header_size; 142 *value = header_size;
142 return true; 143 return true;
143 } 144 }
144 145
145 bool GetRtpHeader(const void* data, size_t len, RtpHeader* header) { 146 bool GetRtpHeader(const void* data, size_t len, RtpHeader* header) {
146 return (GetRtpPayloadType(data, len, &(header->payload_type)) && 147 return (GetRtpPayloadType(data, len, &(header->payload_type)) &&
147 GetRtpSeqNum(data, len, &(header->seq_num)) && 148 GetRtpSeqNum(data, len, &(header->seq_num)) &&
148 GetRtpTimestamp(data, len, &(header->timestamp)) && 149 GetRtpTimestamp(data, len, &(header->timestamp)) &&
149 GetRtpSsrc(data, len, &(header->ssrc))); 150 GetRtpSsrc(data, len, &(header->ssrc)));
150 } 151 }
151 152
152 bool GetRtcpType(const void* data, size_t len, int* value) { 153 bool GetRtcpType(const void* data, size_t len, int* value) {
153 if (len < kMinRtcpPacketLen) { 154 if (len < kMinRtcpPacketLen) {
154 return false; 155 return false;
155 } 156 }
156 return GetUint8(data, kRtcpPayloadTypeOffset, value); 157 return GetUint8(data, kRtcpPayloadTypeOffset, value);
157 } 158 }
158 159
159 // This method returns SSRC first of RTCP packet, except if packet is SDES. 160 // This method returns SSRC first of RTCP packet, except if packet is SDES.
160 // TODO(mallinath) - Fully implement RFC 5506. This standard doesn't restrict 161 // TODO(mallinath) - Fully implement RFC 5506. This standard doesn't restrict
161 // to send non-compound packets only to feedback messages. 162 // to send non-compound packets only to feedback messages.
162 bool GetRtcpSsrc(const void* data, size_t len, uint32* value) { 163 bool GetRtcpSsrc(const void* data, size_t len, uint32_t* value) {
163 // Packet should be at least of 8 bytes, to get SSRC from a RTCP packet. 164 // Packet should be at least of 8 bytes, to get SSRC from a RTCP packet.
164 if (!data || len < kMinRtcpPacketLen + 4 || !value) return false; 165 if (!data || len < kMinRtcpPacketLen + 4 || !value) return false;
165 int pl_type; 166 int pl_type;
166 if (!GetRtcpType(data, len, &pl_type)) return false; 167 if (!GetRtcpType(data, len, &pl_type)) return false;
167 // SDES packet parsing is not supported. 168 // SDES packet parsing is not supported.
168 if (pl_type == kRtcpTypeSDES) return false; 169 if (pl_type == kRtcpTypeSDES) return false;
169 *value = rtc::GetBE32(static_cast<const uint8*>(data) + 4); 170 *value = rtc::GetBE32(static_cast<const uint8_t*>(data) + 4);
170 return true; 171 return true;
171 } 172 }
172 173
173 bool SetRtpSsrc(void* data, size_t len, uint32 value) { 174 bool SetRtpSsrc(void* data, size_t len, uint32_t value) {
174 return SetUint32(data, kRtpSsrcOffset, value); 175 return SetUint32(data, kRtpSsrcOffset, value);
175 } 176 }
176 177
177 // Assumes version 2, no padding, no extensions, no csrcs. 178 // Assumes version 2, no padding, no extensions, no csrcs.
178 bool SetRtpHeader(void* data, size_t len, const RtpHeader& header) { 179 bool SetRtpHeader(void* data, size_t len, const RtpHeader& header) {
179 if (!IsValidRtpPayloadType(header.payload_type) || 180 if (!IsValidRtpPayloadType(header.payload_type) ||
180 header.seq_num < 0 || header.seq_num > UINT16_MAX) { 181 header.seq_num < 0 || header.seq_num > UINT16_MAX) {
181 return false; 182 return false;
182 } 183 }
183 return (SetUint8(data, kRtpFlagsOffset, kRtpVersion << 6) && 184 return (SetUint8(data, kRtpFlagsOffset, kRtpVersion << 6) &&
184 SetUint8(data, kRtpPayloadTypeOffset, header.payload_type & 0x7F) && 185 SetUint8(data, kRtpPayloadTypeOffset, header.payload_type & 0x7F) &&
185 SetUint16(data, kRtpSeqNumOffset, 186 SetUint16(data, kRtpSeqNumOffset,
186 static_cast<uint16_t>(header.seq_num)) && 187 static_cast<uint16_t>(header.seq_num)) &&
187 SetUint32(data, kRtpTimestampOffset, header.timestamp) && 188 SetUint32(data, kRtpTimestampOffset, header.timestamp) &&
188 SetRtpSsrc(data, len, header.ssrc)); 189 SetRtpSsrc(data, len, header.ssrc));
189 } 190 }
190 191
191 bool IsRtpPacket(const void* data, size_t len) { 192 bool IsRtpPacket(const void* data, size_t len) {
192 if (len < kMinRtpPacketLen) 193 if (len < kMinRtpPacketLen)
193 return false; 194 return false;
194 195
195 return (static_cast<const uint8*>(data)[0] >> 6) == kRtpVersion; 196 return (static_cast<const uint8_t*>(data)[0] >> 6) == kRtpVersion;
196 } 197 }
197 198
198 bool IsValidRtpPayloadType(int payload_type) { 199 bool IsValidRtpPayloadType(int payload_type) {
199 return payload_type >= 0 && payload_type <= 127; 200 return payload_type >= 0 && payload_type <= 127;
200 } 201 }
201 202
202 } // namespace cricket 203 } // namespace cricket
OLDNEW
« no previous file with comments | « talk/media/base/rtputils.h ('k') | talk/media/base/rtputils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698