OPAL Version 3.10.2
|
00001 /* 00002 * sdp.h 00003 * 00004 * Session Description Protocol 00005 * 00006 * Open Phone Abstraction Library (OPAL) 00007 * Formally known as the Open H323 project. 00008 * 00009 * Copyright (c) 2001 Equivalence Pty. Ltd. 00010 * 00011 * The contents of this file are subject to the Mozilla Public License 00012 * Version 1.0 (the "License"); you may not use this file except in 00013 * compliance with the License. You may obtain a copy of the License at 00014 * http://www.mozilla.org/MPL/ 00015 * 00016 * Software distributed under the License is distributed on an "AS IS" 00017 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00018 * the License for the specific language governing rights and limitations 00019 * under the License. 00020 * 00021 * The Original Code is Open Phone Abstraction Library. 00022 * 00023 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 00024 * 00025 * Contributor(s): ______________________________________. 00026 * 00027 * $Revision: 25734 $ 00028 * $Author: rjongbloed $ 00029 * $Date: 2011-05-10 21:41:47 -0500 (Tue, 10 May 2011) $ 00030 */ 00031 00032 #ifndef OPAL_SIP_SDP_H 00033 #define OPAL_SIP_SDP_H 00034 00035 #ifdef P_USE_PRAGMA 00036 #pragma interface 00037 #endif 00038 00039 #include <opal/buildopts.h> 00040 00041 #if OPAL_SIP 00042 00043 #include <opal/transports.h> 00044 #include <opal/mediatype.h> 00045 #include <opal/mediafmt.h> 00046 #include <rtp/rtp.h> 00047 00049 00050 class SDPBandwidth : public std::map<PCaselessString, unsigned> 00051 { 00052 public: 00053 unsigned & operator[](const PCaselessString & type); 00054 unsigned operator[](const PCaselessString & type) const; 00055 friend ostream & operator<<(ostream & out, const SDPBandwidth & bw); 00056 bool Parse(const PString & param); 00057 void SetMax(const PCaselessString & type, unsigned value); 00058 }; 00059 00061 00062 class SDPMediaDescription; 00063 00064 class SDPMediaFormat : public PObject 00065 { 00066 PCLASSINFO(SDPMediaFormat, PObject); 00067 public: 00068 SDPMediaFormat( 00069 SDPMediaDescription & parent, 00070 RTP_DataFrame::PayloadTypes payloadType, 00071 const char * name = NULL 00072 ); 00073 00074 SDPMediaFormat( 00075 SDPMediaDescription & parent, 00076 const OpalMediaFormat & mediaFormat 00077 ); 00078 00079 virtual void PrintOn(ostream & str) const; 00080 00081 RTP_DataFrame::PayloadTypes GetPayloadType() const { return payloadType; } 00082 00083 const PCaselessString & GetEncodingName() const { return encodingName; } 00084 void SetEncodingName(const PString & v) { encodingName = v; } 00085 00086 void SetFMTP(const PString & _fmtp); 00087 PString GetFMTP() const; 00088 00089 unsigned GetClockRate(void) { return clockRate ; } 00090 void SetClockRate(unsigned v) { clockRate = v; } 00091 00092 void SetParameters(const PString & v) { parameters = v; } 00093 void SetRTCP_FB(const PString & v) { m_rtcp_fb = v; } 00094 00095 const OpalMediaFormat & GetMediaFormat() const { return m_mediaFormat; } 00096 OpalMediaFormat & GetWritableMediaFormat() { return m_mediaFormat; } 00097 00098 bool PreEncode(); 00099 bool PostDecode(const OpalMediaFormatList & mediaFormats, unsigned bandwidth); 00100 00101 protected: 00102 void SetMediaFormatOptions(OpalMediaFormat & mediaFormat) const; 00103 00104 OpalMediaFormat m_mediaFormat; 00105 00106 SDPMediaDescription & m_parent; 00107 RTP_DataFrame::PayloadTypes payloadType; 00108 unsigned clockRate; 00109 PCaselessString encodingName; 00110 PString parameters; 00111 PString m_fmtp; 00112 PString m_rtcp_fb; // RFC4585 00113 }; 00114 00115 typedef PList<SDPMediaFormat> SDPMediaFormatList; 00116 00118 00119 class SDPMediaDescription : public PObject 00120 { 00121 PCLASSINFO(SDPMediaDescription, PObject); 00122 public: 00123 // The following enum is arranged so it can be used as a bit mask, 00124 // e.g. GetDirection()&SendOnly indicates send is available 00125 enum Direction { 00126 Undefined = -1, 00127 Inactive, 00128 RecvOnly, 00129 SendOnly, 00130 SendRecv 00131 }; 00132 00133 SDPMediaDescription( 00134 const OpalTransportAddress & address, 00135 const OpalMediaType & mediaType 00136 ); 00137 00138 virtual bool PreEncode(); 00139 virtual void Encode(const OpalTransportAddress & commonAddr, ostream & str) const; 00140 virtual bool PrintOn(ostream & strm, const PString & str) const; 00141 00142 virtual bool Decode(const PStringArray & tokens); 00143 virtual bool Decode(char key, const PString & value); 00144 virtual bool PostDecode(const OpalMediaFormatList & mediaFormats); 00145 00146 virtual SDPMediaDescription * CreateEmpty() const = 0; 00147 00148 // return the string used within SDP to identify this media type 00149 virtual PString GetSDPMediaType() const = 0; 00150 00151 // return the string used within SDP to identify the transport used by this media 00152 virtual PCaselessString GetSDPTransportType() const = 0; 00153 00154 virtual const SDPMediaFormatList & GetSDPMediaFormats() const 00155 { return formats; } 00156 00157 virtual OpalMediaFormatList GetMediaFormats() const; 00158 00159 virtual void AddSDPMediaFormat(SDPMediaFormat * sdpMediaFormat); 00160 00161 virtual void AddMediaFormat(const OpalMediaFormat & mediaFormat); 00162 virtual void AddMediaFormats(const OpalMediaFormatList & mediaFormats, const OpalMediaType & mediaType); 00163 00164 virtual void SetAttribute(const PString & attr, const PString & value); 00165 00166 virtual void SetDirection(const Direction & d) { direction = d; } 00167 virtual Direction GetDirection() const { return transportAddress.IsEmpty() ? Inactive : direction; } 00168 00169 virtual const OpalTransportAddress & GetTransportAddress() const { return transportAddress; } 00170 virtual PBoolean SetTransportAddress(const OpalTransportAddress &t); 00171 00172 virtual WORD GetPort() const { return port; } 00173 00174 virtual OpalMediaType GetMediaType() const { return mediaType; } 00175 00176 virtual unsigned GetBandwidth(const PString & type) const { return bandwidth[type]; } 00177 virtual void SetBandwidth(const PString & type, unsigned value) { bandwidth[type] = value; } 00178 00179 virtual const SDPBandwidth & GetBandwidth() const { return bandwidth; } 00180 00181 virtual void CreateSDPMediaFormats(const PStringArray & tokens); 00182 virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString) = 0; 00183 00184 virtual PString GetSDPPortList() const = 0; 00185 00186 virtual void ProcessMediaOptions(SDPMediaFormat & sdpFormat, const OpalMediaFormat & mediaFormat); 00187 00188 unsigned GetPTime () const { return ptime; } 00189 unsigned GetMaxPTime () const { return maxptime; } 00190 00191 protected: 00192 virtual SDPMediaFormat * FindFormat(PString & str) const; 00193 00194 OpalTransportAddress transportAddress; 00195 Direction direction; 00196 WORD port; 00197 WORD portCount; 00198 OpalMediaType mediaType; 00199 00200 SDPMediaFormatList formats; 00201 SDPBandwidth bandwidth; 00202 unsigned ptime; 00203 unsigned maxptime; 00204 }; 00205 00206 PARRAY(SDPMediaDescriptionArray, SDPMediaDescription); 00207 00208 00209 class SDPDummyMediaDescription : public SDPMediaDescription 00210 { 00211 PCLASSINFO(SDPDummyMediaDescription, SDPMediaDescription); 00212 public: 00213 SDPDummyMediaDescription(const OpalTransportAddress & address, const PStringArray & tokens); 00214 virtual SDPMediaDescription * CreateEmpty() const; 00215 virtual PString GetSDPMediaType() const; 00216 virtual PCaselessString GetSDPTransportType() const; 00217 virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString); 00218 virtual PString GetSDPPortList() const; 00219 00220 private: 00221 PStringArray m_tokens; 00222 }; 00223 00224 00226 // 00227 // SDP media description for media classes using RTP/AVP transport (audio and video) 00228 // 00229 00230 class SDPRTPAVPMediaDescription : public SDPMediaDescription 00231 { 00232 PCLASSINFO(SDPRTPAVPMediaDescription, SDPMediaDescription); 00233 public: 00234 SDPRTPAVPMediaDescription(const OpalTransportAddress & address, const OpalMediaType & mediaType); 00235 virtual PCaselessString GetSDPTransportType() const; 00236 virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString); 00237 virtual PString GetSDPPortList() const; 00238 virtual bool PrintOn(ostream & str, const PString & connectString) const; 00239 virtual void SetAttribute(const PString & attr, const PString & value); 00240 }; 00241 00243 // 00244 // SDP media description for audio media 00245 // 00246 00247 class SDPAudioMediaDescription : public SDPRTPAVPMediaDescription 00248 { 00249 PCLASSINFO(SDPAudioMediaDescription, SDPRTPAVPMediaDescription); 00250 public: 00251 SDPAudioMediaDescription(const OpalTransportAddress & address); 00252 virtual SDPMediaDescription * CreateEmpty() const; 00253 virtual PString GetSDPMediaType() const; 00254 virtual bool PrintOn(ostream & str, const PString & connectString) const; 00255 virtual void SetAttribute(const PString & attr, const PString & value); 00256 00257 bool GetOfferPTime() const { return m_offerPTime; } 00258 void SetOfferPTime(bool value) { m_offerPTime = value; } 00259 00260 protected: 00261 bool m_offerPTime; 00262 }; 00263 00265 // 00266 // SDP media description for video media 00267 // 00268 00269 class SDPVideoMediaDescription : public SDPRTPAVPMediaDescription 00270 { 00271 PCLASSINFO(SDPVideoMediaDescription, SDPRTPAVPMediaDescription); 00272 public: 00273 SDPVideoMediaDescription(const OpalTransportAddress & address); 00274 virtual SDPMediaDescription * CreateEmpty() const; 00275 virtual PString GetSDPMediaType() const; 00276 virtual bool PreEncode(); 00277 virtual bool PrintOn(ostream & str, const PString & connectString) const; 00278 void SetAttribute(const PString & attr, const PString & value); 00279 }; 00280 00282 // 00283 // SDP media description for application media 00284 // 00285 00286 class SDPApplicationMediaDescription : public SDPMediaDescription 00287 { 00288 PCLASSINFO(SDPApplicationMediaDescription, SDPMediaDescription); 00289 public: 00290 SDPApplicationMediaDescription(const OpalTransportAddress & address); 00291 virtual PCaselessString GetSDPTransportType() const; 00292 virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString); 00293 virtual SDPMediaDescription * CreateEmpty() const; 00294 virtual PString GetSDPMediaType() const; 00295 virtual PString GetSDPPortList() const; 00296 }; 00297 00299 00300 class SDPSessionDescription : public PObject 00301 { 00302 PCLASSINFO(SDPSessionDescription, PObject); 00303 public: 00304 SDPSessionDescription( 00305 time_t sessionId, 00306 unsigned version, 00307 const OpalTransportAddress & address 00308 ); 00309 00310 void PrintOn(ostream & strm) const; 00311 PString Encode() const; 00312 bool Decode(const PString & str, const OpalMediaFormatList & mediaFormats); 00313 00314 void SetSessionName(const PString & v); 00315 PString GetSessionName() const { return sessionName; } 00316 00317 void SetUserName(const PString & v); 00318 PString GetUserName() const { return ownerUsername; } 00319 00320 const SDPMediaDescriptionArray & GetMediaDescriptions() const { return mediaDescriptions; } 00321 00322 SDPMediaDescription * GetMediaDescriptionByType(const OpalMediaType & rtpMediaType) const; 00323 SDPMediaDescription * GetMediaDescriptionByIndex(PINDEX i) const; 00324 void AddMediaDescription(SDPMediaDescription * md) { mediaDescriptions.Append(md); } 00325 00326 void SetDirection(const SDPMediaDescription::Direction & d) { direction = d; } 00327 SDPMediaDescription::Direction GetDirection(unsigned) const; 00328 bool IsHold() const; 00329 00330 const OpalTransportAddress & GetDefaultConnectAddress() const { return defaultConnectAddress; } 00331 void SetDefaultConnectAddress( 00332 const OpalTransportAddress & address 00333 ); 00334 00335 time_t GetOwnerSessionId() const { return ownerSessionId; } 00336 void SetOwnerSessionId(time_t value) { ownerSessionId = value; } 00337 00338 PINDEX GetOwnerVersion() const { return ownerVersion; } 00339 void SetOwnerVersion(PINDEX value) { ownerVersion = value; } 00340 00341 OpalTransportAddress GetOwnerAddress() const { return ownerAddress; } 00342 void SetOwnerAddress(OpalTransportAddress addr) { ownerAddress = addr; } 00343 00344 unsigned GetBandwidth(const PString & type) const { return bandwidth[type]; } 00345 void SetBandwidth(const PString & type, unsigned value) { bandwidth[type] = value; } 00346 00347 OpalMediaFormatList GetMediaFormats() const; 00348 00349 static const PCaselessString & ConferenceTotalBandwidthType(); 00350 static const PCaselessString & ApplicationSpecificBandwidthType(); 00351 static const PCaselessString & TransportIndependentBandwidthType(); // RFC3890 00352 00353 protected: 00354 void ParseOwner(const PString & str); 00355 00356 SDPMediaDescriptionArray mediaDescriptions; 00357 SDPMediaDescription::Direction direction; 00358 00359 PINDEX protocolVersion; 00360 PString sessionName; 00361 00362 PString ownerUsername; 00363 time_t ownerSessionId; 00364 unsigned ownerVersion; 00365 OpalTransportAddress ownerAddress; 00366 OpalTransportAddress defaultConnectAddress; 00367 00368 SDPBandwidth bandwidth; 00369 }; 00370 00372 00373 00374 #endif // OPAL_SIP 00375 00376 #endif // OPAL_SIP_SDP_H 00377 00378 00379 // End of File ///////////////////////////////////////////////////////////////