OPAL  Version 3.12.5
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: 28208 $
28  * $Author: rjongbloed $
29  * $Date: 2012-08-16 20:54:46 -0500 (Thu, 16 Aug 2012) $
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_session.h>
47 
48 
49 
53 #define OPAL_OPT_OFFER_SDP_PTIME "Offer-SDP-PTime"
54 
62 #define OPAL_OPT_OFFER_RTCP_FB "Offer-RTCP-FB"
63 
68 #define OPAL_OPT_FORCE_RTCP_FB "Force-RTCP-FB"
69 
70 
72 
73 class SDPBandwidth : public std::map<PCaselessString, OpalBandwidth>
74 {
75  typedef std::map<PCaselessString, OpalBandwidth> BaseClass;
76  public:
77  OpalBandwidth & operator[](const PCaselessString & type);
78  OpalBandwidth operator[](const PCaselessString & type) const;
79  friend ostream & operator<<(ostream & out, const SDPBandwidth & bw);
80  bool Parse(const PString & param);
81  void SetMax(const PCaselessString & type, OpalBandwidth value);
82 };
83 
85 
87 
88 class SDPMediaFormat : public PObject
89 {
90  PCLASSINFO(SDPMediaFormat, PObject);
91  public:
93  SDPMediaDescription & parent,
95  const char * name = NULL
96  );
97 
99  SDPMediaDescription & parent,
100  const OpalMediaFormat & mediaFormat
101  );
102 
103  virtual void PrintOn(ostream & str) const;
104  virtual PObject * Clone() const { return new SDPMediaFormat(*this); }
105 
107 
108  const PCaselessString & GetEncodingName() const { return encodingName; }
109  void SetEncodingName(const PString & v) { encodingName = v; }
110 
111  void SetFMTP(const PString & _fmtp);
112  PString GetFMTP() const;
113 
114  unsigned GetClockRate(void) { return clockRate ; }
115  void SetClockRate(unsigned v) { clockRate = v; }
116 
117  void SetParameters(const PString & v) { parameters = v; }
118 
119 #if OPAL_VIDEO
120  void SetRTCP_FB(const PString & v) { m_rtcp_fb.FromString(v); }
121  OpalVideoFormat::RTCPFeedback GetRTCP_FB() const { return m_rtcp_fb; }
122 #endif
123 
124  const OpalMediaFormat & GetMediaFormat() const { return m_mediaFormat; }
126 
127  bool PreEncode();
128  bool PostDecode(const OpalMediaFormatList & mediaFormats, unsigned bandwidth);
129 
130  protected:
131  void SetMediaFormatOptions(OpalMediaFormat & mediaFormat) const;
132 
134 
137  unsigned clockRate;
138  PCaselessString encodingName;
139  PString parameters;
140  PString m_fmtp;
141 #if OPAL_VIDEO
142  OpalVideoFormat::RTCPFeedback m_rtcp_fb; // RFC4585
143 #endif
144 };
145 
146 typedef PList<SDPMediaFormat> SDPMediaFormatList;
147 
148 
150 
152 {
153  public:
154  // The following enum is arranged so it can be used as a bit mask,
155  // e.g. GetDirection()&SendOnly indicates send is available
156  enum Direction {
157  Undefined = -1,
162  };
163 
166  { }
167 
168  virtual ~SDPCommonAttributes() { }
169 
170  virtual void SetDirection(const Direction & d) { m_direction = d; }
171  virtual Direction GetDirection() const { return m_direction; }
172 
173  virtual OpalBandwidth GetBandwidth(const PString & type) const { return m_bandwidth[type]; }
174  virtual void SetBandwidth(const PString & type, OpalBandwidth value) { m_bandwidth[type] = value; }
175 
176  virtual const SDPBandwidth & GetBandwidth() const { return m_bandwidth; }
177 
178  virtual const RTPExtensionHeaders & GetExtensionHeaders() const { return m_extensionHeaders; }
179  virtual void SetExtensionHeader(const RTPExtensionHeaderInfo & ext) { m_extensionHeaders.insert(ext); }
180 
181  virtual void ParseAttribute(const PString & value);
182  virtual void SetAttribute(const PString & attr, const PString & value);
183 
184  virtual void OutputAttributes(ostream & strm) const;
185 
186  static const PCaselessString & ConferenceTotalBandwidthType();
187  static const PCaselessString & ApplicationSpecificBandwidthType();
188  static const PCaselessString & TransportIndependentBandwidthType(); // RFC3890
189 
190  protected:
194 };
195 
196 
198 
199 class SDPMediaDescription : public PObject, public SDPCommonAttributes
200 {
201  PCLASSINFO(SDPMediaDescription, PObject);
202  public:
204  const OpalTransportAddress & address,
205  const OpalMediaType & mediaType
206  );
207 
208  virtual bool PreEncode();
209  virtual void Encode(const OpalTransportAddress & commonAddr, ostream & str) const;
210 
211  virtual bool Decode(const PStringArray & tokens);
212  virtual bool Decode(char key, const PString & value);
213  virtual bool PostDecode(const OpalMediaFormatList & mediaFormats);
214 
215  // return the string used within SDP to identify this media type
216  virtual PString GetSDPMediaType() const = 0;
217 
218  // return the string used within SDP to identify the transport used by this media
219  virtual PCaselessString GetSDPTransportType() const = 0;
220 
221  virtual const SDPMediaFormatList & GetSDPMediaFormats() const
222  { return formats; }
223 
224  virtual OpalMediaFormatList GetMediaFormats() const;
225 
226  virtual void AddSDPMediaFormat(SDPMediaFormat * sdpMediaFormat);
227 
228  virtual void AddMediaFormat(const OpalMediaFormat & mediaFormat);
229  virtual void AddMediaFormats(const OpalMediaFormatList & mediaFormats, const OpalMediaType & mediaType);
230 
231  virtual void SetCryptoKeys(OpalMediaCryptoKeyList & cryptoKeys);
232  virtual OpalMediaCryptoKeyList GetCryptoKeys() const;
233 
234  virtual void SetAttribute(const PString & attr, const PString & value);
235 
236  virtual Direction GetDirection() const { return m_transportAddress.IsEmpty() ? Inactive : m_direction; }
237 
238  virtual const OpalTransportAddress & GetTransportAddress() const { return m_transportAddress; }
239  virtual PBoolean SetTransportAddress(const OpalTransportAddress &t);
240 
241  virtual WORD GetPort() const { return m_port; }
242 
243  virtual OpalMediaType GetMediaType() const { return m_mediaType; }
244 
245  virtual void CreateSDPMediaFormats(const PStringArray & tokens);
246  virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString) = 0;
247 
248  virtual PString GetSDPPortList() const;
249 
250  virtual void ProcessMediaOptions(SDPMediaFormat & sdpFormat, const OpalMediaFormat & mediaFormat);
251 
252 #if OPAL_VIDEO
253  virtual OpalVideoFormat::ContentRole GetContentRole() const { return OpalVideoFormat::eNoRole; }
254 #endif
255 
256  void SetOptionStrings(const PStringOptions & options) { m_stringOptions = options; }
257  const PStringOptions & GetOptionStrings() const { return m_stringOptions; }
258 
259  virtual void Copy(SDPMediaDescription & mediaDescription);
260 
261  protected:
262  virtual SDPMediaFormat * FindFormat(PString & str) const;
263 
265  PCaselessString m_transportType;
266  PStringOptions m_stringOptions;
267  WORD m_port;
270 
272 };
273 
274 PARRAY(SDPMediaDescriptionArray, SDPMediaDescription);
275 
276 
278 {
280  public:
281  SDPDummyMediaDescription(const OpalTransportAddress & address, const PStringArray & tokens);
282  virtual PString GetSDPMediaType() const;
283  virtual PCaselessString GetSDPTransportType() const;
284  virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
285  virtual PString GetSDPPortList() const;
286  virtual void Copy(SDPMediaDescription & mediaDescription);
287 
288  private:
289  PStringArray m_tokens;
290 };
291 
292 
294 {
295  PCLASSINFO(SDPDummySession, OpalMediaSession)
296  public:
297  SDPDummySession(const Init & init);
298  static const PCaselessString & SessionType();
299  virtual const PCaselessString & GetSessionType() const;
301  virtual OpalMediaStream * CreateMediaStream(const OpalMediaFormat & mediaFormat, unsigned sessionID, bool isSource);
302 
303  private:
304  PStringArray m_tokens;
305 };
306 
307 
308 class SDPCryptoSuite : public PObject
309 {
310  PCLASSINFO(SDPCryptoSuite, PObject)
311  public:
312  SDPCryptoSuite(unsigned tag);
313 
314  bool SetKeyInfo(const OpalMediaCryptoKeyInfo & keyInfo);
316 
317  bool Decode(const PString & attrib);
318  void PrintOn(ostream & strm) const;
319 
320  struct KeyParam {
321  KeyParam(const PString & keySalt)
322  : m_keySalt(keySalt)
323  , m_lifetime(0)
324  , m_mkiIndex(0)
325  , m_mkiLength(0)
326  { }
327 
328  PString m_keySalt;
329  PUInt64 m_lifetime;
330  unsigned m_mkiIndex;
331  unsigned m_mkiLength;
332  };
333 
334  unsigned GetTag() const { return m_tag; }
335  const PString & GetName() const { return m_suiteName; }
336 
337  protected:
338  unsigned m_tag;
339  PString m_suiteName;
340  list<KeyParam> m_keyParams;
341  PStringOptions m_sessionParams;
342 };
343 
345 //
346 // SDP media description for media classes using RTP/AVP transport (audio and video)
347 //
348 
350 {
352  public:
353  SDPRTPAVPMediaDescription(const OpalTransportAddress & address, const OpalMediaType & mediaType);
354  virtual bool Decode(const PStringArray & tokens);
355  virtual PCaselessString GetSDPTransportType() const;
356  virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
357  virtual PString GetSDPPortList() const;
358  virtual bool PreEncode();
359  virtual void OutputAttributes(ostream & str) const;
360  virtual void SetCryptoKeys(OpalMediaCryptoKeyList & cryptoKeys);
361  virtual OpalMediaCryptoKeyList GetCryptoKeys() const;
362  virtual void SetAttribute(const PString & attr, const PString & value);
363 
364  void EnableFeedback() { m_enableFeedback = true; }
365 
366  protected:
368 #if OPAL_VIDEO
369  OpalVideoFormat::RTCPFeedback m_rtcp_fb;
370 #endif
371  PList<SDPCryptoSuite> m_cryptoSuites;
372 };
373 
375 //
376 // SDP media description for audio media
377 //
378 
380 {
382  public:
384  virtual PString GetSDPMediaType() const;
385  virtual void OutputAttributes(ostream & str) const;
386  virtual void SetAttribute(const PString & attr, const PString & value);
387  virtual bool PostDecode(const OpalMediaFormatList & mediaFormats);
388 
389  protected:
390  unsigned m_PTime;
391  unsigned m_maxPTime;
392 };
393 
394 
395 #if OPAL_VIDEO
396 
398 //
399 // SDP media description for video media
400 //
401 
403 {
405  public:
407  virtual PString GetSDPMediaType() const;
408  virtual bool PreEncode();
409  virtual void OutputAttributes(ostream & str) const;
410  virtual void SetAttribute(const PString & attr, const PString & value);
411  virtual bool PostDecode(const OpalMediaFormatList & mediaFormats);
412  virtual OpalVideoFormat::ContentRole GetContentRole() const { return m_contentRole; }
413 
414  protected:
415  OpalVideoFormat::ContentRole m_contentRole;
416  unsigned m_contentMask;
417 };
418 
419 #endif // OPAL_VIDEO
420 
421 
423 //
424 // SDP media description for application media
425 //
426 
428 {
430  public:
432  virtual PCaselessString GetSDPTransportType() const;
433  virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
434  virtual PString GetSDPMediaType() const;
435 };
436 
438 
439 class SDPSessionDescription : public PObject, public SDPCommonAttributes
440 {
441  PCLASSINFO(SDPSessionDescription, PObject);
442  public:
444  time_t sessionId,
445  unsigned version,
446  const OpalTransportAddress & address
447  );
448 
449  void PrintOn(ostream & strm) const;
450  PString Encode() const;
451  bool Decode(const PString & str, const OpalMediaFormatList & mediaFormats);
452 
453  void SetSessionName(const PString & v);
454  PString GetSessionName() const { return sessionName; }
455 
456  void SetUserName(const PString & v);
457  PString GetUserName() const { return ownerUsername; }
458 
459  const SDPMediaDescriptionArray & GetMediaDescriptions() const { return mediaDescriptions; }
460 
461  SDPMediaDescription * GetMediaDescriptionByType(const OpalMediaType & rtpMediaType) const;
463  void AddMediaDescription(SDPMediaDescription * md) { mediaDescriptions.Append(PAssertNULL(md)); }
464 
465  virtual SDPMediaDescription::Direction GetDirection(unsigned) const;
466  bool IsHold() const;
467 
470  const OpalTransportAddress & address
471  );
472 
473  time_t GetOwnerSessionId() const { return ownerSessionId; }
474  void SetOwnerSessionId(time_t value) { ownerSessionId = value; }
475 
476  unsigned GetOwnerVersion() const { return ownerVersion; }
477  void SetOwnerVersion(unsigned value) { ownerVersion = value; }
478 
481 
483 
484  protected:
485  void ParseOwner(const PString & str);
486 
487  SDPMediaDescriptionArray mediaDescriptions;
488 
490  PString sessionName;
491 
492  PString ownerUsername;
494  unsigned ownerVersion;
497 };
498 
500 
501 
502 #endif // OPAL_SIP
503 
504 #endif // OPAL_SIP_SDP_H
505 
506 
507 // End of File ///////////////////////////////////////////////////////////////