00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * t38_terminal.h - T.38 termination, less the packet exchange part 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: t38_terminal.h,v 1.37 2008/08/14 14:06:05 steveu Exp $ 00026 */ 00027 00028 /*! \file */ 00029 00030 #if !defined(_SPANDSP_T38_TERMINAL_H_) 00031 #define _SPANDSP_T38_TERMINAL_H_ 00032 00033 /*! \page t38_terminal_page T.38 real time FAX over IP termination 00034 \section t38_terminal_page_sec_1 What does it do? 00035 00036 \section t38_terminal_page_sec_2 How does it work? 00037 */ 00038 00039 /* Make sure the HDLC frame buffers are big enough for ECM frames. */ 00040 #define T38_MAX_HDLC_LEN 260 00041 00042 typedef struct 00043 { 00044 /*! \brief Internet Aware FAX mode bit mask. */ 00045 int iaf; 00046 /*! \brief Required time between T.38 transmissions, in ms. */ 00047 int ms_per_tx_chunk; 00048 /*! \brief Bit fields controlling the way data is packed into chunked for transmission. */ 00049 int chunking_modes; 00050 00051 /*! \brief Core T.38 IFP support */ 00052 t38_core_state_t t38; 00053 00054 /*! \brief The current transmit step being timed */ 00055 int timed_step; 00056 00057 /*! \brief TRUE is there has been some T.38 data missed (i.e. lost packets) in the current 00058 reception period. */ 00059 int rx_data_missing; 00060 00061 /*! \brief The number of octets to send in each image packet (non-ECM or ECM) at the current 00062 rate and the current specified packet interval. */ 00063 int octets_per_data_packet; 00064 00065 struct 00066 { 00067 /*! \brief HDLC receive buffer */ 00068 uint8_t buf[T38_MAX_HDLC_LEN]; 00069 /*! \brief The length of the contents of the HDLC receive buffer */ 00070 int len; 00071 } hdlc_rx; 00072 00073 struct 00074 { 00075 /*! \brief HDLC transmit buffer */ 00076 uint8_t buf[T38_MAX_HDLC_LEN]; 00077 /*! \brief The length of the contents of the HDLC transmit buffer */ 00078 int len; 00079 /*! \brief Current pointer within the contents of the HDLC transmit buffer */ 00080 int ptr; 00081 /*! \brief The number of extra bits in a fully stuffed version of the 00082 contents of the HDLC transmit buffer. This is needed to accurately 00083 estimate the playout time for this frame, through an analogue modem. */ 00084 int extra_bits; 00085 } tx; 00086 00087 /*! \brief Counter for trailing non-ECM bytes, used to flush out the far end's modem. */ 00088 int non_ecm_trailer_bytes; 00089 00090 /*! \brief The next T.38 indicator queued for transmission. */ 00091 int next_tx_indicator; 00092 /*! \brief The current T.38 data type being transmitted. */ 00093 int current_tx_data_type; 00094 00095 /*! \brief TRUE if a carrier is present. Otherwise FALSE. */ 00096 int rx_signal_present; 00097 00098 /*! \brief The current operating mode of the receiver. */ 00099 int current_rx_type; 00100 /*! \brief The current operating mode of the transmitter. */ 00101 int current_tx_type; 00102 00103 /*! \brief Current transmission bit rate. */ 00104 int tx_bit_rate; 00105 /*! \brief A "sample" count, used to time events. */ 00106 int32_t samples; 00107 /*! \brief The value for samples at the next transmission point. */ 00108 int32_t next_tx_samples; 00109 /*! \brief The current receive timeout. */ 00110 int32_t timeout_rx_samples; 00111 } t38_terminal_front_end_state_t; 00112 00113 /*! 00114 T.38 terminal state. 00115 */ 00116 typedef struct 00117 { 00118 /*! \brief The T.30 back-end */ 00119 t30_state_t t30; 00120 00121 /*! \brief The T.38 front-end */ 00122 t38_terminal_front_end_state_t t38_fe; 00123 00124 /*! \brief Error and flow logging control */ 00125 logging_state_t logging; 00126 } t38_terminal_state_t; 00127 00128 #if defined(__cplusplus) 00129 extern "C" 00130 { 00131 #endif 00132 00133 int t38_terminal_send_timeout(t38_terminal_state_t *s, int samples); 00134 00135 void t38_terminal_set_config(t38_terminal_state_t *s, int without_pacing); 00136 00137 /*! Select whether the time for talker echo protection tone will be allowed for when sending. 00138 \brief Select whether TEP time will be allowed for. 00139 \param s The T.38 context. 00140 \param use_tep TRUE if TEP should be allowed for. 00141 */ 00142 void t38_terminal_set_tep_mode(t38_terminal_state_t *s, int use_tep); 00143 00144 /*! Select whether non-ECM fill bits are to be removed during transmission. 00145 \brief Select whether non-ECM fill bits are to be removed during transmission. 00146 \param s The T.38 context. 00147 \param remove TRUE if fill bits are to be removed. 00148 */ 00149 void t38_terminal_set_fill_bit_removal(t38_terminal_state_t *s, int remove); 00150 00151 /*! Get a pointer to the T.30 engine associated with a termination mode T.38 context. 00152 \brief Get a pointer to the T.30 engine associated with a T.38 context. 00153 \param s The T.38 context. 00154 \return A pointer to the T.30 context, or NULL. 00155 */ 00156 t30_state_t *t38_terminal_get_t30_state(t38_terminal_state_t *s); 00157 00158 /*! \brief Initialise a termination mode T.38 context. 00159 \param s The T.38 context. 00160 \param calling_party TRUE if the context is for a calling party. FALSE if the 00161 context is for an answering party. 00162 \param tx_packet_handler A callback routine to encapsulate and transmit T.38 packets. 00163 \param tx_packet_user_data An opaque pointer passed to the tx_packet_handler routine. 00164 \return A pointer to the termination mode T.38 context, or NULL if there was a problem. */ 00165 t38_terminal_state_t *t38_terminal_init(t38_terminal_state_t *s, 00166 int calling_party, 00167 t38_tx_packet_handler_t *tx_packet_handler, 00168 void *tx_packet_user_data); 00169 00170 /*! Release a termination mode T.38 context. 00171 \brief Release a T.38 context. 00172 \param s The T.38 context. 00173 \return 0 for OK, else -1. */ 00174 int t38_terminal_release(t38_terminal_state_t *s); 00175 00176 /*! Free a a termination mode T.38 context. 00177 \brief Free a T.38 context. 00178 \param s The T.38 context. 00179 \return 0 for OK, else -1. */ 00180 int t38_terminal_free(t38_terminal_state_t *s); 00181 00182 #if defined(__cplusplus) 00183 } 00184 #endif 00185 00186 #endif 00187 /*- End of file ------------------------------------------------------------*/