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

Generated on Mon Sep 15 11:49:15 2008 for OPAL by  doxygen 1.5.1