ROHC compression/decompression library
comp_wlsb.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011,2012,2013 Didier Barvaux
3  * Copyright 2007,2009,2010 Viveris Technologies
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 /**
21  * @file schemes/comp_wlsb.h
22  * @brief Window-based Least Significant Bits (W-LSB) encoding
23  * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com>
24  * @author David Moreau from TAS
25  */
26 
27 #ifndef ROHC_COMP_SCHEMES_WLSB_H
28 #define ROHC_COMP_SCHEMES_WLSB_H
29 
30 #include "interval.h" /* for rohc_lsb_shift_t */
31 
32 #include <stdlib.h>
33 #include <stdint.h>
34 #include <stdbool.h>
35 
36 
37 /*
38  * Public structures and types
39  */
40 
41 /**
42  * @brief One W-LSB window entry
43  */
44 struct c_window
45 {
46  bool used; /**< Whether the window entry is used or not */
47  uint32_t sn; /**< The Sequence Number (SN) associated with the entry
48  (used to acknowledge the entry) */
49  uint32_t value; /**< The value stored in the window entry */
50 };
51 
52 
53 /**
54  * @brief One W-LSB encoding object
55  */
56 struct c_wlsb
57 {
58  /** The width of the window */
59  size_t window_width; /* TODO: R-mode needs a non-fixed window width */
60 
61  /** A pointer on the oldest entry in the window (change on acknowledgement) */
62  size_t oldest;
63  /** A pointer on the current entry in the window (change on add and ack) */
64  size_t next;
65 
66  /** The count of entries in the window */
67  size_t count;
68 
69  /** The maximal number of bits for representing the value */
70  size_t bits;
71  /** The shift parameter (see 4.5.2 in the RFC 3095) */
73 
74  /** The window in which previous values of the encoded value are stored */
75  struct c_window window[ROHC_WLSB_WIDTH_MAX];
76 };
77 
78 
79 /*
80  * Public function prototypes:
81  */
82 
83 void wlsb_init(struct c_wlsb *const wlsb,
84  const size_t bits,
85  const size_t window_width,
86  const rohc_lsb_shift_t p)
87  __attribute__((nonnull(1)));
88 
89 void c_add_wlsb(struct c_wlsb *const wlsb,
90  const uint32_t sn,
91  const uint32_t value)
92  __attribute__((nonnull(1)));
93 
94 size_t wlsb_get_k_8bits(const struct c_wlsb *const wlsb,
95  const uint8_t value)
96  __attribute__((warn_unused_result, nonnull(1)));
97 size_t wlsb_get_kp_8bits(const struct c_wlsb *const wlsb,
98  const uint8_t value,
99  const rohc_lsb_shift_t p)
100  __attribute__((warn_unused_result, nonnull(1)));
101 
102 bool wlsb_is_kp_possible_8bits(const struct c_wlsb *const wlsb,
103  const uint8_t value,
104  const size_t k,
105  const rohc_lsb_shift_t p)
106  __attribute__((warn_unused_result, nonnull(1)));
107 
108 size_t wlsb_get_k_16bits(const struct c_wlsb *const wlsb,
109  const uint16_t value)
110  __attribute__((warn_unused_result, nonnull(1)));
111 size_t wlsb_get_mink_16bits(const struct c_wlsb *const wlsb,
112  const uint16_t value,
113  const size_t min_k)
114  __attribute__((warn_unused_result, nonnull(1)));
115 size_t wlsb_get_kp_16bits(const struct c_wlsb *const wlsb,
116  const uint16_t value,
117  const rohc_lsb_shift_t p)
118  __attribute__((warn_unused_result, nonnull(1)));
119 size_t wlsb_get_minkp_16bits(const struct c_wlsb *const wlsb,
120  const uint16_t value,
121  const size_t min_k,
122  const rohc_lsb_shift_t p)
123  __attribute__((warn_unused_result, nonnull(1)));
124 
125 bool wlsb_is_kp_possible_16bits(const struct c_wlsb *const wlsb,
126  const uint16_t value,
127  const size_t k,
128  const rohc_lsb_shift_t p)
129  __attribute__((warn_unused_result, nonnull(1)));
130 
131 size_t wlsb_get_k_32bits(const struct c_wlsb *const wlsb,
132  const uint32_t value)
133  __attribute__((warn_unused_result, nonnull(1)));
134 size_t wlsb_get_mink_32bits(const struct c_wlsb *const wlsb,
135  const uint32_t value,
136  const size_t min_k)
137  __attribute__((warn_unused_result, nonnull(1)));
138 size_t wlsb_get_kp_32bits(const struct c_wlsb *const wlsb,
139  const uint32_t value,
140  const rohc_lsb_shift_t p)
141  __attribute__((warn_unused_result, nonnull(1)));
142 
143 bool wlsb_is_kp_possible_32bits(const struct c_wlsb *const wlsb,
144  const uint32_t value,
145  const size_t k,
146  const rohc_lsb_shift_t p)
147  __attribute__((warn_unused_result, nonnull(1)));
148 
149 size_t wlsb_ack(struct c_wlsb *const wlsb,
150  const uint32_t sn_bits,
151  const size_t sn_bits_nr)
152  __attribute__((warn_unused_result, nonnull(1)));
153 
154 bool wlsb_is_sn_present(struct c_wlsb *const wlsb, const uint32_t sn)
155  __attribute__((warn_unused_result, nonnull(1)));
156 
157 #endif
158 
bool used
Definition: comp_wlsb.h:46
rohc_lsb_shift_t
the different values of the shift parameter of the LSB algorithm
Definition: interval.h:47
size_t next
Definition: comp_wlsb.h:64
size_t oldest
Definition: comp_wlsb.h:62
#define ROHC_WLSB_WIDTH_MAX
Definition: interval.h:35
size_t wlsb_get_k_16bits(const struct c_wlsb *const wlsb, const uint16_t value)
Find out the minimal number of bits of the to-be-encoded value required to be able to uniquely recrea...
Definition: comp_wlsb.c:311
size_t bits
Definition: comp_wlsb.h:70
size_t wlsb_ack(struct c_wlsb *const wlsb, const uint32_t sn_bits, const size_t sn_bits_nr)
Acknowledge based on the Sequence Number (SN)
Definition: comp_wlsb.c:769
uint32_t value
Definition: comp_wlsb.h:49
bool wlsb_is_kp_possible_16bits(const struct c_wlsb *const wlsb, const uint16_t value, const size_t k, const rohc_lsb_shift_t p)
Find out whether the given number of bits is enough to encode value.
Definition: comp_wlsb.c:457
uint32_t sn
Definition: comp_wlsb.h:47
void c_add_wlsb(struct c_wlsb *const wlsb, const uint32_t sn, const uint32_t value)
Add a value into a W-LSB encoding object.
Definition: comp_wlsb.c:96
rohc_lsb_shift_t p
Definition: comp_wlsb.h:72
size_t count
Definition: comp_wlsb.h:67
bool wlsb_is_kp_possible_8bits(const struct c_wlsb *const wlsb, const uint8_t value, const size_t k, const rohc_lsb_shift_t p)
Find out whether the given number of bits is enough to encode value.
Definition: comp_wlsb.c:227
One W-LSB encoding object.
Definition: comp_wlsb.h:56
bool wlsb_is_sn_present(struct c_wlsb *const wlsb, const uint32_t sn)
Whether the given SN is present in the given WLSB window.
Definition: comp_wlsb.c:809
size_t wlsb_get_mink_16bits(const struct c_wlsb *const wlsb, const uint16_t value, const size_t min_k)
Find out the minimal number of bits of the to-be-encoded value required to be able to uniquely recrea...
Definition: comp_wlsb.c:329
size_t wlsb_get_kp_32bits(const struct c_wlsb *const wlsb, const uint32_t value, const rohc_lsb_shift_t p)
Find out the minimal number of bits of the to-be-encoded value required to be able to uniquely recrea...
Definition: comp_wlsb.c:574
size_t window_width
Definition: comp_wlsb.h:59
void wlsb_init(struct c_wlsb *const wlsb, const size_t bits, const size_t window_width, const rohc_lsb_shift_t p)
Initialize the given W-LSB encoding object.
Definition: comp_wlsb.c:64
size_t wlsb_get_k_8bits(const struct c_wlsb *const wlsb, const uint8_t value)
Find out the minimal number of bits of the to-be-encoded value required to be able to uniquely recrea...
Definition: comp_wlsb.c:127
size_t wlsb_get_k_32bits(const struct c_wlsb *const wlsb, const uint32_t value)
Find out the minimal number of bits of the to-be-encoded value required to be able to uniquely recrea...
Definition: comp_wlsb.c:537
size_t wlsb_get_kp_16bits(const struct c_wlsb *const wlsb, const uint16_t value, const rohc_lsb_shift_t p)
Find out the minimal number of bits of the to-be-encoded value required to be able to uniquely recrea...
Definition: comp_wlsb.c:348
size_t wlsb_get_minkp_16bits(const struct c_wlsb *const wlsb, const uint16_t value, const size_t min_k, const rohc_lsb_shift_t p)
Find out the minimal number of bits of the to-be-encoded value required to be able to uniquely recrea...
Definition: comp_wlsb.c:369
size_t wlsb_get_mink_32bits(const struct c_wlsb *const wlsb, const uint32_t value, const size_t min_k)
Find out the minimal number of bits of the to-be-encoded value required to be able to uniquely recrea...
Definition: comp_wlsb.c:555
One W-LSB window entry.
Definition: comp_wlsb.h:44
bool wlsb_is_kp_possible_32bits(const struct c_wlsb *const wlsb, const uint32_t value, const size_t k, const rohc_lsb_shift_t p)
Find out whether the given number of bits is enough to encode value.
Definition: comp_wlsb.c:684
size_t wlsb_get_kp_8bits(const struct c_wlsb *const wlsb, const uint8_t value, const rohc_lsb_shift_t p)
Find out the minimal number of bits of the to-be-encoded value required to be able to uniquely recrea...
Definition: comp_wlsb.c:144
Compute the interpretation interval for LSB and W-LSB encoding.