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 if (size_bytes < RtcpCommonHeader::kHeaderSizeBytes) { |
| 470 LOG(LS_WARNING) << "Too little data (" << size_bytes << " byte" |
| 471 << (size_bytes != 1 ? "s" : "") |
| 472 << ") remaining in buffer to parse RTCP header (4 bytes)."; |
| 473 return false; |
| 474 } |
| 475 |
| 476 const uint8_t kRtcpVersion = 2; |
| 477 uint8_t version = packet[0] >> 6; |
| 478 if (version != kRtcpVersion) { |
| 479 LOG(LS_WARNING) << "Invalid RTCP header: Version must be " |
| 480 << static_cast<int>(kRtcpVersion) << " but was " |
| 481 << static_cast<int>(version); |
| 482 return false; |
| 483 } |
| 484 |
| 485 bool has_padding = (packet[0] & 0x20) != 0; |
| 486 uint8_t format = packet[0] & 0x1F; |
| 487 uint8_t packet_type = packet[1]; |
| 488 size_t packet_size_words = |
| 489 ByteReader<uint16_t>::ReadBigEndian(&packet[2]) + 1; |
| 490 |
| 491 if (size_bytes < packet_size_words * 4) { |
| 492 LOG(LS_WARNING) << "Buffer too small (" << size_bytes |
| 493 << " bytes) to fit an RtcpPacket of " << packet_size_words |
| 494 << " 32bit words."; |
| 495 return false; |
| 496 } |
| 497 |
| 498 size_t payload_size = packet_size_words * 4; |
| 499 size_t padding_bytes = 0; |
| 500 if (has_padding) { |
| 501 if (payload_size <= RtcpCommonHeader::kHeaderSizeBytes) { |
| 502 LOG(LS_WARNING) << "Invalid RTCP header: Padding bit set but 0 payload " |
| 503 "size specified."; |
| 504 return false; |
469 } | 505 } |
470 | 506 |
471 // 0 1 2 3 | 507 padding_bytes = packet[payload_size - 1]; |
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 | 508 if (RtcpCommonHeader::kHeaderSizeBytes + padding_bytes > payload_size) { |
473 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 509 LOG(LS_WARNING) << "Invalid RTCP header: Too many padding bytes (" |
474 // |V=2|P| IC | PT | length | | 510 << padding_bytes << ") for a packet size of " |
475 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 511 << payload_size << "bytes."; |
476 // | 512 return false; |
477 // Common header for all RTCP packets, 4 octets. | 513 } |
| 514 payload_size -= padding_bytes; |
| 515 } |
| 516 payload_size -= RtcpCommonHeader::kHeaderSizeBytes; |
478 | 517 |
479 if ((ptrDataEnd - ptrDataBegin) < 4) | 518 parsed_header->version = kRtcpVersion; |
480 { | 519 parsed_header->count_or_format = format; |
481 return false; | 520 parsed_header->packet_type = packet_type; |
482 } | 521 parsed_header->payload_size_bytes = payload_size; |
| 522 parsed_header->padding_bytes = padding_bytes; |
483 | 523 |
484 parsedHeader.V = ptrDataBegin[0] >> 6; | 524 return true; |
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 } | 525 } |
504 | 526 |
505 bool | 527 bool |
506 RTCPUtility::RTCPParserV2::ParseRR() | 528 RTCPUtility::RTCPParserV2::ParseRR() |
507 { | 529 { |
508 const ptrdiff_t length = _ptrRTCPBlockEnd - _ptrRTCPData; | 530 const ptrdiff_t length = _ptrRTCPBlockEnd - _ptrRTCPData; |
509 | 531 |
510 if (length < 8) | 532 if (length < 8) |
511 { | 533 { |
512 return false; | 534 return false; |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1130 _state = ParseState::State_TopLevel; | 1152 _state = ParseState::State_TopLevel; |
1131 EndCurrentBlock(); | 1153 EndCurrentBlock(); |
1132 return false; | 1154 return false; |
1133 } | 1155 } |
1134 // Skip block. | 1156 // Skip block. |
1135 _ptrRTCPData += kBlockLengthInBytes; | 1157 _ptrRTCPData += kBlockLengthInBytes; |
1136 _state = ParseState::State_XRItem; | 1158 _state = ParseState::State_XRItem; |
1137 return false; | 1159 return false; |
1138 } | 1160 } |
1139 | 1161 |
1140 bool | 1162 bool RTCPUtility::RTCPParserV2::ParseFBCommon(const RtcpCommonHeader& header) { |
1141 RTCPUtility::RTCPParserV2::ParseFBCommon(const RTCPCommonHeader& header) | 1163 assert((header.packet_type == PT_RTPFB) || |
1142 { | 1164 (header.packet_type == PT_PSFB)); // Parser logic check |
1143 assert((header.PT == PT_RTPFB) || (header.PT == PT_PSFB)); // Parser logic c
heck | |
1144 | 1165 |
1145 const ptrdiff_t length = _ptrRTCPBlockEnd - _ptrRTCPData; | 1166 const ptrdiff_t length = _ptrRTCPBlockEnd - _ptrRTCPData; |
1146 | 1167 |
1147 if (length < 12) // 4 * 3, RFC4585 section 6.1 | 1168 if (length < 12) // 4 * 3, RFC4585 section 6.1 |
1148 { | 1169 { |
1149 EndCurrentBlock(); | 1170 EndCurrentBlock(); |
1150 return false; | 1171 return false; |
1151 } | 1172 } |
1152 | 1173 |
1153 _ptrRTCPData += 4; // Skip RTCP header | 1174 _ptrRTCPData += 4; // Skip RTCP header |
1154 | 1175 |
1155 uint32_t senderSSRC = *_ptrRTCPData++ << 24; | 1176 uint32_t senderSSRC = *_ptrRTCPData++ << 24; |
1156 senderSSRC += *_ptrRTCPData++ << 16; | 1177 senderSSRC += *_ptrRTCPData++ << 16; |
1157 senderSSRC += *_ptrRTCPData++ << 8; | 1178 senderSSRC += *_ptrRTCPData++ << 8; |
1158 senderSSRC += *_ptrRTCPData++; | 1179 senderSSRC += *_ptrRTCPData++; |
1159 | 1180 |
1160 uint32_t mediaSSRC = *_ptrRTCPData++ << 24; | 1181 uint32_t mediaSSRC = *_ptrRTCPData++ << 24; |
1161 mediaSSRC += *_ptrRTCPData++ << 16; | 1182 mediaSSRC += *_ptrRTCPData++ << 16; |
1162 mediaSSRC += *_ptrRTCPData++ << 8; | 1183 mediaSSRC += *_ptrRTCPData++ << 8; |
1163 mediaSSRC += *_ptrRTCPData++; | 1184 mediaSSRC += *_ptrRTCPData++; |
1164 | 1185 |
1165 if (header.PT == PT_RTPFB) | 1186 if (header.packet_type == PT_RTPFB) { |
1166 { | |
1167 // Transport layer feedback | 1187 // Transport layer feedback |
1168 | 1188 |
1169 switch (header.IC) | 1189 switch (header.count_or_format) { |
1170 { | |
1171 case 1: | 1190 case 1: |
1172 { | 1191 { |
1173 // NACK | 1192 // NACK |
1174 _packetType = RTCPPacketTypes::kRtpfbNack; | 1193 _packetType = RTCPPacketTypes::kRtpfbNack; |
1175 _packet.NACK.SenderSSRC = senderSSRC; | 1194 _packet.NACK.SenderSSRC = senderSSRC; |
1176 _packet.NACK.MediaSSRC = mediaSSRC; | 1195 _packet.NACK.MediaSSRC = mediaSSRC; |
1177 | 1196 |
1178 _state = ParseState::State_RTPFB_NACKItem; | 1197 _state = ParseState::State_RTPFB_NACKItem; |
1179 | 1198 |
1180 return true; | 1199 return true; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1215 _packetType = RTCPPacketTypes::kRtpfbSrReq; | 1234 _packetType = RTCPPacketTypes::kRtpfbSrReq; |
1216 | 1235 |
1217 // Note: No state transition, SR REQ is empty! | 1236 // Note: No state transition, SR REQ is empty! |
1218 return true; | 1237 return true; |
1219 } | 1238 } |
1220 default: | 1239 default: |
1221 break; | 1240 break; |
1222 } | 1241 } |
1223 EndCurrentBlock(); | 1242 EndCurrentBlock(); |
1224 return false; | 1243 return false; |
1225 } | 1244 } else if (header.packet_type == PT_PSFB) { |
1226 else if (header.PT == PT_PSFB) | |
1227 { | |
1228 // Payload specific feedback | 1245 // Payload specific feedback |
1229 switch (header.IC) | 1246 switch (header.count_or_format) { |
1230 { | |
1231 case 1: | 1247 case 1: |
1232 // PLI | 1248 // PLI |
1233 _packetType = RTCPPacketTypes::kPsfbPli; | 1249 _packetType = RTCPPacketTypes::kPsfbPli; |
1234 _packet.PLI.SenderSSRC = senderSSRC; | 1250 _packet.PLI.SenderSSRC = senderSSRC; |
1235 _packet.PLI.MediaSSRC = mediaSSRC; | 1251 _packet.PLI.MediaSSRC = mediaSSRC; |
1236 | 1252 |
1237 // Note: No state transition, PLI FCI is empty! | 1253 // Note: No state transition, PLI FCI is empty! |
1238 return true; | 1254 return true; |
1239 case 2: | 1255 case 2: |
1240 // SLI | 1256 // SLI |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1572 _packet.FIRItem.SSRC = *_ptrRTCPData++ << 24; | 1588 _packet.FIRItem.SSRC = *_ptrRTCPData++ << 24; |
1573 _packet.FIRItem.SSRC += *_ptrRTCPData++ << 16; | 1589 _packet.FIRItem.SSRC += *_ptrRTCPData++ << 16; |
1574 _packet.FIRItem.SSRC += *_ptrRTCPData++ << 8; | 1590 _packet.FIRItem.SSRC += *_ptrRTCPData++ << 8; |
1575 _packet.FIRItem.SSRC += *_ptrRTCPData++; | 1591 _packet.FIRItem.SSRC += *_ptrRTCPData++; |
1576 | 1592 |
1577 _packet.FIRItem.CommandSequenceNumber = *_ptrRTCPData++; | 1593 _packet.FIRItem.CommandSequenceNumber = *_ptrRTCPData++; |
1578 _ptrRTCPData += 3; // Skip "Reserved" bytes. | 1594 _ptrRTCPData += 3; // Skip "Reserved" bytes. |
1579 return true; | 1595 return true; |
1580 } | 1596 } |
1581 | 1597 |
1582 bool | 1598 bool RTCPUtility::RTCPParserV2::ParseAPP(const RtcpCommonHeader& header) { |
1583 RTCPUtility::RTCPParserV2::ParseAPP( const RTCPCommonHeader& header) | |
1584 { | |
1585 ptrdiff_t length = _ptrRTCPBlockEnd - _ptrRTCPData; | 1599 ptrdiff_t length = _ptrRTCPBlockEnd - _ptrRTCPData; |
1586 | 1600 |
1587 if (length < 12) // 4 * 3, RFC 3550 6.7 APP: Application-Defined RTCP Packet | 1601 if (length < 12) // 4 * 3, RFC 3550 6.7 APP: Application-Defined RTCP Packet |
1588 { | 1602 { |
1589 EndCurrentBlock(); | 1603 EndCurrentBlock(); |
1590 return false; | 1604 return false; |
1591 } | 1605 } |
1592 | 1606 |
1593 _ptrRTCPData += 4; // Skip RTCP header | 1607 _ptrRTCPData += 4; // Skip RTCP header |
1594 | 1608 |
1595 uint32_t senderSSRC = *_ptrRTCPData++ << 24; | 1609 uint32_t senderSSRC = *_ptrRTCPData++ << 24; |
1596 senderSSRC += *_ptrRTCPData++ << 16; | 1610 senderSSRC += *_ptrRTCPData++ << 16; |
1597 senderSSRC += *_ptrRTCPData++ << 8; | 1611 senderSSRC += *_ptrRTCPData++ << 8; |
1598 senderSSRC += *_ptrRTCPData++; | 1612 senderSSRC += *_ptrRTCPData++; |
1599 | 1613 |
1600 uint32_t name = *_ptrRTCPData++ << 24; | 1614 uint32_t name = *_ptrRTCPData++ << 24; |
1601 name += *_ptrRTCPData++ << 16; | 1615 name += *_ptrRTCPData++ << 16; |
1602 name += *_ptrRTCPData++ << 8; | 1616 name += *_ptrRTCPData++ << 8; |
1603 name += *_ptrRTCPData++; | 1617 name += *_ptrRTCPData++; |
1604 | 1618 |
1605 length = _ptrRTCPBlockEnd - _ptrRTCPData; | 1619 length = _ptrRTCPBlockEnd - _ptrRTCPData; |
1606 | 1620 |
1607 _packetType = RTCPPacketTypes::kApp; | 1621 _packetType = RTCPPacketTypes::kApp; |
1608 | 1622 |
1609 _packet.APP.SubType = header.IC; | 1623 _packet.APP.SubType = header.count_or_format; |
1610 _packet.APP.Name = name; | 1624 _packet.APP.Name = name; |
1611 | 1625 |
1612 _state = ParseState::State_AppItem; | 1626 _state = ParseState::State_AppItem; |
1613 return true; | 1627 return true; |
1614 } | 1628 } |
1615 | 1629 |
1616 bool | 1630 bool |
1617 RTCPUtility::RTCPParserV2::ParseAPPItem() | 1631 RTCPUtility::RTCPParserV2::ParseAPPItem() |
1618 { | 1632 { |
1619 const ptrdiff_t length = _ptrRTCPBlockEnd - _ptrRTCPData; | 1633 const ptrdiff_t length = _ptrRTCPBlockEnd - _ptrRTCPData; |
(...skipping 24 matching lines...) Expand all Loading... |
1644 size_t rtcpDataLength) | 1658 size_t rtcpDataLength) |
1645 : _ptrBegin(rtcpData), | 1659 : _ptrBegin(rtcpData), |
1646 _ptrEnd(rtcpData + rtcpDataLength), | 1660 _ptrEnd(rtcpData + rtcpDataLength), |
1647 _ptrBlock(NULL) { | 1661 _ptrBlock(NULL) { |
1648 memset(&_header, 0, sizeof(_header)); | 1662 memset(&_header, 0, sizeof(_header)); |
1649 } | 1663 } |
1650 | 1664 |
1651 RTCPUtility::RTCPPacketIterator::~RTCPPacketIterator() { | 1665 RTCPUtility::RTCPPacketIterator::~RTCPPacketIterator() { |
1652 } | 1666 } |
1653 | 1667 |
1654 const RTCPUtility::RTCPCommonHeader* | 1668 const RTCPUtility::RtcpCommonHeader* RTCPUtility::RTCPPacketIterator::Begin() { |
1655 RTCPUtility::RTCPPacketIterator::Begin() | |
1656 { | |
1657 _ptrBlock = _ptrBegin; | 1669 _ptrBlock = _ptrBegin; |
1658 | 1670 |
1659 return Iterate(); | 1671 return Iterate(); |
1660 } | 1672 } |
1661 | 1673 |
1662 const RTCPUtility::RTCPCommonHeader* | 1674 const RTCPUtility::RtcpCommonHeader* |
1663 RTCPUtility::RTCPPacketIterator::Iterate() | 1675 RTCPUtility::RTCPPacketIterator::Iterate() { |
1664 { | 1676 if ((_ptrEnd <= _ptrBlock) || |
1665 const bool success = RTCPParseCommonHeader(_ptrBlock, _ptrEnd, _header); | 1677 !RtcpParseCommonHeader(_ptrBlock, _ptrEnd - _ptrBlock, &_header)) { |
1666 if (!success) | 1678 _ptrBlock = nullptr; |
1667 { | 1679 return nullptr; |
1668 _ptrBlock = NULL; | 1680 } |
1669 return NULL; | 1681 _ptrBlock += _header.BlockSize(); |
1670 } | |
1671 _ptrBlock += _header.LengthInOctets; | |
1672 | 1682 |
1673 if (_ptrBlock > _ptrEnd) | 1683 if (_ptrBlock > _ptrEnd) { |
1674 { | 1684 _ptrBlock = nullptr; |
1675 _ptrBlock = NULL; | 1685 return nullptr; |
1676 return NULL; | 1686 } |
1677 } | |
1678 | 1687 |
1679 return &_header; | 1688 return &_header; |
1680 } | 1689 } |
1681 | 1690 |
1682 const RTCPUtility::RTCPCommonHeader* | 1691 const RTCPUtility::RtcpCommonHeader* |
1683 RTCPUtility::RTCPPacketIterator::Current() | 1692 RTCPUtility::RTCPPacketIterator::Current() { |
1684 { | |
1685 if (!_ptrBlock) | 1693 if (!_ptrBlock) |
1686 { | 1694 { |
1687 return NULL; | 1695 return NULL; |
1688 } | 1696 } |
1689 | 1697 |
1690 return &_header; | 1698 return &_header; |
1691 } | 1699 } |
1692 } // namespace webrtc | 1700 } // namespace webrtc |
OLD | NEW |