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.29 2007/10/18 15:08:06 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 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     int current_non_ecm_octet;
00105     /*! \brief The current bit number in the current non-ECM octet. */
00106     int non_ecm_bit_no;
00107     /*! \brief A count of the number of non-ECM fill octets generated for flow control control
00108                purposes. */
00109     int non_ecm_flow_control_fill_octets;
00110 
00111     /*! \brief the current class of field being received - i.e. none, non-ECM or HDLC */
00112     int current_rx_field_class;
00113     /*! \brief The T.38 indicator currently in use */
00114     int in_progress_rx_indicator;
00115 
00116     /*! \brief The current T.38 data type being sent. */
00117     int current_tx_data_type;
00118 
00119     /*! \brief TRUE if we are in error correcting (ECM) mode */
00120     int ecm_mode;
00121     /*! \brief The current bit rate for the fast modem. */
00122     int fast_bit_rate;
00123     /*! \brief The current fast modem type. */
00124     int fast_modem;
00125     /*! \brief TRUE if between DCS and TCF */
00126     int tcf_in_progress;
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 /*! Select whether silent audio will be sent when transmit is idle.
00249     \brief Select whether silent audio will be sent when transmit is idle.
00250     \param s The T.38 context.
00251     \param transmit_on_idle TRUE if silent audio should be output when the FAX transmitter is
00252            idle. FALSE to transmit zero length audio when the FAX transmitter is idle. The default
00253            behaviour is FALSE.
00254 */
00255 void t38_gateway_set_transmit_on_idle(t38_gateway_state_t *s, int transmit_on_idle);
00256 
00257 /*! Specify which modem types are supported by a T.30 context.
00258     \brief Specify supported modems.
00259     \param s The T.38 context.
00260     \param supported_modems Bit field list of the supported modems.
00261 */
00262 void t38_gateway_set_supported_modems(t38_gateway_state_t *s, int supported_modems);
00263 
00264 /*! Select whether NSC, NSF, and NSS should be suppressed. It selected, the contents of
00265     these messages are forced to zero for all octets beyond the message type. This makes
00266     them look like manufacturer specific messages, from a manufacturer which does not exist.
00267     \brief Select whether NSC, NSF, and NSS should be suppressed.
00268     \param s The T.38 context.
00269     \param suppress_nsx TRUE if NSC, NSF, and NSS should be suppressed.
00270 */
00271 void t38_gateway_set_nsx_suppression(t38_gateway_state_t *s, int suppress_nsx);
00272 
00273 /*! Select whether talker echo protection tone will be sent for the image modems.
00274     \brief Select whether TEP will be sent for the image modems.
00275     \param s The T.38 context.
00276     \param use_tep TRUE if TEP should be sent.
00277 */
00278 void t38_gateway_set_tep_mode(t38_gateway_state_t *s, int use_tep);
00279 
00280 #if defined(__cplusplus)
00281 }
00282 #endif
00283 
00284 #endif
00285 /*- End of file ------------------------------------------------------------*/

Generated on Sat Nov 3 00:56:51 2007 for libspandsp by  doxygen 1.5.2