blob: 9ae8543d7f0fb7a9dfbf0dcfcbc854c18d466a6e [file] [log] [blame]
asapersson@webrtc.org0f2809a2014-02-21 08:14:45 +00001/*
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
13namespace webrtc {
14namespace test {
15
16RtcpPacketParser::RtcpPacketParser() {}
17
18RtcpPacketParser::~RtcpPacketParser() {}
19
20void RtcpPacketParser::Parse(const void *data, int len) {
21 const uint8_t* packet = static_cast<const uint8_t*>(data);
22 RTCPUtility::RTCPParserV2 parser(packet, len, true);
23 for (RTCPUtility::RTCPPacketTypes type = parser.Begin();
24 type != RTCPUtility::kRtcpNotValidCode;
25 type = parser.Iterate()) {
asapersson@webrtc.orga8260062014-05-20 09:53:51 +000026 switch (type) {
27 case RTCPUtility::kRtcpSrCode:
28 sender_report_.Set(parser.Packet().SR);
29 break;
30 case RTCPUtility::kRtcpRrCode:
31 receiver_report_.Set(parser.Packet().RR);
32 break;
33 case RTCPUtility::kRtcpByeCode:
34 bye_.Set(parser.Packet().BYE);
35 break;
36 case RTCPUtility::kRtcpReportBlockItemCode:
37 report_block_.Set(parser.Packet().ReportBlockItem);
38 ++report_blocks_per_ssrc_[parser.Packet().ReportBlockItem.SSRC];
39 break;
40 case RTCPUtility::kRtcpPsfbRpsiCode:
41 rpsi_.Set(parser.Packet().RPSI);
42 break;
43 case RTCPUtility::kRtcpPsfbFirCode:
44 fir_.Set(parser.Packet().FIR);
45 break;
46 case RTCPUtility::kRtcpPsfbFirItemCode:
47 fir_item_.Set(parser.Packet().FIRItem);
48 break;
49 case RTCPUtility::kRtcpRtpfbNackCode:
50 nack_.Set(parser.Packet().NACK);
51 nack_item_.Clear();
52 break;
53 case RTCPUtility::kRtcpRtpfbNackItemCode:
54 nack_item_.Set(parser.Packet().NACKItem);
55 break;
56 default:
57 break;
asapersson@webrtc.org0f2809a2014-02-21 08:14:45 +000058 }
59 }
60}
asapersson@webrtc.orga8260062014-05-20 09:53:51 +000061
62uint64_t Rpsi::PictureId() const {
63 assert(num_packets_ > 0);
64 uint16_t num_bytes = rpsi_.NumberOfValidBits / 8;
65 assert(num_bytes > 0);
66 uint64_t picture_id = 0;
67 for (uint16_t i = 0; i < num_bytes - 1; ++i) {
68 picture_id += (rpsi_.NativeBitString[i] & 0x7f);
69 picture_id <<= 7;
70 }
71 picture_id += (rpsi_.NativeBitString[num_bytes - 1] & 0x7f);
72 return picture_id;
73}
74
asapersson@webrtc.org0f2809a2014-02-21 08:14:45 +000075} // namespace test
76} // namespace webrtc