1 |
pcg |
1.1 |
/* |
2 |
|
|
ROHC Project 2003 at Lulea University of Technology, Sweden. |
3 |
|
|
Authors: Andreas Vernersson <andver-8@student.luth.se> |
4 |
|
|
Daniel Pettersson <danpet-7@student.luth.se> |
5 |
|
|
Erik Soderstrom <soderstrom@yahoo.com> |
6 |
|
|
Fredrik Lindstrom <frelin-9@student.luth.se> |
7 |
|
|
Johan Stenmark <johste-8@student.luth.se> |
8 |
|
|
Martin Juhlin <juhlin@users.sourceforge.net> |
9 |
|
|
Mikael Larsson <larmik-9@student.luth.se> |
10 |
|
|
Robert Maxe <robmax-1@student.luth.se> |
11 |
|
|
|
12 |
|
|
Copyright (C) 2003 Andreas Vernersson, Daniel Pettersson, |
13 |
|
|
Erik Soderström, Fredrik Lindström, Johan Stenmark, |
14 |
|
|
Martin Juhlin, Mikael Larsson, Robert Maxe. |
15 |
|
|
|
16 |
|
|
This program is free software; you can redistribute it and/or modify |
17 |
|
|
it under the terms of the GNU General Public License as published by |
18 |
|
|
the Free Software Foundation; either version 2 of the License, or |
19 |
|
|
(at your option) any later version. |
20 |
|
|
|
21 |
|
|
This program is distributed in the hope that it will be useful, |
22 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
23 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
24 |
|
|
GNU General Public License for more details. |
25 |
|
|
|
26 |
|
|
You should have received a copy of the GNU General Public License |
27 |
|
|
along with this program; if not, write to the Free Software |
28 |
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
29 |
|
|
*/ |
30 |
|
|
/*************************************************************************** |
31 |
|
|
* File: c_util.h * |
32 |
|
|
* Description: utility functions for the compressor * |
33 |
|
|
***************************************************************************/ |
34 |
|
|
|
35 |
|
|
#ifndef _C_UTIL_H |
36 |
|
|
#define _C_UTIL_H |
37 |
|
|
|
38 |
|
|
#include "rohc.h" |
39 |
|
|
|
40 |
|
|
///////////////////////////////////////////////////////////////////// |
41 |
|
|
// W-LSB: Window based Least Significant Bits encoding |
42 |
|
|
|
43 |
|
|
struct sc_window { |
44 |
|
|
int sn; |
45 |
|
|
int time; |
46 |
|
|
int value; |
47 |
|
|
boolean used; |
48 |
|
|
}; |
49 |
|
|
|
50 |
|
|
struct sc_wlsb { |
51 |
|
|
int windowWidth; |
52 |
|
|
struct sc_window *window; // windowWidth number of sc_window.. |
53 |
|
|
|
54 |
|
|
int oldest; // points to the oldest entry in the window |
55 |
|
|
int next; // keeps track of the current position in the window |
56 |
|
|
|
57 |
|
|
int bits; |
58 |
|
|
int p; |
59 |
|
|
}; |
60 |
|
|
|
61 |
|
|
|
62 |
|
|
// Create new window.. |
63 |
|
|
struct sc_wlsb *c_create_wlsb(int bits, int windowWidth, int p); |
64 |
|
|
|
65 |
|
|
// Print window content |
66 |
|
|
void print_wlsb_stats(struct sc_wlsb * s); |
67 |
|
|
|
68 |
|
|
// Add value to window with the given sequence number and timestamp |
69 |
|
|
void c_add_wlsb(struct sc_wlsb *, int sn, int time, int value); |
70 |
|
|
|
71 |
|
|
// Get minimum number of bits necessary (k) of value needed for |
72 |
|
|
// decompressor to decode correctly |
73 |
|
|
int c_get_k_wlsb(struct sc_wlsb *, int value); |
74 |
|
|
|
75 |
|
|
// Acknowledge (remove older values) from window based on the sequence number |
76 |
|
|
void c_ack_sn_wlsb(struct sc_wlsb *, int sn); |
77 |
|
|
|
78 |
|
|
// Acknowledge (remove odler values) from window based on the timestamp |
79 |
|
|
void c_ack_time_wlsb(struct sc_wlsb *, int time); |
80 |
|
|
|
81 |
|
|
// Unallocate all memory used in the WLSB structure |
82 |
|
|
void c_destroy_wlsb(struct sc_wlsb *); |
83 |
|
|
|
84 |
|
|
// Calculate the sum of the values in window (used for a statistics window) |
85 |
|
|
int c_sum_wlsb(struct sc_wlsb *); |
86 |
|
|
|
87 |
|
|
// Calculate the mean-value in window (used for a statistics window) |
88 |
|
|
int c_mean_wlsb(struct sc_wlsb *); |
89 |
|
|
|
90 |
|
|
void c_print_wlsb(struct sc_wlsb *); |
91 |
|
|
|
92 |
|
|
///////////////////////////////////////////////////////////////////// |
93 |
|
|
// SDVL: Self Described Variable Length encoding |
94 |
|
|
|
95 |
|
|
// returns number of bytes needed to represent value |
96 |
|
|
int c_bytesSdvl(int value); |
97 |
|
|
|
98 |
|
|
// returns false if value is to big (value>2^29) |
99 |
|
|
boolean c_encodeSdvl(unsigned char *dest, int value); |
100 |
|
|
|
101 |
|
|
// returns add-cid value |
102 |
|
|
unsigned char c_add_cid(int cid); |
103 |
|
|
|
104 |
|
|
/* Function that sets the cid_values it will set the cids proper in the |
105 |
|
|
pointer dest, the function takes a pointer called first_position where you get the position |
106 |
|
|
to place your first byte, the second byte can be placed in the value that this function returns. |
107 |
|
|
*/ |
108 |
|
|
int code_cid_values(struct sc_context *context,unsigned char *dest,int max_size,int *first_position); |
109 |
|
|
|
110 |
|
|
///////////////////////////////////////////////////////////////////// |
111 |
|
|
// CRC |
112 |
|
|
|
113 |
|
|
#define CRC_TYPE_3 1 |
114 |
|
|
#define CRC_TYPE_7 2 |
115 |
|
|
#define CRC_TYPE_8 3 |
116 |
|
|
|
117 |
|
|
unsigned int crc_calculate(int type, unsigned char *, int length); |
118 |
|
|
int crc_get_polynom(int type); |
119 |
|
|
void crc_init_table(unsigned char *table, unsigned char polynum); |
120 |
|
|
|
121 |
|
|
#endif |