OPAL Version 3.10.4

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files

- File List
- Globals

sdp.h
Go to the documentation of this file.
1 /*
2 * sdp.h
3 *
4 * Session Description Protocol
5 *
6 * Open Phone Abstraction Library (OPAL)
7 * Formally known as the Open H323 project.
8 *
9 * Copyright (c) 2001 Equivalence Pty. Ltd.
10 *
11 * The contents of this file are subject to the Mozilla Public License
12 * Version 1.0 (the "License"); you may not use this file except in
13 * compliance with the License. You may obtain a copy of the License at
14 * http://www.mozilla.org/MPL/
15 *
16 * Software distributed under the License is distributed on an "AS IS"
17 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
18 * the License for the specific language governing rights and limitations
19 * under the License.
20 *
21 * The Original Code is Open Phone Abstraction Library.
22 *
23 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 *
25 * Contributor(s): ______________________________________.
26 *
27 * $Revision: 25734 $
28 * $Author: rjongbloed $
29 * $Date: 2011-05-10 21:41:47 -0500 (Tue, 10 May 2011) $
30 */
31
32 #ifndef OPAL_SIP_SDP_H
33 #define OPAL_SIP_SDP_H
34
35 #ifdef P_USE_PRAGMA
36 #pragma interface
37 #endif
38
39 #include <opal/buildopts.h>
40
41 #if OPAL_SIP
42
43 #include <opal/transports.h>
44 #include <opal/mediatype.h>
45 #include <opal/mediafmt.h>
46 #include <rtp/rtp.h>
47
49
50 class SDPBandwidth : public std::map<PCaselessString, unsigned>
51 {
52 public:
53 unsigned & operator[](const PCaselessString & type);
54 unsigned operator[](const PCaselessString & type) const;
55 friend ostream & operator<<(ostream & out, const SDPBandwidth & bw);
56 bool Parse(const PString & param);
57 void SetMax(const PCaselessString & type, unsigned value);
58 };
59
61
62 class SDPMediaDescription;
63
64 class SDPMediaFormat : public PObject
65 {
66 PCLASSINFO(SDPMediaFormat, PObject);
67 public:
68 SDPMediaFormat(
69 SDPMediaDescription & parent,
70 RTP_DataFrame::PayloadTypes payloadType,
71 const char * name = NULL
72 );
73
74 SDPMediaFormat(
75 SDPMediaDescription & parent,
76 const OpalMediaFormat & mediaFormat
77 );
78
79 virtual void PrintOn(ostream & str) const;
80
81 RTP_DataFrame::PayloadTypes GetPayloadType() const { return payloadType; }
82
83 const PCaselessString & GetEncodingName() const { return encodingName; }
84 void SetEncodingName(const PString & v) { encodingName = v; }
85
86 void SetFMTP(const PString & _fmtp);
87 PString GetFMTP() const;
88
89 unsigned GetClockRate(void) { return clockRate ; }
90 void SetClockRate(unsigned v) { clockRate = v; }
91
92 void SetParameters(const PString & v) { parameters = v; }
93 void SetRTCP_FB(const PString & v) { m_rtcp_fb = v; }
94
95 const OpalMediaFormat & GetMediaFormat() const { return m_mediaFormat; }
96 OpalMediaFormat & GetWritableMediaFormat() { return m_mediaFormat; }
97
98 bool PreEncode();
99 bool PostDecode(const OpalMediaFormatList & mediaFormats, unsigned bandwidth);
100
101 protected:
102 void SetMediaFormatOptions(OpalMediaFormat & mediaFormat) const;
103
104 OpalMediaFormat m_mediaFormat;
105
106 SDPMediaDescription & m_parent;
107 RTP_DataFrame::PayloadTypes payloadType;
108 unsigned clockRate;
109 PCaselessString encodingName;
110 PString parameters;
111 PString m_fmtp;
112 PString m_rtcp_fb; // RFC4585
113 };
114
115 typedef PList<SDPMediaFormat> SDPMediaFormatList;
116
118
119 class SDPMediaDescription : public PObject
120 {
121 PCLASSINFO(SDPMediaDescription, PObject);
122 public:
123 // The following enum is arranged so it can be used as a bit mask,
124 // e.g. GetDirection()&SendOnly indicates send is available
125 enum Direction {
126 Undefined = -1,
127 Inactive,
128 RecvOnly,
129 SendOnly,
130 SendRecv
131 };
132
133 SDPMediaDescription(
134 const OpalTransportAddress & address,
135 const OpalMediaType & mediaType
136 );
137
138 virtual bool PreEncode();
139 virtual void Encode(const OpalTransportAddress & commonAddr, ostream & str) const;
140 virtual bool PrintOn(ostream & strm, const PString & str) const;
141
142 virtual bool Decode(const PStringArray & tokens);
143 virtual bool Decode(char key, const PString & value);
144 virtual bool PostDecode(const OpalMediaFormatList & mediaFormats);
145
146 virtual SDPMediaDescription * CreateEmpty() const = 0;
147
148 // return the string used within SDP to identify this media type
149 virtual PString GetSDPMediaType() const = 0;
150
151 // return the string used within SDP to identify the transport used by this media
152 virtual PCaselessString GetSDPTransportType() const = 0;
153
154 virtual const SDPMediaFormatList & GetSDPMediaFormats() const
155 { return formats; }
156
157 virtual OpalMediaFormatList GetMediaFormats() const;
158
159 virtual void AddSDPMediaFormat(SDPMediaFormat * sdpMediaFormat);
160
161 virtual void AddMediaFormat(const OpalMediaFormat & mediaFormat);
162 virtual void AddMediaFormats(const OpalMediaFormatList & mediaFormats, const OpalMediaType & mediaType);
163
164 virtual void SetAttribute(const PString & attr, const PString & value);
165
166 virtual void SetDirection(const Direction & d) { direction = d; }
167 virtual Direction GetDirection() const { return transportAddress.IsEmpty() ? Inactive : direction; }
168
169 virtual const OpalTransportAddress & GetTransportAddress() const { return transportAddress; }
170 virtual PBoolean SetTransportAddress(const OpalTransportAddress &t);
171
172 virtual WORD GetPort() const { return port; }
173
174 virtual OpalMediaType GetMediaType() const { return mediaType; }
175
176 virtual unsigned GetBandwidth(const PString & type) const { return bandwidth[type]; }
177 virtual void SetBandwidth(const PString & type, unsigned value) { bandwidth[type] = value; }
178
179 virtual const SDPBandwidth & GetBandwidth() const { return bandwidth; }
180
181 virtual void CreateSDPMediaFormats(const PStringArray & tokens);
182 virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString) = 0;
183
184 virtual PString GetSDPPortList() const = 0;
185
186 virtual void ProcessMediaOptions(SDPMediaFormat & sdpFormat, const OpalMediaFormat & mediaFormat);
187
188 unsigned GetPTime () const { return ptime; }
189 unsigned GetMaxPTime () const { return maxptime; }
190
191 protected:
192 virtual SDPMediaFormat * FindFormat(PString & str) const;
193
194 OpalTransportAddress transportAddress;
195 Direction direction;
196 WORD port;
197 WORD portCount;
198 OpalMediaType mediaType;
199
200 SDPMediaFormatList formats;
201 SDPBandwidth bandwidth;
202 unsigned ptime;
203 unsigned maxptime;
204 };
205
206 PARRAY(SDPMediaDescriptionArray, SDPMediaDescription);
207
208
209 class SDPDummyMediaDescription : public SDPMediaDescription
210 {
211 PCLASSINFO(SDPDummyMediaDescription, SDPMediaDescription);
212 public:
213 SDPDummyMediaDescription(const OpalTransportAddress & address, const PStringArray & tokens);
214 virtual SDPMediaDescription * CreateEmpty() const;
215 virtual PString GetSDPMediaType() const;
216 virtual PCaselessString GetSDPTransportType() const;
217 virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
218 virtual PString GetSDPPortList() const;
219
220 private:
221 PStringArray m_tokens;
222 };
223
224
226 //
227 // SDP media description for media classes using RTP/AVP transport (audio and video)
228 //
229
230 class SDPRTPAVPMediaDescription : public SDPMediaDescription
231 {
232 PCLASSINFO(SDPRTPAVPMediaDescription, SDPMediaDescription);
233 public:
234 SDPRTPAVPMediaDescription(const OpalTransportAddress & address, const OpalMediaType & mediaType);
235 virtual PCaselessString GetSDPTransportType() const;
236 virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
237 virtual PString GetSDPPortList() const;
238 virtual bool PrintOn(ostream & str, const PString & connectString) const;
239 virtual void SetAttribute(const PString & attr, const PString & value);
240 };
241
243 //
244 // SDP media description for audio media
245 //
246
247 class SDPAudioMediaDescription : public SDPRTPAVPMediaDescription
248 {
249 PCLASSINFO(SDPAudioMediaDescription, SDPRTPAVPMediaDescription);
250 public:
251 SDPAudioMediaDescription(const OpalTransportAddress & address);
252 virtual SDPMediaDescription * CreateEmpty() const;
253 virtual PString GetSDPMediaType() const;
254 virtual bool PrintOn(ostream & str, const PString & connectString) const;
255 virtual void SetAttribute(const PString & attr, const PString & value);
256
257 bool GetOfferPTime() const { return m_offerPTime; }
258 void SetOfferPTime(bool value) { m_offerPTime = value; }
259
260 protected:
261 bool m_offerPTime;
262 };
263
265 //
266 // SDP media description for video media
267 //
268
269 class SDPVideoMediaDescription : public SDPRTPAVPMediaDescription
270 {
271 PCLASSINFO(SDPVideoMediaDescription, SDPRTPAVPMediaDescription);
272 public:
273 SDPVideoMediaDescription(const OpalTransportAddress & address);
274 virtual SDPMediaDescription * CreateEmpty() const;
275 virtual PString GetSDPMediaType() const;
276 virtual bool PreEncode();
277 virtual bool PrintOn(ostream & str, const PString & connectString) const;
278 void SetAttribute(const PString & attr, const PString & value);
279 };
280
282 //
283 // SDP media description for application media
284 //
285
286 class SDPApplicationMediaDescription : public SDPMediaDescription
287 {
288 PCLASSINFO(SDPApplicationMediaDescription, SDPMediaDescription);
289 public:
290 SDPApplicationMediaDescription(const OpalTransportAddress & address);
291 virtual PCaselessString GetSDPTransportType() const;
292 virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
293 virtual SDPMediaDescription * CreateEmpty() const;
294 virtual PString GetSDPMediaType() const;
295 virtual PString GetSDPPortList() const;
296 };
297
299
300 class SDPSessionDescription : public PObject
301 {
302 PCLASSINFO(SDPSessionDescription, PObject);
303 public:
304 SDPSessionDescription(
305 time_t sessionId,
306 unsigned version,
307 const OpalTransportAddress & address
308 );
309
310 void PrintOn(ostream & strm) const;
311 PString Encode() const;
312 bool Decode(const PString & str, const OpalMediaFormatList & mediaFormats);
313
314 void SetSessionName(const PString & v);
315 PString GetSessionName() const { return sessionName; }
316
317 void SetUserName(const PString & v);
318 PString GetUserName() const { return ownerUsername; }
319
320 const SDPMediaDescriptionArray & GetMediaDescriptions() const { return mediaDescriptions; }
321
322 SDPMediaDescription * GetMediaDescriptionByType(const OpalMediaType & rtpMediaType) const;
323 SDPMediaDescription * GetMediaDescriptionByIndex(PINDEX i) const;
324 void AddMediaDescription(SDPMediaDescription * md) { mediaDescriptions.Append(md); }
325
326 void SetDirection(const SDPMediaDescription::Direction & d) { direction = d; }
327 SDPMediaDescription::Direction GetDirection(unsigned) const;
328 bool IsHold() const;
329
330 const OpalTransportAddress & GetDefaultConnectAddress() const { return defaultConnectAddress; }
331 void SetDefaultConnectAddress(
332 const OpalTransportAddress & address
333 );
334
335 time_t GetOwnerSessionId() const { return ownerSessionId; }
336 void SetOwnerSessionId(time_t value) { ownerSessionId = value; }
337
338 PINDEX GetOwnerVersion() const { return ownerVersion; }
339 void SetOwnerVersion(PINDEX value) { ownerVersion = value; }
340
341 OpalTransportAddress GetOwnerAddress() const { return ownerAddress; }
342 void SetOwnerAddress(OpalTransportAddress addr) { ownerAddress = addr; }
343
344 unsigned GetBandwidth(const PString & type) const { return bandwidth[type]; }
345 void SetBandwidth(const PString & type, unsigned value) { bandwidth[type] = value; }
346
347 OpalMediaFormatList GetMediaFormats() const;
348
349 static const PCaselessString & ConferenceTotalBandwidthType();
350 static const PCaselessString & ApplicationSpecificBandwidthType();
351 static const PCaselessString & TransportIndependentBandwidthType(); // RFC3890
352
353 protected:
354 void ParseOwner(const PString & str);
355
356 SDPMediaDescriptionArray mediaDescriptions;
357 SDPMediaDescription::Direction direction;
358
359 PINDEX protocolVersion;
360 PString sessionName;
361
362 PString ownerUsername;
363 time_t ownerSessionId;
364 unsigned ownerVersion;
365 OpalTransportAddress ownerAddress;
366 OpalTransportAddress defaultConnectAddress;
367
368 SDPBandwidth bandwidth;
369 };
370
372
373
374 #endif // OPAL_SIP
375
376 #endif // OPAL_SIP_SDP_H
377
378
379 // End of File ///////////////////////////////////////////////////////////////