OPAL  Version 3.12.5
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  * $Revision: 29550 $
27  * $Author: rjongbloed $
28  * $Date: 2013-04-22 22:08:10 -0500 (Mon, 22 Apr 2013) $
29  */
30 
31 #ifndef OPAL_T38_T38PROTO_H
32 #define OPAL_T38_T38PROTO_H
33 
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37 
38 #include <opal/buildopts.h>
39 
40 #if OPAL_FAX
41 
42 #include <opal/mediafmt.h>
43 #include <opal/mediastrm.h>
44 #include <opal/mediasession.h>
45 #include <ep/localep.h>
46 
47 
48 class OpalTransport;
49 class OpalFaxConnection;
50 
51 #if OPAL_PTLIB_ASN
52 class T38_IFPPacket;
53 class PASN_OctetString;
54 #endif
55 
56 #define OPAL_OPT_STATION_ID "Station-Id"
57 #define OPAL_OPT_HEADER_INFO "Header-Info"
58 #define OPAL_NO_G111_FAX "No-G711-Fax"
59 #define OPAL_SWITCH_ON_CED "Switch-On-CED"
60 #define OPAL_T38_SWITCH_TIME "T38-Switch-Time"
61 
62 #define OPAL_FAX_TIFF_FILE "TIFF-File"
63 
64 
66 
67 class OpalFaxConnection;
68 
81 {
83  public:
90  const char * g711Prefix = "fax",
91  const char * t38Prefix = "t38"
92  );
93 
98 
101  virtual PSafePtr<OpalConnection> MakeConnection(
102  OpalCall & call,
103  const PString & party,
104  void * userData = NULL,
105  unsigned int options = 0,
106  OpalConnection::StringOptions * stringOptions = NULL
107  );
108 
116  virtual OpalMediaFormatList GetMediaFormats() const;
118 
123  virtual bool IsAvailable() const;
124 
128  OpalCall & call,
129  void * userData,
130  OpalConnection::StringOptions * stringOptions,
131  const PString & filename,
132  bool receiving,
133  bool disableT38
134  );
135 
139  virtual void OnFaxCompleted(
140  OpalFaxConnection & connection,
141  bool failed
142  );
144 
148  const PString & GetDefaultDirectory() const { return m_defaultDirectory; }
149 
153  const PString & dir
154  ) { m_defaultDirectory = dir; }
155 
156  const PString & GetT38Prefix() const { return m_t38Prefix; }
158 
159  protected:
160  PString m_t38Prefix;
161  PDirectory m_defaultDirectory;
162 };
163 
164 
166 
184 {
186  public:
192  OpalCall & call,
194  const PString & filename,
195  bool receiving,
196  bool disableT38,
197  OpalConnection::StringOptions * stringOptions = NULL
198  );
199 
204 
207  virtual PString GetPrefixName() const;
208 
209  virtual OpalMediaFormatList GetMediaFormats() const;
210  virtual void AdjustMediaFormats(bool local, const OpalConnection * otherConnection, OpalMediaFormatList & mediaFormats) const;
211  virtual void OnEstablished();
212  virtual void OnReleased();
213  virtual OpalMediaStream * CreateMediaStream(const OpalMediaFormat & mediaFormat, unsigned sessionID, PBoolean isSource);
214  virtual void OnStartMediaPatch(OpalMediaPatch & patch);
215  virtual void OnClosedMediaStream(const OpalMediaStream & stream);
216  virtual PBoolean SendUserInputTone(char tone, unsigned duration);
217  virtual void OnUserInputTone(char tone, unsigned duration);
218  virtual bool SwitchFaxMediaStreams(bool toT38);
219  virtual void OnSwitchedFaxMediaStreams(bool toT38, bool success);
220  virtual bool OnSwitchingFaxMediaStreams(bool toT38);
221  virtual void OnApplyStringOptions();
223 
229  virtual void OnFaxCompleted(
230  bool failed
231  );
232 
235  virtual void GetStatistics(
236  OpalMediaStatistics & statistics
237  ) const;
238 
241  const PString & GetFileName() const { return m_filename; }
242 
245  bool IsReceive() const { return m_receiving; }
247 
248  protected:
249  PDECLARE_NOTIFIER(PTimer, OpalFaxConnection, OnSwitchTimeout);
250  void InternalOpenFaxStreams();
251  void InternalOnFaxCompleted();
252 
253  void SetFaxMediaFormatOptions(OpalMediaFormat & mediaFormat) const;
254 
256  PString m_filename;
259  unsigned m_switchTime;
261 
263 
265  PAtomicBoolean m_completed;
266 };
267 
268 
269 typedef OpalFaxConnection OpalT38Connection; // For backward compatibility
270 
271 class T38_UDPTLPacket;
272 
274 {
275  public:
276  static const PCaselessString & UDPTL();
277 
278  OpalFaxSession(const Init & init);
279  ~OpalFaxSession();
280 
281  virtual const PCaselessString & GetSessionType() const { return UDPTL(); }
282  virtual bool Open(const PString & localInterface, const OpalTransportAddress & remoteAddress, bool isMediaAddress);
283  virtual bool IsOpen() const;
284  virtual bool Close();
285  virtual OpalTransportAddress GetLocalAddress(bool isMediaAddress = true) const;
286  virtual OpalTransportAddress GetRemoteAddress(bool isMediaAddress = true) const;
287  virtual bool SetRemoteAddress(const OpalTransportAddress & remoteAddress, bool isMediaAddress = true);
288 
289  virtual void AttachTransport(Transport & transport);
290  virtual Transport DetachTransport();
291 
293  const OpalMediaFormat & mediaFormat,
294  unsigned sessionID,
295  bool isSource
296  );
297 
298  bool WriteData(RTP_DataFrame & frame);
299  bool ReadData(RTP_DataFrame & frame);
300 
301  void ApplyMediaOptions(const OpalMediaFormat & mediaFormat);
302 
303  protected:
304  void SetFrameFromIFP(RTP_DataFrame & frame, const PASN_OctetString & ifp, unsigned sequenceNumber);
305  void DecrementSentPacketRedundancy(bool stripRedundancy);
306  bool WriteUDPTL();
307 
309  PIPSocket * m_dataSocket;
311 
312  bool m_rawUDPTL; // Put UDPTL directly in RTP payload
314 
317  T38_UDPTLPacket * m_receivedPacket;
320 
321  std::map<int, int> m_redundancy;
322  PTimeInterval m_redundancyInterval;
323  PTimeInterval m_keepAliveInterval;
325  std::vector<int> m_sentPacketRedundancy;
326  T38_UDPTLPacket * m_sentPacket;
327  PMutex m_writeMutex;
329  PDECLARE_NOTIFIER(PTimer, OpalFaxSession, OnWriteDataIdle);
330 };
331 
333 {
334  PCLASSINFO(OpalFaxMediaStream, OpalMediaStream);
335 
336  public:
339  unsigned sessionID,
340  bool isSource,
341  OpalFaxSession & session);
342 
343  virtual PBoolean Open();
344  virtual PBoolean ReadPacket(RTP_DataFrame & packet);
345  virtual PBoolean WritePacket(RTP_DataFrame & packet);
346  virtual PBoolean IsSynchronous() const;
347  virtual bool InternalUpdateMediaFormat(const OpalMediaFormat & mediaFormat);
348 
349  protected:
350  virtual void InternalClose();
351 
353 };
354 
355 #endif // OPAL_FAX
356 
357 #endif // OPAL_T38_T38PROTO_H