OPAL  Version 3.12.9
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: 30956 $
28  * $Author: rjongbloed $
29  * $Date: 2013-11-25 11:51:07 +1100 (Mon, 25 Nov 2013) $
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 AddRTCP_FB(const PString & str) { m_rtcp_fb.FromString(str, false); }
121  void SetRTCP_FB(const OpalVideoFormat::RTCPFeedback & v) { m_rtcp_fb = v; }
122  OpalVideoFormat::RTCPFeedback GetRTCP_FB() const { return m_rtcp_fb; }
123 #endif
124 
125  const OpalMediaFormat & GetMediaFormat() const { return m_mediaFormat; }
127 
128  bool PreEncode();
129  bool PostDecode(const OpalMediaFormatList & mediaFormats, unsigned bandwidth);
130 
131  protected:
132  void SetMediaFormatOptions(OpalMediaFormat & mediaFormat) const;
133 
135 
138  unsigned clockRate;
139  PCaselessString encodingName;
140  PString parameters;
141  PString m_fmtp;
142 #if OPAL_VIDEO
143  OpalVideoFormat::RTCPFeedback m_rtcp_fb; // RFC4585
144 #endif
145 };
146 
147 typedef PList<SDPMediaFormat> SDPMediaFormatList;
148 
149 
151 
153 {
154  public:
155  // The following enum is arranged so it can be used as a bit mask,
156  // e.g. GetDirection()&SendOnly indicates send is available
157  enum Direction {
158  Undefined = -1,
163  };
164 
167  { }
168 
169  virtual ~SDPCommonAttributes() { }
170 
171  virtual void SetDirection(const Direction & d) { m_direction = d; }
172  virtual Direction GetDirection() const { return m_direction; }
173 
174  virtual OpalBandwidth GetBandwidth(const PString & type) const { return m_bandwidth[type]; }
175  virtual void SetBandwidth(const PString & type, OpalBandwidth value) { m_bandwidth[type] = value; }
176 
177  virtual const SDPBandwidth & GetBandwidth() const { return m_bandwidth; }
178 
179  virtual const RTPExtensionHeaders & GetExtensionHeaders() const { return m_extensionHeaders; }
180  virtual void SetExtensionHeader(const RTPExtensionHeaderInfo & ext) { m_extensionHeaders.insert(ext); }
181 
182  virtual void ParseAttribute(const PString & value);
183  virtual void SetAttribute(const PString & attr, const PString & value);
184 
185  virtual void OutputAttributes(ostream & strm) const;
186 
187  static const PCaselessString & ConferenceTotalBandwidthType();
188  static const PCaselessString & ApplicationSpecificBandwidthType();
189  static const PCaselessString & TransportIndependentBandwidthType(); // RFC3890
190 
191  protected:
195 };
196 
197 
199 
200 class SDPMediaDescription : public PObject, public SDPCommonAttributes
201 {
202  PCLASSINFO(SDPMediaDescription, PObject);
203  public:
205  const OpalTransportAddress & address,
206  const OpalMediaType & mediaType
207  );
208 
209  virtual bool PreEncode();
210  virtual void Encode(const OpalTransportAddress & commonAddr, ostream & str) const;
211 
212  virtual bool Decode(const PStringArray & tokens);
213  virtual bool Decode(char key, const PString & value);
214  virtual bool PostDecode(const OpalMediaFormatList & mediaFormats);
215 
216  // return the string used within SDP to identify this media type
217  virtual PString GetSDPMediaType() const = 0;
218 
219  // return the string used within SDP to identify the transport used by this media
220  virtual PCaselessString GetSDPTransportType() const = 0;
221 
222  virtual const SDPMediaFormatList & GetSDPMediaFormats() const
223  { return formats; }
224 
225  virtual OpalMediaFormatList GetMediaFormats() const;
226 
227  virtual void AddSDPMediaFormat(SDPMediaFormat * sdpMediaFormat);
228 
229  virtual void AddMediaFormat(const OpalMediaFormat & mediaFormat);
230  virtual void AddMediaFormats(const OpalMediaFormatList & mediaFormats, const OpalMediaType & mediaType);
231 
232  virtual void SetCryptoKeys(OpalMediaCryptoKeyList & cryptoKeys);
233  virtual OpalMediaCryptoKeyList GetCryptoKeys() const;
234 
235  virtual void SetAttribute(const PString & attr, const PString & value);
236 
237  virtual Direction GetDirection() const { return m_transportAddress.IsEmpty() ? Inactive : m_direction; }
238 
239  virtual const OpalTransportAddress & GetTransportAddress() const { return m_transportAddress; }
240  virtual PBoolean SetTransportAddress(const OpalTransportAddress &t);
241 
242  virtual WORD GetPort() const { return m_port; }
243 
244  virtual OpalMediaType GetMediaType() const { return m_mediaType; }
245 
246  virtual void CreateSDPMediaFormats(const PStringArray & tokens);
247  virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString) = 0;
248 
249  virtual PString GetSDPPortList() const;
250 
251  virtual void ProcessMediaOptions(SDPMediaFormat & sdpFormat, const OpalMediaFormat & mediaFormat);
252 
253 #if OPAL_VIDEO
254  virtual OpalVideoFormat::ContentRole GetContentRole() const { return OpalVideoFormat::eNoRole; }
255 #endif
256 
257  void SetOptionStrings(const PStringOptions & options) { m_stringOptions = options; }
258  const PStringOptions & GetOptionStrings() const { return m_stringOptions; }
259 
260  virtual void Copy(SDPMediaDescription & mediaDescription);
261 
262  protected:
263  virtual SDPMediaFormat * FindFormat(PString & str) const;
264 
266  PCaselessString m_transportType;
267  PStringOptions m_stringOptions;
268  WORD m_port;
271 
273 };
274 
275 PARRAY(SDPMediaDescriptionArray, SDPMediaDescription);
276 
277 
279 {
281  public:
282  SDPDummyMediaDescription(const OpalTransportAddress & address, const PStringArray & tokens);
283  virtual PString GetSDPMediaType() const;
284  virtual PCaselessString GetSDPTransportType() const;
285  virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
286  virtual PString GetSDPPortList() const;
287  virtual void Copy(SDPMediaDescription & mediaDescription);
288 
289  private:
290  PStringArray m_tokens;
291 };
292 
293 
295 {
296  PCLASSINFO(SDPDummySession, OpalMediaSession)
297  public:
298  SDPDummySession(const Init & init);
299  static const PCaselessString & SessionType();
300  virtual const PCaselessString & GetSessionType() const;
302  virtual OpalMediaStream * CreateMediaStream(const OpalMediaFormat & mediaFormat, unsigned sessionID, bool isSource);
303 
304  private:
305  PStringArray m_tokens;
306 };
307 
308 
309 class SDPCryptoSuite : public PObject
310 {
311  PCLASSINFO(SDPCryptoSuite, PObject)
312  public:
313  SDPCryptoSuite(unsigned tag);
314 
315  bool SetKeyInfo(const OpalMediaCryptoKeyInfo & keyInfo);
317 
318  bool Decode(const PString & attrib);
319  void PrintOn(ostream & strm) const;
320 
321  struct KeyParam {
322  KeyParam(const PString & keySalt)
323  : m_keySalt(keySalt)
324  , m_lifetime(0)
325  , m_mkiIndex(0)
326  , m_mkiLength(0)
327  { }
328 
329  PString m_keySalt;
330  PUInt64 m_lifetime;
331  unsigned m_mkiIndex;
332  unsigned m_mkiLength;
333  };
334 
335  unsigned GetTag() const { return m_tag; }
336  const PString & GetName() const { return m_suiteName; }
337 
338  protected:
339  unsigned m_tag;
340  PString m_suiteName;
341  list<KeyParam> m_keyParams;
342  PStringOptions m_sessionParams;
343 };
344 
346 //
347 // SDP media description for media classes using RTP/AVP transport (audio and video)
348 //
349 
351 {
353  public:
354  SDPRTPAVPMediaDescription(const OpalTransportAddress & address, const OpalMediaType & mediaType);
355  virtual bool Decode(const PStringArray & tokens);
356  virtual PCaselessString GetSDPTransportType() const;
357  virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
358  virtual PString GetSDPPortList() const;
359  virtual bool PreEncode();
360  virtual void OutputAttributes(ostream & str) const;
361  virtual void SetCryptoKeys(OpalMediaCryptoKeyList & cryptoKeys);
362  virtual OpalMediaCryptoKeyList GetCryptoKeys() const;
363  virtual void SetAttribute(const PString & attr, const PString & value);
364 
365  void EnableFeedback() { m_enableFeedback = true; }
366 
367  protected:
369 #if OPAL_VIDEO
370  OpalVideoFormat::RTCPFeedback m_rtcp_fb;
371 #endif
372  PList<SDPCryptoSuite> m_cryptoSuites;
373 };
374 
376 //
377 // SDP media description for audio media
378 //
379 
381 {
383  public:
385  virtual PString GetSDPMediaType() const;
386  virtual void OutputAttributes(ostream & str) const;
387  virtual void SetAttribute(const PString & attr, const PString & value);
388  virtual bool PostDecode(const OpalMediaFormatList & mediaFormats);
389 
390  protected:
391  unsigned m_PTime;
392  unsigned m_maxPTime;
393 };
394 
395 
396 #if OPAL_VIDEO
397 
399 //
400 // SDP media description for video media
401 //
402 
404 {
406  public:
408  virtual PString GetSDPMediaType() const;
409  virtual bool PreEncode();
410  virtual void OutputAttributes(ostream & str) const;
411  virtual void SetAttribute(const PString & attr, const PString & value);
412  virtual bool PostDecode(const OpalMediaFormatList & mediaFormats);
413  virtual OpalVideoFormat::ContentRole GetContentRole() const { return m_contentRole; }
414 
415  protected:
416  OpalVideoFormat::ContentRole m_contentRole;
417  unsigned m_contentMask;
418 };
419 
420 #endif // OPAL_VIDEO
421 
422 
424 //
425 // SDP media description for application media
426 //
427 
429 {
431  public:
433  virtual PCaselessString GetSDPTransportType() const;
434  virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
435  virtual PString GetSDPMediaType() const;
436 };
437 
439 
440 class SDPSessionDescription : public PObject, public SDPCommonAttributes
441 {
442  PCLASSINFO_WITH_CLONE(SDPSessionDescription, PObject);
443  public:
445  time_t sessionId,
446  unsigned version,
447  const OpalTransportAddress & address
448  );
449 
450  virtual void PrintOn(ostream & strm) const;
451  virtual PString Encode() const;
452  virtual bool Decode(const PString & str, const OpalMediaFormatList & mediaFormats);
453 
454  void SetSessionName(const PString & v);
455  PString GetSessionName() const { return sessionName; }
456 
457  void SetUserName(const PString & v);
458  PString GetUserName() const { return ownerUsername; }
459 
460  const SDPMediaDescriptionArray & GetMediaDescriptions() const { return mediaDescriptions; }
461 
462  SDPMediaDescription * GetMediaDescriptionByType(const OpalMediaType & rtpMediaType) const;
464  void AddMediaDescription(SDPMediaDescription * md) { mediaDescriptions.Append(PAssertNULL(md)); }
465 
466  virtual SDPMediaDescription::Direction GetDirection(unsigned) const;
467  bool IsHold() const;
468 
471  const OpalTransportAddress & address
472  );
473 
474  time_t GetOwnerSessionId() const { return ownerSessionId; }
475  void SetOwnerSessionId(time_t value) { ownerSessionId = value; }
476 
477  unsigned GetOwnerVersion() const { return ownerVersion; }
478  void SetOwnerVersion(unsigned value) { ownerVersion = value; }
479 
482 
484 
485  protected:
486  void ParseOwner(const PString & str);
487 
488  SDPMediaDescriptionArray mediaDescriptions;
489 
491  PString sessionName;
492 
493  PString ownerUsername;
495  unsigned ownerVersion;
498 };
499 
501 
502 
503 #endif // OPAL_SIP
504 
505 #endif // OPAL_SIP_SDP_H
506 
507 
508 // End of File ///////////////////////////////////////////////////////////////