sdp.h

Go to the documentation of this file.
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: 22902 $
00028  * $Author: rjongbloed $
00029  * $Date: 2009-06-16 04:58:09 +0000 (Tue, 16 Jun 2009) $
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<PString, unsigned>
00051 {
00052   public:
00053     unsigned & operator[](const PString & type);
00054     unsigned operator[](const PString & type) const;
00055     friend ostream & operator<<(ostream & out, const SDPBandwidth & bw);
00056     bool Parse(const PString & param);
00057     void SetMin(const PString & 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     PString 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 
00094     void SetPacketTime(const PString & optionName, unsigned ptime);
00095 
00096     const OpalMediaFormat & GetMediaFormat() const;
00097 
00098     bool PreEncode();
00099     bool PostDecode(unsigned bandwidth);
00100 
00101   protected:
00102     void InitialiseMediaFormat();
00103 
00104     OpalMediaFormat mediaFormat;
00105 
00106     SDPMediaDescription & m_parent;
00107     RTP_DataFrame::PayloadTypes payloadType;
00108     unsigned clockRate;
00109     PString encodingName;
00110     PString parameters;
00111     PString fmtp;
00112 };
00113 
00114 PLIST(SDPMediaFormatList, SDPMediaFormat);
00115 
00117 
00118 class SDPMediaDescription : public PObject
00119 {
00120   PCLASSINFO(SDPMediaDescription, PObject);
00121   public:
00122     // The following enum is arranged so it can be used as a bit mask,
00123     // e.g. GetDirection()&SendOnly indicates send is available
00124     enum Direction {
00125       Undefined = -1,
00126       Inactive,
00127       RecvOnly,
00128       SendOnly,
00129       SendRecv
00130     };
00131 
00132     SDPMediaDescription(
00133       const OpalTransportAddress & address
00134     );
00135 
00136     virtual bool PreEncode();
00137     virtual void Encode(const OpalTransportAddress & commonAddr, ostream & str) const;
00138     virtual bool PrintOn(ostream & strm, const PString & str) const;
00139 
00140     virtual bool Decode(const PStringArray & tokens);
00141     virtual bool Decode(char key, const PString & value);
00142     virtual bool PostDecode();
00143 
00144     // return the string used within SDP to identify this media type
00145     virtual PString GetSDPMediaType() const = 0;
00146 
00147     // return the string used within SDP to identify the transport used by this media
00148     virtual PCaselessString GetSDPTransportType() const = 0;
00149 
00150     virtual const SDPMediaFormatList & GetSDPMediaFormats() const
00151       { return formats; }
00152 
00153     virtual OpalMediaFormatList GetMediaFormats() const;
00154 
00155     virtual void AddSDPMediaFormat(SDPMediaFormat * sdpMediaFormat);
00156 
00157     virtual void AddMediaFormat(const OpalMediaFormat & mediaFormat);
00158     virtual void AddMediaFormats(const OpalMediaFormatList & mediaFormats, const OpalMediaType & mediaType);
00159 
00160     virtual void SetAttribute(const PString & attr, const PString & value);
00161 
00162     virtual void SetDirection(const Direction & d) { direction = d; }
00163     virtual Direction GetDirection() const { return transportAddress.IsEmpty() ? Inactive : direction; }
00164 
00165     virtual const OpalTransportAddress & GetTransportAddress() const { return transportAddress; }
00166     virtual PBoolean SetTransportAddress(const OpalTransportAddress &t);
00167 
00168     virtual WORD GetPort() const { return port; }
00169 
00170     virtual OpalMediaType GetMediaType() const { return mediaType; }
00171 
00172     virtual unsigned GetBandwidth(const PString & type) const { return bandwidth[type]; }
00173     virtual void SetBandwidth(const PString & type, unsigned value) { bandwidth[type] = value; }
00174 
00175     virtual const SDPBandwidth & GetBandwidth() const { return bandwidth; }
00176 
00177     virtual void RemoveSDPMediaFormat(const SDPMediaFormat & sdpMediaFormat);
00178 
00179     virtual void CreateSDPMediaFormats(const PStringArray & tokens);
00180     virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString) = 0;
00181 
00182     virtual PString GetSDPPortList() const = 0;
00183 
00184     virtual void ProcessMediaOptions(SDPMediaFormat & sdpFormat, const OpalMediaFormat & mediaFormat);
00185 
00186   protected:
00187     virtual SDPMediaFormat * FindFormat(PString & str) const;
00188     virtual void SetPacketTime(const PString & optionName, const PString & value);
00189 
00190     OpalTransportAddress transportAddress;
00191     Direction direction;
00192     WORD port;
00193     WORD portCount;
00194     OpalMediaType mediaType;
00195 
00196     SDPMediaFormatList formats;
00197     SDPBandwidth       bandwidth;
00198 };
00199 
00200 PARRAY(SDPMediaDescriptionArray, SDPMediaDescription);
00201 
00203 //
00204 //  SDP media description for media classes using RTP/AVP transport (audio and video)
00205 //
00206 
00207 class SDPRTPAVPMediaDescription : public SDPMediaDescription
00208 {
00209   PCLASSINFO(SDPRTPAVPMediaDescription, SDPMediaDescription);
00210   public:
00211     SDPRTPAVPMediaDescription(const OpalTransportAddress & address);
00212     virtual PCaselessString GetSDPTransportType() const;
00213     virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
00214     virtual PString GetSDPPortList() const;
00215     virtual bool PrintOn(ostream & str, const PString & connectString) const;
00216     void SetAttribute(const PString & attr, const PString & value);
00217 };
00218 
00220 //
00221 //  SDP media description for audio media
00222 //
00223 
00224 class SDPAudioMediaDescription : public SDPRTPAVPMediaDescription
00225 {
00226   PCLASSINFO(SDPAudioMediaDescription, SDPRTPAVPMediaDescription);
00227   public:
00228     SDPAudioMediaDescription(const OpalTransportAddress & address);
00229     virtual PString GetSDPMediaType() const;
00230     virtual bool PrintOn(ostream & str, const PString & connectString) const;
00231     void SetAttribute(const PString & attr, const PString & value);
00232 };
00233 
00235 //
00236 //  SDP media description for video media
00237 //
00238 
00239 class SDPVideoMediaDescription : public SDPRTPAVPMediaDescription
00240 {
00241   PCLASSINFO(SDPVideoMediaDescription, SDPRTPAVPMediaDescription);
00242   public:
00243     SDPVideoMediaDescription(const OpalTransportAddress & address);
00244     virtual PString GetSDPMediaType() const;
00245     virtual bool PreEncode();
00246 };
00247 
00249 //
00250 //  SDP media description for application media
00251 //
00252 
00253 class SDPApplicationMediaDescription : public SDPMediaDescription
00254 {
00255   PCLASSINFO(SDPApplicationMediaDescription, SDPMediaDescription);
00256   public:
00257     SDPApplicationMediaDescription(const OpalTransportAddress & address);
00258     virtual PCaselessString GetSDPTransportType() const;
00259     virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
00260     virtual PString GetSDPMediaType() const;
00261     virtual PString GetSDPPortList() const;
00262 };
00263 
00265 
00266 class SDPSessionDescription : public PObject
00267 {
00268   PCLASSINFO(SDPSessionDescription, PObject);
00269   public:
00270     SDPSessionDescription(
00271       time_t sessionId,
00272       unsigned version,
00273       const OpalTransportAddress & address
00274     );
00275 
00276     void PrintOn(ostream & strm) const;
00277     PString Encode() const;
00278     PBoolean Decode(const PString & str);
00279 
00280     void SetSessionName(const PString & v) { sessionName = v; }
00281     PString GetSessionName() const         { return sessionName; }
00282 
00283     void SetUserName(const PString & v)    { ownerUsername = v; }
00284     PString GetUserName() const            { return ownerUsername; }
00285 
00286     const SDPMediaDescriptionArray & GetMediaDescriptions() const { return mediaDescriptions; }
00287 
00288     SDPMediaDescription * GetMediaDescriptionByType(const OpalMediaType & rtpMediaType) const;
00289     SDPMediaDescription * GetMediaDescriptionByIndex(PINDEX i) const;
00290     void AddMediaDescription(SDPMediaDescription * md) { mediaDescriptions.Append(md); }
00291     
00292     void SetDirection(const SDPMediaDescription::Direction & d) { direction = d; }
00293     SDPMediaDescription::Direction GetDirection(unsigned) const;
00294     bool IsHold() const;
00295 
00296     const OpalTransportAddress & GetDefaultConnectAddress() const { return defaultConnectAddress; }
00297     void SetDefaultConnectAddress(
00298       const OpalTransportAddress & address
00299     );
00300         
00301     time_t GetOwnerSessionId() const { return ownerSessionId; }
00302     void SetOwnerSessionId(time_t value) { ownerSessionId = value; }
00303 
00304     PINDEX GetOwnerVersion() const { return ownerVersion; }
00305     void SetOwnerVersion(PINDEX value) { ownerVersion = value; }
00306 
00307     OpalTransportAddress GetOwnerAddress() const { return ownerAddress; }
00308     void SetOwnerAddress(OpalTransportAddress addr) { ownerAddress = addr; }
00309 
00310     unsigned GetBandwidth(const PString & type) const { return bandwidth[type]; }
00311     void SetBandwidth(const PString & type, unsigned value) { bandwidth[type] = value; }
00312 
00313     static const PString & ConferenceTotalBandwidthType();
00314     static const PString & ApplicationSpecificBandwidthType();
00315     static const PString & TransportIndependentBandwidthType(); // RFC3890
00316 
00317   protected:
00318     void ParseOwner(const PString & str);
00319 
00320     SDPMediaDescriptionArray mediaDescriptions;
00321     SDPMediaDescription::Direction direction;
00322 
00323     PINDEX protocolVersion;
00324     PString sessionName;
00325 
00326     PString ownerUsername;
00327     time_t ownerSessionId;
00328     unsigned ownerVersion;
00329     OpalTransportAddress ownerAddress;
00330     OpalTransportAddress defaultConnectAddress;
00331 
00332     SDPBandwidth bandwidth;     
00333 };
00334 
00336 
00337 
00338 #endif // OPAL_SIP
00339 
00340 #endif // OPAL_SIP_SDP_H
00341 
00342 
00343 // End of File ///////////////////////////////////////////////////////////////

Generated on Mon Feb 1 00:25:54 2010 for OPAL by  doxygen 1.5.1