danilchap | 0219c9b | 2015-11-18 05:56:53 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 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 | #ifndef MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_APP_H_ |
| 12 | #define MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_APP_H_ |
danilchap | 0219c9b | 2015-11-18 05:56:53 -0800 | [diff] [blame] | 13 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 14 | #include <stddef.h> |
| 15 | #include <stdint.h> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "modules/rtp_rtcp/source/rtcp_packet.h" |
| 18 | #include "rtc_base/buffer.h" |
danilchap | 0219c9b | 2015-11-18 05:56:53 -0800 | [diff] [blame] | 19 | |
| 20 | namespace webrtc { |
| 21 | namespace rtcp { |
danilchap | 2874ed5 | 2016-07-26 06:40:29 -0700 | [diff] [blame] | 22 | class CommonHeader; |
danilchap | 0219c9b | 2015-11-18 05:56:53 -0800 | [diff] [blame] | 23 | |
| 24 | class App : public RtcpPacket { |
| 25 | public: |
danilchap | 2874ed5 | 2016-07-26 06:40:29 -0700 | [diff] [blame] | 26 | static constexpr uint8_t kPacketType = 204; |
eladalon | 8fa21c4 | 2017-06-16 07:07:47 -0700 | [diff] [blame] | 27 | App(); |
| 28 | ~App() override; |
danilchap | 0219c9b | 2015-11-18 05:56:53 -0800 | [diff] [blame] | 29 | |
| 30 | // Parse assumes header is already parsed and validated. |
danilchap | 2874ed5 | 2016-07-26 06:40:29 -0700 | [diff] [blame] | 31 | bool Parse(const CommonHeader& packet); |
danilchap | 0219c9b | 2015-11-18 05:56:53 -0800 | [diff] [blame] | 32 | |
danilchap | 822a16f | 2016-09-27 09:27:47 -0700 | [diff] [blame] | 33 | void SetSsrc(uint32_t ssrc) { ssrc_ = ssrc; } |
| 34 | void SetSubType(uint8_t subtype); |
| 35 | void SetName(uint32_t name) { name_ = name; } |
| 36 | void SetData(const uint8_t* data, size_t data_length); |
danilchap | 0219c9b | 2015-11-18 05:56:53 -0800 | [diff] [blame] | 37 | |
| 38 | uint8_t sub_type() const { return sub_type_; } |
| 39 | uint32_t ssrc() const { return ssrc_; } |
| 40 | uint32_t name() const { return name_; } |
| 41 | size_t data_size() const { return data_.size(); } |
| 42 | const uint8_t* data() const { return data_.data(); } |
| 43 | |
eladalon | 8fa21c4 | 2017-06-16 07:07:47 -0700 | [diff] [blame] | 44 | size_t BlockLength() const override; |
| 45 | |
danilchap | 0219c9b | 2015-11-18 05:56:53 -0800 | [diff] [blame] | 46 | bool Create(uint8_t* packet, |
| 47 | size_t* index, |
| 48 | size_t max_length, |
Danil Chapovalov | 5c3cc41 | 2017-12-07 10:15:53 +0100 | [diff] [blame] | 49 | PacketReadyCallback callback) const override; |
danilchap | 0219c9b | 2015-11-18 05:56:53 -0800 | [diff] [blame] | 50 | |
Sebastian Jansson | e1795f4 | 2019-07-24 11:38:03 +0200 | [diff] [blame^] | 51 | static inline constexpr uint32_t NameToInt(const char name[5]) { |
| 52 | return static_cast<uint32_t>(name[0]) << 24 | |
| 53 | static_cast<uint32_t>(name[1]) << 16 | |
| 54 | static_cast<uint32_t>(name[2]) << 8 | static_cast<uint32_t>(name[3]); |
| 55 | } |
| 56 | |
danilchap | 0219c9b | 2015-11-18 05:56:53 -0800 | [diff] [blame] | 57 | private: |
danilchap | 2874ed5 | 2016-07-26 06:40:29 -0700 | [diff] [blame] | 58 | static constexpr size_t kAppBaseLength = 8; // Ssrc and Name. |
| 59 | static constexpr size_t kMaxDataSize = 0xffff * 4 - kAppBaseLength; |
danilchap | 0219c9b | 2015-11-18 05:56:53 -0800 | [diff] [blame] | 60 | |
| 61 | uint8_t sub_type_; |
| 62 | uint32_t ssrc_; |
| 63 | uint32_t name_; |
| 64 | rtc::Buffer data_; |
danilchap | 0219c9b | 2015-11-18 05:56:53 -0800 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | } // namespace rtcp |
| 68 | } // namespace webrtc |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 69 | #endif // MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_APP_H_ |