1 // Copyright (C) 2002-2015 Federico Montesino Pouzols <fedemp@altern.org>.
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public License
14 // along with GNU ccRTP.  If not, see <http://www.gnu.org/licenses/>.
15 //
16 // As a special exception, you may use this file as part of a free software
17 // library without restriction.  Specifically, if other files instantiate
18 // templates or use macros or inline functions from this file, or you compile
19 // this file and link it with other files to produce an executable, this
20 // file does not by itself cause the resulting executable to be covered by
21 // the GNU General Public License.  This exception does not however
22 // invalidate any other reasons why the executable file might be covered by
23 // the GNU General Public License.
24 //
25 // This exception applies only to the code released under the name GNU
26 // ccRTP.  If you copy code from other releases into a copy of GNU
27 // ccRTP, as the General Public License permits, the exception does
28 // not apply to the code that you add in this way.  To avoid misleading
29 // anyone as to the status of such modified files, you must delete
30 // this exception notice from them.
31 //
32 // If you write modifications of your own for GNU ccRTP, it is your choice
33 // whether to permit this exception to apply to your modifications.
34 // If you do not wish that, delete this exception notice.
35 //
36 
37 #ifndef CCXX_RTP_FORMATS_H_
38 #define CCXX_RTP_FORMATS_H_
39 
40 NAMESPACE_COMMONCPP
41 
42 /**
43  * @file formats.h
44  *
45  * @short Payload types and formats.
46  **/
47 
48 /**
49  * @defgroup payload Payload types and formats.
50  * @{
51  **/
52 
53 /**
54  * @typedef PayloadType
55  *
56  * @short RTP payload type numeric identifier.
57  *
58  * At the RTP level a payload format is identified with a 7 bit
59  * number. This number is binded to a payload format through non-RTP
60  * means (SIP, SAP, application specific rules, etc.)
61  **/
62 typedef uint8 PayloadType;
63 
64 /// Predefined value for invalid or uninitialized payload type variables.
65 const PayloadType ptINVALID = 128;
66 
67 /**
68  * @enum StaticPayloadType
69  *
70  * @short RTP static payload types (default bindings) defined in the
71  * AVP profile.
72  **/
73 typedef enum {
74     // Types for audio formats:
75     sptPCMU = 0,        ///< ITU-T G.711. mu-law audio 8 Khz (RFC 1890)
76     firstStaticPayloadType = sptPCMU,
77     // 1016 static payload type is now deprecated. Type 1 is reserved.
78     // spt1016,         ///< CELP audio (FED-STD 1016) (RFC 1890)
79     sptG726_32 = 2,     ///< ITU-T G.726. ADPCM audio (RFC 1890)
80     sptGSM,             ///< GSM audio (RFC 1890)
81     sptG723,            ///< ITU-T G.723. MP-MLQ ACELP audio (RFC 1890)
82     sptDVI4_8000,       ///< Modified IMA ADPCM audio 8Khz (RFC 1890)
83     sptDVI4_16000,      ///< Modified IMA ADPCM audio 16Khz (RFC 1890)
84     sptLPC,             ///< LPC audio (RFC 1890)
85     sptPCMA,            ///< ITU-T G.711 A-law audio 8 Khz (RFC 1890)
86     sptG722,            ///< Audio (RFCs 1890, 3047)
87     sptL16_DUAL,        ///< Linear uncompressed dual audio (RFC 1890)
88     sptL16_MONO,        ///< Linear uncompressed mono audio (RFC 1890)
89     sptQCELP,           ///< Audio at 8000 hz.
90     // Type 13 is reserved.
91     sptMPA = 14,        ///< MPEG Audio elem. stream (RFCs 1890, 2250)
92     sptG728,            ///< ITU-T G.728. LD-CELP audio
93     sptDVI4_11025,      ///< DVI audio at 11025 hz (by Joseph Di Pol)
94     sptDVI4_22050,      ///< DVI audio at 22050 hz (by Joseph Di Pol)
95     sptG729,            ///< ITU-T G.729. CS-ACELP audio
96     // Type 19 is reserved. Types 20 - 23 are unassigned.
97     lastStaticAudioPayloadType = sptG729,
98 
99     // Types for video formats:
100     // Type 24 is unassigned.
101     sptCELB = 25,       ///< Sun's propietary video (RFCs 1890, 2029)
102     sptJPEG,            ///< JPEG (ISO 10918) video (RFCs 1890, 2435)
103     // Type 27 is unassigned.
104     sptNV = 28,         ///< Ron Frederick's nv audio (RFC 1890)
105     // Types 29 and 30 are unassigned.
106     sptH261 = 31,       ///< ITU-T H.261 video (RFCs 1890, 2032)
107     sptMPV,             ///< MPEG Video elem. stream (RFCs 1890, 2250)
108     sptMP2T,            ///< MPEG 2 Transport stream (RFCs 1890, 2250)
109     sptH263,            ///< ITU-T H.263 video (RFCs 2190, 2429)
110     // Types 35 - 71 are unassigned.
111     // Types 72 - 76 are reserved.
112     // Types 96 - 127 are dynamic.
113     lastStaticPayloadType = sptH263
114 }   StaticPayloadType;
115 
116 /**
117  * @class PayloadFormat
118  * @short Base payload format class.
119  *
120  * The properties of a payload format that, as an RTP stack, ccRTP
121  * takes into account are the payload type (numeric identifier) and
122  * the RTP clock rate.
123  *
124  * This is a base class for both StaticPayloadFormat and
125  * DynamicPayloadFormat.
126  *
127  * @author Federico Montesino Pouzols <fedemp@altern.org>
128  **/
129 class __EXPORT PayloadFormat
130 {
131 public:
132     /**
133      * Get payload type numeric identifier carried in RTP packets.
134      *
135      * @return payload type numeric identifier.
136      **/
getPayloadType()137     inline PayloadType getPayloadType() const
138     { return payloadType; }
139 
140     /**
141      * Get RTP clock rate for this payload format. Note this
142      * method provides the RTP clock rate (for the timestamp in
143      * RTP data packets headers), which is not necessarily the
144      * same as the codec clock rate.
145      *
146      * @return RTP clock rate in Hz.
147      **/
getRTPClockRate()148     inline uint32 getRTPClockRate() const
149     { return RTPClockRate; }
150 
151 protected:
152     /**
153      * PayloadFormat must not be used but as base class.
154      **/
PayloadFormat()155     PayloadFormat()
156     { }
157 
158     /**
159      * PayloadFormat must not be used but as base class.
160      **/
~PayloadFormat()161     inline virtual ~PayloadFormat()
162     { }
163 
164     /**
165      * Set payload type numeric identifier carried in RTP packets.
166      *
167      * @param pt payload type number.
168      **/
setPayloadType(PayloadType pt)169     inline void setPayloadType(PayloadType pt)
170     { payloadType = pt; }
171 
172     /**
173      * Set RTP clock rate.
174      *
175      * @param rate RTP clock rate in Hz.
176      **/
setRTPClockRate(uint32 rate)177     inline void setRTPClockRate(uint32 rate)
178     { RTPClockRate = rate; }
179 
180     // default clock rate
181     static const uint32 defaultRTPClockRate;
182 
183 private:
184     PayloadType payloadType;    ///< Numeric identifier.
185     uint32 RTPClockRate;        ///< Rate in Hz.
186 };
187 
188 /**
189  * @class StaticPayloadFormat
190  * @short Static payload format objects.
191  *
192  * Class of payload formats objects for payload types statically
193  * assigned. Because these payloads have an RTP clock rate assigned,
194  * it is not specified to the constructor. A call to
195  * StaticPayloadFormat(sptPCMU) will set the proper clock rate and any
196  * other parameters for that static payload type.
197  *
198  * @author Federico Montesino Pouzols <fedemp@altern.org>
199  **/
200 class __EXPORT StaticPayloadFormat : public PayloadFormat
201 {
202 public:
203     /**
204      * Constructor. Builds a payload format from a static payload
205      * binding identifier, assigning the numeric identifier and
206      * RTP clock rate statically bounded.
207      *
208      * @param type Numeric identifier in the range 0-96.
209      * @note some identifiers are reserved.
210      **/
211     StaticPayloadFormat(StaticPayloadType type);
212 
213 private:
214     /**
215      * RTP clock rate for static payload types. There is no need
216      * for a table like this for video types, since they all have
217      * 90000 Khz rate.
218      **/
219     static uint32 staticAudioTypesRates[lastStaticAudioPayloadType -
220                         firstStaticPayloadType + 1];
221 };
222 
223 /**
224  * @class DynamicPayloadFormat
225  * @short Dynamic payload format objects.
226  *
227  * Class of payload formats objects for payload types dynamically
228  * negotiated. Because these payloads do not have a fix RTP clock rate
229  * assigned, it must be specified to the constructor. This class will
230  * be used by applications that support dynamic payload negotiation.
231  *
232  * @author Federico Montesino Pouzols <fedemp@altern.org>
233  **/
234 class __EXPORT DynamicPayloadFormat : public PayloadFormat
235 {
236 public:
237     /**
238      * Constructor. Builds a dynamic payload format from payload
239      * numeric identifier and the corresponding RTP clock rate.
240      *
241      * @param type payload type numeric identifier.
242      * @param rate RTP clock rate.
243      **/
244     DynamicPayloadFormat(PayloadType type, uint32 rate);
245 };
246 
247 /** @}*/ // payload
248 
249 END_NAMESPACE
250 
251 #endif  // ndef CCXX_RTP_FORMATS_H_
252 
253 /** EMACS **
254  * Local variables:
255  * mode: c++
256  * c-basic-offset: 8
257  * End:
258  */
259