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  * $Log: t38proto.h,v $
00027  * Revision 2.13  2007/09/25 19:35:30  csoutheren
00028  * Fix compilation when using --disable-audio
00029  *
00030  * Revision 2.12  2007/07/25 01:14:52  csoutheren
00031  * Add support for receiving faxes into a TIFF file
00032  *
00033  * Revision 2.11  2007/05/10 05:34:01  csoutheren
00034  * Ensure fax transmission works with reasonable size audio blocks
00035  *
00036  * Revision 2.10  2007/03/29 08:31:25  csoutheren
00037  * Fix media formats for T.38 endpoint
00038  *
00039  * Revision 2.9  2007/03/29 05:19:54  csoutheren
00040  * Implement T.38 and fax
00041  *
00042  * Revision 2.8  2005/02/21 12:19:48  rjongbloed
00043  * Added new "options list" to the OpalMediaFormat class.
00044  *
00045  * Revision 2.7  2003/01/07 04:39:53  robertj
00046  * Updated to OpenH323 v1.11.2
00047  *
00048  * Revision 2.6  2002/11/10 11:33:17  robertj
00049  * Updated to OpenH323 v1.10.3
00050  *
00051  * Revision 2.5  2002/09/16 02:52:36  robertj
00052  * Added #define so can select if #pragma interface/implementation is used on
00053  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00054  *
00055  * Revision 2.4  2002/09/04 06:01:47  robertj
00056  * Updated to OpenH323 v1.9.6
00057  *
00058  * Revision 2.3  2002/02/11 09:32:12  robertj
00059  * Updated to openH323 v1.8.0
00060  *
00061  * Revision 2.2  2002/01/14 06:35:57  robertj
00062  * Updated to OpenH323 v1.7.9
00063  *
00064  * Revision 2.1  2001/08/01 05:06:00  robertj
00065  * Major changes to H.323 capabilities, uses OpalMediaFormat for base name.
00066  *
00067  * Revision 2.0  2001/07/27 15:48:24  robertj
00068  * Conversion of OpenH323 to Open Phone Abstraction Library (OPAL)
00069  *
00070  * Revision 1.9  2002/12/02 04:07:58  robertj
00071  * Turned T.38 Originate inside out, so now has WriteXXX() functions that can
00072  *   be call ed in different thread contexts.
00073  *
00074  * Revision 1.8  2002/12/02 00:37:15  robertj
00075  * More implementation of T38 base library code, some taken from the t38modem
00076  *   application by Vyacheslav Frolov, eg redundent frames.
00077  *
00078  * Revision 1.7  2002/09/16 01:14:15  robertj
00079  * Added #define so can select if #pragma interface/implementation is used on
00080  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00081  *
00082  * Revision 1.6  2002/09/03 06:19:37  robertj
00083  * Normalised the multi-include header prevention ifdef/define symbol.
00084  *
00085  * Revision 1.5  2002/02/09 04:39:01  robertj
00086  * Changes to allow T.38 logical channels to use single transport which is
00087  *   now owned by the OpalT38Protocol object instead of H323Channel.
00088  *
00089  * Revision 1.4  2002/01/01 23:27:50  craigs
00090  * Added CleanupOnTermination functions
00091  * Thanks to Vyacheslav Frolov
00092  *
00093  * Revision 1.3  2001/12/22 01:57:04  robertj
00094  * Cleaned up code and allowed for repeated sequence numbers.
00095  *
00096  * Revision 1.2  2001/11/09 05:39:54  craigs
00097  * Added initial T.38 support thanks to Adam Lazur
00098  *
00099  * Revision 1.1  2001/07/17 04:44:29  robertj
00100  * Partial implementation of T.120 and T.38 logical channels.
00101  *
00102  */
00103 
00104 #ifndef __OPAL_T38PROTO_H
00105 #define __OPAL_T38PROTO_H
00106 
00107 #ifdef P_USE_PRAGMA
00108 #pragma interface
00109 #endif
00110 
00111 
00112 #include <ptlib/pipechan.h>
00113 
00114 #include <opal/mediafmt.h>
00115 #include <opal/mediastrm.h>
00116 #include <opal/endpoint.h>
00117 
00118 class OpalTransport;
00119 class T38_IFPPacket;
00120 class PASN_OctetString;
00121 
00122 namespace PWLibStupidLinkerHacks {
00123   extern int t38Loader;
00124 };
00125 
00127 
00130 class OpalT38Protocol : public PObject
00131 {
00132     PCLASSINFO(OpalT38Protocol, PObject);
00133   public:
00138     OpalT38Protocol();
00139 
00142     ~OpalT38Protocol();
00144 
00149     virtual void Close();
00150 
00155     virtual BOOL Originate();
00156 
00159     virtual BOOL WritePacket(
00160       const T38_IFPPacket & pdu
00161     );
00162 
00165     virtual BOOL WriteIndicator(
00166       unsigned indicator
00167     );
00168 
00171     virtual BOOL WriteMultipleData(
00172       unsigned mode,
00173       PINDEX count,
00174       unsigned * type,
00175       const PBYTEArray * data
00176     );
00177 
00180     virtual BOOL WriteData(
00181       unsigned mode,
00182       unsigned type,
00183       const PBYTEArray & data
00184     );
00185 
00188     virtual BOOL Answer();
00189 
00194     virtual BOOL HandlePacket(
00195       const T38_IFPPacket & pdu
00196     );
00197 
00202     virtual BOOL HandlePacketLost(
00203       unsigned nLost
00204     );
00205 
00209     virtual BOOL OnIndicator(
00210       unsigned indicator
00211     );
00212 
00216     virtual BOOL OnCNG();
00217 
00221     virtual BOOL OnCED();
00222 
00226     virtual BOOL OnPreamble();
00227 
00231     virtual BOOL OnTraining(
00232       unsigned indicator
00233     );
00234 
00239     virtual BOOL OnData(
00240       unsigned mode,
00241       unsigned type,
00242       const PBYTEArray & data
00243     );
00245 
00246     OpalTransport * GetTransport() const { return transport; }
00247     void SetTransport(
00248       OpalTransport * transport,
00249       BOOL autoDelete = TRUE
00250     );
00251 
00252   protected:
00253     BOOL HandleRawIFP(
00254       const PASN_OctetString & pdu
00255     );
00256 
00257     OpalTransport * transport;
00258     BOOL            autoDeleteTransport;
00259 
00260     BOOL     corrigendumASN;
00261     unsigned indicatorRedundancy;
00262     unsigned lowSpeedRedundancy;
00263     unsigned highSpeedRedundancy;
00264 
00265     int               lastSentSequenceNumber;
00266     PList<PBYTEArray> redundantIFPs;
00267 };
00268 
00269 
00271 
00272 #if OPAL_AUDIO
00273 
00279 class OpalFaxAudioFormat : public OpalMediaFormat
00280 {
00281   friend class OpalPluginCodecManager;
00282     PCLASSINFO(OpalFaxAudioFormat, OpalMediaFormat);
00283   public:
00284     OpalFaxAudioFormat(
00285       const char * fullName,    
00286       RTP_DataFrame::PayloadTypes rtpPayloadType, 
00287       const char * encodingName,
00288       PINDEX   frameSize,       
00289       unsigned frameTime,       
00290       unsigned rxFrames,        
00291       unsigned txFrames,        
00292       unsigned maxFrames = 256, 
00293       unsigned clockRate = 8000, 
00294       time_t timeStamp = 0       
00295     );
00296 };
00297 
00298 #endif
00299 
00301 
00307 class T38PseudoRTP : public RTP_UDP
00308 {
00309   PCLASSINFO(T38PseudoRTP, RTP_UDP);
00310 
00311   public:
00316     T38PseudoRTP(
00317       PHandleAggregator * aggregator, 
00318       unsigned id,                    
00319       BOOL remoteIsNAT                
00320     );
00321 
00323     ~T38PseudoRTP();
00324 
00325     BOOL ReadData(RTP_DataFrame & frame, BOOL loop);
00326     BOOL WriteData(RTP_DataFrame & frame);
00327     RTP_Session::SendReceiveStatus OnSendData(RTP_DataFrame & frame);
00328     RTP_Session::SendReceiveStatus OnSendControl(RTP_ControlFrame & /*frame*/, PINDEX & /*len*/);
00329 
00330     RTP_Session::SendReceiveStatus ReadDataPDU(RTP_DataFrame & frame);
00331     RTP_Session::SendReceiveStatus OnReceiveData(RTP_DataFrame & frame);
00332 
00333     BOOL SetRemoteSocketInfo(PIPSocket::Address address, WORD port, BOOL isDataPort);
00334 
00335   protected:
00336     int WaitForPDU(PUDPSocket & dataSocket, PUDPSocket & controlSocket, const PTimeInterval & timeout);
00337     BOOL OnTimeout(RTP_DataFrame & frame);
00338     BOOL corrigendumASN;
00339     int consecutiveBadPackets;
00340 
00341     PBYTEArray lastIFP;
00342 
00343 #if 0
00344     PList<PBYTEArray> redundantIFPs;
00345 #endif
00346 
00348 };
00349 
00351 
00352 class OpalFaxCallInfo {
00353   public:
00354     OpalFaxCallInfo();
00355     PUDPSocket socket;
00356     PPipeChannel spanDSP;
00357     unsigned refCount;
00358     PIPSocket::Address spanDSPAddr;
00359     WORD spanDSPPort;
00360 };
00361 
00363 
00366 class OpalFaxMediaStream : public OpalMediaStream
00367 {
00368   PCLASSINFO(OpalFaxMediaStream, OpalMediaStream);
00369   public:
00374     OpalFaxMediaStream(
00375       OpalConnection & conn,
00376       const OpalMediaFormat & mediaFormat, 
00377       unsigned sessionID, 
00378       BOOL isSource ,                      
00379       const PString & token,               
00380       const PString & filename,
00381       BOOL receive
00382     );
00384 
00391     virtual BOOL Open();
00392 
00397     virtual BOOL Close();
00398 
00404     virtual BOOL Start();
00405 
00409     virtual BOOL ReadPacket(
00410       RTP_DataFrame & packet
00411     );
00412 
00416     virtual BOOL WritePacket(
00417       RTP_DataFrame & packet
00418     );
00419 
00423     virtual BOOL IsSynchronous() const;
00424 
00425     virtual PString GetSpanDSPCommandLine(OpalFaxCallInfo &);
00426 
00428 
00429   protected:
00430     PMutex infoMutex;
00431     PString sessionToken;
00432     OpalFaxCallInfo * faxCallInfo;
00433     PFilePath filename;
00434     BOOL receive;
00435     BYTE writeBuffer[320];
00436     PINDEX writeBufferLen;
00437 };
00438 
00440 
00443 class OpalT38MediaStream : public OpalFaxMediaStream
00444 {
00445   PCLASSINFO(OpalT38MediaStream, OpalFaxMediaStream);
00446   public:
00447     OpalT38MediaStream(
00448       OpalConnection & conn,
00449       const OpalMediaFormat & mediaFormat, 
00450       unsigned sessionID, 
00451       BOOL isSource ,                      
00452       const PString & token,               
00453       const PString & filename,            
00454       BOOL receive
00455     );
00456 
00457     PString GetSpanDSPCommandLine(OpalFaxCallInfo &);
00458 
00459     BOOL ReadPacket(RTP_DataFrame & packet);
00460     BOOL WritePacket(RTP_DataFrame & packet);
00461 };
00462 
00464 
00465 class OpalFaxConnection;
00466 
00469 class OpalFaxEndPoint : public OpalEndPoint
00470 {
00471   PCLASSINFO(OpalFaxEndPoint, OpalEndPoint);
00472   public:
00477     OpalFaxEndPoint(
00478       OpalManager & manager,      
00479       const char * prefix = "fax" 
00480     );
00481 
00484     ~OpalFaxEndPoint();
00486 
00487     virtual BOOL MakeConnection(
00488       OpalCall & call,          
00489       const PString & party,    
00490       void * userData = NULL,          
00491       unsigned int options = 0,     
00492       OpalConnection::StringOptions * stringOptions = NULL
00493     );
00494 
00497     virtual OpalFaxConnection * CreateConnection(
00498       OpalCall & call,          
00499       const PString & filename, 
00500       BOOL receive,
00501       void * userData = NULL,   
00502       OpalConnection::StringOptions * stringOptions = NULL
00503     );
00504 
00514     virtual OpalMediaFormatList GetMediaFormats() const;
00515 
00516     virtual PString MakeToken();
00517 
00521     virtual void AcceptIncomingConnection(
00522       const PString & connectionToken 
00523     );
00524 
00529     virtual void OnPatchMediaStream(
00530       const OpalFaxConnection & connection, 
00531       BOOL isSource,                         
00532       OpalMediaPatch & patch                 
00533     );
00535 };
00536 
00538 
00541 class OpalFaxConnection : public OpalConnection
00542 {
00543   PCLASSINFO(OpalFaxConnection, OpalConnection);
00544   public:
00549     OpalFaxConnection(
00550       OpalCall & call,                 
00551       OpalFaxEndPoint & endpoint,      
00552       const PString & filename,        
00553       BOOL receive,                    
00554       const PString & _token,           
00555       OpalConnection::StringOptions * stringOptions = NULL
00556     );
00557 
00560     ~OpalFaxConnection();
00562 
00571     virtual BOOL SetUpConnection();
00572 
00583     virtual BOOL SetAlerting(
00584       const PString & calleeName,   
00585       BOOL withMedia                
00586     );
00587 
00592     virtual BOOL SetConnected();
00593 
00601     virtual OpalMediaFormatList GetMediaFormats() const;
00602 
00603     OpalMediaStream * CreateMediaStream(const OpalMediaFormat & mediaFormat, unsigned sessionID, BOOL isSource);
00604 
00612     virtual void OnPatchMediaStream(
00613       BOOL isSource,
00614       OpalMediaPatch & patch    
00615     );
00616 
00619     virtual BOOL OpenSourceMediaStream(
00620       const OpalMediaFormatList & mediaFormats, 
00621       unsigned sessionID                   
00622     );
00623 
00626     virtual OpalMediaStream * OpenSinkMediaStream(
00627       OpalMediaStream & source    
00628     );
00629 
00634     virtual void AcceptIncoming();
00635 
00637 
00638     void AdjustMediaFormats(OpalMediaFormatList & mediaFormats) const;
00639 
00640   protected:
00641     OpalFaxEndPoint & endpoint;
00642     PString filename;
00643     BOOL receive;
00644     BOOL forceFaxAudio;
00645 };
00646 
00648 
00649 class OpalT38Connection;
00650 
00653 class OpalT38EndPoint : public OpalFaxEndPoint
00654 {
00655   PCLASSINFO(OpalT38EndPoint, OpalFaxEndPoint);
00656   public:
00661     OpalT38EndPoint(
00662       OpalManager & manager,      
00663       const char * prefix = "t38" 
00664     );
00665     OpalMediaFormatList GetMediaFormats() const;
00666     PString MakeToken();
00667     virtual OpalFaxConnection * CreateConnection(OpalCall & call, const PString & filename, BOOL receive, void * /*userData*/, OpalConnection::StringOptions * stringOptions);
00668 };
00669 
00671 
00674 class OpalT38Connection : public OpalFaxConnection
00675 {
00676   PCLASSINFO(OpalT38Connection, OpalFaxConnection);
00677   public:
00682     OpalT38Connection(
00683       OpalCall & call,                 
00684       OpalT38EndPoint & endpoint,      
00685       const PString & filename,        
00686       BOOL receive,
00687       const PString & _token,           
00688       OpalConnection::StringOptions * stringOptions = NULL
00689     );
00690     void AdjustMediaFormats(OpalMediaFormatList & mediaFormats) const;
00691     OpalMediaStream * CreateMediaStream(const OpalMediaFormat & mediaFormat, unsigned sessionID, BOOL isSource);
00692     OpalMediaFormatList GetMediaFormats() const;
00693 };
00694 
00696 
00697 #define OPAL_T38            "T.38"
00698 #define OPAL_PCM16_FAX      "PCM-16-Fax"
00699 
00700 extern const OpalFaxAudioFormat & GetOpalPCM16Fax();
00701 extern const OpalMediaFormat    & GetOpalT38();
00702 
00703 #define OpalPCM16Fax          GetOpalPCM16Fax()
00704 #define OpalT38               GetOpalT38()
00705 
00706 
00707 #endif // __OPAL_T38PROTO_H
00708 
00709 

Generated on Fri Mar 7 06:33:41 2008 for OPAL by  doxygen 1.5.1