5
|
1 /*
|
|
2 * SpanDSP - a series of DSP components for telephony
|
|
3 *
|
|
4 * t38_gateway.h - An implementation of T.38, less the packet exchange part
|
|
5 *
|
|
6 * Written by Steve Underwood <steveu@coppice.org>
|
|
7 *
|
|
8 * Copyright (C) 2005 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 General Public License version 2, as
|
|
14 * 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 General Public License for more details.
|
|
20 *
|
|
21 * You should have received a copy of the GNU General Public License
|
|
22 * along with this program; if not, write to the Free Software
|
|
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
24 *
|
|
25 * $Id: t38_gateway.h,v 1.17 2006/12/07 13:22:26 steveu Exp $
|
|
26 */
|
|
27
|
|
28 /*! \file */
|
|
29
|
|
30 #if !defined(_T38_GATEWAY_H_)
|
|
31 #define _T38_GATEWAY_H_
|
|
32
|
|
33 /*! \page t38_gateway_page T.38 real time FAX over IP PSTN gateway
|
|
34 \section t38_gateway_page_sec_1 What does it do?
|
|
35
|
|
36 The T.38 gateway facility provides a robust interface between T.38 IP packet streams and
|
|
37 and 8k samples/second audio streams. It provides the buffering and flow control features needed
|
|
38 to maximum the tolerance of jitter and packet loss on the IP network.
|
|
39
|
|
40 \section t38_gateway_page_sec_2 How does it work?
|
|
41 */
|
|
42
|
|
43 #define T38_RX_BUF_LEN 2048
|
|
44 #define T38_TX_BUF_LEN 16384
|
|
45
|
|
46 #define T38_TX_HDLC_BUFS 256
|
|
47
|
|
48 /* Make sure the HDLC frame buffers are big enough for ECM frames. */
|
|
49 #define T38_MAX_HDLC_LEN 260
|
|
50
|
|
51 typedef struct
|
|
52 {
|
|
53 t38_core_state_t t38;
|
|
54
|
|
55 int ecm_allowed;
|
|
56
|
|
57 /*! \brief HDLC message buffers. */
|
|
58 uint8_t hdlc_buf[T38_TX_HDLC_BUFS][T38_MAX_HDLC_LEN];
|
|
59 /*! \brief HDLC message lengths. */
|
|
60 int hdlc_len[T38_TX_HDLC_BUFS];
|
|
61 /*! \brief HDLC message status flags. */
|
|
62 int hdlc_flags[T38_TX_HDLC_BUFS];
|
|
63 /*! \brief HDLC buffer contents. */
|
|
64 int hdlc_contents[T38_TX_HDLC_BUFS];
|
|
65 /*! \brief HDLC buffer number for input. */
|
|
66 int hdlc_in;
|
|
67 /*! \brief HDLC buffer number for output. */
|
|
68 int hdlc_out;
|
|
69
|
|
70 /*! \brief Progressively calculated CRC for HDLC messaging received from a modem. */
|
|
71 uint16_t crc;
|
|
72
|
|
73 /*! \brief non-ECM modem receive data buffer */
|
|
74 uint8_t rx_data[T38_RX_BUF_LEN];
|
|
75 int rx_data_ptr;
|
|
76
|
|
77 /*! \brief non-ECM modem transmit data buffer */
|
|
78 uint8_t non_ecm_tx_data[T38_TX_BUF_LEN];
|
|
79 int non_ecm_tx_in_ptr;
|
|
80 int non_ecm_tx_out_ptr;
|
|
81
|
|
82 /*! \brief The location of the most recent EOL marker in the non-ECM data buffer */
|
|
83 int non_ecm_tx_latest_eol_ptr;
|
|
84 unsigned int bit_stream;
|
|
85 /*! \brief The non-ECM flow control fill octet (0xFF before the first data, and 0x00
|
|
86 once data has started). */
|
|
87 uint8_t non_ecm_flow_control_fill_octet;
|
|
88 /*! \brief TRUE if we are in the initial all ones part of non-ECM transmission. */
|
|
89 int non_ecm_at_initial_all_ones;
|
|
90 /*! \brief TRUE is the end of non-ECM data indication has been received. */
|
|
91 int non_ecm_data_finished;
|
|
92 /*! \brief The current octet being sent as non-ECM data. */
|
|
93 int current_non_ecm_octet;
|
|
94 /*! \brief The current bit number in the current non-ECM octet. */
|
|
95 int non_ecm_bit_no;
|
|
96 /*! \brief A count of the number of non-ECM fill octets generated for flow control control
|
|
97 purposes. */
|
|
98 int non_ecm_flow_control_fill_octets;
|
|
99
|
|
100 int current_rx_data_type;
|
|
101 int current_rx_field_type;
|
|
102 int current_rx_field_class;
|
|
103 int in_progress_rx_indicator;
|
|
104
|
|
105 /*! \brief The current T.38 data type being sent. */
|
|
106 int current_tx_data_type;
|
|
107
|
|
108 /*! \brief TRUE if we are in error correcting (ECM) mode */
|
|
109 int ecm_mode;
|
|
110 /*! \brief The current bit rate for the fast modem. */
|
|
111 int fast_bit_rate;
|
|
112 /*! \brief The current fast modem type. */
|
|
113 int fast_modem;
|
|
114 /*! \brief Use talker echo protection when transmitting. */
|
|
115 int use_tep;
|
|
116 /*! \brief TRUE if a carrier is present. Otherwise FALSE. */
|
|
117 int rx_signal_present;
|
|
118 /*! \brief TRUE if a modem has trained correctly. */
|
|
119 int rx_trained;
|
|
120
|
|
121 /*! \brief A tone generator context used to generate supervisory tones during
|
|
122 FAX handling. */
|
|
123 tone_gen_state_t tone_gen;
|
|
124 /*! \brief An HDLC context used when receiving HDLC messages. */
|
|
125 hdlc_rx_state_t hdlcrx;
|
|
126
|
|
127 /*! \brief HDLC data used when transmitting HDLC messages. */
|
|
128 hdlc_tx_state_t hdlctx;
|
|
129
|
|
130 /*! \brief A V.21 FSK modem context used when transmitting HDLC over V.21
|
|
131 messages. */
|
|
132 fsk_tx_state_t v21tx;
|
|
133 /*! \brief A V.21 FSK modem context used when receiving HDLC over V.21
|
|
134 messages. */
|
|
135 fsk_rx_state_t v21rx;
|
|
136
|
|
137 #if defined(ENABLE_V17)
|
|
138 /*! \brief A V.17 modem context used when sending FAXes at 7200bps, 9600bps
|
|
139 12000bps or 14400bps*/
|
|
140 v17_tx_state_t v17tx;
|
|
141 /*! \brief A V.29 modem context used when receiving FAXes at 7200bps, 9600bps
|
|
142 12000bps or 14400bps*/
|
|
143 v17_rx_state_t v17rx;
|
|
144 #endif
|
|
145
|
|
146 /*! \brief A V.29 modem context used when sending FAXes at 7200bps or
|
|
147 9600bps */
|
|
148 v29_tx_state_t v29tx;
|
|
149 /*! \brief A V.29 modem context used when receiving FAXes at 7200bps or
|
|
150 9600bps */
|
|
151 v29_rx_state_t v29rx;
|
|
152
|
|
153 /*! \brief A V.27ter modem context used when sending FAXes at 2400bps or
|
|
154 4800bps */
|
|
155 v27ter_tx_state_t v27ter_tx;
|
|
156 /*! \brief A V.27ter modem context used when receiving FAXes at 2400bps or
|
|
157 4800bps */
|
|
158 v27ter_rx_state_t v27ter_rx;
|
|
159
|
|
160 /*! \brief Used to insert timed silences. */
|
|
161 silence_gen_state_t silence_gen;
|
|
162
|
|
163 /*! The current receive signal handler */
|
|
164 span_rx_handler_t *rx_handler;
|
|
165 void *rx_user_data;
|
|
166
|
|
167 /*! The current transmit signal handler */
|
|
168 span_tx_handler_t *tx_handler;
|
|
169 void *tx_user_data;
|
|
170 /*! The transmit signal handler to be used when the current one has finished sending. */
|
|
171 span_tx_handler_t *next_tx_handler;
|
|
172 void *next_tx_user_data;
|
|
173
|
|
174 /*! The number of octets to send in each image packet (non-ECM or ECM) at the current
|
|
175 rate and the current specified packet interval. */
|
|
176 int octets_per_data_packet;
|
|
177
|
|
178 int v21_rx_active;
|
|
179 int fast_rx_active;
|
|
180 int samples_since_last_tx_packet;
|
|
181 int octets_since_last_tx_packet;
|
|
182 int short_train;
|
|
183
|
|
184 /*! \brief TRUE if we need to corrupt the HDLC frame in progress, so the receiver cannot
|
|
185 interpret it. */
|
|
186 int corrupt_the_frame;
|
|
187
|
|
188 int current_rx_type;
|
|
189 int current_tx_type;
|
|
190
|
|
191 logging_state_t logging;
|
|
192 } t38_gateway_state_t;
|
|
193
|
|
194 #ifdef __cplusplus
|
|
195 extern "C" {
|
|
196 #endif
|
|
197
|
|
198 /*! \brief Initialise a gateway mode T.38 context.
|
|
199 \param s The T.38 context.
|
|
200 \param tx_packet_handler A callback routine to encapsulate and transmit T.38 packets.
|
|
201 \param tx_packet_user_data An opaque pointer passed to the tx_packet_handler routine.
|
|
202 \return A pointer to the termination mode T.38 context, or NULL if there was a problem. */
|
|
203 t38_gateway_state_t *t38_gateway_init(t38_gateway_state_t *s,
|
|
204 t38_tx_packet_handler_t *tx_packet_handler,
|
|
205 void *tx_packet_user_data);
|
|
206
|
|
207 /*! Process a block of received FAX audio samples.
|
|
208 \brief Process a block of received FAX audio samples.
|
|
209 \param s The T.38 context.
|
|
210 \param amp The audio sample buffer.
|
|
211 \param len The number of samples in the buffer.
|
|
212 \return The number of samples unprocessed. */
|
|
213 int t38_gateway_rx(t38_gateway_state_t *s, const int16_t *amp, int len);
|
|
214
|
|
215 /*! Generate a block of FAX audio samples.
|
|
216 \brief Generate a block of FAX audio samples.
|
|
217 \param s The T.38 context.
|
|
218 \param amp The audio sample buffer.
|
|
219 \param max_len The number of samples to be generated.
|
|
220 \return The number of samples actually generated.
|
|
221 */
|
|
222 int t38_gateway_tx(t38_gateway_state_t *s, int16_t *amp, int max_len);
|
|
223
|
|
224 /*! Control whether error correcting mode (ECM) is allowed.
|
|
225 \brief Control whether error correcting mode (ECM) is allowed.
|
|
226 \param s The T.38 context.
|
|
227 \param ecm_allowed TRUE is ECM is to be allowed.
|
|
228 */
|
|
229 void t38_gateway_ecm_control(t38_gateway_state_t *s, int ecm_allowed);
|
|
230
|
|
231 #ifdef __cplusplus
|
|
232 }
|
|
233 #endif
|
|
234
|
|
235 #endif
|
|
236 /*- End of file ------------------------------------------------------------*/
|