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 64U
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_VAR = 103, /**< real value is variable */
61  ROHC_LSB_SHIFT_TCP_WINDOW = 16383, /**< real value for TCP window */
62  ROHC_LSB_SHIFT_TCP_TS_3B = 0x00040000, /**< real value for TCP TS */
63  ROHC_LSB_SHIFT_TCP_TS_4B = 0x04000000, /**< real value for TCP TS */
65 
66 
67 /**
68  * @brief An interval of 8-bit values
69  *
70  * Lower and upper bound values are always included in the interval.
71  *
72  * The upper bound may be greater that the lower bound of the interval if the
73  * interval straddles the interval boundaries.
74  *
75  * Example of interval that does not straddle field boundaries:
76  * [1, 3]
77  *
78  * Example of interval that straddles field boundaries (8-bit field):
79  * [250, 4]
80  */
82 {
83  uint8_t min; /**< The lower bound of the interval */
84  uint8_t max; /**< The upper bound of the interval */
85 };
86 
87 
88 /**
89  * @brief An interval of 16-bit values
90  *
91  * Lower and upper bound values are always included in the interval.
92  *
93  * The upper bound may be greater that the lower bound of the interval if the
94  * interval straddles the interval boundaries.
95  *
96  * Example of interval that does not straddle field boundaries:
97  * [1, 3]
98  *
99  * Example of interval that straddles field boundaries (16-bit field):
100  * [65530, 4]
101  */
103 {
104  uint16_t min; /**< The lower bound of the interval */
105  uint16_t max; /**< The upper bound of the interval */
106 };
107 
108 
109 /**
110  * @brief An interval of 32-bit values
111  *
112  * Lower and upper bound values are always included in the interval.
113  *
114  * The upper bound may be greater that the lower bound of the interval if the
115  * interval straddles the interval boundaries.
116  *
117  * Example of interval that does not straddle field boundaries:
118  * [1, 3]
119  *
120  * Example of interval that straddles field boundaries (32-bit field):
121  * [65530, 4]
122  */
124 {
125  uint32_t min; /**< The lower bound of the interval */
126  uint32_t max; /**< The upper bound of the interval */
127 };
128 
129 
130 /*
131  * Public function prototypes:
132  */
133 
134 static inline int32_t rohc_interval_compute_p(const size_t k,
135  const rohc_lsb_shift_t p)
136  __attribute__((warn_unused_result, const));
137 
138 struct rohc_interval32 rohc_f_32bits(const uint32_t v_ref,
139  const size_t k,
140  const rohc_lsb_shift_t p)
141  __attribute__((warn_unused_result, const));
142 
143 int32_t rohc_interval_get_rfc5225_msn_p(const size_t k,
144  rohc_reordering_offset_t reorder_ratio)
145  __attribute__((warn_unused_result, const));
146 
147 int32_t rohc_interval_get_rfc5225_id_id_p(const size_t k)
148  __attribute__((warn_unused_result, const));
149 
150 
151 /**
152  * @brief Compute the shift parameter p for the f function
153  *
154  * @param k The number of least significant bits of the value that are
155  * transmitted
156  * @param p The shift parameter (may be negative)
157  * @return The computed shift parameter p
158  */
159 static inline int32_t rohc_interval_compute_p(const size_t k,
160  const rohc_lsb_shift_t p)
161 {
162  int32_t computed_p;
163 
164  /* determine the real p value to use */
165  if(p == ROHC_LSB_SHIFT_RTP_TS)
166  {
167  /* special computation for RTP TS encoding */
168  computed_p = (k <= 2 ? 0 : (1 << (k - 2)) - 1);
169  }
170  else if(p == ROHC_LSB_SHIFT_RTP_SN || p == ROHC_LSB_SHIFT_ESP_SN)
171  {
172  /* special computation for RTP and ESP SN encoding */
173  computed_p = (k <= 4 ? 1 : (1 << (k - 5)) - 1);
174  }
175  else
176  {
177  /* otherwise: use the p value given as parameter */
178  computed_p = p;
179  }
180 
181  return computed_p;
182 }
183 
184 #endif
185 
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
Definition: interval.h:60
uint16_t min
Definition: interval.h:104
Definition: interval.h:63
rohc_reordering_offset_t
The different values of reordering offset.
Definition: rohc.h:203
Definition: interval.h:55
Definition: interval.h:62
An interval of 8-bit values.
Definition: interval.h:81
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:159
Definition: interval.h:52
An interval of 32-bit values.
Definition: interval.h:123
uint8_t max
Definition: interval.h:84
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:83
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:61
Definition: interval.h:58
Definition: interval.h:53
uint32_t max
Definition: interval.h:126
An interval of 16-bit values.
Definition: interval.h:102
uint16_t max
Definition: interval.h:105
uint32_t min
Definition: interval.h:125
Definition: interval.h:59
Definition: interval.h:49