00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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 class OpalFaxConnection;
00054
00055
00056 namespace PWLibStupidLinkerHacks {
00057 extern int t38Loader;
00058 };
00059
00061
00067 class OpalFaxAudioFormat : public OpalMediaFormat
00068 {
00069 friend class OpalPluginCodecManager;
00070 PCLASSINFO(OpalFaxAudioFormat, OpalMediaFormat);
00071 public:
00072 OpalFaxAudioFormat(
00073 const char * fullName,
00074 RTP_DataFrame::PayloadTypes rtpPayloadType,
00075 const char * encodingName,
00076 PINDEX frameSize,
00077 unsigned frameTime,
00078 unsigned rxFrames,
00079 unsigned txFrames,
00080 unsigned maxFrames = 256,
00081 unsigned clockRate = 8000,
00082 time_t timeStamp = 0
00083 );
00084 };
00085
00086
00088
00089 class OpalFaxCallInfo {
00090 public:
00091 OpalFaxCallInfo();
00092 PUDPSocket socket;
00093 PPipeChannel spanDSP;
00094 unsigned refCount;
00095 PIPSocket::Address spanDSPAddr;
00096 WORD spanDSPPort;
00097 };
00098
00100
00103 class OpalFaxMediaStream : public OpalMediaStream
00104 {
00105 PCLASSINFO(OpalFaxMediaStream, OpalMediaStream);
00106 public:
00111 OpalFaxMediaStream(
00112 OpalFaxConnection & conn,
00113 const OpalMediaFormat & mediaFormat,
00114 unsigned sessionID,
00115 bool isSource,
00116 const PString & token,
00117 const PString & filename,
00118 bool receive,
00119 const PString & stationId
00120 );
00122
00129 virtual PBoolean Open();
00130
00135 virtual PBoolean Close();
00136
00140 virtual PBoolean ReadPacket(
00141 RTP_DataFrame & packet
00142 );
00143
00147 virtual PBoolean WritePacket(
00148 RTP_DataFrame & packet
00149 );
00150
00154 virtual PBoolean IsSynchronous() const;
00155
00156 virtual PString GetSpanDSPCommandLine(OpalFaxCallInfo &);
00157
00159
00160 protected:
00161 OpalFaxConnection & m_connection;
00162 PMutex infoMutex;
00163 PString sessionToken;
00164 OpalFaxCallInfo * m_faxCallInfo;
00165 PFilePath m_filename;
00166 bool m_receive;
00167 BYTE writeBuffer[320];
00168 PINDEX writeBufferLen;
00169 PString m_stationId;
00170 };
00171
00173
00176 class OpalT38MediaStream : public OpalFaxMediaStream
00177 {
00178 PCLASSINFO(OpalT38MediaStream, OpalFaxMediaStream);
00179 public:
00180 OpalT38MediaStream(
00181 OpalFaxConnection & conn,
00182 const OpalMediaFormat & mediaFormat,
00183 unsigned sessionID,
00184 bool isSource,
00185 const PString & token,
00186 const PString & filename,
00187 bool receive,
00188 const PString & stationId
00189 );
00190
00191 PString GetSpanDSPCommandLine(OpalFaxCallInfo &);
00192
00193 virtual PBoolean ReadPacket(RTP_DataFrame & packet);
00194 virtual PBoolean WritePacket(RTP_DataFrame & packet);
00195
00196 RTP_DataFrameList queuedFrames;
00197 };
00198
00200
00201 class OpalFaxConnection;
00202
00211 class OpalFaxEndPoint : public OpalEndPoint
00212 {
00213 PCLASSINFO(OpalFaxEndPoint, OpalEndPoint);
00214 public:
00219 OpalFaxEndPoint(
00220 OpalManager & manager,
00221 const char * g711Prefix = "fax",
00222 const char * t38Prefix = "t38"
00223 );
00224
00227 ~OpalFaxEndPoint();
00229
00230 virtual PBoolean MakeConnection(
00231 OpalCall & call,
00232 const PString & party,
00233 void * userData = NULL,
00234 unsigned int options = 0,
00235 OpalConnection::StringOptions * stringOptions = NULL
00236 );
00237
00240 virtual OpalFaxConnection * CreateConnection(
00241 OpalCall & call,
00242 void * userData,
00243 OpalConnection::StringOptions * stringOptions,
00244 const PString & filename,
00245 bool receive,
00246 bool t38
00247 );
00248
00258 virtual OpalMediaFormatList GetMediaFormats() const;
00259
00263 virtual void AcceptIncomingConnection(
00264 const PString & connectionToken
00265 );
00267
00271 const PFilePath & GetSpanDSP() const { return m_spanDSP; }
00272
00275 void SetSpanDSP(
00276 const PString & path
00277 ) { m_spanDSP = path; }
00278
00281 const PString & GetDefaultDirectory() const { return m_defaultDirectory; }
00282
00285 void SetDefaultDirectory(
00286 const PString & dir
00287 ) { m_defaultDirectory = dir; }
00288
00289 const PString & GetT38Prefix() const { return m_t38Prefix; }
00291
00292 protected:
00293 PString m_t38Prefix;
00294 PFilePath m_spanDSP;
00295 PDirectory m_defaultDirectory;
00296 };
00297
00298
00300
00303 class OpalFaxConnection : public OpalConnection
00304 {
00305 PCLASSINFO(OpalFaxConnection, OpalConnection);
00306 public:
00311 OpalFaxConnection(
00312 OpalCall & call,
00313 OpalFaxEndPoint & endpoint,
00314 const PString & filename,
00315 bool receive,
00316 const PString & _token,
00317 OpalConnection::StringOptions * stringOptions = NULL
00318 );
00319
00322 ~OpalFaxConnection();
00324
00335 virtual bool IsNetworkConnection() const { return false; }
00336
00343 virtual PBoolean SetUpConnection();
00344
00355 virtual PBoolean SetAlerting(
00356 const PString & calleeName,
00357 PBoolean withMedia
00358 );
00359
00367 virtual OpalMediaFormatList GetMediaFormats() const;
00368
00369 virtual void ApplyStringOptions(OpalConnection::StringOptions & stringOptions);
00370 virtual OpalMediaStream * CreateMediaStream(const OpalMediaFormat & mediaFormat, unsigned sessionID, PBoolean isSource);
00371 virtual void AdjustMediaFormats(OpalMediaFormatList & mediaFormats) const;
00372
00377 virtual void AcceptIncoming();
00378
00381 void CheckFaxStopped();
00383
00384 protected:
00385 PDECLARE_NOTIFIER(PTimer, OpalFaxConnection, OnFaxStoppedTimeout);
00386
00387 OpalFaxEndPoint & m_endpoint;
00388 PString m_filename;
00389 bool m_receive;
00390 PString m_stationId;
00391 PTimer m_faxStopped;
00392 };
00393
00395
00398 class OpalT38Connection : public OpalFaxConnection
00399 {
00400 PCLASSINFO(OpalT38Connection, OpalFaxConnection);
00401 public:
00406 OpalT38Connection(
00407 OpalCall & call,
00408 OpalFaxEndPoint & endpoint,
00409 const PString & filename,
00410 bool receive,
00411 const PString & token,
00412 OpalConnection::StringOptions * stringOptions = NULL
00413 );
00414
00415 virtual PString GetPrefixName() const { return m_endpoint.GetT38Prefix(); }
00416 virtual void ApplyStringOptions(OpalConnection::StringOptions & stringOptions);
00417 virtual void OnEstablished();
00418 virtual OpalMediaStream * CreateMediaStream(const OpalMediaFormat & mediaFormat, unsigned sessionID, PBoolean isSource);
00419 virtual void OnClosedMediaStream(const OpalMediaStream & stream);
00420 virtual OpalMediaFormatList GetMediaFormats() const;
00421
00422
00423 enum Mode {
00424 Mode_Wait,
00425 Mode_Timeout,
00426 Mode_UserInput,
00427 Mode_InBand
00428 };
00429
00430 virtual PBoolean SendUserInputTone(
00431 char tone,
00432 unsigned duration
00433 );
00434
00435 protected:
00436 PDECLARE_NOTIFIER(PTimer, OpalT38Connection, OnSendCNGCED);
00437 PDECLARE_NOTIFIER(PTimer, OpalT38Connection, OnFaxChangeTimeout);
00438 PDECLARE_NOTIFIER(PThread, OpalT38Connection, OpenFaxStreams);
00439 void RequestFaxMode(bool fax);
00440
00441 Mode m_syncMode;
00442
00443 bool m_faxMode;
00444 PTimer m_faxTimer;
00445 };
00446
00447
00448 #endif // OPAL_FAX
00449
00450 #endif // OPAL_T38_T38PROTO_H