rohc_comp_get_segment2 − Get the next ROHC segment if any.
#include <rohc/rohc_comp.h>
rohc_status_t
rohc_comp_get_segment2(
struct rohc_comp *const comp,
struct rohc_buf *const segment
);
Get the next ROHC segment if any.
To get all the segments of one ROHC packet, call this function until ROHC_STATUS_OK or ROHC_STATUS_ERROR is returned.
comp |
The ROHC compressor |
segment [output]
The buffer where to store the ROHC segment
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) */
};
Possible return values:
• ROHC_STATUS_SEGMENT if a ROHC segment is returned and more segments are available,
• ROHC_STATUS_OK if a ROHC segment is returned and no more ROHC segment is available
• ROHC_STATUS_ERROR if an error occurred
struct rohc_comp *comp;
ess the IP
packet with a small ROHC buffer
status = rohc_compress4(comp, ip_packet, &rohc_packet);
if(status == ROHC_STATUS_SEGMENT)
{
/* ROHC segmentation is required to compress the IP packet
*/
/* get the segments */
while((status = rohc_comp_get_segment2(comp,
&rohc_packet)) == ROHC_STATUS_SEGMENT)
{
/* new ROHC segment retrieved */
press the ROHC
segment here, the function
decompress3 shall return ROHC_STATUS_OK
o decompressed packet
if(uncomp_packet.len
> 0)
{
fprintf(stderr, "decompression of ROHC segment
succeeded while "
"it should have not0);
goto destroy_decomp;
}
rohc_packet.len = 0;
}
if(status != ROHC_STATUS_OK)
{
fprintf(stderr, "failed to generate ROHC segment
(status = %d)0,
status);
goto destroy_decomp;
}
/* final ROHC segment retrieved */
press the final ROHC segment here, the function
decompress4 shall return ROHC_STATUS_OK
if(uncomp_packet.len == 0)
{
fprintf(stderr, "decompression of ROHC segment failed
while it "
"should have succeeded0);
goto destroy_decomp;
}
}
else if(status != ROHC_STATUS_OK)
{
e compression error here
rohc_comp.h(3), ROHC_STATUS_OK(3), ROHC_STATUS_ERROR(3), ROHC_STATUS_SEGMENT(3), rohc_comp_get_mrru(3), rohc_comp_set_mrru(3), rohc_compress4(3)