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.24 2007/05/15 13:22:43 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     /*! \brief A V.17 modem context used when sending FAXes at 7200bps, 9600bps
00095                12000bps or 14400bps*/
00096     v17_tx_state_t v17tx;
00097     /*! \brief A V.29 modem context used when receiving FAXes at 7200bps, 9600bps
00098                12000bps or 14400bps*/
00099     v17_rx_state_t v17rx;
00100     /*! \brief A V.27ter modem context used when sending FAXes at 2400bps or
00101                4800bps */
00102     v27ter_tx_state_t v27ter_tx;
00103     /*! \brief A V.27ter modem context used when receiving FAXes at 2400bps or
00104                4800bps */
00105     v27ter_rx_state_t v27ter_rx;
00106     /*! \brief A V.29 modem context used when sending FAXes at 7200bps or
00107                9600bps */
00108     v29_tx_state_t v29tx;
00109     /*! \brief A V.29 modem context used when receiving FAXes at 7200bps or
00110                9600bps */
00111     v29_rx_state_t v29rx;
00112     /*! \brief Used to insert timed silences. */
00113     silence_gen_state_t silence_gen;
00114     /*! \brief */
00115     dc_restore_state_t dc_restore;
00116 
00117     /*! \brief TRUE is the short training sequence should be used. */
00118     int short_train;
00119 
00120     /*! The currently select receiver type */
00121     int current_rx_type;
00122     /*! The currently select transmitter type */
00123     int current_tx_type;
00124 
00125     int first_tx_hdlc_frame;
00126 
00127     /*! Audio logging file handles */
00128     int fax_audio_rx_log;
00129     int fax_audio_tx_log;
00130     /*! \brief Error and flow logging control */
00131     logging_state_t logging;
00132 };
00133 
00134 #if defined(__cplusplus)
00135 extern "C"
00136 {
00137 #endif
00138 
00139 /*! Apply T.30 receive processing to a block of audio samples.
00140     \brief Apply T.30 receive processing to a block of audio samples.
00141     \param s The FAX context.
00142     \param amp The audio sample buffer.
00143     \param len The number of samples in the buffer.
00144     \return The number of samples unprocessed. This should only be non-zero if
00145             the software has reached the end of the FAX call.
00146 */
00147 int fax_rx(fax_state_t *s, int16_t *amp, int len);
00148 
00149 /*! Apply T.30 transmit processing to generate a block of audio samples.
00150     \brief Apply T.30 transmit processing to generate a block of audio samples.
00151     \param s The FAX context.
00152     \param amp The audio sample buffer.
00153     \param max_len The number of samples to be generated.
00154     \return The number of samples actually generated. This will be zero when
00155             there is nothing to send.
00156 */
00157 int fax_tx(fax_state_t *s, int16_t *amp, int max_len);
00158 
00159 void fax_set_flush_handler(fax_state_t *s, fax_flush_handler_t *handler, void *user_data);
00160 
00161 /*! Select whether silent audio will be sent when FAX transmit is idle.
00162     \brief Select whether silent audio will be sent when FAX transmit is idle.
00163     \param s The FAX context.
00164     \param transmit_on_idle TRUE if silent audio should be output when the FAX transmitter is
00165            idle. FALSE to transmit zero length audio when the FAX transmitter is idle. The default
00166            behaviour is FALSE.
00167 */
00168 void fax_set_transmit_on_idle(fax_state_t *s, int transmit_on_idle);
00169 
00170 /*! Select whether talker echo protection tone will be sent for the image modems.
00171     \brief Select whether TEP will be sent for the image modems.
00172     \param s The FAX context.
00173     \param use_tep TRUE if TEP should be sent.
00174 */
00175 void fax_set_tep_mode(fax_state_t *s, int use_tep);
00176 
00177 /*! Initialise a FAX context.
00178     \brief Initialise a FAX context.
00179     \param s The FAX context.
00180     \param calling_party TRUE if the context is for a calling party. FALSE if the
00181            context is for an answering party.
00182     \return A pointer to the FAX context, or NULL if there was a problem.
00183 */
00184 fax_state_t *fax_init(fax_state_t *s, int calling_party);
00185 
00186 /*! Release a FAX context.
00187     \brief Release a FAX context.
00188     \param s The FAX context. */
00189 int fax_release(fax_state_t *s);
00190 
00191 #if defined(__cplusplus)
00192 }
00193 #endif
00194 
00195 #endif
00196 /*- End of file ------------------------------------------------------------*/

Generated on Tue Jul 24 11:29:28 2007 for libspandsp by  doxygen 1.5.2