00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * v42bis.h 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: v42bis.h,v 1.27 2009/04/11 18:11:19 steveu Exp $ 00026 */ 00027 00028 /*! \page v42bis_page V.42bis modem data compression 00029 \section v42bis_page_sec_1 What does it do? 00030 The v.42bis specification defines a data compression scheme, to work in 00031 conjunction with the error correction scheme defined in V.42. 00032 00033 \section v42bis_page_sec_2 How does it work? 00034 */ 00035 00036 #if !defined(_SPANDSP_V42BIS_H_) 00037 #define _SPANDSP_V42BIS_H_ 00038 00039 #define V42BIS_MAX_BITS 12 00040 #define V42BIS_MAX_CODEWORDS 4096 /* 2^V42BIS_MAX_BITS */ 00041 #define V42BIS_TABLE_SIZE 5021 /* This should be a prime >(2^V42BIS_MAX_BITS) */ 00042 #define V42BIS_MAX_STRING_SIZE 250 00043 00044 enum 00045 { 00046 V42BIS_P0_NEITHER_DIRECTION = 0, 00047 V42BIS_P0_INITIATOR_RESPONDER, 00048 V42BIS_P0_RESPONDER_INITIATOR, 00049 V42BIS_P0_BOTH_DIRECTIONS 00050 }; 00051 00052 enum 00053 { 00054 V42BIS_COMPRESSION_MODE_DYNAMIC = 0, 00055 V42BIS_COMPRESSION_MODE_ALWAYS, 00056 V42BIS_COMPRESSION_MODE_NEVER 00057 }; 00058 00059 typedef void (*v42bis_frame_handler_t)(void *user_data, const uint8_t *pkt, int len); 00060 typedef void (*v42bis_data_handler_t)(void *user_data, const uint8_t *buf, int len); 00061 00062 /*! 00063 V.42bis compression/decompression descriptor. This defines the working state for a 00064 single instance of V.42bis compress/decompression. 00065 */ 00066 typedef struct v42bis_state_s v42bis_state_t; 00067 00068 #if defined(__cplusplus) 00069 extern "C" 00070 { 00071 #endif 00072 00073 /*! Compress a block of octets. 00074 \param s The V.42bis context. 00075 \param buf The data to be compressed. 00076 \param len The length of the data buffer. 00077 \return 0 */ 00078 SPAN_DECLARE(int) v42bis_compress(v42bis_state_t *s, const uint8_t *buf, int len); 00079 00080 /*! Flush out any data remaining in a compression buffer. 00081 \param s The V.42bis context. 00082 \return 0 */ 00083 SPAN_DECLARE(int) v42bis_compress_flush(v42bis_state_t *s); 00084 00085 /*! Decompress a block of octets. 00086 \param s The V.42bis context. 00087 \param buf The data to be decompressed. 00088 \param len The length of the data buffer. 00089 \return 0 */ 00090 SPAN_DECLARE(int) v42bis_decompress(v42bis_state_t *s, const uint8_t *buf, int len); 00091 00092 /*! Flush out any data remaining in the decompression buffer. 00093 \param s The V.42bis context. 00094 \return 0 */ 00095 SPAN_DECLARE(int) v42bis_decompress_flush(v42bis_state_t *s); 00096 00097 /*! Set the compression mode. 00098 \param s The V.42bis context. 00099 \param mode One of the V.42bis compression modes - 00100 V42BIS_COMPRESSION_MODE_DYNAMIC, 00101 V42BIS_COMPRESSION_MODE_ALWAYS, 00102 V42BIS_COMPRESSION_MODE_NEVER */ 00103 SPAN_DECLARE(void) v42bis_compression_control(v42bis_state_t *s, int mode); 00104 00105 /*! Initialise a V.42bis context. 00106 \param s The V.42bis context. 00107 \param negotiated_p0 The negotiated P0 parameter, from the V.42bis spec. 00108 \param negotiated_p1 The negotiated P1 parameter, from the V.42bis spec. 00109 \param negotiated_p2 The negotiated P2 parameter, from the V.42bis spec. 00110 \param frame_handler Frame callback handler. 00111 \param frame_user_data An opaque pointer passed to the frame callback handler. 00112 \param max_frame_len The maximum length that should be passed to the frame handler. 00113 \param data_handler data callback handler. 00114 \param data_user_data An opaque pointer passed to the data callback handler. 00115 \param max_data_len The maximum length that should be passed to the data handler. 00116 \return The V.42bis context. */ 00117 SPAN_DECLARE(v42bis_state_t *) v42bis_init(v42bis_state_t *s, 00118 int negotiated_p0, 00119 int negotiated_p1, 00120 int negotiated_p2, 00121 v42bis_frame_handler_t frame_handler, 00122 void *frame_user_data, 00123 int max_frame_len, 00124 v42bis_data_handler_t data_handler, 00125 void *data_user_data, 00126 int max_data_len); 00127 00128 /*! Release a V.42bis context. 00129 \param s The V.42bis context. 00130 \return 0 if OK */ 00131 SPAN_DECLARE(int) v42bis_release(v42bis_state_t *s); 00132 00133 /*! Free a V.42bis context. 00134 \param s The V.42bis context. 00135 \return 0 if OK */ 00136 SPAN_DECLARE(int) v42bis_free(v42bis_state_t *s); 00137 00138 #if defined(__cplusplus) 00139 } 00140 #endif 00141 00142 #endif 00143 /*- End of file ------------------------------------------------------------*/