00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * t38_gateway.h - An implementation of T.38, less the packet exchange part 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2005 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.28 2007/05/15 13:22:43 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 /*! TRUE if ECM FAX mode is allowed through the gateway. */ 00054 int ecm_allowed; 00055 00056 /*! If TRUE, transmit silence when there is nothing else to transmit. If FALSE return only 00057 the actual generated audio. Note that this only affects untimed silences. Timed silences 00058 (e.g. the 75ms silence between V.21 and a high speed modem) will alway be transmitted as 00059 silent audio. */ 00060 int transmit_on_idle; 00061 00062 int supported_modems; 00063 00064 int suppress_nsx; 00065 00066 /*! \brief HDLC message buffers. */ 00067 uint8_t hdlc_buf[T38_TX_HDLC_BUFS][T38_MAX_HDLC_LEN]; 00068 /*! \brief HDLC message lengths. */ 00069 int hdlc_len[T38_TX_HDLC_BUFS]; 00070 /*! \brief HDLC message status flags. */ 00071 int hdlc_flags[T38_TX_HDLC_BUFS]; 00072 /*! \brief HDLC buffer contents. */ 00073 int hdlc_contents[T38_TX_HDLC_BUFS]; 00074 /*! \brief HDLC buffer number for input. */ 00075 int hdlc_in; 00076 /*! \brief HDLC buffer number for output. */ 00077 int hdlc_out; 00078 00079 /*! \brief Progressively calculated CRC for HDLC messaging received from a modem. */ 00080 uint16_t crc; 00081 00082 /*! \brief non-ECM and HDLC modem receive data buffer */ 00083 uint8_t rx_data[T38_RX_BUF_LEN]; 00084 int rx_data_ptr; 00085 00086 /*! \brief non-ECM modem transmit data buffer */ 00087 uint8_t non_ecm_tx_data[T38_NON_ECM_TX_BUF_LEN]; 00088 int non_ecm_tx_in_ptr; 00089 int non_ecm_tx_out_ptr; 00090 00091 /*! \brief The location of the most recent EOL marker in the non-ECM data buffer */ 00092 int non_ecm_tx_latest_eol_ptr; 00093 unsigned int bit_stream; 00094 /*! \brief The non-ECM flow control fill octet (0xFF before the first data, and 0x00 00095 once data has started). */ 00096 uint8_t non_ecm_flow_control_fill_octet; 00097 /*! \brief TRUE if we are in the initial all ones part of non-ECM transmission. */ 00098 int non_ecm_at_initial_all_ones; 00099 /*! \brief TRUE is the end of non-ECM data indication has been received. */ 00100 int non_ecm_data_finished; 00101 /*! \brief The current octet being sent as non-ECM data. */ 00102 int current_non_ecm_octet; 00103 /*! \brief The current bit number in the current non-ECM octet. */ 00104 int non_ecm_bit_no; 00105 /*! \brief A count of the number of non-ECM fill octets generated for flow control control 00106 purposes. */ 00107 int non_ecm_flow_control_fill_octets; 00108 00109 /*! \brief the current class of field being received - i.e. none, non-ECM or HDLC */ 00110 int current_rx_field_class; 00111 /*! \brief The T.38 indicator currently in use */ 00112 int in_progress_rx_indicator; 00113 00114 /*! \brief The current T.38 data type being sent. */ 00115 int current_tx_data_type; 00116 00117 /*! \brief TRUE if we are in error correcting (ECM) mode */ 00118 int ecm_mode; 00119 /*! \brief The current bit rate for the fast modem. */ 00120 int fast_bit_rate; 00121 /*! \brief The current fast modem type. */ 00122 int fast_modem; 00123 /*! \brief TRUE if between DCS and TCF */ 00124 int tcf_in_progress; 00125 /*! \brief Use talker echo protection when transmitting. */ 00126 int use_tep; 00127 /*! \brief TRUE if a carrier is present. Otherwise FALSE. */ 00128 int rx_signal_present; 00129 /*! \brief TRUE if a modem has trained correctly. */ 00130 int rx_trained; 00131 00132 /*! \brief A tone generator context used to generate supervisory tones during 00133 FAX handling. */ 00134 tone_gen_state_t tone_gen; 00135 /*! \brief An HDLC context used when receiving HDLC messages. */ 00136 hdlc_rx_state_t hdlcrx; 00137 00138 /*! \brief HDLC data used when transmitting HDLC messages. */ 00139 hdlc_tx_state_t hdlctx; 00140 00141 /*! \brief A V.21 FSK modem context used when transmitting HDLC over V.21 00142 messages. */ 00143 fsk_tx_state_t v21tx; 00144 /*! \brief A V.21 FSK modem context used when receiving HDLC over V.21 00145 messages. */ 00146 fsk_rx_state_t v21rx; 00147 00148 /*! \brief A V.17 modem context used when sending FAXes at 7200bps, 9600bps 00149 12000bps or 14400bps*/ 00150 v17_tx_state_t v17tx; 00151 /*! \brief A V.29 modem context used when receiving FAXes at 7200bps, 9600bps 00152 12000bps or 14400bps*/ 00153 v17_rx_state_t v17rx; 00154 00155 /*! \brief A V.29 modem context used when sending FAXes at 7200bps or 00156 9600bps */ 00157 v29_tx_state_t v29tx; 00158 /*! \brief A V.29 modem context used when receiving FAXes at 7200bps or 00159 9600bps */ 00160 v29_rx_state_t v29rx; 00161 00162 /*! \brief A V.27ter modem context used when sending FAXes at 2400bps or 00163 4800bps */ 00164 v27ter_tx_state_t v27ter_tx; 00165 /*! \brief A V.27ter modem context used when receiving FAXes at 2400bps or 00166 4800bps */ 00167 v27ter_rx_state_t v27ter_rx; 00168 00169 /*! \brief */ 00170 dc_restore_state_t dc_restore; 00171 00172 /*! \brief Used to insert timed silences. */ 00173 silence_gen_state_t silence_gen; 00174 00175 /*! \brief The current receive signal handler */ 00176 span_rx_handler_t *rx_handler; 00177 void *rx_user_data; 00178 00179 /*! \brief The current transmit signal handler */ 00180 span_tx_handler_t *tx_handler; 00181 void *tx_user_data; 00182 /*! \brief The transmit signal handler to be used when the current one has finished sending. */ 00183 span_tx_handler_t *next_tx_handler; 00184 void *next_tx_user_data; 00185 00186 /*! \brief The number of octets to send in each image packet (non-ECM or ECM) at the current 00187 rate and the current specified packet interval. */ 00188 int octets_per_data_packet; 00189 00190 /*! \brief The type of fast receive modem currently active, which may be T38_NONE */ 00191 int fast_rx_active; 00192 /*! \brief The number of samples until the next timeout event */ 00193 int samples_to_timeout; 00194 /*! \brief TRUE is short training is to be used for the fast modem */ 00195 int short_train; 00196 00197 /*! \brief TRUE if we need to corrupt the HDLC frame in progress, so the receiver cannot 00198 interpret it. */ 00199 int corrupt_the_frame_to_t38; 00200 /*! \brief TRUE if we need to corrupt the HDLC frame in progress, so the receiver cannot 00201 interpret it. */ 00202 int corrupt_the_frame_from_t38; 00203 00204 int current_rx_type; 00205 int current_tx_type; 00206 00207 logging_state_t logging; 00208 } t38_gateway_state_t; 00209 00210 #if defined(__cplusplus) 00211 extern "C" 00212 { 00213 #endif 00214 00215 /*! \brief Initialise a gateway mode T.38 context. 00216 \param s The T.38 context. 00217 \param tx_packet_handler A callback routine to encapsulate and transmit T.38 packets. 00218 \param tx_packet_user_data An opaque pointer passed to the tx_packet_handler routine. 00219 \return A pointer to the termination mode T.38 context, or NULL if there was a problem. */ 00220 t38_gateway_state_t *t38_gateway_init(t38_gateway_state_t *s, 00221 t38_tx_packet_handler_t *tx_packet_handler, 00222 void *tx_packet_user_data); 00223 00224 /*! Process a block of received FAX audio samples. 00225 \brief Process a block of received FAX audio samples. 00226 \param s The T.38 context. 00227 \param amp The audio sample buffer. 00228 \param len The number of samples in the buffer. 00229 \return The number of samples unprocessed. */ 00230 int t38_gateway_rx(t38_gateway_state_t *s, int16_t amp[], int len); 00231 00232 /*! Generate a block of FAX audio samples. 00233 \brief Generate a block of FAX audio samples. 00234 \param s The T.38 context. 00235 \param amp The audio sample buffer. 00236 \param max_len The number of samples to be generated. 00237 \return The number of samples actually generated. 00238 */ 00239 int t38_gateway_tx(t38_gateway_state_t *s, int16_t amp[], int max_len); 00240 00241 /*! Control whether error correcting mode (ECM) is allowed. 00242 \brief Control whether error correcting mode (ECM) is allowed. 00243 \param s The T.38 context. 00244 \param ecm_allowed TRUE is ECM is to be allowed. 00245 */ 00246 void t38_gateway_set_ecm_capability(t38_gateway_state_t *s, int ecm_allowed); 00247 00248 void t38_gateway_set_transmit_on_idle(t38_gateway_state_t *s, int transmit_on_idle); 00249 00250 void t38_gateway_set_supported_modems(t38_gateway_state_t *s, int supported_modems); 00251 00252 void t38_gateway_set_nsx_suppression(t38_gateway_state_t *s, int suppress_nsx); 00253 00254 #if defined(__cplusplus) 00255 } 00256 #endif 00257 00258 #endif 00259 /*- End of file ------------------------------------------------------------*/