t38proto.h

Go to the documentation of this file.
00001 /*
00002  * t38proto.h
00003  *
00004  * T.38 protocol handler
00005  *
00006  * Open Phone Abstraction Library
00007  *
00008  * Copyright (c) 2001 Equivalence Pty. Ltd.
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 H323 Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Contributor(s): ______________________________________.
00025  *
00026  * $Revision: 29550 $
00027  * $Author: rjongbloed $
00028  * $Date: 2013-04-22 22:08:10 -0500 (Mon, 22 Apr 2013) $
00029  */
00030 
00031 #ifndef OPAL_T38_T38PROTO_H
00032 #define OPAL_T38_T38PROTO_H
00033 
00034 #ifdef P_USE_PRAGMA
00035 #pragma interface
00036 #endif
00037 
00038 #include <opal/buildopts.h>
00039 
00040 #if OPAL_FAX
00041 
00042 #include <opal/mediafmt.h>
00043 #include <opal/mediastrm.h>
00044 #include <opal/mediasession.h>
00045 #include <ep/localep.h>
00046 
00047 
00048 class OpalTransport;
00049 class OpalFaxConnection;
00050 
00051 #if OPAL_PTLIB_ASN
00052 class T38_IFPPacket;
00053 class PASN_OctetString;
00054 #endif
00055 
00056 #define OPAL_OPT_STATION_ID  "Station-Id"      
00057 #define OPAL_OPT_HEADER_INFO "Header-Info"     
00058 #define OPAL_NO_G111_FAX     "No-G711-Fax"     
00059 #define OPAL_SWITCH_ON_CED   "Switch-On-CED"   
00060 #define OPAL_T38_SWITCH_TIME "T38-Switch-Time" 
00061 
00062 #define OPAL_FAX_TIFF_FILE "TIFF-File"
00063 
00064 
00066 
00067 class OpalFaxConnection;
00068 
00080 class OpalFaxEndPoint : public OpalLocalEndPoint
00081 {
00082   PCLASSINFO(OpalFaxEndPoint, OpalLocalEndPoint);
00083   public:
00088     OpalFaxEndPoint(
00089       OpalManager & manager,        
00090       const char * g711Prefix = "fax", 
00091       const char * t38Prefix = "t38"  
00092     );
00093 
00096     ~OpalFaxEndPoint();
00098 
00101     virtual PSafePtr<OpalConnection> MakeConnection(
00102       OpalCall & call,          
00103       const PString & party,    
00104       void * userData = NULL,          
00105       unsigned int options = 0,     
00106       OpalConnection::StringOptions * stringOptions = NULL  
00107     );
00108 
00116     virtual OpalMediaFormatList GetMediaFormats() const;
00118 
00123     virtual bool IsAvailable() const;
00124 
00127     virtual OpalFaxConnection * CreateConnection(
00128       OpalCall & call,          
00129       void * userData,          
00130       OpalConnection::StringOptions * stringOptions, 
00131       const PString & filename, 
00132       bool receiving,           
00133       bool disableT38           
00134     );
00135 
00139     virtual void OnFaxCompleted(
00140       OpalFaxConnection & connection, 
00141       bool failed   
00142     );
00144 
00148     const PString & GetDefaultDirectory() const { return m_defaultDirectory; }
00149 
00152     void SetDefaultDirectory(
00153       const PString & dir    
00154     ) { m_defaultDirectory = dir; }
00155 
00156     const PString & GetT38Prefix() const { return m_t38Prefix; }
00158 
00159   protected:
00160     PString    m_t38Prefix;
00161     PDirectory m_defaultDirectory;
00162 };
00163 
00164 
00166 
00183 class OpalFaxConnection : public OpalLocalConnection
00184 {
00185   PCLASSINFO(OpalFaxConnection, OpalLocalConnection);
00186   public:
00191     OpalFaxConnection(
00192       OpalCall & call,                 
00193       OpalFaxEndPoint & endpoint,      
00194       const PString & filename,        
00195       bool receiving,                  
00196       bool disableT38,                 
00197       OpalConnection::StringOptions * stringOptions = NULL  
00198     );
00199 
00202     ~OpalFaxConnection();
00204 
00207     virtual PString GetPrefixName() const;
00208 
00209     virtual OpalMediaFormatList GetMediaFormats() const;
00210     virtual void AdjustMediaFormats(bool local, const OpalConnection * otherConnection, OpalMediaFormatList & mediaFormats) const;
00211     virtual void OnEstablished();
00212     virtual void OnReleased();
00213     virtual OpalMediaStream * CreateMediaStream(const OpalMediaFormat & mediaFormat, unsigned sessionID, PBoolean isSource);
00214     virtual void OnStartMediaPatch(OpalMediaPatch & patch);
00215     virtual void OnClosedMediaStream(const OpalMediaStream & stream);
00216     virtual PBoolean SendUserInputTone(char tone, unsigned duration);
00217     virtual void OnUserInputTone(char tone, unsigned duration);
00218     virtual bool SwitchFaxMediaStreams(bool toT38);
00219     virtual void OnSwitchedFaxMediaStreams(bool toT38, bool success);
00220     virtual bool OnSwitchingFaxMediaStreams(bool toT38);
00221     virtual void OnApplyStringOptions();
00223 
00229     virtual void OnFaxCompleted(
00230       bool failed   
00231     );
00232 
00235     virtual void GetStatistics(
00236       OpalMediaStatistics & statistics  
00237     ) const;
00238 
00241     const PString & GetFileName() const { return m_filename; }
00242 
00245     bool IsReceive() const { return m_receiving; }
00247 
00248   protected:
00249     PDECLARE_NOTIFIER(PTimer,  OpalFaxConnection, OnSwitchTimeout);
00250     void InternalOpenFaxStreams();
00251     void InternalOnFaxCompleted();
00252 
00253     void SetFaxMediaFormatOptions(OpalMediaFormat & mediaFormat) const;
00254 
00255     OpalFaxEndPoint & m_endpoint;
00256     PString           m_filename;
00257     bool              m_receiving;
00258     bool              m_disableT38;
00259     unsigned          m_switchTime;
00260     OpalMediaFormat   m_tiffFileFormat;
00261 
00262     PTimer m_switchTimer;
00263 
00264     OpalMediaStatistics m_finalStatistics;
00265     PAtomicBoolean      m_completed;
00266 };
00267 
00268 
00269 typedef OpalFaxConnection OpalT38Connection; // For backward compatibility
00270 
00271 class T38_UDPTLPacket;
00272 
00273 class OpalFaxSession : public OpalMediaSession
00274 {
00275   public:
00276     static const PCaselessString & UDPTL();
00277 
00278     OpalFaxSession(const Init & init);
00279     ~OpalFaxSession();
00280 
00281     virtual const PCaselessString & GetSessionType() const { return UDPTL(); }
00282     virtual bool Open(const PString & localInterface, const OpalTransportAddress & remoteAddress, bool isMediaAddress);
00283     virtual bool IsOpen() const;
00284     virtual bool Close();
00285     virtual OpalTransportAddress GetLocalAddress(bool isMediaAddress = true) const;
00286     virtual OpalTransportAddress GetRemoteAddress(bool isMediaAddress = true) const;
00287     virtual bool SetRemoteAddress(const OpalTransportAddress & remoteAddress, bool isMediaAddress = true);
00288 
00289     virtual void AttachTransport(Transport & transport);
00290     virtual Transport DetachTransport();
00291 
00292     virtual OpalMediaStream * CreateMediaStream(
00293       const OpalMediaFormat & mediaFormat, 
00294       unsigned sessionID, 
00295       bool isSource
00296     );
00297 
00298     bool WriteData(RTP_DataFrame & frame);
00299     bool ReadData(RTP_DataFrame & frame);
00300 
00301     void ApplyMediaOptions(const OpalMediaFormat & mediaFormat);
00302 
00303   protected:
00304     void SetFrameFromIFP(RTP_DataFrame & frame, const PASN_OctetString & ifp, unsigned sequenceNumber);
00305     void DecrementSentPacketRedundancy(bool stripRedundancy);
00306     bool WriteUDPTL();
00307 
00308     Transport          m_savedTransport;
00309     PIPSocket        * m_dataSocket;
00310     bool               m_shuttingDown;
00311 
00312     bool               m_rawUDPTL; // Put UDPTL directly in RTP payload
00313     PINDEX             m_datagramSize;
00314 
00315     int                m_consecutiveBadPackets;
00316     bool               m_awaitingGoodPacket;
00317     T38_UDPTLPacket  * m_receivedPacket;
00318     unsigned           m_expectedSequenceNumber;
00319     int                m_secondaryPacket;
00320 
00321     std::map<int, int> m_redundancy;
00322     PTimeInterval      m_redundancyInterval;
00323     PTimeInterval      m_keepAliveInterval;
00324     bool               m_optimiseOnRetransmit;
00325     std::vector<int>   m_sentPacketRedundancy;
00326     T38_UDPTLPacket  * m_sentPacket;
00327     PMutex             m_writeMutex;
00328     PTimer             m_timerWriteDataIdle;
00329     PDECLARE_NOTIFIER(PTimer,  OpalFaxSession, OnWriteDataIdle);
00330 };
00331 
00332 class OpalFaxMediaStream : public OpalMediaStream
00333 {
00334     PCLASSINFO(OpalFaxMediaStream, OpalMediaStream);
00335 
00336   public:
00337     OpalFaxMediaStream(OpalConnection & conn,
00338                        const OpalMediaFormat & mediaFormat,
00339                        unsigned sessionID,
00340                        bool isSource,
00341                        OpalFaxSession & session);
00342 
00343     virtual PBoolean Open();
00344     virtual PBoolean ReadPacket(RTP_DataFrame & packet);
00345     virtual PBoolean WritePacket(RTP_DataFrame & packet);
00346     virtual PBoolean IsSynchronous() const;
00347     virtual bool InternalUpdateMediaFormat(const OpalMediaFormat & mediaFormat);
00348 
00349   protected:
00350     virtual void InternalClose();
00351 
00352     OpalFaxSession & m_session;
00353 };
00354 
00355 #endif // OPAL_FAX
00356 
00357 #endif // OPAL_T38_T38PROTO_H

Generated on 21 Jun 2013 for OPAL by  doxygen 1.4.7