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

Generated on Mon Sep 25 16:20:10 2006 for OPAL by  doxygen 1.4.7