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

Generated on Mon Aug 3 20:50:25 2009 for OPAL by  doxygen 1.5.1