1663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org/* 2663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 3663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org * 4663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org * Use of this source code is governed by a BSD-style license 5663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org * that can be found in the LICENSE file in the root of the source 6663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org * tree. An additional intellectual property rights grant can be found 7663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org * in the file PATENTS. All contributing project authors may 8663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org * be found in the AUTHORS file in the root of the source tree. 9663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org */ 10663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org 11663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org#include "webrtc/test/rtcp_packet_parser.h" 12663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org 13663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.orgnamespace webrtc { 14663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.orgnamespace test { 15663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org 16663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.orgRtcpPacketParser::RtcpPacketParser() {} 17663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org 18663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.orgRtcpPacketParser::~RtcpPacketParser() {} 19663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org 20663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.orgvoid RtcpPacketParser::Parse(const void *data, int len) { 21663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org const uint8_t* packet = static_cast<const uint8_t*>(data); 22663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org RTCPUtility::RTCPParserV2 parser(packet, len, true); 23663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org for (RTCPUtility::RTCPPacketTypes type = parser.Begin(); 24663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org type != RTCPUtility::kRtcpNotValidCode; 25663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org type = parser.Iterate()) { 26b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org switch (type) { 27b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org case RTCPUtility::kRtcpSrCode: 28b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org sender_report_.Set(parser.Packet().SR); 29b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org break; 30b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org case RTCPUtility::kRtcpRrCode: 31b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org receiver_report_.Set(parser.Packet().RR); 32b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org break; 33b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org case RTCPUtility::kRtcpReportBlockItemCode: 34b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org report_block_.Set(parser.Packet().ReportBlockItem); 35b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org ++report_blocks_per_ssrc_[parser.Packet().ReportBlockItem.SSRC]; 36b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org break; 37847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org case RTCPUtility::kRtcpSdesCode: 38847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org sdes_.Set(); 39847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org break; 40847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org case RTCPUtility::kRtcpSdesChunkCode: 41847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org sdes_chunk_.Set(parser.Packet().CName); 42847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org break; 43847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org case RTCPUtility::kRtcpByeCode: 44847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org bye_.Set(parser.Packet().BYE); 45847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org break; 46847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org case RTCPUtility::kRtcpAppCode: 47847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org app_.Set(parser.Packet().APP); 48847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org break; 49847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org case RTCPUtility::kRtcpAppItemCode: 50847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org app_item_.Set(parser.Packet().APP); 51847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org break; 52847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org case RTCPUtility::kRtcpExtendedIjCode: 53847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org ij_.Set(); 54847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org break; 55847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org case RTCPUtility::kRtcpExtendedIjItemCode: 56847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org ij_item_.Set(parser.Packet().ExtendedJitterReportItem); 57847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org break; 58847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org case RTCPUtility::kRtcpPsfbPliCode: 59847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org pli_.Set(parser.Packet().PLI); 60847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org break; 61847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org case RTCPUtility::kRtcpPsfbSliCode: 62847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org sli_.Set(parser.Packet().SLI); 63847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org break; 64847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org case RTCPUtility::kRtcpPsfbSliItemCode: 65847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org sli_item_.Set(parser.Packet().SLIItem); 66847dfa535730a30d57cf26d788d31070b70a02afasapersson@webrtc.org break; 67b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org case RTCPUtility::kRtcpPsfbRpsiCode: 68b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org rpsi_.Set(parser.Packet().RPSI); 69b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org break; 70b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org case RTCPUtility::kRtcpPsfbFirCode: 71b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org fir_.Set(parser.Packet().FIR); 72b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org break; 73b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org case RTCPUtility::kRtcpPsfbFirItemCode: 74b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org fir_item_.Set(parser.Packet().FIRItem); 75b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org break; 76b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org case RTCPUtility::kRtcpRtpfbNackCode: 77b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org nack_.Set(parser.Packet().NACK); 78b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org nack_item_.Clear(); 79b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org break; 80b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org case RTCPUtility::kRtcpRtpfbNackItemCode: 81b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org nack_item_.Set(parser.Packet().NACKItem); 82b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org break; 837eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org case RTCPUtility::kRtcpPsfbAppCode: 847eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org psfb_app_.Set(parser.Packet().PSFBAPP); 857eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org break; 867eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org case RTCPUtility::kRtcpPsfbRembItemCode: 877eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org remb_item_.Set(parser.Packet().REMBItem); 887eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org break; 897eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org case RTCPUtility::kRtcpRtpfbTmmbrCode: 907eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org tmmbr_.Set(parser.Packet().TMMBR); 917eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org break; 927eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org case RTCPUtility::kRtcpRtpfbTmmbrItemCode: 937eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org tmmbr_item_.Set(parser.Packet().TMMBRItem); 947eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org break; 957eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org case RTCPUtility::kRtcpRtpfbTmmbnCode: 967eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org tmmbn_.Set(parser.Packet().TMMBN); 977eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org tmmbn_items_.Clear(); 987eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org break; 997eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org case RTCPUtility::kRtcpRtpfbTmmbnItemCode: 1007eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org tmmbn_items_.Set(parser.Packet().TMMBNItem); 1017eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org break; 1027eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org case RTCPUtility::kRtcpXrHeaderCode: 1037eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org xr_header_.Set(parser.Packet().XR); 1047eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org dlrr_items_.Clear(); 1057eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org break; 1067eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org case RTCPUtility::kRtcpXrReceiverReferenceTimeCode: 1077eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org rrtr_.Set(parser.Packet().XRReceiverReferenceTimeItem); 1087eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org break; 1097eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org case RTCPUtility::kRtcpXrDlrrReportBlockCode: 1107eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org dlrr_.Set(); 1117eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org break; 1127eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org case RTCPUtility::kRtcpXrDlrrReportBlockItemCode: 1137eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org dlrr_items_.Set(parser.Packet().XRDLRRReportBlockItem); 1147eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org break; 1157eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org case RTCPUtility::kRtcpXrVoipMetricCode: 1167eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org voip_metric_.Set(parser.Packet().XRVOIPMetricItem); 1177eec1dd08bce4d7a30d090c67a240c274b95755casapersson@webrtc.org break; 118b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org default: 119b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org break; 120663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org } 121663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org } 122663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org} 123b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org 124b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.orguint64_t Rpsi::PictureId() const { 125b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org assert(num_packets_ > 0); 126b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org uint16_t num_bytes = rpsi_.NumberOfValidBits / 8; 127b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org assert(num_bytes > 0); 128b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org uint64_t picture_id = 0; 129b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org for (uint16_t i = 0; i < num_bytes - 1; ++i) { 130b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org picture_id += (rpsi_.NativeBitString[i] & 0x7f); 131b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org picture_id <<= 7; 132b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org } 133b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org picture_id += (rpsi_.NativeBitString[num_bytes - 1] & 0x7f); 134b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org return picture_id; 135b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org} 136b5b864863573bcf0a341e6462fe697450c64a873asapersson@webrtc.org 137663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org} // namespace test 138663ba07859170b985f47fb4ce8fd9af947e440efasapersson@webrtc.org} // namespace webrtc 139