spandsp  3.0.0
t38_gateway.h
Go to the documentation of this file.
1 /*
2  * SpanDSP - a series of DSP components for telephony
3  *
4  * t38_gateway.h - A T.38, less the packet exchange part
5  *
6  * Written by Steve Underwood <steveu@coppice.org>
7  *
8  * Copyright (C) 2005, 2006, 2007 Steve Underwood
9  *
10  * All rights reserved.
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 2.1,
14  * as published by the Free Software Foundation.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this program; if not, write to the Free Software
23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25 
26 /*! \file */
27 
28 #if !defined(_SPANDSP_T38_GATEWAY_H_)
29 #define _SPANDSP_T38_GATEWAY_H_
30 
31 /*! \page t38_gateway_page T.38 real time FAX over IP PSTN gateway
32 \section t38_gateway_page_sec_1 What does it do?
33 
34 The T.38 gateway facility provides a robust interface between T.38 IP packet streams and
35 and 8k samples/second audio streams. It provides the buffering and flow control features needed
36 to maximum the tolerance of jitter and packet loss on the IP network.
37 
38 \section t38_gateway_page_sec_2 How does it work?
39 */
40 
41 /*! The maximum number of bytes to be zapped, in order to corrupt NSF,
42  NSS and NSC messages, so the receiver does not recognise them. */
43 #define MAX_NSX_SUPPRESSION 10
44 
46 
47 /*!
48  T.38 gateway real time frame handler.
49  \brief T.38 gateway real time frame handler.
50  \param user_data An opaque pointer.
51  \param incoming True for incoming, false for outgoing.
52  \param msg The HDLC message.
53  \param len The length of the message.
54 */
55 typedef void (*t38_gateway_real_time_frame_handler_t)(void *user_data,
56  bool incoming,
57  const uint8_t *msg,
58  int len);
59 
60 /*!
61  T.38 gateway results.
62  */
63 typedef struct
64 {
65  /*! \brief The current bit rate for image transfer. */
66  int bit_rate;
67  /*! \brief True if error correcting mode is used. */
69  /*! \brief The number of pages transferred so far. */
71 } t38_stats_t;
72 
73 #if defined(__cplusplus)
74 extern "C"
75 {
76 #endif
77 
78 /*! \brief Initialise a gateway mode T.38 context.
79  \param s The T.38 context.
80  \param tx_packet_handler A callback routine to encapsulate and transmit T.38 packets.
81  \param tx_packet_user_data An opaque pointer passed to the tx_packet_handler routine.
82  \return A pointer to the termination mode T.38 context, or NULL if there was a problem. */
84  t38_tx_packet_handler_t tx_packet_handler,
85  void *tx_packet_user_data);
86 
87 /*! Release a gateway mode T.38 context.
88  \brief Release a T.38 context.
89  \param s The T.38 context.
90  \return 0 for OK, else -1. */
91 SPAN_DECLARE(int) t38_gateway_release(t38_gateway_state_t *s);
92 
93 /*! Free a gateway mode T.38 context.
94  \brief Free a T.38 context.
95  \param s The T.38 context.
96  \return 0 for OK, else -1. */
97 SPAN_DECLARE(int) t38_gateway_free(t38_gateway_state_t *s);
98 
99 /*! Process a block of received FAX audio samples.
100  \brief Process a block of received FAX audio samples.
101  \param s The T.38 context.
102  \param amp The audio sample buffer.
103  \param len The number of samples in the buffer.
104  \return The number of samples unprocessed. */
105 SPAN_DECLARE(int) t38_gateway_rx(t38_gateway_state_t *s, int16_t amp[], int len);
106 
107 /*! Apply fake processing when a block of audio samples is missing (e.g due
108  to packet loss).
109  \brief Apply fake received audio processing.
110  \param s The T.38 context.
111  \param len The number of samples to fake.
112  \return The number of samples unprocessed. This should only be non-zero if
113  the software has reached the end of the FAX call.
114 */
115 SPAN_DECLARE(int) t38_gateway_rx_fillin(t38_gateway_state_t *s, int len);
116 
117 /*! Generate a block of FAX audio samples.
118  \brief Generate a block of FAX audio samples.
119  \param s The T.38 context.
120  \param amp The audio sample buffer.
121  \param max_len The number of samples to be generated.
122  \return The number of samples actually generated.
123 */
124 SPAN_DECLARE(int) t38_gateway_tx(t38_gateway_state_t *s, int16_t amp[], int max_len);
125 
126 /*! Control whether error correcting mode (ECM) is allowed.
127  \brief Control whether error correcting mode (ECM) is allowed.
128  \param s The T.38 context.
129  \param ecm_allowed True is ECM is to be allowed.
130 */
131 SPAN_DECLARE(void) t38_gateway_set_ecm_capability(t38_gateway_state_t *s, bool ecm_allowed);
132 
133 /*! Select whether silent audio will be sent when transmit is idle.
134  \brief Select whether silent audio will be sent when transmit is idle.
135  \param s The T.38 context.
136  \param transmit_on_idle True if silent audio should be output when the FAX transmitter is
137  idle. False to transmit zero length audio when the FAX transmitter is idle. The default
138  behaviour is false.
139 */
140 SPAN_DECLARE(void) t38_gateway_set_transmit_on_idle(t38_gateway_state_t *s, bool transmit_on_idle);
141 
142 /*! Specify which modem types are supported by a T.30 context.
143  \brief Specify supported modems.
144  \param s The T.38 context.
145  \param supported_modems Bit field list of the supported modems.
146 */
147 SPAN_DECLARE(void) t38_gateway_set_supported_modems(t38_gateway_state_t *s, int supported_modems);
148 
149 /*! Select whether NSC, NSF, and NSS should be suppressed. It selected, the contents of
150  these messages are forced to zero for all octets beyond the message type. This makes
151  them look like manufacturer specific messages, from a manufacturer which does not exist.
152  \brief Select whether NSC, NSF, and NSS should be suppressed.
153  \param s The T.38 context.
154  \param from_t38 A string of bytes to overwrite the header of any NSC, NSF, and NSS
155  frames passing through the gateway from T.38 the the modem.
156  \param from_t38_len The length of the overwrite string.
157  \param from_modem A string of bytes to overwrite the header of any NSC, NSF, and NSS
158  frames passing through the gateway from the modem to T.38.
159  \param from_modem_len The length of the overwrite string.
160 */
162  const uint8_t *from_t38,
163  int from_t38_len,
164  const uint8_t *from_modem,
165  int from_modem_len);
166 
167 /*! Select whether talker echo protection tone will be sent for the image modems.
168  \brief Select whether TEP will be sent for the image modems.
169  \param s The T.38 context.
170  \param use_tep True if TEP should be sent.
171 */
172 SPAN_DECLARE(void) t38_gateway_set_tep_mode(t38_gateway_state_t *s, bool use_tep);
173 
174 /*! Select whether non-ECM fill bits are to be removed during transmission.
175  \brief Select whether non-ECM fill bits are to be removed during transmission.
176  \param s The T.38 context.
177  \param remove True if fill bits are to be removed.
178 */
179 SPAN_DECLARE(void) t38_gateway_set_fill_bit_removal(t38_gateway_state_t *s, bool remove);
180 
181 /*! Get the current transfer statistics for the current T.38 session.
182  \brief Get the current transfer statistics.
183  \param s The T.38 context.
184  \param t A pointer to a buffer for the statistics. */
186 
187 /*! Get a pointer to the T.38 core IFP packet engine associated with a
188  gateway mode T.38 context.
189  \brief Get a pointer to the T.38 core IFP packet engine associated
190  with a T.38 context.
191  \param s The T.38 context.
192  \return A pointer to the T.38 core context, or NULL.
193 */
195 
196 /*! Get a pointer to the logging context associated with a T.38 context.
197  \brief Get a pointer to the logging context associated with a T.38 context.
198  \param s The T.38 context.
199  \return A pointer to the logging context, or NULL.
200 */
202 
203 /*! Set a callback function for T.30 frame exchange monitoring. This is called from the heart
204  of the signal processing, so don't take too long in the handler routine.
205  \brief Set a callback function for T.30 frame exchange monitoring.
206  \param s The T.30 context.
207  \param handler The callback function.
208  \param user_data An opaque pointer passed to the callback function. */
211  void *user_data);
212 
213 #if defined(__cplusplus)
214 }
215 #endif
216 
217 #endif
218 /*- End of file ------------------------------------------------------------*/
int t38_gateway_release(t38_gateway_state_t *s)
Release a T.38 context.
Definition: t38_gateway.c:2423
void(* t38_gateway_real_time_frame_handler_t)(void *user_data, bool incoming, const uint8_t *msg, int len)
T.38 gateway real time frame handler.
Definition: t38_gateway.h:55
t38_core_state_t * t38_gateway_get_t38_core_state(t38_gateway_state_t *s)
Get a pointer to the T.38 core IFP packet engine associated with a T.38 context.
Definition: t38_gateway.c:2238
int t38_gateway_free(t38_gateway_state_t *s)
Free a T.38 context.
Definition: t38_gateway.c:2429
void t38_gateway_set_tep_mode(t38_gateway_state_t *s, bool use_tep)
Select whether TEP will be sent for the image modems.
Definition: t38_gateway.c:2292
int bit_rate
The current bit rate for image transfer.
Definition: t38_gateway.h:66
bool error_correcting_mode
True if error correcting mode is used.
Definition: t38_gateway.h:68
int t38_gateway_rx_fillin(t38_gateway_state_t *s, int len)
Apply fake received audio processing.
Definition: t38_gateway.c:2156
int t38_gateway_rx(t38_gateway_state_t *s, int16_t amp[], int len)
Process a block of received FAX audio samples.
Definition: t38_gateway.c:2137
void t38_gateway_get_transfer_statistics(t38_gateway_state_t *s, t38_stats_t *t)
Get the current transfer statistics.
Definition: t38_gateway.c:2229
t38_gateway_state_t * t38_gateway_init(t38_gateway_state_t *s, t38_tx_packet_handler_t tx_packet_handler, void *tx_packet_user_data)
Initialise a gateway mode T.38 context.
Definition: t38_gateway.c:2357
int t38_gateway_tx(t38_gateway_state_t *s, int16_t amp[], int max_len)
Generate a block of FAX audio samples.
Definition: t38_gateway.c:2184
void t38_gateway_set_ecm_capability(t38_gateway_state_t *s, bool ecm_allowed)
Control whether error correcting mode (ECM) is allowed.
Definition: t38_gateway.c:2250
Definition: t38_gateway.h:63
Definition: private/logging.h:33
Definition: private/t38_gateway.h:191
void t38_gateway_set_transmit_on_idle(t38_gateway_state_t *s, bool transmit_on_idle)
Select whether silent audio will be sent when transmit is idle.
Definition: t38_gateway.c:2256
logging_state_t * t38_gateway_get_logging_state(t38_gateway_state_t *s)
Get a pointer to the logging context associated with a T.38 context.
Definition: t38_gateway.c:2244
int pages_transferred
The number of pages transferred so far.
Definition: t38_gateway.h:70
Definition: private/t38_core.h:32
void t38_gateway_set_nsx_suppression(t38_gateway_state_t *s, const uint8_t *from_t38, int from_t38_len, const uint8_t *from_modem, int from_modem_len)
Select whether NSC, NSF, and NSS should be suppressed.
Definition: t38_gateway.c:2275
void t38_gateway_set_fill_bit_removal(t38_gateway_state_t *s, bool remove)
Select whether non-ECM fill bits are to be removed during transmission.
Definition: t38_gateway.c:2298
void t38_gateway_set_real_time_frame_handler(t38_gateway_state_t *s, t38_gateway_real_time_frame_handler_t handler, void *user_data)
Set a callback function for T.30 frame exchange monitoring.
Definition: t38_gateway.c:2304
void t38_gateway_set_supported_modems(t38_gateway_state_t *s, int supported_modems)
Specify supported modems.
Definition: t38_gateway.c:2262