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: 21283 $
00027  * $Author: rjongbloed $
00028  * $Date: 2008-10-11 07:10:58 +0000 (Sat, 11 Oct 2008) $
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 
00041 #if OPAL_FAX
00042 
00043 #include <ptlib/pipechan.h>
00044 
00045 #include <opal/mediafmt.h>
00046 #include <opal/mediastrm.h>
00047 #include <opal/endpoint.h>
00048 
00049 
00050 class OpalTransport;
00051 class T38_IFPPacket;
00052 class PASN_OctetString;
00053 
00054 
00055 namespace PWLibStupidLinkerHacks {
00056   extern int t38Loader;
00057 };
00058 
00060 
00066 class OpalFaxAudioFormat : public OpalMediaFormat
00067 {
00068   friend class OpalPluginCodecManager;
00069     PCLASSINFO(OpalFaxAudioFormat, OpalMediaFormat);
00070   public:
00071     OpalFaxAudioFormat(
00072       const char * fullName,    
00073       RTP_DataFrame::PayloadTypes rtpPayloadType, 
00074       const char * encodingName,
00075       PINDEX   frameSize,       
00076       unsigned frameTime,       
00077       unsigned rxFrames,        
00078       unsigned txFrames,        
00079       unsigned maxFrames = 256, 
00080       unsigned clockRate = 8000, 
00081       time_t timeStamp = 0       
00082     );
00083 };
00084 
00085 
00087 
00088 class OpalFaxCallInfo {
00089   public:
00090     OpalFaxCallInfo();
00091     PUDPSocket socket;
00092     PPipeChannel spanDSP;
00093     unsigned refCount;
00094     PIPSocket::Address spanDSPAddr;
00095     WORD spanDSPPort;
00096 };
00097 
00099 
00102 class OpalFaxMediaStream : public OpalMediaStream
00103 {
00104   PCLASSINFO(OpalFaxMediaStream, OpalMediaStream);
00105   public:
00110     OpalFaxMediaStream(
00111       OpalConnection & conn,
00112       const OpalMediaFormat & mediaFormat, 
00113       unsigned sessionID, 
00114       PBoolean isSource ,                      
00115       const PString & token,               
00116       const PString & filename,
00117       PBoolean receive,
00118       const PString & stationId
00119     );
00121 
00128     virtual PBoolean Open();
00129 
00134     virtual PBoolean Close();
00135 
00141     virtual PBoolean Start();
00142 
00146     virtual PBoolean ReadPacket(
00147       RTP_DataFrame & packet
00148     );
00149 
00153     virtual PBoolean WritePacket(
00154       RTP_DataFrame & packet
00155     );
00156 
00160     virtual PBoolean IsSynchronous() const;
00161 
00162     virtual PString GetSpanDSPCommandLine(OpalFaxCallInfo &);
00163 
00165 
00166   protected:
00167     PMutex infoMutex;
00168     PString sessionToken;
00169     OpalFaxCallInfo * faxCallInfo;
00170     PFilePath filename;
00171     PBoolean receive;
00172     BYTE writeBuffer[320];
00173     PINDEX writeBufferLen;
00174     PString stationId;
00175 };
00176 
00178 
00181 class OpalT38MediaStream : public OpalFaxMediaStream
00182 {
00183   PCLASSINFO(OpalT38MediaStream, OpalFaxMediaStream);
00184   public:
00185     OpalT38MediaStream(
00186       OpalConnection & conn,
00187       const OpalMediaFormat & mediaFormat, 
00188       unsigned sessionID, 
00189       PBoolean isSource ,                      
00190       const PString & token,               
00191       const PString & filename,            
00192       PBoolean receive,
00193       const PString & stationId
00194     );
00195 
00196     PString GetSpanDSPCommandLine(OpalFaxCallInfo &);
00197 
00198     PBoolean ReadPacket(RTP_DataFrame & packet);
00199     PBoolean WritePacket(RTP_DataFrame & packet);
00200 
00201     RTP_DataFrameList queuedFrames;
00202 };
00203 
00205 
00206 class OpalFaxConnection;
00207 
00216 class OpalFaxEndPoint : public OpalEndPoint
00217 {
00218   PCLASSINFO(OpalFaxEndPoint, OpalEndPoint);
00219   public:
00224     OpalFaxEndPoint(
00225       OpalManager & manager,      
00226       const char * prefix = "fax" 
00227     );
00228 
00231     ~OpalFaxEndPoint();
00233 
00234     virtual PBoolean MakeConnection(
00235       OpalCall & call,          
00236       const PString & party,    
00237       void * userData = NULL,          
00238       unsigned int options = 0,     
00239       OpalConnection::StringOptions * stringOptions = NULL
00240     );
00241 
00244     virtual OpalFaxConnection * CreateConnection(
00245       OpalCall & call,          
00246       const PString & filename, 
00247       PBoolean receive,
00248       void * userData = NULL,   
00249       OpalConnection::StringOptions * stringOptions = NULL
00250     );
00251 
00261     virtual OpalMediaFormatList GetMediaFormats() const;
00262 
00263     virtual PString MakeToken();
00264 
00268     virtual void AcceptIncomingConnection(
00269       const PString & connectionToken 
00270     );
00271 
00276     virtual void OnPatchMediaStream(
00277       const OpalFaxConnection & connection, 
00278       PBoolean isSource,                         
00279       OpalMediaPatch & patch                 
00280     );
00282 
00286     const PFilePath & GetSpanDSP() const { return m_spanDSP; }
00287 
00290     void SetSpanDSP(
00291       const PString & path    
00292     ) { m_spanDSP = path; }
00293 
00296     const PString & GetDefaultDirectory() const { return m_defaultDirectory; }
00297 
00300     void SetDefaultDirectory(
00301       const PString & dir    
00302     ) { m_defaultDirectory = dir; }
00304 
00305   protected:
00306     PFilePath  m_spanDSP;
00307     PDirectory m_defaultDirectory;
00308 };
00309 
00311 
00314 class OpalFaxConnection : public OpalConnection
00315 {
00316   PCLASSINFO(OpalFaxConnection, OpalConnection);
00317   public:
00322     OpalFaxConnection(
00323       OpalCall & call,                 
00324       OpalFaxEndPoint & endpoint,      
00325       const PString & filename,        
00326       PBoolean receive,                    
00327       const PString & _token,           
00328       OpalConnection::StringOptions * stringOptions = NULL
00329     );
00330 
00333     ~OpalFaxConnection();
00335 
00346     virtual bool IsNetworkConnection() const { return false; }
00347 
00354     virtual PBoolean SetUpConnection();
00355 
00366     virtual PBoolean SetAlerting(
00367       const PString & calleeName,   
00368       PBoolean withMedia                
00369     );
00370 
00378     virtual OpalMediaFormatList GetMediaFormats() const;
00379 
00380     OpalMediaStream * CreateMediaStream(const OpalMediaFormat & mediaFormat, unsigned sessionID, PBoolean isSource);
00381 
00389     virtual void OnPatchMediaStream(
00390       PBoolean isSource,
00391       OpalMediaPatch & patch    
00392     );
00393 
00398     virtual void AcceptIncoming();
00399 
00401 
00402     void AdjustMediaFormats(OpalMediaFormatList & mediaFormats) const;
00403 
00404   protected:
00405     OpalFaxEndPoint & endpoint;
00406     PString filename;
00407     PBoolean receive;
00408     PBoolean forceFaxAudio;
00409     PString stationId;
00410 };
00411 
00413 
00414 class OpalT38Connection;
00415 
00424 class OpalT38EndPoint : public OpalFaxEndPoint
00425 {
00426   PCLASSINFO(OpalT38EndPoint, OpalFaxEndPoint);
00427   public:
00432     OpalT38EndPoint(
00433       OpalManager & manager,      
00434       const char * prefix = "t38" 
00435     );
00436     OpalMediaFormatList GetMediaFormats() const;
00437     PString MakeToken();
00438     virtual OpalFaxConnection * CreateConnection(OpalCall & call, const PString & filename, PBoolean receive, void * /*userData*/, OpalConnection::StringOptions * stringOptions);
00439 };
00440 
00442 
00445 class OpalT38Connection : public OpalFaxConnection
00446 {
00447   PCLASSINFO(OpalT38Connection, OpalFaxConnection);
00448   public:
00453     OpalT38Connection(
00454       OpalCall & call,                 
00455       OpalT38EndPoint & endpoint,      
00456       const PString & filename,        
00457       PBoolean receive,                
00458       const PString & _token,          
00459       OpalConnection::StringOptions * stringOptions = NULL
00460     );
00461 
00462     ~OpalT38Connection();
00463 
00464     void OnPatchMediaStream(PBoolean isSource, OpalMediaPatch & patch);
00465     OpalMediaStream * CreateMediaStream(const OpalMediaFormat & mediaFormat, unsigned sessionID, PBoolean isSource);
00466     OpalMediaFormatList GetMediaFormats() const;
00467 
00468     // triggers into fax mode
00469     enum {
00470       T38Mode_Wait         = 0,   // Do nothing and wait for the other end to send a reinvite
00471       T38Mode_InBandCED    = 1,   // If receiving, send CED tone in-band. If sending, trigger mode change if CED detected in-band
00472       T38Mode_NSECED       = 2,   // If receiving, send CED as RFC2833. If sending, trigger mode change if RFC2833 CED received
00473       T38Mode_Timeout      = 4,   // Trigger mode change if has not occurred after 5 seconds
00474       T38Mode_Auto         = 7    // All of the above :)
00475     };
00476 
00477     virtual PBoolean SendUserInputTone(
00478       char tone,
00479       unsigned duration
00480     );
00481 
00482     PDECLARE_NOTIFIER(PTimer, OpalT38Connection, OnFaxChangeTimeout);
00483 
00484   protected:
00485     void RequestFaxMode(bool fax);
00486     void InFaxMode(bool fax);
00487 
00488     unsigned t38WaitMode;
00489 
00490     PMutex modeMutex;
00491     bool currentMode, newMode;  // false if audio, true if fax
00492     bool modeChangeTriggered;
00493     PTimer faxTimer;
00494     bool faxStartup;
00495 };
00496 
00497 
00498 #endif // OPAL_FAX
00499 
00500 #endif // OPAL_T38_T38PROTO_H

Generated on Mon Feb 23 02:01:39 2009 for OPAL by  doxygen 1.5.1