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 #include <stddef.h>
36 
37 
38 /*
39  * Public structures and types
40  */
41 
42 /**
43  * @brief One W-LSB window entry
44  */
45 struct c_window
46 {
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 /* compiler sanity check for C11-compliant compilers and GCC >= 4.6 */
53 #if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
54  (defined(__GNUC__) && defined(__GNUC_MINOR__) && \
55  (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))))
56 _Static_assert((offsetof(struct c_window, sn) % 8) == 0,
57  "sn in c_window should be aligned on 8 bytes");
58 _Static_assert((offsetof(struct c_window, value) % 4) == 0,
59  "value in c_window should be aligned on 4 bytes");
60 _Static_assert((sizeof(struct c_window) % 8) == 0,
61  "c_window length should be multiple of 8 bytes");
62 #endif
63 
64 
65 /**
66  * @brief One W-LSB encoding object
67  */
68 struct c_wlsb
69 {
70  /** The window in which previous values of the encoded value are stored */
71  struct c_window *window;
72 
73  /** The width of the window */
74  uint8_t window_width; /* TODO: R-mode needs a non-fixed window width */
75 
76  /** A pointer on the next entry in the window */
77  uint8_t next;
78 
79  /** The count of entries in the window */
80  uint8_t count;
81 
82 };
83 
84 /* compiler sanity check for C11-compliant compilers and GCC >= 4.6 */
85 #if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
86  (defined(__GNUC__) && defined(__GNUC_MINOR__) && \
87  (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))))
88 _Static_assert((offsetof(struct c_wlsb, window) % 8) == 0,
89  "window in c_wlsb should be aligned on 8 bytes");
90 _Static_assert((sizeof(struct c_wlsb) % 8) == 0,
91  "c_wlsb length should be multiple of 8 bytes");
92 #endif
93 
94 
95 
96 /*
97  * Public function prototypes:
98  */
99 
100 bool wlsb_new(struct c_wlsb *const wlsb,
101  const size_t window_width)
102  __attribute__((warn_unused_result, nonnull(1)));
103 bool wlsb_copy(struct c_wlsb *const dst,
104  const struct c_wlsb *const src)
105  __attribute__((warn_unused_result, nonnull(1, 2)));
106 void wlsb_free(struct c_wlsb *const wlsb)
107  __attribute__((nonnull(1)));
108 
109 void c_add_wlsb(struct c_wlsb *const wlsb,
110  const uint32_t sn,
111  const uint32_t value)
112  __attribute__((nonnull(1)));
113 
114 bool wlsb_is_kp_possible_8bits(const struct c_wlsb *const wlsb,
115  const uint8_t value,
116  const size_t k,
117  const rohc_lsb_shift_t p)
118  __attribute__((warn_unused_result, nonnull(1)));
119 
120 bool wlsb_is_kp_possible_16bits(const struct c_wlsb *const wlsb,
121  const uint16_t value,
122  const size_t k,
123  const rohc_lsb_shift_t p)
124  __attribute__((warn_unused_result, nonnull(1)));
125 
126 bool wlsb_is_kp_possible_32bits(const struct c_wlsb *const wlsb,
127  const uint32_t value,
128  const size_t k,
129  const rohc_lsb_shift_t p)
130  __attribute__((warn_unused_result, nonnull(1)));
131 
132 size_t wlsb_ack(struct c_wlsb *const wlsb,
133  const uint32_t sn_bits,
134  const size_t sn_bits_nr)
135  __attribute__((warn_unused_result, nonnull(1)));
136 
137 bool wlsb_is_sn_present(struct c_wlsb *const wlsb, const uint32_t sn)
138  __attribute__((warn_unused_result, nonnull(1)));
139 
140 #endif
141 
rohc_lsb_shift_t
the different values of the shift parameter of the LSB algorithm
Definition: interval.h:47
struct c_window * window
Definition: comp_wlsb.h:71
void wlsb_free(struct c_wlsb *const wlsb)
Destroy a Window-based LSB (W-LSB) encoding object.
Definition: comp_wlsb.c:116
uint8_t window_width
Definition: comp_wlsb.h:74
bool wlsb_new(struct c_wlsb *const wlsb, const size_t window_width)
Create a new Window-based Least Significant Bits (W-LSB) encoding object.
Definition: comp_wlsb.c:56
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:394
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:240
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:129
uint8_t next
Definition: comp_wlsb.h:77
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:164
One W-LSB encoding object.
Definition: comp_wlsb.h:68
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:446
bool wlsb_copy(struct c_wlsb *const dst, const struct c_wlsb *const src)
Create a new Window-based Least Significant Bits (W-LSB) encoding object from another.
Definition: comp_wlsb.c:88
bool nonnull(1)))
uint8_t count
Definition: comp_wlsb.h:80
One W-LSB window entry.
Definition: comp_wlsb.h:45
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:318
Compute the interpretation interval for LSB and W-LSB encoding.