rtpconn.h

Go to the documentation of this file.
00001 /*
00002  * rtpconn.h
00003  *
00004  * Connection abstraction
00005  *
00006  * Open Phone Abstraction Library (OPAL)
00007  *
00008  * Copyright (C) 2007 Post Increment
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Open Phone Abstraction Library.
00021  *
00022  * The Initial Developer of the Original Code is Post Increment
00023  *
00024  * Contributor(s): ______________________________________.
00025  *
00026  * $Revision: 22533 $
00027  * $Author: csoutheren $
00028  * $Date: 2009-05-06 13:15:17 +0000 (Wed, 06 May 2009) $
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 //#ifdef HAS_LIBZRTP
00065 //#ifndef __ZRTP_TYPES_H__
00066 //struct zrtp_conn_ctx_t;
00067 //#endif
00068 //#endif
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;     // media type for session
00107     unsigned sessionId;          // unique session ID
00108 };
00109 
00112 class OpalRTPMediaSession : public OpalMediaSession
00113 {
00114   PCLASSINFO(OpalRTPMediaSession, OpalMediaSession);
00115   public:
00116     OpalRTPMediaSession(
00117       OpalConnection & conn,
00118       const OpalMediaType & mediaType,
00119       unsigned sessionId,
00120       RTP_Session * rtpSession
00121     );
00122     OpalRTPMediaSession(const OpalRTPMediaSession & obj);
00123 
00124     PObject * Clone() const { return new OpalRTPMediaSession(*this); }
00125 
00126     virtual void Close();
00127 
00128     virtual bool IsActive() const { return rtpSession != NULL; }
00129 
00130     virtual bool IsRTP() const { return true; }
00131 
00132     virtual bool HasFailed() const { return (rtpSession != NULL) && (rtpSession->HasFailed() || (rtpSession->GetPacketsReceived() == 0)); }
00133 
00134     virtual OpalTransportAddress GetLocalMediaAddress() const;
00135 
00136 #if OPAL_SIP
00137     virtual SDPMediaDescription * CreateSDPMediaDescription(
00138       const OpalTransportAddress & localAddress
00139     );
00140 #endif
00141 
00142     virtual OpalMediaStream * CreateMediaStream(
00143       const OpalMediaFormat & mediaFormat, 
00144       unsigned sessionID, 
00145       PBoolean isSource
00146     );
00147 
00148     RTP_Session * rtpSession;    // RTP session
00149 };
00150 
00153 class OpalRTPSessionManager : public PObject
00154 {
00155   PCLASSINFO(OpalRTPSessionManager , PObject);
00156 
00157   public:
00162     OpalRTPSessionManager(OpalConnection & conn);
00163     ~OpalRTPSessionManager();
00164     void operator=(const OpalRTPSessionManager & other) { sessions = other.sessions; }
00166 
00171     unsigned GetNextSessionID();
00172 
00179     void AddSession(
00180       RTP_Session * session,          
00181       const OpalMediaType & mediaType 
00182     );
00183     void AddMediaSession(
00184       OpalMediaSession * session,          
00185       const OpalMediaType & mediaType 
00186     );
00187 
00190     void ReleaseSession(
00191       unsigned sessionID,    
00192       PBoolean clearAll = PFalse  
00193     );
00194 
00197     RTP_Session * GetSession(
00198       unsigned sessionID    
00199     ) const;
00200     OpalMediaSession * GetMediaSession(
00201       unsigned sessionID
00202     ) const;
00203 
00209     bool ChangeSessionID(
00210       unsigned fromSessionID,   
00211       unsigned toSessionID      
00212     );
00214 
00215     PMutex & GetMutex() { return m_mutex; }
00216 
00217     virtual bool AllSessionsFailing();
00218 
00219   protected:
00220     OpalConnection & connection;
00221     PMutex m_mutex;
00222 
00223     PDICTIONARY(SessionDict, POrdinalKey, OpalMediaSession);
00224     SessionDict sessions;
00225 };
00226 
00227 typedef OpalRTPSessionManager RTP_SessionManager;
00228 
00232 class OpalRTPConnection : public OpalConnection
00233 {
00234   PCLASSINFO(OpalRTPConnection, OpalConnection);
00235   public:
00240     OpalRTPConnection(
00241       OpalCall & call,                         
00242       OpalRTPEndPoint & endpoint,              
00243       const PString & token,                   
00244       unsigned options = 0,                    
00245       OpalConnection::StringOptions * stringOptions = NULL     
00246     );  
00247 
00250     ~OpalRTPConnection();
00251 
00252 
00257     virtual unsigned GetNextSessionID(
00258       const OpalMediaType & mediaType,   
00259       bool isSource                      
00260     );
00261 
00265     virtual RTP_Session * GetSession(
00266       unsigned sessionID    
00267     ) const;
00268     virtual OpalMediaSession * GetMediaSession(
00269       unsigned sessionID    
00270     ) const;
00271 
00280     virtual RTP_Session * UseSession(
00281       const OpalTransport & transport,  
00282       unsigned sessionID,               
00283       const OpalMediaType & mediatype,  
00284       RTP_QOS * rtpqos = NULL           
00285     );
00286 
00289     virtual void ReleaseSession(
00290       unsigned sessionID,    
00291       PBoolean clearAll = PFalse  
00292     );
00293 
00298     virtual RTP_Session * CreateSession(
00299       const OpalTransport & transport,
00300       unsigned sessionID,
00301       const OpalMediaType & mediaType,
00302       RTP_QOS * rtpqos
00303     );
00304 
00307     virtual RTP_UDP * CreateRTPSession(
00308       unsigned sessionId,
00309       const OpalMediaType & mediaType,
00310       bool remoteIsNat
00311     );
00312 
00318     virtual bool ChangeSessionID(
00319       unsigned fromSessionID,   
00320       unsigned toSessionID      
00321     );
00323 
00325 
00327     virtual PBoolean RemoteIsNAT() const
00328     { return remoteIsNAT; }
00329 
00347     virtual PBoolean IsRTPNATEnabled(
00348       const PIPSocket::Address & localAddr,   
00349       const PIPSocket::Address & peerAddr,    
00350       const PIPSocket::Address & signalAddr,  
00351       PBoolean incoming                       
00352     );
00354 
00359     virtual void AttachRFC2833HandlerToPatch(PBoolean isSource, OpalMediaPatch & patch);
00360 
00361     virtual PBoolean SendUserInputTone(
00362       char tone,        
00363       unsigned duration = 0  
00364     );
00365 
00368     struct MediaInformation {
00369       MediaInformation() { 
00370         rfc2833  = RTP_DataFrame::IllegalPayloadType; 
00371         ciscoNSE = RTP_DataFrame::IllegalPayloadType; 
00372       }
00373 
00374       OpalTransportAddress data;           
00375       OpalTransportAddress control;        
00376       RTP_DataFrame::PayloadTypes rfc2833; 
00377       RTP_DataFrame::PayloadTypes ciscoNSE; 
00378     };
00379 
00388     virtual PBoolean GetMediaInformation(
00389       unsigned sessionID,     
00390       MediaInformation & info 
00391     ) const;
00392 
00397     virtual PBoolean IsMediaBypassPossible(
00398       unsigned sessionID                  
00399     ) const;
00400 
00413     virtual OpalMediaStream * CreateMediaStream(
00414       const OpalMediaFormat & mediaFormat, 
00415       unsigned sessionID,                  
00416       PBoolean isSource                        
00417     );
00418 
00421     virtual void OnPatchMediaStream(PBoolean isSource, OpalMediaPatch & patch);
00422 
00423     void OnMediaCommand(OpalMediaCommand & command, INT extra);
00424 
00425     PDECLARE_NOTIFIER(OpalRFC2833Info, OpalRTPConnection, OnUserInputInlineRFC2833);
00426     PDECLARE_NOTIFIER(OpalRFC2833Info, OpalRTPConnection, OnUserInputInlineCiscoNSE);
00427 
00428     virtual void SessionFailing(RTP_Session & session);
00429 
00430   protected:
00431     OpalRTPSessionManager m_rtpSessions;
00432     OpalRFC2833Proto * rfc2833Handler;
00433 #if OPAL_T38_CAPABILITY
00434     OpalRFC2833Proto * ciscoNSEHandler;
00435 #endif
00436 
00437     PBoolean remoteIsNAT;
00438     PBoolean useRTPAggregation;
00439 
00440 #ifdef OPAL_ZRTP
00441     bool zrtpEnabled;
00442     PMutex zrtpConnInfoMutex;
00443     OpalZRTPConnectionInfo * zrtpConnInfo;
00444 #endif
00445 };
00446 
00447 
00448 class RTP_UDP;
00449 
00450 class OpalSecurityMode : public PObject
00451 {
00452   PCLASSINFO(OpalSecurityMode, PObject);
00453   public:
00454     virtual RTP_UDP * CreateRTPSession(
00455       OpalRTPConnection & connection,     
00456       const RTP_Session::Params & options 
00457     ) = 0;
00458     virtual PBoolean Open() = 0;
00459 };
00460 
00461 #endif // OPAL_OPAL_RTPCONN_H

Generated on Mon Aug 3 20:50:25 2009 for OPAL by  doxygen 1.5.1