fax.h

Go to the documentation of this file.
00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * fax.h - definitions for analogue line ITU T.30 fax processing
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: fax.h,v 1.22 2007/04/05 19:20:49 steveu Exp $
00026  */
00027 
00028 /*! \file */
00029 
00030 #if !defined(_SPANDSP_FAX_H_)
00031 #define _SPANDSP_FAX_H_
00032 
00033 /*! \page fax_page FAX over analogue modem handling
00034 
00035 \section fax_page_sec_1 What does it do?
00036 
00037 \section fax_page_sec_2 How does it work?
00038 */
00039 
00040 typedef struct fax_state_s fax_state_t;
00041 
00042 typedef void (fax_flush_handler_t)(fax_state_t *s, void *user_data, int which);
00043 
00044 /*!
00045     Analogue line T.30 FAX channel descriptor. This defines the state of a single working
00046     instance of an analogue line soft-FAX machine.
00047 */
00048 struct fax_state_s
00049 {
00050     /* This must be kept the first thing in the structure, so it can be pointed
00051        to reliably as the structures change over time. */
00052     t30_state_t t30_state;
00053 
00054     /*! TRUE is talker echo protection should be sent for the image modems */
00055     int use_tep;
00056 
00057     fax_flush_handler_t *flush_handler;
00058     void *flush_user_data;
00059 
00060     /*! The current receive signal handler */
00061     span_rx_handler_t *rx_handler;
00062     void *rx_user_data;
00063 
00064     /*! The current transmit signal handler */
00065     span_tx_handler_t *tx_handler;
00066     void *tx_user_data;
00067     int tx_hdlc_preamble_len;
00068     /*! The transmit signal handler to be used when the current one has finished sending. */
00069     span_tx_handler_t *next_tx_handler;
00070     void *next_tx_user_data;
00071     
00072     /*! If TRUE, transmission is in progress */
00073     int transmit;
00074 
00075     /*! If TRUE, transmit silence when there is nothing else to transmit. If FALSE return only
00076         the actual generated audio. Note that this only affects untimed silences. Timed silences
00077         (e.g. the 75ms silence between V.21 and a high speed modem) will alway be transmitted as
00078         silent audio. */
00079     int transmit_on_idle;
00080 
00081     /*! \brief A tone generator context used to generate supervisory tones during
00082                FAX handling. */
00083     tone_gen_state_t tone_gen;
00084     /*! \brief An HDLC context used when receiving HDLC over V.21 messages. */
00085     hdlc_rx_state_t hdlcrx;
00086     /*! \brief An HDLC context used when transmitting HDLC over V.21 messages. */
00087     hdlc_tx_state_t hdlctx;
00088     /*! \brief A V.21 FSK modem context used when transmitting HDLC over V.21
00089                messages. */
00090     fsk_tx_state_t v21tx;
00091     /*! \brief A V.21 FSK modem context used when receiving HDLC over V.21
00092                messages. */
00093     fsk_rx_state_t v21rx;
00094 #if defined(ENABLE_V17)
00095     /*! \brief A V.17 modem context used when sending FAXes at 7200bps, 9600bps
00096                12000bps or 14400bps*/
00097     v17_tx_state_t v17tx;
00098     /*! \brief A V.29 modem context used when receiving FAXes at 7200bps, 9600bps
00099                12000bps or 14400bps*/
00100     v17_rx_state_t v17rx;
00101 #endif
00102     /*! \brief A V.27ter modem context used when sending FAXes at 2400bps or
00103                4800bps */
00104     v27ter_tx_state_t v27ter_tx;
00105     /*! \brief A V.27ter modem context used when receiving FAXes at 2400bps or
00106                4800bps */
00107     v27ter_rx_state_t v27ter_rx;
00108     /*! \brief A V.29 modem context used when sending FAXes at 7200bps or
00109                9600bps */
00110     v29_tx_state_t v29tx;
00111     /*! \brief A V.29 modem context used when receiving FAXes at 7200bps or
00112                9600bps */
00113     v29_rx_state_t v29rx;
00114     /*! \brief Used to insert timed silences. */
00115     silence_gen_state_t silence_gen;
00116     /*! \brief */
00117     dc_restore_state_t dc_restore;
00118 
00119     /*! \brief TRUE is the short training sequence should be used. */
00120     int short_train;
00121 
00122     /*! The currently select receiver type */
00123     int current_rx_type;
00124     /*! The currently select transmitter type */
00125     int current_tx_type;
00126 
00127     int first_tx_hdlc_frame;
00128 
00129     /*! Audio logging file handles */
00130     int fax_audio_rx_log;
00131     int fax_audio_tx_log;
00132     /*! \brief Error and flow logging control */
00133     logging_state_t logging;
00134 };
00135 
00136 #ifdef __cplusplus
00137 extern "C"
00138 {
00139 #endif
00140 
00141 /*! Apply T.30 receive processing to a block of audio samples.
00142     \brief Apply T.30 receive processing to a block of audio samples.
00143     \param s The FAX context.
00144     \param amp The audio sample buffer.
00145     \param len The number of samples in the buffer.
00146     \return The number of samples unprocessed. This should only be non-zero if
00147             the software has reached the end of the FAX call.
00148 */
00149 int fax_rx(fax_state_t *s, int16_t *amp, int len);
00150 
00151 /*! Apply T.30 transmit processing to generate a block of audio samples.
00152     \brief Apply T.30 transmit processing to generate a block of audio samples.
00153     \param s The FAX context.
00154     \param amp The audio sample buffer.
00155     \param max_len The number of samples to be generated.
00156     \return The number of samples actually generated. This will be zero when
00157             there is nothing to send.
00158 */
00159 int fax_tx(fax_state_t *s, int16_t *amp, int max_len);
00160 
00161 void fax_set_flush_handler(fax_state_t *s, fax_flush_handler_t *handler, void *user_data);
00162 
00163 /*! Select whether silent audio will be sent when FAX transmit is idle.
00164     \brief Select whether silent audio will be sent when FAX transmit is idle.
00165     \param s The FAX context.
00166     \param transmit_on_idle TRUE if silent audio should be output when the FAX transmitter is
00167            idle. FALSE to transmit zero length audio when the FAX transmitter is idle. The default
00168            behaviour is FALSE.
00169 */
00170 void fax_set_transmit_on_idle(fax_state_t *s, int transmit_on_idle);
00171 
00172 /*! Select whether talker echo protection tone will be sent for the image modems.
00173     \brief Select whether TEP will be sent for the image modems.
00174     \param s The FAX context.
00175     \param use_tep TRUE if TEP should be sent.
00176 */
00177 void fax_set_tep_mode(fax_state_t *s, int use_tep);
00178 
00179 /*! Initialise a FAX context.
00180     \brief Initialise a FAX context.
00181     \param s The FAX context.
00182     \param calling_party TRUE if the context is for a calling party. FALSE if the
00183            context is for an answering party.
00184     \return 0 for OK, else -1.
00185 */
00186 int fax_init(fax_state_t *s, int calling_party);
00187 
00188 /*! Release a FAX context.
00189     \brief Release a FAX context.
00190     \param s The FAX context. */
00191 int fax_release(fax_state_t *s);
00192 
00193 #ifdef __cplusplus
00194 }
00195 #endif
00196 
00197 #endif
00198 /*- End of file ------------------------------------------------------------*/

Generated on Fri Apr 13 13:16:32 2007 for libspandsp by  doxygen 1.5.2