00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef OPAL_SIP_SDP_H
00033 #define OPAL_SIP_SDP_H
00034
00035 #ifdef P_USE_PRAGMA
00036 #pragma interface
00037 #endif
00038
00039 #include <opal/buildopts.h>
00040
00041 #if OPAL_SIP
00042
00043 #include <opal/transports.h>
00044 #include <opal/mediatype.h>
00045 #include <opal/mediafmt.h>
00046 #include <rtp/rtp.h>
00047
00049
00050 class SDPBandwidth : public std::map<PString, unsigned>
00051 {
00052 public:
00053 unsigned & operator[](const PString & type);
00054 unsigned operator[](const PString & type) const;
00055 friend ostream & operator<<(ostream & out, const SDPBandwidth & bw);
00056 bool Parse(const PString & param);
00057 };
00058
00060
00061 class SDPMediaDescription;
00062
00063 class SDPMediaFormat : public PObject
00064 {
00065 PCLASSINFO(SDPMediaFormat, PObject);
00066 public:
00067 SDPMediaFormat(
00068 SDPMediaDescription & parent,
00069 RTP_DataFrame::PayloadTypes payloadType,
00070 const char * name = NULL
00071 );
00072
00073 SDPMediaFormat(
00074 SDPMediaDescription & parent,
00075 const OpalMediaFormat & mediaFormat
00076 );
00077
00078 virtual void PrintOn(ostream & str) const;
00079
00080 RTP_DataFrame::PayloadTypes GetPayloadType() const { return payloadType; }
00081
00082 PString GetEncodingName() const { return encodingName; }
00083 void SetEncodingName(const PString & v) { encodingName = v; }
00084
00085 void SetFMTP(const PString & _fmtp);
00086 PString GetFMTP() const;
00087
00088 unsigned GetClockRate(void) { return clockRate ; }
00089 void SetClockRate(unsigned v) { clockRate = v; }
00090
00091 void SetParameters(const PString & v) { parameters = v; }
00092
00093 void SetPacketTime(const PString & optionName, unsigned ptime);
00094
00095 const OpalMediaFormat & GetMediaFormat() const;
00096
00097 bool ToNormalisedOptions();
00098
00099 protected:
00100 virtual void UpdateMediaFormat() const;
00101
00102 mutable OpalMediaFormat mediaFormat;
00103 RTP_DataFrame::PayloadTypes payloadType;
00104
00105 SDPMediaDescription & m_parent;
00106 unsigned clockRate;
00107 PString encodingName;
00108 PString parameters;
00109 PString fmtp;
00110 };
00111
00112 PLIST(SDPMediaFormatList, SDPMediaFormat);
00113
00115
00116 class SDPMediaDescription : public PObject
00117 {
00118 PCLASSINFO(SDPMediaDescription, PObject);
00119 public:
00120
00121
00122 enum Direction {
00123 Undefined = -1,
00124 Inactive,
00125 RecvOnly,
00126 SendOnly,
00127 SendRecv
00128 };
00129
00130 SDPMediaDescription(
00131 const OpalTransportAddress & address
00132 );
00133
00134 virtual void PrintOn(ostream & strm) const;
00135 virtual void PrintOn(const OpalTransportAddress & commonAddr, ostream & str) const;
00136
00137 virtual bool Decode(const PStringArray & tokens);
00138 virtual bool Decode(char key, const PString & value);
00139 virtual bool PostDecode();
00140
00141
00142 virtual PString GetSDPMediaType() const = 0;
00143
00144
00145 virtual PCaselessString GetSDPTransportType() const = 0;
00146
00147 virtual const SDPMediaFormatList & GetSDPMediaFormats() const
00148 { return formats; }
00149
00150 virtual OpalMediaFormatList GetMediaFormats() const;
00151
00152 virtual void AddSDPMediaFormat(SDPMediaFormat * sdpMediaFormat);
00153
00154 virtual void AddMediaFormat(const OpalMediaFormat & mediaFormat);
00155 virtual void AddMediaFormats(const OpalMediaFormatList & mediaFormats, const OpalMediaType & mediaType);
00156
00157 virtual void SetAttribute(const PString & attr, const PString & value);
00158
00159 virtual void SetDirection(const Direction & d) { direction = d; }
00160 virtual Direction GetDirection() const { return transportAddress.IsEmpty() ? Inactive : direction; }
00161
00162 virtual const OpalTransportAddress & GetTransportAddress() const { return transportAddress; }
00163 virtual PBoolean SetTransportAddress(const OpalTransportAddress &t);
00164
00165 virtual WORD GetPort() const { return port; }
00166
00167 virtual OpalMediaType GetMediaType() const { return mediaType; }
00168
00169 virtual unsigned GetBandwidth(const PString & type) const { return bandwidth[type]; }
00170 virtual void SetBandwidth(const PString & type, unsigned value) { bandwidth[type] = value; }
00171
00172 virtual const SDPBandwidth & GetBandwidth() const { return bandwidth; }
00173
00174 virtual void RemoveSDPMediaFormat(const SDPMediaFormat & sdpMediaFormat);
00175
00176 virtual void CreateSDPMediaFormats(const PStringArray & tokens);
00177 virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString) = 0;
00178
00179 virtual PString GetSDPPortList() const = 0;
00180
00181 virtual void ProcessMediaOptions(SDPMediaFormat & sdpFormat, const OpalMediaFormat & mediaFormat);
00182
00183 virtual bool PrintOn(ostream & strm, const PString & str) const;
00184
00185 protected:
00186 virtual SDPMediaFormat * FindFormat(PString & str) const;
00187 virtual void SetPacketTime(const PString & optionName, const PString & value);
00188
00189 OpalTransportAddress transportAddress;
00190 Direction direction;
00191 WORD port;
00192 WORD portCount;
00193 OpalMediaType mediaType;
00194
00195 SDPMediaFormatList formats;
00196 SDPBandwidth bandwidth;
00197 };
00198
00199 PARRAY(SDPMediaDescriptionArray, SDPMediaDescription);
00200
00202
00203
00204
00205
00206 class SDPRTPAVPMediaDescription : public SDPMediaDescription
00207 {
00208 PCLASSINFO(SDPRTPAVPMediaDescription, SDPMediaDescription);
00209 public:
00210 SDPRTPAVPMediaDescription(const OpalTransportAddress & address);
00211 virtual PCaselessString GetSDPTransportType() const;
00212 virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
00213 virtual PString GetSDPPortList() const;
00214 virtual bool PrintOn(ostream & str, const PString & connectString) const;
00215 void SetAttribute(const PString & attr, const PString & value);
00216 };
00217
00219
00220
00221
00222
00223 class SDPAudioMediaDescription : public SDPRTPAVPMediaDescription
00224 {
00225 PCLASSINFO(SDPAudioMediaDescription, SDPRTPAVPMediaDescription);
00226 public:
00227 SDPAudioMediaDescription(const OpalTransportAddress & address);
00228 virtual PString GetSDPMediaType() const;
00229 virtual bool PrintOn(ostream & str, const PString & connectString) const;
00230 void SetAttribute(const PString & attr, const PString & value);
00231 };
00232
00234
00235
00236
00237
00238 class SDPVideoMediaDescription : public SDPRTPAVPMediaDescription
00239 {
00240 PCLASSINFO(SDPVideoMediaDescription, SDPRTPAVPMediaDescription);
00241 public:
00242 SDPVideoMediaDescription(const OpalTransportAddress & address);
00243 virtual PString GetSDPMediaType() const;
00244 };
00245
00247
00248
00249
00250
00251 class SDPApplicationMediaDescription : public SDPMediaDescription
00252 {
00253 PCLASSINFO(SDPApplicationMediaDescription, SDPMediaDescription);
00254 public:
00255 SDPApplicationMediaDescription(const OpalTransportAddress & address);
00256 virtual PCaselessString GetSDPTransportType() const;
00257 virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
00258 virtual PString GetSDPMediaType() const;
00259 virtual PString GetSDPPortList() const;
00260 };
00261
00263
00264 class SDPSessionDescription : public PObject
00265 {
00266 PCLASSINFO(SDPSessionDescription, PObject);
00267 public:
00268 SDPSessionDescription(
00269 const OpalTransportAddress & address = OpalTransportAddress()
00270 );
00271
00272 void PrintOn(ostream & strm) const;
00273 PString Encode() const;
00274 PBoolean Decode(const PString & str);
00275
00276 void SetSessionName(const PString & v) { sessionName = v; }
00277 PString GetSessionName() const { return sessionName; }
00278
00279 void SetUserName(const PString & v) { ownerUsername = v; }
00280 PString GetUserName() const { return ownerUsername; }
00281
00282 const SDPMediaDescriptionArray & GetMediaDescriptions() const { return mediaDescriptions; }
00283
00284 SDPMediaDescription * GetMediaDescriptionByType(const OpalMediaType & rtpMediaType) const;
00285 SDPMediaDescription * GetMediaDescriptionByIndex(PINDEX i) const;
00286 void AddMediaDescription(SDPMediaDescription * md) { mediaDescriptions.Append(md); }
00287
00288 void SetDirection(const SDPMediaDescription::Direction & d) { direction = d; }
00289 SDPMediaDescription::Direction GetDirection(unsigned) const;
00290 bool IsHold() const;
00291
00292 const OpalTransportAddress & GetDefaultConnectAddress() const { return defaultConnectAddress; }
00293 void SetDefaultConnectAddress(
00294 const OpalTransportAddress & address
00295 );
00296
00297 PINDEX GetOwnerSessionId() const { return ownerSessionId; }
00298 void SetOwnerSessionId(PINDEX value) { ownerSessionId = value; }
00299
00300 PINDEX GetOwnerVersion() const { return ownerVersion; }
00301 void SetOwnerVersion(PINDEX value) { ownerVersion = value; }
00302
00303 OpalTransportAddress GetOwnerAddress() const { return ownerAddress; }
00304 void SetOwnerAddress(OpalTransportAddress addr) { ownerAddress = addr; }
00305
00306 unsigned GetBandwidth(const PString & type) const { return bandwidth[type]; }
00307 void SetBandwidth(const PString & type, unsigned value) { bandwidth[type] = value; }
00308
00309 static const PString & ConferenceTotalBandwidthType();
00310 static const PString & ApplicationSpecificBandwidthType();
00311
00312 protected:
00313 void ParseOwner(const PString & str);
00314
00315 SDPMediaDescriptionArray mediaDescriptions;
00316 SDPMediaDescription::Direction direction;
00317
00318 PINDEX protocolVersion;
00319 PString sessionName;
00320
00321 PString ownerUsername;
00322 unsigned ownerSessionId;
00323 unsigned ownerVersion;
00324 OpalTransportAddress ownerAddress;
00325 OpalTransportAddress defaultConnectAddress;
00326
00327 SDPBandwidth bandwidth;
00328 };
00329
00331
00332
00333 #endif // OPAL_SIP
00334
00335 #endif // OPAL_SIP_SDP_H
00336
00337
00338