comparison spandsp-0.0.3/spandsp-0.0.3/src/spandsp/v42bis.h @ 5:f762bf195c4b

import spandsp-0.0.3
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Fri, 25 Jun 2010 16:00:21 +0200
parents
children
comparison
equal deleted inserted replaced
4:26cd8f1ef0b1 5:f762bf195c4b
1 /*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * v42bis.h
5 *
6 * Written by Steve Underwood <steveu@coppice.org>
7 *
8 * Copyright (C) 2005 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 General Public License version 2, as
14 * 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 General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 * $Id: v42bis.h,v 1.15 2006/11/30 15:41:47 steveu Exp $
26 */
27
28 /*! \page v42bis_page V.42bis modem data compression
29 \section v42bis_page_sec_1 What does it do?
30 The v.42bis specification defines a data compression scheme, to work in
31 conjunction with the error correction scheme defined in V.42.
32
33 \section v42bis_page_sec_2 How does it work?
34 */
35
36 #if !defined(_V42BIS_H_)
37 #define _V42BIS_H_
38
39 #define V42BIS_MAX_BITS 12
40 #define V42BIS_MAX_CODEWORDS 4096 /* 2^V42BIS_MAX_BITS */
41 #define V42BIS_TABLE_SIZE 5021 /* This should be a prime >(2^V42BIS_MAX_BITS) */
42 #define V42BIS_MAX_STRING_SIZE 250
43
44 enum
45 {
46 V42BIS_P0_NEITHER_DIRECTION = 0,
47 V42BIS_P0_INITIATOR_RESPONDER,
48 V42BIS_P0_RESPONDER_INITIATOR,
49 V42BIS_P0_BOTH_DIRECTIONS
50 };
51
52 enum
53 {
54 V42BIS_COMPRESSION_MODE_DYNAMIC = 0,
55 V42BIS_COMPRESSION_MODE_ALWAYS,
56 V42BIS_COMPRESSION_MODE_NEVER
57 };
58
59 typedef void (*v42bis_frame_handler_t)(void *user_data, const uint8_t *pkt, int len);
60 typedef void (*v42bis_data_handler_t)(void *user_data, const uint8_t *buf, int len);
61
62 typedef struct
63 {
64 /*! \brief The prior code for each defined code. */
65 uint16_t parent_code;
66 /*! \brief The number of leaf nodes this node has */
67 int16_t leaves;
68 /*! \brief This leaf octet for each defined code. */
69 uint8_t node_octet;
70 /*! \brief Bit map of the children which exist */
71 uint32_t children[8];
72 } v42bis_dict_node_t;
73
74 typedef struct
75 {
76 /*! \brief Compression mode. */
77 int compression_mode;
78 /*! \brief Callback function to handle received frames. */
79 v42bis_frame_handler_t handler;
80 /*! \brief An opaque pointer passed in calls to frame_handler. */
81 void *user_data;
82 /*! \brief The maximum frame length allowed */
83 int max_len;
84
85 uint32_t string_code;
86 uint32_t latest_code;
87 int string_length;
88 uint32_t output_bit_buffer;
89 int output_bit_count;
90 int output_octet_count;
91 uint8_t output_buf[1024];
92 v42bis_dict_node_t dict[V42BIS_MAX_CODEWORDS];
93 /*! \brief TRUE if we are in transparent (i.e. uncompressable) mode */
94 int transparent;
95 int change_transparency;
96 int compressibility_filter;
97 int compressibility_persistence;
98
99 /*! \brief Next empty dictionary entry */
100 uint32_t v42bis_parm_c1;
101 /*! \brief Current codeword size */
102 int v42bis_parm_c2;
103 /*! \brief Threshold for codeword size change */
104 uint32_t v42bis_parm_c3;
105
106 /*! \brief Mark that this is the first octet/code to be processed */
107 int first;
108 uint8_t escape_code;
109 } v42bis_compress_state_t;
110
111 typedef struct
112 {
113 /*! \brief Callback function to handle decompressed data. */
114 v42bis_data_handler_t handler;
115 /*! \brief An opaque pointer passed in calls to data_handler. */
116 void *user_data;
117 /*! \brief The maximum decompressed data block length allowed */
118 int max_len;
119
120 uint32_t old_code;
121 uint32_t last_old_code;
122 uint32_t input_bit_buffer;
123 int input_bit_count;
124 int octet;
125 int last_length;
126 int output_octet_count;
127 uint8_t output_buf[1024];
128 v42bis_dict_node_t dict[V42BIS_MAX_CODEWORDS];
129 /*! \brief TRUE if we are in transparent (i.e. uncompressable) mode */
130 int transparent;
131
132 int last_extra_octet;
133
134 /*! \brief Next empty dictionary entry */
135 int v42bis_parm_c1;
136 /*! \brief Current codeword size */
137 int v42bis_parm_c2;
138 /*! \brief Threshold for codeword size change */
139 int v42bis_parm_c3;
140
141 /*! \brief Mark that this is the first octet/code to be processed */
142 int first;
143 uint8_t escape_code;
144 int escaped;
145 } v42bis_decompress_state_t;
146
147 /*!
148 V.42bis compression/decompression descriptor. This defines the working state for a
149 single instance of V.42bis compress/decompression.
150 */
151 typedef struct
152 {
153 /*! \brief V.42bis data compression directions. */
154 int v42bis_parm_p0;
155
156 v42bis_compress_state_t compress;
157 v42bis_decompress_state_t decompress;
158
159 /*! \brief Maximum codeword size (bits) */
160 int v42bis_parm_n1;
161 /*! \brief Total number of codewords */
162 uint32_t v42bis_parm_n2;
163 /*! \brief Maximum string length */
164 int v42bis_parm_n7;
165 } v42bis_state_t;
166
167 #ifdef __cplusplus
168 extern "C" {
169 #endif
170
171 /*! Compress a block of octets.
172 \param s The V.42bis context.
173 \param buf The data to be compressed.
174 \param len The length of the data buffer.
175 \return 0 */
176 int v42bis_compress(v42bis_state_t *s, const uint8_t *buf, int len);
177
178 /*! Flush out any data remaining in a compression buffer.
179 \param s The V.42bis context.
180 \return 0 */
181 int v42bis_compress_flush(v42bis_state_t *s);
182
183 /*! Decompress a block of octets.
184 \param s The V.42bis context.
185 \param buf The data to be decompressed.
186 \param len The length of the data buffer.
187 \return 0 */
188 int v42bis_decompress(v42bis_state_t *s, const uint8_t *buf, int len);
189
190 /*! Flush out any data remaining in the decompression buffer.
191 \param s The V.42bis context.
192 \return 0 */
193 int v42bis_decompress_flush(v42bis_state_t *s);
194
195 /*! Initialise a V.42bis context.
196 \param s The V.42bis context.
197 \param negotiated_p0 The negotiated P0 parameter, from the V.42bis spec.
198 \param negotiated_p1 The negotiated P1 parameter, from the V.42bis spec.
199 \param negotiated_p2 The negotiated P2 parameter, from the V.42bis spec.
200 \param frame_handler .
201 \param frame_user_data .
202 \param max_frame_len The maximum length that should be passed to the frame handler.
203 \param data_handler .
204 \param data_user_data .
205 \param max_data_len The maximum length that should be passed to the data handler.
206 \return The V.42bis context. */
207 v42bis_state_t *v42bis_init(v42bis_state_t *s,
208 int negotiated_p0,
209 int negotiated_p1,
210 int negotiated_p2,
211 v42bis_frame_handler_t frame_handler,
212 void *frame_user_data,
213 int max_frame_len,
214 v42bis_data_handler_t data_handler,
215 void *data_user_data,
216 int max_data_len);
217
218 /*! Set the compression mode.
219 \param s The V.42bis context.
220 \param mode One of the V.42bis compression modes -
221 V42BIS_COMPRESSION_MODE_DYNAMIC,
222 V42BIS_COMPRESSION_MODE_ALWAYS,
223 V42BIS_COMPRESSION_MODE_NEVER */
224 void v42bis_compression_control(v42bis_state_t *s, int mode);
225
226 /*! Release a V.42bis context.
227 \param s The V.42bis context.
228 \return 0 if OK */
229 int v42bis_release(v42bis_state_t *s);
230
231 #ifdef __cplusplus
232 }
233 #endif
234
235 #endif
236 /*- End of file ------------------------------------------------------------*/

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.