eladalon | a52722f | 2017-06-26 11:23:54 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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 "call/rtp_rtcp_demuxer_helper.h" |
eladalon | a52722f | 2017-06-26 11:23:54 -0700 | [diff] [blame] | 12 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 13 | #include "modules/rtp_rtcp/source/byte_io.h" |
| 14 | #include "modules/rtp_rtcp/source/rtcp_packet/bye.h" |
| 15 | #include "modules/rtp_rtcp/source/rtcp_packet/common_header.h" |
| 16 | #include "modules/rtp_rtcp/source/rtcp_packet/extended_reports.h" |
| 17 | #include "modules/rtp_rtcp/source/rtcp_packet/psfb.h" |
| 18 | #include "modules/rtp_rtcp/source/rtcp_packet/receiver_report.h" |
| 19 | #include "modules/rtp_rtcp/source/rtcp_packet/rtpfb.h" |
| 20 | #include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h" |
eladalon | a52722f | 2017-06-26 11:23:54 -0700 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 24 | absl::optional<uint32_t> ParseRtcpPacketSenderSsrc( |
eladalon | a52722f | 2017-06-26 11:23:54 -0700 | [diff] [blame] | 25 | rtc::ArrayView<const uint8_t> packet) { |
| 26 | rtcp::CommonHeader header; |
| 27 | for (const uint8_t* next_packet = packet.begin(); next_packet < packet.end(); |
| 28 | next_packet = header.NextPacket()) { |
| 29 | if (!header.Parse(next_packet, packet.end() - next_packet)) { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 30 | return absl::nullopt; |
eladalon | a52722f | 2017-06-26 11:23:54 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | switch (header.type()) { |
| 34 | case rtcp::Bye::kPacketType: |
| 35 | case rtcp::ExtendedReports::kPacketType: |
| 36 | case rtcp::Psfb::kPacketType: |
| 37 | case rtcp::ReceiverReport::kPacketType: |
| 38 | case rtcp::Rtpfb::kPacketType: |
| 39 | case rtcp::SenderReport::kPacketType: { |
| 40 | // Sender SSRC at the beginning of the RTCP payload. |
| 41 | if (header.payload_size_bytes() >= sizeof(uint32_t)) { |
| 42 | const uint32_t ssrc_sender = |
| 43 | ByteReader<uint32_t>::ReadBigEndian(header.payload()); |
Oskar Sundbom | fedc00c | 2017-11-16 10:55:08 +0100 | [diff] [blame] | 44 | return ssrc_sender; |
eladalon | a52722f | 2017-06-26 11:23:54 -0700 | [diff] [blame] | 45 | } else { |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 46 | return absl::nullopt; |
eladalon | a52722f | 2017-06-26 11:23:54 -0700 | [diff] [blame] | 47 | } |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
Danil Chapovalov | b9b146c | 2018-06-15 12:28:07 +0200 | [diff] [blame] | 52 | return absl::nullopt; |
eladalon | a52722f | 2017-06-26 11:23:54 -0700 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | } // namespace webrtc |