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