# 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: 21035 $
    00027  * $Author: rjongbloed $
    00028  * $Date: 2008-09-17 07:57:58 +0000 (Wed, 17 Sep 2008) $
    00029  */
    00030
    00031 #ifndef __OPAL_RTPCONN_H
    00032 #define __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
    00044 class OpalRTPEndPoint;
    00045
    00046 //#ifdef HAS_LIBZRTP
    00047 //#ifndef __ZRTP_TYPES_H__
    00048 //struct zrtp_conn_ctx_t;
    00049 //#endif
    00050 //#endif
    00051
    00054 class OpalMediaSession : public PObject
    00055 {
    00056   PCLASSINFO(OpalMediaSession, PObject);
    00057   public:
    00058     OpalMediaSession(const OpalMediaType & _mediaType);
    00059     OpalMediaSession(const OpalMediaSession & _obj);
    00060
    00061     PObject * Clone() const { return new OpalMediaSession(*this); }
    00062
    00063     OpalMediaType mediaType;     // media type for session
    00064     bool autoStartReceive;       // if true, this session should receive data when the call is started
    00065     bool autoStartTransmit;      // if true, this session  should transmit data when the call is started
    00066     unsigned sessionId;          // unique session ID
    00067
    00068     RTP_Session * rtpSession;    // RTP session
    00069 };
    00070
    00073 class OpalRTPSessionManager : public PObject
    00074 {
    00075   PCLASSINFO(OpalRTPSessionManager , PObject);
    00076
    00077   public:
    00082     OpalRTPSessionManager();
    00083     ~OpalRTPSessionManager();
    00085
    00086     void CopyFromMaster(const OpalRTPSessionManager & sm);
    00087     void CopyToMaster(OpalRTPSessionManager & sm);
    00088
    00092     void Initialise(
    00093       OpalRTPConnection & conn,
    00094       OpalConnection::StringOptions * stringOptions
    00095     );
    00096
    00100     unsigned AutoStartSession(
    00101       unsigned sessionID,
    00102       const OpalMediaType & mediaType,
    00103       bool autoStartReceive,
    00104       bool autoStartTransmit
    00105     );
    00106
    00115     void AddSession(
    00116       RTP_Session * session,
    00117       const OpalMediaType & mediaType
    00118     );
    00119
    00122     void ReleaseSession(
    00123       unsigned sessionID,
    00124       PBoolean clearAll = PFalse
    00125     );
    00126
    00129     RTP_Session * GetSession(
    00130       unsigned sessionID
    00131     ) const;
    00132
    00133     void SetCleanup(bool v) { m_cleanupOnDelete = v; }
    00134
    00136     PMutex & GetMutex() { return m_mutex; }
    00137
    00138   protected:
    00139     void SetOldOptions(unsigned channelId, const OpalMediaType & mediaType, bool rx, bool tx);
    00140
    00141     PMutex m_mutex;
    00142     bool m_initialised;
    00143     bool m_cleanupOnDelete;
    00144     PDICTIONARY(SessionDict, POrdinalKey, OpalMediaSession);
    00145     SessionDict sessions;
    00146
    00147   private:
    00148     OpalRTPSessionManager (const OpalRTPSessionManager & other): PObject (other) { }
    00149     OpalRTPSessionManager & operator=(const OpalRTPSessionManager &) { return *this; }
    00150
    00151 };
    00152
    00153 typedef OpalRTPSessionManager RTP_SessionManager;
    00154
    00158 class OpalRTPConnection : public OpalConnection
    00159 {
    00160   PCLASSINFO(OpalRTPConnection, OpalConnection);
    00161   public:
    00166     OpalRTPConnection(
    00167       OpalCall & call,
    00168       OpalRTPEndPoint & endpoint,
    00169       const PString & token,
    00170       unsigned options = 0,
    00171       OpalConnection::StringOptions * stringOptions = NULL
    00172     );
    00173
    00176     ~OpalRTPConnection();
    00177
    00178
    00184     virtual RTP_Session * GetSession(
    00185       unsigned sessionID
    00186     ) const;
    00187
    00196     virtual RTP_Session * UseSession(
    00197       const OpalTransport & transport,
    00198       unsigned sessionID,
    00199       const OpalMediaType & mediatype,
    00200       RTP_QOS * rtpqos = NULL
    00201     );
    00202
    00205     virtual void ReleaseSession(
    00206       unsigned sessionID,
    00207       PBoolean clearAll = PFalse
    00208     );
    00209
    00214     virtual RTP_Session * CreateSession(
    00215       const OpalTransport & transport,
    00216       unsigned sessionID,
    00217       RTP_QOS * rtpqos
    00218     );
    00219
    00221
    00223
    00225     virtual PBoolean RemoteIsNAT() const
    00226     { return remoteIsNAT; }
    00227
    00245     virtual PBoolean IsRTPNATEnabled(
    00246       const PIPSocket::Address & localAddr,
    00247       const PIPSocket::Address & peerAddr,
    00248       const PIPSocket::Address & signalAddr,
    00249       PBoolean incoming
    00250     );
    00252
    00257     virtual void AttachRFC2833HandlerToPatch(PBoolean isSource, OpalMediaPatch & patch);
    00258
    00259     virtual PBoolean SendUserInputTone(
    00260       char tone,
    00261       unsigned duration = 0
    00262     );
    00263
    00266     struct MediaInformation {
    00267       MediaInformation() {
    00268         rfc2833  = RTP_DataFrame::IllegalPayloadType;
    00269         ciscoNSE = RTP_DataFrame::IllegalPayloadType;
    00270       }
    00271
    00272       OpalTransportAddress data;
    00273       OpalTransportAddress control;
    00274       RTP_DataFrame::PayloadTypes rfc2833;
    00275       RTP_DataFrame::PayloadTypes ciscoNSE;
    00276     };
    00277
    00286     virtual PBoolean GetMediaInformation(
    00287       unsigned sessionID,
    00288       MediaInformation & info
    00289     ) const;
    00290
    00295     virtual PBoolean IsMediaBypassPossible(
    00296       unsigned sessionID
    00297     ) const;
    00298
    00311     virtual OpalMediaStream * CreateMediaStream(
    00312       const OpalMediaFormat & mediaFormat,
    00313       unsigned sessionID,
    00314       PBoolean isSource
    00315     );
    00316
    00319     virtual void OnPatchMediaStream(PBoolean isSource, OpalMediaPatch & patch);
    00320
    00321     virtual void SetSecurityMode(const PString & v)
    00322     { securityMode = v; }
    00323
    00324     virtual PString GetSecurityMode() const
    00325     { return securityMode; }
    00326
    00327     virtual void * GetSecurityData();
    00328     virtual void SetSecurityData(void *data);
    00329
    00330     void OnMediaCommand(OpalMediaCommand & command, INT extra);
    00331
    00332     PDECLARE_NOTIFIER(OpalRFC2833Info, OpalRTPConnection, OnUserInputInlineRFC2833);
    00333     PDECLARE_NOTIFIER(OpalRFC2833Info, OpalRTPConnection, OnUserInputInlineCiscoNSE);
    00334
    00335   protected:
    00336     PString securityMode;
    00337     void * securityData;
    00338     OpalRTPSessionManager m_rtpSessions;
    00339     OpalRFC2833Proto * rfc2833Handler;
    00340     OpalRFC2833Proto * ciscoNSEHandler;
    00341
    00342     PBoolean remoteIsNAT;
    00343     PBoolean useRTPAggregation;
    00344 };
    00345
    00346
    00347 class RTP_UDP;
    00348
    00349 class OpalSecurityMode : public PObject
    00350 {
    00351   PCLASSINFO(OpalSecurityMode, PObject);
    00352   public:
    00353     virtual RTP_UDP * CreateRTPSession(
    00354       OpalRTPConnection & connection,
    00355       const RTP_Session::Params & options
    00356     ) = 0;
    00357     virtual PBoolean Open() = 0;
    00358 };
    00359
    00360 #endif
    00361