OPAL  Version 3.18.8
t38proto.h
Go to the documentation of this file.
1 /*
2  * t38proto.h
3  *
4  * T.38 protocol handler
5  *
6  * Open Phone Abstraction Library
7  *
8  * Copyright (c) 2001 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Open H323 Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Contributor(s): ______________________________________.
25  */
26 
27 #ifndef OPAL_T38_T38PROTO_H
28 #define OPAL_T38_T38PROTO_H
29 
30 #ifdef P_USE_PRAGMA
31 #pragma interface
32 #endif
33 
34 #include <opal_config.h>
35 
36 #if OPAL_T38_CAPABILITY
37 
38 #include <opal/mediafmt.h>
39 #include <opal/mediastrm.h>
40 #include <opal/mediasession.h>
41 #include <ep/localep.h>
42 
43 
44 class OpalTransport;
45 class OpalFaxConnection;
46 
47 #if OPAL_PTLIB_ASN
48 class T38_IFPPacket;
49 class PASN_OctetString;
50 #endif
51 
52 #define OPAL_OPT_STATION_ID "Station-Id"
53 #define OPAL_OPT_HEADER_INFO "Header-Info"
54 #define OPAL_NO_G711_FAX "No-G711-Fax"
55 #define OPAL_SWITCH_ON_CED "Switch-On-CED"
56 #define OPAL_T38_SWITCH_TIME "T38-Switch-Time"
57 
58 #define OPAL_FAX_TIFF_FILE "TIFF-File"
59 
60 #define OPAL_T38FaxRateManagement "T38FaxRateManagement"
61 #define OPAL_T38localTCF "localTCF"
62 #define OPAL_T38transferredTCF "transferredTCF"
63 #define OPAL_T38FaxVersion "T38FaxVersion"
64 #define OPAL_T38MaxBitRate "T38MaxBitRate"
65 #define OPAL_T38FaxMaxBuffer "T38FaxMaxBuffer"
66 #define OPAL_T38FaxMaxDatagram "T38FaxMaxDatagram"
67 #define OPAL_T38FaxUdpEC "T38FaxUdpEC"
68 #define OPAL_T38UDPFEC "t38UDPFEC"
69 #define OPAL_T38UDPRedundancy "t38UDPRedundancy"
70 #define OPAL_T38FaxFillBitRemoval "T38FaxFillBitRemoval"
71 #define OPAL_T38FaxTranscodingMMR "T38FaxTranscodingMMR"
72 #define OPAL_T38FaxTranscodingJBIG "T38FaxTranscodingJBIG"
73 #define OPAL_T38UseECM "Use-ECM"
74 #define OPAL_FaxStationIdentifier "Station-Identifier"
75 #define OPAL_FaxHeaderInfo "Header-Info"
76 #define OPAL_UDPTLRawMode "UDPTL-Raw-Mode"
77 #define OPAL_UDPTLRedundancy "UDPTL-Redundancy"
78 #define OPAL_UDPTLRedundancyInterval "UDPTL-Redundancy-Interval"
79 #define OPAL_UDPTLOptimiseRetransmit "UDPTL-Optimise-On-Retransmit"
80 #define OPAL_UDPTLKeepAliveInterval "UDPTL-Keep-Alive-Interval"
81 
82 
83 
84 #if OPAL_FAX
85 
87 
88 class OpalFaxConnection;
89 
101 class OpalFaxEndPoint : public OpalLocalEndPoint
102 {
103  PCLASSINFO(OpalFaxEndPoint, OpalLocalEndPoint);
104  public:
109  OpalFaxEndPoint(
110  OpalManager & manager,
111  const char * g711Prefix = "fax",
112  const char * t38Prefix = "t38"
113  );
114 
117  ~OpalFaxEndPoint();
119 
122  virtual PSafePtr<OpalConnection> MakeConnection(
123  OpalCall & call,
124  const PString & party,
125  void * userData = NULL,
126  unsigned int options = 0,
127  OpalConnection::StringOptions * stringOptions = NULL
128  );
129 
137  virtual OpalMediaFormatList GetMediaFormats() const;
138 
141  virtual PStringList GetAvailableStringOptions() const;
143 
148  virtual bool IsAvailable() const;
149 
152  virtual OpalFaxConnection * CreateConnection(
153  OpalCall & call,
154  void * userData,
155  OpalConnection::StringOptions * stringOptions,
156  const PString & filename,
157  bool receiving,
158  bool disableT38
159  );
160 
164  virtual void OnFaxCompleted(
165  OpalFaxConnection & connection,
166  bool failed
167  );
169 
173  const PString & GetDefaultDirectory() const { return m_defaultDirectory; }
174 
177  void SetDefaultDirectory(
178  const PString & dir
179  ) { m_defaultDirectory = dir; }
180 
181  const PString & GetT38Prefix() const { return m_t38Prefix; }
183 
184  protected:
185  PString m_t38Prefix;
186  PDirectory m_defaultDirectory;
187 };
188 
189 
191 
208 class OpalFaxConnection : public OpalLocalConnection
209 {
210  PCLASSINFO(OpalFaxConnection, OpalLocalConnection);
211  public:
216  OpalFaxConnection(
217  OpalCall & call,
218  OpalFaxEndPoint & endpoint,
219  const PString & filename,
220  bool receiving,
221  bool disableT38,
222  OpalConnection::StringOptions * stringOptions = NULL
223  );
224 
227  ~OpalFaxConnection();
229 
232  virtual PString GetPrefixName() const;
233 
234  virtual OpalMediaFormatList GetMediaFormats() const;
235  virtual void AdjustMediaFormats(bool local, const OpalConnection * otherConnection, OpalMediaFormatList & mediaFormats) const;
236  virtual void OnEstablished();
237  virtual void OnReleased();
238  virtual OpalMediaStream * CreateMediaStream(const OpalMediaFormat & mediaFormat, unsigned sessionID, PBoolean isSource);
239  virtual void OnClosedMediaStream(const OpalMediaStream & stream);
240  virtual void OnStopMediaPatch(OpalMediaPatch & patch);
241  virtual PBoolean SendUserInputTone(char tone, unsigned duration);
242  virtual void OnUserInputTone(char tone, unsigned duration);
243  virtual bool SwitchFaxMediaStreams(bool toT38);
244  virtual void OnSwitchedFaxMediaStreams(bool toT38, bool success);
245  virtual bool OnSwitchingFaxMediaStreams(bool toT38);
246  virtual void OnApplyStringOptions();
248 
254  virtual void OnFaxCompleted(
255  bool failed
256  );
257 
260  virtual void GetStatistics(
261  OpalMediaStatistics & statistics
262  ) const;
263 
266  const PString & GetFileName() const { return m_filename; }
267 
270  bool IsReceive() const { return m_receiving; }
272 
273  protected:
274  PDECLARE_NOTIFIER(PTimer, OpalFaxConnection, OnSwitchTimeout);
275  void InternalOpenFaxStreams();
276  void InternalOnFaxCompleted();
277 
278  void SetFaxMediaFormatOptions(OpalMediaFormat & mediaFormat) const;
279 
280  OpalFaxEndPoint & m_endpoint;
281  PString m_filename;
282  bool m_receiving;
283  bool m_disableT38;
284  unsigned m_switchTime;
285  atomic<bool> m_switchedOnUserInput;
286  OpalMediaFormat m_tiffFileFormat;
287 
288  PTimer m_switchTimer;
289 
290  OpalMediaStatistics m_finalStatistics;
291  atomic<bool> m_completed;
292 };
293 
294 
295 typedef OpalFaxConnection OpalT38Connection; // For backward compatibility
296 
297 class T38_UDPTLPacket;
298 
299 class OpalFaxSession : public OpalMediaSession
300 {
301  public:
302  static const PCaselessString & UDPTL();
303 
304  OpalFaxSession(const Init & init);
305  ~OpalFaxSession();
306 
307  virtual const PCaselessString & GetSessionType() const { return UDPTL(); }
308  virtual void AttachTransport(const OpalMediaTransportPtr & transport);
309  virtual bool Open(const PString & localInterface, const OpalTransportAddress & remoteAddress);
310  virtual bool IsOpen() const;
311  virtual bool Close();
312 
314  const OpalMediaFormat & mediaFormat,
315  unsigned sessionID,
316  bool isSource
317  );
318 
319  bool WriteData(RTP_DataFrame & frame);
320  bool ReadData(RTP_DataFrame & frame);
321 
322  void ApplyMediaOptions(const OpalMediaFormat & mediaFormat);
323 
324  virtual void GetStatistics(OpalMediaStatistics & statistics, bool receiver) const;
325 
326  protected:
327  void SetFrameFromIFP(RTP_DataFrame & frame, const PASN_OctetString & ifp, unsigned sequenceNumber);
328  void DecrementSentPacketRedundancy(bool stripRedundancy);
329  bool WriteUDPTL();
330 
331  PDECLARE_MediaReadNotifier(OpalFaxSession, OnReadPacket);
332  PSyncQueue<PBYTEArray> m_readQueue;
333 
334  bool m_rawUDPTL; // Put UDPTL directly in RTP payload
335  PINDEX m_datagramSize;
336 
337  int m_consecutiveBadPackets;
338  bool m_awaitingGoodPacket;
339  T38_UDPTLPacket * m_receivedPacket;
340  unsigned m_expectedSequenceNumber;
341  int m_secondaryPacket;
342 
343  std::map<int, int> m_redundancy;
344  PTimeInterval m_redundancyInterval;
345  PTimeInterval m_keepAliveInterval;
346  bool m_optimiseOnRetransmit;
347  std::vector<int> m_sentPacketRedundancy;
348  T38_UDPTLPacket * m_sentPacket;
349  PDECLARE_MUTEX(m_writeMutex);
350  PTimer m_timerWriteDataIdle;
351  PDECLARE_NOTIFIER(PTimer, OpalFaxSession, OnWriteDataIdle);
352 
353  PUInt64 m_txBytes;
354  unsigned m_txPackets;
355  PUInt64 m_rxBytes;
356  unsigned m_rxPackets;
357  unsigned m_missingPackets;
358 };
359 
360 class OpalFaxMediaStream : public OpalMediaStream
361 {
362  PCLASSINFO(OpalFaxMediaStream, OpalMediaStream);
363 
364  public:
365  OpalFaxMediaStream(OpalConnection & conn,
366  const OpalMediaFormat & mediaFormat,
367  unsigned sessionID,
368  bool isSource,
369  OpalFaxSession & session);
370 
371  virtual PBoolean Open();
372  virtual PBoolean Start();
373  virtual PBoolean ReadPacket(RTP_DataFrame & packet);
374  virtual PBoolean WritePacket(RTP_DataFrame & packet);
375  virtual PString GetPatchThreadName() const;
376  virtual PBoolean IsSynchronous() const;
377  virtual bool InternalUpdateMediaFormat(const OpalMediaFormat & mediaFormat);
378  virtual void GetStatistics(OpalMediaStatistics & statistics, bool fromPatch) const;
379 
380  protected:
381  virtual void InternalClose();
382 
383  OpalFaxSession & m_session;
384 };
385 
386 #endif // OPAL_FAX
387 #endif // OPAL_T38_CAPABILITY
388 
389 #endif // OPAL_T38_T38PROTO_H
virtual void OnClosedMediaStream(const OpalMediaStream &stream)
virtual PStringList GetAvailableStringOptions() const
virtual const PCaselessString & GetSessionType() const =0
#define PDECLARE_MediaReadNotifier(cls, fn)
Definition: mediasession.h:487
virtual void OnReleased()
bool GetStatistics(const OpalMediaType &mediaType, bool source, OpalMediaStatistics &statistics) const
Get media statistics of the type, and of the specifed direction.
Definition: manager.h:150
virtual PBoolean IsSynchronous() const =0
virtual void OnUserInputTone(char tone, unsigned duration)
virtual OpalMediaStream * CreateMediaStream(const OpalMediaFormat &mediaFormat, unsigned sessionID, PBoolean isSource)
virtual bool Open(const PString &localInterface, const OpalTransportAddress &remoteAddress)=0
virtual void OnApplyStringOptions()
Call back for connection to act on changed string options.
Definition: localep.h:469
Definition: mediasession.h:647
Definition: transports.h:788
virtual PBoolean SendUserInputTone(char tone, unsigned duration=0)
virtual PSafePtr< OpalConnection > MakeConnection(OpalCall &call, const PString &party, void *userData=NULL, unsigned int options=0, OpalConnection::StringOptions *stringOptions=NULL)
OpalLocalEndPoint & m_endpoint
Definition: localep.h:830
virtual bool Close()
virtual PBoolean Open()
virtual void OnStopMediaPatch(OpalMediaPatch &patch)
Definition: mediafmt.h:112
Definition: connection.h:530
Definition: rtp.h:540
Definition: localep.h:63
Definition: patch.h:56
virtual void OnEstablished()
Definition: mediafmt.h:806
Definition: call.h:62
virtual void AdjustMediaFormats(bool local, const OpalConnection *otherConnection, OpalMediaFormatList &mediaFormats) const
virtual bool IsOpen() const
virtual OpalMediaFormatList GetMediaFormats() const
virtual void AttachTransport(const OpalMediaTransportPtr &transport)
virtual void InternalClose()=0
PSafePtr< OpalMediaTransport, PSafePtrMultiThreaded > OpalMediaTransportPtr
Definition: mediasession.h:605
PDECLARE_NOTIFIER(RTP_DataFrame, OpalConnection, OnRecordAudio)
virtual void GetStatistics(OpalMediaStatistics &statistics, bool fromPatch=false) const
Definition: mediastrm.h:110
virtual PString GetPatchThreadName() const
virtual bool InternalUpdateMediaFormat(const OpalMediaFormat &mediaFormat)
virtual PBoolean Start()
Definition: connection.h:415
virtual void GetStatistics(OpalMediaStatistics &statistics, bool receiver) const
virtual PBoolean WritePacket(RTP_DataFrame &packet)
virtual OpalLocalConnection * CreateConnection(OpalCall &call, void *userData, unsigned options, OpalConnection::StringOptions *stringOptions)
virtual PString GetPrefixName() const
Definition: mediasession.h:210
Definition: transports.h:151
virtual OpalMediaStream * CreateMediaStream(const OpalMediaFormat &mediaFormat, unsigned sessionID, bool isSource)=0
virtual OpalMediaFormatList GetMediaFormats() const
virtual PBoolean ReadPacket(RTP_DataFrame &packet)