00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * t38_gateway.h - A T.38, less the packet exchange part 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2005, 2006, 2007 Steve Underwood 00009 * 00010 * All rights reserved. 00011 * 00012 * This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU General Public License version 2, as 00014 * published by the Free Software Foundation. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU General Public License 00022 * along with this program; if not, write to the Free Software 00023 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00024 * 00025 * $Id: t38_gateway.h,v 1.36 2007/11/30 12:20:35 steveu Exp $ 00026 */ 00027 00028 /*! \file */ 00029 00030 #if !defined(_SPANDSP_T38_GATEWAY_H_) 00031 #define _SPANDSP_T38_GATEWAY_H_ 00032 00033 /*! \page t38_gateway_page T.38 real time FAX over IP PSTN gateway 00034 \section t38_gateway_page_sec_1 What does it do? 00035 00036 The T.38 gateway facility provides a robust interface between T.38 IP packet streams and 00037 and 8k samples/second audio streams. It provides the buffering and flow control features needed 00038 to maximum the tolerance of jitter and packet loss on the IP network. 00039 00040 \section t38_gateway_page_sec_2 How does it work? 00041 */ 00042 00043 #define T38_RX_BUF_LEN 2048 00044 #define T38_NON_ECM_TX_BUF_LEN 16384 00045 #define T38_TX_HDLC_BUFS 256 00046 /* Make sure the HDLC frame buffers are big enough for ECM frames. */ 00047 #define T38_MAX_HDLC_LEN 260 00048 00049 typedef struct 00050 { 00051 t38_core_state_t t38; 00052 00053 /*! \brief TRUE if ECM FAX mode is allowed through the gateway. */ 00054 int ecm_allowed; 00055 /*! \brief Use talker echo protection when transmitting. */ 00056 int use_tep; 00057 00058 /*! \brief If TRUE, transmit silence when there is nothing else to transmit. If FALSE return only 00059 the actual generated audio. Note that this only affects untimed silences. Timed silences 00060 (e.g. the 75ms silence between V.21 and a high speed modem) will alway be transmitted as 00061 silent audio. */ 00062 int transmit_on_idle; 00063 00064 int supported_modems; 00065 00066 int suppress_nsx; 00067 00068 /*! \brief HDLC message buffers. */ 00069 uint8_t hdlc_buf[T38_TX_HDLC_BUFS][T38_MAX_HDLC_LEN]; 00070 /*! \brief HDLC message lengths. */ 00071 int hdlc_len[T38_TX_HDLC_BUFS]; 00072 /*! \brief HDLC message status flags. */ 00073 int hdlc_flags[T38_TX_HDLC_BUFS]; 00074 /*! \brief HDLC buffer contents. */ 00075 int hdlc_contents[T38_TX_HDLC_BUFS]; 00076 /*! \brief HDLC buffer number for input. */ 00077 int hdlc_in; 00078 /*! \brief HDLC buffer number for output. */ 00079 int hdlc_out; 00080 00081 /*! \brief Progressively calculated CRC for HDLC messaging received from a modem. */ 00082 uint16_t crc; 00083 00084 /*! \brief non-ECM and HDLC modem receive data buffer */ 00085 uint8_t rx_data[T38_RX_BUF_LEN]; 00086 int rx_data_ptr; 00087 00088 /*! \brief non-ECM modem transmit data buffer */ 00089 uint8_t non_ecm_tx_data[T38_NON_ECM_TX_BUF_LEN]; 00090 int non_ecm_tx_in_ptr; 00091 int non_ecm_tx_out_ptr; 00092 00093 /*! \brief The location of the most recent EOL marker in the non-ECM data buffer */ 00094 int non_ecm_tx_latest_eol_ptr; 00095 unsigned int non_ecm_bit_stream; 00096 /*! \brief The non-ECM flow control fill octet (0xFF before the first data, and 0x00 00097 once data has started). */ 00098 uint8_t non_ecm_flow_control_fill_octet; 00099 /*! \brief TRUE if we are in the initial all ones part of non-ECM transmission. */ 00100 int non_ecm_at_initial_all_ones; 00101 /*! \brief TRUE is the end of non-ECM data indication has been received. */ 00102 int non_ecm_data_finished; 00103 /*! \brief The current octet being sent as non-ECM data. */ 00104 unsigned int non_ecm_rx_bit_stream; 00105 unsigned int non_ecm_tx_octet; 00106 /*! \brief The current bit number in the current non-ECM octet. */ 00107 int non_ecm_bit_no; 00108 int non_ecm_in_octets; 00109 int non_ecm_out_octets; 00110 int non_ecm_in_rows; 00111 int non_ecm_out_rows; 00112 /*! \brief A count of the number of non-ECM fill octets generated for flow control control 00113 purposes. */ 00114 int non_ecm_flow_control_fill_octets; 00115 00116 /*! \brief the current class of field being received - i.e. none, non-ECM or HDLC */ 00117 int current_rx_field_class; 00118 /*! \brief The T.38 indicator currently in use */ 00119 int in_progress_rx_indicator; 00120 00121 /*! \brief The current T.38 data type being sent. */ 00122 int current_tx_data_type; 00123 00124 /*! \brief TRUE if we are in error correcting (ECM) mode */ 00125 int ecm_mode; 00126 /*! \brief The current bit rate for the fast modem. */ 00127 int fast_bit_rate; 00128 /*! \brief The current fast modem type. */ 00129 int fast_modem; 00130 /*! \brief TRUE if between DCS and TCF */ 00131 int tcf_in_progress; 00132 /*! \brief TRUE if a carrier is present. Otherwise FALSE. */ 00133 int rx_signal_present; 00134 /*! \brief TRUE if a modem has trained correctly. */ 00135 int rx_trained; 00136 00137 /*! \brief A tone generator context used to generate supervisory tones during 00138 FAX handling. */ 00139 tone_gen_state_t tone_gen; 00140 /*! \brief An HDLC context used when receiving HDLC messages. */ 00141 hdlc_rx_state_t hdlcrx; 00142 00143 /*! \brief HDLC data used when transmitting HDLC messages. */ 00144 hdlc_tx_state_t hdlctx; 00145 00146 /*! \brief A V.21 FSK modem context used when transmitting HDLC over V.21 00147 messages. */ 00148 fsk_tx_state_t v21tx; 00149 /*! \brief A V.21 FSK modem context used when receiving HDLC over V.21 00150 messages. */ 00151 fsk_rx_state_t v21rx; 00152 00153 /*! \brief A V.17 modem context used when sending FAXes at 7200bps, 9600bps 00154 12000bps or 14400bps*/ 00155 v17_tx_state_t v17tx; 00156 /*! \brief A V.29 modem context used when receiving FAXes at 7200bps, 9600bps 00157 12000bps or 14400bps*/ 00158 v17_rx_state_t v17rx; 00159 00160 /*! \brief A V.29 modem context used when sending FAXes at 7200bps or 00161 9600bps */ 00162 v29_tx_state_t v29tx; 00163 /*! \brief A V.29 modem context used when receiving FAXes at 7200bps or 00164 9600bps */ 00165 v29_rx_state_t v29rx; 00166 00167 /*! \brief A V.27ter modem context used when sending FAXes at 2400bps or 00168 4800bps */ 00169 v27ter_tx_state_t v27ter_tx; 00170 /*! \brief A V.27ter modem context used when receiving FAXes at 2400bps or 00171 4800bps */ 00172 v27ter_rx_state_t v27ter_rx; 00173 00174 /*! \brief */ 00175 dc_restore_state_t dc_restore; 00176 00177 /*! \brief Used to insert timed silences. */ 00178 silence_gen_state_t silence_gen; 00179 00180 /*! \brief The current receive signal handler */ 00181 span_rx_handler_t *rx_handler; 00182 void *rx_user_data; 00183 00184 /*! \brief The current transmit signal handler */ 00185 span_tx_handler_t *tx_handler; 00186 void *tx_user_data; 00187 /*! \brief The transmit signal handler to be used when the current one has finished sending. */ 00188 span_tx_handler_t *next_tx_handler; 00189 void *next_tx_user_data; 00190 00191 /*! \brief The number of octets to send in each image packet (non-ECM or ECM) at the current 00192 rate and the current specified packet interval. */ 00193 int octets_per_data_packet; 00194 00195 /*! \brief The type of fast receive modem currently active, which may be T38_NONE */ 00196 int fast_rx_active; 00197 /*! \brief The number of samples until the next timeout event */ 00198 int samples_to_timeout; 00199 /*! \brief TRUE if in image data mode (as opposed to TCF mode). */ 00200 int image_data_mode; 00201 /*! \brief TRUE if in image data modem is to use short training. */ 00202 int short_train; 00203 00204 /*! \brief TRUE if we need to corrupt the HDLC frame in progress, so the receiver cannot 00205 interpret it. */ 00206 int corrupt_the_frame_to_t38; 00207 /*! \brief TRUE if we need to corrupt the HDLC frame in progress, so the receiver cannot 00208 interpret it. */ 00209 int corrupt_the_frame_from_t38; 00210 00211 /*! \brief The currently select receiver type */ 00212 int current_rx_type; 00213 /*! \brief The currently select transmitter type */ 00214 int current_tx_type; 00215 00216 /*! \brief Audio logging file handles */ 00217 int fax_audio_rx_log; 00218 int fax_audio_tx_log; 00219 /*! \brief Error and flow logging control */ 00220 logging_state_t logging; 00221 } t38_gateway_state_t; 00222 00223 #if defined(__cplusplus) 00224 extern "C" 00225 { 00226 #endif 00227 00228 /*! \brief Initialise a gateway mode T.38 context. 00229 \param s The T.38 context. 00230 \param tx_packet_handler A callback routine to encapsulate and transmit T.38 packets. 00231 \param tx_packet_user_data An opaque pointer passed to the tx_packet_handler routine. 00232 \return A pointer to the termination mode T.38 context, or NULL if there was a problem. */ 00233 t38_gateway_state_t *t38_gateway_init(t38_gateway_state_t *s, 00234 t38_tx_packet_handler_t *tx_packet_handler, 00235 void *tx_packet_user_data); 00236 00237 /*! Free a gateway mode T.38 context. 00238 \brief Free a T.38 context. 00239 \param s The T.38 context. 00240 \return 0 for OK, else -1. */ 00241 int t38_gateway_free(t38_gateway_state_t *s); 00242 00243 /*! Process a block of received FAX audio samples. 00244 \brief Process a block of received FAX audio samples. 00245 \param s The T.38 context. 00246 \param amp The audio sample buffer. 00247 \param len The number of samples in the buffer. 00248 \return The number of samples unprocessed. */ 00249 int t38_gateway_rx(t38_gateway_state_t *s, int16_t amp[], int len); 00250 00251 /*! Generate a block of FAX audio samples. 00252 \brief Generate a block of FAX audio samples. 00253 \param s The T.38 context. 00254 \param amp The audio sample buffer. 00255 \param max_len The number of samples to be generated. 00256 \return The number of samples actually generated. 00257 */ 00258 int t38_gateway_tx(t38_gateway_state_t *s, int16_t amp[], int max_len); 00259 00260 /*! Control whether error correcting mode (ECM) is allowed. 00261 \brief Control whether error correcting mode (ECM) is allowed. 00262 \param s The T.38 context. 00263 \param ecm_allowed TRUE is ECM is to be allowed. 00264 */ 00265 void t38_gateway_set_ecm_capability(t38_gateway_state_t *s, int ecm_allowed); 00266 00267 /*! Select whether silent audio will be sent when transmit is idle. 00268 \brief Select whether silent audio will be sent when transmit is idle. 00269 \param s The T.38 context. 00270 \param transmit_on_idle TRUE if silent audio should be output when the FAX transmitter is 00271 idle. FALSE to transmit zero length audio when the FAX transmitter is idle. The default 00272 behaviour is FALSE. 00273 */ 00274 void t38_gateway_set_transmit_on_idle(t38_gateway_state_t *s, int transmit_on_idle); 00275 00276 /*! Specify which modem types are supported by a T.30 context. 00277 \brief Specify supported modems. 00278 \param s The T.38 context. 00279 \param supported_modems Bit field list of the supported modems. 00280 */ 00281 void t38_gateway_set_supported_modems(t38_gateway_state_t *s, int supported_modems); 00282 00283 /*! Select whether NSC, NSF, and NSS should be suppressed. It selected, the contents of 00284 these messages are forced to zero for all octets beyond the message type. This makes 00285 them look like manufacturer specific messages, from a manufacturer which does not exist. 00286 \brief Select whether NSC, NSF, and NSS should be suppressed. 00287 \param s The T.38 context. 00288 \param suppress_nsx TRUE if NSC, NSF, and NSS should be suppressed. 00289 */ 00290 void t38_gateway_set_nsx_suppression(t38_gateway_state_t *s, int suppress_nsx); 00291 00292 /*! Select whether talker echo protection tone will be sent for the image modems. 00293 \brief Select whether TEP will be sent for the image modems. 00294 \param s The T.38 context. 00295 \param use_tep TRUE if TEP should be sent. 00296 */ 00297 void t38_gateway_set_tep_mode(t38_gateway_state_t *s, int use_tep); 00298 00299 #if defined(__cplusplus) 00300 } 00301 #endif 00302 00303 #endif 00304 /*- End of file ------------------------------------------------------------*/