asapersson@webrtc.org | 0f2809a | 2014-02-21 08:14:45 +0000 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "test/rtcp_packet_parser.h" |
| 12 | #include "rtc_base/checks.h" |
| 13 | #include "rtc_base/logging.h" |
asapersson@webrtc.org | 0f2809a | 2014-02-21 08:14:45 +0000 | [diff] [blame] | 14 | |
| 15 | namespace webrtc { |
| 16 | namespace test { |
| 17 | |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 18 | RtcpPacketParser::RtcpPacketParser() = default; |
| 19 | RtcpPacketParser::~RtcpPacketParser() = default; |
Erik Språng | 242e22b | 2015-05-11 10:17:43 +0200 | [diff] [blame] | 20 | |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 21 | bool 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 Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 29 | RTC_LOG(LS_WARNING) |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 30 | << "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.org | a826006 | 2014-05-20 09:53:51 +0000 | [diff] [blame] | 37 | break; |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 38 | case rtcp::Bye::kPacketType: |
danilchap | 3dc929e | 2016-11-02 08:21:59 -0700 | [diff] [blame] | 39 | bye_.Parse(header, &sender_ssrc_); |
asapersson@webrtc.org | a826006 | 2014-05-20 09:53:51 +0000 | [diff] [blame] | 40 | break; |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 41 | case rtcp::ExtendedReports::kPacketType: |
danilchap | 3dc929e | 2016-11-02 08:21:59 -0700 | [diff] [blame] | 42 | xr_.Parse(header, &sender_ssrc_); |
asapersson@webrtc.org | a826006 | 2014-05-20 09:53:51 +0000 | [diff] [blame] | 43 | break; |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 44 | case rtcp::ExtendedJitterReport::kPacketType: |
| 45 | ij_.Parse(header); |
asapersson@webrtc.org | 4b12d40 | 2014-06-16 14:09:28 +0000 | [diff] [blame] | 46 | break; |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 47 | case rtcp::Psfb::kPacketType: |
| 48 | switch (header.fmt()) { |
| 49 | case rtcp::Fir::kFeedbackMessageType: |
danilchap | 3dc929e | 2016-11-02 08:21:59 -0700 | [diff] [blame] | 50 | fir_.Parse(header, &sender_ssrc_); |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 51 | break; |
| 52 | case rtcp::Pli::kFeedbackMessageType: |
danilchap | 3dc929e | 2016-11-02 08:21:59 -0700 | [diff] [blame] | 53 | pli_.Parse(header, &sender_ssrc_); |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 54 | break; |
| 55 | case rtcp::Remb::kFeedbackMessageType: |
danilchap | 3dc929e | 2016-11-02 08:21:59 -0700 | [diff] [blame] | 56 | remb_.Parse(header, &sender_ssrc_); |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 57 | break; |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 58 | default: |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 59 | RTC_LOG(LS_WARNING) |
| 60 | << "Unknown rtcp payload specific feedback type " |
| 61 | << header.fmt(); |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 62 | break; |
| 63 | } |
asapersson@webrtc.org | 4b12d40 | 2014-06-16 14:09:28 +0000 | [diff] [blame] | 64 | break; |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 65 | case rtcp::ReceiverReport::kPacketType: |
danilchap | 3dc929e | 2016-11-02 08:21:59 -0700 | [diff] [blame] | 66 | receiver_report_.Parse(header, &sender_ssrc_); |
asapersson@webrtc.org | 4b12d40 | 2014-06-16 14:09:28 +0000 | [diff] [blame] | 67 | break; |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 68 | case rtcp::Rtpfb::kPacketType: |
| 69 | switch (header.fmt()) { |
| 70 | case rtcp::Nack::kFeedbackMessageType: |
danilchap | 3dc929e | 2016-11-02 08:21:59 -0700 | [diff] [blame] | 71 | nack_.Parse(header, &sender_ssrc_); |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 72 | break; |
| 73 | case rtcp::RapidResyncRequest::kFeedbackMessageType: |
danilchap | 3dc929e | 2016-11-02 08:21:59 -0700 | [diff] [blame] | 74 | rrr_.Parse(header, &sender_ssrc_); |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 75 | break; |
| 76 | case rtcp::Tmmbn::kFeedbackMessageType: |
danilchap | 3dc929e | 2016-11-02 08:21:59 -0700 | [diff] [blame] | 77 | tmmbn_.Parse(header, &sender_ssrc_); |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 78 | break; |
| 79 | case rtcp::Tmmbr::kFeedbackMessageType: |
danilchap | 3dc929e | 2016-11-02 08:21:59 -0700 | [diff] [blame] | 80 | tmmbr_.Parse(header, &sender_ssrc_); |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 81 | break; |
| 82 | case rtcp::TransportFeedback::kFeedbackMessageType: |
danilchap | 3dc929e | 2016-11-02 08:21:59 -0700 | [diff] [blame] | 83 | transport_feedback_.Parse(header, &sender_ssrc_); |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 84 | break; |
| 85 | default: |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 86 | RTC_LOG(LS_WARNING) |
| 87 | << "Unknown rtcp transport feedback type " << header.fmt(); |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 88 | break; |
| 89 | } |
asapersson@webrtc.org | 4b12d40 | 2014-06-16 14:09:28 +0000 | [diff] [blame] | 90 | break; |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 91 | case rtcp::Sdes::kPacketType: |
| 92 | sdes_.Parse(header); |
asapersson@webrtc.org | 4b12d40 | 2014-06-16 14:09:28 +0000 | [diff] [blame] | 93 | break; |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 94 | case rtcp::SenderReport::kPacketType: |
danilchap | 3dc929e | 2016-11-02 08:21:59 -0700 | [diff] [blame] | 95 | sender_report_.Parse(header, &sender_ssrc_); |
asapersson@webrtc.org | 3b84b3a | 2014-06-25 12:22:17 +0000 | [diff] [blame] | 96 | break; |
asapersson@webrtc.org | a826006 | 2014-05-20 09:53:51 +0000 | [diff] [blame] | 97 | default: |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 98 | RTC_LOG(LS_WARNING) << "Unknown rtcp packet type " << header.type(); |
asapersson@webrtc.org | a826006 | 2014-05-20 09:53:51 +0000 | [diff] [blame] | 99 | break; |
asapersson@webrtc.org | 0f2809a | 2014-02-21 08:14:45 +0000 | [diff] [blame] | 100 | } |
| 101 | } |
Danil Chapovalov | ba6f7be | 2016-09-02 18:29:10 +0200 | [diff] [blame] | 102 | return true; |
asapersson@webrtc.org | a826006 | 2014-05-20 09:53:51 +0000 | [diff] [blame] | 103 | } |
| 104 | |
asapersson@webrtc.org | 0f2809a | 2014-02-21 08:14:45 +0000 | [diff] [blame] | 105 | } // namespace test |
| 106 | } // namespace webrtc |