ROHC compression/decompression library
decomp_wlsb.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011,2012,2013 Didier Barvaux
3  * Copyright 2007,2009,2010,2013 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/decomp_wlsb.h
22  * @brief Window-based Least Significant Bits (W-LSB) decoding
23  * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com>
24  * @author Didier Barvaux <didier@barvaux.org>
25  */
26 
27 #ifndef ROHC_DECOMP_SCHEMES_WLSB_H
28 #define ROHC_DECOMP_SCHEMES_WLSB_H
29 
30 #include "interval.h" /* for rohc_lsb_shift_t */
31 #include "rohc_internal.h" /* for bits_nr_t */
32 
33 #include <stdlib.h>
34 #include <stdint.h>
35 #include <stddef.h>
36 #include <stdbool.h>
37 
38 
39 /*
40  * Public structures and types
41  */
42 
43 
44 /** The different reference values for LSB decoding */
45 typedef enum
46 {
47  ROHC_LSB_REF_MINUS_1 = 0, /**< Use the 'ref -1' reference value */
48  ROHC_LSB_REF_0 = 1, /**< Use the 'ref 0' reference value */
49  ROHC_LSB_REF_MAX /**< The number of different reference values */
50 
52 
53 
54 /**
55  * @brief The Least Significant Bits (LSB) decoding object
56  *
57  * See RFC 3095, ยง4.5.1
58  */
60 {
61  /** The reference values (ref -1 and ref 0) */
63 
64  bool is_init; /**< Whether the reference value was initialized */
65  uint8_t max_len; /**< The max length (in bits) of the uncomp. field */
66  uint8_t unused[6];
67 };
68 
69 /* compiler sanity check for C11-compliant compilers and GCC >= 4.6 */
70 #if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
71  (defined(__GNUC__) && defined(__GNUC_MINOR__) && \
72  (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))))
73 _Static_assert((offsetof(struct rohc_lsb_decode, v_ref_d) % 8) == 0,
74  "v_ref_d in rohc_lsb_decode should be aligned on 8 bytes");
75 _Static_assert((sizeof(struct rohc_lsb_decode) % 8) == 0,
76  "rohc_lsb_decode length should be multiple of 8 bytes");
77 #endif
78 
79 
80 /** The context to parse and decode one LSB-encoded 32-bit field */
82 {
83  rohc_lsb_shift_t p; /**< The LSB shift parameter to decode extracted bits */
84  uint32_t bits; /**< The bits extracted from the ROHC packet */
85  bits_nr_t bits_nr; /**< The number of bits extracted from the ROHC packet */
86  uint8_t unused[7];
87 };
88 
89 /* compiler sanity check for C11-compliant compilers and GCC >= 4.6 */
90 #if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
91  (defined(__GNUC__) && defined(__GNUC_MINOR__) && \
92  (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))))
93 _Static_assert((sizeof(struct rohc_lsb_field32) % 8) == 0,
94  "rohc_lsb_field32 length should be multiple of 8 bytes");
95 #endif
96 
97 
98 /** The context to parse and decode one LSB-encoded 16-bit field */
100 {
101  rohc_lsb_shift_t p; /**< The LSB shift parameter to decode extracted bits */
102  uint16_t bits; /**< The bits extracted from the ROHC packet */
103  bits_nr_t bits_nr; /**< The number of bits extracted from the ROHC packet */
104  uint8_t unused[1];
105 };
106 
107 /* compiler sanity check for C11-compliant compilers and GCC >= 4.6 */
108 #if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
109  (defined(__GNUC__) && defined(__GNUC_MINOR__) && \
110  (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))))
111 _Static_assert((sizeof(struct rohc_lsb_field16) % 8) == 0,
112  "rohc_lsb_field16 length should be multiple of 8 bytes");
113 #endif
114 
115 
116 /** The context to parse and decode one LSB-encoded 8-bit field */
118 {
119  rohc_lsb_shift_t p; /**< The LSB shift parameter to decode extracted bits */
120  uint8_t bits; /**< The bits extracted from the ROHC packet */
121  bits_nr_t bits_nr; /**< The number of bits extracted from the ROHC packet */
122  uint8_t unused[2];
123 };
124 
125 /* compiler sanity check for C11-compliant compilers and GCC >= 4.6 */
126 #if ((defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
127  (defined(__GNUC__) && defined(__GNUC_MINOR__) && \
128  (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6))))
129 _Static_assert((sizeof(struct rohc_lsb_field8) % 8) == 0,
130  "rohc_lsb_field8 length should be multiple of 8 bytes");
131 #endif
132 
133 
134 /*
135  * Function prototypes
136  */
137 
138 void rohc_lsb_init(struct rohc_lsb_decode *const lsb, const size_t max_len)
139  __attribute__((nonnull(1)));
140 
141 bool rohc_lsb_is_ready(const struct rohc_lsb_decode *const lsb)
142  __attribute__((warn_unused_result, nonnull(1), pure));
143 
144 bool rohc_lsb_decode(const struct rohc_lsb_decode *const lsb,
145  const rohc_lsb_ref_t ref_type,
146  const uint32_t v_ref_d_offset,
147  const uint32_t m,
148  const size_t k,
149  const rohc_lsb_shift_t p,
150  uint32_t *const decoded)
151  __attribute__((warn_unused_result, nonnull(1, 7)));
152 
153 void rohc_lsb_set_ref(struct rohc_lsb_decode *const lsb,
154  const uint32_t v_ref_d,
155  const bool keep_ref_minus_1)
156  __attribute__((nonnull(1)));
157 
158 uint32_t rohc_lsb_get_ref(const struct rohc_lsb_decode *const lsb,
159  const rohc_lsb_ref_t ref_type)
160  __attribute__((nonnull(1), warn_unused_result));
161 
162 #endif
163 
rohc_lsb_shift_t
the different values of the shift parameter of the LSB algorithm
Definition: interval.h:47
void rohc_lsb_init(struct rohc_lsb_decode *const lsb, const size_t max_len)
Initialize a given Least Significant Bits (LSB) decoding context.
Definition: decomp_wlsb.c:78
Definition: decomp_wlsb.h:47
bool is_init
Definition: decomp_wlsb.h:64
Definition: decomp_wlsb.h:99
uint32_t v_ref_d[ROHC_LSB_REF_MAX]
Definition: decomp_wlsb.h:62
Definition: decomp_wlsb.h:48
uint16_t bits
Definition: decomp_wlsb.h:102
uint8_t bits
Definition: decomp_wlsb.h:120
The Least Significant Bits (LSB) decoding object.
Definition: decomp_wlsb.h:59
Definition: decomp_wlsb.h:49
Definition: decomp_wlsb.h:117
uint8_t max_len
Definition: decomp_wlsb.h:65
uint32_t rohc_lsb_get_ref(const struct rohc_lsb_decode *const lsb, const rohc_lsb_ref_t ref_type)
Get the current LSB reference value (ref 0)
Definition: decomp_wlsb.c:385
bool nonnull(1)))
uint8_t unused[6]
Definition: decomp_wlsb.h:66
uint32_t bits
Definition: decomp_wlsb.h:84
uint8_t unused[2]
Definition: decomp_wlsb.h:122
bits_nr_t bits_nr
Definition: decomp_wlsb.h:103
uint8_t unused[7]
Definition: decomp_wlsb.h:86
bits_nr_t bits_nr
Definition: decomp_wlsb.h:85
Definition: decomp_wlsb.h:81
rohc_lsb_shift_t p
Definition: decomp_wlsb.h:83
uint8_t bits_nr_t
A number of bits required or retrieved.
Definition: rohc_internal.h:205
rohc_lsb_ref_t
Definition: decomp_wlsb.h:45
ROHC private common definitions and routines.
rohc_lsb_shift_t p
Definition: decomp_wlsb.h:101
bool rohc_lsb_decode(const struct rohc_lsb_decode *const lsb, const rohc_lsb_ref_t ref_type, const uint32_t v_ref_d_offset, const uint32_t m, const size_t k, const rohc_lsb_shift_t p, uint32_t *const decoded)
Decode a LSB-encoded value.
Definition: decomp_wlsb.c:116
bits_nr_t bits_nr
Definition: decomp_wlsb.h:121
rohc_lsb_shift_t p
Definition: decomp_wlsb.h:119
bool rohc_lsb_is_ready(const struct rohc_lsb_decode *const lsb)
Is the LSB decoding context ready to decode a compressed value.
Definition: decomp_wlsb.c:93
uint8_t unused[1]
Definition: decomp_wlsb.h:104
void rohc_lsb_set_ref(struct rohc_lsb_decode *const lsb, const uint32_t v_ref_d, const bool keep_ref_minus_1)
Update the LSB reference value.
Definition: decomp_wlsb.c:361
Compute the interpretation interval for LSB and W-LSB encoding.