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 #ifndef OPAL_OPAL_RTPCONN_H
00032 #define OPAL_OPAL_RTPCONN_H
00033
00034 #ifdef P_USE_PRAGMA
00035 #pragma interface
00036 #endif
00037
00038 #include <opal/buildopts.h>
00039
00040 #include <opal/connection.h>
00041 #include <opal/mediatype.h>
00042
00043 #ifdef OPAL_ZRTP
00044
00045 class OpalZRTPStreamInfo {
00046 public:
00047 virtual bool Open() = 0;
00048 virtual RTP_UDP * CreateRTPSession(OpalConnection & conn, unsigned sessionId, bool remoteIsNat) = 0;
00049 };
00050
00051 class OpalZRTPConnectionInfo {
00052 public:
00053 virtual bool Open() = 0;
00054 virtual RTP_UDP * CreateRTPSession(OpalConnection & conn, unsigned sessionId, bool remoteIsNat) = 0;
00055
00056 PMutex mutex;
00057 };
00058
00059 #endif // OPAL_ZRTP
00060
00061
00062 class OpalRTPEndPoint;
00063
00064
00065
00066
00067
00068
00069
00072 class OpalMediaSession : public PObject
00073 {
00074 PCLASSINFO(OpalMediaSession, PObject);
00075 public:
00076 OpalMediaSession(OpalConnection & conn, const OpalMediaType & _mediaType, unsigned sessionId);
00077 OpalMediaSession(const OpalMediaSession & _obj);
00078
00079 virtual void Close() = 0;
00080
00081 virtual PObject * Clone() const = 0;
00082
00083 virtual bool IsActive() const = 0;
00084
00085 virtual bool IsRTP() const = 0;
00086
00087 virtual bool HasFailed() const = 0;
00088
00089 virtual OpalTransportAddress GetLocalMediaAddress() const = 0;
00090
00091 virtual void SetRemoteMediaAddress(const OpalTransportAddress &, const OpalMediaFormatList & ) { }
00092
00093 #if OPAL_SIP
00094 virtual SDPMediaDescription * CreateSDPMediaDescription(
00095 const OpalTransportAddress & localAddress
00096 ) = 0;
00097 #endif
00098
00099 virtual OpalMediaStream * CreateMediaStream(
00100 const OpalMediaFormat & mediaFormat,
00101 unsigned sessionID,
00102 PBoolean isSource
00103 ) = 0;
00104
00105 OpalConnection & connection;
00106 OpalMediaType mediaType;
00107 unsigned sessionId;
00108 };
00109
00110
00113 class OpalRTPMediaSession : public OpalMediaSession
00114 {
00115 PCLASSINFO(OpalRTPMediaSession, OpalMediaSession);
00116 public:
00117 OpalRTPMediaSession(
00118 OpalConnection & conn,
00119 const OpalMediaType & mediaType,
00120 unsigned sessionId
00121 );
00122 OpalRTPMediaSession(const OpalRTPMediaSession & obj);
00123 ~OpalRTPMediaSession();
00124
00125 PObject * Clone() const { return new OpalRTPMediaSession(*this); }
00126
00127 void Attach(RTP_Session * rtpSession);
00128
00129 virtual void Close();
00130
00131 virtual bool IsActive() const { return rtpSession != NULL; }
00132
00133 virtual bool IsRTP() const { return true; }
00134
00135 virtual bool HasFailed() const { return (rtpSession != NULL) && (rtpSession->HasFailed() || (rtpSession->GetPacketsReceived() == 0)); }
00136
00137 virtual OpalTransportAddress GetLocalMediaAddress() const;
00138
00139 #if OPAL_SIP
00140 virtual SDPMediaDescription * CreateSDPMediaDescription(
00141 const OpalTransportAddress & localAddress
00142 );
00143 #endif
00144
00145 virtual OpalMediaStream * CreateMediaStream(
00146 const OpalMediaFormat & mediaFormat,
00147 unsigned sessionID,
00148 PBoolean isSource
00149 );
00150
00151 RTP_Session * GetSession() const { return rtpSession; }
00152
00153 protected:
00154 RTP_Session * rtpSession;
00155 };
00156
00159 class OpalRTPSessionManager : public PObject
00160 {
00161 PCLASSINFO(OpalRTPSessionManager , PObject);
00162 public:
00167 OpalRTPSessionManager(
00168 OpalRTPConnection & connection
00169 );
00170
00172 ~OpalRTPSessionManager();
00173
00175 OpalRTPSessionManager(const OpalRTPSessionManager & other);
00176
00178 void operator=(const OpalRTPSessionManager & other) { sessions = other.sessions; }
00180
00185 unsigned GetNextSessionID();
00186
00193 void AddSession(
00194 RTP_Session * session,
00195 const OpalMediaType & mediaType
00196 );
00197 void AddMediaSession(
00198 OpalMediaSession * session,
00199 const OpalMediaType & mediaType
00200 );
00201
00204 virtual void CloseSession(
00205 unsigned sessionID
00206 );
00207
00210 RTP_Session * GetSession(
00211 unsigned sessionID
00212 ) const;
00213 OpalMediaSession * GetMediaSession(
00214 unsigned sessionID
00215 ) const;
00216
00222 bool ChangeSessionID(
00223 unsigned fromSessionID,
00224 unsigned toSessionID
00225 );
00227
00228 PMutex & GetMutex() { return m_mutex; }
00229
00230 virtual bool AllSessionsFailing();
00231
00232 protected:
00233 OpalRTPConnection & m_connection;
00234 PMutex m_mutex;
00235
00236 PDICTIONARY(SessionDict, POrdinalKey, OpalMediaSession);
00237 SessionDict sessions;
00238 };
00239
00240
00241 typedef OpalRTPSessionManager RTP_SessionManager;
00242
00243
00247 class OpalRTPConnection : public OpalConnection
00248 {
00249 PCLASSINFO(OpalRTPConnection, OpalConnection);
00250 public:
00255 OpalRTPConnection(
00256 OpalCall & call,
00257 OpalRTPEndPoint & endpoint,
00258 const PString & token,
00259 unsigned options = 0,
00260 OpalConnection::StringOptions * stringOptions = NULL
00261 );
00262
00265 ~OpalRTPConnection();
00266
00284 virtual void OnReleased();
00286
00287
00292 virtual unsigned GetNextSessionID(
00293 const OpalMediaType & mediaType,
00294 bool isSource
00295 );
00296
00300 virtual RTP_Session * GetSession(
00301 unsigned sessionID
00302 ) const;
00303 virtual OpalMediaSession * GetMediaSession(
00304 unsigned sessionID
00305 ) const;
00306
00315 virtual RTP_Session * UseSession(
00316 const OpalTransport & transport,
00317 unsigned sessionID,
00318 const OpalMediaType & mediatype,
00319 RTP_QOS * rtpqos = NULL
00320 );
00321
00324 virtual void CloseSession(
00325 unsigned sessionID
00326 );
00327
00332 virtual RTP_Session * CreateSession(
00333 const OpalTransport & transport,
00334 unsigned sessionID,
00335 const OpalMediaType & mediaType,
00336 RTP_QOS * rtpqos
00337 );
00338
00341 virtual RTP_UDP * CreateRTPSession(
00342 unsigned sessionId,
00343 const OpalMediaType & mediaType,
00344 bool remoteIsNat
00345 );
00346
00352 virtual bool ChangeSessionID(
00353 unsigned fromSessionID,
00354 unsigned toSessionID
00355 );
00357
00362 virtual PBoolean RemoteIsNAT() const
00363 { return remoteIsNAT; }
00364
00382 virtual PBoolean IsRTPNATEnabled(
00383 const PIPSocket::Address & localAddr,
00384 const PIPSocket::Address & peerAddr,
00385 const PIPSocket::Address & signalAddr,
00386 PBoolean incoming
00387 );
00389
00394 virtual void AttachRFC2833HandlerToPatch(PBoolean isSource, OpalMediaPatch & patch);
00395
00396 virtual PBoolean SendUserInputTone(
00397 char tone,
00398 unsigned duration = 0
00399 );
00400
00403 struct MediaInformation {
00404 MediaInformation() {
00405 rfc2833 = RTP_DataFrame::IllegalPayloadType;
00406 ciscoNSE = RTP_DataFrame::IllegalPayloadType;
00407 }
00408
00409 OpalTransportAddress data;
00410 OpalTransportAddress control;
00411 RTP_DataFrame::PayloadTypes rfc2833;
00412 RTP_DataFrame::PayloadTypes ciscoNSE;
00413 };
00415
00426 virtual PBoolean GetMediaInformation(
00427 unsigned sessionID,
00428 MediaInformation & info
00429 ) const;
00430
00435 virtual PBoolean IsMediaBypassPossible(
00436 unsigned sessionID
00437 ) const;
00438
00451 virtual OpalMediaStream * CreateMediaStream(
00452 const OpalMediaFormat & mediaFormat,
00453 unsigned sessionID,
00454 PBoolean isSource
00455 );
00456
00470 virtual void AdjustMediaFormats(
00471 bool local,
00472 const OpalConnection * otherConnection,
00473 OpalMediaFormatList & mediaFormats
00474 ) const;
00475
00484 virtual void OnPatchMediaStream(
00485 PBoolean isSource,
00486 OpalMediaPatch & patch
00487 );
00488
00494 virtual bool OnMediaCommand(
00495 OpalMediaStream & stream,
00496 const OpalMediaCommand & command
00497 );
00499
00500 virtual void SessionFailing(RTP_Session & session);
00501
00502 protected:
00503 PDECLARE_NOTIFIER(OpalRFC2833Info, OpalRTPConnection, OnUserInputInlineRFC2833);
00504 PDECLARE_NOTIFIER(OpalRFC2833Info, OpalRTPConnection, OnUserInputInlineCiscoNSE);
00505
00506 OpalRTPSessionManager m_rtpSessions;
00507 OpalRFC2833Proto * rfc2833Handler;
00508 #if OPAL_T38_CAPABILITY
00509 OpalRFC2833Proto * ciscoNSEHandler;
00510 #endif
00511
00512 PBoolean remoteIsNAT;
00513 PBoolean useRTPAggregation;
00514
00515 #ifdef OPAL_ZRTP
00516 bool zrtpEnabled;
00517 PMutex zrtpConnInfoMutex;
00518 OpalZRTPConnectionInfo * zrtpConnInfo;
00519 #endif
00520 };
00521
00522
00523 class RTP_UDP;
00524
00525 class OpalSecurityMode : public PObject
00526 {
00527 PCLASSINFO(OpalSecurityMode, PObject);
00528 public:
00529 virtual RTP_UDP * CreateRTPSession(
00530 OpalRTPConnection & connection,
00531 const RTP_Session::Params & options
00532 ) = 0;
00533 virtual PBoolean Open() = 0;
00534 };
00535
00536 #endif // OPAL_OPAL_RTPCONN_H