00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * t38_gateway.h - A T.38, less the packet exchange part 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2005, 2006, 2007 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 00026 /*! \file */ 00027 00028 #if !defined(_SPANDSP_T38_GATEWAY_H_) 00029 #define _SPANDSP_T38_GATEWAY_H_ 00030 00031 /*! \page t38_gateway_page T.38 real time FAX over IP PSTN gateway 00032 \section t38_gateway_page_sec_1 What does it do? 00033 00034 The T.38 gateway facility provides a robust interface between T.38 IP packet streams and 00035 and 8k samples/second audio streams. It provides the buffering and flow control features needed 00036 to maximum the tolerance of jitter and packet loss on the IP network. 00037 00038 \section t38_gateway_page_sec_2 How does it work? 00039 */ 00040 00041 /*! The receive buffer length */ 00042 #define T38_RX_BUF_LEN 2048 00043 /*! The number of HDLC transmit buffers */ 00044 #define T38_TX_HDLC_BUFS 256 00045 /*! The maximum length of an HDLC frame buffer. This must be big enough for ECM frames. */ 00046 #define T38_MAX_HDLC_LEN 260 00047 00048 typedef struct t38_gateway_state_s t38_gateway_state_t; 00049 00050 /*! 00051 T.30 real time frame handler. 00052 \brief T.30 real time frame handler. 00053 \param s The T.30 context. 00054 \param user_data An opaque pointer. 00055 \param direction TRUE for incoming, FALSE for outgoing. 00056 \param msg The HDLC message. 00057 \param len The length of the message. 00058 */ 00059 typedef void (t38_gateway_real_time_frame_handler_t)(t38_gateway_state_t *s, 00060 void *user_data, 00061 int direction, 00062 const uint8_t *msg, 00063 int len); 00064 00065 /*! 00066 T.38 gateway results. 00067 */ 00068 typedef struct 00069 { 00070 /*! \brief The current bit rate for image transfer. */ 00071 int bit_rate; 00072 /*! \brief TRUE if error correcting mode is used. */ 00073 int error_correcting_mode; 00074 /*! \brief The number of pages transferred so far. */ 00075 int pages_transferred; 00076 } t38_stats_t; 00077 00078 #if defined(__cplusplus) 00079 extern "C" 00080 { 00081 #endif 00082 00083 /*! \brief Initialise a gateway mode T.38 context. 00084 \param s The T.38 context. 00085 \param tx_packet_handler A callback routine to encapsulate and transmit T.38 packets. 00086 \param tx_packet_user_data An opaque pointer passed to the tx_packet_handler routine. 00087 \return A pointer to the termination mode T.38 context, or NULL if there was a problem. */ 00088 SPAN_DECLARE(t38_gateway_state_t *) t38_gateway_init(t38_gateway_state_t *s, 00089 t38_tx_packet_handler_t *tx_packet_handler, 00090 void *tx_packet_user_data); 00091 00092 /*! Release a gateway mode T.38 context. 00093 \brief Release a T.38 context. 00094 \param s The T.38 context. 00095 \return 0 for OK, else -1. */ 00096 SPAN_DECLARE(int) t38_gateway_release(t38_gateway_state_t *s); 00097 00098 /*! Free a gateway mode T.38 context. 00099 \brief Free a T.38 context. 00100 \param s The T.38 context. 00101 \return 0 for OK, else -1. */ 00102 SPAN_DECLARE(int) t38_gateway_free(t38_gateway_state_t *s); 00103 00104 /*! Process a block of received FAX audio samples. 00105 \brief Process a block of received FAX audio samples. 00106 \param s The T.38 context. 00107 \param amp The audio sample buffer. 00108 \param len The number of samples in the buffer. 00109 \return The number of samples unprocessed. */ 00110 SPAN_DECLARE_NONSTD(int) t38_gateway_rx(t38_gateway_state_t *s, int16_t amp[], int len); 00111 00112 /*! Apply fake processing when a block of audio samples is missing (e.g due 00113 to packet loss). 00114 \brief Apply fake received audio processing. 00115 \param s The T.38 context. 00116 \param len The number of samples to fake. 00117 \return The number of samples unprocessed. This should only be non-zero if 00118 the software has reached the end of the FAX call. 00119 */ 00120 SPAN_DECLARE_NONSTD(int) t38_gateway_rx_fillin(t38_gateway_state_t *s, int len); 00121 00122 /*! Generate a block of FAX audio samples. 00123 \brief Generate a block of FAX audio samples. 00124 \param s The T.38 context. 00125 \param amp The audio sample buffer. 00126 \param max_len The number of samples to be generated. 00127 \return The number of samples actually generated. 00128 */ 00129 SPAN_DECLARE_NONSTD(int) t38_gateway_tx(t38_gateway_state_t *s, int16_t amp[], int max_len); 00130 00131 /*! Control whether error correcting mode (ECM) is allowed. 00132 \brief Control whether error correcting mode (ECM) is allowed. 00133 \param s The T.38 context. 00134 \param ecm_allowed TRUE is ECM is to be allowed. 00135 */ 00136 SPAN_DECLARE(void) t38_gateway_set_ecm_capability(t38_gateway_state_t *s, int ecm_allowed); 00137 00138 /*! Select whether silent audio will be sent when transmit is idle. 00139 \brief Select whether silent audio will be sent when transmit is idle. 00140 \param s The T.38 context. 00141 \param transmit_on_idle TRUE if silent audio should be output when the FAX transmitter is 00142 idle. FALSE to transmit zero length audio when the FAX transmitter is idle. The default 00143 behaviour is FALSE. 00144 */ 00145 SPAN_DECLARE(void) t38_gateway_set_transmit_on_idle(t38_gateway_state_t *s, int transmit_on_idle); 00146 00147 /*! Specify which modem types are supported by a T.30 context. 00148 \brief Specify supported modems. 00149 \param s The T.38 context. 00150 \param supported_modems Bit field list of the supported modems. 00151 */ 00152 SPAN_DECLARE(void) t38_gateway_set_supported_modems(t38_gateway_state_t *s, int supported_modems); 00153 00154 /*! Select whether NSC, NSF, and NSS should be suppressed. It selected, the contents of 00155 these messages are forced to zero for all octets beyond the message type. This makes 00156 them look like manufacturer specific messages, from a manufacturer which does not exist. 00157 \brief Select whether NSC, NSF, and NSS should be suppressed. 00158 \param s The T.38 context. 00159 \param from_t38 A string of bytes to overwrite the header of any NSC, NSF, and NSS 00160 frames passing through the gateway from T.38 the the modem. 00161 \param from_t38_len The length of the overwrite string. 00162 \param from_modem A string of bytes to overwrite the header of any NSC, NSF, and NSS 00163 frames passing through the gateway from the modem to T.38. 00164 \param from_modem_len The length of the overwrite string. 00165 */ 00166 SPAN_DECLARE(void) t38_gateway_set_nsx_suppression(t38_gateway_state_t *s, 00167 const uint8_t *from_t38, 00168 int from_t38_len, 00169 const uint8_t *from_modem, 00170 int from_modem_len); 00171 00172 /*! Select whether talker echo protection tone will be sent for the image modems. 00173 \brief Select whether TEP will be sent for the image modems. 00174 \param s The T.38 context. 00175 \param use_tep TRUE if TEP should be sent. 00176 */ 00177 SPAN_DECLARE(void) t38_gateway_set_tep_mode(t38_gateway_state_t *s, int use_tep); 00178 00179 /*! Select whether non-ECM fill bits are to be removed during transmission. 00180 \brief Select whether non-ECM fill bits are to be removed during transmission. 00181 \param s The T.38 context. 00182 \param remove TRUE if fill bits are to be removed. 00183 */ 00184 SPAN_DECLARE(void) t38_gateway_set_fill_bit_removal(t38_gateway_state_t *s, int remove); 00185 00186 /*! Get the current transfer statistics for the current T.38 session. 00187 \brief Get the current transfer statistics. 00188 \param s The T.38 context. 00189 \param t A pointer to a buffer for the statistics. */ 00190 SPAN_DECLARE(void) t38_gateway_get_transfer_statistics(t38_gateway_state_t *s, t38_stats_t *t); 00191 00192 /*! Get a pointer to the T.38 core IFP packet engine associated with a 00193 gateway mode T.38 context. 00194 \brief Get a pointer to the T.38 core IFP packet engine associated 00195 with a T.38 context. 00196 \param s The T.38 context. 00197 \return A pointer to the T.38 core context, or NULL. 00198 */ 00199 SPAN_DECLARE(t38_core_state_t *) t38_gateway_get_t38_core_state(t38_gateway_state_t *s); 00200 00201 /*! Get a pointer to the logging context associated with a T.38 context. 00202 \brief Get a pointer to the logging context associated with a T.38 context. 00203 \param s The T.38 context. 00204 \return A pointer to the logging context, or NULL. 00205 */ 00206 SPAN_DECLARE(logging_state_t *) t38_gateway_get_logging_state(t38_gateway_state_t *s); 00207 00208 /*! Set a callback function for T.30 frame exchange monitoring. This is called from the heart 00209 of the signal processing, so don't take too long in the handler routine. 00210 \brief Set a callback function for T.30 frame exchange monitoring. 00211 \param s The T.30 context. 00212 \param handler The callback function. 00213 \param user_data An opaque pointer passed to the callback function. */ 00214 SPAN_DECLARE(void) t38_gateway_set_real_time_frame_handler(t38_gateway_state_t *s, 00215 t38_gateway_real_time_frame_handler_t *handler, 00216 void *user_data); 00217 00218 #if defined(__cplusplus) 00219 } 00220 #endif 00221 00222 #endif 00223 /*- End of file ------------------------------------------------------------*/