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_session.h>
00047
00048
00049
00053 #define OPAL_OPT_OFFER_SDP_PTIME "Offer-SDP-PTime"
00054
00062 #define OPAL_OPT_OFFER_RTCP_FB "Offer-RTCP-FB"
00063
00068 #define OPAL_OPT_FORCE_RTCP_FB "Force-RTCP-FB"
00069
00070
00072
00073 class SDPBandwidth : public std::map<PCaselessString, OpalBandwidth>
00074 {
00075 typedef std::map<PCaselessString, OpalBandwidth> BaseClass;
00076 public:
00077 OpalBandwidth & operator[](const PCaselessString & type);
00078 OpalBandwidth operator[](const PCaselessString & type) const;
00079 friend ostream & operator<<(ostream & out, const SDPBandwidth & bw);
00080 bool Parse(const PString & param);
00081 void SetMax(const PCaselessString & type, OpalBandwidth value);
00082 };
00083
00085
00086 class SDPMediaDescription;
00087
00088 class SDPMediaFormat : public PObject
00089 {
00090 PCLASSINFO(SDPMediaFormat, PObject);
00091 public:
00092 SDPMediaFormat(
00093 SDPMediaDescription & parent,
00094 RTP_DataFrame::PayloadTypes payloadType,
00095 const char * name = NULL
00096 );
00097
00098 SDPMediaFormat(
00099 SDPMediaDescription & parent,
00100 const OpalMediaFormat & mediaFormat
00101 );
00102
00103 virtual void PrintOn(ostream & str) const;
00104 virtual PObject * Clone() const { return new SDPMediaFormat(*this); }
00105
00106 RTP_DataFrame::PayloadTypes GetPayloadType() const { return payloadType; }
00107
00108 const PCaselessString & GetEncodingName() const { return encodingName; }
00109 void SetEncodingName(const PString & v) { encodingName = v; }
00110
00111 void SetFMTP(const PString & _fmtp);
00112 PString GetFMTP() const;
00113
00114 unsigned GetClockRate(void) { return clockRate ; }
00115 void SetClockRate(unsigned v) { clockRate = v; }
00116
00117 void SetParameters(const PString & v) { parameters = v; }
00118
00119 #if OPAL_VIDEO
00120 void SetRTCP_FB(const PString & v) { m_rtcp_fb.FromString(v); }
00121 OpalVideoFormat::RTCPFeedback GetRTCP_FB() const { return m_rtcp_fb; }
00122 #endif
00123
00124 const OpalMediaFormat & GetMediaFormat() const { return m_mediaFormat; }
00125 OpalMediaFormat & GetWritableMediaFormat() { return m_mediaFormat; }
00126
00127 bool PreEncode();
00128 bool PostDecode(const OpalMediaFormatList & mediaFormats, unsigned bandwidth);
00129
00130 protected:
00131 void SetMediaFormatOptions(OpalMediaFormat & mediaFormat) const;
00132
00133 OpalMediaFormat m_mediaFormat;
00134
00135 SDPMediaDescription & m_parent;
00136 RTP_DataFrame::PayloadTypes payloadType;
00137 unsigned clockRate;
00138 PCaselessString encodingName;
00139 PString parameters;
00140 PString m_fmtp;
00141 #if OPAL_VIDEO
00142 OpalVideoFormat::RTCPFeedback m_rtcp_fb;
00143 #endif
00144 };
00145
00146 typedef PList<SDPMediaFormat> SDPMediaFormatList;
00147
00148
00150
00151 class SDPCommonAttributes
00152 {
00153 public:
00154
00155
00156 enum Direction {
00157 Undefined = -1,
00158 Inactive,
00159 RecvOnly,
00160 SendOnly,
00161 SendRecv
00162 };
00163
00164 SDPCommonAttributes()
00165 : m_direction(Undefined)
00166 { }
00167
00168 virtual ~SDPCommonAttributes() { }
00169
00170 virtual void SetDirection(const Direction & d) { m_direction = d; }
00171 virtual Direction GetDirection() const { return m_direction; }
00172
00173 virtual OpalBandwidth GetBandwidth(const PString & type) const { return m_bandwidth[type]; }
00174 virtual void SetBandwidth(const PString & type, OpalBandwidth value) { m_bandwidth[type] = value; }
00175
00176 virtual const SDPBandwidth & GetBandwidth() const { return m_bandwidth; }
00177
00178 virtual const RTPExtensionHeaders & GetExtensionHeaders() const { return m_extensionHeaders; }
00179 virtual void SetExtensionHeader(const RTPExtensionHeaderInfo & ext) { m_extensionHeaders.insert(ext); }
00180
00181 virtual void ParseAttribute(const PString & value);
00182 virtual void SetAttribute(const PString & attr, const PString & value);
00183
00184 virtual void OutputAttributes(ostream & strm) const;
00185
00186 static const PCaselessString & ConferenceTotalBandwidthType();
00187 static const PCaselessString & ApplicationSpecificBandwidthType();
00188 static const PCaselessString & TransportIndependentBandwidthType();
00189
00190 protected:
00191 Direction m_direction;
00192 SDPBandwidth m_bandwidth;
00193 RTPExtensionHeaders m_extensionHeaders;
00194 };
00195
00196
00198
00199 class SDPMediaDescription : public PObject, public SDPCommonAttributes
00200 {
00201 PCLASSINFO(SDPMediaDescription, PObject);
00202 public:
00203 SDPMediaDescription(
00204 const OpalTransportAddress & address,
00205 const OpalMediaType & mediaType
00206 );
00207
00208 virtual bool PreEncode();
00209 virtual void Encode(const OpalTransportAddress & commonAddr, ostream & str) const;
00210
00211 virtual bool Decode(const PStringArray & tokens);
00212 virtual bool Decode(char key, const PString & value);
00213 virtual bool PostDecode(const OpalMediaFormatList & mediaFormats);
00214
00215
00216 virtual PString GetSDPMediaType() const = 0;
00217
00218
00219 virtual PCaselessString GetSDPTransportType() const = 0;
00220
00221 virtual const SDPMediaFormatList & GetSDPMediaFormats() const
00222 { return formats; }
00223
00224 virtual OpalMediaFormatList GetMediaFormats() const;
00225
00226 virtual void AddSDPMediaFormat(SDPMediaFormat * sdpMediaFormat);
00227
00228 virtual void AddMediaFormat(const OpalMediaFormat & mediaFormat);
00229 virtual void AddMediaFormats(const OpalMediaFormatList & mediaFormats, const OpalMediaType & mediaType);
00230
00231 virtual void SetCryptoKeys(OpalMediaCryptoKeyList & cryptoKeys);
00232 virtual OpalMediaCryptoKeyList GetCryptoKeys() const;
00233
00234 virtual void SetAttribute(const PString & attr, const PString & value);
00235
00236 virtual Direction GetDirection() const { return m_transportAddress.IsEmpty() ? Inactive : m_direction; }
00237
00238 virtual const OpalTransportAddress & GetTransportAddress() const { return m_transportAddress; }
00239 virtual PBoolean SetTransportAddress(const OpalTransportAddress &t);
00240
00241 virtual WORD GetPort() const { return m_port; }
00242
00243 virtual OpalMediaType GetMediaType() const { return m_mediaType; }
00244
00245 virtual void CreateSDPMediaFormats(const PStringArray & tokens);
00246 virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString) = 0;
00247
00248 virtual PString GetSDPPortList() const;
00249
00250 virtual void ProcessMediaOptions(SDPMediaFormat & sdpFormat, const OpalMediaFormat & mediaFormat);
00251
00252 #if OPAL_VIDEO
00253 virtual OpalVideoFormat::ContentRole GetContentRole() const { return OpalVideoFormat::eNoRole; }
00254 #endif
00255
00256 void SetOptionStrings(const PStringOptions & options) { m_stringOptions = options; }
00257 const PStringOptions & GetOptionStrings() const { return m_stringOptions; }
00258
00259 virtual void Copy(SDPMediaDescription & mediaDescription);
00260
00261 protected:
00262 virtual SDPMediaFormat * FindFormat(PString & str) const;
00263
00264 OpalTransportAddress m_transportAddress;
00265 PCaselessString m_transportType;
00266 PStringOptions m_stringOptions;
00267 WORD m_port;
00268 WORD m_portCount;
00269 OpalMediaType m_mediaType;
00270
00271 SDPMediaFormatList formats;
00272 };
00273
00274 PARRAY(SDPMediaDescriptionArray, SDPMediaDescription);
00275
00276
00277 class SDPDummyMediaDescription : public SDPMediaDescription
00278 {
00279 PCLASSINFO(SDPDummyMediaDescription, SDPMediaDescription);
00280 public:
00281 SDPDummyMediaDescription(const OpalTransportAddress & address, const PStringArray & tokens);
00282 virtual PString GetSDPMediaType() const;
00283 virtual PCaselessString GetSDPTransportType() const;
00284 virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
00285 virtual PString GetSDPPortList() const;
00286 virtual void Copy(SDPMediaDescription & mediaDescription);
00287
00288 private:
00289 PStringArray m_tokens;
00290 };
00291
00292
00293 class SDPDummySession : public OpalMediaSession
00294 {
00295 PCLASSINFO(SDPDummySession, OpalMediaSession)
00296 public:
00297 SDPDummySession(const Init & init);
00298 static const PCaselessString & SessionType();
00299 virtual const PCaselessString & GetSessionType() const;
00300 virtual SDPMediaDescription * CreateSDPMediaDescription();
00301 virtual OpalMediaStream * CreateMediaStream(const OpalMediaFormat & mediaFormat, unsigned sessionID, bool isSource);
00302
00303 private:
00304 PStringArray m_tokens;
00305 };
00306
00307
00308 class SDPCryptoSuite : public PObject
00309 {
00310 PCLASSINFO(SDPCryptoSuite, PObject)
00311 public:
00312 SDPCryptoSuite(unsigned tag);
00313
00314 bool SetKeyInfo(const OpalMediaCryptoKeyInfo & keyInfo);
00315 OpalMediaCryptoKeyInfo * GetKeyInfo() const;
00316
00317 bool Decode(const PString & attrib);
00318 void PrintOn(ostream & strm) const;
00319
00320 struct KeyParam {
00321 KeyParam(const PString & keySalt)
00322 : m_keySalt(keySalt)
00323 , m_lifetime(0)
00324 , m_mkiIndex(0)
00325 , m_mkiLength(0)
00326 { }
00327
00328 PString m_keySalt;
00329 PUInt64 m_lifetime;
00330 unsigned m_mkiIndex;
00331 unsigned m_mkiLength;
00332 };
00333
00334 unsigned GetTag() const { return m_tag; }
00335 const PString & GetName() const { return m_suiteName; }
00336
00337 protected:
00338 unsigned m_tag;
00339 PString m_suiteName;
00340 list<KeyParam> m_keyParams;
00341 PStringOptions m_sessionParams;
00342 };
00343
00345
00346
00347
00348
00349 class SDPRTPAVPMediaDescription : public SDPMediaDescription
00350 {
00351 PCLASSINFO(SDPRTPAVPMediaDescription, SDPMediaDescription);
00352 public:
00353 SDPRTPAVPMediaDescription(const OpalTransportAddress & address, const OpalMediaType & mediaType);
00354 virtual bool Decode(const PStringArray & tokens);
00355 virtual PCaselessString GetSDPTransportType() const;
00356 virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
00357 virtual PString GetSDPPortList() const;
00358 virtual bool PreEncode();
00359 virtual void OutputAttributes(ostream & str) const;
00360 virtual void SetCryptoKeys(OpalMediaCryptoKeyList & cryptoKeys);
00361 virtual OpalMediaCryptoKeyList GetCryptoKeys() const;
00362 virtual void SetAttribute(const PString & attr, const PString & value);
00363
00364 void EnableFeedback() { m_enableFeedback = true; }
00365
00366 protected:
00367 bool m_enableFeedback;
00368 #if OPAL_VIDEO
00369 OpalVideoFormat::RTCPFeedback m_rtcp_fb;
00370 #endif
00371 PList<SDPCryptoSuite> m_cryptoSuites;
00372 };
00373
00375
00376
00377
00378
00379 class SDPAudioMediaDescription : public SDPRTPAVPMediaDescription
00380 {
00381 PCLASSINFO(SDPAudioMediaDescription, SDPRTPAVPMediaDescription);
00382 public:
00383 SDPAudioMediaDescription(const OpalTransportAddress & address);
00384 virtual PString GetSDPMediaType() const;
00385 virtual void OutputAttributes(ostream & str) const;
00386 virtual void SetAttribute(const PString & attr, const PString & value);
00387 virtual bool PostDecode(const OpalMediaFormatList & mediaFormats);
00388
00389 protected:
00390 unsigned m_PTime;
00391 unsigned m_maxPTime;
00392 };
00393
00394
00395 #if OPAL_VIDEO
00396
00398
00399
00400
00401
00402 class SDPVideoMediaDescription : public SDPRTPAVPMediaDescription
00403 {
00404 PCLASSINFO(SDPVideoMediaDescription, SDPRTPAVPMediaDescription);
00405 public:
00406 SDPVideoMediaDescription(const OpalTransportAddress & address);
00407 virtual PString GetSDPMediaType() const;
00408 virtual bool PreEncode();
00409 virtual void OutputAttributes(ostream & str) const;
00410 virtual void SetAttribute(const PString & attr, const PString & value);
00411 virtual bool PostDecode(const OpalMediaFormatList & mediaFormats);
00412 virtual OpalVideoFormat::ContentRole GetContentRole() const { return m_contentRole; }
00413
00414 protected:
00415 OpalVideoFormat::ContentRole m_contentRole;
00416 unsigned m_contentMask;
00417 };
00418
00419 #endif // OPAL_VIDEO
00420
00421
00423
00424
00425
00426
00427 class SDPApplicationMediaDescription : public SDPMediaDescription
00428 {
00429 PCLASSINFO(SDPApplicationMediaDescription, SDPMediaDescription);
00430 public:
00431 SDPApplicationMediaDescription(const OpalTransportAddress & address);
00432 virtual PCaselessString GetSDPTransportType() const;
00433 virtual SDPMediaFormat * CreateSDPMediaFormat(const PString & portString);
00434 virtual PString GetSDPMediaType() const;
00435 };
00436
00438
00439 class SDPSessionDescription : public PObject, public SDPCommonAttributes
00440 {
00441 PCLASSINFO(SDPSessionDescription, PObject);
00442 public:
00443 SDPSessionDescription(
00444 time_t sessionId,
00445 unsigned version,
00446 const OpalTransportAddress & address
00447 );
00448
00449 void PrintOn(ostream & strm) const;
00450 PString Encode() const;
00451 bool Decode(const PString & str, const OpalMediaFormatList & mediaFormats);
00452
00453 void SetSessionName(const PString & v);
00454 PString GetSessionName() const { return sessionName; }
00455
00456 void SetUserName(const PString & v);
00457 PString GetUserName() const { return ownerUsername; }
00458
00459 const SDPMediaDescriptionArray & GetMediaDescriptions() const { return mediaDescriptions; }
00460
00461 SDPMediaDescription * GetMediaDescriptionByType(const OpalMediaType & rtpMediaType) const;
00462 SDPMediaDescription * GetMediaDescriptionByIndex(PINDEX i) const;
00463 void AddMediaDescription(SDPMediaDescription * md) { mediaDescriptions.Append(PAssertNULL(md)); }
00464
00465 virtual SDPMediaDescription::Direction GetDirection(unsigned) const;
00466 bool IsHold() const;
00467
00468 const OpalTransportAddress & GetDefaultConnectAddress() const { return defaultConnectAddress; }
00469 void SetDefaultConnectAddress(
00470 const OpalTransportAddress & address
00471 );
00472
00473 time_t GetOwnerSessionId() const { return ownerSessionId; }
00474 void SetOwnerSessionId(time_t value) { ownerSessionId = value; }
00475
00476 unsigned GetOwnerVersion() const { return ownerVersion; }
00477 void SetOwnerVersion(unsigned value) { ownerVersion = value; }
00478
00479 OpalTransportAddress GetOwnerAddress() const { return ownerAddress; }
00480 void SetOwnerAddress(OpalTransportAddress addr) { ownerAddress = addr; }
00481
00482 OpalMediaFormatList GetMediaFormats() const;
00483
00484 protected:
00485 void ParseOwner(const PString & str);
00486
00487 SDPMediaDescriptionArray mediaDescriptions;
00488
00489 PINDEX protocolVersion;
00490 PString sessionName;
00491
00492 PString ownerUsername;
00493 time_t ownerSessionId;
00494 unsigned ownerVersion;
00495 OpalTransportAddress ownerAddress;
00496 OpalTransportAddress defaultConnectAddress;
00497 };
00498
00500
00501
00502 #endif // OPAL_SIP
00503
00504 #endif // OPAL_SIP_SDP_H
00505
00506
00507