blob: 607a58e514ec8626a92cca418a26c0a176dbdafa [file] [log] [blame]
Philipp0b11db72016-08-01 18:13:40 +02001/*
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, 2011 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/*! \page v42bis_page V.42bis modem data compression
27\section v42bis_page_sec_1 What does it do?
28The v.42bis specification defines a data compression scheme, to work in
29conjunction with the error correction scheme defined in V.42.
30
31\section v42bis_page_sec_2 How does it work?
32*/
33
Philippd8b45772016-09-02 13:32:38 +020034#include <stdint.h>
35
Philipp0b11db72016-08-01 18:13:40 +020036#if !defined(_SPANDSP_V42BIS_H_)
37#define _SPANDSP_V42BIS_H_
38
Philippd8b45772016-09-02 13:32:38 +020039#define SPAN_DECLARE(x) x
40
Philipp0b11db72016-08-01 18:13:40 +020041#define V42BIS_MIN_STRING_SIZE 6
42#define V42BIS_MAX_STRING_SIZE 250
43#define V42BIS_MIN_DICTIONARY_SIZE 512
44#define V42BIS_MAX_BITS 12
45#define V42BIS_MAX_CODEWORDS 4096 /* 2^V42BIS_MAX_BITS */
46#define V42BIS_MAX_OUTPUT_LENGTH 1024
47
48enum
49{
50 V42BIS_P0_NEITHER_DIRECTION = 0,
51 V42BIS_P0_INITIATOR_RESPONDER,
52 V42BIS_P0_RESPONDER_INITIATOR,
53 V42BIS_P0_BOTH_DIRECTIONS
54};
55
56enum
57{
58 V42BIS_COMPRESSION_MODE_DYNAMIC = 0,
59 V42BIS_COMPRESSION_MODE_ALWAYS,
60 V42BIS_COMPRESSION_MODE_NEVER
61};
62
Philippd8b45772016-09-02 13:32:38 +020063typedef void (*put_msg_func_t)(void *user_data, const uint8_t *msg, int len);
64
Philipp0b11db72016-08-01 18:13:40 +020065/*!
66 V.42bis compression/decompression descriptor. This defines the working state for a
67 single instance of V.42bis compress/decompression.
68*/
69typedef struct v42bis_state_s v42bis_state_t;
70
71#if defined(__cplusplus)
72extern "C"
73{
74#endif
75
76/*! Compress a block of octets.
77 \param s The V.42bis context.
78 \param buf The data to be compressed.
79 \param len The length of the data buffer.
80 \return 0 */
81SPAN_DECLARE(int) v42bis_compress(v42bis_state_t *s, const uint8_t buf[], int len);
82
83/*! Flush out any data remaining in a compression buffer.
84 \param s The V.42bis context.
85 \return 0 */
86SPAN_DECLARE(int) v42bis_compress_flush(v42bis_state_t *s);
87
88/*! Decompress a block of octets.
89 \param s The V.42bis context.
90 \param buf The data to be decompressed.
91 \param len The length of the data buffer.
92 \return 0 */
93SPAN_DECLARE(int) v42bis_decompress(v42bis_state_t *s, const uint8_t buf[], int len);
94
95/*! Flush out any data remaining in the decompression buffer.
96 \param s The V.42bis context.
97 \return 0 */
98SPAN_DECLARE(int) v42bis_decompress_flush(v42bis_state_t *s);
99
100/*! Set the compression mode.
101 \param s The V.42bis context.
102 \param mode One of the V.42bis compression modes -
103 V42BIS_COMPRESSION_MODE_DYNAMIC,
104 V42BIS_COMPRESSION_MODE_ALWAYS,
105 V42BIS_COMPRESSION_MODE_NEVER */
106SPAN_DECLARE(void) v42bis_compression_control(v42bis_state_t *s, int mode);
107
108/*! Initialise a V.42bis context.
109 \param s The V.42bis context.
110 \param negotiated_p0 The negotiated P0 parameter, from the V.42bis spec.
111 \param negotiated_p1 The negotiated P1 parameter, from the V.42bis spec.
112 \param negotiated_p2 The negotiated P2 parameter, from the V.42bis spec.
113 \param encode_handler Encode callback handler.
114 \param encode_user_data An opaque pointer passed to the encode callback handler.
115 \param max_encode_len The maximum length that should be passed to the encode handler.
116 \param decode_handler Decode callback handler.
117 \param decode_user_data An opaque pointer passed to the decode callback handler.
118 \param max_decode_len The maximum length that should be passed to the decode handler.
119 \return The V.42bis context. */
Philippd8b45772016-09-02 13:32:38 +0200120SPAN_DECLARE(v42bis_state_t *) v42bis_init(const void *ctx,
121 v42bis_state_t *s,
Philipp0b11db72016-08-01 18:13:40 +0200122 int negotiated_p0,
123 int negotiated_p1,
124 int negotiated_p2,
125 put_msg_func_t encode_handler,
126 void *encode_user_data,
127 int max_encode_len,
128 put_msg_func_t decode_handler,
129 void *decode_user_data,
130 int max_decode_len);
131
132/*! Release a V.42bis context.
133 \param s The V.42bis context.
134 \return 0 if OK */
135SPAN_DECLARE(int) v42bis_release(v42bis_state_t *s);
136
137/*! Free a V.42bis context.
138 \param s The V.42bis context.
139 \return 0 if OK */
140SPAN_DECLARE(int) v42bis_free(v42bis_state_t *s);
141
142#if defined(__cplusplus)
143}
144#endif
145
146#endif
147/*- End of file ------------------------------------------------------------*/