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.15.2.3  2007/04/21 13:48:49  dsandras
00029  * Allow a different connect address per media description. Fixes
00030  * Ekiga bug #430870.
00031  *
00032  * Revision 2.15.2.2  2006/04/23 20:17:09  dsandras
00033  * Backport from HEAD.
00034  *
00035  * Revision 2.19  2006/04/23 20:12:52  dsandras
00036  * The RFC tells that the SDP answer SHOULD have the same payload type than the
00037  * SDP offer. Added rtpmap support to allow this. Fixes problems with Asterisk,
00038  * and Ekiga report #337456.
00039  *
00040  * Revision 2.15.2.1  2006/02/06 04:38:37  csoutheren
00041  * Backported RTP payload mapping fixes from CVS head
00042  *
00043  * Revision 2.16  2006/02/02 07:02:57  csoutheren
00044  * Added RTP payload map to transcoders and connections to allow remote SIP endpoints
00045  * to change the payload type used for outgoing RTP.
00046  *
00047  * Revision 2.15  2005/12/15 21:15:44  dsandras
00048  * Fixed compilation with gcc 4.1.
00049  *
00050  * Revision 2.14  2005/10/04 18:31:01  dsandras
00051  * Allow SetFMTP and GetFMTP to work with any option set for a=fmtp:.
00052  *
00053  * Revision 2.13  2005/09/15 17:01:08  dsandras
00054  * Added support for the direction attributes in the audio & video media descriptions and in the session.
00055  *
00056  * Revision 2.12  2005/07/14 08:52:19  csoutheren
00057  * Modified to output media desscription specific connection address if needed
00058  *
00059  * Revision 2.11  2005/04/28 20:22:52  dsandras
00060  * Applied big sanity patch for SIP thanks to Ted Szoczei <tszoczei@microtronix.ca>.
00061  * Thanks a lot!
00062  *
00063  * Revision 2.10  2005/04/10 20:51:25  dsandras
00064  * Added possibility to set/get the direction of a stream in an SDP.
00065  *
00066  * Revision 2.9  2004/02/09 13:13:01  rjongbloed
00067  * Added debug string output for media type enum.
00068  *
00069  * Revision 2.8  2004/02/07 02:18:19  rjongbloed
00070  * Improved searching for media format to use payload type AND the encoding name.
00071  *
00072  * Revision 2.7  2004/01/08 22:27:03  csoutheren
00073  * Fixed problem with not using session ID when constructing SDP lists
00074  *
00075  * Revision 2.6  2002/09/16 02:52:35  robertj
00076  * Added #define so can select if #pragma interface/implementation is used on
00077  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00078  *
00079  * Revision 2.5  2002/06/16 02:21:56  robertj
00080  * Utilised new standard PWLib class for POrdinalKey
00081  *
00082  * Revision 2.4  2002/03/15 07:08:24  robertj
00083  * Removed redundent return value on SetXXX function.
00084  *
00085  * Revision 2.3  2002/02/13 02:27:50  robertj
00086  * Normalised some function names.
00087  * Fixed incorrect port number usage stopping audio in one direction.
00088  *
00089  * Revision 2.2  2002/02/11 07:34:58  robertj
00090  * Changed SDP to use OpalTransport for hosts instead of IP addresses/ports
00091  *
00092  * Revision 2.1  2002/02/01 04:53:01  robertj
00093  * Added (very primitive!) SIP support.
00094  *
00095  */
00096 
00097 #ifndef __OPAL_SDP_H
00098 #define __OPAL_SDP_H
00099 
00100 #ifdef P_USE_PRAGMA
00101 #pragma interface
00102 #endif
00103 
00104 
00105 #include <opal/transports.h>
00106 #include <opal/mediafmt.h>
00107 #include <rtp/rtp.h>
00108 
00109 
00111 
00112 class SDPMediaFormat : public PObject
00113 {
00114   PCLASSINFO(SDPMediaFormat, PObject);
00115   public:
00116     // the following values are mandated by RFC 2833
00117     enum NTEEvent {
00118       Digit0 = 0,
00119       Digit1 = 1,
00120       Digit2 = 2,
00121       Digit3 = 3,
00122       Digit4 = 4,
00123       Digit5 = 5,
00124       Digit6 = 6,
00125       Digit7 = 7,
00126       Digit8 = 8,
00127       Digit9 = 9,
00128       Star   = 10,
00129       Hash   = 11,
00130       A      = 12,
00131       B      = 13,
00132       C      = 14,
00133       D      = 15,
00134       Flash  = 16
00135     };
00136     
00137     SDPMediaFormat(
00138       RTP_DataFrame::PayloadTypes payloadType,
00139       const char * name = "-",
00140       unsigned rate = 8000,
00141       const char * param = ""
00142     );
00143 
00144     SDPMediaFormat(const PString & fmtp, RTP_DataFrame::PayloadTypes pt);
00145 
00146     void PrintOn(ostream & str) const;
00147 
00148     RTP_DataFrame::PayloadTypes GetPayloadType() const { return payloadType; }
00149 
00150     PString GetEncodingName() const         { return encodingName; }
00151     void SetEncodingName(const PString & v) { encodingName = v; }
00152 
00153     void SetFMTP(const PString & _fmtp); 
00154     PString GetFMTP() const;
00155 
00156     unsigned GetClockRate(void)                        { return clockRate ; }
00157     void SetClockRate(unsigned  v)                     { clockRate = v; }
00158 
00159     void SetParameters(const PString & v)              { parameters = v; }
00160 
00161     OpalMediaFormat GetMediaFormat() const;
00162 
00163   protected:
00164     void AddNTEString(const PString & str);
00165     void AddNTEToken(const PString & ostr);
00166     PString GetNTEString() const;
00167 
00168     RTP_DataFrame::PayloadTypes payloadType;
00169 
00170     unsigned clockRate;
00171     PString encodingName;
00172     PString parameters;
00173     PString fmtp;
00174 
00175     POrdinalSet nteSet;     // used for NTE formats only
00176 };
00177 
00178 PLIST(SDPMediaFormatList, SDPMediaFormat);
00179 
00180 
00182 
00183 class SDPMediaDescription : public PObject
00184 {
00185   PCLASSINFO(SDPMediaDescription, PObject);
00186   public:
00187     enum Direction {
00188       RecvOnly,
00189       SendOnly,
00190       SendRecv,
00191       Inactive,
00192       Undefined
00193     };
00194     
00195     enum MediaType {
00196       Audio,
00197       Video,
00198       Application,
00199       Unknown,
00200       NumMediaTypes
00201     };
00202 #if PTRACING
00203     friend ostream & operator<<(ostream & out, MediaType type);
00204 #endif
00205 
00206     SDPMediaDescription(
00207       const OpalTransportAddress & address,
00208       MediaType mediaType = Unknown
00209     );
00210 
00211     void PrintOn(ostream & strm) const;
00212     void PrintOn(const OpalTransportAddress & commonAddr, ostream & str) const;
00213 
00214     BOOL Decode(const PString & str);
00215 
00216     MediaType GetMediaType() const { return mediaType; }
00217 
00218     const SDPMediaFormatList & GetSDPMediaFormats() const
00219       { return formats; }
00220 
00221     OpalMediaFormatList GetMediaFormats(unsigned) const;
00222     void CreateRTPMap(unsigned sessionID, RTP_DataFrame::PayloadMapType & map) const;
00223 
00224     void AddSDPMediaFormat(SDPMediaFormat * sdpMediaFormat);
00225 
00226     void AddMediaFormat(const OpalMediaFormat & mediaFormat, const RTP_DataFrame::PayloadMapType & map);
00227     void AddMediaFormats(const OpalMediaFormatList & mediaFormats, unsigned session, const RTP_DataFrame::PayloadMapType & map);
00228 
00229     void SetAttribute(const PString & attr);
00230 
00231     void SetDirection(const Direction & d) { direction = d; }
00232     Direction GetDirection() const { return direction; }
00233 
00234     const OpalTransportAddress & GetTransportAddress() const { return transportAddress; }
00235     BOOL SetTransportAddress(const OpalTransportAddress &t);
00236 
00237     PString GetTransport() const         { return transport; }
00238     void SetTransport(const PString & v) { transport = v; }
00239 
00240           PINDEX GetPacketTime () const            { return packetTime; }
00241           void SetPacketTime (PINDEX milliseconds) { packetTime = milliseconds; }
00242 
00243   protected:
00244     void PrintOn(ostream & strm, const PString & str) const;
00245     MediaType mediaType;
00246     WORD portCount;
00247     PCaselessString media;
00248     PCaselessString transport;
00249     OpalTransportAddress transportAddress;
00250 
00251     Direction direction;
00252 
00253     SDPMediaFormatList formats;
00254     PINDEX packetTime;                  // ptime attribute, in milliseconds
00255 };
00256 
00257 PLIST(SDPMediaDescriptionList, SDPMediaDescription);
00258 
00259 
00261 
00262 class SDPSessionDescription : public PObject
00263 {
00264   PCLASSINFO(SDPSessionDescription, PObject);
00265   public:
00266     SDPSessionDescription(
00267       const OpalTransportAddress & address = OpalTransportAddress()
00268     );
00269 
00270     void PrintOn(ostream & strm) const;
00271     PString Encode() const;
00272     BOOL Decode(const PString & str);
00273 
00274     void SetSessionName(const PString & v) { sessionName = v; }
00275     PString GetSessionName() const         { return sessionName; }
00276 
00277     void SetUserName(const PString & v)    { ownerUsername = v; }
00278     PString GetUserName() const            { return ownerUsername; }
00279 
00280     const SDPMediaDescriptionList & GetMediaDescriptions() const { return mediaDescriptions; }
00281 
00282     SDPMediaDescription * GetMediaDescription(
00283       SDPMediaDescription::MediaType rtpMediaType
00284     ) const;
00285     void AddMediaDescription(SDPMediaDescription * md) { mediaDescriptions.Append(md); }
00286     
00287     void SetDirection(const SDPMediaDescription::Direction & d) { direction = d; }
00288     SDPMediaDescription::Direction GetDirection(unsigned) const;
00289 
00290     const OpalTransportAddress & GetDefaultConnectAddress() const { return defaultConnectAddress; }
00291     void SetDefaultConnectAddress(
00292       const OpalTransportAddress & address
00293     ) { defaultConnectAddress = address; }
00294 
00295 
00296   protected:
00297     void ParseOwner(const PString & str);
00298 
00299     SDPMediaDescriptionList mediaDescriptions;
00300     SDPMediaDescription::Direction direction;
00301 
00302     PINDEX protocolVersion;
00303     PString sessionName;
00304 
00305     PString ownerUsername;
00306     unsigned ownerSessionId;
00307     unsigned ownerVersion;
00308     OpalTransportAddress ownerAddress;
00309     OpalTransportAddress defaultConnectAddress;
00310 };
00311 
00313 
00314 
00315 #endif // __OPAL_SDP_H
00316 
00317 
00318 // End of File ///////////////////////////////////////////////////////////////

Generated on Fri Jan 25 01:20:18 2008 for OPAL by  doxygen 1.5.4