1 /**
2  * Copyright (C) 2022 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 /** \addtogroup  RTP_Stack
18  *  @{
19  */
20 
21 #ifndef __RTCP_HEADER_H__
22 #define __RTCP_HEADER_H__
23 
24 #include <RtpGlobal.h>
25 #include <RtpBuffer.h>
26 
27 #define MAX_RTP_VERSION            3
28 #define MAX_RECEPTION_REPORT_COUNT 31
29 
30 /**
31  * @class   RtcpHeader
32  * @brief   This class provides RTCP packet encode and decode functionality.
33  *          RTCP header fields can be accessed via get/set APIs.
34  */
35 class RtcpHeader
36 {
37 private:
38     /**
39      * m_ucVersion identifies the version of RTCP
40      */
41     RtpDt_UChar m_ucVersion;
42 
43     /**
44      * If the padding bit is set, RTCP packet contains some additional padding octets at the end.
45      */
46     eRtp_Bool m_ucIsPadding;
47 
48     /**
49      * The number of reception report blocks contained in this packet.
50      */
51     RtpDt_UChar m_ucReceptionReportCount;
52 
53     /**
54      * It Identifies the RTCP packet type.
55      */
56     RtpDt_UChar m_ucPacketType;
57 
58     /**
59      * The length of the RTCP packet in 32-bit words minus one,
60      * including the header and any padding
61      */
62     RtpDt_UInt32 m_usLength;
63 
64     // Synchronization source.
65     RtpDt_UInt32 m_uiSsrc;
66 
67 public:
68     // Constructor
69     RtcpHeader();
70 
71     // Destructor
72     ~RtcpHeader();
73 
74     /**
75      *  Set RTCP protocol version.
76      *  It's a 2-bit field and value should not be greater than 3.
77      *  Version defined by the specification is 2.
78      *
79      *  @param ucVersion Version number to be set.
80      *  @return false if ucVersion is greater than 3.
81      */
82     eRtp_Bool setVersion(IN RtpDt_UChar ucVersion);
83 
84     /**
85      * Get RTCP protocol version.
86      *
87      * @return RTP version number.
88      */
89     RtpDt_UChar getVersion();
90 
91     /**
92      * Set method for padding bit.
93      *
94      * Padding bit indicates if RTCP packet contains additional padding octets at the end to align
95      * with block size required by encryption algorithms.
96      */
97     RtpDt_Void setPadding(eRtp_Bool padding = eRTP_TRUE);
98 
99     /**
100      * Get method for padding bit.
101      *
102      * @return true if padding bit is set and false otherwise.
103      */
104     eRtp_Bool getPadding();
105 
106     /**
107      * Set method for Reception report count.
108      * It's a 5-bits field. Max value is
109      *
110      * @param ucReceptionReport The number of reception report blocks contained in this packet.
111      */
112     eRtp_Bool setReceptionReportCount(IN RtpDt_UChar ucReceptionReport);
113 
114     /**
115      * Get method for Reception report count.
116      */
117     RtpDt_UChar getReceptionReportCount();
118 
119     /**
120      * Sets Packet type to identify RTCP packet type. It's a 8-bits field.
121      *
122      * @param ucPacketType Possible values are:
123      * 200 = SR Sender Report packet.
124      * 201 = RR Receiver Report packet.
125      * 202 = SDES Source Description packet.
126      * 203 = BYE Goodbye packet.
127      * 204 = APP Application-defined packet.
128      */
129     RtpDt_Void setPacketType(IN RtpDt_UChar ucPacketType);
130 
131     /**
132      * Get method for RTCP packet type.
133      */
134     RtpDt_UChar getPacketType();
135 
136     /**
137      * Set method for length of RTCP packet. It's a 16-bit field.
138      *
139      * @param usLength  length in 32-bit words minus one, including the header and any padding.
140      */
141     RtpDt_Void setLength(IN RtpDt_UInt32 usLength);
142 
143     /**
144      * Get method for RTCP packet length.
145      */
146     RtpDt_UInt32 getLength();
147 
148     /**
149      * Get method for SSRC (synchronization source identifier)
150      *
151      * @param uiSsrc SSRC of the originator of this RTCP packet.
152      */
153     RtpDt_Void setSsrc(IN RtpDt_UInt32 uiSsrc);
154 
155     /**
156      * Get method for SSRC (synchronization source identifier)
157      */
158     RtpDt_UInt32 getSsrc();
159 
160     /**
161      * Equality operator overloaded
162      */
163     bool operator==(const RtcpHeader& objRtcpHeader) const;
164 
165     /**
166      * Decodes and stores the information of the RTCP Header.
167      *
168      * @param[in] pobjRtcpPktBuf RTCP pcaket buffer.
169      * @return eRTP_SUCCESS on successful decoding
170      */
171     eRtp_Bool decodeRtcpHeader(IN RtpDt_UChar* pRtcpBuffer, RtpDt_Int32 length);
172 
173     /**
174      * Performs the encoding of the RTCP header using the data filled by set methods.
175      *
176      * @param[out] pobjRtcpPktBuf RTCP header is encoded into this buffer. Buffer should be
177      * allocated by the caller.
178      * @return eRTP_SUCCESS on successful encoding
179      */
180     eRtp_Bool formRtcpHeader(OUT RtpBuffer* pobjRtcpPktBuf);
181 
182     /**
183      * Performs the encoding of the first 4 octets of the RTCP Header.
184      *
185      * @param[out] pobjRtcpPktBuf First 4 octets of the RTCP header is encoded into this buffer.
186      * Buffer should be allocated by the caller.
187      * @return eRTP_SUCCESS on successful encoding
188      */
189     eRtp_Bool formPartialRtcpHeader(OUT RtpBuffer* pobjRtcpPktBuf);
190 
191     /**
192      * It populates RTCP header information
193      */
194     RtpDt_Void populateRtcpHeader(IN RtpDt_UChar ucReceptionReportCount,
195             IN RtpDt_UChar ucPacketType, IN RtpDt_UInt32 uiSsrc);
196 
197 };  // end of RtcpHeader
198 
199 #endif  //__RTCP_HEADER_H__
200 
201 /** @}*/
202