ROHC compression/decompression library
Defines | 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.h"
#include "rohc_packets.h"
#include "rohc_utils.h"
#include "sdvl.h"
#include "crc.h"
#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
Include dependency graph for c_rtp.c:

Defines

#define RTP_PORTS   1234, 36780, 33238, 5020, 5002
 The list of UDP ports associated with RTP streams.

Functions

int rtp_code_static_rtp_part (const struct c_context *context, const unsigned char *next_header, unsigned char *const dest, int counter)
 Build the static part of the UDP/RTP headers.
int rtp_code_dynamic_rtp_part (const struct c_context *context, const unsigned char *next_header, unsigned char *const dest, int counter)
 Build the dynamic part of the UDP/RTP headers.
int rtp_changed_rtp_dynamic (const struct c_context *context, const struct udphdr *udp)
 Check if the dynamic part of the UDP/RTP headers changed.
int c_rtp_create (struct c_context *const context, const struct ip_packet *ip)
 Create a new RTP context and initialize it thanks to the given IP/UDP/RTP packet.
void c_rtp_destroy (struct c_context *const context)
 Destroy the RTP context.
int c_rtp_check_context (const struct c_context *context, const struct ip_packet *ip)
 Check if the IP/UDP/RTP packet belongs to the context.
int c_rtp_encode (struct c_context *const context, const struct ip_packet *ip, const int packet_size, unsigned char *const dest, const int dest_size, rohc_packet_t *const packet_type, int *const payload_offset)
 Encode an IP/UDP/RTP packet according to a pattern decided by several different factors.
void rtp_decide_state (struct c_context *const context)
 Decide the state that should be used for the next packet compressed with the ROHC RTP profile.

Variables

int rtp_ports [] = { RTP_PORTS, 0 }
 List of UDP ports which are associated with RTP streams.
struct c_profile c_rtp_profile
 Define the compression part of the RTP profile as described in the RFC 3095.

Detailed Description

ROHC compression context for the RTP profile.

Author:
David Moreau from TAS
Didier Barvaux <didier.barvaux@toulouse.viveris.com>
Didier Barvaux <didier@barvaux.org>

Define Documentation

#define RTP_PORTS   1234, 36780, 33238, 5020, 5002

The list of UDP ports associated with RTP streams.

The port numbers must be separated by a comma


Function Documentation

int c_rtp_check_context ( const struct c_context context,
const struct ip_packet ip 
)

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
ipThe IP/UDP/RTP packet to check
Returns:
1 if the IP/UDP/RTP packet belongs to the context, 0 if it does not belong to the context and -1 if an error occurs
See also:
c_udp_check_context

References c_udp_check_context(), ip_get_inner_packet(), ip_get_next_layer(), ip_get_protocol(), sc_rtp_context::old_rtp, rohc_debugf, ROHC_IPPROTO_IPIP, ROHC_IPPROTO_IPV6, c_context::specific, c_generic_context::specific, and rtphdr::ssrc.

int c_rtp_create ( struct c_context *const  context,
const struct ip_packet ip 
)

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
ipThe IP/UDP/RTP packet given to initialize the new context
Returns:
1 if successful, 0 otherwise

References c_create_sc(), c_generic_create(), c_generic_destroy(), c_generic_context::code_dynamic_part, c_generic_context::code_ir_remainder, c_generic_context::code_static_part, c_generic_context::code_UO_packet_head, c_generic_context::code_uo_remainder, c_context::compressor, c_generic_context::compute_crc_dynamic, c_generic_context::compute_crc_static, c_generic_context::decide_extension, c_generic_context::decide_FO_packet, c_generic_context::decide_SO_packet, c_generic_context::decide_state, c_generic_context::encode_uncomp_fields, c_generic_context::get_next_sn, c_generic_context::init_at_IR, ip_get_inner_packet(), ip_get_next_layer(), ip_get_protocol(), rtp_tmp_vars::m_set, c_generic_context::next_header_len, c_generic_context::next_header_proto, rtp_tmp_vars::nr_ts_bits, sc_rtp_context::old_rtp, sc_rtp_context::old_udp, rohc_debugf, ROHC_IPPROTO_IPIP, ROHC_IPPROTO_IPV6, ROHC_IPPROTO_UDP, ROHC_LSB_SHIFT_RTP_SN, rtp_code_dynamic_rtp_part(), rtp_code_static_rtp_part(), rtp_compute_crc_dynamic(), rtp_compute_crc_static(), rtp_decide_state(), sc_rtp_context::rtp_pt_change_count, rtp_tmp_vars::rtp_pt_changed, rtp_tmp_vars::send_rtp_dynamic, rtphdr::sn, c_generic_context::sn, c_context::specific, c_generic_context::specific, rtp_tmp_vars::timestamp, sc_rtp_context::tmp, sc_rtp_context::ts_sc, rtp_tmp_vars::ts_send, sc_rtp_context::udp_checksum_change_count, udp_code_uo_remainder(), and rohc_comp::wlsb_window_width.

void c_rtp_destroy ( struct c_context *const  context)

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

References c_destroy_sc(), c_generic_destroy(), c_context::specific, c_generic_context::specific, and sc_rtp_context::ts_sc.

int c_rtp_encode ( struct c_context *const  context,
const struct ip_packet ip,
const int  packet_size,
unsigned char *const  dest,
const int  dest_size,
rohc_packet_t *const  packet_type,
int *const  payload_offset 
)

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

Parameters:
contextThe compression context
ipThe IP packet to encode
packet_sizeThe length of the IP packet to encode
destThe rohc-packet-under-build buffer
dest_sizeThe length of the rohc-packet-under-build buffer
packet_typeOUT: The type of ROHC packet that is created
payload_offsetThe offset for the payload in the IP packet
Returns:
The length of the created ROHC packet

References c_generic_encode(), ip_get_inner_packet(), ip_get_next_layer(), ip_get_protocol(), sc_rtp_context::old_rtp, sc_rtp_context::old_udp, PACKET_IR, PACKET_IR_DYN, generic_tmp_vars::packet_type, rohc_debugf, ROHC_IPPROTO_IPIP, ROHC_IPPROTO_IPV6, ROHC_IPPROTO_UDP, rtp_changed_rtp_dynamic(), rtp_tmp_vars::send_rtp_dynamic, c_context::specific, c_generic_context::specific, sc_rtp_context::tmp, and c_generic_context::tmp.

int rtp_changed_rtp_dynamic ( const struct c_context context,
const struct udphdr udp 
)
int rtp_code_dynamic_rtp_part ( const struct c_context context,
const unsigned char *  next_header,
unsigned char *const  dest,
int  counter 
)

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

References c_bytesSdvl(), c_encodeSdvl(), rtphdr::cc, udphdr::check, rtphdr::extension, get_ts_stride(), INIT_STRIDE, INIT_TS, rtphdr::m, c_context::mode, ts_sc_comp::nr_init_stride_packets, rtphdr::padding, rtphdr::pt, rohc_debugf, ROHC_INIT_TS_STRIDE_MIN, sc_rtp_context::rtp_pt_change_count, SEND_SCALED, rtphdr::sn, c_context::specific, c_generic_context::specific, ts_sc_comp::state, rtphdr::timestamp, sc_rtp_context::ts_sc, sc_rtp_context::udp_checksum_change_count, and rtphdr::version.

Referenced by c_rtp_create().

int rtp_code_static_rtp_part ( const struct c_context context,
const unsigned char *  next_header,
unsigned char *const  dest,
int  counter 
)

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

References rohc_debugf, rtphdr::ssrc, and udp_code_static_udp_part().

Referenced by c_rtp_create().

void rtp_decide_state ( struct c_context *const  context)

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

References change_state(), decide_state(), FO, INIT_TS, IR, MAX_IR_COUNT, rohc_debugf, rtp_tmp_vars::send_rtp_dynamic, c_context::specific, c_generic_context::specific, ts_sc_comp::state, c_context::state, sc_rtp_context::tmp, sc_rtp_context::ts_sc, and sc_rtp_context::udp_checksum_change_count.

Referenced by c_rtp_create().


Variable Documentation

Initial value:

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

int rtp_ports[] = { RTP_PORTS, 0 }

List of UDP ports which are associated with RTP streams.