OPAL  Version 3.10.10
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 
63 
64 class SDPMediaFormat : public PObject
65 {
66  PCLASSINFO(SDPMediaFormat, PObject);
67  public:
69  SDPMediaDescription & parent,
70  RTP_DataFrame::PayloadTypes payloadType,
71  const char * name = NULL
72  );
73 
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 
105 
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,
130  SendRecv
131  };
132 
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 
196  WORD port;
197  WORD portCount;
199 
202  unsigned ptime;
203  unsigned maxptime;
204 };
205 
206 PARRAY(SDPMediaDescriptionArray, SDPMediaDescription);
207 
208 
210 {
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 
231 {
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 
248 {
250  public:
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:
262 };
263 
265 //
266 // SDP media description for video media
267 //
268 
270 {
272  public:
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 
287 {
289  public:
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:
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;
358 
360  PString sessionName;
361 
362  PString ownerUsername;
364  unsigned ownerVersion;
367 
369 };
370 
372 
373 
374 #endif // OPAL_SIP
375 
376 #endif // OPAL_SIP_SDP_H
377 
378 
379 // End of File ///////////////////////////////////////////////////////////////
void SetMax(const PCaselessString &type, unsigned value)
OpalTransportAddress defaultConnectAddress
Definition: sdp.h:366
unsigned clockRate
Definition: sdp.h:108
PList< SDPMediaFormat > SDPMediaFormatList
Definition: sdp.h:115
SDPMediaDescription & m_parent
Definition: sdp.h:106
time_t ownerSessionId
Definition: sdp.h:363
PString m_rtcp_fb
Definition: sdp.h:112
unsigned maxptime
Definition: sdp.h:203
PString GetSessionName() const
Definition: sdp.h:315
OpalMediaType mediaType
Definition: sdp.h:198
OpalTransportAddress ownerAddress
Definition: sdp.h:365
void SetOwnerSessionId(time_t value)
Definition: sdp.h:336
OpalMediaFormat & GetWritableMediaFormat()
Definition: sdp.h:96
Definition: sdp.h:247
void SetOwnerVersion(PINDEX value)
Definition: sdp.h:339
Direction
Definition: sdp.h:125
virtual const SDPMediaFormatList & GetSDPMediaFormats() const
Definition: sdp.h:154
virtual Direction GetDirection() const
Definition: sdp.h:167
virtual const OpalTransportAddress & GetTransportAddress() const
Definition: sdp.h:169
unsigned GetBandwidth(const PString &type) const
Definition: sdp.h:344
void AddMediaDescription(SDPMediaDescription *md)
Definition: sdp.h:324
Definition: mediatype.h:57
bool Parse(const PString &param)
Definition: sdp.h:209
virtual OpalMediaType GetMediaType() const
Definition: sdp.h:174
PINDEX GetOwnerVersion() const
Definition: sdp.h:338
SDPMediaFormatList formats
Definition: sdp.h:200
PString ownerUsername
Definition: sdp.h:362
bool GetOfferPTime() const
Definition: sdp.h:257
virtual WORD GetPort() const
Definition: sdp.h:172
OpalTransportAddress GetOwnerAddress() const
Definition: sdp.h:341
PARRAY(SDPMediaDescriptionArray, SDPMediaDescription)
const PCaselessString & GetEncodingName() const
Definition: sdp.h:83
SDPMediaDescription::Direction direction
Definition: sdp.h:357
PayloadTypes
Definition: rtp.h:86
virtual unsigned GetBandwidth(const PString &type) const
Definition: sdp.h:176
virtual void SetDirection(const Direction &d)
Definition: sdp.h:166
Definition: mediafmt.h:72
Direction direction
Definition: sdp.h:195
OpalTransportAddress transportAddress
Definition: sdp.h:194
void SetEncodingName(const PString &v)
Definition: sdp.h:84
void SetOwnerAddress(OpalTransportAddress addr)
Definition: sdp.h:342
PString sessionName
Definition: sdp.h:360
Definition: sdp.h:128
Definition: sdp.h:127
OpalMediaFormat m_mediaFormat
Definition: sdp.h:104
PString m_fmtp
Definition: sdp.h:111
PString parameters
Definition: sdp.h:110
unsigned GetPTime() const
Definition: sdp.h:188
void SetBandwidth(const PString &type, unsigned value)
Definition: sdp.h:345
Definition: sdp.h:129
Definition: mediafmt.h:724
Definition: sdp.h:119
Definition: sdp.h:50
Definition: sdp.h:300
PCaselessString encodingName
Definition: sdp.h:109
void SetOfferPTime(bool value)
Definition: sdp.h:258
void SetParameters(const PString &v)
Definition: sdp.h:92
SDPMediaDescriptionArray mediaDescriptions
Definition: sdp.h:356
Definition: sdp.h:64
friend ostream & operator<<(ostream &out, const SDPBandwidth &bw)
RTP_DataFrame::PayloadTypes payloadType
Definition: sdp.h:107
unsigned ptime
Definition: sdp.h:202
bool m_offerPTime
Definition: sdp.h:261
Definition: sdp.h:230
WORD port
Definition: sdp.h:196
SDPBandwidth bandwidth
Definition: sdp.h:368
void SetClockRate(unsigned v)
Definition: sdp.h:90
Definition: sdp.h:286
Definition: sdp.h:269
unsigned GetClockRate(void)
Definition: sdp.h:89
unsigned GetMaxPTime() const
Definition: sdp.h:189
const OpalTransportAddress & GetDefaultConnectAddress() const
Definition: sdp.h:330
Definition: transports.h:149
PINDEX protocolVersion
Definition: sdp.h:359
void SetDirection(const SDPMediaDescription::Direction &d)
Definition: sdp.h:326
const SDPMediaDescriptionArray & GetMediaDescriptions() const
Definition: sdp.h:320
virtual void SetBandwidth(const PString &type, unsigned value)
Definition: sdp.h:177
const OpalMediaFormat & GetMediaFormat() const
Definition: sdp.h:95
RTP_DataFrame::PayloadTypes GetPayloadType() const
Definition: sdp.h:81
unsigned & operator[](const PCaselessString &type)
virtual const SDPBandwidth & GetBandwidth() const
Definition: sdp.h:179
PString GetUserName() const
Definition: sdp.h:318
unsigned ownerVersion
Definition: sdp.h:364
void SetRTCP_FB(const PString &v)
Definition: sdp.h:93
WORD portCount
Definition: sdp.h:197
time_t GetOwnerSessionId() const
Definition: sdp.h:335
SDPBandwidth bandwidth
Definition: sdp.h:201