1 /* 2 * SpanDSP - a series of DSP components for telephony 3 * 4 * t31.h - A T.31 compatible class 1 FAX modem interface. 5 * 6 * Written by Steve Underwood <steveu@coppice.org> 7 * 8 * Copyright (C) 2004 Steve Underwood 9 * 10 * All rights reserved. 11 * 12 * This program is free software; you can redistribute it and/or modify 13 * it under the terms of the GNU Lesser General Public License version 2.1, 14 * as published by the Free Software Foundation. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU Lesser General Public License for more details. 20 * 21 * You should have received a copy of the GNU Lesser General Public 22 * License along with this program; if not, write to the Free Software 23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 */ 25 26 /*! \file */ 27 28 #if !defined(_SPANDSP_T31_H_) 29 #define _SPANDSP_T31_H_ 30 31 /*! \page t31_page T.31 Class 1 FAX modem protocol handling 32 \section t31_page_sec_1 What does it do? 33 The T.31 class 1 FAX modem modules implements a class 1 interface to the FAX 34 modems in spandsp. 35 36 \section t31_page_sec_2 How does it work? 37 */ 38 39 /*! 40 T.31 descriptor. This defines the working state for a single instance of 41 a T.31 FAX modem. 42 */ 43 typedef struct t31_state_s t31_state_t; 44 45 typedef int (*t31_modem_control_handler_t)(t31_state_t *s, void *user_data, int op, const char *num); 46 47 #if defined(__cplusplus) 48 extern "C" 49 { 50 #endif 51 52 SPAN_DECLARE(void) t31_call_event(t31_state_t *s, int event); 53 54 /*! Return the amount of free space in the AT COMMAND BUFFER. 55 \brief Return the amount of free space in the AT COMMAND BUFFER. 56 \param s The T.31 modem context. 57 \return The number of bytes of free space. */ 58 SPAN_DECLARE(int) t31_at_rx_free_space(t31_state_t *s); 59 60 SPAN_DECLARE(int) t31_at_rx(t31_state_t *s, const char *t, int len); 61 62 /*! Process a block of received T.31 modem audio samples. 63 \brief Process a block of received T.31 modem audio samples. 64 \param s The T.31 modem context. 65 \param amp The audio sample buffer. 66 \param len The number of samples in the buffer. 67 \return The number of samples unprocessed. */ 68 SPAN_DECLARE(int) t31_rx(t31_state_t *s, int16_t amp[], int len); 69 70 /*! Fake processing of a missing block of received T.31 modem audio samples 71 (e.g due to packet loss). 72 \brief Fake processing of a missing block of received T.31 modem audio samples. 73 \param s The T.31 modem context. 74 \param len The number of samples to fake. 75 \return The number of samples unprocessed. */ 76 SPAN_DECLARE(int) t31_rx_fillin(t31_state_t *s, int len); 77 78 /*! Generate a block of T.31 modem audio samples. 79 \brief Generate a block of T.31 modem audio samples. 80 \param s The T.31 modem context. 81 \param amp The audio sample buffer. 82 \param max_len The number of samples to be generated. 83 \return The number of samples actually generated. 84 */ 85 SPAN_DECLARE(int) t31_tx(t31_state_t *s, int16_t amp[], int max_len); 86 87 SPAN_DECLARE(int) t31_t38_send_timeout(t31_state_t *s, int samples); 88 89 /*! Select whether silent audio will be sent when transmit is idle. 90 \brief Select whether silent audio will be sent when transmit is idle. 91 \param s The T.31 modem context. 92 \param transmit_on_idle True if silent audio should be output when the transmitter is 93 idle. False to transmit zero length audio when the transmitter is idle. The default 94 behaviour is false. 95 */ 96 SPAN_DECLARE(void) t31_set_transmit_on_idle(t31_state_t *s, bool transmit_on_idle); 97 98 /*! Select whether TEP mode will be used (or time allowed for it (when transmitting). 99 \brief Select whether TEP mode will be used. 100 \param s The T.31 modem context. 101 \param use_tep True if TEP is to be used. 102 */ 103 SPAN_DECLARE(void) t31_set_tep_mode(t31_state_t *s, bool use_tep); 104 105 /*! Select whether T.38 data will be paced as it is transmitted. 106 \brief Select whether T.38 data will be paced. 107 \param s The T.31 modem context. 108 \param without_pacing True if data is to be sent as fast as possible. False if it is 109 to be paced. 110 */ 111 SPAN_DECLARE(void) t31_set_t38_config(t31_state_t *s, bool without_pacing); 112 113 /*! Set audio or T.38 mode. 114 \brief Set audio or T.38 mode. 115 \param s The T.31 modem context. 116 \param t38_mode True for T.38 mode operation. False for audio mode operation. 117 */ 118 SPAN_DECLARE(void) t31_set_mode(t31_state_t *s, bool t38_mode); 119 120 /*! Get a pointer to the logging context associated with a T.31 context. 121 \brief Get a pointer to the logging context associated with a T.31 context. 122 \param s The T.31 context. 123 \return A pointer to the logging context, or NULL. 124 */ 125 SPAN_DECLARE(logging_state_t *) t31_get_logging_state(t31_state_t *s); 126 127 /*! Get a pointer to the AT interpreter context associated with a T.31 context. 128 \brief Get a pointer to the AT interpreter context associated with a T.31 context. 129 \param s The T.31 context. 130 \return A pointer to the AT interpreter context, or NULL. 131 */ 132 SPAN_DECLARE(at_state_t *) t31_get_at_state(t31_state_t *s); 133 134 /*! Get a pointer to the T.38 core context associated with a T.31 context. 135 \brief Get a pointer to the T.38 core context associated with a T.31 context. 136 \param s The T.31 context. 137 \return A pointer to the T.38 core context, or NULL. 138 */ 139 SPAN_DECLARE(t38_core_state_t *) t31_get_t38_core_state(t31_state_t *s); 140 141 /*! Initialise a T.31 context. This must be called before the first 142 use of the context, to initialise its contents. 143 \brief Initialise a T.31 context. 144 \param s The T.31 context. 145 \param at_tx_handler A callback routine to handle AT interpreter channel output. 146 \param at_tx_user_data An opaque pointer passed in called to at_tx_handler. 147 \param modem_control_handler A callback routine to handle control of the modem (off-hook, etc). 148 \param modem_control_user_data An opaque pointer passed in called to modem_control_handler. 149 \param tx_t38_packet_handler ??? 150 \param tx_t38_packet_user_data ??? 151 \return A pointer to the T.31 context. */ 152 SPAN_DECLARE(t31_state_t *) t31_init(t31_state_t *s, 153 at_tx_handler_t at_tx_handler, 154 void *at_tx_user_data, 155 t31_modem_control_handler_t modem_control_handler, 156 void *modem_control_user_data, 157 t38_tx_packet_handler_t tx_t38_packet_handler, 158 void *tx_t38_packet_user_data); 159 160 /*! Release a T.31 context. 161 \brief Release a T.31 context. 162 \param s The T.31 context. 163 \return 0 for OK */ 164 SPAN_DECLARE(int) t31_release(t31_state_t *s); 165 166 /*! Free a T.31 context. 167 \brief Release a T.31 context. 168 \param s The T.31 context. 169 \return 0 for OK */ 170 SPAN_DECLARE(int) t31_free(t31_state_t *s); 171 172 #if defined(__cplusplus) 173 } 174 #endif 175 176 #endif 177 /*- End of file ------------------------------------------------------------*/ 178