1 /* 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "webrtc/test/rtcp_packet_parser.h" 12 13 #include "testing/gtest/include/gtest/gtest.h" 14 15 namespace webrtc { 16 namespace test { 17 18 using namespace RTCPUtility; 19 RtcpPacketParser()20RtcpPacketParser::RtcpPacketParser() {} 21 ~RtcpPacketParser()22RtcpPacketParser::~RtcpPacketParser() {} 23 Parse(const void * data,size_t len)24void RtcpPacketParser::Parse(const void *data, size_t len) { 25 const uint8_t* packet = static_cast<const uint8_t*>(data); 26 RTCPUtility::RTCPParserV2 parser(packet, len, true); 27 EXPECT_TRUE(parser.IsValid()); 28 for (RTCPUtility::RTCPPacketTypes type = parser.Begin(); 29 type != RTCPPacketTypes::kInvalid; type = parser.Iterate()) { 30 switch (type) { 31 case RTCPPacketTypes::kSr: 32 sender_report_.Set(parser.Packet().SR); 33 break; 34 case RTCPPacketTypes::kRr: 35 receiver_report_.Set(parser.Packet().RR); 36 break; 37 case RTCPPacketTypes::kReportBlockItem: 38 report_block_.Set(parser.Packet().ReportBlockItem); 39 ++report_blocks_per_ssrc_[parser.Packet().ReportBlockItem.SSRC]; 40 break; 41 case RTCPPacketTypes::kSdes: 42 sdes_.Set(); 43 break; 44 case RTCPPacketTypes::kSdesChunk: 45 sdes_chunk_.Set(parser.Packet().CName); 46 break; 47 case RTCPPacketTypes::kBye: 48 bye_.Set(parser.Packet().BYE); 49 break; 50 case RTCPPacketTypes::kApp: 51 app_.Set(parser.Packet().APP); 52 break; 53 case RTCPPacketTypes::kAppItem: 54 app_item_.Set(parser.Packet().APP); 55 break; 56 case RTCPPacketTypes::kExtendedIj: 57 ij_.Set(); 58 break; 59 case RTCPPacketTypes::kExtendedIjItem: 60 ij_item_.Set(parser.Packet().ExtendedJitterReportItem); 61 break; 62 case RTCPPacketTypes::kPsfbPli: 63 pli_.Set(parser.Packet().PLI); 64 break; 65 case RTCPPacketTypes::kPsfbSli: 66 sli_.Set(parser.Packet().SLI); 67 break; 68 case RTCPPacketTypes::kPsfbSliItem: 69 sli_item_.Set(parser.Packet().SLIItem); 70 break; 71 case RTCPPacketTypes::kPsfbRpsi: 72 rpsi_.Set(parser.Packet().RPSI); 73 break; 74 case RTCPPacketTypes::kPsfbFir: 75 fir_.Set(parser.Packet().FIR); 76 break; 77 case RTCPPacketTypes::kPsfbFirItem: 78 fir_item_.Set(parser.Packet().FIRItem); 79 break; 80 case RTCPPacketTypes::kRtpfbNack: 81 nack_.Set(parser.Packet().NACK); 82 nack_item_.Clear(); 83 break; 84 case RTCPPacketTypes::kRtpfbNackItem: 85 nack_item_.Set(parser.Packet().NACKItem); 86 break; 87 case RTCPPacketTypes::kPsfbApp: 88 psfb_app_.Set(parser.Packet().PSFBAPP); 89 break; 90 case RTCPPacketTypes::kPsfbRembItem: 91 remb_item_.Set(parser.Packet().REMBItem); 92 break; 93 case RTCPPacketTypes::kRtpfbTmmbr: 94 tmmbr_.Set(parser.Packet().TMMBR); 95 break; 96 case RTCPPacketTypes::kRtpfbTmmbrItem: 97 tmmbr_item_.Set(parser.Packet().TMMBRItem); 98 break; 99 case RTCPPacketTypes::kRtpfbTmmbn: 100 tmmbn_.Set(parser.Packet().TMMBN); 101 tmmbn_items_.Clear(); 102 break; 103 case RTCPPacketTypes::kRtpfbTmmbnItem: 104 tmmbn_items_.Set(parser.Packet().TMMBNItem); 105 break; 106 case RTCPPacketTypes::kXrHeader: 107 xr_header_.Set(parser.Packet().XR); 108 dlrr_items_.Clear(); 109 break; 110 case RTCPPacketTypes::kXrReceiverReferenceTime: 111 rrtr_.Set(parser.Packet().XRReceiverReferenceTimeItem); 112 break; 113 case RTCPPacketTypes::kXrDlrrReportBlock: 114 dlrr_.Set(); 115 break; 116 case RTCPPacketTypes::kXrDlrrReportBlockItem: 117 dlrr_items_.Set(parser.Packet().XRDLRRReportBlockItem); 118 break; 119 case RTCPPacketTypes::kXrVoipMetric: 120 voip_metric_.Set(parser.Packet().XRVOIPMetricItem); 121 break; 122 default: 123 break; 124 } 125 } 126 } 127 PictureId() const128uint64_t Rpsi::PictureId() const { 129 assert(num_packets_ > 0); 130 uint16_t num_bytes = rpsi_.NumberOfValidBits / 8; 131 assert(num_bytes > 0); 132 uint64_t picture_id = 0; 133 for (uint16_t i = 0; i < num_bytes - 1; ++i) { 134 picture_id += (rpsi_.NativeBitString[i] & 0x7f); 135 picture_id <<= 7; 136 } 137 picture_id += (rpsi_.NativeBitString[num_bytes - 1] & 0x7f); 138 return picture_id; 139 } 140 141 } // namespace test 142 } // namespace webrtc 143