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