PageRenderTime 41ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/opal-3.10.2/include/sip/sdp.h

#
C Header | 379 lines | 233 code | 90 blank | 56 comment | 0 complexity | 5aac21b4fcf6d328830229d8e3117993 MD5 | raw file
Possible License(s): BSD-3-Clause
  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. #ifndef OPAL_SIP_SDP_H
  32. #define OPAL_SIP_SDP_H
  33. #ifdef P_USE_PRAGMA
  34. #pragma interface
  35. #endif
  36. #include <opal/buildopts.h>
  37. #if OPAL_SIP
  38. #include <opal/transports.h>
  39. #include <opal/mediatype.h>
  40. #include <opal/mediafmt.h>
  41. #include <rtp/rtp.h>
  42. /////////////////////////////////////////////////////////
  43. class SDPBandwidth : public std::map<PCaselessString, unsigned>
  44. {
  45. public:
  46. unsigned & operator[](const PCaselessString & type);
  47. unsigned operator[](const PCaselessString & type) const;
  48. friend ostream & operator<<(ostream & out, const SDPBandwidth & bw);
  49. bool Parse(const PString & param);
  50. void SetMax(const PCaselessString & type, unsigned value);
  51. };
  52. /////////////////////////////////////////////////////////
  53. class SDPMediaDescription;
  54. class SDPMediaFormat : public PObject
  55. {
  56. PCLASSINFO(SDPMediaFormat, PObject);
  57. public:
  58. SDPMediaFormat(
  59. SDPMediaDescription & parent,
  60. RTP_DataFrame::PayloadTypes payloadType,
  61. const char * name = NULL
  62. );
  63. SDPMediaFormat(
  64. SDPMediaDescription & parent,
  65. const OpalMediaFormat & mediaFormat
  66. );
  67. virtual void PrintOn(ostream & str) const;
  68. RTP_DataFrame::PayloadTypes GetPayloadType() const { return payloadType; }
  69. const PCaselessString & GetEncodingName() const { return encodingName; }
  70. void SetEncodingName(const PString & v) { encodingName = v; }
  71. void SetFMTP(const PString & _fmtp);
  72. PString GetFMTP() const;
  73. unsigned GetClockRate(void) { return clockRate ; }
  74. void SetClockRate(unsigned v) { clockRate = v; }
  75. void SetParameters(const PString & v) { parameters = v; }
  76. void SetRTCP_FB(const PString & v) { m_rtcp_fb = v; }
  77. const OpalMediaFormat & GetMediaFormat() const { return m_mediaFormat; }
  78. OpalMediaFormat & GetWritableMediaFormat() { return m_mediaFormat; }
  79. bool PreEncode();
  80. bool PostDecode(const OpalMediaFormatList & mediaFormats, unsigned bandwidth);
  81. protected:
  82. void SetMediaFormatOptions(OpalMediaFormat & mediaFormat) const;
  83. OpalMediaFormat m_mediaFormat;
  84. SDPMediaDescription & m_parent;
  85. RTP_DataFrame::PayloadTypes payloadType;
  86. unsigned clockRate;
  87. PCaselessString encodingName;
  88. PString parameters;
  89. PString m_fmtp;
  90. PString m_rtcp_fb; // RFC4585
  91. };
  92. typedef PList<SDPMediaFormat> SDPMediaFormatList;
  93. /////////////////////////////////////////////////////////
  94. class SDPMediaDescription : public PObject
  95. {
  96. PCLASSINFO(SDPMediaDescription, PObject);
  97. public:
  98. // The following enum is arranged so it can be used as a bit mask,
  99. // e.g. GetDirection()&SendOnly indicates send is available
  100. enum Direction {
  101. Undefined = -1,
  102. Inactive,
  103. RecvOnly,
  104. SendOnly,
  105. SendRecv
  106. };
  107. SDPMediaDescription(
  108. const OpalTransportAddress & address,
  109. const OpalMediaType & mediaType
  110. );
  111. virtual bool PreEncode();
  112. virtual void Encode(const OpalTransportAddress & commonAddr, ostream & str) const;
  113. virtual bool PrintOn(ostream & strm, const PString & str) const;
  114. virtual bool Decode(const PStringArray & tokens);
  115. virtual bool Decode(char key, const PString & value);
  116. virtual bool PostDecode(const OpalMediaFormatList & mediaFormats);
  117. virtual SDPMediaDescription * CreateEmpty() const = 0;
  118. // return the string used within SDP to identify this media type
  119. virtual PString GetSDPMediaType() const = 0;
  120. // return the string used within SDP to identify the transport used by this media
  121. virtual PCaselessString GetSDPTransportType() const = 0;
  122. virtual const SDPMediaFormatList & GetSDPMediaFormats() const
  123. { return formats; }
  124. virtual OpalMediaFormatList GetMediaFormats() const;
  125. virtual void AddSDPMediaFormat(SDPMediaFormat * sdpMediaFormat);
  126. virtual void AddMediaFormat(const OpalMediaFormat & mediaFormat);
  127. virtual void AddMediaFormats(const OpalMediaFormatList & mediaFormats, const OpalMediaType & mediaType);
  128. virtual void SetAttribute(const PString & attr, const PString & value);
  129. virtual void SetDirection(const Direction & d) { direction = d; }
  130. virtual Direction GetDirection() const { return transportAddress.IsEmpty() ? Inactive : direction; }
  131. virtual const OpalTransportAddress & GetTransportAddress() const { return transportAddress; }
  132. virtual PBoolean SetTransportAddress(const OpalTransportAddress &t);
  133. virtual WORD GetPort() const { return port; }
  134. virtual OpalMediaType GetMediaType() const { return mediaType; }
  135. virtual unsigned GetBandwidth(const PString & type) const { return bandwidth[type]; }
  136. virtual void SetBandwidth(const PString & type, unsigned value) { bandwidth[type] = value; }
  137. virtual const SDPBandwidth & GetBandwidth() const { return bandwidth; }
  138. virtual void CreateSDPMediaFormats(const PStringArray & tokens);
  139. virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString) = 0;
  140. virtual PString GetSDPPortList() const = 0;
  141. virtual void ProcessMediaOptions(SDPMediaFormat & sdpFormat, const OpalMediaFormat & mediaFormat);
  142. unsigned GetPTime () const { return ptime; }
  143. unsigned GetMaxPTime () const { return maxptime; }
  144. protected:
  145. virtual SDPMediaFormat * FindFormat(PString & str) const;
  146. OpalTransportAddress transportAddress;
  147. Direction direction;
  148. WORD port;
  149. WORD portCount;
  150. OpalMediaType mediaType;
  151. SDPMediaFormatList formats;
  152. SDPBandwidth bandwidth;
  153. unsigned ptime;
  154. unsigned maxptime;
  155. };
  156. PARRAY(SDPMediaDescriptionArray, SDPMediaDescription);
  157. class SDPDummyMediaDescription : public SDPMediaDescription
  158. {
  159. PCLASSINFO(SDPDummyMediaDescription, SDPMediaDescription);
  160. public:
  161. SDPDummyMediaDescription(const OpalTransportAddress & address, const PStringArray & tokens);
  162. virtual SDPMediaDescription * CreateEmpty() const;
  163. virtual PString GetSDPMediaType() const;
  164. virtual PCaselessString GetSDPTransportType() const;
  165. virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
  166. virtual PString GetSDPPortList() const;
  167. private:
  168. PStringArray m_tokens;
  169. };
  170. /////////////////////////////////////////////////////////
  171. //
  172. // SDP media description for media classes using RTP/AVP transport (audio and video)
  173. //
  174. class SDPRTPAVPMediaDescription : public SDPMediaDescription
  175. {
  176. PCLASSINFO(SDPRTPAVPMediaDescription, SDPMediaDescription);
  177. public:
  178. SDPRTPAVPMediaDescription(const OpalTransportAddress & address, const OpalMediaType & mediaType);
  179. virtual PCaselessString GetSDPTransportType() const;
  180. virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
  181. virtual PString GetSDPPortList() const;
  182. virtual bool PrintOn(ostream & str, const PString & connectString) const;
  183. virtual void SetAttribute(const PString & attr, const PString & value);
  184. };
  185. /////////////////////////////////////////////////////////
  186. //
  187. // SDP media description for audio media
  188. //
  189. class SDPAudioMediaDescription : public SDPRTPAVPMediaDescription
  190. {
  191. PCLASSINFO(SDPAudioMediaDescription, SDPRTPAVPMediaDescription);
  192. public:
  193. SDPAudioMediaDescription(const OpalTransportAddress & address);
  194. virtual SDPMediaDescription * CreateEmpty() const;
  195. virtual PString GetSDPMediaType() const;
  196. virtual bool PrintOn(ostream & str, const PString & connectString) const;
  197. virtual void SetAttribute(const PString & attr, const PString & value);
  198. bool GetOfferPTime() const { return m_offerPTime; }
  199. void SetOfferPTime(bool value) { m_offerPTime = value; }
  200. protected:
  201. bool m_offerPTime;
  202. };
  203. /////////////////////////////////////////////////////////
  204. //
  205. // SDP media description for video media
  206. //
  207. class SDPVideoMediaDescription : public SDPRTPAVPMediaDescription
  208. {
  209. PCLASSINFO(SDPVideoMediaDescription, SDPRTPAVPMediaDescription);
  210. public:
  211. SDPVideoMediaDescription(const OpalTransportAddress & address);
  212. virtual SDPMediaDescription * CreateEmpty() const;
  213. virtual PString GetSDPMediaType() const;
  214. virtual bool PreEncode();
  215. virtual bool PrintOn(ostream & str, const PString & connectString) const;
  216. void SetAttribute(const PString & attr, const PString & value);
  217. };
  218. /////////////////////////////////////////////////////////
  219. //
  220. // SDP media description for application media
  221. //
  222. class SDPApplicationMediaDescription : public SDPMediaDescription
  223. {
  224. PCLASSINFO(SDPApplicationMediaDescription, SDPMediaDescription);
  225. public:
  226. SDPApplicationMediaDescription(const OpalTransportAddress & address);
  227. virtual PCaselessString GetSDPTransportType() const;
  228. virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
  229. virtual SDPMediaDescription * CreateEmpty() const;
  230. virtual PString GetSDPMediaType() const;
  231. virtual PString GetSDPPortList() const;
  232. };
  233. /////////////////////////////////////////////////////////
  234. class SDPSessionDescription : public PObject
  235. {
  236. PCLASSINFO(SDPSessionDescription, PObject);
  237. public:
  238. SDPSessionDescription(
  239. time_t sessionId,
  240. unsigned version,
  241. const OpalTransportAddress & address
  242. );
  243. void PrintOn(ostream & strm) const;
  244. PString Encode() const;
  245. bool Decode(const PString & str, const OpalMediaFormatList & mediaFormats);
  246. void SetSessionName(const PString & v);
  247. PString GetSessionName() const { return sessionName; }
  248. void SetUserName(const PString & v);
  249. PString GetUserName() const { return ownerUsername; }
  250. const SDPMediaDescriptionArray & GetMediaDescriptions() const { return mediaDescriptions; }
  251. SDPMediaDescription * GetMediaDescriptionByType(const OpalMediaType & rtpMediaType) const;
  252. SDPMediaDescription * GetMediaDescriptionByIndex(PINDEX i) const;
  253. void AddMediaDescription(SDPMediaDescription * md) { mediaDescriptions.Append(md); }
  254. void SetDirection(const SDPMediaDescription::Direction & d) { direction = d; }
  255. SDPMediaDescription::Direction GetDirection(unsigned) const;
  256. bool IsHold() const;
  257. const OpalTransportAddress & GetDefaultConnectAddress() const { return defaultConnectAddress; }
  258. void SetDefaultConnectAddress(
  259. const OpalTransportAddress & address
  260. );
  261. time_t GetOwnerSessionId() const { return ownerSessionId; }
  262. void SetOwnerSessionId(time_t value) { ownerSessionId = value; }
  263. PINDEX GetOwnerVersion() const { return ownerVersion; }
  264. void SetOwnerVersion(PINDEX value) { ownerVersion = value; }
  265. OpalTransportAddress GetOwnerAddress() const { return ownerAddress; }
  266. void SetOwnerAddress(OpalTransportAddress addr) { ownerAddress = addr; }
  267. unsigned GetBandwidth(const PString & type) const { return bandwidth[type]; }
  268. void SetBandwidth(const PString & type, unsigned value) { bandwidth[type] = value; }
  269. OpalMediaFormatList GetMediaFormats() const;
  270. static const PCaselessString & ConferenceTotalBandwidthType();
  271. static const PCaselessString & ApplicationSpecificBandwidthType();
  272. static const PCaselessString & TransportIndependentBandwidthType(); // RFC3890
  273. protected:
  274. void ParseOwner(const PString & str);
  275. SDPMediaDescriptionArray mediaDescriptions;
  276. SDPMediaDescription::Direction direction;
  277. PINDEX protocolVersion;
  278. PString sessionName;
  279. PString ownerUsername;
  280. time_t ownerSessionId;
  281. unsigned ownerVersion;
  282. OpalTransportAddress ownerAddress;
  283. OpalTransportAddress defaultConnectAddress;
  284. SDPBandwidth bandwidth;
  285. };
  286. /////////////////////////////////////////////////////////
  287. #endif // OPAL_SIP
  288. #endif // OPAL_SIP_SDP_H
  289. // End of File ///////////////////////////////////////////////////////////////