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 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: fax.h,v 1.30 2008/04/17 14:27:00 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     /*! The transmit signal handler to be used when the current one has finished sending. */
00068     span_tx_handler_t *next_tx_handler;
00069     void *next_tx_user_data;
00070     
00071     /*! If TRUE, transmission is in progress */
00072     int transmit;
00073 
00074     /*! If TRUE, transmit silence when there is nothing else to transmit. If FALSE return only
00075         the actual generated audio. Note that this only affects untimed silences. Timed silences
00076         (e.g. the 75ms silence between V.21 and a high speed modem) will alway be transmitted as
00077         silent audio. */
00078     int transmit_on_idle;
00079 
00080     /*! \brief A tone generator context used to generate supervisory tones during
00081                FAX handling. */
00082     tone_gen_state_t tone_gen;
00083     /*! \brief An HDLC context used when receiving HDLC over V.21 messages. */
00084     hdlc_rx_state_t hdlcrx;
00085     /*! \brief An HDLC context used when transmitting HDLC over V.21 messages. */
00086     hdlc_tx_state_t hdlctx;
00087     /*! \brief A V.21 FSK modem context used when transmitting HDLC over V.21
00088                messages. */
00089     fsk_tx_state_t v21_tx;
00090     /*! \brief A V.21 FSK modem context used when receiving HDLC over V.21
00091                messages. */
00092     fsk_rx_state_t v21_rx;
00093     /*! \brief A V.17 modem context used when sending FAXes at 7200bps, 9600bps
00094                12000bps or 14400bps*/
00095     v17_tx_state_t v17_tx;
00096     /*! \brief A V.29 modem context used when receiving FAXes at 7200bps, 9600bps
00097                12000bps or 14400bps*/
00098     v17_rx_state_t v17_rx;
00099     /*! \brief A V.27ter modem context used when sending FAXes at 2400bps or
00100                4800bps */
00101     v27ter_tx_state_t v27ter_tx;
00102     /*! \brief A V.27ter modem context used when receiving FAXes at 2400bps or
00103                4800bps */
00104     v27ter_rx_state_t v27ter_rx;
00105     /*! \brief A V.29 modem context used when sending FAXes at 7200bps or
00106                9600bps */
00107     v29_tx_state_t v29_tx;
00108     /*! \brief A V.29 modem context used when receiving FAXes at 7200bps or
00109                9600bps */
00110     v29_rx_state_t v29_rx;
00111     /*! \brief Used to insert timed silences. */
00112     silence_gen_state_t silence_gen;
00113     /*! \brief */
00114     dc_restore_state_t dc_restore;
00115 
00116     /*! \brief TRUE is the short training sequence should be used. */
00117     int short_train;
00118 
00119     /*! \brief The currently select receiver type */
00120     int current_rx_type;
00121     /*! \brief The currently select transmitter type */
00122     int current_tx_type;
00123 
00124     /*! \brief Audio logging file handle for received audio. */
00125     int fax_audio_rx_log;
00126     /*! \brief Audio logging file handle for transmitted audio. */
00127     int fax_audio_tx_log;
00128     /*! \brief Error and flow logging control */
00129     logging_state_t logging;
00130 };
00131 
00132 #if defined(__cplusplus)
00133 extern "C"
00134 {
00135 #endif
00136 
00137 /*! Apply T.30 receive processing to a block of audio samples.
00138     \brief Apply T.30 receive processing to a block of audio samples.
00139     \param s The FAX context.
00140     \param amp The audio sample buffer.
00141     \param len The number of samples in the buffer.
00142     \return The number of samples unprocessed. This should only be non-zero if
00143             the software has reached the end of the FAX call.
00144 */
00145 int fax_rx(fax_state_t *s, int16_t *amp, int len);
00146 
00147 /*! Apply T.30 transmit processing to generate a block of audio samples.
00148     \brief Apply T.30 transmit processing to generate a block of audio samples.
00149     \param s The FAX context.
00150     \param amp The audio sample buffer.
00151     \param max_len The number of samples to be generated.
00152     \return The number of samples actually generated. This will be zero when
00153             there is nothing to send.
00154 */
00155 int fax_tx(fax_state_t *s, int16_t *amp, int max_len);
00156 
00157 void fax_set_flush_handler(fax_state_t *s, fax_flush_handler_t *handler, void *user_data);
00158 
00159 /*! Select whether silent audio will be sent when FAX transmit is idle.
00160     \brief Select whether silent audio will be sent when FAX transmit is idle.
00161     \param s The FAX context.
00162     \param transmit_on_idle TRUE if silent audio should be output when the FAX transmitter is
00163            idle. FALSE to transmit zero length audio when the FAX transmitter is idle. The default
00164            behaviour is FALSE.
00165 */
00166 void fax_set_transmit_on_idle(fax_state_t *s, int transmit_on_idle);
00167 
00168 /*! Select whether talker echo protection tone will be sent for the image modems.
00169     \brief Select whether TEP will be sent for the image modems.
00170     \param s The FAX context.
00171     \param use_tep TRUE if TEP should be sent.
00172 */
00173 void fax_set_tep_mode(fax_state_t *s, int use_tep);
00174 
00175 /*! Initialise a FAX context.
00176     \brief Initialise a FAX context.
00177     \param s The FAX context.
00178     \param calling_party TRUE if the context is for a calling party. FALSE if the
00179            context is for an answering party.
00180     \return A pointer to the FAX context, or NULL if there was a problem.
00181 */
00182 fax_state_t *fax_init(fax_state_t *s, int calling_party);
00183 
00184 /*! Release a FAX context.
00185     \brief Release a FAX context.
00186     \param s The FAX context.
00187     \return 0 for OK, else -1. */
00188 int fax_release(fax_state_t *s);
00189 
00190 /*! Free a FAX context.
00191     \brief Free a FAX context.
00192     \param s The FAX context.
00193     \return 0 for OK, else -1. */
00194 int fax_free(fax_state_t *s);
00195 
00196 #if defined(__cplusplus)
00197 }
00198 #endif
00199 
00200 #endif
00201 /*- End of file ------------------------------------------------------------*/

Generated on Mon Nov 21 19:46:23 2011 for libspandsp by  doxygen 1.5.3