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: 19586 $
00028  * $Author: rjongbloed $
00029  * $Date: 2008-02-22 11:46:50 +0000 (Fri, 22 Feb 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/mediafmt.h>
00042 #include <rtp/rtp.h>
00043 
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   protected:
00103     void AddNTEString(const PString & str);
00104     void AddNTEToken(const PString & ostr);
00105     PString GetNTEString() const;
00106 
00107 #if OPAL_T38FAX
00108     void AddNSEString(const PString & str);
00109     void AddNSEToken(const PString & ostr);
00110     PString GetNSEString() const;
00111 #endif
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 #if OPAL_T38FAX
00127     mutable POrdinalSet nseSet;     // used for NSE formats only
00128 #endif
00129 };
00130 
00131 PLIST(SDPMediaFormatList, SDPMediaFormat);
00132 
00133 
00135 
00136 class SDPBandwidth : public std::map<PString, unsigned>
00137 {
00138   public:
00139     unsigned & operator[](const PString & type);
00140     unsigned operator[](const PString & type) const;
00141     friend ostream & operator<<(ostream & out, const SDPBandwidth & bw);
00142     bool Parse(const PString & param);
00143 };
00144 
00145 
00147 
00148 class SDPMediaDescription : public PObject
00149 {
00150   PCLASSINFO(SDPMediaDescription, PObject);
00151   public:
00152     // The following enum is arranged so it can be used as a bit mask,
00153     // e.g. GetDirection()&SendOnly indicates send is available
00154     enum Direction {
00155       Undefined = -1,
00156       Inactive,
00157       RecvOnly,
00158       SendOnly,
00159       SendRecv
00160     };
00161     
00162     enum MediaType {
00163       Audio,
00164       Video,
00165       Application,
00166       Image,
00167       Unknown,
00168       NumMediaTypes
00169     };
00170 #if PTRACING
00171     friend ostream & operator<<(ostream & out, MediaType type);
00172 #endif
00173 
00174     SDPMediaDescription(
00175       const OpalTransportAddress & address,
00176       MediaType mediaType = Unknown
00177     );
00178 
00179     void PrintOn(ostream & strm) const;
00180     void PrintOn(const OpalTransportAddress & commonAddr, ostream & str) const;
00181 
00182     bool Decode(const PString & value);
00183     bool Decode(char key, const PString & value);
00184 
00185     MediaType GetMediaType() const { return mediaType; }
00186 
00187     const SDPMediaFormatList & GetSDPMediaFormats() const
00188       { return formats; }
00189 
00190     OpalMediaFormatList GetMediaFormats(unsigned) const;
00191     void CreateRTPMap(unsigned sessionID, RTP_DataFrame::PayloadMapType & map) const;
00192 
00193     void AddSDPMediaFormat(SDPMediaFormat * sdpMediaFormat);
00194 
00195     void AddMediaFormat(const OpalMediaFormat & mediaFormat, const RTP_DataFrame::PayloadMapType & map);
00196     void AddMediaFormats(const OpalMediaFormatList & mediaFormats, unsigned session, const RTP_DataFrame::PayloadMapType & map);
00197 
00198     void SetAttribute(const PString & attr, const PString & value);
00199 
00200     void SetDirection(const Direction & d) { direction = d; }
00201     Direction GetDirection() const { return direction; }
00202 
00203     const OpalTransportAddress & GetTransportAddress() const { return transportAddress; }
00204     PBoolean SetTransportAddress(const OpalTransportAddress &t);
00205 
00206     PString GetTransport() const         { return transport; }
00207     void SetTransport(const PString & v) { transport = v; }
00208 
00209     WORD GetPort() const { return port; }
00210 
00211     PCaselessString GetMedia() const { return media; }
00212     void SetMedia(const PCaselessString & mediaStr) { media = mediaStr;}
00213 
00214     unsigned GetBandwidth(const PString & type) const { return bandwidth[type]; }
00215     void SetBandwidth(const PString & type, unsigned value) { bandwidth[type] = value; }
00216 
00217     void RemoveSDPMediaFormat(const SDPMediaFormat & sdpMediaFormat);
00218 
00219   protected:
00220     void PrintOn(ostream & strm, const PString & str) const;
00221     SDPMediaFormat * FindFormat(PString & str) const;
00222     void SetPacketTime(const PString & optionName, const PString & value);
00223 
00224     MediaType mediaType;
00225     WORD portCount;
00226     PCaselessString media;
00227     PCaselessString transport;
00228     OpalTransportAddress transportAddress;
00229     WORD port;
00230 
00231     Direction direction;
00232 
00233     SDPMediaFormatList formats;
00234     SDPBandwidth       bandwidth;
00235 
00236 #if OPAL_T38FAX
00237     PStringToString t38Attributes;
00238 #endif // OPAL_T38FAX
00239 };
00240 
00241 PARRAY(SDPMediaDescriptionArray, SDPMediaDescription);
00242 
00243 
00245 
00246 class SDPSessionDescription : public PObject
00247 {
00248   PCLASSINFO(SDPSessionDescription, PObject);
00249   public:
00250     SDPSessionDescription(
00251       const OpalTransportAddress & address = OpalTransportAddress()
00252     );
00253 
00254     void PrintOn(ostream & strm) const;
00255     PString Encode() const;
00256     PBoolean Decode(const PString & str);
00257 
00258     void SetSessionName(const PString & v) { sessionName = v; }
00259     PString GetSessionName() const         { return sessionName; }
00260 
00261     void SetUserName(const PString & v)    { ownerUsername = v; }
00262     PString GetUserName() const            { return ownerUsername; }
00263 
00264     const SDPMediaDescriptionArray & GetMediaDescriptions() const { return mediaDescriptions; }
00265 
00266     SDPMediaDescription * GetMediaDescription(
00267       SDPMediaDescription::MediaType rtpMediaType
00268     ) const;
00269     void AddMediaDescription(SDPMediaDescription * md) { mediaDescriptions.Append(md); }
00270     
00271     void SetDirection(const SDPMediaDescription::Direction & d) { direction = d; }
00272     SDPMediaDescription::Direction GetDirection(unsigned) const;
00273 
00274     const OpalTransportAddress & GetDefaultConnectAddress() const { return defaultConnectAddress; }
00275     void SetDefaultConnectAddress(
00276       const OpalTransportAddress & address
00277     );
00278         
00279     PINDEX GetOwnerSessionId() const { return ownerSessionId; }
00280     void SetOwnerSessionId(PINDEX value) { ownerSessionId = value; }
00281 
00282     PINDEX GetOwnerVersion() const { return ownerVersion; }
00283     void SetOwnerVersion(PINDEX value) { ownerVersion = value; }
00284 
00285     OpalTransportAddress GetOwnerAddress() const { return ownerAddress; }
00286     void SetOwnerAddress(OpalTransportAddress addr) { ownerAddress = addr; }
00287 
00288     unsigned GetBandwidth(const PString & type) const { return bandwidth[type]; }
00289     void SetBandwidth(const PString & type, unsigned value) { bandwidth[type] = value; }
00290 
00291     static const PString & ConferenceTotalBandwidthType();
00292     static const PString & ApplicationSpecificBandwidthType();
00293 
00294   protected:
00295     void ParseOwner(const PString & str);
00296 
00297     SDPMediaDescriptionArray mediaDescriptions;
00298     SDPMediaDescription::Direction direction;
00299 
00300     PINDEX protocolVersion;
00301     PString sessionName;
00302 
00303     PString ownerUsername;
00304     unsigned ownerSessionId;
00305     unsigned ownerVersion;
00306     OpalTransportAddress ownerAddress;
00307     OpalTransportAddress defaultConnectAddress;
00308 
00309     SDPBandwidth bandwidth;     
00310 };
00311 
00313 
00314 
00315 #endif // __OPAL_SDP_H
00316 
00317 
00318 // End of File ///////////////////////////////////////////////////////////////

Generated on Fri Mar 7 07:36:39 2008 for OPAL by  doxygen 1.5.1