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  * $Log: sdp.h,v $
00028  * Revision 2.26  2007/09/14 06:08:58  csoutheren
00029  * Fix problems with incorrect parsing of "c=" lines
00030  * Clamp ptime to 60 so Ciscos will work
00031  *
00032  * Revision 2.25  2007/09/04 08:27:45  rjongbloed
00033  * Added ptime and maxptime SDP attributes.
00034  *
00035  * Revision 2.24  2007/06/22 05:41:47  rjongbloed
00036  * Major codec API update:
00037  *   Automatically map OpalMediaOptions to SIP/SDP FMTP parameters.
00038  *   Automatically map OpalMediaOptions to H.245 Generic Capability parameters.
00039  *   Largely removed need to distinguish between SIP and H.323 codecs.
00040  *   New mechanism for setting OpalMediaOptions from within a plug in.
00041  *
00042  * Revision 2.23  2007/04/21 13:49:15  dsandras
00043  * Allow a different connect address per media description. Fixes
00044  * Ekiga bug #430870.
00045  *
00046  * Revision 2.22  2007/04/10 05:15:54  rjongbloed
00047  * Fixed issue with use of static C string variables in DLL environment,
00048  *   must use functional interface for correct initialisation.
00049  *
00050  * Revision 2.21  2007/03/13 00:32:17  csoutheren
00051  * Simple but messy changes to allow compile time removal of protocol
00052  * options such as H.450 and H.460
00053  * Fix MakeConnection overrides
00054  *
00055  * Revision 2.20  2006/11/09 17:54:13  hfriederich
00056  * Allow matching of fixed RTP payload type media formats if no rtpmap attribute is present in the received SDP
00057  *
00058  * Revision 2.19  2006/04/23 20:12:52  dsandras
00059  * The RFC tells that the SDP answer SHOULD have the same payload type than the
00060  * SDP offer. Added rtpmap support to allow this. Fixes problems with Asterisk,
00061  * and Ekiga report #337456.
00062  *
00063  * Revision 2.18  2006/04/21 14:36:51  hfriederich
00064  * Adding ability to parse and transmit simple bandwidth information
00065  *
00066  * Revision 2.17  2006/03/08 10:59:02  csoutheren
00067  * Applied patch #1444783 - Add 'image' SDP meda type and 'udptl' transport protocol
00068  * Thanks to Drazen Dimoti
00069  *
00070  * Revision 2.16  2006/02/02 07:02:57  csoutheren
00071  * Added RTP payload map to transcoders and connections to allow remote SIP endpoints
00072  * to change the payload type used for outgoing RTP.
00073  *
00074  * Revision 2.15  2005/12/15 21:15:44  dsandras
00075  * Fixed compilation with gcc 4.1.
00076  *
00077  * Revision 2.14  2005/10/04 18:31:01  dsandras
00078  * Allow SetFMTP and GetFMTP to work with any option set for a=fmtp:.
00079  *
00080  * Revision 2.13  2005/09/15 17:01:08  dsandras
00081  * Added support for the direction attributes in the audio & video media descriptions and in the session.
00082  *
00083  * Revision 2.12  2005/07/14 08:52:19  csoutheren
00084  * Modified to output media desscription specific connection address if needed
00085  *
00086  * Revision 2.11  2005/04/28 20:22:52  dsandras
00087  * Applied big sanity patch for SIP thanks to Ted Szoczei <tszoczei@microtronix.ca>.
00088  * Thanks a lot!
00089  *
00090  * Revision 2.10  2005/04/10 20:51:25  dsandras
00091  * Added possibility to set/get the direction of a stream in an SDP.
00092  *
00093  * Revision 2.9  2004/02/09 13:13:01  rjongbloed
00094  * Added debug string output for media type enum.
00095  *
00096  * Revision 2.8  2004/02/07 02:18:19  rjongbloed
00097  * Improved searching for media format to use payload type AND the encoding name.
00098  *
00099  * Revision 2.7  2004/01/08 22:27:03  csoutheren
00100  * Fixed problem with not using session ID when constructing SDP lists
00101  *
00102  * Revision 2.6  2002/09/16 02:52:35  robertj
00103  * Added #define so can select if #pragma interface/implementation is used on
00104  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00105  *
00106  * Revision 2.5  2002/06/16 02:21:56  robertj
00107  * Utilised new standard PWLib class for POrdinalKey
00108  *
00109  * Revision 2.4  2002/03/15 07:08:24  robertj
00110  * Removed redundent return value on SetXXX function.
00111  *
00112  * Revision 2.3  2002/02/13 02:27:50  robertj
00113  * Normalised some function names.
00114  * Fixed incorrect port number usage stopping audio in one direction.
00115  *
00116  * Revision 2.2  2002/02/11 07:34:58  robertj
00117  * Changed SDP to use OpalTransport for hosts instead of IP addresses/ports
00118  *
00119  * Revision 2.1  2002/02/01 04:53:01  robertj
00120  * Added (very primitive!) SIP support.
00121  *
00122  */
00123 
00124 #ifndef __OPAL_SDP_H
00125 #define __OPAL_SDP_H
00126 
00127 #ifdef P_USE_PRAGMA
00128 #pragma interface
00129 #endif
00130 
00131 
00132 #include <opal/transports.h>
00133 #include <opal/mediafmt.h>
00134 #include <rtp/rtp.h>
00135 
00136 
00138 
00139 class SDPMediaFormat : public PObject
00140 {
00141   PCLASSINFO(SDPMediaFormat, PObject);
00142   public:
00143     // the following values are mandated by RFC 2833
00144     enum NTEEvent {
00145       Digit0 = 0,
00146       Digit1 = 1,
00147       Digit2 = 2,
00148       Digit3 = 3,
00149       Digit4 = 4,
00150       Digit5 = 5,
00151       Digit6 = 6,
00152       Digit7 = 7,
00153       Digit8 = 8,
00154       Digit9 = 9,
00155       Star   = 10,
00156       Hash   = 11,
00157       A      = 12,
00158       B      = 13,
00159       C      = 14,
00160       D      = 15,
00161       Flash  = 16
00162     };
00163     
00164     SDPMediaFormat(
00165       RTP_DataFrame::PayloadTypes payloadType,
00166       const char * name = NULL
00167     );
00168 
00169     SDPMediaFormat(
00170       const OpalMediaFormat & mediaFormat,
00171       RTP_DataFrame::PayloadTypes pt,
00172       const char * nteString = NULL
00173     );
00174 
00175     void PrintOn(ostream & str) const;
00176 
00177     RTP_DataFrame::PayloadTypes GetPayloadType() const { return payloadType; }
00178 
00179     PString GetEncodingName() const         { return encodingName; }
00180     void SetEncodingName(const PString & v) { encodingName = v; }
00181 
00182     void SetFMTP(const PString & _fmtp); 
00183     PString GetFMTP() const;
00184 
00185     unsigned GetClockRate(void)                        { return clockRate ; }
00186     void SetClockRate(unsigned  v)                     { clockRate = v; }
00187 
00188     void SetParameters(const PString & v) { parameters = v; }
00189 
00190     void SetPacketTime(const PString & optionName, unsigned ptime);
00191 
00192     const OpalMediaFormat & GetMediaFormat() const;
00193 
00194   protected:
00195     void AddNTEString(const PString & str);
00196     void AddNTEToken(const PString & ostr);
00197     PString GetNTEString() const;
00198 
00199 #if OPAL_T38FAX
00200     void AddNSEString(const PString & str);
00201     void AddNSEToken(const PString & ostr);
00202     PString GetNSEString() const;
00203 #endif
00204 
00205     void AddNXEString(POrdinalSet & nxeSet, const PString & str);
00206     void AddNXEToken(POrdinalSet & nxeSet, const PString & ostr);
00207     PString GetNXEString(POrdinalSet & nxeSet) const;
00208 
00209     mutable OpalMediaFormat mediaFormat;
00210     RTP_DataFrame::PayloadTypes payloadType;
00211 
00212     unsigned clockRate;
00213     PString encodingName;
00214     PString parameters;
00215     PString fmtp;
00216 
00217     mutable POrdinalSet nteSet;     // used for NTE formats only
00218 #if OPAL_T38FAX
00219     mutable POrdinalSet nseSet;     // used for NSE formats only
00220 #endif
00221 };
00222 
00223 PLIST(SDPMediaFormatList, SDPMediaFormat);
00224 
00225 
00227 
00228 class SDPMediaDescription : public PObject
00229 {
00230   PCLASSINFO(SDPMediaDescription, PObject);
00231   public:
00232     enum Direction {
00233       RecvOnly,
00234       SendOnly,
00235       SendRecv,
00236       Inactive,
00237       Undefined
00238     };
00239     
00240     enum MediaType {
00241       Audio,
00242       Video,
00243       Application,
00244       Image,
00245       Unknown,
00246       NumMediaTypes
00247     };
00248 #if PTRACING
00249     friend ostream & operator<<(ostream & out, MediaType type);
00250 #endif
00251 
00252     SDPMediaDescription(
00253       const OpalTransportAddress & address,
00254       MediaType mediaType = Unknown
00255     );
00256 
00257     void PrintOn(ostream & strm) const;
00258     void PrintOn(const OpalTransportAddress & commonAddr, ostream & str) const;
00259 
00260     BOOL Decode(const PString & str);
00261 
00262     MediaType GetMediaType() const { return mediaType; }
00263 
00264     const SDPMediaFormatList & GetSDPMediaFormats() const
00265       { return formats; }
00266 
00267     OpalMediaFormatList GetMediaFormats(unsigned) const;
00268     void CreateRTPMap(unsigned sessionID, RTP_DataFrame::PayloadMapType & map) const;
00269 
00270     void AddSDPMediaFormat(SDPMediaFormat * sdpMediaFormat);
00271 
00272     void AddMediaFormat(const OpalMediaFormat & mediaFormat, const RTP_DataFrame::PayloadMapType & map);
00273     void AddMediaFormats(const OpalMediaFormatList & mediaFormats, unsigned session, const RTP_DataFrame::PayloadMapType & map);
00274 
00275     void SetAttribute(const PString & attr, const PString & value);
00276 
00277     void SetDirection(const Direction & d) { direction = d; }
00278     Direction GetDirection() const { return direction; }
00279 
00280     const OpalTransportAddress & GetTransportAddress() const { return transportAddress; }
00281     BOOL SetTransportAddress(const OpalTransportAddress &t);
00282 
00283     PString GetTransport() const         { return transport; }
00284     void SetTransport(const PString & v) { transport = v; }
00285 
00286     WORD GetPort() const { return port; }
00287 
00288   protected:
00289     void PrintOn(ostream & strm, const PString & str) const;
00290     SDPMediaFormat * FindFormat(PString & str) const;
00291     void SetPacketTime(const PString & optionName, const PString & value);
00292 
00293     MediaType mediaType;
00294     WORD portCount;
00295     PCaselessString media;
00296     PCaselessString transport;
00297     OpalTransportAddress transportAddress;
00298     WORD port;
00299 
00300     Direction direction;
00301 
00302     SDPMediaFormatList formats;
00303 
00304 #if OPAL_T38FAX
00305     PStringToString t38Attributes;
00306 #endif // OPAL_T38FAX
00307 };
00308 
00309 PLIST(SDPMediaDescriptionList, SDPMediaDescription);
00310 
00311 
00313 
00314 class SDPSessionDescription : public PObject
00315 {
00316   PCLASSINFO(SDPSessionDescription, PObject);
00317   public:
00318     SDPSessionDescription(
00319       const OpalTransportAddress & address = OpalTransportAddress()
00320     );
00321 
00322     void PrintOn(ostream & strm) const;
00323     PString Encode() const;
00324     BOOL Decode(const PString & str);
00325 
00326     void SetSessionName(const PString & v) { sessionName = v; }
00327     PString GetSessionName() const         { return sessionName; }
00328 
00329     void SetUserName(const PString & v)    { ownerUsername = v; }
00330     PString GetUserName() const            { return ownerUsername; }
00331 
00332     const SDPMediaDescriptionList & GetMediaDescriptions() const { return mediaDescriptions; }
00333 
00334     SDPMediaDescription * GetMediaDescription(
00335       SDPMediaDescription::MediaType rtpMediaType
00336     ) const;
00337     void AddMediaDescription(SDPMediaDescription * md) { mediaDescriptions.Append(md); }
00338     
00339     void SetDirection(const SDPMediaDescription::Direction & d) { direction = d; }
00340     SDPMediaDescription::Direction GetDirection(unsigned) const;
00341 
00342     const OpalTransportAddress & GetDefaultConnectAddress() const { return defaultConnectAddress; }
00343     void SetDefaultConnectAddress(
00344       const OpalTransportAddress & address
00345     ) { defaultConnectAddress = address; }
00346         
00347     const PString & GetBandwidthModifier() const { return bandwidthModifier; }
00348     void SetBandwidthModifier(const PString & modifier) { bandwidthModifier = modifier; }
00349 
00350     PINDEX GetBandwidthValue() const { return bandwidthValue; }
00351     void SetBandwidthValue(PINDEX value) { bandwidthValue = value; }
00352 
00353     static const PString & ConferenceTotalBandwidthModifier();
00354     static const PString & ApplicationSpecificBandwidthModifier();
00355 
00356   protected:
00357     void ParseOwner(const PString & str);
00358 
00359     SDPMediaDescriptionList mediaDescriptions;
00360     SDPMediaDescription::Direction direction;
00361 
00362     PINDEX protocolVersion;
00363     PString sessionName;
00364 
00365     PString ownerUsername;
00366     unsigned ownerSessionId;
00367     unsigned ownerVersion;
00368     OpalTransportAddress ownerAddress;
00369     OpalTransportAddress defaultConnectAddress;
00370     WORD defaultConnectPort;
00371         
00372     PString bandwidthModifier;
00373     PINDEX bandwidthValue;
00374 };
00375 
00377 
00378 
00379 #endif // __OPAL_SDP_H
00380 
00381 
00382 // End of File ///////////////////////////////////////////////////////////////

Generated on Fri Mar 7 06:33:41 2008 for OPAL by  doxygen 1.5.1