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 - 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 Lesser General Public License version 2.1,
00014  * as 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 Lesser General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Lesser General Public
00022  * License 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.45 2008/05/08 12:21:09 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 /*!
00050     T.38 gateway state.
00051 */
00052 typedef struct
00053 {
00054     /*! Core T.38 support */
00055     t38_core_state_t t38;
00056 
00057     /*! \brief A bit mask of the currently supported modem types. */
00058     int supported_modems;
00059     /*! \brief Use talker echo protection when transmitting. */
00060     int use_tep;    
00061     /*! \brief TRUE if ECM FAX mode is allowed through the gateway. */
00062     int ecm_allowed;
00063     /*! \brief TRUE if the NSF, NSC, and NSS are to be suppressed by altering
00064                their contents to something the far end will not recognise. */
00065     int suppress_nsx;
00066 
00067     /*! \brief If TRUE, transmit silence when there is nothing else to transmit. If FALSE return only
00068                the actual generated audio. Note that this only affects untimed silences. Timed silences
00069                (e.g. the 75ms silence between V.21 and a high speed modem) will alway be transmitted as
00070                silent audio. */
00071     int transmit_on_idle;
00072 
00073     /*! \brief TRUE if we should count the next MCF as a page end, else FALSE */
00074     int count_page_on_mcf;
00075     /*! \brief The number of pages for which a confirm (MCF) message was returned. */
00076     int pages_confirmed;
00077     /*! \brief HDLC message buffers. */
00078     uint8_t hdlc_buf[T38_TX_HDLC_BUFS][T38_MAX_HDLC_LEN];
00079     /*! \brief HDLC message lengths. */
00080     int hdlc_len[T38_TX_HDLC_BUFS];
00081     /*! \brief HDLC message status flags. */
00082     int hdlc_flags[T38_TX_HDLC_BUFS];
00083     /*! \brief HDLC buffer contents. */
00084     int hdlc_contents[T38_TX_HDLC_BUFS];
00085     /*! \brief HDLC buffer number for input. */
00086     int hdlc_in;
00087     /*! \brief HDLC buffer number for output. */
00088     int hdlc_out;
00089 
00090     /*! \brief Progressively calculated CRC for HDLC messaging received from a modem. */
00091     uint16_t crc;
00092 
00093     /*! \brief non-ECM and HDLC modem receive data buffer */
00094     uint8_t rx_data[T38_RX_BUF_LEN];
00095     int rx_data_ptr;
00096 
00097     /*! \brief non-ECM modem transmit data buffer */
00098     uint8_t non_ecm_tx_data[T38_NON_ECM_TX_BUF_LEN];
00099     int non_ecm_tx_in_ptr;
00100     int non_ecm_tx_out_ptr;
00101 
00102     /*! \brief The location of the most recent EOL marker in the non-ECM data buffer */
00103     int non_ecm_tx_latest_eol_ptr;
00104     unsigned int non_ecm_bit_stream;
00105     /*! \brief The non-ECM flow control fill octet (0xFF before the first data, and 0x00
00106                once data has started). */
00107     uint8_t non_ecm_flow_control_fill_octet;
00108     /*! \brief TRUE if we are in the initial all ones part of non-ECM transmission. */
00109     int non_ecm_at_initial_all_ones;
00110     /*! \brief TRUE is the end of non-ECM data indication has been received. */
00111     int non_ecm_data_finished;
00112     /*! \brief The current octet being sent as non-ECM data. */
00113     unsigned int non_ecm_rx_bit_stream;
00114     unsigned int non_ecm_tx_octet;
00115     /*! \brief The current bit number in the current non-ECM octet. */
00116     int non_ecm_bit_no;
00117     int non_ecm_in_octets;
00118     int non_ecm_out_octets;
00119     int non_ecm_in_rows;
00120     int non_ecm_out_rows;
00121     /*! \brief A count of the number of non-ECM fill octets generated for flow control control
00122                purposes. */
00123     int non_ecm_flow_control_fill_octets;
00124 
00125     /*! \brief the current class of field being received - i.e. none, non-ECM or HDLC */
00126     int current_rx_field_class;
00127     /*! \brief The T.38 indicator currently in use */
00128     int in_progress_rx_indicator;
00129 
00130     /*! \brief The current T.38 data type being sent. */
00131     int current_tx_data_type;
00132 
00133     /*! \brief TRUE if we are in error correcting (ECM) mode */
00134     int ecm_mode;
00135     /*! \brief The current bit rate for the fast modem. */
00136     int fast_bit_rate;
00137     /*! \brief The current fast modem type. */
00138     int fast_modem;
00139     /*! \brief TRUE if between DCS and TCF, and we want the fast image modem to
00140                start in the T.38 data at a predictable time from the end of the
00141                V.21 signal. */
00142     int tcf_mode_predictable_modem_start;
00143     /*! \brief TRUE if a carrier is present. Otherwise FALSE. */
00144     int rx_signal_present;
00145     /*! \brief TRUE if a modem has trained correctly. */
00146     int rx_trained;
00147 
00148     /*! \brief A tone generator context used to generate supervisory tones during
00149                FAX handling. */
00150     tone_gen_state_t tone_gen;
00151     /*! \brief An HDLC context used when receiving HDLC messages. */
00152     hdlc_rx_state_t hdlcrx;
00153 
00154     /*! \brief HDLC data used when transmitting HDLC messages. */
00155     hdlc_tx_state_t hdlctx;
00156 
00157     /*! \brief A V.21 FSK modem context used when transmitting HDLC over V.21
00158                messages. */
00159     fsk_tx_state_t v21_tx;
00160     /*! \brief A V.21 FSK modem context used when receiving HDLC over V.21
00161                messages. */
00162     fsk_rx_state_t v21_rx;
00163 
00164     /*! \brief A V.17 modem context used when sending FAXes at 7200bps, 9600bps
00165                12000bps or 14400bps*/
00166     v17_tx_state_t v17_tx;
00167     /*! \brief A V.29 modem context used when receiving FAXes at 7200bps, 9600bps
00168                12000bps or 14400bps*/
00169     v17_rx_state_t v17_rx;
00170 
00171     /*! \brief A V.29 modem context used when sending FAXes at 7200bps or
00172                9600bps */
00173     v29_tx_state_t v29_tx;
00174     /*! \brief A V.29 modem context used when receiving FAXes at 7200bps or
00175                9600bps */
00176     v29_rx_state_t v29_rx;
00177 
00178     /*! \brief A V.27ter modem context used when sending FAXes at 2400bps or
00179                4800bps */
00180     v27ter_tx_state_t v27ter_tx;
00181     /*! \brief A V.27ter modem context used when receiving FAXes at 2400bps or
00182                4800bps */
00183     v27ter_rx_state_t v27ter_rx;
00184 
00185     /*! \brief */
00186     dc_restore_state_t dc_restore;
00187 
00188     /*! \brief Used to insert timed silences. */
00189     silence_gen_state_t silence_gen;
00190 
00191     /*! \brief The immediately active receive signal handler, which may hop between
00192                rx_handler and dummy_rx(). */
00193     span_rx_handler_t *immediate_rx_handler;
00194     /*! \brief The current receive signal handler */
00195     span_rx_handler_t *rx_handler;
00196     /*! \brief An opaque pointer, passed to rx_handler. */
00197     void *rx_user_data;
00198 
00199     /*! \brief The current transmit signal handler */
00200     span_tx_handler_t *tx_handler;
00201     /*! \brief An opaque pointer, passed to tx_handler. */
00202     void *tx_user_data;
00203     /*! \brief The transmit signal handler to be used when the current one has finished sending. */
00204     span_tx_handler_t *next_tx_handler;
00205     /*! \brief An opaque pointer, passed to next_tx_handler. */
00206     void *next_tx_user_data;
00207 
00208     /*! \brief The number of octets to send in each image packet (non-ECM or ECM) at the current
00209                rate and the current specified packet interval. */
00210     int octets_per_data_packet;
00211 
00212     /*! \brief The type of fast receive modem currently active, which may be T38_NONE */
00213     int fast_rx_active;
00214     /*! \brief The number of samples until the next timeout event */
00215     int samples_to_timeout;
00216     /*! \brief TRUE if in image data mode (as opposed to TCF mode). */
00217     int image_data_mode;
00218     /*! \brief TRUE if in image data modem is to use short training. */
00219     int short_train;
00220 
00221     /*! \brief TRUE if we need to corrupt the HDLC frame in progress, so the receiver cannot
00222                interpret it. */
00223     int corrupt_the_frame_to_t38;
00224     /*! \brief TRUE if we need to corrupt the HDLC frame in progress, so the receiver cannot
00225                interpret it. */
00226     int corrupt_the_frame_from_t38;
00227 
00228     /*! \brief The currently select receiver type */
00229     int current_rx_type;
00230     /*! \brief The currently select transmitter type */
00231     int current_tx_type;
00232 
00233     /*! \brief Audio logging file handles */
00234     int fax_audio_rx_log;
00235     int fax_audio_tx_log;
00236     /*! \brief Error and flow logging control */
00237     logging_state_t logging;
00238 } t38_gateway_state_t;
00239 
00240 typedef struct
00241 {
00242     /*! \brief The current bit rate for image transfer. */
00243     int bit_rate;
00244     /*! \brief TRUE if error correcting mode is used. */
00245     int error_correcting_mode;
00246     /*! \brief The number of pages transferred so far. */
00247     int pages_transferred;
00248 } t38_stats_t;
00249 
00250 #if defined(__cplusplus)
00251 extern "C"
00252 {
00253 #endif
00254 
00255 /*! \brief Initialise a gateway mode T.38 context.
00256     \param s The T.38 context.
00257     \param tx_packet_handler A callback routine to encapsulate and transmit T.38 packets.
00258     \param tx_packet_user_data An opaque pointer passed to the tx_packet_handler routine.
00259     \return A pointer to the termination mode T.38 context, or NULL if there was a problem. */
00260 t38_gateway_state_t *t38_gateway_init(t38_gateway_state_t *s,
00261                                       t38_tx_packet_handler_t *tx_packet_handler,
00262                                       void *tx_packet_user_data);
00263 
00264 /*! Free a gateway mode T.38 context.
00265     \brief Free a T.38 context.
00266     \param s The T.38 context.
00267     \return 0 for OK, else -1. */
00268 int t38_gateway_free(t38_gateway_state_t *s);
00269 
00270 /*! Process a block of received FAX audio samples.
00271     \brief Process a block of received FAX audio samples.
00272     \param s The T.38 context.
00273     \param amp The audio sample buffer.
00274     \param len The number of samples in the buffer.
00275     \return The number of samples unprocessed. */
00276 int t38_gateway_rx(t38_gateway_state_t *s, int16_t amp[], int len);
00277 
00278 /*! Generate a block of FAX audio samples.
00279     \brief Generate a block of FAX audio samples.
00280     \param s The T.38 context.
00281     \param amp The audio sample buffer.
00282     \param max_len The number of samples to be generated.
00283     \return The number of samples actually generated.
00284 */
00285 int t38_gateway_tx(t38_gateway_state_t *s, int16_t amp[], int max_len);
00286 
00287 /*! Control whether error correcting mode (ECM) is allowed.
00288     \brief Control whether error correcting mode (ECM) is allowed.
00289     \param s The T.38 context.
00290     \param ecm_allowed TRUE is ECM is to be allowed.
00291 */
00292 void t38_gateway_set_ecm_capability(t38_gateway_state_t *s, int ecm_allowed);
00293 
00294 /*! Select whether silent audio will be sent when transmit is idle.
00295     \brief Select whether silent audio will be sent when transmit is idle.
00296     \param s The T.38 context.
00297     \param transmit_on_idle TRUE if silent audio should be output when the FAX transmitter is
00298            idle. FALSE to transmit zero length audio when the FAX transmitter is idle. The default
00299            behaviour is FALSE.
00300 */
00301 void t38_gateway_set_transmit_on_idle(t38_gateway_state_t *s, int transmit_on_idle);
00302 
00303 /*! Specify which modem types are supported by a T.30 context.
00304     \brief Specify supported modems.
00305     \param s The T.38 context.
00306     \param supported_modems Bit field list of the supported modems.
00307 */
00308 void t38_gateway_set_supported_modems(t38_gateway_state_t *s, int supported_modems);
00309 
00310 /*! Select whether NSC, NSF, and NSS should be suppressed. It selected, the contents of
00311     these messages are forced to zero for all octets beyond the message type. This makes
00312     them look like manufacturer specific messages, from a manufacturer which does not exist.
00313     \brief Select whether NSC, NSF, and NSS should be suppressed.
00314     \param s The T.38 context.
00315     \param suppress_nsx TRUE if NSC, NSF, and NSS should be suppressed.
00316 */
00317 void t38_gateway_set_nsx_suppression(t38_gateway_state_t *s, int suppress_nsx);
00318 
00319 /*! Select whether talker echo protection tone will be sent for the image modems.
00320     \brief Select whether TEP will be sent for the image modems.
00321     \param s The T.38 context.
00322     \param use_tep TRUE if TEP should be sent.
00323 */
00324 void t38_gateway_set_tep_mode(t38_gateway_state_t *s, int use_tep);
00325 
00326 /*! Get the current transfer statistics for the current T.38 session.
00327     \brief Get the current transfer statistics.
00328     \param s The T.38 context.
00329     \param t A pointer to a buffer for the statistics. */
00330 void t38_gateway_get_transfer_statistics(t38_gateway_state_t *s, t38_stats_t *t);
00331 
00332 #if defined(__cplusplus)
00333 }
00334 #endif
00335 
00336 #endif
00337 /*- End of file ------------------------------------------------------------*/

Generated on Thu Feb 26 01:29:52 2009 for libspandsp by  doxygen 1.5.8