blob: 2f9658a9e592a26829a3b15c7c2a82252d3d6099 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "test/rtcp_packet_parser.h"
12#include "rtc_base/checks.h"
13#include "rtc_base/logging.h"
asapersson@webrtc.org0f2809a2014-02-21 08:14:45 +000014
15namespace webrtc {
16namespace test {
17
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020018RtcpPacketParser::RtcpPacketParser() = default;
19RtcpPacketParser::~RtcpPacketParser() = default;
Erik Språng242e22b2015-05-11 10:17:43 +020020
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020021bool RtcpPacketParser::Parse(const void* data, size_t length) {
22 const uint8_t* const buffer = static_cast<const uint8_t*>(data);
23 const uint8_t* const buffer_end = buffer + length;
24 rtcp::CommonHeader header;
25 for (const uint8_t* next_packet = buffer; next_packet != buffer_end;
26 next_packet = header.NextPacket()) {
27 RTC_DCHECK_GT(buffer_end - next_packet, 0);
28 if (!header.Parse(next_packet, buffer_end - next_packet)) {
Mirko Bonadei675513b2017-11-09 11:09:25 +010029 RTC_LOG(LS_WARNING)
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020030 << "Invalid rtcp header or unaligned rtcp packet at position "
31 << (next_packet - buffer);
32 return false;
33 }
34 switch (header.type()) {
35 case rtcp::App::kPacketType:
36 app_.Parse(header);
asapersson@webrtc.orga8260062014-05-20 09:53:51 +000037 break;
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020038 case rtcp::Bye::kPacketType:
danilchap3dc929e2016-11-02 08:21:59 -070039 bye_.Parse(header, &sender_ssrc_);
asapersson@webrtc.orga8260062014-05-20 09:53:51 +000040 break;
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020041 case rtcp::ExtendedReports::kPacketType:
danilchap3dc929e2016-11-02 08:21:59 -070042 xr_.Parse(header, &sender_ssrc_);
asapersson@webrtc.orga8260062014-05-20 09:53:51 +000043 break;
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020044 case rtcp::ExtendedJitterReport::kPacketType:
45 ij_.Parse(header);
asapersson@webrtc.org4b12d402014-06-16 14:09:28 +000046 break;
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020047 case rtcp::Psfb::kPacketType:
48 switch (header.fmt()) {
49 case rtcp::Fir::kFeedbackMessageType:
danilchap3dc929e2016-11-02 08:21:59 -070050 fir_.Parse(header, &sender_ssrc_);
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020051 break;
52 case rtcp::Pli::kFeedbackMessageType:
danilchap3dc929e2016-11-02 08:21:59 -070053 pli_.Parse(header, &sender_ssrc_);
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020054 break;
55 case rtcp::Remb::kFeedbackMessageType:
danilchap3dc929e2016-11-02 08:21:59 -070056 remb_.Parse(header, &sender_ssrc_);
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020057 break;
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020058 default:
Mirko Bonadei675513b2017-11-09 11:09:25 +010059 RTC_LOG(LS_WARNING)
60 << "Unknown rtcp payload specific feedback type "
61 << header.fmt();
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020062 break;
63 }
asapersson@webrtc.org4b12d402014-06-16 14:09:28 +000064 break;
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020065 case rtcp::ReceiverReport::kPacketType:
danilchap3dc929e2016-11-02 08:21:59 -070066 receiver_report_.Parse(header, &sender_ssrc_);
asapersson@webrtc.org4b12d402014-06-16 14:09:28 +000067 break;
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020068 case rtcp::Rtpfb::kPacketType:
69 switch (header.fmt()) {
70 case rtcp::Nack::kFeedbackMessageType:
danilchap3dc929e2016-11-02 08:21:59 -070071 nack_.Parse(header, &sender_ssrc_);
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020072 break;
73 case rtcp::RapidResyncRequest::kFeedbackMessageType:
danilchap3dc929e2016-11-02 08:21:59 -070074 rrr_.Parse(header, &sender_ssrc_);
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020075 break;
76 case rtcp::Tmmbn::kFeedbackMessageType:
danilchap3dc929e2016-11-02 08:21:59 -070077 tmmbn_.Parse(header, &sender_ssrc_);
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020078 break;
79 case rtcp::Tmmbr::kFeedbackMessageType:
danilchap3dc929e2016-11-02 08:21:59 -070080 tmmbr_.Parse(header, &sender_ssrc_);
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020081 break;
82 case rtcp::TransportFeedback::kFeedbackMessageType:
danilchap3dc929e2016-11-02 08:21:59 -070083 transport_feedback_.Parse(header, &sender_ssrc_);
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020084 break;
85 default:
Mirko Bonadei675513b2017-11-09 11:09:25 +010086 RTC_LOG(LS_WARNING)
87 << "Unknown rtcp transport feedback type " << header.fmt();
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020088 break;
89 }
asapersson@webrtc.org4b12d402014-06-16 14:09:28 +000090 break;
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020091 case rtcp::Sdes::kPacketType:
92 sdes_.Parse(header);
asapersson@webrtc.org4b12d402014-06-16 14:09:28 +000093 break;
Danil Chapovalovba6f7be2016-09-02 18:29:10 +020094 case rtcp::SenderReport::kPacketType:
danilchap3dc929e2016-11-02 08:21:59 -070095 sender_report_.Parse(header, &sender_ssrc_);
asapersson@webrtc.org3b84b3a2014-06-25 12:22:17 +000096 break;
asapersson@webrtc.orga8260062014-05-20 09:53:51 +000097 default:
Mirko Bonadei675513b2017-11-09 11:09:25 +010098 RTC_LOG(LS_WARNING) << "Unknown rtcp packet type " << header.type();
asapersson@webrtc.orga8260062014-05-20 09:53:51 +000099 break;
asapersson@webrtc.org0f2809a2014-02-21 08:14:45 +0000100 }
101 }
Danil Chapovalovba6f7be2016-09-02 18:29:10 +0200102 return true;
asapersson@webrtc.orga8260062014-05-20 09:53:51 +0000103}
104
asapersson@webrtc.org0f2809a2014-02-21 08:14:45 +0000105} // namespace test
106} // namespace webrtc