00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * t38_non_ecm_buffer.h - A rate adapting buffer for T.38 non-ECM image 00005 * and TCF data 00006 * 00007 * Written by Steve Underwood <steveu@coppice.org> 00008 * 00009 * Copyright (C) 2005, 2006, 2007, 2008 Steve Underwood 00010 * 00011 * All rights reserved. 00012 * 00013 * This program is free software; you can redistribute it and/or modify 00014 * it under the terms of the GNU Lesser General Public License version 2.1, 00015 * as published by the Free Software Foundation. 00016 * 00017 * This program is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU Lesser General Public License for more details. 00021 * 00022 * You should have received a copy of the GNU Lesser General Public 00023 * License along with this program; if not, write to the Free Software 00024 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00025 * 00026 * $Id: t38_non_ecm_buffer.h,v 1.2 2008/09/02 13:56:10 steveu Exp $ 00027 */ 00028 00029 /*! \file */ 00030 00031 #if !defined(_SPANDSP_T38_NON_ECM_BUFFER_H_) 00032 #define _SPANDSP_T38_NON_ECM_BUFFER_H_ 00033 00034 /*! \page t38_non_ecm_buffer_page T.38 rate adapting non-ECM image data buffer 00035 \section t38_non_ecm_buffer_page_sec_1 What does it do? 00036 00037 The T.38 rate adapting non-ECM image data buffer is used to buffer TCF and non-ECM 00038 FAX image data being gatewayed from a T.38 linke to an analogue FAX modem link. 00039 00040 \section t38_non_ecm_buffer_page_sec_2 How does it work? 00041 */ 00042 00043 /*! The buffer length much be a power of two. The chosen length is big enough for 00044 over 9s of data at the V.17 14,400bps rate. */ 00045 #define T38_NON_ECM_TX_BUF_LEN 16384 00046 00047 /*! \brief A flow controlled non-ECM image data buffer, for buffering T.38 to analogue 00048 modem data. 00049 */ 00050 typedef struct 00051 { 00052 /*! \brief Minimum number of bits per row, used when fill bits are being deleted on the 00053 link, and restored at the emitting gateway. */ 00054 int min_row_bits; 00055 00056 /*! \brief non-ECM modem transmit data buffer. */ 00057 uint8_t data[T38_NON_ECM_TX_BUF_LEN]; 00058 /*! \brief The current write point in the buffer. */ 00059 int in_ptr; 00060 /*! \brief The current read point in the buffer. */ 00061 int out_ptr; 00062 /*! \brief The location of the most recent EOL marker in the buffer. */ 00063 int latest_eol_ptr; 00064 /*! \brief The number of bits to date in the current row, used when min_row_bits is 00065 to be applied. */ 00066 int row_bits; 00067 00068 /*! \brief The bit stream entering the buffer, used to detect EOLs */ 00069 unsigned int bit_stream; 00070 /*! \brief The non-ECM flow control fill octet (0xFF before the first data, and 0x00 00071 once data has started). */ 00072 uint8_t flow_control_fill_octet; 00073 /*! \brief TRUE if we are in the initial all ones part of non-ECM transmission. */ 00074 int at_initial_all_ones; 00075 /*! \brief TRUE is the end of non-ECM data indication has been received. */ 00076 int data_finished; 00077 /*! \brief The current octet being transmitted from the buffer. */ 00078 unsigned int octet; 00079 /*! \brief The current bit number in the current non-ECM octet. */ 00080 int bit_no; 00081 /*! \brief TRUE if in image data mode, as opposed to TCF mode. */ 00082 int image_data_mode; 00083 00084 /*! \brief The number of octets input to the buffer. */ 00085 int in_octets; 00086 /*! \brief The number of rows input to the buffer. */ 00087 int in_rows; 00088 /*! \brief The number of non-ECM fill octets generated for minimum row bits 00089 purposes. */ 00090 int min_row_bits_fill_octets; 00091 /*! \brief The number of octets output from the buffer. */ 00092 int out_octets; 00093 /*! \brief The number of rows output from the buffer. */ 00094 int out_rows; 00095 /*! \brief The number of non-ECM fill octets generated for flow control 00096 purposes. */ 00097 int flow_control_fill_octets; 00098 } t38_non_ecm_buffer_state_t; 00099 00100 #if defined(__cplusplus) 00101 extern "C" 00102 { 00103 #endif 00104 00105 /*! \brief Initialise a T.38 rate adapting non-ECM buffer context. 00106 \param s The buffer context. 00107 \param mode TRUE for image data mode, or FALSE for TCF mode. 00108 \param bits The minimum number of bits per FAX image row. 00109 \return A pointer to the buffer context, or NULL if there was a problem. */ 00110 t38_non_ecm_buffer_state_t *t38_non_ecm_buffer_init(t38_non_ecm_buffer_state_t *s, int mode, int min_row_bits); 00111 00112 /*! \brief Set the mode of a T.38 rate adapting non-ECM buffer context. 00113 \param s The buffer context. 00114 \param mode TRUE for image data mode, or FALSE for TCF mode. 00115 \param bits The minimum number of bits per FAX image row. */ 00116 void t38_non_ecm_buffer_set_mode(t38_non_ecm_buffer_state_t *s, int mode, int min_row_bits); 00117 00118 /*! \brief Inject data to T.38 rate adapting non-ECM buffer context. 00119 \param s The buffer context. 00120 \param buf The data buffer to be injected. 00121 \param len The length of the data to be injected. */ 00122 void t38_non_ecm_buffer_inject(t38_non_ecm_buffer_state_t *s, const uint8_t *buf, int len); 00123 00124 /*! \brief Inform a T.38 rate adapting non-ECM buffer context that the incoming data has finished, 00125 and the contents of the buffer should be played out as quickly as possible. 00126 \param s The buffer context. */ 00127 void t38_non_ecm_buffer_push(t38_non_ecm_buffer_state_t *s); 00128 00129 /*! \brief Report the input status of a T.38 rate adapting non-ECM buffer context to the specified 00130 logging context. 00131 \param s The buffer context. 00132 \param logging The logging context. */ 00133 void t38_non_ecm_buffer_report_input_status(t38_non_ecm_buffer_state_t *s, logging_state_t *logging); 00134 00135 /*! \brief Report the output status of a T.38 rate adapting non-ECM buffer context to the specified 00136 logging context. 00137 \param s The buffer context. 00138 \param logging The logging context. */ 00139 void t38_non_ecm_buffer_report_output_status(t38_non_ecm_buffer_state_t *s, logging_state_t *logging); 00140 00141 /*! \brief Get the next bit of data from a T.38 rate adapting non-ECM buffer context. 00142 \param user_data The buffer context, cast to a void pointer. 00143 \return The next bit, or one of the values indicating a change of modem status. */ 00144 int t38_non_ecm_buffer_get_bit(void *user_data); 00145 00146 #if defined(__cplusplus) 00147 } 00148 #endif 00149 00150 #endif 00151 /*- End of file ------------------------------------------------------------*/