ROHC compression/decompression library
Functions | Variables
c_rtp.c File Reference

ROHC compression context for the RTP profile. More...

#include "c_rtp.h"
#include "c_udp.h"
#include "rohc_traces_internal.h"
#include "rohc_packets.h"
#include "rohc_utils.h"
#include "sdvl.h"
#include "crc.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
Include dependency graph for c_rtp.c:

Functions

static bool c_rtp_create (struct rohc_comp_ctxt *const context, const struct net_pkt *const packet)
 Create a new RTP context and initialize it thanks to the given IP/UDP/RTP packet. More...
 
static void c_rtp_destroy (struct rohc_comp_ctxt *const context)
 Destroy the RTP context. More...
 
static bool c_rtp_check_profile (const struct rohc_comp *const comp, const struct net_pkt *const packet)
 Check if the given packet corresponds to the RTP profile. More...
 
static bool c_rtp_check_context (const struct rohc_comp_ctxt *const context, const struct net_pkt *const packet)
 Check if the IP/UDP/RTP packet belongs to the context. More...
 
static int c_rtp_encode (struct rohc_comp_ctxt *const context, const struct net_pkt *const uncomp_pkt, uint8_t *const rohc_pkt, const size_t rohc_pkt_max_len, rohc_packet_t *const packet_type, size_t *const payload_offset)
 Encode an IP/UDP/RTP packet according to a pattern decided by several different factors. More...
 
static void rtp_decide_state (struct rohc_comp_ctxt *const context)
 Decide the state that should be used for the next packet compressed with the ROHC RTP profile. More...
 
static rohc_packet_t c_rtp_decide_FO_packet (const struct rohc_comp_ctxt *context)
 Decide which packet to send when in First Order (FO) state. More...
 
static rohc_packet_t c_rtp_decide_SO_packet (const struct rohc_comp_ctxt *context)
 Decide which packet to send when in Second Order (SO) state. More...
 
static rohc_ext_t c_rtp_decide_extension (const struct rohc_comp_ctxt *context)
 Decide what extension shall be used in the UO-1/UO-2 packet. More...
 
static uint32_t c_rtp_get_next_sn (const struct rohc_comp_ctxt *const context, const struct net_pkt *const uncomp_pkt)
 Determine the SN value for the next packet. More...
 
static bool rtp_encode_uncomp_fields (struct rohc_comp_ctxt *const context, const struct net_pkt *const uncomp_pkt)
 Encode uncompressed RTP fields. More...
 
static size_t rtp_code_static_rtp_part (const struct rohc_comp_ctxt *const context, const uint8_t *const next_header, uint8_t *const dest, const size_t counter)
 Build the static part of the UDP/RTP headers. More...
 
static size_t rtp_code_dynamic_rtp_part (const struct rohc_comp_ctxt *const context, const uint8_t *const next_header, uint8_t *const dest, const size_t counter)
 Build the dynamic part of the UDP/RTP headers. More...
 
static int rtp_changed_rtp_dynamic (const struct rohc_comp_ctxt *const context, const struct udphdr *const udp, const struct rtphdr *const rtp)
 Check if the dynamic part of the UDP/RTP headers changed. More...
 

Variables

const struct rohc_comp_profile c_rtp_profile
 Define the compression part of the RTP profile as described in the RFC 3095. More...
 

Detailed Description

ROHC compression context for the RTP profile.

Author
David Moreau from TAS
Didier Barvaux didie.nosp@m.r.ba.nosp@m.rvaux.nosp@m.@tou.nosp@m.louse.nosp@m..viv.nosp@m.eris..nosp@m.com
Didier Barvaux didie.nosp@m.r@ba.nosp@m.rvaux.nosp@m..org

Function Documentation

static bool c_rtp_check_context ( const struct rohc_comp_ctxt *const  context,
const struct net_pkt *const  packet 
)
static

Check if the IP/UDP/RTP packet belongs to the context.

Conditions are:

  • the number of IP headers must be the same as in context
  • IP version of the two IP headers must be the same as in context
  • IP packets must not be fragmented
  • the source and destination addresses of the two IP headers must match the ones in the context
  • the transport protocol must be UDP
  • the source and destination ports of the UDP header must match the ones in the context
  • IPv6 only: the Flow Label of the two IP headers must match the ones the context
  • the SSRC field of the RTP header must match the one in the context

All the context but the last one are done by the c_udp_check_context() function.

This function is one of the functions that must exist in one profile for the framework to work.

Parameters
contextThe compression context
packetThe IP/UDP/RTP packet to check
Returns
true if the IP/UDP/RTP packet belongs to the context false if it does not belong to the context
See also
c_udp_check_context
static bool c_rtp_check_profile ( const struct rohc_comp *const  comp,
const struct net_pkt *const  packet 
)
static

Check if the given packet corresponds to the RTP profile.

Conditions are:

  • the transport protocol is UDP
  • the version of the outer IP header is 4 or 6
  • the outer IP header is not an IP fragment
  • if there are at least 2 IP headers, the version of the inner IP header is 4 or 6
  • if there are at least 2 IP headers, the inner IP header is not an IP fragment
  • the inner IP payload is at least 8-byte long for UDP header
  • the UDP Length field and the UDP payload match
  • the UDP payload is at least 12-byte long for RTP header
  • the UDP ports are in the list of RTP ports or the user-defined RTP callback function detected one RTP packet
See also
c_udp_check_profile

This function is one of the functions that must exist in one profile for the framework to work.

Parameters
compThe ROHC compressor
packetThe packet to check
Returns
Whether the IP packet corresponds to the profile:
  • true if the IP packet corresponds to the profile,
  • false if the IP packet does not correspond to the profile
static bool c_rtp_create ( struct rohc_comp_ctxt *const  context,
const struct net_pkt *const  packet 
)
static

Create a new RTP context and initialize it thanks to the given IP/UDP/RTP packet.

This function is one of the functions that must exist in one profile for the framework to work.

Parameters
contextThe compression context
packetThe IP/UDP/RTP packet given to initialize the new context
Returns
true if successful, false otherwise
static rohc_ext_t c_rtp_decide_extension ( const struct rohc_comp_ctxt context)
static

Decide what extension shall be used in the UO-1/UO-2 packet.

Extensions 0, 1 & 2 are IPv4 only because of the IP-ID.

Parameters
contextThe compression context
Returns
The extension code among ROHC_EXT_NO, ROHC_EXT_0, ROHC_EXT_1 and ROHC_EXT_3 if successful, ROHC_EXT_UNKNOWN otherwise
static rohc_packet_t c_rtp_decide_FO_packet ( const struct rohc_comp_ctxt context)
static

Decide which packet to send when in First Order (FO) state.

Packets that can be used are the IR-DYN and UO-2 packets.

See also
decide_packet
Parameters
contextThe compression context
Returns
The packet type among:
  • ROHC_PACKET_UOR_2_RTP
  • ROHC_PACKET_UOR_2_TS
  • ROHC_PACKET_UOR_2_ID
  • ROHC_PACKET_IR_DYN
static rohc_packet_t c_rtp_decide_SO_packet ( const struct rohc_comp_ctxt context)
static

Decide which packet to send when in Second Order (SO) state.

Packets that can be used are the UO-0, UO-1 and UO-2 (with or without extensions) packets.

See also
decide_packet
Parameters
contextThe compression context
Returns
The packet type among:
  • ROHC_PACKET_UO_0
  • ROHC_PACKET_UO_1_RTP
  • ROHC_PACKET_UO_1_TS
  • ROHC_PACKET_UO_1_ID
  • ROHC_PACKET_UOR_2_RTP
  • ROHC_PACKET_UOR_2_TS
  • ROHC_PACKET_UOR_2_ID
  • ROHC_PACKET_IR_DYN
static void c_rtp_destroy ( struct rohc_comp_ctxt *const  context)
static

Destroy the RTP context.

This function is one of the functions that must exist in one profile for the framework to work.

Parameters
contextThe RTP compression context to destroy
static int c_rtp_encode ( struct rohc_comp_ctxt *const  context,
const struct net_pkt *const  uncomp_pkt,
uint8_t *const  rohc_pkt,
const size_t  rohc_pkt_max_len,
rohc_packet_t *const  packet_type,
size_t *const  payload_offset 
)
static

Encode an IP/UDP/RTP packet according to a pattern decided by several different factors.

Parameters
contextThe compression context
uncomp_pktThe uncompressed packet to encode
rohc_pktOUT: The ROHC packet
rohc_pkt_max_lenThe maximum length of the ROHC packet
packet_typeOUT: The type of ROHC packet that is created
payload_offsetOUT: The offset for the payload in the IP packet
Returns
The length of the ROHC packet if successful, -1 otherwise
static uint32_t c_rtp_get_next_sn ( const struct rohc_comp_ctxt *const  context,
const struct net_pkt *const  uncomp_pkt 
)
static

Determine the SN value for the next packet.

Profile SN is the 16-bit RTP SN.

Parameters
contextThe compression context
uncomp_pktThe uncompressed packet to encode
Returns
The SN
static int rtp_changed_rtp_dynamic ( const struct rohc_comp_ctxt *const  context,
const struct udphdr *const  udp,
const struct rtphdr *const  rtp 
)
static

Check if the dynamic part of the UDP/RTP headers changed.

Parameters
contextThe compression context
udpThe UDP header
rtpThe RTP header
Returns
The number of UDP/RTP fields that changed
static size_t rtp_code_dynamic_rtp_part ( const struct rohc_comp_ctxt *const  context,
const uint8_t *const  next_header,
uint8_t *const  dest,
const size_t  counter 
)
static

Build the dynamic part of the UDP/RTP headers.

 Dynamic part of UDP header (5.7.7.5):

    +---+---+---+---+---+---+---+---+
 1  /           Checksum            /   2 octets
    +---+---+---+---+---+---+---+---+

 Dynamic part of RTP header (5.7.7.6):

    +---+---+---+---+---+---+---+---+
 2  |  V=2  | P | RX|      CC       |  (RX is NOT the RTP X bit)
    +---+---+---+---+---+---+---+---+
 3  | M |            PT             |
    +---+---+---+---+---+---+---+---+
 4  /      RTP Sequence Number      /  2 octets
    +---+---+---+---+---+---+---+---+
 5  /   RTP Timestamp (absolute)    /  4 octets
    +---+---+---+---+---+---+---+---+
 6  /      Generic CSRC list        /  variable length
    +---+---+---+---+---+---+---+---+
 7  : Reserved  | X |  Mode |TIS|TSS:  if RX = 1
    +---+---+---+---+---+---+---+---+
 8  :         TS_Stride             :  1-4 octets, if TSS = 1
    +---+---+---+---+---+---+---+---+
 9  :         Time_Stride           :  1-4 octets, if TIS = 1
    +---+---+---+---+---+---+---+---+

Parts 6 & 9 are not supported yet. The TIS flag in part 7 is not supported.

Parameters
contextThe compression context
next_headerThe UDP/RTP headers
destThe rohc-packet-under-build buffer
counterThe current position in the rohc-packet-under-build buffer
Returns
The new position in the rohc-packet-under-build buffer
static size_t rtp_code_static_rtp_part ( const struct rohc_comp_ctxt *const  context,
const uint8_t *const  next_header,
uint8_t *const  dest,
const size_t  counter 
)
static

Build the static part of the UDP/RTP headers.

 Static part of UDP header (5.7.7.5):

    +---+---+---+---+---+---+---+---+
 1  /          Source Port          /   2 octets
    +---+---+---+---+---+---+---+---+
 2  /       Destination Port        /   2 octets
    +---+---+---+---+---+---+---+---+

 Static part of RTP header (5.7.7.6):

    +---+---+---+---+---+---+---+---+
 3  /             SSRC              /   4 octets
    +---+---+---+---+---+---+---+---+

Parts 1 & 2 are done by the udp_code_static_udp_part() function. Part 3 is done by this function.

Parameters
contextThe compression context
next_headerThe UDP/RTP headers
destThe rohc-packet-under-build buffer
counterThe current position in the rohc-packet-under-build buffer
Returns
The new position in the rohc-packet-under-build buffer
See also
udp_code_static_udp_part
static void rtp_decide_state ( struct rohc_comp_ctxt *const  context)
static

Decide the state that should be used for the next packet compressed with the ROHC RTP profile.

The three states are:

  • Initialization and Refresh (IR),
  • First Order (FO),
  • Second Order (SO).
Parameters
contextThe compression context
static bool rtp_encode_uncomp_fields ( struct rohc_comp_ctxt *const  context,
const struct net_pkt *const  uncomp_pkt 
)
static

Encode uncompressed RTP fields.

Handle the RTP TS field.

Parameters
contextThe compression context
uncomp_pktThe uncompressed packet to encode
Returns
true in case of success, false otherwise

Variable Documentation

const struct rohc_comp_profile c_rtp_profile
Initial value:
=
{
.protocol = ROHC_IPPROTO_UDP,
.create = c_rtp_create,
.destroy = c_rtp_destroy,
.check_profile = c_rtp_check_profile,
.check_context = c_rtp_check_context,
.encode = c_rtp_encode,
.reinit_context = rohc_comp_reinit_context,
}
Definition: rohc.h:217
static bool c_rtp_check_profile(const struct rohc_comp *const comp, const struct net_pkt *const packet)
Check if the given packet corresponds to the RTP profile.
Definition: c_rtp.c:268
Definition: ip_numbers.h:62
static bool c_rtp_create(struct rohc_comp_ctxt *const context, const struct net_pkt *const packet)
Create a new RTP context and initialize it thanks to the given IP/UDP/RTP packet. ...
Definition: c_rtp.c:119
bool rohc_comp_rfc3095_feedback(struct rohc_comp_ctxt *const context, const enum rohc_feedback_type feedback_type, const uint8_t *const packet, const size_t packet_len, const uint8_t *const feedback_data, const size_t feedback_data_len)
Update the profile when feedback is received.
Definition: rohc_comp_rfc3095.c:908
static bool c_rtp_check_context(const struct rohc_comp_ctxt *const context, const struct net_pkt *const packet)
Check if the IP/UDP/RTP packet belongs to the context.
Definition: c_rtp.c:390
bool rohc_comp_reinit_context(struct rohc_comp_ctxt *const context)
Re-initialize the given context.
Definition: rohc_comp.c:2694
static int c_rtp_encode(struct rohc_comp_ctxt *const context, const struct net_pkt *const uncomp_pkt, uint8_t *const rohc_pkt, const size_t rohc_pkt_max_len, rohc_packet_t *const packet_type, size_t *const payload_offset)
Encode an IP/UDP/RTP packet according to a pattern decided by several different factors.
Definition: c_rtp.c:837
static void c_rtp_destroy(struct rohc_comp_ctxt *const context)
Destroy the RTP context.
Definition: c_rtp.c:223

Define the compression part of the RTP profile as described in the RFC 3095.