t38_non_ecm_buffer.h

Go to the documentation of this file.
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 
00027 /*! \file */
00028 
00029 #if !defined(_SPANDSP_T38_NON_ECM_BUFFER_H_)
00030 #define _SPANDSP_T38_NON_ECM_BUFFER_H_
00031 
00032 /*! \page t38_non_ecm_buffer_page T.38 rate adapting non-ECM image data buffer
00033 \section t38_non_ecm_buffer_page_sec_1 What does it do?
00034 
00035 The T.38 rate adapting non-ECM image data buffer is used to buffer TCF and non-ECM
00036 FAX image data being gatewayed from a T.38 link to an analogue FAX modem link.
00037 
00038 As well as rate adapting, the buffer has the ability to impose a minimum on the number
00039 of bits per row of image data. This allows any row padding zeros to be stripped from
00040 the data stream, to minimise the data sent as T.38 packets, and be reinserted before
00041 the data is sent to its final destination. Not all T.38 implementations support this
00042 feature, so it's use must be negotiated.
00043 
00044 \section t38_non_ecm_buffer_page_sec_2 How does it work?
00045 
00046 When inserting padding bits, whether to ensure a minimum row time or for flow control,
00047 it is important the right value is inserted at the right point in the data sequence.
00048 If we are in the optional initial period of all ones, we can insert a byte of extra
00049 ones at any time. Once we pass that initial stage, TCF and image data need separate
00050 handling.
00051 
00052 TCF data is all zeros. Once the period of all zeros has begun it is OK to insert
00053 additional bytes of zeros at any point.
00054 
00055 Image data consists of rows, separated by EOL (end of line) markers. Inserting
00056 zeros at arbitrary times would corrupt the image. However, it is OK to insert a
00057 considerable number of extra zeros just before an EOL. Therefore we track where the
00058 EOL markers occur as we fill the buffer. As we empty the buffer stop outputting real
00059 data, and start outputting bytes of zero, if we reach this last EOL marker location.
00060 The EOL marker is 11 zeros following by 1 (1D mode) or 2 (2D mode) ones. Therefore, it
00061 always spills across 2 bytes in the buffer, and there is always a point where we can
00062 insert our extra zeros between bytes.
00063 
00064 Padding between the group of successive EOL markers which for the RTC (return to control)
00065 marker that ends an image causes some FAX machines not to recognise them as an RTC condition.
00066 Therefore, our padding applies special protection so padding never occurs between two
00067 successive EOL markers, with no pixel data between them.
00068 */
00069 
00070 /*! The buffer length much be a power of two. The chosen length is big enough for
00071     over 9s of data at the V.17 14,400bps rate. */    
00072 #define T38_NON_ECM_TX_BUF_LEN  16384
00073 
00074 /*! \brief A flow controlled non-ECM image data buffer, for buffering T.38 to analogue
00075            modem data.
00076 */
00077 typedef struct t38_non_ecm_buffer_state_s t38_non_ecm_buffer_state_t;
00078 
00079 #if defined(__cplusplus)
00080 extern "C"
00081 {
00082 #endif
00083 
00084 /*! \brief Initialise a T.38 rate adapting non-ECM buffer context.
00085     \param s The buffer context.
00086     \param mode TRUE for image data mode, or FALSE for TCF mode.
00087     \param bits The minimum number of bits per FAX image row.
00088     \return A pointer to the buffer context, or NULL if there was a problem. */
00089 SPAN_DECLARE(t38_non_ecm_buffer_state_t *) t38_non_ecm_buffer_init(t38_non_ecm_buffer_state_t *s, int mode, int min_row_bits);
00090 
00091 SPAN_DECLARE(int) t38_non_ecm_buffer_release(t38_non_ecm_buffer_state_t *s);
00092 
00093 SPAN_DECLARE(int) t38_non_ecm_buffer_free(t38_non_ecm_buffer_state_t *s);
00094 
00095 /*! \brief Set the mode of a T.38 rate adapting non-ECM buffer context.
00096     \param s The buffer context.
00097     \param mode TRUE for image data mode, or FALSE for TCF mode.
00098     \param bits The minimum number of bits per FAX image row. */
00099 SPAN_DECLARE(void) t38_non_ecm_buffer_set_mode(t38_non_ecm_buffer_state_t *s, int mode, int min_row_bits);
00100 
00101 /*! \brief Inject data to T.38 rate adapting non-ECM buffer context.
00102     \param s The buffer context.
00103     \param buf The data buffer to be injected.
00104     \param len The length of the data to be injected. */
00105 SPAN_DECLARE(void) t38_non_ecm_buffer_inject(t38_non_ecm_buffer_state_t *s, const uint8_t *buf, int len);
00106 
00107 /*! \brief Inform a T.38 rate adapting non-ECM buffer context that the incoming data has finished,
00108            and the contents of the buffer should be played out as quickly as possible.
00109     \param s The buffer context. */
00110 SPAN_DECLARE(void) t38_non_ecm_buffer_push(t38_non_ecm_buffer_state_t *s);
00111 
00112 /*! \brief Report the input status of a T.38 rate adapting non-ECM buffer context to the specified
00113            logging context.
00114     \param s The buffer context.
00115     \param logging The logging context. */
00116 SPAN_DECLARE(void) t38_non_ecm_buffer_report_input_status(t38_non_ecm_buffer_state_t *s, logging_state_t *logging);
00117 
00118 /*! \brief Report the output status of a T.38 rate adapting non-ECM buffer context to the specified
00119            logging context.
00120     \param s The buffer context.
00121     \param logging The logging context. */
00122 SPAN_DECLARE(void) t38_non_ecm_buffer_report_output_status(t38_non_ecm_buffer_state_t *s, logging_state_t *logging);
00123 
00124 /*! \brief Get the next bit of data from a T.38 rate adapting non-ECM buffer context.
00125     \param user_data The buffer context, cast to a void pointer.
00126     \return The next bit, or one of the values indicating a change of modem status. */
00127 SPAN_DECLARE_NONSTD(int) t38_non_ecm_buffer_get_bit(void *user_data);
00128 
00129 #if defined(__cplusplus)
00130 }
00131 #endif
00132 
00133 #endif
00134 /*- End of file ------------------------------------------------------------*/

Generated on 9 Jul 2012 for spandsp by  doxygen 1.6.1