1 /* 2 * Copyright (c) 2016 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 #ifndef MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_COMMON_HEADER_H_ 11 #define MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_COMMON_HEADER_H_ 12 13 #include <stddef.h> 14 #include <stdint.h> 15 16 namespace webrtc { 17 namespace rtcp { 18 class CommonHeader { 19 public: 20 static constexpr size_t kHeaderSizeBytes = 4; 21 CommonHeader()22 CommonHeader() {} 23 CommonHeader(const CommonHeader&) = default; 24 CommonHeader& operator=(const CommonHeader&) = default; 25 26 bool Parse(const uint8_t* buffer, size_t size_bytes); 27 type()28 uint8_t type() const { return packet_type_; } 29 // Depending on packet type same header field can be used either as count or 30 // as feedback message type (fmt). Caller expected to know how it is used. fmt()31 uint8_t fmt() const { return count_or_format_; } count()32 uint8_t count() const { return count_or_format_; } payload_size_bytes()33 size_t payload_size_bytes() const { return payload_size_; } payload()34 const uint8_t* payload() const { return payload_; } packet_size()35 size_t packet_size() const { 36 return kHeaderSizeBytes + payload_size_ + padding_size_; 37 } 38 // Returns pointer to the next RTCP packet in compound packet. NextPacket()39 const uint8_t* NextPacket() const { 40 return payload_ + payload_size_ + padding_size_; 41 } 42 43 private: 44 uint8_t packet_type_ = 0; 45 uint8_t count_or_format_ = 0; 46 uint8_t padding_size_ = 0; 47 uint32_t payload_size_ = 0; 48 const uint8_t* payload_ = nullptr; 49 }; 50 } // namespace rtcp 51 } // namespace webrtc 52 #endif // MODULES_RTP_RTCP_SOURCE_RTCP_PACKET_COMMON_HEADER_H_ 53