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 size_t wlsb_get_k_16bits(const struct c_wlsb *const wlsb,
103  const uint16_t value)
104  __attribute__((warn_unused_result, nonnull(1)));
105 size_t wlsb_get_mink_16bits(const struct c_wlsb *const wlsb,
106  const uint16_t value,
107  const size_t min_k)
108  __attribute__((warn_unused_result, nonnull(1)));
109 size_t wlsb_get_kp_16bits(const struct c_wlsb *const wlsb,
110  const uint16_t value,
111  const rohc_lsb_shift_t p)
112  __attribute__((warn_unused_result, nonnull(1)));
113 size_t wlsb_get_minkp_16bits(const struct c_wlsb *const wlsb,
114  const uint16_t value,
115  const size_t min_k,
116  const rohc_lsb_shift_t p)
117  __attribute__((warn_unused_result, nonnull(1)));
118 
119 size_t wlsb_get_k_32bits(const struct c_wlsb *const wlsb,
120  const uint32_t value)
121  __attribute__((warn_unused_result, nonnull(1)));
122 size_t wlsb_get_mink_32bits(const struct c_wlsb *const wlsb,
123  const uint32_t value,
124  const size_t min_k)
125  __attribute__((warn_unused_result, nonnull(1)));
126 size_t wlsb_get_kp_32bits(const struct c_wlsb *const wlsb,
127  const uint32_t value,
128  const rohc_lsb_shift_t p)
129  __attribute__((warn_unused_result, nonnull(1)));
130 
131 size_t wlsb_ack(struct c_wlsb *const wlsb,
132  const uint32_t sn_bits,
133  const size_t sn_bits_nr)
134  __attribute__((warn_unused_result, nonnull(1)));
135 
136 bool wlsb_is_sn_present(struct c_wlsb *const wlsb, const uint32_t sn)
137  __attribute__((warn_unused_result, nonnull(1)));
138 
139 #endif
140 
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:45
size_t next
Definition: comp_wlsb.h:64
size_t oldest
Definition: comp_wlsb.h:62
#define ROHC_WLSB_WIDTH_MAX
Definition: interval.h:33
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:226
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:518
uint32_t value
Definition: comp_wlsb.h:49
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
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:558
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:244
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:408
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:371
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:263
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:284
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:389
One W-LSB window entry.
Definition: comp_wlsb.h:44
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.