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 void SetMin(const PString & type, unsigned value);
00058 };
00059
00061
00062 class SDPMediaDescription;
00063
00064 class SDPMediaFormat : public PObject
00065 {
00066 PCLASSINFO(SDPMediaFormat, PObject);
00067 public:
00068 SDPMediaFormat(
00069 SDPMediaDescription & parent,
00070 RTP_DataFrame::PayloadTypes payloadType,
00071 const char * name = NULL
00072 );
00073
00074 SDPMediaFormat(
00075 SDPMediaDescription & parent,
00076 const OpalMediaFormat & mediaFormat
00077 );
00078
00079 virtual void PrintOn(ostream & str) const;
00080
00081 RTP_DataFrame::PayloadTypes GetPayloadType() const { return payloadType; }
00082
00083 const PCaselessString & GetEncodingName() const { return encodingName; }
00084 void SetEncodingName(const PString & v) { encodingName = v; }
00085
00086 void SetFMTP(const PString & _fmtp);
00087 PString GetFMTP() const;
00088
00089 unsigned GetClockRate(void) { return clockRate ; }
00090 void SetClockRate(unsigned v) { clockRate = v; }
00091
00092 void SetParameters(const PString & v) { parameters = v; }
00093
00094 const OpalMediaFormat & GetMediaFormat() const;
00095 OpalMediaFormat & GetWritableMediaFormat();
00096
00097 bool PreEncode();
00098 bool PostDecode(unsigned bandwidth);
00099
00100 protected:
00101 void InitialiseMediaFormat(OpalMediaFormat & mediaFormat) const;
00102 void SetMediaFormatOptions(OpalMediaFormat & mediaFormat) const;
00103
00104 OpalMediaFormat m_mediaFormat;
00105
00106 SDPMediaDescription & m_parent;
00107 RTP_DataFrame::PayloadTypes payloadType;
00108 unsigned clockRate;
00109 PCaselessString encodingName;
00110 PString parameters;
00111 PString m_fmtp;
00112 };
00113
00114 PLIST(SDPMediaFormatList, SDPMediaFormat);
00115
00117
00118 class SDPMediaDescription : public PObject
00119 {
00120 PCLASSINFO(SDPMediaDescription, PObject);
00121 public:
00122
00123
00124 enum Direction {
00125 Undefined = -1,
00126 Inactive,
00127 RecvOnly,
00128 SendOnly,
00129 SendRecv
00130 };
00131
00132 SDPMediaDescription(
00133 const OpalTransportAddress & address,
00134 const OpalMediaType & mediaType
00135 );
00136
00137 virtual bool PreEncode();
00138 virtual void Encode(const OpalTransportAddress & commonAddr, ostream & str) const;
00139 virtual bool PrintOn(ostream & strm, const PString & str) const;
00140
00141 virtual bool Decode(const PStringArray & tokens);
00142 virtual bool Decode(char key, const PString & value);
00143 virtual bool PostDecode();
00144
00145
00146 virtual PString GetSDPMediaType() const = 0;
00147
00148
00149 virtual PCaselessString GetSDPTransportType() const = 0;
00150
00151 virtual const SDPMediaFormatList & GetSDPMediaFormats() const
00152 { return formats; }
00153
00154 virtual OpalMediaFormatList GetMediaFormats() const;
00155
00156 virtual void AddSDPMediaFormat(SDPMediaFormat * sdpMediaFormat);
00157
00158 virtual void AddMediaFormat(const OpalMediaFormat & mediaFormat);
00159 virtual void AddMediaFormats(const OpalMediaFormatList & mediaFormats, const OpalMediaType & mediaType);
00160
00161 virtual void SetAttribute(const PString & attr, const PString & value);
00162
00163 virtual void SetDirection(const Direction & d) { direction = d; }
00164 virtual Direction GetDirection() const { return transportAddress.IsEmpty() ? Inactive : direction; }
00165
00166 virtual const OpalTransportAddress & GetTransportAddress() const { return transportAddress; }
00167 virtual PBoolean SetTransportAddress(const OpalTransportAddress &t);
00168
00169 virtual WORD GetPort() const { return port; }
00170
00171 virtual OpalMediaType GetMediaType() const { return mediaType; }
00172
00173 virtual unsigned GetBandwidth(const PString & type) const { return bandwidth[type]; }
00174 virtual void SetBandwidth(const PString & type, unsigned value) { bandwidth[type] = value; }
00175
00176 virtual const SDPBandwidth & GetBandwidth() const { return bandwidth; }
00177
00178 virtual void CreateSDPMediaFormats(const PStringArray & tokens);
00179 virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString) = 0;
00180
00181 virtual PString GetSDPPortList() const = 0;
00182
00183 virtual void ProcessMediaOptions(SDPMediaFormat & sdpFormat, const OpalMediaFormat & mediaFormat);
00184
00185 unsigned GetPTime () const { return ptime; }
00186 unsigned GetMaxPTime () const { return maxptime; }
00187
00188 protected:
00189 virtual SDPMediaFormat * FindFormat(PString & str) const;
00190
00191 OpalTransportAddress transportAddress;
00192 Direction direction;
00193 WORD port;
00194 WORD portCount;
00195 OpalMediaType mediaType;
00196
00197 SDPMediaFormatList formats;
00198 SDPBandwidth bandwidth;
00199 unsigned ptime;
00200 unsigned maxptime;
00201 };
00202
00203 PARRAY(SDPMediaDescriptionArray, SDPMediaDescription);
00204
00205
00206 class SDPDummyMediaDescription : public SDPMediaDescription
00207 {
00208 PCLASSINFO(SDPDummyMediaDescription, SDPMediaDescription);
00209 public:
00210 SDPDummyMediaDescription(const OpalTransportAddress & address, const PStringArray & tokens);
00211 virtual PString GetSDPMediaType() const;
00212 virtual PCaselessString GetSDPTransportType() const;
00213 virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
00214 virtual PString GetSDPPortList() const;
00215
00216 private:
00217 PStringArray m_tokens;
00218 };
00219
00220
00222
00223
00224
00225
00226 class SDPRTPAVPMediaDescription : public SDPMediaDescription
00227 {
00228 PCLASSINFO(SDPRTPAVPMediaDescription, SDPMediaDescription);
00229 public:
00230 SDPRTPAVPMediaDescription(const OpalTransportAddress & address, const OpalMediaType & mediaType);
00231 virtual PCaselessString GetSDPTransportType() const;
00232 virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
00233 virtual PString GetSDPPortList() const;
00234 virtual bool PrintOn(ostream & str, const PString & connectString) const;
00235 void SetAttribute(const PString & attr, const PString & value);
00236 };
00237
00239
00240
00241
00242
00243 class SDPAudioMediaDescription : public SDPRTPAVPMediaDescription
00244 {
00245 PCLASSINFO(SDPAudioMediaDescription, SDPRTPAVPMediaDescription);
00246 public:
00247 SDPAudioMediaDescription(const OpalTransportAddress & address);
00248 virtual PString GetSDPMediaType() const;
00249 virtual bool PrintOn(ostream & str, const PString & connectString) const;
00250 void SetAttribute(const PString & attr, const PString & value);
00251 };
00252
00254
00255
00256
00257
00258 class SDPVideoMediaDescription : public SDPRTPAVPMediaDescription
00259 {
00260 PCLASSINFO(SDPVideoMediaDescription, SDPRTPAVPMediaDescription);
00261 public:
00262 SDPVideoMediaDescription(const OpalTransportAddress & address);
00263 virtual PString GetSDPMediaType() const;
00264 virtual bool PreEncode();
00265 virtual bool PrintOn(ostream & str, const PString & connectString) const;
00266 void SetAttribute(const PString & attr, const PString & value);
00267 };
00268
00270
00271
00272
00273
00274 class SDPApplicationMediaDescription : public SDPMediaDescription
00275 {
00276 PCLASSINFO(SDPApplicationMediaDescription, SDPMediaDescription);
00277 public:
00278 SDPApplicationMediaDescription(const OpalTransportAddress & address);
00279 virtual PCaselessString GetSDPTransportType() const;
00280 virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
00281 virtual PString GetSDPMediaType() const;
00282 virtual PString GetSDPPortList() const;
00283 };
00284
00286
00287 class SDPSessionDescription : public PObject
00288 {
00289 PCLASSINFO(SDPSessionDescription, PObject);
00290 public:
00291 SDPSessionDescription(
00292 time_t sessionId,
00293 unsigned version,
00294 const OpalTransportAddress & address
00295 );
00296
00297 void PrintOn(ostream & strm) const;
00298 PString Encode() const;
00299 PBoolean Decode(const PString & str);
00300
00301 void SetSessionName(const PString & v);
00302 PString GetSessionName() const { return sessionName; }
00303
00304 void SetUserName(const PString & v);
00305 PString GetUserName() const { return ownerUsername; }
00306
00307 const SDPMediaDescriptionArray & GetMediaDescriptions() const { return mediaDescriptions; }
00308
00309 SDPMediaDescription * GetMediaDescriptionByType(const OpalMediaType & rtpMediaType) const;
00310 SDPMediaDescription * GetMediaDescriptionByIndex(PINDEX i) const;
00311 void AddMediaDescription(SDPMediaDescription * md) { mediaDescriptions.Append(md); }
00312
00313 void SetDirection(const SDPMediaDescription::Direction & d) { direction = d; }
00314 SDPMediaDescription::Direction GetDirection(unsigned) const;
00315 bool IsHold() const;
00316
00317 const OpalTransportAddress & GetDefaultConnectAddress() const { return defaultConnectAddress; }
00318 void SetDefaultConnectAddress(
00319 const OpalTransportAddress & address
00320 );
00321
00322 time_t GetOwnerSessionId() const { return ownerSessionId; }
00323 void SetOwnerSessionId(time_t value) { ownerSessionId = value; }
00324
00325 PINDEX GetOwnerVersion() const { return ownerVersion; }
00326 void SetOwnerVersion(PINDEX value) { ownerVersion = value; }
00327
00328 OpalTransportAddress GetOwnerAddress() const { return ownerAddress; }
00329 void SetOwnerAddress(OpalTransportAddress addr) { ownerAddress = addr; }
00330
00331 unsigned GetBandwidth(const PString & type) const { return bandwidth[type]; }
00332 void SetBandwidth(const PString & type, unsigned value) { bandwidth[type] = value; }
00333
00334 OpalMediaFormatList GetMediaFormats() const;
00335
00336 static const PString & ConferenceTotalBandwidthType();
00337 static const PString & ApplicationSpecificBandwidthType();
00338 static const PString & TransportIndependentBandwidthType();
00339
00340 protected:
00341 void ParseOwner(const PString & str);
00342
00343 SDPMediaDescriptionArray mediaDescriptions;
00344 SDPMediaDescription::Direction direction;
00345
00346 PINDEX protocolVersion;
00347 PString sessionName;
00348
00349 PString ownerUsername;
00350 time_t ownerSessionId;
00351 unsigned ownerVersion;
00352 OpalTransportAddress ownerAddress;
00353 OpalTransportAddress defaultConnectAddress;
00354
00355 SDPBandwidth bandwidth;
00356 };
00357
00359
00360
00361 #endif // OPAL_SIP
00362
00363 #endif // OPAL_SIP_SDP_H
00364
00365
00366