00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * private/t30.h - definitions for T.30 fax processing 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2003 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: t30.h,v 1.4 2009/04/12 14:18:02 steveu Exp $ 00026 */ 00027 00028 /*! \file */ 00029 00030 #if !defined(_SPANDSP_PRIVATE_T30_H_) 00031 #define _SPANDSP_PRIVATE_T30_H_ 00032 00033 /*! 00034 T.30 FAX channel descriptor. This defines the state of a single working 00035 instance of a T.30 FAX channel. 00036 */ 00037 struct t30_state_s 00038 { 00039 /* This must be kept the first thing in the structure, so it can be pointed 00040 to reliably as the structures change over time. */ 00041 /*! \brief T.4 context for reading or writing image data. */ 00042 t4_state_t t4; 00043 00044 /*! \brief The type of FAX operation currently in progress */ 00045 int operation_in_progress; 00046 00047 /*! \brief TRUE if behaving as the calling party */ 00048 int calling_party; 00049 00050 /*! \brief The received DCS, formatted as an ASCII string, for inclusion 00051 in the TIFF file. */ 00052 char rx_dcs_string[T30_MAX_DIS_DTC_DCS_LEN*3 + 1]; 00053 /*! \brief The text which will be used in FAX page header. No text results 00054 in no header line. */ 00055 char header_info[T30_MAX_PAGE_HEADER_INFO + 1]; 00056 /*! \brief The information fields received. */ 00057 t30_exchanged_info_t rx_info; 00058 /*! \brief The information fields to be transmitted. */ 00059 t30_exchanged_info_t tx_info; 00060 /*! \brief The country of origin of the remote machine, if known, else NULL. */ 00061 const char *country; 00062 /*! \brief The vendor of the remote machine, if known, else NULL. */ 00063 const char *vendor; 00064 /*! \brief The model of the remote machine, if known, else NULL. */ 00065 const char *model; 00066 00067 /*! \brief A pointer to a callback routine to be called when phase B events 00068 occur. */ 00069 t30_phase_b_handler_t *phase_b_handler; 00070 /*! \brief An opaque pointer supplied in event B callbacks. */ 00071 void *phase_b_user_data; 00072 /*! \brief A pointer to a callback routine to be called when phase D events 00073 occur. */ 00074 t30_phase_d_handler_t *phase_d_handler; 00075 /*! \brief An opaque pointer supplied in event D callbacks. */ 00076 void *phase_d_user_data; 00077 /*! \brief A pointer to a callback routine to be called when phase E events 00078 occur. */ 00079 t30_phase_e_handler_t *phase_e_handler; 00080 /*! \brief An opaque pointer supplied in event E callbacks. */ 00081 void *phase_e_user_data; 00082 /*! \brief A pointer to a callback routine to be called when frames are 00083 exchanged. */ 00084 t30_real_time_frame_handler_t *real_time_frame_handler; 00085 /*! \brief An opaque pointer supplied in real time frame callbacks. */ 00086 void *real_time_frame_user_data; 00087 00088 /*! \brief A pointer to a callback routine to be called when document events 00089 (e.g. end of transmitted document) occur. */ 00090 t30_document_handler_t *document_handler; 00091 /*! \brief An opaque pointer supplied in document callbacks. */ 00092 void *document_user_data; 00093 00094 /*! \brief The handler for changes to the receive mode */ 00095 t30_set_handler_t *set_rx_type_handler; 00096 /*! \brief An opaque pointer passed to the handler for changes to the receive mode */ 00097 void *set_rx_type_user_data; 00098 /*! \brief The handler for changes to the transmit mode */ 00099 t30_set_handler_t *set_tx_type_handler; 00100 /*! \brief An opaque pointer passed to the handler for changes to the transmit mode */ 00101 void *set_tx_type_user_data; 00102 00103 /*! \brief The transmitted HDLC frame handler. */ 00104 t30_send_hdlc_handler_t *send_hdlc_handler; 00105 /*! \brief An opaque pointer passed to the transmitted HDLC frame handler. */ 00106 void *send_hdlc_user_data; 00107 00108 /*! \brief The DIS code for the minimum scan row time we require. This is usually 0ms, 00109 but if we are trying to simulate another type of FAX machine, we may need a non-zero 00110 value here. */ 00111 uint8_t local_min_scan_time_code; 00112 00113 /*! \brief The current T.30 phase. */ 00114 int phase; 00115 /*! \brief The T.30 phase to change to when the current phase ends. */ 00116 int next_phase; 00117 /*! \brief The current state of the T.30 state machine. */ 00118 int state; 00119 /*! \brief The step in sending a sequence of HDLC frames. */ 00120 int step; 00121 00122 /*! \brief The preparation buffer for the DCS message to be transmitted. */ 00123 uint8_t dcs_frame[T30_MAX_DIS_DTC_DCS_LEN]; 00124 /*! \brief The length of the DCS message to be transmitted. */ 00125 int dcs_len; 00126 /*! \brief The preparation buffer for DIS or DTC message to be transmitted. */ 00127 uint8_t local_dis_dtc_frame[T30_MAX_DIS_DTC_DCS_LEN]; 00128 /*! \brief The length of the DIS or DTC message to be transmitted. */ 00129 int local_dis_dtc_len; 00130 /*! \brief The last DIS or DTC message received form the far end. */ 00131 uint8_t far_dis_dtc_frame[T30_MAX_DIS_DTC_DCS_LEN]; 00132 /*! \brief The length of the last DIS or DTC message received form the far end. */ 00133 int far_dis_dtc_len; 00134 /*! \brief TRUE if a valid DIS has been received from the far end. */ 00135 int dis_received; 00136 00137 /*! \brief A flag to indicate a message is in progress. */ 00138 int in_message; 00139 00140 /*! \brief TRUE if the short training sequence should be used. */ 00141 int short_train; 00142 00143 /*! \brief A count of the number of bits in the trainability test. This counts down to zero when 00144 sending TCF, and counts up when receiving it. */ 00145 int tcf_test_bits; 00146 /*! \brief The current count of consecutive received zero bits, during the trainability test. */ 00147 int tcf_current_zeros; 00148 /*! \brief The maximum consecutive received zero bits seen to date, during the trainability test. */ 00149 int tcf_most_zeros; 00150 00151 /*! \brief The current fallback step for the fast message transfer modem. */ 00152 int current_fallback; 00153 /*! \brief The subset of supported modems allowed at the current time, allowing for negotiation. */ 00154 int current_permitted_modems; 00155 /*! \brief TRUE if a carrier is present. Otherwise FALSE. */ 00156 int rx_signal_present; 00157 /*! \brief TRUE if a modem has trained correctly. */ 00158 int rx_trained; 00159 /*! \brief TRUE if a valid HDLC frame has been received in the current reception period. */ 00160 int rx_frame_received; 00161 00162 /*! \brief Current reception mode. */ 00163 int current_rx_type; 00164 /*! \brief Current transmission mode. */ 00165 int current_tx_type; 00166 00167 /*! \brief T0 is the answer timeout when calling another FAX machine. 00168 Placing calls is handled outside the FAX processing, but this timeout keeps 00169 running until V.21 modulation is sent or received. 00170 T1 is the remote terminal identification timeout (in audio samples). */ 00171 int timer_t0_t1; 00172 /*! \brief T2, T2A and T2B are the HDLC command timeouts. 00173 T4, T4A and T4B are the HDLC response timeouts (in audio samples). */ 00174 int timer_t2_t4; 00175 /*! \brief A value specifying which of the possible timers is currently running in timer_t2_t4 */ 00176 int timer_t2_t4_is; 00177 /*! \brief Procedural interrupt timeout (in audio samples). */ 00178 int timer_t3; 00179 /*! \brief This is only used in error correcting mode. */ 00180 int timer_t5; 00181 /*! \brief This is only used in full duplex (e.g. ISDN) modes. */ 00182 int timer_t6; 00183 /*! \brief This is only used in full duplex (e.g. ISDN) modes. */ 00184 int timer_t7; 00185 /*! \brief This is only used in full duplex (e.g. ISDN) modes. */ 00186 int timer_t8; 00187 00188 /*! \brief TRUE once the far end FAX entity has been detected. */ 00189 int far_end_detected; 00190 00191 /*! \brief TRUE if a local T.30 interrupt is pending. */ 00192 int local_interrupt_pending; 00193 /*! \brief The image coding being used on the line. */ 00194 int line_encoding; 00195 /*! \brief The image coding being used for output files. */ 00196 int output_encoding; 00197 /*! \brief The current DCS message minimum scan time code. */ 00198 uint8_t min_scan_time_code; 00199 /*! \brief The X direction resolution of the current image, in pixels per metre. */ 00200 int x_resolution; 00201 /*! \brief The Y direction resolution of the current image, in pixels per metre. */ 00202 int y_resolution; 00203 /*! \brief The width of the current image, in pixels. */ 00204 t4_image_width_t image_width; 00205 /*! \brief Current number of retries of the action in progress. */ 00206 int retries; 00207 /*! \brief TRUE if error correcting mode is used. */ 00208 int error_correcting_mode; 00209 /*! \brief The number of HDLC frame retries, if error correcting mode is used. */ 00210 int error_correcting_mode_retries; 00211 /*! \brief The current count of consecutive T30_PPR messages. */ 00212 int ppr_count; 00213 /*! \brief The current count of consecutive T30_RNR messages. */ 00214 int receiver_not_ready_count; 00215 /*! \brief The number of octets to be used per ECM frame. */ 00216 int octets_per_ecm_frame; 00217 /*! \brief The ECM partial page buffer. */ 00218 uint8_t ecm_data[256][260]; 00219 /*! \brief The lengths of the frames in the ECM partial page buffer. */ 00220 int16_t ecm_len[256]; 00221 /*! \brief A bit map of the OK ECM frames, constructed as a PPR frame. */ 00222 uint8_t ecm_frame_map[3 + 32]; 00223 00224 /*! \brief The current page number for receiving, in ECM mode. This is reset at the start of a call. */ 00225 int ecm_rx_page; 00226 /*! \brief The current page number for sending, in ECM mode. This is reset at the start of a call. */ 00227 int ecm_tx_page; 00228 /*! \brief The current block number, in ECM mode */ 00229 int ecm_block; 00230 /*! \brief The number of frames in the current block number, in ECM mode */ 00231 int ecm_frames; 00232 /*! \brief The number of frames sent in the current burst of image transmission, in ECM mode */ 00233 int ecm_frames_this_tx_burst; 00234 /*! \brief The current ECM frame, during ECM transmission. */ 00235 int ecm_current_tx_frame; 00236 /*! \brief TRUE if we are at the end of an ECM page to se sent - i.e. there are no more 00237 partial pages still to come. */ 00238 int ecm_at_page_end; 00239 00240 /*! \brief The transmission step queued to follow the one in progress. */ 00241 int next_tx_step; 00242 /*! \brief The FCF for the next receive step. */ 00243 uint8_t next_rx_step; 00244 /*! \brief Image file name for image reception. */ 00245 char rx_file[256]; 00246 /*! \brief The last page we are prepared accept for a received image file. -1 means no restriction. */ 00247 int rx_stop_page; 00248 /*! \brief Image file name to be sent. */ 00249 char tx_file[256]; 00250 /*! \brief The first page to be sent from the image file. -1 means no restriction. */ 00251 int tx_start_page; 00252 /*! \brief The last page to be sent from the image file. -1 means no restriction. */ 00253 int tx_stop_page; 00254 /*! \brief The current completion status. */ 00255 int current_status; 00256 /*! \brief Internet Aware FAX mode bit mask. */ 00257 int iaf; 00258 /*! \brief A bit mask of the currently supported modem types. */ 00259 int supported_modems; 00260 /*! \brief A bit mask of the currently supported image compression modes. */ 00261 int supported_compressions; 00262 /*! \brief A bit mask of the currently supported image resolutions. */ 00263 int supported_resolutions; 00264 /*! \brief A bit mask of the currently supported image sizes. */ 00265 int supported_image_sizes; 00266 /*! \brief A bit mask of the currently supported T.30 special features. */ 00267 int supported_t30_features; 00268 /*! \brief TRUE is ECM mode handling is enabled. */ 00269 int ecm_allowed; 00270 00271 /*! \brief the FCF2 field of the last PPS message we received. */ 00272 uint8_t last_pps_fcf2; 00273 /*! \brief The number of the first ECM frame which we do not currently received correctly. For 00274 a partial page received correctly, this will be one greater than the number of frames it 00275 contains. */ 00276 int ecm_first_bad_frame; 00277 /*! \brief A count of successfully received ECM frames, to assess progress as a basis for 00278 deciding whether to continue error correction when PPRs keep repeating. */ 00279 int ecm_progress; 00280 00281 /*! \brief Error and flow logging control */ 00282 logging_state_t logging; 00283 }; 00284 00285 #endif 00286 /*- End of file ------------------------------------------------------------*/