blob: 5c32fed1f2b2daab6f263a0bbae52eefc0ebaa4b [file] [log] [blame]
asapersson@webrtc.org0f2809a2014-02-21 08:14:451/*
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 04:47:3111#include "test/rtcp_packet_parser.h"
Yves Gerey3e707812018-11-28 15:47:4912
13#include "modules/rtp_rtcp/source/rtcp_packet/psfb.h"
14#include "modules/rtp_rtcp/source/rtcp_packet/rtpfb.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3115#include "rtc_base/checks.h"
16#include "rtc_base/logging.h"
asapersson@webrtc.org0f2809a2014-02-21 08:14:4517
18namespace webrtc {
19namespace test {
20
Danil Chapovalovba6f7be2016-09-02 16:29:1021RtcpPacketParser::RtcpPacketParser() = default;
22RtcpPacketParser::~RtcpPacketParser() = default;
Erik Språng242e22b2015-05-11 08:17:4323
Danil Chapovalovba6f7be2016-09-02 16:29:1024bool RtcpPacketParser::Parse(const void* data, size_t length) {
25 const uint8_t* const buffer = static_cast<const uint8_t*>(data);
26 const uint8_t* const buffer_end = buffer + length;
27 rtcp::CommonHeader header;
28 for (const uint8_t* next_packet = buffer; next_packet != buffer_end;
29 next_packet = header.NextPacket()) {
30 RTC_DCHECK_GT(buffer_end - next_packet, 0);
31 if (!header.Parse(next_packet, buffer_end - next_packet)) {
Mirko Bonadei675513b2017-11-09 10:09:2532 RTC_LOG(LS_WARNING)
Danil Chapovalovba6f7be2016-09-02 16:29:1033 << "Invalid rtcp header or unaligned rtcp packet at position "
34 << (next_packet - buffer);
35 return false;
36 }
37 switch (header.type()) {
38 case rtcp::App::kPacketType:
39 app_.Parse(header);
asapersson@webrtc.orga8260062014-05-20 09:53:5140 break;
Danil Chapovalovba6f7be2016-09-02 16:29:1041 case rtcp::Bye::kPacketType:
danilchap3dc929e2016-11-02 15:21:5942 bye_.Parse(header, &sender_ssrc_);
asapersson@webrtc.orga8260062014-05-20 09:53:5143 break;
Danil Chapovalovba6f7be2016-09-02 16:29:1044 case rtcp::ExtendedReports::kPacketType:
danilchap3dc929e2016-11-02 15:21:5945 xr_.Parse(header, &sender_ssrc_);
asapersson@webrtc.orga8260062014-05-20 09:53:5146 break;
Danil Chapovalovba6f7be2016-09-02 16:29:1047 case rtcp::ExtendedJitterReport::kPacketType:
48 ij_.Parse(header);
asapersson@webrtc.org4b12d402014-06-16 14:09:2849 break;
Danil Chapovalovba6f7be2016-09-02 16:29:1050 case rtcp::Psfb::kPacketType:
51 switch (header.fmt()) {
52 case rtcp::Fir::kFeedbackMessageType:
danilchap3dc929e2016-11-02 15:21:5953 fir_.Parse(header, &sender_ssrc_);
Danil Chapovalovba6f7be2016-09-02 16:29:1054 break;
55 case rtcp::Pli::kFeedbackMessageType:
danilchap3dc929e2016-11-02 15:21:5956 pli_.Parse(header, &sender_ssrc_);
Danil Chapovalovba6f7be2016-09-02 16:29:1057 break;
58 case rtcp::Remb::kFeedbackMessageType:
danilchap3dc929e2016-11-02 15:21:5959 remb_.Parse(header, &sender_ssrc_);
Danil Chapovalovba6f7be2016-09-02 16:29:1060 break;
Danil Chapovalovba6f7be2016-09-02 16:29:1061 default:
Mirko Bonadei675513b2017-11-09 10:09:2562 RTC_LOG(LS_WARNING)
63 << "Unknown rtcp payload specific feedback type "
64 << header.fmt();
Danil Chapovalovba6f7be2016-09-02 16:29:1065 break;
66 }
asapersson@webrtc.org4b12d402014-06-16 14:09:2867 break;
Danil Chapovalovba6f7be2016-09-02 16:29:1068 case rtcp::ReceiverReport::kPacketType:
danilchap3dc929e2016-11-02 15:21:5969 receiver_report_.Parse(header, &sender_ssrc_);
asapersson@webrtc.org4b12d402014-06-16 14:09:2870 break;
Danil Chapovalovba6f7be2016-09-02 16:29:1071 case rtcp::Rtpfb::kPacketType:
72 switch (header.fmt()) {
73 case rtcp::Nack::kFeedbackMessageType:
danilchap3dc929e2016-11-02 15:21:5974 nack_.Parse(header, &sender_ssrc_);
Danil Chapovalovba6f7be2016-09-02 16:29:1075 break;
76 case rtcp::RapidResyncRequest::kFeedbackMessageType:
danilchap3dc929e2016-11-02 15:21:5977 rrr_.Parse(header, &sender_ssrc_);
Danil Chapovalovba6f7be2016-09-02 16:29:1078 break;
79 case rtcp::Tmmbn::kFeedbackMessageType:
danilchap3dc929e2016-11-02 15:21:5980 tmmbn_.Parse(header, &sender_ssrc_);
Danil Chapovalovba6f7be2016-09-02 16:29:1081 break;
82 case rtcp::Tmmbr::kFeedbackMessageType:
danilchap3dc929e2016-11-02 15:21:5983 tmmbr_.Parse(header, &sender_ssrc_);
Danil Chapovalovba6f7be2016-09-02 16:29:1084 break;
85 case rtcp::TransportFeedback::kFeedbackMessageType:
danilchap3dc929e2016-11-02 15:21:5986 transport_feedback_.Parse(header, &sender_ssrc_);
Danil Chapovalovba6f7be2016-09-02 16:29:1087 break;
88 default:
Mirko Bonadei675513b2017-11-09 10:09:2589 RTC_LOG(LS_WARNING)
90 << "Unknown rtcp transport feedback type " << header.fmt();
Danil Chapovalovba6f7be2016-09-02 16:29:1091 break;
92 }
asapersson@webrtc.org4b12d402014-06-16 14:09:2893 break;
Danil Chapovalovba6f7be2016-09-02 16:29:1094 case rtcp::Sdes::kPacketType:
95 sdes_.Parse(header);
asapersson@webrtc.org4b12d402014-06-16 14:09:2896 break;
Danil Chapovalovba6f7be2016-09-02 16:29:1097 case rtcp::SenderReport::kPacketType:
danilchap3dc929e2016-11-02 15:21:5998 sender_report_.Parse(header, &sender_ssrc_);
asapersson@webrtc.org3b84b3a2014-06-25 12:22:1799 break;
asapersson@webrtc.orga8260062014-05-20 09:53:51100 default:
Mirko Bonadei675513b2017-11-09 10:09:25101 RTC_LOG(LS_WARNING) << "Unknown rtcp packet type " << header.type();
asapersson@webrtc.orga8260062014-05-20 09:53:51102 break;
asapersson@webrtc.org0f2809a2014-02-21 08:14:45103 }
104 }
Danil Chapovalovba6f7be2016-09-02 16:29:10105 return true;
asapersson@webrtc.orga8260062014-05-20 09:53:51106}
107
asapersson@webrtc.org0f2809a2014-02-21 08:14:45108} // namespace test
109} // namespace webrtc