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: 21283 $
00028  * $Author: rjongbloed $
00029  * $Date: 2008-10-11 07:10:58 +0000 (Sat, 11 Oct 2008) $
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 SDPMediaFormat : public PObject
00051 {
00052   PCLASSINFO(SDPMediaFormat, PObject);
00053   public:
00054     // the following values are mandated by RFC 2833
00055     enum NTEEvent {
00056       Digit0 = 0,
00057       Digit1 = 1,
00058       Digit2 = 2,
00059       Digit3 = 3,
00060       Digit4 = 4,
00061       Digit5 = 5,
00062       Digit6 = 6,
00063       Digit7 = 7,
00064       Digit8 = 8,
00065       Digit9 = 9,
00066       Star   = 10,
00067       Hash   = 11,
00068       A      = 12,
00069       B      = 13,
00070       C      = 14,
00071       D      = 15,
00072       Flash  = 16
00073     };
00074     
00075     SDPMediaFormat(
00076       RTP_DataFrame::PayloadTypes payloadType,
00077       const char * name = NULL
00078     );
00079 
00080     SDPMediaFormat(
00081       const OpalMediaFormat & mediaFormat,
00082       RTP_DataFrame::PayloadTypes pt,
00083       const char * nteString = NULL
00084     );
00085 
00086     void PrintOn(ostream & str) const;
00087 
00088     RTP_DataFrame::PayloadTypes GetPayloadType() const { return payloadType; }
00089 
00090     PString GetEncodingName() const         { return encodingName; }
00091     void SetEncodingName(const PString & v) { encodingName = v; }
00092 
00093     void SetFMTP(const PString & _fmtp); 
00094     PString GetFMTP() const;
00095 
00096     unsigned GetClockRate(void)                        { return clockRate ; }
00097     void SetClockRate(unsigned  v)                     { clockRate = v; }
00098 
00099     void SetParameters(const PString & v) { parameters = v; }
00100 
00101     void SetPacketTime(const PString & optionName, unsigned ptime);
00102 
00103     const OpalMediaFormat & GetMediaFormat() const;
00104 
00105     bool ToNormalisedOptions();
00106 
00107   protected:
00108     void AddNTEString(const PString & str);
00109     void AddNTEToken(const PString & ostr);
00110     PString GetNTEString() const;
00111 
00112     void AddNSEString(const PString & str);
00113     void AddNSEToken(const PString & ostr);
00114     PString GetNSEString() const;
00115 
00116     void AddNXEString(POrdinalSet & nxeSet, const PString & str);
00117     void AddNXEToken(POrdinalSet & nxeSet, const PString & ostr);
00118     PString GetNXEString(POrdinalSet & nxeSet) const;
00119 
00120     mutable OpalMediaFormat mediaFormat;
00121     RTP_DataFrame::PayloadTypes payloadType;
00122 
00123     unsigned clockRate;
00124     PString encodingName;
00125     PString parameters;
00126     PString fmtp;
00127 
00128     mutable POrdinalSet nteSet;     // used for NTE formats only
00129     mutable POrdinalSet nseSet;     // used for NSE formats only
00130 };
00131 
00132 PLIST(SDPMediaFormatList, SDPMediaFormat);
00133 
00134 
00136 
00137 class SDPBandwidth : public std::map<PString, unsigned>
00138 {
00139   public:
00140     unsigned & operator[](const PString & type);
00141     unsigned operator[](const PString & type) const;
00142     friend ostream & operator<<(ostream & out, const SDPBandwidth & bw);
00143     bool Parse(const PString & param);
00144 };
00145 
00146 
00148 
00149 class SDPMediaDescription : public PObject
00150 {
00151   PCLASSINFO(SDPMediaDescription, PObject);
00152   public:
00153     // The following enum is arranged so it can be used as a bit mask,
00154     // e.g. GetDirection()&SendOnly indicates send is available
00155     enum Direction {
00156       Undefined = -1,
00157       Inactive,
00158       RecvOnly,
00159       SendOnly,
00160       SendRecv
00161     };
00162 
00163     SDPMediaDescription(
00164       const OpalTransportAddress & address
00165     );
00166 
00167     virtual void PrintOn(ostream & strm) const;
00168     virtual void PrintOn(const OpalTransportAddress & commonAddr, ostream & str) const;
00169 
00170     virtual bool Decode(const PStringArray & tokens);
00171     virtual bool Decode(char key, const PString & value);
00172     virtual bool PostDecode();
00173 
00174     //virtual MediaType GetMediaType() const { return mediaType; }
00175 
00176     // return the string used within SDP to identify this media type
00177     virtual PString GetSDPMediaType() const = 0;
00178 
00179     // return the string used within SDP to identify the transport used by this media
00180     virtual PCaselessString GetSDPTransportType() const = 0;
00181 
00182     virtual const SDPMediaFormatList & GetSDPMediaFormats() const
00183       { return formats; }
00184 
00185     virtual OpalMediaFormatList GetMediaFormats() const;
00186 
00187     virtual void AddSDPMediaFormat(SDPMediaFormat * sdpMediaFormat);
00188 
00189     virtual void AddMediaFormat(const OpalMediaFormat & mediaFormat);
00190     virtual void AddMediaFormats(const OpalMediaFormatList & mediaFormats, const OpalMediaType & mediaType);
00191 
00192     virtual void SetAttribute(const PString & attr, const PString & value);
00193 
00194     virtual void SetDirection(const Direction & d) { direction = d; }
00195     virtual Direction GetDirection() const { return transportAddress.IsEmpty() ? Inactive : direction; }
00196 
00197     virtual const OpalTransportAddress & GetTransportAddress() const { return transportAddress; }
00198     virtual PBoolean SetTransportAddress(const OpalTransportAddress &t);
00199 
00200     virtual WORD GetPort() const { return port; }
00201 
00202     virtual OpalMediaType GetMediaType() const { return mediaType; }
00203 
00204     virtual unsigned GetBandwidth(const PString & type) const { return bandwidth[type]; }
00205     virtual void SetBandwidth(const PString & type, unsigned value) { bandwidth[type] = value; }
00206 
00207     virtual void RemoveSDPMediaFormat(const SDPMediaFormat & sdpMediaFormat);
00208 
00209     virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString) = 0;
00210 
00211     virtual PString GetSDPPortList() const = 0;
00212 
00213     virtual void ProcessMediaOptions(SDPMediaFormat & sdpFormat, const OpalMediaFormat & mediaFormat);
00214 
00215   protected:
00216     virtual bool PrintOn(ostream & strm, const PString & str) const;
00217     virtual SDPMediaFormat * FindFormat(PString & str) const;
00218     virtual void SetPacketTime(const PString & optionName, const PString & value);
00219 
00220     OpalTransportAddress transportAddress;
00221     Direction direction;
00222     WORD port;
00223     WORD portCount;
00224     OpalMediaType mediaType;
00225 
00226     SDPMediaFormatList formats;
00227     SDPBandwidth       bandwidth;
00228 };
00229 
00230 PARRAY(SDPMediaDescriptionArray, SDPMediaDescription);
00231 
00233 //
00234 //  SDP media description for media classes using RTP/AVP transport (audio and video)
00235 //
00236 
00237 class SDPRTPAVPMediaDescription : public SDPMediaDescription
00238 {
00239   PCLASSINFO(SDPRTPAVPMediaDescription, SDPMediaDescription);
00240   public:
00241     SDPRTPAVPMediaDescription(const OpalTransportAddress & address);
00242     virtual PCaselessString GetSDPTransportType() const;
00243     virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
00244     virtual PString GetSDPPortList() const;
00245     virtual bool PrintOn(ostream & str, const PString & connectString) const;
00246     void SetAttribute(const PString & attr, const PString & value);
00247 };
00248 
00250 //
00251 //  SDP media description for audio media
00252 //
00253 
00254 class SDPAudioMediaDescription : public SDPRTPAVPMediaDescription
00255 {
00256   PCLASSINFO(SDPAudioMediaDescription, SDPRTPAVPMediaDescription);
00257   public:
00258     SDPAudioMediaDescription(const OpalTransportAddress & address);
00259     virtual PString GetSDPMediaType() const;
00260     virtual bool PrintOn(ostream & str, const PString & connectString) const;
00261     void SetAttribute(const PString & attr, const PString & value);
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 PString GetSDPMediaType() const;
00275 };
00276 
00278 //
00279 //  SDP media description for application media
00280 //
00281 
00282 class SDPApplicationMediaDescription : public SDPMediaDescription
00283 {
00284   PCLASSINFO(SDPApplicationMediaDescription, SDPMediaDescription);
00285   public:
00286     SDPApplicationMediaDescription(const OpalTransportAddress & address);
00287     virtual PCaselessString GetSDPTransportType() const;
00288     virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
00289     virtual PString GetSDPMediaType() const;
00290     virtual PString GetSDPPortList() const;
00291 };
00292 
00294 
00295 class SDPSessionDescription : public PObject
00296 {
00297   PCLASSINFO(SDPSessionDescription, PObject);
00298   public:
00299     SDPSessionDescription(
00300       const OpalTransportAddress & address = OpalTransportAddress()
00301     );
00302 
00303     void PrintOn(ostream & strm) const;
00304     PString Encode() const;
00305     PBoolean Decode(const PString & str);
00306 
00307     void SetSessionName(const PString & v) { sessionName = v; }
00308     PString GetSessionName() const         { return sessionName; }
00309 
00310     void SetUserName(const PString & v)    { ownerUsername = v; }
00311     PString GetUserName() const            { return ownerUsername; }
00312 
00313     const SDPMediaDescriptionArray & GetMediaDescriptions() const { return mediaDescriptions; }
00314 
00315     SDPMediaDescription * GetMediaDescriptionByType(const OpalMediaType & rtpMediaType) const;
00316     SDPMediaDescription * GetMediaDescriptionByIndex(PINDEX i) const;
00317     void AddMediaDescription(SDPMediaDescription * md) { mediaDescriptions.Append(md); }
00318     
00319     void SetDirection(const SDPMediaDescription::Direction & d) { direction = d; }
00320     SDPMediaDescription::Direction GetDirection(unsigned) const;
00321     bool IsHold() const;
00322 
00323     const OpalTransportAddress & GetDefaultConnectAddress() const { return defaultConnectAddress; }
00324     void SetDefaultConnectAddress(
00325       const OpalTransportAddress & address
00326     );
00327         
00328     PINDEX GetOwnerSessionId() const { return ownerSessionId; }
00329     void SetOwnerSessionId(PINDEX value) { ownerSessionId = value; }
00330 
00331     PINDEX GetOwnerVersion() const { return ownerVersion; }
00332     void SetOwnerVersion(PINDEX value) { ownerVersion = value; }
00333 
00334     OpalTransportAddress GetOwnerAddress() const { return ownerAddress; }
00335     void SetOwnerAddress(OpalTransportAddress addr) { ownerAddress = addr; }
00336 
00337     unsigned GetBandwidth(const PString & type) const { return bandwidth[type]; }
00338     void SetBandwidth(const PString & type, unsigned value) { bandwidth[type] = value; }
00339 
00340     static const PString & ConferenceTotalBandwidthType();
00341     static const PString & ApplicationSpecificBandwidthType();
00342 
00343   protected:
00344     void ParseOwner(const PString & str);
00345 
00346     SDPMediaDescriptionArray mediaDescriptions;
00347     SDPMediaDescription::Direction direction;
00348 
00349     PINDEX protocolVersion;
00350     PString sessionName;
00351 
00352     PString ownerUsername;
00353     unsigned ownerSessionId;
00354     unsigned ownerVersion;
00355     OpalTransportAddress ownerAddress;
00356     OpalTransportAddress defaultConnectAddress;
00357 
00358     SDPBandwidth bandwidth;     
00359 };
00360 
00362 
00363 
00364 #endif // OPAL_SIP
00365 
00366 #endif // OPAL_SIP_SDP_H
00367 
00368 
00369 // End of File ///////////////////////////////////////////////////////////////

Generated on Mon Feb 23 02:01:39 2009 for OPAL by  doxygen 1.5.1