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 
00112 class OpalRTPMediaSession : public OpalMediaSession
00113 {
00114   PCLASSINFO(OpalRTPMediaSession, OpalMediaSession);
00115   public:
00116     OpalRTPMediaSession(OpalConnection & conn, const OpalMediaType & mediaType, unsigned sessionId);
00117     OpalRTPMediaSession(const OpalRTPMediaSession & obj);
00118 
00119     PObject * Clone() const { return new OpalRTPMediaSession(*this); }
00120 
00121     virtual void Close();
00122 
00123     virtual bool IsActive() const { return rtpSession != NULL; }
00124 
00125     virtual bool IsRTP() const { return true; }
00126 
00127     virtual bool HasFailed() const { return (rtpSession != NULL) && (rtpSession->HasFailed() || (rtpSession->GetPacketsReceived() == 0)); }
00128 
00129     virtual OpalTransportAddress GetLocalMediaAddress() const;
00130 
00131 #if OPAL_SIP
00132     virtual SDPMediaDescription * CreateSDPMediaDescription(
00133       const OpalTransportAddress & localAddress
00134     );
00135 #endif
00136 
00137     virtual OpalMediaStream * CreateMediaStream(
00138       const OpalMediaFormat & mediaFormat, 
00139       unsigned sessionID, 
00140       PBoolean isSource
00141     );
00142 
00143     RTP_Session * rtpSession;    
00144 };
00145 
00148 class OpalRTPSessionManager : public PObject
00149 {
00150   PCLASSINFO(OpalRTPSessionManager , PObject);
00151 
00152   public:
00157     OpalRTPSessionManager(OpalConnection & conn);
00158     ~OpalRTPSessionManager();
00159     void operator=(const OpalRTPSessionManager & other) { sessions = other.sessions; }
00161 
00170     void AddSession(
00171       RTP_Session * session,          
00172       const OpalMediaType & mediaType 
00173     );
00174     void AddMediaSession(
00175       OpalMediaSession * session,          
00176       const OpalMediaType & mediaType 
00177     );
00178 
00181     void ReleaseSession(
00182       unsigned sessionID,    
00183       PBoolean clearAll = PFalse  
00184     );
00185 
00188     RTP_Session * GetSession(
00189       unsigned sessionID    
00190     ) const;
00191     OpalMediaSession * GetMediaSession(
00192       unsigned sessionID
00193     ) const;
00195 
00196     PMutex & GetMutex() { return m_mutex; }
00197 
00198     virtual bool AllSessionsFailing();
00199 
00200   protected:
00201     OpalConnection & connection;
00202     PMutex m_mutex;
00203 
00204     PDICTIONARY(SessionDict, POrdinalKey, OpalMediaSession);
00205     SessionDict sessions;
00206 };
00207 
00208 typedef OpalRTPSessionManager RTP_SessionManager;
00209 
00213 class OpalRTPConnection : public OpalConnection
00214 {
00215   PCLASSINFO(OpalRTPConnection, OpalConnection);
00216   public:
00221     OpalRTPConnection(
00222       OpalCall & call,                         
00223       OpalRTPEndPoint & endpoint,              
00224       const PString & token,                   
00225       unsigned options = 0,                    
00226       OpalConnection::StringOptions * stringOptions = NULL     
00227     );  
00228 
00231     ~OpalRTPConnection();
00232 
00233 
00239     virtual RTP_Session * GetSession(
00240       unsigned sessionID    
00241     ) const;
00242     virtual OpalMediaSession * GetMediaSession(
00243       unsigned sessionID    
00244     ) const;
00245 
00254     virtual RTP_Session * UseSession(
00255       const OpalTransport & transport,  
00256       unsigned sessionID,               
00257       const OpalMediaType & mediatype,  
00258       RTP_QOS * rtpqos = NULL           
00259     );
00260 
00263     virtual void ReleaseSession(
00264       unsigned sessionID,    
00265       PBoolean clearAll = PFalse  
00266     );
00267 
00272     virtual RTP_Session * CreateSession(
00273       const OpalTransport & transport,
00274       unsigned sessionID,
00275       RTP_QOS * rtpqos
00276     );
00277 
00280     virtual RTP_UDP * CreateRTPSession(
00281       unsigned sessionId,
00282       bool remoteIsNat
00283     );
00285 
00287 
00289     virtual PBoolean RemoteIsNAT() const
00290     { return remoteIsNAT; }
00291 
00309     virtual PBoolean IsRTPNATEnabled(
00310       const PIPSocket::Address & localAddr,   
00311       const PIPSocket::Address & peerAddr,    
00312       const PIPSocket::Address & signalAddr,  
00313       PBoolean incoming                       
00314     );
00316 
00321     virtual void AttachRFC2833HandlerToPatch(PBoolean isSource, OpalMediaPatch & patch);
00322 
00323     virtual PBoolean SendUserInputTone(
00324       char tone,        
00325       unsigned duration = 0  
00326     );
00327 
00330     struct MediaInformation {
00331       MediaInformation() { 
00332         rfc2833  = RTP_DataFrame::IllegalPayloadType; 
00333         ciscoNSE = RTP_DataFrame::IllegalPayloadType; 
00334       }
00335 
00336       OpalTransportAddress data;           
00337       OpalTransportAddress control;        
00338       RTP_DataFrame::PayloadTypes rfc2833; 
00339       RTP_DataFrame::PayloadTypes ciscoNSE; 
00340     };
00341 
00350     virtual PBoolean GetMediaInformation(
00351       unsigned sessionID,     
00352       MediaInformation & info 
00353     ) const;
00354 
00359     virtual PBoolean IsMediaBypassPossible(
00360       unsigned sessionID                  
00361     ) const;
00362 
00375     virtual OpalMediaStream * CreateMediaStream(
00376       const OpalMediaFormat & mediaFormat, 
00377       unsigned sessionID,                  
00378       PBoolean isSource                        
00379     );
00380 
00383     virtual void OnPatchMediaStream(PBoolean isSource, OpalMediaPatch & patch);
00384 
00385     void OnMediaCommand(OpalMediaCommand & command, INT extra);
00386 
00387     PDECLARE_NOTIFIER(OpalRFC2833Info, OpalRTPConnection, OnUserInputInlineRFC2833);
00388     PDECLARE_NOTIFIER(OpalRFC2833Info, OpalRTPConnection, OnUserInputInlineCiscoNSE);
00389 
00390     virtual void SessionFailing(RTP_Session & session);
00391 
00392   protected:
00393     OpalRTPSessionManager m_rtpSessions;
00394     OpalRFC2833Proto * rfc2833Handler;
00395 #if OPAL_T38_CAPABILITY
00396     OpalRFC2833Proto * ciscoNSEHandler;
00397 #endif
00398 
00399     PBoolean remoteIsNAT;
00400     PBoolean useRTPAggregation;
00401 
00402 #ifdef OPAL_ZRTP
00403     bool zrtpEnabled;
00404     PMutex zrtpConnInfoMutex;
00405     OpalZRTPConnectionInfo * zrtpConnInfo;
00406 #endif
00407 };
00408 
00409 
00410 class RTP_UDP;
00411 
00412 class OpalSecurityMode : public PObject
00413 {
00414   PCLASSINFO(OpalSecurityMode, PObject);
00415   public:
00416     virtual RTP_UDP * CreateRTPSession(
00417       OpalRTPConnection & connection,     
00418       const RTP_Session::Params & options 
00419     ) = 0;
00420     virtual PBoolean Open() = 0;
00421 };
00422 
00423 #endif // OPAL_OPAL_RTPCONN_H