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: 24365 $
00027  * $Author: rjongbloed $
00028  * $Date: 2010-05-21 01:02:25 -0500 (Fri, 21 May 2010) $
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 
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       RTP_Session * rtpSession
00122     );
00123     OpalRTPMediaSession(const OpalRTPMediaSession & obj);
00124 
00125     PObject * Clone() const { return new OpalRTPMediaSession(*this); }
00126 
00127     virtual void Close();
00128 
00129     virtual bool IsActive() const { return rtpSession != NULL; }
00130 
00131     virtual bool IsRTP() const { return true; }
00132 
00133     virtual bool HasFailed() const { return (rtpSession != NULL) && (rtpSession->HasFailed() || (rtpSession->GetPacketsReceived() == 0)); }
00134 
00135     virtual OpalTransportAddress GetLocalMediaAddress() const;
00136 
00137 #if OPAL_SIP
00138     virtual SDPMediaDescription * CreateSDPMediaDescription(
00139       const OpalTransportAddress & localAddress
00140     );
00141 #endif
00142 
00143     virtual OpalMediaStream * CreateMediaStream(
00144       const OpalMediaFormat & mediaFormat, 
00145       unsigned sessionID, 
00146       PBoolean isSource
00147     );
00148 
00149     RTP_Session * rtpSession;    // RTP session
00150 };
00151 
00154 class OpalRTPSessionManager : public PObject
00155 {
00156     PCLASSINFO(OpalRTPSessionManager , PObject);
00157   public:
00162     OpalRTPSessionManager(
00163       OpalRTPConnection & connection 
00164     );
00165 
00167     ~OpalRTPSessionManager();
00168 
00170     OpalRTPSessionManager(const OpalRTPSessionManager & other);
00171 
00173     void operator=(const OpalRTPSessionManager & other) { sessions = other.sessions; }
00175 
00180     unsigned GetNextSessionID();
00181 
00188     void AddSession(
00189       RTP_Session * session,          
00190       const OpalMediaType & mediaType 
00191     );
00192     void AddMediaSession(
00193       OpalMediaSession * session,          
00194       const OpalMediaType & mediaType 
00195     );
00196 
00199     void ReleaseSession(
00200       unsigned sessionID,    
00201       PBoolean clearAll = PFalse  
00202     );
00203 
00206     RTP_Session * GetSession(
00207       unsigned sessionID    
00208     ) const;
00209     OpalMediaSession * GetMediaSession(
00210       unsigned sessionID
00211     ) const;
00212 
00216     virtual RTP_UDP * FindSessionByLocalPort(
00217       WORD port    
00218     ) const;
00219 
00225     bool ChangeSessionID(
00226       unsigned fromSessionID,   
00227       unsigned toSessionID      
00228     );
00230 
00231     PMutex & GetMutex() { return m_mutex; }
00232 
00233     virtual bool AllSessionsFailing();
00234 
00235   protected:
00236     OpalRTPConnection & m_connection;
00237     PMutex m_mutex;
00238 
00239     PDICTIONARY(SessionDict, POrdinalKey, OpalMediaSession);
00240     SessionDict sessions;
00241 };
00242 
00243 
00244 typedef OpalRTPSessionManager RTP_SessionManager;
00245 
00246 
00250 class OpalRTPConnection : public OpalConnection
00251 {
00252     PCLASSINFO(OpalRTPConnection, OpalConnection);
00253   public:
00258     OpalRTPConnection(
00259       OpalCall & call,                         
00260       OpalRTPEndPoint & endpoint,              
00261       const PString & token,                   
00262       unsigned options = 0,                    
00263       OpalConnection::StringOptions * stringOptions = NULL     
00264     );  
00265 
00268     ~OpalRTPConnection();
00269 
00270 
00275     virtual unsigned GetNextSessionID(
00276       const OpalMediaType & mediaType,   
00277       bool isSource                      
00278     );
00279 
00283     virtual RTP_Session * GetSession(
00284       unsigned sessionID    
00285     ) const;
00286     virtual OpalMediaSession * GetMediaSession(
00287       unsigned sessionID    
00288     ) const;
00289 
00293     virtual RTP_UDP * FindSessionByLocalPort(
00294       WORD port    
00295     ) const;
00296 
00305     virtual RTP_Session * UseSession(
00306       const OpalTransport & transport,  
00307       unsigned sessionID,               
00308       const OpalMediaType & mediatype,  
00309       RTP_QOS * rtpqos = NULL           
00310     );
00311 
00314     virtual void ReleaseSession(
00315       unsigned sessionID,    
00316       PBoolean clearAll = PFalse  
00317     );
00318 
00323     virtual RTP_Session * CreateSession(
00324       const OpalTransport & transport,
00325       unsigned sessionID,
00326       const OpalMediaType & mediaType,
00327       RTP_QOS * rtpqos
00328     );
00329 
00332     virtual RTP_UDP * CreateRTPSession(
00333       unsigned sessionId,
00334       const OpalMediaType & mediaType,
00335       bool remoteIsNat
00336     );
00337 
00343     virtual bool ChangeSessionID(
00344       unsigned fromSessionID,   
00345       unsigned toSessionID      
00346     );
00348 
00353     virtual PBoolean RemoteIsNAT() const
00354     { return remoteIsNAT; }
00355 
00373     virtual PBoolean IsRTPNATEnabled(
00374       const PIPSocket::Address & localAddr,   
00375       const PIPSocket::Address & peerAddr,    
00376       const PIPSocket::Address & signalAddr,  
00377       PBoolean incoming                       
00378     );
00380 
00385     virtual void AttachRFC2833HandlerToPatch(PBoolean isSource, OpalMediaPatch & patch);
00386 
00387     virtual PBoolean SendUserInputTone(
00388       char tone,        
00389       unsigned duration = 0  
00390     );
00391 
00394     struct MediaInformation {
00395       MediaInformation() { 
00396         rfc2833  = RTP_DataFrame::IllegalPayloadType; 
00397         ciscoNSE = RTP_DataFrame::IllegalPayloadType; 
00398       }
00399 
00400       OpalTransportAddress data;           
00401       OpalTransportAddress control;        
00402       RTP_DataFrame::PayloadTypes rfc2833; 
00403       RTP_DataFrame::PayloadTypes ciscoNSE; 
00404     };
00406 
00417     virtual PBoolean GetMediaInformation(
00418       unsigned sessionID,     
00419       MediaInformation & info 
00420     ) const;
00421 
00426     virtual PBoolean IsMediaBypassPossible(
00427       unsigned sessionID                  
00428     ) const;
00429 
00442     virtual OpalMediaStream * CreateMediaStream(
00443       const OpalMediaFormat & mediaFormat, 
00444       unsigned sessionID,                  
00445       PBoolean isSource                        
00446     );
00447 
00460     virtual void AdjustMediaFormats(
00461       bool local,                          
00462       OpalMediaFormatList & mediaFormats,  
00463       OpalConnection * otherConnection     
00464     ) const;
00465 
00474     virtual void OnPatchMediaStream(
00475       PBoolean isSource,        
00476       OpalMediaPatch & patch    
00477     );
00478 
00482     void OnMediaCommand(OpalMediaCommand & command, INT extra);
00484 
00485     virtual void SessionFailing(RTP_Session & session);
00486 
00487   protected:
00488     PDECLARE_NOTIFIER(OpalRFC2833Info, OpalRTPConnection, OnUserInputInlineRFC2833);
00489     PDECLARE_NOTIFIER(OpalRFC2833Info, OpalRTPConnection, OnUserInputInlineCiscoNSE);
00490 
00491     list<OpalRTPSessionManager *> m_allSessions; // Note this must be before m_rtpSessions
00492 
00493     OpalRTPSessionManager m_rtpSessions;
00494     OpalRFC2833Proto * rfc2833Handler;
00495 #if OPAL_T38_CAPABILITY
00496     OpalRFC2833Proto * ciscoNSEHandler;
00497 #endif
00498 
00499     PBoolean remoteIsNAT;
00500     PBoolean useRTPAggregation;
00501 
00502 #ifdef OPAL_ZRTP
00503     bool zrtpEnabled;
00504     PMutex zrtpConnInfoMutex;
00505     OpalZRTPConnectionInfo * zrtpConnInfo;
00506 #endif
00507 
00508   friend class OpalRTPSessionManager;
00509 };
00510 
00511 
00512 class RTP_UDP;
00513 
00514 class OpalSecurityMode : public PObject
00515 {
00516   PCLASSINFO(OpalSecurityMode, PObject);
00517   public:
00518     virtual RTP_UDP * CreateRTPSession(
00519       OpalRTPConnection & connection,     
00520       const RTP_Session::Params & options 
00521     ) = 0;
00522     virtual PBoolean Open() = 0;
00523 };
00524 
00525 #endif // OPAL_OPAL_RTPCONN_H

Generated on Mon Feb 21 20:19:21 2011 for OPAL by  doxygen 1.4.7