OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 #include <math.h> // ceil | 14 #include <math.h> // ceil |
15 #include <string.h> // memcpy | 15 #include <string.h> // memcpy |
16 | 16 |
17 #include "webrtc/base/checks.h" | |
18 #include "webrtc/base/logging.h" | |
19 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | |
20 | |
17 namespace webrtc { | 21 namespace webrtc { |
18 | 22 |
19 namespace RTCPUtility { | 23 namespace RTCPUtility { |
20 | 24 |
21 NackStats::NackStats() | 25 NackStats::NackStats() |
22 : max_sequence_number_(0), | 26 : max_sequence_number_(0), |
23 requests_(0), | 27 requests_(0), |
24 unique_requests_(0) {} | 28 unique_requests_(0) {} |
25 | 29 |
26 NackStats::~NackStats() {} | 30 NackStats::~NackStats() {} |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 } | 152 } |
149 } | 153 } |
150 return _packetType; | 154 return _packetType; |
151 } | 155 } |
152 | 156 |
153 void | 157 void |
154 RTCPUtility::RTCPParserV2::IterateTopLevel() | 158 RTCPUtility::RTCPParserV2::IterateTopLevel() |
155 { | 159 { |
156 for (;;) | 160 for (;;) |
157 { | 161 { |
158 RTCPCommonHeader header; | 162 RtcpCommonHeader header; |
163 if (_ptrRTCPDataEnd <= _ptrRTCPData) | |
164 return; | |
159 | 165 |
160 const bool success = RTCPParseCommonHeader(_ptrRTCPData, | 166 if (!RtcpParseCommonHeader(_ptrRTCPData, _ptrRTCPDataEnd - _ptrRTCPData, |
161 _ptrRTCPDataEnd, | 167 &header)) { |
162 header); | |
163 | |
164 if (!success) | |
165 { | |
166 return; | 168 return; |
167 } | 169 } |
168 _ptrRTCPBlockEnd = _ptrRTCPData + header.LengthInOctets; | 170 _ptrRTCPBlockEnd = _ptrRTCPData + header.BlockSize(); |
169 if (_ptrRTCPBlockEnd > _ptrRTCPDataEnd) | 171 if (_ptrRTCPBlockEnd > _ptrRTCPDataEnd) |
170 { | 172 { |
171 // Bad block! | 173 // Bad block! |
172 return; | 174 return; |
173 } | 175 } |
174 | 176 |
175 switch (header.PT) | 177 switch (header.packet_type) { |
176 { | |
177 case PT_SR: | 178 case PT_SR: |
178 { | 179 { |
179 // number of Report blocks | 180 // number of Report blocks |
180 _numberOfBlocks = header.IC; | 181 _numberOfBlocks = header.count_or_format; |
181 ParseSR(); | 182 ParseSR(); |
182 return; | 183 return; |
183 } | 184 } |
184 case PT_RR: | 185 case PT_RR: |
185 { | 186 { |
186 // number of Report blocks | 187 // number of Report blocks |
187 _numberOfBlocks = header.IC; | 188 _numberOfBlocks = header.count_or_format; |
188 ParseRR(); | 189 ParseRR(); |
189 return; | 190 return; |
190 } | 191 } |
191 case PT_SDES: | 192 case PT_SDES: |
192 { | 193 { |
193 // number of SDES blocks | 194 // number of SDES blocks |
194 _numberOfBlocks = header.IC; | 195 _numberOfBlocks = header.count_or_format; |
195 const bool ok = ParseSDES(); | 196 const bool ok = ParseSDES(); |
196 if (!ok) | 197 if (!ok) |
197 { | 198 { |
198 // Nothing supported found, continue to next block! | 199 // Nothing supported found, continue to next block! |
199 break; | 200 break; |
200 } | 201 } |
201 return; | 202 return; |
202 } | 203 } |
203 case PT_BYE: | 204 case PT_BYE: |
204 { | 205 { |
205 _numberOfBlocks = header.IC; | 206 _numberOfBlocks = header.count_or_format; |
206 const bool ok = ParseBYE(); | 207 const bool ok = ParseBYE(); |
207 if (!ok) | 208 if (!ok) |
208 { | 209 { |
209 // Nothing supported found, continue to next block! | 210 // Nothing supported found, continue to next block! |
210 break; | 211 break; |
211 } | 212 } |
212 return; | 213 return; |
213 } | 214 } |
214 case PT_IJ: | 215 case PT_IJ: |
215 { | 216 { |
216 // number of Report blocks | 217 // number of Report blocks |
217 _numberOfBlocks = header.IC; | 218 _numberOfBlocks = header.count_or_format; |
218 ParseIJ(); | 219 ParseIJ(); |
219 return; | 220 return; |
220 } | 221 } |
221 case PT_RTPFB: // Fall through! | 222 case PT_RTPFB: // Fall through! |
222 case PT_PSFB: | 223 case PT_PSFB: |
223 { | 224 { |
224 const bool ok = ParseFBCommon(header); | 225 const bool ok = ParseFBCommon(header); |
225 if (!ok) | 226 if (!ok) |
226 { | 227 { |
227 // Nothing supported found, continue to next block! | 228 // Nothing supported found, continue to next block! |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 const bool success = ParseAPPItem(); | 404 const bool success = ParseAPPItem(); |
404 if (!success) | 405 if (!success) |
405 { | 406 { |
406 Iterate(); | 407 Iterate(); |
407 } | 408 } |
408 } | 409 } |
409 | 410 |
410 void | 411 void |
411 RTCPUtility::RTCPParserV2::Validate() | 412 RTCPUtility::RTCPParserV2::Validate() |
412 { | 413 { |
413 if (_ptrRTCPData == NULL) | 414 if (_ptrRTCPData == nullptr) |
414 { | 415 return; // NOT VALID |
415 return; // NOT VALID | |
416 } | |
417 | 416 |
418 RTCPCommonHeader header; | 417 RtcpCommonHeader header; |
419 const bool success = RTCPParseCommonHeader(_ptrRTCPDataBegin, | 418 if (_ptrRTCPDataEnd <= _ptrRTCPDataBegin) |
420 _ptrRTCPDataEnd, | 419 return; // NOT VALID |
421 header); | |
422 | 420 |
423 if (!success) | 421 if (!RtcpParseCommonHeader(_ptrRTCPDataBegin, |
424 { | 422 _ptrRTCPDataEnd - _ptrRTCPDataBegin, &header)) |
425 return; // NOT VALID! | 423 return; // NOT VALID! |
426 } | |
427 | 424 |
428 // * if (!reducedSize) : first packet must be RR or SR. | 425 // * if (!reducedSize) : first packet must be RR or SR. |
429 // | 426 // |
430 // * The padding bit (P) should be zero for the first packet of a | 427 // * The padding bit (P) should be zero for the first packet of a |
431 // compound RTCP packet because padding should only be applied, | 428 // compound RTCP packet because padding should only be applied, |
432 // if it is needed, to the last packet. (NOT CHECKED!) | 429 // if it is needed, to the last packet. (NOT CHECKED!) |
433 // | 430 // |
434 // * The length fields of the individual RTCP packets must add up | 431 // * The length fields of the individual RTCP packets must add up |
435 // to the overall length of the compound RTCP packet as | 432 // to the overall length of the compound RTCP packet as |
436 // received. This is a fairly strong check. (NOT CHECKED!) | 433 // received. This is a fairly strong check. (NOT CHECKED!) |
437 | 434 |
438 if (!_RTCPReducedSizeEnable) | 435 if (!_RTCPReducedSizeEnable) |
439 { | 436 { |
440 if ((header.PT != PT_SR) && (header.PT != PT_RR)) | 437 if ((header.packet_type != PT_SR) && (header.packet_type != PT_RR)) { |
441 { | |
442 return; // NOT VALID | 438 return; // NOT VALID |
443 } | 439 } |
444 } | 440 } |
445 | 441 |
446 _validPacket = true; | 442 _validPacket = true; |
447 } | 443 } |
448 | 444 |
449 bool | 445 bool |
450 RTCPUtility::RTCPParserV2::IsValid() const | 446 RTCPUtility::RTCPParserV2::IsValid() const |
451 { | 447 { |
452 return _validPacket; | 448 return _validPacket; |
453 } | 449 } |
454 | 450 |
455 void | 451 void |
456 RTCPUtility::RTCPParserV2::EndCurrentBlock() | 452 RTCPUtility::RTCPParserV2::EndCurrentBlock() |
457 { | 453 { |
458 _ptrRTCPData = _ptrRTCPBlockEnd; | 454 _ptrRTCPData = _ptrRTCPBlockEnd; |
459 } | 455 } |
460 | 456 |
461 bool | 457 // 0 1 2 3 |
462 RTCPUtility::RTCPParseCommonHeader( const uint8_t* ptrDataBegin, | 458 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 |
463 const uint8_t* ptrDataEnd, | 459 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
464 RTCPCommonHeader& parsedHeader) | 460 // |V=2|P| IC | PT | length | |
465 { | 461 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
466 if (!ptrDataBegin || !ptrDataEnd) | 462 // |
467 { | 463 // Common header for all RTCP packets, 4 octets. |
468 return false; | 464 |
465 bool RTCPUtility::RtcpParseCommonHeader(const uint8_t* packet, | |
466 size_t size_bytes, | |
467 RtcpCommonHeader* parsed_header) { | |
468 DCHECK(parsed_header != nullptr); | |
469 const size_t kHeaderLength = 4; | |
åsapersson
2015/09/10 13:27:33
use define in RtcpCommonHeader?
sprang_webrtc
2015/09/11 13:03:19
Done.
| |
470 if (size_bytes < kHeaderLength) { | |
471 LOG(LS_WARNING) << "Too little data (" << size_bytes << " byte" | |
472 << (size_bytes != 1 ? "s" : "") | |
473 << ") remaining in buffer to parse RTCP header (4 bytes)."; | |
474 return false; | |
475 } | |
476 | |
477 const uint8_t kRtcpVersion = 2; | |
478 uint8_t version = packet[0] >> 6; | |
479 if (version != kRtcpVersion) { | |
480 LOG(LS_WARNING) << "Invalid RTCP header: Version must be " | |
481 << static_cast<int>(kRtcpVersion) << " but was " | |
482 << static_cast<int>(version); | |
483 return false; | |
484 } | |
485 | |
486 bool has_padding = (packet[0] & 0x20) != 0; | |
487 uint8_t format = packet[0] & 0x1F; | |
488 uint8_t packet_type = packet[1]; | |
489 size_t packet_size_words = | |
490 ByteReader<uint16_t>::ReadBigEndian(&packet[2]) + 1; | |
491 | |
492 if (size_bytes < packet_size_words * 4) { | |
493 LOG(LS_WARNING) << "Buffer too small (" << size_bytes | |
494 << " bytes) to fit an RtcpPacket of " << packet_size_words | |
495 << " 32bit words."; | |
496 return false; | |
497 } | |
498 | |
499 size_t payload_size = packet_size_words * 4; | |
500 size_t padding_bytes = 0; | |
501 if (has_padding) { | |
502 padding_bytes = packet[payload_size - 1]; | |
åsapersson
2015/09/10 13:27:33
if size_bytes is 4 and packet_size_words is 1 (len
sprang_webrtc
2015/09/11 13:03:19
Done.
Good catch!
| |
503 if (kHeaderLength + padding_bytes > payload_size) { | |
504 LOG(LS_WARNING) << "Invalid RTCP header: Too many padding bytes (" | |
505 << padding_bytes << ") for a packet size of " | |
506 << payload_size << "bytes."; | |
507 return false; | |
469 } | 508 } |
509 payload_size -= padding_bytes; | |
510 } | |
511 payload_size -= kHeaderLength; | |
470 | 512 |
471 // 0 1 2 3 | 513 parsed_header->version = kRtcpVersion; |
472 // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 | 514 parsed_header->count_or_format = format; |
473 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 515 parsed_header->packet_type = packet_type; |
474 // |V=2|P| IC | PT | length | | 516 parsed_header->payload_size_bytes = payload_size; |
475 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 517 parsed_header->padding_bytes = padding_bytes; |
476 // | |
477 // Common header for all RTCP packets, 4 octets. | |
478 | 518 |
479 if ((ptrDataEnd - ptrDataBegin) < 4) | 519 return true; |
480 { | |
481 return false; | |
482 } | |
483 | |
484 parsedHeader.V = ptrDataBegin[0] >> 6; | |
485 parsedHeader.P = ((ptrDataBegin[0] & 0x20) == 0) ? false : true ; | |
486 parsedHeader.IC = ptrDataBegin[0] & 0x1f; | |
487 parsedHeader.PT = ptrDataBegin[1]; | |
488 | |
489 parsedHeader.LengthInOctets = (ptrDataBegin[2] << 8) + ptrDataBegin[3] + 1; | |
490 parsedHeader.LengthInOctets *= 4; | |
491 | |
492 if(parsedHeader.LengthInOctets == 0) | |
493 { | |
494 return false; | |
495 } | |
496 // Check if RTP version field == 2 | |
497 if (parsedHeader.V != 2) | |
498 { | |
499 return false; | |
500 } | |
501 | |
502 return true; | |
503 } | 520 } |
504 | 521 |
505 bool | 522 bool |
506 RTCPUtility::RTCPParserV2::ParseRR() | 523 RTCPUtility::RTCPParserV2::ParseRR() |
507 { | 524 { |
508 const ptrdiff_t length = _ptrRTCPBlockEnd - _ptrRTCPData; | 525 const ptrdiff_t length = _ptrRTCPBlockEnd - _ptrRTCPData; |
509 | 526 |
510 if (length < 8) | 527 if (length < 8) |
511 { | 528 { |
512 return false; | 529 return false; |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1130 _state = ParseState::State_TopLevel; | 1147 _state = ParseState::State_TopLevel; |
1131 EndCurrentBlock(); | 1148 EndCurrentBlock(); |
1132 return false; | 1149 return false; |
1133 } | 1150 } |
1134 // Skip block. | 1151 // Skip block. |
1135 _ptrRTCPData += kBlockLengthInBytes; | 1152 _ptrRTCPData += kBlockLengthInBytes; |
1136 _state = ParseState::State_XRItem; | 1153 _state = ParseState::State_XRItem; |
1137 return false; | 1154 return false; |
1138 } | 1155 } |
1139 | 1156 |
1140 bool | 1157 bool RTCPUtility::RTCPParserV2::ParseFBCommon(const RtcpCommonHeader& header) { |
1141 RTCPUtility::RTCPParserV2::ParseFBCommon(const RTCPCommonHeader& header) | 1158 assert((header.packet_type == PT_RTPFB) || |
1142 { | 1159 (header.packet_type == PT_PSFB)); // Parser logic check |
1143 assert((header.PT == PT_RTPFB) || (header.PT == PT_PSFB)); // Parser logic c heck | |
1144 | 1160 |
1145 const ptrdiff_t length = _ptrRTCPBlockEnd - _ptrRTCPData; | 1161 const ptrdiff_t length = _ptrRTCPBlockEnd - _ptrRTCPData; |
1146 | 1162 |
1147 if (length < 12) // 4 * 3, RFC4585 section 6.1 | 1163 if (length < 12) // 4 * 3, RFC4585 section 6.1 |
1148 { | 1164 { |
1149 EndCurrentBlock(); | 1165 EndCurrentBlock(); |
1150 return false; | 1166 return false; |
1151 } | 1167 } |
1152 | 1168 |
1153 _ptrRTCPData += 4; // Skip RTCP header | 1169 _ptrRTCPData += 4; // Skip RTCP header |
1154 | 1170 |
1155 uint32_t senderSSRC = *_ptrRTCPData++ << 24; | 1171 uint32_t senderSSRC = *_ptrRTCPData++ << 24; |
1156 senderSSRC += *_ptrRTCPData++ << 16; | 1172 senderSSRC += *_ptrRTCPData++ << 16; |
1157 senderSSRC += *_ptrRTCPData++ << 8; | 1173 senderSSRC += *_ptrRTCPData++ << 8; |
1158 senderSSRC += *_ptrRTCPData++; | 1174 senderSSRC += *_ptrRTCPData++; |
1159 | 1175 |
1160 uint32_t mediaSSRC = *_ptrRTCPData++ << 24; | 1176 uint32_t mediaSSRC = *_ptrRTCPData++ << 24; |
1161 mediaSSRC += *_ptrRTCPData++ << 16; | 1177 mediaSSRC += *_ptrRTCPData++ << 16; |
1162 mediaSSRC += *_ptrRTCPData++ << 8; | 1178 mediaSSRC += *_ptrRTCPData++ << 8; |
1163 mediaSSRC += *_ptrRTCPData++; | 1179 mediaSSRC += *_ptrRTCPData++; |
1164 | 1180 |
1165 if (header.PT == PT_RTPFB) | 1181 if (header.packet_type == PT_RTPFB) { |
1166 { | |
1167 // Transport layer feedback | 1182 // Transport layer feedback |
1168 | 1183 |
1169 switch (header.IC) | 1184 switch (header.count_or_format) { |
1170 { | |
1171 case 1: | 1185 case 1: |
1172 { | 1186 { |
1173 // NACK | 1187 // NACK |
1174 _packetType = RTCPPacketTypes::kRtpfbNack; | 1188 _packetType = RTCPPacketTypes::kRtpfbNack; |
1175 _packet.NACK.SenderSSRC = senderSSRC; | 1189 _packet.NACK.SenderSSRC = senderSSRC; |
1176 _packet.NACK.MediaSSRC = mediaSSRC; | 1190 _packet.NACK.MediaSSRC = mediaSSRC; |
1177 | 1191 |
1178 _state = ParseState::State_RTPFB_NACKItem; | 1192 _state = ParseState::State_RTPFB_NACKItem; |
1179 | 1193 |
1180 return true; | 1194 return true; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1215 _packetType = RTCPPacketTypes::kRtpfbSrReq; | 1229 _packetType = RTCPPacketTypes::kRtpfbSrReq; |
1216 | 1230 |
1217 // Note: No state transition, SR REQ is empty! | 1231 // Note: No state transition, SR REQ is empty! |
1218 return true; | 1232 return true; |
1219 } | 1233 } |
1220 default: | 1234 default: |
1221 break; | 1235 break; |
1222 } | 1236 } |
1223 EndCurrentBlock(); | 1237 EndCurrentBlock(); |
1224 return false; | 1238 return false; |
1225 } | 1239 } else if (header.packet_type == PT_PSFB) { |
1226 else if (header.PT == PT_PSFB) | |
1227 { | |
1228 // Payload specific feedback | 1240 // Payload specific feedback |
1229 switch (header.IC) | 1241 switch (header.count_or_format) { |
1230 { | |
1231 case 1: | 1242 case 1: |
1232 // PLI | 1243 // PLI |
1233 _packetType = RTCPPacketTypes::kPsfbPli; | 1244 _packetType = RTCPPacketTypes::kPsfbPli; |
1234 _packet.PLI.SenderSSRC = senderSSRC; | 1245 _packet.PLI.SenderSSRC = senderSSRC; |
1235 _packet.PLI.MediaSSRC = mediaSSRC; | 1246 _packet.PLI.MediaSSRC = mediaSSRC; |
1236 | 1247 |
1237 // Note: No state transition, PLI FCI is empty! | 1248 // Note: No state transition, PLI FCI is empty! |
1238 return true; | 1249 return true; |
1239 case 2: | 1250 case 2: |
1240 // SLI | 1251 // SLI |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1572 _packet.FIRItem.SSRC = *_ptrRTCPData++ << 24; | 1583 _packet.FIRItem.SSRC = *_ptrRTCPData++ << 24; |
1573 _packet.FIRItem.SSRC += *_ptrRTCPData++ << 16; | 1584 _packet.FIRItem.SSRC += *_ptrRTCPData++ << 16; |
1574 _packet.FIRItem.SSRC += *_ptrRTCPData++ << 8; | 1585 _packet.FIRItem.SSRC += *_ptrRTCPData++ << 8; |
1575 _packet.FIRItem.SSRC += *_ptrRTCPData++; | 1586 _packet.FIRItem.SSRC += *_ptrRTCPData++; |
1576 | 1587 |
1577 _packet.FIRItem.CommandSequenceNumber = *_ptrRTCPData++; | 1588 _packet.FIRItem.CommandSequenceNumber = *_ptrRTCPData++; |
1578 _ptrRTCPData += 3; // Skip "Reserved" bytes. | 1589 _ptrRTCPData += 3; // Skip "Reserved" bytes. |
1579 return true; | 1590 return true; |
1580 } | 1591 } |
1581 | 1592 |
1582 bool | 1593 bool RTCPUtility::RTCPParserV2::ParseAPP(const RtcpCommonHeader& header) { |
1583 RTCPUtility::RTCPParserV2::ParseAPP( const RTCPCommonHeader& header) | |
1584 { | |
1585 ptrdiff_t length = _ptrRTCPBlockEnd - _ptrRTCPData; | 1594 ptrdiff_t length = _ptrRTCPBlockEnd - _ptrRTCPData; |
1586 | 1595 |
1587 if (length < 12) // 4 * 3, RFC 3550 6.7 APP: Application-Defined RTCP Packet | 1596 if (length < 12) // 4 * 3, RFC 3550 6.7 APP: Application-Defined RTCP Packet |
1588 { | 1597 { |
1589 EndCurrentBlock(); | 1598 EndCurrentBlock(); |
1590 return false; | 1599 return false; |
1591 } | 1600 } |
1592 | 1601 |
1593 _ptrRTCPData += 4; // Skip RTCP header | 1602 _ptrRTCPData += 4; // Skip RTCP header |
1594 | 1603 |
1595 uint32_t senderSSRC = *_ptrRTCPData++ << 24; | 1604 uint32_t senderSSRC = *_ptrRTCPData++ << 24; |
1596 senderSSRC += *_ptrRTCPData++ << 16; | 1605 senderSSRC += *_ptrRTCPData++ << 16; |
1597 senderSSRC += *_ptrRTCPData++ << 8; | 1606 senderSSRC += *_ptrRTCPData++ << 8; |
1598 senderSSRC += *_ptrRTCPData++; | 1607 senderSSRC += *_ptrRTCPData++; |
1599 | 1608 |
1600 uint32_t name = *_ptrRTCPData++ << 24; | 1609 uint32_t name = *_ptrRTCPData++ << 24; |
1601 name += *_ptrRTCPData++ << 16; | 1610 name += *_ptrRTCPData++ << 16; |
1602 name += *_ptrRTCPData++ << 8; | 1611 name += *_ptrRTCPData++ << 8; |
1603 name += *_ptrRTCPData++; | 1612 name += *_ptrRTCPData++; |
1604 | 1613 |
1605 length = _ptrRTCPBlockEnd - _ptrRTCPData; | 1614 length = _ptrRTCPBlockEnd - _ptrRTCPData; |
1606 | 1615 |
1607 _packetType = RTCPPacketTypes::kApp; | 1616 _packetType = RTCPPacketTypes::kApp; |
1608 | 1617 |
1609 _packet.APP.SubType = header.IC; | 1618 _packet.APP.SubType = header.count_or_format; |
1610 _packet.APP.Name = name; | 1619 _packet.APP.Name = name; |
1611 | 1620 |
1612 _state = ParseState::State_AppItem; | 1621 _state = ParseState::State_AppItem; |
1613 return true; | 1622 return true; |
1614 } | 1623 } |
1615 | 1624 |
1616 bool | 1625 bool |
1617 RTCPUtility::RTCPParserV2::ParseAPPItem() | 1626 RTCPUtility::RTCPParserV2::ParseAPPItem() |
1618 { | 1627 { |
1619 const ptrdiff_t length = _ptrRTCPBlockEnd - _ptrRTCPData; | 1628 const ptrdiff_t length = _ptrRTCPBlockEnd - _ptrRTCPData; |
(...skipping 24 matching lines...) Expand all Loading... | |
1644 size_t rtcpDataLength) | 1653 size_t rtcpDataLength) |
1645 : _ptrBegin(rtcpData), | 1654 : _ptrBegin(rtcpData), |
1646 _ptrEnd(rtcpData + rtcpDataLength), | 1655 _ptrEnd(rtcpData + rtcpDataLength), |
1647 _ptrBlock(NULL) { | 1656 _ptrBlock(NULL) { |
1648 memset(&_header, 0, sizeof(_header)); | 1657 memset(&_header, 0, sizeof(_header)); |
1649 } | 1658 } |
1650 | 1659 |
1651 RTCPUtility::RTCPPacketIterator::~RTCPPacketIterator() { | 1660 RTCPUtility::RTCPPacketIterator::~RTCPPacketIterator() { |
1652 } | 1661 } |
1653 | 1662 |
1654 const RTCPUtility::RTCPCommonHeader* | 1663 const RTCPUtility::RtcpCommonHeader* RTCPUtility::RTCPPacketIterator::Begin() { |
1655 RTCPUtility::RTCPPacketIterator::Begin() | |
1656 { | |
1657 _ptrBlock = _ptrBegin; | 1664 _ptrBlock = _ptrBegin; |
1658 | 1665 |
1659 return Iterate(); | 1666 return Iterate(); |
1660 } | 1667 } |
1661 | 1668 |
1662 const RTCPUtility::RTCPCommonHeader* | 1669 const RTCPUtility::RtcpCommonHeader* |
1663 RTCPUtility::RTCPPacketIterator::Iterate() | 1670 RTCPUtility::RTCPPacketIterator::Iterate() { |
1664 { | 1671 if ((_ptrEnd <= _ptrBlock) || |
1665 const bool success = RTCPParseCommonHeader(_ptrBlock, _ptrEnd, _header); | 1672 !RtcpParseCommonHeader(_ptrBlock, _ptrEnd - _ptrBlock, &_header)) { |
1666 if (!success) | 1673 _ptrBlock = nullptr; |
1667 { | 1674 return nullptr; |
1668 _ptrBlock = NULL; | 1675 } |
1669 return NULL; | 1676 _ptrBlock += _header.BlockSize(); |
1670 } | |
1671 _ptrBlock += _header.LengthInOctets; | |
1672 | 1677 |
1673 if (_ptrBlock > _ptrEnd) | 1678 if (_ptrBlock > _ptrEnd) { |
1674 { | 1679 _ptrBlock = nullptr; |
1675 _ptrBlock = NULL; | 1680 return nullptr; |
1676 return NULL; | 1681 } |
1677 } | |
1678 | 1682 |
1679 return &_header; | 1683 return &_header; |
1680 } | 1684 } |
1681 | 1685 |
1682 const RTCPUtility::RTCPCommonHeader* | 1686 const RTCPUtility::RtcpCommonHeader* |
1683 RTCPUtility::RTCPPacketIterator::Current() | 1687 RTCPUtility::RTCPPacketIterator::Current() { |
1684 { | |
1685 if (!_ptrBlock) | 1688 if (!_ptrBlock) |
1686 { | 1689 { |
1687 return NULL; | 1690 return NULL; |
1688 } | 1691 } |
1689 | 1692 |
1690 return &_header; | 1693 return &_header; |
1691 } | 1694 } |
1692 } // namespace webrtc | 1695 } // namespace webrtc |
OLD | NEW |