ROHC compression/decompression library
rohc_comp.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010,2012,2013,2014 Didier Barvaux
3  * Copyright 2013 Friedrich
4  * Copyright 2009,2010 Thales Communications
5  * Copyright 2007,2009,2010,2012,2013,2014,2017 Viveris Technologies
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 /**
23  * @file rohc_comp.h
24  * @brief ROHC compression routines
25  * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com>
26  * @author Didier Barvaux <didier@barvaux.org>
27  */
28 
29 #ifndef ROHC_COMP_H
30 #define ROHC_COMP_H
31 
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #endif
36 
37 #include <rohc/rohc.h>
38 #include <rohc/rohc_packets.h>
39 #include <rohc/rohc_traces.h>
40 #include <rohc/rohc_time.h>
41 #include <rohc/rohc_buf.h>
42 
43 #include <stdlib.h>
44 #include <stdint.h>
45 #include <stdbool.h>
46 
47 
48 /** Macro that handles DLL export declarations gracefully */
49 #ifdef DLL_EXPORT /* passed by autotools on command line */
50 # define ROHC_EXPORT __declspec(dllexport)
51 #else
52 # define ROHC_EXPORT
53 #endif
54 
55 
56 /*
57  * Declare the private ROHC compressor structure that is defined inside the
58  * library.
59  */
60 
61 struct rohc_comp;
62 
63 
64 /*
65  * Public structures and types
66  */
67 
68 
69 /**
70  * @brief The different ROHC compressor states
71  *
72  * The different ROHC operation states at compressor as defined in section
73  * 4.3.1 of RFC 3095. The CR operation state is defined in RFC 4164.
74  *
75  * If you add a new compressor state, please also add the corresponding
76  * textual description in \ref rohc_comp_get_state_descr.
77  *
78  * @ingroup rohc_comp
79  *
80  * @see rohc_comp_get_state_descr
81  */
82 typedef enum
83 {
84  /** Unknown compressor state */
86  /** The Initialization and Refresh (IR) compressor state */
88  /** The First Order (FO) compressor state */
90  /** The Second Order (SO) compressor state */
92  /** The Context Replication (CR) compressor state */
94 
96 
97 
98 /**
99  * @brief Some information about the last compressed packet
100  *
101  * The structure is used by the \ref rohc_comp_get_last_packet_info2 function
102  * to store some information about the last compressed packet.
103  *
104  * Versioning works as follow:
105  * - The \e version_major field defines the compatibility level. If the major
106  * number given by user does not match the one expected by the library,
107  * an error is returned.
108  * - The \e version_minor field defines the extension level. If the minor
109  * number given by user does not match the one expected by the library,
110  * only the fields supported in that minor version will be filled by
111  * \ref rohc_comp_get_last_packet_info2.
112  *
113  * Notes for developers:
114  * - Increase the major version if a field is removed.
115  * - Increase the major version if a field is added at the beginning or in
116  * the middle of the structure.
117  * - Increase the minor version if a field is added at the very end of the
118  * structure.
119  * - The version_major and version_minor fields must be located at the very
120  * beginning of the structure.
121  * - The structure must be packed.
122  *
123  * Supported versions:
124  * - Major 0 / Minor 0 contains: version_major, version_minor, context_id,
125  * is_context_init, context_mode, context_state, context_used, profile_id,
126  * packet_type, total_last_uncomp_size, header_last_uncomp_size,
127  * total_last_comp_size, and header_last_comp_size
128  *
129  * @ingroup rohc_comp
130  *
131  * @see rohc_comp_get_last_packet_info2
132  */
133 typedef struct
134 {
135  /** The major version of this structure */
136  unsigned short version_major;
137  /** The minor version of this structure */
138  unsigned short version_minor;
139  /** The Context ID (CID) */
140  unsigned int context_id;
141  /** Whether the context was initialized (created/re-used) by the packet */
143  /** The mode of the last context used by the compressor */
145  /** The state of the last context used by the compressor */
147  /** Whether the last context used by the compressor is still in use */
149  /** The profile ID of the last context used by the compressor */
151  /** The type of ROHC packet created for the last compressed packet */
153  /** The uncompressed size (in bytes) of the last compressed packet */
154  unsigned long total_last_uncomp_size;
155  /** The uncompressed size (in bytes) of the last compressed header */
156  unsigned long header_last_uncomp_size;
157  /** The compressed size (in bytes) of the last compressed packet */
158  unsigned long total_last_comp_size;
159  /** The compressed size (in bytes) of the last compressed header */
160  unsigned long header_last_comp_size;
161 } __attribute__((packed)) rohc_comp_last_packet_info2_t;
162 
163 
164 /**
165  * @brief Some general information about the compressor
166  *
167  * The structure is used by the \ref rohc_comp_get_general_info function
168  * to store some general information about the compressor.
169  *
170  * Versioning works as follow:
171  * - The \e version_major field defines the compatibility level. If the major
172  * number given by user does not match the one expected by the library,
173  * an error is returned.
174  * - The \e version_minor field defines the extension level. If the minor
175  * number given by user does not match the one expected by the library,
176  * only the fields supported in that minor version will be filled by
177  * \ref rohc_comp_get_general_info.
178  *
179  * Notes for developers:
180  * - Increase the major version if a field is removed.
181  * - Increase the major version if a field is added at the beginning or in
182  * the middle of the structure.
183  * - Increase the minor version if a field is added at the very end of the
184  * structure.
185  * - The version_major and version_minor fields must be located at the very
186  * beginning of the structure.
187  * - The structure must be packed.
188  *
189  * Supported versions:
190  * - major 0 and minor = 0 contains: version_major, version_minor,
191  * contexts_nr, packets_nr, uncomp_bytes_nr, and comp_bytes_nr.
192  *
193  * @ingroup rohc_comp
194  *
195  * @see rohc_comp_get_general_info
196  */
197 typedef struct
198 {
199  /** The major version of this structure */
200  unsigned short version_major;
201  /** The minor version of this structure */
202  unsigned short version_minor;
203  /** The number of contexts used by the compressor */
204  size_t contexts_nr;
205  /** The number of packets processed by the compressor */
206  unsigned long packets_nr;
207  /** The number of uncompressed bytes received by the compressor */
208  unsigned long uncomp_bytes_nr;
209  /** The number of compressed bytes produced by the compressor */
210  unsigned long comp_bytes_nr;
211 } __attribute__((packed)) rohc_comp_general_info_t;
212 
213 
214 /**
215  * @brief The different features of the ROHC compressor
216  *
217  * Features for the ROHC compressor control whether mechanisms defined as
218  * optional by RFCs are enabled or not. They can be set or unset with the
219  * function \ref rohc_comp_set_features.
220  *
221  * @ingroup rohc_comp
222  *
223  * @see rohc_comp_set_features
224  */
225 typedef enum
226 {
227  /** No feature at all */
229  /** Be compatible with 1.6.x versions */
231  /** Do not check IP checksums at compressor */
233  /** Dump content of packets in traces (beware: performance impact) */
235  /** Allow periodic refreshes based on inter-packet time */
237 
239 
240 
241 /**
242  * @brief The prototype of the RTP detection callback
243  *
244  * User-defined function that is called by the ROHC library for every UDP
245  * packet to determine whether the UDP packet transports RTP data. If the
246  * function returns true, the RTP profile is used to compress the packet.
247  * Otherwise the UDP profile is used.
248  *
249  * The user-defined function is set by calling the function
250  * \ref rohc_comp_set_rtp_detection_cb
251  *
252  * @param ip The innermost IP packet
253  * @param udp The UDP header of the packet
254  * @param payload The UDP payload of the packet
255  * @param payload_size The size of the UDP payload (in bytes)
256  * @param rtp_private A pointer to a memory area to be used by the callback
257  * function, may be NULL.
258  * @return true if the packet is an RTP packet, false otherwise
259  *
260  * @see rohc_comp_set_rtp_detection_cb
261  * @ingroup rohc_comp
262  */
263 typedef bool (*rohc_rtp_detection_callback_t)(const unsigned char *const ip,
264  const unsigned char *const udp,
265  const unsigned char *const payload,
266  const unsigned int payload_size,
267  void *const rtp_private)
268  __attribute__((warn_unused_result));
269 
270 
271 /**
272  * @brief The prototype of the callback for random numbers
273  *
274  * User-defined function that is called when the ROHC library requires a random
275  * number. Currently, the ROHC library uses it when initializing the Sequence
276  * Number (SN) of contexts using the IP-only, IP/UDP, and IP/UDP-Lite profiles.
277  *
278  * The user-defined function is set by calling the function
279  * \ref rohc_comp_new2
280  *
281  * @param comp The ROHC compressor
282  * @param user_context The context given by the user when he/she called the
283  * \ref rohc_comp_new2 function, may be NULL.
284  *
285  * @see rohc_comp_new2
286  * @ingroup rohc_comp
287  */
288 typedef int (*rohc_comp_random_cb_t) (const struct rohc_comp *const comp,
289  void *const user_context)
290  __attribute__((warn_unused_result));
291 
292 
293 /*
294  * Prototypes of main public functions related to ROHC compression
295  */
296 
297 struct rohc_comp * ROHC_EXPORT rohc_comp_new2(const rohc_cid_type_t cid_type,
298  const rohc_cid_t max_cid,
299  const rohc_comp_random_cb_t rand_cb,
300  void *const rand_priv)
301  __attribute__((warn_unused_result));
302 
303 void ROHC_EXPORT rohc_comp_free(struct rohc_comp *const comp);
304 
305 bool ROHC_EXPORT rohc_comp_set_traces_cb2(struct rohc_comp *const comp,
306  rohc_trace_callback2_t callback,
307  void *const priv_ctxt)
308  __attribute__((warn_unused_result));
309 
311  const struct rohc_buf uncomp_packet,
312  struct rohc_buf *const rohc_packet)
313  __attribute__((warn_unused_result));
314 
316  struct rohc_buf *const rohc_packet,
317  const size_t min_pkt_len)
318  __attribute__((warn_unused_result));
319 
321  struct rohc_buf *const segment)
322  __attribute__((warn_unused_result));
323 
325  __attribute__((warn_unused_result));
326 
327 
328 /*
329  * Prototypes of public functions related to user interaction
330  */
331 
332 bool ROHC_EXPORT rohc_comp_profile_enabled(const struct rohc_comp *const comp,
333  const rohc_profile_t profile)
334  __attribute__((warn_unused_result));
335 
336 bool ROHC_EXPORT rohc_comp_enable_profile(struct rohc_comp *const comp,
337  const rohc_profile_t profile)
338  __attribute__((warn_unused_result));
339 bool ROHC_EXPORT rohc_comp_disable_profile(struct rohc_comp *const comp,
340  const rohc_profile_t profile)
341  __attribute__((warn_unused_result));
342 
343 bool ROHC_EXPORT rohc_comp_enable_profiles(struct rohc_comp *const comp,
344  ...)
345  __attribute__((warn_unused_result));
346 bool ROHC_EXPORT rohc_comp_disable_profiles(struct rohc_comp *const comp,
347  ...)
348  __attribute__((warn_unused_result));
349 
350 bool ROHC_EXPORT rohc_comp_set_mrru(struct rohc_comp *const comp,
351  const size_t mrru)
352  __attribute__((warn_unused_result));
353 bool ROHC_EXPORT rohc_comp_get_mrru(const struct rohc_comp *const comp,
354  size_t *const mrru)
355  __attribute__((warn_unused_result));
356 
357 bool ROHC_EXPORT rohc_comp_get_max_cid(const struct rohc_comp *const comp,
358  size_t *const max_cid)
359  __attribute__((warn_unused_result));
360 
361 bool ROHC_EXPORT rohc_comp_get_cid_type(const struct rohc_comp *const comp,
362  rohc_cid_type_t *const cid_type)
363  __attribute__((warn_unused_result));
364 
367  void *const rtp_private)
368  __attribute__((warn_unused_result));
369 
370 bool ROHC_EXPORT rohc_comp_set_features(struct rohc_comp *const comp,
372  __attribute__((warn_unused_result));
373 
374 bool ROHC_EXPORT rohc_comp_deliver_feedback2(struct rohc_comp *const comp,
375  const struct rohc_buf feedback)
376  __attribute__((warn_unused_result));
377 
378 
379 /*
380  * Prototypes of public functions that configure robustness to packet
381  * loss/damage
382  */
383 
385  const size_t width)
386  __attribute__((warn_unused_result));
387 
389  const size_t ir_timeout,
390  const size_t fo_timeout)
391  __attribute__((warn_unused_result));
392 
394  const uint64_t ir_timeout,
395  const uint64_t fo_timeout)
396  __attribute__((warn_unused_result));
397 
398 bool ROHC_EXPORT rohc_comp_set_list_trans_nr(struct rohc_comp *const comp,
399  const size_t list_trans_nr)
400  __attribute__((warn_unused_result));
401 
402 
403 /*
404  * Prototypes of public functions related to ROHC compression statistics
405  */
406 
407 bool ROHC_EXPORT rohc_comp_get_general_info(const struct rohc_comp *const comp,
408  rohc_comp_general_info_t *const info)
409  __attribute__((warn_unused_result));
410 
411 bool ROHC_EXPORT rohc_comp_get_last_packet_info2(const struct rohc_comp *const comp,
412  rohc_comp_last_packet_info2_t *const info)
413  __attribute__((warn_unused_result));
414 
416  __attribute__((warn_unused_result, const));
417 
418 
419 #undef ROHC_EXPORT /* do not pollute outside this header */
420 
421 #ifdef __cplusplus
422 }
423 #endif
424 
425 #endif /* ROHC_COMP_H */
426 
Definition: rohc_comp.h:230
bool ROHC_EXPORT rohc_comp_get_cid_type(const struct rohc_comp *const comp, rohc_cid_type_t *const cid_type)
Get the CID type that the compressor uses.
Definition: rohc_comp.c:1862
int(* rohc_comp_random_cb_t)(const struct rohc_comp *const comp, void *const user_context)
The prototype of the callback for random numbers.
Definition: rohc_comp.h:288
size_t rohc_cid_t
Definition: rohc.h:193
rohc_packet_t packet_type
Definition: rohc_comp.h:152
bool ROHC_EXPORT rohc_comp_force_contexts_reinit(struct rohc_comp *const comp)
Force the compressor to re-initialize all its contexts.
Definition: rohc_comp.c:1052
bool ROHC_EXPORT rohc_comp_set_features(struct rohc_comp *const comp, const rohc_comp_features_t features)
Enable/disable features for ROHC compressor.
Definition: rohc_comp.c:1898
rohc_comp_features_t features
Definition: rohc_comp_internals.h:135
bool context_used
Definition: rohc_comp.h:148
bool ROHC_EXPORT rohc_comp_set_periodic_refreshes_time(struct rohc_comp *const comp, const uint64_t ir_timeout, const uint64_t fo_timeout)
Set the timeouts in ms for IR and FO periodic refreshes.
Definition: rohc_comp.c:1218
rohc_mode_t
ROHC operation modes.
Definition: rohc.h:109
bool ROHC_EXPORT rohc_comp_set_mrru(struct rohc_comp *const comp, const size_t mrru)
Set the Maximum Reconstructed Reception Unit (MRRU).
Definition: rohc_comp.c:1732
bool ROHC_EXPORT rohc_comp_get_general_info(const struct rohc_comp *const comp, rohc_comp_general_info_t *const info)
Get some general information about the compressor.
Definition: rohc_comp.c:2223
unsigned short version_minor
Definition: rohc_comp.h:138
bool ROHC_EXPORT rohc_comp_set_traces_cb2(struct rohc_comp *const comp, rohc_trace_callback2_t callback, void *const priv_ctxt)
Set the callback function used to manage traces in compressor.
Definition: rohc_comp.c:424
unsigned short version_major
Definition: rohc_comp.h:200
bool ROHC_EXPORT rohc_comp_disable_profile(struct rohc_comp *const comp, const rohc_profile_t profile)
Disable a compression profile for a compressor.
Definition: rohc_comp.c:1527
bool ROHC_EXPORT rohc_comp_set_wlsb_window_width(struct rohc_comp *const comp, const size_t width)
Set the window width for the W-LSB encoding scheme.
Definition: rohc_comp.c:1102
rohc_status_t
The status code of several functions in the library API.
Definition: rohc.h:77
The ROHC compressor.
Definition: rohc_comp_internals.h:129
rohc_cid_type_t
The different types of Context IDs (CID)
Definition: rohc.h:174
Some general information about the compressor.
Definition: rohc_comp.h:197
bool ROHC_EXPORT rohc_comp_get_max_cid(const struct rohc_comp *const comp, size_t *const max_cid)
Get the maximal CID value the compressor uses.
Definition: rohc_comp.c:1833
rohc_status_t ROHC_EXPORT rohc_comp_get_segment2(struct rohc_comp *const comp, struct rohc_buf *const segment)
Get the next ROHC segment if any.
Definition: rohc_comp.c:928
rohc_comp_state_t context_state
Definition: rohc_comp.h:146
rohc_mode_t context_mode
Definition: rohc_comp.h:144
size_t contexts_nr
Definition: rohc_comp.h:204
struct rohc_comp *ROHC_EXPORT rohc_comp_new2(const rohc_cid_type_t cid_type, const rohc_cid_t max_cid, const rohc_comp_random_cb_t rand_cb, void *const rand_priv)
Create a new ROHC compressor.
Definition: rohc_comp.c:229
unsigned long packets_nr
Definition: rohc_comp.h:206
bool is_context_init
Definition: rohc_comp.h:142
void(* rohc_trace_callback2_t)(void *const priv_ctxt, const rohc_trace_level_t level, const rohc_trace_entity_t entity, const int profile, const char *const format,...)
The function prototype for the trace callback.
Definition: rohc_traces.h:118
unsigned long total_last_comp_size
Definition: rohc_comp.h:158
unsigned long header_last_comp_size
Definition: rohc_comp.h:160
bool ROHC_EXPORT rohc_comp_set_periodic_refreshes(struct rohc_comp *const comp, const size_t ir_timeout, const size_t fo_timeout)
Set the timeouts in packets for IR and FO periodic refreshes.
Definition: rohc_comp.c:1158
bool ROHC_EXPORT rohc_comp_get_last_packet_info2(const struct rohc_comp *const comp, rohc_comp_last_packet_info2_t *const info)
Get some information about the last compressed packet.
Definition: rohc_comp.c:2140
void ROHC_EXPORT rohc_comp_free(struct rohc_comp *const comp)
Destroy the given ROHC compressor.
Definition: rohc_comp.c:365
Definition: rohc_comp.h:85
Definition: rohc_comp.h:91
Definition: rohc_comp.h:234
bool(* rohc_rtp_detection_callback_t)(const unsigned char *const ip, const unsigned char *const udp, const unsigned char *const payload, const unsigned int payload_size, void *const rtp_private)
The prototype of the RTP detection callback.
Definition: rohc_comp.h:263
bool ROHC_EXPORT rohc_comp_deliver_feedback2(struct rohc_comp *const comp, const struct rohc_buf feedback)
Deliver a feedback packet to the compressor.
Definition: rohc_comp.c:2033
Definition: rohc_comp.h:236
unsigned long total_last_uncomp_size
Definition: rohc_comp.h:154
unsigned long uncomp_bytes_nr
Definition: rohc_comp.h:208
const char *ROHC_EXPORT rohc_comp_get_state_descr(const rohc_comp_state_t state)
Give a description for the given ROHC compression context state.
Definition: rohc_comp.c:2286
rohc_status_t ROHC_EXPORT rohc_comp_pad(struct rohc_comp *const comp, struct rohc_buf *const rohc_packet, const size_t min_pkt_len)
Pad the given ROHC compressed packet.
Definition: rohc_comp.c:805
A network buffer for the ROHC library.
Definition: rohc_buf.h:102
bool ROHC_EXPORT rohc_comp_profile_enabled(const struct rohc_comp *const comp, const rohc_profile_t profile)
Is the given compression profile enabled for a compressor?
Definition: rohc_comp.c:1397
bool ROHC_EXPORT rohc_comp_disable_profiles(struct rohc_comp *const comp,...)
Disable several compression profiles for a compressor.
Definition: rohc_comp.c:1659
Definition: rohc_comp.h:228
rohc_comp_features_t
The different features of the ROHC compressor.
Definition: rohc_comp.h:225
rohc_comp_state_t
The different ROHC compressor states.
Definition: rohc_comp.h:82
unsigned short version_minor
Definition: rohc_comp.h:202
Definition: rohc_comp.h:89
bool ROHC_EXPORT rohc_comp_enable_profile(struct rohc_comp *const comp, const rohc_profile_t profile)
Enable a compression profile for a compressor.
Definition: rohc_comp.c:1465
bool ROHC_EXPORT rohc_comp_enable_profiles(struct rohc_comp *const comp,...)
Enable several compression profiles for a compressor.
Definition: rohc_comp.c:1601
size_t list_trans_nr
Definition: rohc_comp_internals.h:219
void * rtp_private
Definition: rohc_comp_internals.h:174
#define ROHC_EXPORT
Definition: rohc_comp.h:52
Definition: rohc_comp.h:93
unsigned long header_last_uncomp_size
Definition: rohc_comp.h:156
Definition: rohc_comp.h:232
Definition: rohc_comp.h:87
Some information about the last compressed packet.
Definition: rohc_comp.h:133
bool ROHC_EXPORT rohc_comp_set_rtp_detection_cb(struct rohc_comp *const comp, rohc_rtp_detection_callback_t callback, void *const rtp_private)
Set the RTP detection callback function.
Definition: rohc_comp.c:1360
rohc_status_t ROHC_EXPORT rohc_compress4(struct rohc_comp *const comp, const struct rohc_buf uncomp_packet, struct rohc_buf *const rohc_packet)
Compress the given uncompressed packet into a ROHC packet.
Definition: rohc_comp.c:520
rohc_profile_t
The different ROHC compression/decompression profiles.
Definition: rohc.h:210
rohc_packet_t
The different types of ROHC packets.
Definition: rohc_packets.h:55
bool ROHC_EXPORT rohc_comp_set_list_trans_nr(struct rohc_comp *const comp, const size_t list_trans_nr)
Set the number of uncompressed transmissions for list compression.
Definition: rohc_comp.c:1278
size_t mrru
Definition: rohc_comp_internals.h:215
unsigned int context_id
Definition: rohc_comp.h:140
unsigned short version_major
Definition: rohc_comp.h:136
bool ROHC_EXPORT rohc_comp_get_mrru(const struct rohc_comp *const comp, size_t *const mrru)
Get the Maximum Reconstructed Reception Unit (MRRU).
Definition: rohc_comp.c:1804
int profile_id
Definition: rohc_comp.h:150
unsigned long comp_bytes_nr
Definition: rohc_comp.h:210