ROHC compression/decompression library
interval.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011,2012,2013 Didier Barvaux
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /**
20  * @file interval.h
21  * @brief Compute the interpretation interval for LSB and W-LSB encoding
22  * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com>
23  */
24 
25 #ifndef ROHC_COMMON_INTERVAL_H
26 #define ROHC_COMMON_INTERVAL_H
27 
28 #include <rohc/rohc.h> /* for rohc_reordering_offset_t */
29 
30 #include <stdlib.h>
31 #include <stdint.h>
32 
33 
34 /** The maximum width of the W-LSB window (implementation specific) */
35 #define ROHC_WLSB_WIDTH_MAX UINT8_MAX
36 
37 
38 /**
39  * @brief the different values of the shift parameter of the LSB algorithm
40  *
41  * The shift parameter is also named 'p' in some RFCs.
42  *
43  * Some values are the real values to use directly. Some others are code
44  * that means that the real value to use shall be computed from the number
45  * of least significant bits that are transmitted.
46  */
47 typedef enum
48 {
49  ROHC_LSB_SHIFT_SN = -1, /**< real value for non-RTP SN */
50 #define ROHC_LSB_SHIFT_TCP_TS_1B ROHC_LSB_SHIFT_SN /**< real value for TCP TS */
51 #define ROHC_LSB_SHIFT_TCP_TS_2B ROHC_LSB_SHIFT_SN /**< real value for TCP TS */
52  ROHC_LSB_SHIFT_IP_ID = 0, /**< real value for IP-ID */
53  ROHC_LSB_SHIFT_TCP_TTL = 3, /**< real value for TCP TTL/HL */
54 #define ROHC_LSB_SHIFT_TCP_ACK_SCALED ROHC_LSB_SHIFT_TCP_TTL
55  ROHC_LSB_SHIFT_TCP_SN = 4, /**< real value for TCP MSN */
56  ROHC_LSB_SHIFT_TCP_SEQ_SCALED = 7, /**< real value for TCP seq/ack scaled */
57  ROHC_LSB_SHIFT_RTP_TS = 100, /**< need to compute real value for RTP TS */
58  ROHC_LSB_SHIFT_RTP_SN = 101, /**< need to compute real value for RTP SN */
59  ROHC_LSB_SHIFT_ESP_SN = 102, /**< need to compute real value for ESP SN */
60  ROHC_LSB_SHIFT_TCP_WINDOW = 16383, /**< real value for TCP window */
61  ROHC_LSB_SHIFT_TCP_TS_3B = 0x00040000, /**< real value for TCP TS */
62  ROHC_LSB_SHIFT_TCP_TS_4B = 0x04000000, /**< real value for TCP TS */
64 
65 
66 /**
67  * @brief An interval of 8-bit values
68  *
69  * Lower and upper bound values are always included in the interval.
70  *
71  * The upper bound may be greater that the lower bound of the interval if the
72  * interval straddles the interval boundaries.
73  *
74  * Example of interval that does not straddle field boundaries:
75  * [1, 3]
76  *
77  * Example of interval that straddles field boundaries (8-bit field):
78  * [250, 4]
79  */
81 {
82  uint8_t min; /**< The lower bound of the interval */
83  uint8_t max; /**< The upper bound of the interval */
84 };
85 
86 
87 /**
88  * @brief An interval of 16-bit values
89  *
90  * Lower and upper bound values are always included in the interval.
91  *
92  * The upper bound may be greater that the lower bound of the interval if the
93  * interval straddles the interval boundaries.
94  *
95  * Example of interval that does not straddle field boundaries:
96  * [1, 3]
97  *
98  * Example of interval that straddles field boundaries (16-bit field):
99  * [65530, 4]
100  */
102 {
103  uint16_t min; /**< The lower bound of the interval */
104  uint16_t max; /**< The upper bound of the interval */
105 };
106 
107 
108 /**
109  * @brief An interval of 32-bit values
110  *
111  * Lower and upper bound values are always included in the interval.
112  *
113  * The upper bound may be greater that the lower bound of the interval if the
114  * interval straddles the interval boundaries.
115  *
116  * Example of interval that does not straddle field boundaries:
117  * [1, 3]
118  *
119  * Example of interval that straddles field boundaries (32-bit field):
120  * [65530, 4]
121  */
123 {
124  uint32_t min; /**< The lower bound of the interval */
125  uint32_t max; /**< The upper bound of the interval */
126 };
127 
128 
129 /*
130  * Public function prototypes:
131  */
132 
133 static inline int32_t rohc_interval_compute_p(const size_t k,
134  const rohc_lsb_shift_t p)
135  __attribute__((warn_unused_result, const));
136 
137 struct rohc_interval32 rohc_f_32bits(const uint32_t v_ref,
138  const size_t k,
139  const rohc_lsb_shift_t p)
140  __attribute__((warn_unused_result, const));
141 
142 static inline int32_t rohc_interval_compute_p_rtp_ts(const size_t k)
143  __attribute__((warn_unused_result, const));
144 
145 static inline int32_t rohc_interval_compute_p_rtp_sn(const size_t k)
146  __attribute__((warn_unused_result, const));
147 
148 static inline int32_t rohc_interval_compute_p_esp_sn(const size_t k)
149  __attribute__((warn_unused_result, const));
150 
151 int32_t rohc_interval_get_rfc5225_msn_p(const size_t k,
152  rohc_reordering_offset_t reorder_ratio)
153  __attribute__((warn_unused_result, const));
154 
155 int32_t rohc_interval_get_rfc5225_id_id_p(const size_t k)
156  __attribute__((warn_unused_result, const));
157 
158 
159 /**
160  * @brief Compute the shift parameter p for the f function
161  *
162  * @param k The number of least significant bits of the value that are
163  * transmitted
164  * @param p The shift parameter (may be negative)
165  * @return The computed shift parameter p
166  */
167 static inline int32_t rohc_interval_compute_p(const size_t k,
168  const rohc_lsb_shift_t p)
169 {
170  int32_t computed_p;
171 
172  /* determine the real p value to use */
173  if(p == ROHC_LSB_SHIFT_RTP_TS)
174  {
175  /* special computation for RTP TS encoding */
176  computed_p = (k <= 2 ? 0 : (1 << (k - 2)) - 1);
177  }
178  else if(p == ROHC_LSB_SHIFT_RTP_SN || p == ROHC_LSB_SHIFT_ESP_SN)
179  {
180  /* special computation for RTP and ESP SN encoding */
181  computed_p = (k <= 4 ? 1 : (1 << (k - 5)) - 1);
182  }
183  else
184  {
185  /* otherwise: use the p value given as parameter */
186  computed_p = p;
187  }
188 
189  return computed_p;
190 }
191 
192 
193 /**
194  * @brief Compute the shift parameter p for the f function
195  *
196  * @param k The number of least significant bits of the value that are
197  * transmitted
198  * @return The computed shift parameter p
199  */
200 static inline int32_t rohc_interval_compute_p_rtp_ts(const size_t k)
201 {
202  return (k <= 2 ? 0 : (1 << (k - 2)) - 1);
203 }
204 
205 
206 /**
207  * @brief Compute the shift parameter p for the f function
208  *
209  * @param k The number of least significant bits of the value that are
210  * transmitted
211  * @return The computed shift parameter p
212  */
213 static inline int32_t rohc_interval_compute_p_rtp_sn(const size_t k)
214 {
215  return (k <= 4 ? 1 : (1 << (k - 5)) - 1);
216 }
217 
218 
219 /**
220  * @brief Compute the shift parameter p for the f function
221  *
222  * @param k The number of least significant bits of the value that are
223  * transmitted
224  * @return The computed shift parameter p
225  */
226 static inline int32_t rohc_interval_compute_p_esp_sn(const size_t k)
227 {
229 }
230 
231 #endif
232 
int32_t rohc_interval_get_rfc5225_msn_p(const size_t k, rohc_reordering_offset_t reorder_ratio)
Get shift parameter p from number of bytes k and reorder ratio.
Definition: interval.c:90
rohc_lsb_shift_t
the different values of the shift parameter of the LSB algorithm
Definition: interval.h:47
uint16_t min
Definition: interval.h:103
Definition: interval.h:62
rohc_reordering_offset_t
The different values of reordering offset.
Definition: rohc.h:204
Definition: interval.h:55
Definition: interval.h:61
An interval of 8-bit values.
Definition: interval.h:80
static int32_t rohc_interval_compute_p_rtp_ts(const size_t k)
Compute the shift parameter p for the f function.
Definition: interval.h:200
static int32_t rohc_interval_compute_p(const size_t k, const rohc_lsb_shift_t p)
Compute the shift parameter p for the f function.
Definition: interval.h:167
Definition: interval.h:52
An interval of 32-bit values.
Definition: interval.h:122
uint8_t max
Definition: interval.h:83
static int32_t rohc_interval_compute_p_esp_sn(const size_t k)
Compute the shift parameter p for the f function.
Definition: interval.h:226
Definition: interval.h:56
int32_t rohc_interval_get_rfc5225_id_id_p(const size_t k)
Get shift parameter p from number of bytes k for ip_id_lsb.
Definition: interval.c:124
uint8_t min
Definition: interval.h:82
static int32_t rohc_interval_compute_p_rtp_sn(const size_t k)
Compute the shift parameter p for the f function.
Definition: interval.h:213
struct rohc_interval32 rohc_f_32bits(const uint32_t v_ref, const size_t k, const rohc_lsb_shift_t p)
The f function as defined in LSB encoding for 32-bit fields.
Definition: interval.c:48
Definition: interval.h:57
Definition: interval.h:60
Definition: interval.h:58
Definition: interval.h:53
uint32_t max
Definition: interval.h:125
An interval of 16-bit values.
Definition: interval.h:101
uint16_t max
Definition: interval.h:104
uint32_t min
Definition: interval.h:124
Definition: interval.h:59
Definition: interval.h:49