5
|
1 /*
|
|
2 * SpanDSP - a series of DSP components for telephony
|
|
3 *
|
|
4 * t31.h - A T.31 compatible class 1 FAX modem interface.
|
|
5 *
|
|
6 * Written by Steve Underwood <steveu@coppice.org>
|
|
7 *
|
|
8 * Copyright (C) 2004 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: t31.h,v 1.37 2006/10/24 13:45:28 steveu Exp $
|
|
26 */
|
|
27
|
|
28 /*! \file */
|
|
29
|
|
30 #if !defined(_T31_H_)
|
|
31 #define _T31_H_
|
|
32
|
|
33 /*! \page t31_page T.31 Class 1 FAX modem protocol handling
|
|
34 \section t31_page_sec_1 What does it do?
|
|
35 The T.31 class 1 FAX modem modules implements a class 1 interface to the FAX
|
|
36 modems in spandsp.
|
|
37
|
|
38 \section t31_page_sec_2 How does it work?
|
|
39 */
|
|
40
|
|
41 typedef struct t31_state_s t31_state_t;
|
|
42
|
|
43 typedef int (t31_modem_control_handler_t)(t31_state_t *s, void *user_data, int op, const char *num);
|
|
44
|
|
45 #define T31_TX_BUF_LEN (4096*32)
|
|
46 #define T31_TX_BUF_HIGH_TIDE (4096*32 - 1024)
|
|
47 #define T31_TX_BUF_LOW_TIDE (1024)
|
|
48
|
|
49 /*!
|
|
50 T.31 descriptor. This defines the working state for a single instance of
|
|
51 a T.31 FAX modem.
|
|
52 */
|
|
53 struct t31_state_s
|
|
54 {
|
|
55 at_state_t at_state;
|
|
56 t31_modem_control_handler_t *modem_control_handler;
|
|
57 void *modem_control_user_data;
|
|
58
|
|
59 /*! The current receive signal handler */
|
|
60 span_rx_handler_t *rx_handler;
|
|
61 void *rx_user_data;
|
|
62
|
|
63 /*! The current transmit signal handler */
|
|
64 span_tx_handler_t *tx_handler;
|
|
65 void *tx_user_data;
|
|
66 /*! The transmit signal handler to be used when the current one has finished sending. */
|
|
67 span_tx_handler_t *next_tx_handler;
|
|
68 void *next_tx_user_data;
|
|
69
|
|
70 /*! If TRUE, transmit silence when there is nothing else to transmit. If FALSE return only
|
|
71 the actual generated audio. Note that this only affects untimed silences. Timed silences
|
|
72 (e.g. the 75ms silence between V.21 and a high speed modem) will alway be transmitted as
|
|
73 silent audio. */
|
|
74 int transmit_on_idle;
|
|
75
|
|
76 uint8_t hdlc_tx_buf[256];
|
|
77 int hdlc_tx_len;
|
|
78 int hdlc_tx_ptr;
|
|
79 /*! TRUE if DLE prefix just used */
|
|
80 int dled;
|
|
81 uint8_t tx_data[T31_TX_BUF_LEN];
|
|
82 /*! \brief The number of bytes stored in transmit buffer. */
|
|
83 int tx_in_bytes;
|
|
84 /*! \brief The number of bytes sent from the transmit buffer. */
|
|
85 int tx_out_bytes;
|
|
86 int tx_holding;
|
|
87 int tx_data_started;
|
|
88 int bit_no;
|
|
89 int current_byte;
|
|
90
|
|
91 /*! \brief The current bit rate for the FAX fast message transfer modem. */
|
|
92 int bit_rate;
|
|
93 int rx_message_received;
|
|
94
|
|
95 /*! \brief A tone generator context used to generate supervisory tones during
|
|
96 FAX handling. */
|
|
97 tone_gen_state_t tone_gen;
|
|
98 /*! \brief An HDLC context used when receiving HDLC over V.21 messages. */
|
|
99 hdlc_rx_state_t hdlcrx;
|
|
100 /*! \brief An HDLC context used when transmitting HDLC over V.21 messages. */
|
|
101 hdlc_tx_state_t hdlctx;
|
|
102 /*! \brief A V.21 FSK modem context used when transmitting HDLC over V.21
|
|
103 messages. */
|
|
104 fsk_tx_state_t v21tx;
|
|
105 /*! \brief A V.21 FSK modem context used when receiving HDLC over V.21
|
|
106 messages. */
|
|
107 fsk_rx_state_t v21rx;
|
|
108
|
|
109 #if defined(ENABLE_V17)
|
|
110 /*! \brief A V.17 modem context used when sending FAXes at 7200bps, 9600bps
|
|
111 12000bps or 14400bps*/
|
|
112 v17_tx_state_t v17tx;
|
|
113 /*! \brief A V.29 modem context used when receiving FAXes at 7200bps, 9600bps
|
|
114 12000bps or 14400bps*/
|
|
115 v17_rx_state_t v17rx;
|
|
116 #endif
|
|
117
|
|
118 /*! \brief A V.29 modem context used when sending FAXes at 7200bps or
|
|
119 9600bps */
|
|
120 v29_tx_state_t v29tx;
|
|
121 /*! \brief A V.29 modem context used when receiving FAXes at 7200bps or
|
|
122 9600bps */
|
|
123 v29_rx_state_t v29rx;
|
|
124
|
|
125 /*! \brief A V.27ter modem context used when sending FAXes at 2400bps or
|
|
126 4800bps */
|
|
127 v27ter_tx_state_t v27ter_tx;
|
|
128 /*! \brief A V.27ter modem context used when receiving FAXes at 2400bps or
|
|
129 4800bps */
|
|
130 v27ter_rx_state_t v27ter_rx;
|
|
131
|
|
132 /*! \brief Used to insert timed silences. */
|
|
133 silence_gen_state_t silence_gen;
|
|
134
|
|
135 /*! \brief Rx power meter, use to detect silence */
|
|
136 power_meter_t rx_power;
|
|
137 int16_t last_sample;
|
|
138 int32_t silence_threshold_power;
|
|
139
|
|
140 t38_core_state_t t38;
|
|
141
|
|
142 /*! \brief Samples of silence heard */
|
|
143 int silence_heard;
|
|
144 /*! \brief Samples of silence awaited */
|
|
145 int silence_awaited;
|
|
146 /*! \brief Samples elapsed in the current call */
|
|
147 int64_t call_samples;
|
|
148 int64_t dte_data_timeout;
|
|
149 int modem;
|
|
150 int short_train;
|
|
151 int hdlc_final;
|
|
152 int data_final;
|
|
153 queue_t rx_queue;
|
|
154
|
|
155 uint8_t hdlc_rx_buf[256];
|
|
156 int hdlc_rx_len;
|
|
157
|
|
158 int t38_mode;
|
|
159 int timed_step;
|
|
160 int current_tx_data;
|
|
161 int64_t next_send_samples;
|
|
162 int next_tx_indicator;
|
|
163
|
|
164 int current_rx_type;
|
|
165 int current_tx_type;
|
|
166
|
|
167 /*! \brief TRUE is there has been some T.38 data missed */
|
|
168 int missing_data;
|
|
169
|
|
170 int octets_per_non_ecm_packet;
|
|
171
|
|
172 /*! \brief Error and flow logging control */
|
|
173 logging_state_t logging;
|
|
174 };
|
|
175
|
|
176 #ifdef __cplusplus
|
|
177 extern "C" {
|
|
178 #endif
|
|
179
|
|
180 void t31_call_event(t31_state_t *s, int event);
|
|
181
|
|
182 int t31_at_rx(t31_state_t *s, const char *t, int len);
|
|
183
|
|
184 /*! Process a block of received T.31 modem audio samples.
|
|
185 \brief Process a block of received T.31 modem audio samples.
|
|
186 \param s The T.31 modem context.
|
|
187 \param amp The audio sample buffer.
|
|
188 \param len The number of samples in the buffer.
|
|
189 \return The number of samples unprocessed. */
|
|
190 int t31_rx(t31_state_t *s, int16_t amp[], int len);
|
|
191
|
|
192 /*! Generate a block of T.31 modem audio samples.
|
|
193 \brief Generate a block of T.31 modem audio samples.
|
|
194 \param s The T.31 modem context.
|
|
195 \param amp The audio sample buffer.
|
|
196 \param max_len The number of samples to be generated.
|
|
197 \return The number of samples actually generated.
|
|
198 */
|
|
199 int t31_tx(t31_state_t *s, int16_t amp[], int max_len);
|
|
200
|
|
201 int t31_t38_send_timeout(t31_state_t *s, int samples);
|
|
202
|
|
203 /*! Select whether silent audio will be sent when transmit is idle.
|
|
204 \brief Select whether silent audio will be sent when transmit is idle.
|
|
205 \param s The T.31 modem context.
|
|
206 \param transmit_on_idle TRUE if silent audio should be output when the transmitter is
|
|
207 idle. FALSE to transmit zero length audio when the transmitter is idle. The default
|
|
208 behaviour is FALSE.
|
|
209 */
|
|
210 void t31_set_transmit_on_idle(t31_state_t *s, int transmit_on_idle);
|
|
211
|
|
212 /*! Initialise a T.31 context. This must be called before the first
|
|
213 use of the context, to initialise its contents.
|
|
214 \brief Initialise a T.31 context.
|
|
215 \param s The T.31 context.
|
|
216 \param at_tx_handler A callback routine to handle AT interpreter channel output.
|
|
217 \param at_tx_user_data An opaque pointer passed in called to at_tx_handler.
|
|
218 \param modem_control_handler A callback routine to handle control of the modem (off-hook, etc).
|
|
219 \param modem_control_user_data An opaque pointer passed in called to modem_control_handler.
|
|
220 \param tx_t38_packet_handler ???
|
|
221 \param tx_t38_packet_user_data ???
|
|
222 \return A pointer to the T.31 context. */
|
|
223 t31_state_t *t31_init(t31_state_t *s,
|
|
224 at_tx_handler_t *at_tx_handler,
|
|
225 void *at_tx_user_data,
|
|
226 t31_modem_control_handler_t *modem_control_handler,
|
|
227 void *modem_control_user_data,
|
|
228 t38_tx_packet_handler_t *tx_t38_packet_handler,
|
|
229 void *tx_t38_packet_user_data);
|
|
230
|
|
231 /*! Release a T.31 context.
|
|
232 \brief Release a T.31 context.
|
|
233 \param s The T.31 context.
|
|
234 \return 0 for OK */
|
|
235 int t31_release(t31_state_t *s);
|
|
236
|
|
237 #ifdef __cplusplus
|
|
238 }
|
|
239 #endif
|
|
240
|
|
241 #endif
|
|
242 /*- End of file ------------------------------------------------------------*/
|