t31.h

Go to the documentation of this file.
00001 /*
00002  * SpanDSP - a series of DSP components for telephony
00003  *
00004  * t31.h - A T.31 compatible class 1 FAX modem interface.
00005  *
00006  * Written by Steve Underwood <steveu@coppice.org>
00007  *
00008  * Copyright (C) 2004 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: t31.h,v 1.52 2008/07/31 12:55:30 steveu Exp $
00026  */
00027 
00028 /*! \file */
00029 
00030 #if !defined(_SPANDSP_T31_H_)
00031 #define _SPANDSP_T31_H_
00032 
00033 /*! \page t31_page T.31 Class 1 FAX modem protocol handling
00034 \section t31_page_sec_1 What does it do?
00035 The T.31 class 1 FAX modem modules implements a class 1 interface to the FAX
00036 modems in spandsp.
00037 
00038 \section t31_page_sec_2 How does it work?
00039 */
00040 
00041 typedef struct t31_state_s t31_state_t;
00042 
00043 typedef int (t31_modem_control_handler_t)(t31_state_t *s, void *user_data, int op, const char *num);
00044 
00045 #define T31_TX_BUF_LEN          (4096)
00046 #define T31_TX_BUF_HIGH_TIDE    (4096 - 1024)
00047 #define T31_TX_BUF_LOW_TIDE     (1024)
00048 #define T31_MAX_HDLC_LEN        284
00049 #define T31_T38_MAX_HDLC_LEN    260
00050 
00051 /*!
00052     Analogue FAX front end channel descriptor. This defines the state of a single working
00053     instance of an analogue line FAX front end.
00054 */
00055 typedef struct
00056 {
00057     fax_modems_state_t modems;
00058 
00059     /*! The transmit signal handler to be used when the current one has finished sending. */
00060     span_tx_handler_t *next_tx_handler;
00061     void *next_tx_user_data;
00062 
00063     /*! \brief No of data bits in current_byte. */
00064     int bit_no;
00065     /*! \brief The current data byte in progress. */
00066     int current_byte;
00067 
00068     /*! \brief Rx power meter, used to detect silence. */
00069     power_meter_t rx_power;
00070     /*! \brief Last sample, used for an elementary HPF for the power meter. */
00071     int16_t last_sample;
00072     /*! \brief The current silence threshold. */
00073     int32_t silence_threshold_power;
00074 
00075     /*! \brief Samples of silence heard */
00076     int silence_heard;
00077 } t31_audio_front_end_state_t;
00078 
00079 /*!
00080     Analogue FAX front end channel descriptor. This defines the state of a single working
00081     instance of an analogue line FAX front end.
00082 */
00083 typedef struct
00084 {
00085     t38_core_state_t t38;
00086 
00087     /*! \brief The number of octets to send in each image packet (non-ECM or ECM) at the current
00088                rate and the current specified packet interval. */
00089     int octets_per_data_packet;
00090 
00091     int timed_step;
00092 
00093     int ms_per_tx_chunk;
00094     int merge_tx_fields;
00095 
00096     /*! \brief TRUE is there has been some T.38 data missed */
00097     int missing_data;
00098 
00099     /*! \brief The number of times an indicator packet will be sent. Numbers greater than one
00100                will increase reliability for UDP transmission. Zero is valid, to suppress all
00101                indicator packets for TCP transmission. */
00102     int indicator_tx_count;
00103 
00104     /*! \brief The number of times a data packet which ends transmission will be sent. Numbers
00105                greater than one will increase reliability for UDP transmission. Zero is not valid. */
00106     int data_end_tx_count;
00107 
00108     /*! \brief The current T.38 data type being transmitted */
00109     int current_tx_data_type;
00110     /*! \brief The next queued tramsit indicator */
00111     int next_tx_indicator;
00112 
00113     int trailer_bytes;
00114 
00115     struct
00116     {
00117         uint8_t buf[T31_T38_MAX_HDLC_LEN];
00118         int len;
00119     } hdlc_rx;
00120 
00121     int current_rx_type;
00122     int current_tx_type;
00123 
00124     int32_t next_tx_samples;
00125     int32_t timeout_rx_samples;
00126     /*! \brief A "sample" count, used to time events */
00127     int32_t samples;
00128 } t31_t38_front_end_state_t;
00129 
00130 /*!
00131     T.31 descriptor. This defines the working state for a single instance of
00132     a T.31 FAX modem.
00133 */
00134 struct t31_state_s
00135 {
00136     at_state_t at_state;
00137     t31_modem_control_handler_t *modem_control_handler;
00138     void *modem_control_user_data;
00139 
00140     t31_audio_front_end_state_t audio;
00141     t31_t38_front_end_state_t t38_fe;
00142     /*! TRUE if working in T.38 mode. */
00143     int t38_mode;
00144 
00145     /*! HDLC buffer, for composing an HDLC frame from the computer to the channel. */
00146     struct
00147     {
00148         uint8_t buf[T31_MAX_HDLC_LEN];
00149         int len;
00150         int ptr;
00151         /*! \brief TRUE when the end of HDLC data from the computer has been detected. */
00152         int final;
00153     } hdlc_tx;
00154     /*! Buffer for data from the computer to the channel. */
00155     struct
00156     {
00157         uint8_t data[T31_TX_BUF_LEN];
00158         /*! \brief The number of bytes stored in transmit buffer. */
00159         int in_bytes;
00160         /*! \brief The number of bytes sent from the transmit buffer. */
00161         int out_bytes;
00162         /*! \brief TRUE if the flow of real data has started. */
00163         int data_started;
00164         /*! \brief TRUE if holding up further data into the buffer, for flow control. */
00165         int holding;
00166         /*! \brief TRUE when the end of non-ECM data from the computer has been detected. */
00167         int final;
00168     } tx;
00169 
00170     /*! TRUE if DLE prefix just used */
00171     int dled;
00172 
00173         /*! \brief Samples of silence awaited, as specified in a "wait for silence" command */
00174     int silence_awaited;
00175 
00176     /*! \brief The current bit rate for the FAX fast message transfer modem. */
00177     int bit_rate;
00178     /*! \brief TRUE if a valid HDLC frame has been received in the current reception period. */
00179     int rx_frame_received;
00180 
00181     /*! \brief Samples elapsed in the current call */
00182     int64_t call_samples;
00183     int64_t dte_data_timeout;
00184 
00185     /*! \brief The currently queued modem type. */
00186     int modem;
00187     /*! \brief TRUE when short training mode has been selected by the computer. */
00188     int short_train;
00189     queue_state_t *rx_queue;
00190 
00191     /*! \brief Error and flow logging control */
00192     logging_state_t logging;
00193 };
00194 
00195 #if defined(__cplusplus)
00196 extern "C"
00197 {
00198 #endif
00199 
00200 void t31_call_event(t31_state_t *s, int event);
00201 
00202 int t31_at_rx(t31_state_t *s, const char *t, int len);
00203 
00204 /*! Process a block of received T.31 modem audio samples.
00205     \brief Process a block of received T.31 modem audio samples.
00206     \param s The T.31 modem context.
00207     \param amp The audio sample buffer.
00208     \param len The number of samples in the buffer.
00209     \return The number of samples unprocessed. */
00210 int t31_rx(t31_state_t *s, int16_t amp[], int len);
00211 
00212 /*! Generate a block of T.31 modem audio samples.
00213     \brief Generate a block of T.31 modem audio samples.
00214     \param s The T.31 modem context.
00215     \param amp The audio sample buffer.
00216     \param max_len The number of samples to be generated.
00217     \return The number of samples actually generated.
00218 */
00219 int t31_tx(t31_state_t *s, int16_t amp[], int max_len);
00220 
00221 int t31_t38_send_timeout(t31_state_t *s, int samples);
00222 
00223 /*! Select whether silent audio will be sent when transmit is idle.
00224     \brief Select whether silent audio will be sent when transmit is idle.
00225     \param s The T.31 modem context.
00226     \param transmit_on_idle TRUE if silent audio should be output when the transmitter is
00227            idle. FALSE to transmit zero length audio when the transmitter is idle. The default
00228            behaviour is FALSE.
00229 */
00230 void t31_set_transmit_on_idle(t31_state_t *s, int transmit_on_idle);
00231 
00232 /*! Select whether TEP mode will be used (or time allowed for it (when transmitting).
00233     \brief Select whether TEP mode will be used.
00234     \param s The T.31 modem context.
00235     \param use_tep TRUE if TEP is to be ised.
00236 */
00237 void t31_set_tep_mode(t31_state_t *s, int use_tep);
00238 
00239 /*! Select whether T.38 data will be paced as it is transmitted.
00240     \brief Select whether T.38 data will be paced.
00241     \param s The T.31 modem context.
00242     \param without_pacing TRUE if data is to be sent as fast as possible. FALSE if it is
00243            to be paced.
00244 */
00245 void t31_set_t38_config(t31_state_t *s, int without_pacing);
00246 
00247 /*! Initialise a T.31 context. This must be called before the first
00248     use of the context, to initialise its contents.
00249     \brief Initialise a T.31 context.
00250     \param s The T.31 context.
00251     \param at_tx_handler A callback routine to handle AT interpreter channel output.
00252     \param at_tx_user_data An opaque pointer passed in called to at_tx_handler.
00253     \param modem_control_handler A callback routine to handle control of the modem (off-hook, etc).
00254     \param modem_control_user_data An opaque pointer passed in called to modem_control_handler.
00255     \param tx_t38_packet_handler ???
00256     \param tx_t38_packet_user_data ???
00257     \return A pointer to the T.31 context. */
00258 t31_state_t *t31_init(t31_state_t *s,
00259                       at_tx_handler_t *at_tx_handler,
00260                       void *at_tx_user_data,
00261                       t31_modem_control_handler_t *modem_control_handler,
00262                       void *modem_control_user_data,
00263                       t38_tx_packet_handler_t *tx_t38_packet_handler,
00264                       void *tx_t38_packet_user_data);
00265 
00266 /*! Release a T.31 context.
00267     \brief Release a T.31 context.
00268     \param s The T.31 context.
00269     \return 0 for OK */
00270 int t31_release(t31_state_t *s);
00271 
00272 #if defined(__cplusplus)
00273 }
00274 #endif
00275 
00276 #endif
00277 /*- End of file ------------------------------------------------------------*/

Generated on Tue Oct 7 20:25:48 2008 for spandsp by  doxygen 1.5.6