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 <stdlib.h>
29 #include <stdint.h>
30 #include <assert.h>
31 
32 
33 /**
34  * @brief the different values of the shift parameter of the LSB algorithm
35  *
36  * The shift parameter is also named 'p' in some RFCs.
37  *
38  * Some values are the real values to use directly. Some others are code
39  * that means that the real value to use shall be computed from the number
40  * of least significant bits that are transmitted.
41  */
42 typedef enum
43 {
44  ROHC_LSB_SHIFT_SN = -1, /**< real value for non-RTP SN */
45 #define ROHC_LSB_SHIFT_TCP_TS_1B ROHC_LSB_SHIFT_SN /**< real value for TCP TS */
46 #define ROHC_LSB_SHIFT_TCP_TS_2B ROHC_LSB_SHIFT_SN /**< real value for TCP TS */
47  ROHC_LSB_SHIFT_IP_ID = 0, /**< real value for IP-ID */
48  ROHC_LSB_SHIFT_TCP_TTL = 3, /**< real value for TCP TTL/HL */
49 #define ROHC_LSB_SHIFT_TCP_ACK_SCALED ROHC_LSB_SHIFT_TCP_TTL
50  ROHC_LSB_SHIFT_TCP_SN = 4, /**< real value for TCP MSN */
51  ROHC_LSB_SHIFT_TCP_SEQ_SCALED = 7, /**< real value for TCP seq/ack scaled */
52  ROHC_LSB_SHIFT_RTP_TS = 100, /**< need to compute real value for RTP TS */
53  ROHC_LSB_SHIFT_RTP_SN = 101, /**< need to compute real value for RTP SN */
54  ROHC_LSB_SHIFT_ESP_SN = 102, /**< need to compute real value for ESP SN */
55  ROHC_LSB_SHIFT_VAR = 103, /**< real value is variable */
56  ROHC_LSB_SHIFT_TCP_WINDOW = 16383, /**< real value for TCP window */
57  ROHC_LSB_SHIFT_TCP_TS_3B = 0x00040000, /**< real value for TCP TS */
58  ROHC_LSB_SHIFT_TCP_TS_4B = 0x04000000, /**< real value for TCP TS */
60 
61 
62 /**
63  * @brief An interval of 8-bit values
64  *
65  * Lower and upper bound values are always included in the interval.
66  *
67  * The upper bound may be greater that the lower bound of the interval if the
68  * interval straddles the interval boundaries.
69  *
70  * Example of interval that does not straddle field boundaries:
71  * [1, 3]
72  *
73  * Example of interval that straddles field boundaries (8-bit field):
74  * [250, 4]
75  */
77 {
78  uint8_t min; /**< The lower bound of the interval */
79  uint8_t max; /**< The upper bound of the interval */
80 };
81 
82 
83 /**
84  * @brief An interval of 16-bit values
85  *
86  * Lower and upper bound values are always included in the interval.
87  *
88  * The upper bound may be greater that the lower bound of the interval if the
89  * interval straddles the interval boundaries.
90  *
91  * Example of interval that does not straddle field boundaries:
92  * [1, 3]
93  *
94  * Example of interval that straddles field boundaries (16-bit field):
95  * [65530, 4]
96  */
98 {
99  uint16_t min; /**< The lower bound of the interval */
100  uint16_t max; /**< The upper bound of the interval */
101 };
102 
103 
104 /**
105  * @brief An interval of 32-bit values
106  *
107  * Lower and upper bound values are always included in the interval.
108  *
109  * The upper bound may be greater that the lower bound of the interval if the
110  * interval straddles the interval boundaries.
111  *
112  * Example of interval that does not straddle field boundaries:
113  * [1, 3]
114  *
115  * Example of interval that straddles field boundaries (32-bit field):
116  * [65530, 4]
117  */
119 {
120  uint32_t min; /**< The lower bound of the interval */
121  uint32_t max; /**< The upper bound of the interval */
122 };
123 
124 
125 /*
126  * Public function prototypes:
127  */
128 
129 static inline int32_t rohc_interval_compute_p(const size_t k,
130  const rohc_lsb_shift_t p)
131  __attribute__((warn_unused_result, const));
132 
133 struct rohc_interval8 rohc_f_8bits(const uint8_t v_ref,
134  const size_t k,
135  const rohc_lsb_shift_t p)
136  __attribute__((warn_unused_result));
137 
138 struct rohc_interval16 rohc_f_16bits(const uint16_t v_ref,
139  const size_t k,
140  const rohc_lsb_shift_t p)
141  __attribute__((warn_unused_result));
142 
143 struct rohc_interval32 rohc_f_32bits(const uint32_t v_ref,
144  const size_t k,
145  const rohc_lsb_shift_t p)
146  __attribute__((warn_unused_result));
147 
148 
149 /**
150  * @brief Compute the shift parameter p for the f function
151  *
152  * @param k The number of least significant bits of the value that are
153  * transmitted
154  * @param p The shift parameter (may be negative)
155  * @return The computed shift parameter p
156  */
157 static inline int32_t rohc_interval_compute_p(const size_t k,
158  const rohc_lsb_shift_t p)
159 {
160  int32_t computed_p;
161 
162  /* determine the real p value to use */
163  switch(p)
164  {
165  case ROHC_LSB_SHIFT_RTP_TS: /* special computation for RTP TS encoding */
166  {
167  if(k <= 2)
168  {
169  computed_p = 0;
170  }
171  else
172  {
173  computed_p = (1 << (k - 2)) - 1;
174  }
175  }
176  break;
177 
178  /* special computation for RTP and ESP SN encoding */
181  {
182  if(k <= 4)
183  {
184  computed_p = 1;
185  }
186  else
187  {
188  computed_p = (1 << (k - 5)) - 1;
189  }
190  }
191  break;
192 
193  case ROHC_LSB_SHIFT_VAR:
194  assert(0); /* should not happen */
195  computed_p = p;
196  break;
197 
198  case ROHC_LSB_SHIFT_SN:
206  default: /* otherwise: use the p value given as parameter */
207  {
208  computed_p = p;
209  }
210  }
211 
212  return computed_p;
213 }
214 
215 #endif
216 
rohc_lsb_shift_t
the different values of the shift parameter of the LSB algorithm
Definition: interval.h:42
Definition: interval.h:55
uint16_t min
Definition: interval.h:99
Definition: interval.h:58
Definition: interval.h:50
Definition: interval.h:57
An interval of 8-bit values.
Definition: interval.h:76
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:157
Definition: interval.h:47
An interval of 32-bit values.
Definition: interval.h:118
uint8_t max
Definition: interval.h:79
Definition: interval.h:51
struct rohc_interval8 rohc_f_8bits(const uint8_t v_ref, const size_t k, const rohc_lsb_shift_t p)
The f function as defined in LSB encoding for 8-bit fields.
Definition: interval.c:48
uint8_t min
Definition: interval.h:78
struct rohc_interval16 rohc_f_16bits(const uint16_t v_ref, const size_t k, const rohc_lsb_shift_t p)
The f function as defined in LSB encoding for 16-bit fields.
Definition: interval.c:84
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:120
Definition: interval.h:52
Definition: interval.h:56
Definition: interval.h:53
Definition: interval.h:48
uint32_t max
Definition: interval.h:121
An interval of 16-bit values.
Definition: interval.h:97
uint16_t max
Definition: interval.h:100
uint32_t min
Definition: interval.h:120
Definition: interval.h:54
Definition: interval.h:44