t38_gateway.h

Go to the documentation of this file.
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.27 2007/04/13 12:12:07 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 #if defined(ENABLE_V17)
00149     /*! \brief A V.17 modem context used when sending FAXes at 7200bps, 9600bps
00150                12000bps or 14400bps*/
00151     v17_tx_state_t v17tx;
00152     /*! \brief A V.29 modem context used when receiving FAXes at 7200bps, 9600bps
00153                12000bps or 14400bps*/
00154     v17_rx_state_t v17rx;
00155 #endif
00156 
00157     /*! \brief A V.29 modem context used when sending FAXes at 7200bps or
00158                9600bps */
00159     v29_tx_state_t v29tx;
00160     /*! \brief A V.29 modem context used when receiving FAXes at 7200bps or
00161                9600bps */
00162     v29_rx_state_t v29rx;
00163 
00164     /*! \brief A V.27ter modem context used when sending FAXes at 2400bps or
00165                4800bps */
00166     v27ter_tx_state_t v27ter_tx;
00167     /*! \brief A V.27ter modem context used when receiving FAXes at 2400bps or
00168                4800bps */
00169     v27ter_rx_state_t v27ter_rx;
00170 
00171     /*! \brief */
00172     dc_restore_state_t dc_restore;
00173 
00174     /*! \brief Used to insert timed silences. */
00175     silence_gen_state_t silence_gen;
00176 
00177     /*! \brief The current receive signal handler */
00178     span_rx_handler_t *rx_handler;
00179     void *rx_user_data;
00180 
00181     /*! \brief The current transmit signal handler */
00182     span_tx_handler_t *tx_handler;
00183     void *tx_user_data;
00184     /*! \brief The transmit signal handler to be used when the current one has finished sending. */
00185     span_tx_handler_t *next_tx_handler;
00186     void *next_tx_user_data;
00187 
00188     /*! \brief The number of octets to send in each image packet (non-ECM or ECM) at the current
00189                rate and the current specified packet interval. */
00190     int octets_per_data_packet;
00191 
00192     /*! \brief The type of fast receive modem currently active, which may be T38_NONE */
00193     int fast_rx_active;
00194     /*! \brief The number of samples until the next timeout event */
00195     int samples_to_timeout;
00196     /*! \brief TRUE is short training is to be used for the fast modem */
00197     int short_train;
00198 
00199     /*! \brief TRUE if we need to corrupt the HDLC frame in progress, so the receiver cannot
00200                interpret it. */
00201     int corrupt_the_frame_to_t38;
00202     /*! \brief TRUE if we need to corrupt the HDLC frame in progress, so the receiver cannot
00203                interpret it. */
00204     int corrupt_the_frame_from_t38;
00205     
00206     int current_rx_type;
00207     int current_tx_type;
00208 
00209     logging_state_t logging;
00210 } t38_gateway_state_t;
00211 
00212 #if defined(__cplusplus)
00213 extern "C"
00214 {
00215 #endif
00216 
00217 /*! \brief Initialise a gateway mode T.38 context.
00218     \param s The T.38 context.
00219     \param tx_packet_handler A callback routine to encapsulate and transmit T.38 packets.
00220     \param tx_packet_user_data An opaque pointer passed to the tx_packet_handler routine.
00221     \return A pointer to the termination mode T.38 context, or NULL if there was a problem. */
00222 t38_gateway_state_t *t38_gateway_init(t38_gateway_state_t *s,
00223                                       t38_tx_packet_handler_t *tx_packet_handler,
00224                                       void *tx_packet_user_data);
00225 
00226 /*! Process a block of received FAX audio samples.
00227     \brief Process a block of received FAX audio samples.
00228     \param s The T.38 context.
00229     \param amp The audio sample buffer.
00230     \param len The number of samples in the buffer.
00231     \return The number of samples unprocessed. */
00232 int t38_gateway_rx(t38_gateway_state_t *s, int16_t amp[], int len);
00233 
00234 /*! Generate a block of FAX audio samples.
00235     \brief Generate a block of FAX audio samples.
00236     \param s The T.38 context.
00237     \param amp The audio sample buffer.
00238     \param max_len The number of samples to be generated.
00239     \return The number of samples actually generated.
00240 */
00241 int t38_gateway_tx(t38_gateway_state_t *s, int16_t amp[], int max_len);
00242 
00243 /*! Control whether error correcting mode (ECM) is allowed.
00244     \brief Control whether error correcting mode (ECM) is allowed.
00245     \param s The T.38 context.
00246     \param ecm_allowed TRUE is ECM is to be allowed.
00247 */
00248 void t38_gateway_set_ecm_capability(t38_gateway_state_t *s, int ecm_allowed);
00249 
00250 void t38_gateway_set_transmit_on_idle(t38_gateway_state_t *s, int transmit_on_idle);
00251 
00252 void t38_gateway_set_supported_modems(t38_gateway_state_t *s, int supported_modems);
00253 
00254 void t38_gateway_set_nsx_suppression(t38_gateway_state_t *s, int suppress_nsx);
00255 
00256 #if defined(__cplusplus)
00257 }
00258 #endif
00259 
00260 #endif
00261 /*- End of file ------------------------------------------------------------*/

Generated on Mon May 14 04:36:39 2007 for libspandsp by  doxygen 1.5.1