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