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