rohc.h − The ROHC compressor/decompressor common API


#include <rohc/rohc.h>


The common API of the ROHC library allows a program to print the version of the ROHC library, or retrieve the description of ROHC modes and packets. No initialization is required.

bool rohc_buf_is_malformed(const struct rohc_buf buf);
bool rohc_buf_is_empty(const struct rohc_buf buf);
void rohc_buf_pull(struct rohc_buf *const buf,
const size_t offset);
void rohc_buf_push(struct rohc_buf *const buf,
const size_t offset);
size_t rohc_buf_avail_len(const struct rohc_buf buf);
uint8_t *rohc_buf_data(const struct rohc_buf buf);
uint8_t *rohc_buf_data_at(const struct rohc_buf buf,
const size_t offset);
void rohc_buf_prepend(struct rohc_buf *const buf,
const uint8_t *const data,
const size_t len);
void rohc_buf_append(struct rohc_buf *const buf,
const uint8_t *const data,
const size_t len);
void rohc_buf_append_buf(struct rohc_buf *const dst,
const struct rohc_buf src);
void rohc_buf_reset(struct rohc_buf *const buf);
char *rohc_version(void);
const char *rohc_strerror(const rohc_status_t status);
const char *rohc_get_mode_descr(const rohc_mode_t mode);
const char *rohc_get_packet_descr(const rohc_packet_t packet_type);
const char *rohc_get_ext_descr(const rohc_ext_t ext_type);
rohc_packet_t rohc_get_packet_type(const char *const packet_id);
const char *rohc_get_profile_descr(const rohc_profile_t profile);
bool rohc_profile_is_rohcv1(const rohc_profile_t profile);
bool rohc_profile_is_rohcv2(const rohc_profile_t profile);
rohc_profile_t rohc_profile_get_other_version(const rohc_profile_t profile);


The status code of several functions in the library API

enum rohc_status_t {
, /* The action was successful */
, /* The action was successful but packet needs to be segmented */
, /* The action failed due to a malformed packet */
, /* The action failed because no matching context exists */
, /* The action failed due to a CRC failure */
, /* The action failed because output buffer is too small */
, /* The action encountered an undefined problem */

ROHC operation modes
The different ROHC operation modes as defined in section 4.4 of RFC 3095.

If you add a new operation mode, please also add the corresponding textual description in rohc_get_mode_descr.

enum rohc_mode_t {
, /* Unknown operational mode */
, /* The Unidirectional mode (U-mode) */
, /* The Bidirectional Optimistic mode (O-mode) */
, /* The Bidirectional Reliable mode (R-mode) */

The different types of Context IDs (CID)
CID values shall be in the range [0, ROHC_LARGE_CID_MAXCID value shall be in the range [0, ROHC_SMALL_CID_MAXThe different types of Context IDs (CID) a ROHC compressor or a ROHC decompressor may use.

Possible values are:

ROHC_LARGE_CID : large CID means that a ROHC compressor or a ROHC decompressor may identify contexts with IDs in the range [0, ROHC_LARGE_CID_MAX ], ie. it may uniquely identify at most ROHC_LARGE_CID_MAX + 1 streams.

ROHC_SMALL_CID : small CID means that a ROHC compressor or a ROHC decompressor may identify contexts with IDs in the range [0, ROHC_SMALL_CID_MAX ], ie. it may uniquely identify at most ROHC_SMALL_CID_MAX + 1 streams.

In short, you choose the CID type in function of the number of simultaneous streams you have to compress efficiently.

enum rohc_cid_type_t {
, /* The context uses large CID. */
, /* The context uses small CID. */

The different ROHC compression/decompression profiles
The ROHC profiles numbers are allocated by the IANA:

• see §8 in the RFC 3095 (ROHCv1)

• see §5 in the RFC 3843 (ROHCv1 IP-only)

• see §7 in the RFC 4019 (ROHCv1 UDP-Lite)

• see §11 in the RFC 6846 (ROHCv1 TCP)

• see §8 in the RFC 5252 (ROHCv2)

If you add a new compression/decompression profile, please also add the corresponding textual description in rohc_get_profile_descr.

enum rohc_profile_t {
, /* The ROHCv1 Uncompressed profile (RFC 3095, section 5.10) */
, /* The ROHCv1 RTP profile (RFC 3095, section 8) */
, /* The ROHCv1 UDP profile (RFC 3095, section 5.11) */
, /* The ROHCv1 ESP profile (RFC 3095, section 5.12) */
, /* The ROHCv1 IP-only profile (RFC 3843, section 5) */
, /* The ROHCv1 IP/UDP/RTP Link-Layer Assisted Profile (LLA) profile (RFC 4362, section 6) */
, /* The ROHCv1 TCP profile (RFC 4996) */
, /* The ROHCv1 UDP-Lite/RTP profile (RFC 4019, section 7) */
, /* The ROHCv1 UDP-Lite profile (RFC 4019, section 7) */
, /* The ROHCv2 RTP/UDP/IP profile */
, /* The ROHCv2 UDP/IP profile */
, /* The ROHCv2 ESP/IP profile */
, /* The ROHCv2 IP-only profile */
, /* The ROHCv2 IP/UDP-Lite/RTP profile */
, /* The ROHCv2 IP/UDP-Lite profile */
, /* */

The different levels of the traces
Used for the level parameter of the rohc_trace_callback2_t user-defined callback.

enum rohc_trace_level_t {
, /* Print debug traces */
, /* Print info (or lower) traces */
, /* Print warning (or lower) traces */
, /* Print error (or lower) traces */
, /* The maximum number of trace levels */

The different entities concerned by the traces
Used for the source entity parameter of the rohc_trace_callback2_t user-defined callback.

enum rohc_trace_entity_t {
, /* Compressor traces */
, /* Decompressor traces */
, /* The maximum number of trace entities */

The function prototype for the trace callback
User-defined function that is called by the ROHC library every time it wants to print something, from errors to debug. User may thus decide what traces are interesting (filter on level, source entity, or profile) and what to do with them (print on console, storage in file, syslog...).

The user-defined function is set by calling:

• function rohc_comp_set_traces_cb2 for a ROHC compressor,

• function rohc_decomp_set_traces_cb2 for a ROHC decompressor.

Both functions accept the NULL value to fully disable tracing.

typedef void (*rohc_trace_callback2_t) (
void *const priv_ctxt
, /* An optional private context, may be NULL */
const rohc_trace_level_t level
, /* The level of the message, */
const rohc_trace_entity_t entity
, /* The entity concerned by the traces */
const int profile
, /* The number of the profile concerned by the message */
const char *const format
/* The format string for the trace message */

A network buffer for the ROHC library
May represent one uncompressed packet, one ROHC packet, or a ROHC feedback.

The network buffer does not contain the packet data itself. It only has a pointer on it. This is designed this way for performance reasons: no copy required to initialize a network buffer, the struct is small and may be passed as copy to function.

The network buffer is able to keep some free space at its beginning. The unused space at the beginning of the buffer may be used to prepend a network header at the very end of the packet handling.

The beginning of the network buffer may also be shifted forward with the rohc_buf_pull function or shifted backward with the rohc_buf_push function. This is useful when parsing a network packet (once bytes are read, shift them forward) for example.

The network buffer may be initialized manually (see below) or with the helper functions rohc_buf_init_empty or rohc_buf_init_full...

struct rohc_buf {
struct rohc_ts time; /* The timestamp associated to the data */
uint8_t *data; /* The buffer data */
size_t max_len; /* The maximum length of the buffer */
size_t offset; /* The offset for the beginning of the data */
size_t len; /* The data length (in bytes) */


rohc_buf_is_malformed(3), rohc_buf_is_empty(3), rohc_buf_pull(3), rohc_buf_push(3), rohc_buf_avail_len(3), rohc_buf_data(3), rohc_buf_data_at(3), rohc_buf_prepend(3), rohc_buf_append(3), rohc_buf_append_buf(3), rohc_buf_reset(3), rohc_version(3), rohc_strerror(3), rohc_get_mode_descr(3), rohc_get_packet_descr(3), rohc_get_ext_descr(3), rohc_get_packet_type(3), rohc_get_profile_descr(3), rohc_profile_is_rohcv1(3), rohc_profile_is_rohcv2(3), rohc_profile_get_other_version(3)