Zephyr API Documentation 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
RTP (Real-time Transport Protocol)

Data Structures

struct  rtp_header_extension
 RTP header extension as defined in RFC 3550 section 5.3.1. More...
struct  rtp_header
 RTP fixed header as defined in RFC 3550 section 5.1. More...
struct  rtp_packet
 Decoded RTP packet with header and payload separated. More...
struct  rtp_session_context
 RTP session configuration context. More...
struct  rtp_transport
 Internal transport state embedded in rtp_session. More...
struct  rtp_session
 RTP session state. More...

Macros

#define RTP_VERSION   2
 RTP protocol version 2 as defined in RFC 3550.
#define RTP_MIN_HEADER_LEN   12
 Minimum RTP header length in bytes, excluding any CSRC list or extension.
#define RTP_PAYLOAD_TYPE_MAX   127
 Maximum value for the payload type in an RTP packet.
#define RTP_MARKER   1
 Convenience value for the marker argument of rtp_session_send that sets the RTP marker bit.
#define RTP_HDR_V_MASK   GENMASK(7, 6)
 Mask for the version (V) field within rtp_header::vpxcc.
#define RTP_HDR_P_MASK   BIT(5)
 Mask for the padding (P) flag within rtp_header::vpxcc.
#define RTP_HDR_X_MASK   BIT(4)
 Mask for the extension (X) flag within rtp_header::vpxcc.
#define RTP_HDR_CC_MASK   GENMASK(3, 0)
 Mask for the CSRC count (CC) field within rtp_header::vpxcc.
#define RTP_HDR_M_MASK   BIT(7)
 Mask for the marker (M) bit within rtp_header::mpt.
#define RTP_HDR_PT_MASK   GENMASK(6, 0)
 Mask for the payload type (PT) field within rtp_header::mpt.
#define RTP_MAX_CSRC_COUNT   CONFIG_RTP_MAX_CSRC_COUNT
 Maximum number of csrc's that can be stored.
#define RTP_SESSION_DEFINE(_name, _local_port)
 Define an RTP session.

Typedefs

typedef void(* rtp_rx_cb_t) (struct rtp_session *session, struct rtp_packet *packet, void *user_data)
 RTP packet receive callback type.

Enumerations

enum  rtp_role { RTP_ROLE_SINK , RTP_ROLE_SOURCE , RTP_ROLE_BOTH }
 Role of an RTP session. More...
enum  rtp_transport_type { RTP_TRANSPORT_NUM }
 Transport backend used by an RTP session. More...

Functions

int rtp_init_header_extension (struct rtp_header_extension *hdr_x, uint16_t definition, uint8_t *data, size_t len)
 Initialize an RTP header extension.
int rtp_session_init (struct rtp_session *session, struct net_if *iface, struct net_sockaddr *sock_addr, enum rtp_role role, uint8_t payload_type, rtp_rx_cb_t callback, void *user_data, enum rtp_transport_type transport_type)
 Initialize an RTP session.
static int rtp_session_init_rx (struct rtp_session *session, struct net_if *iface, struct net_sockaddr *sock_addr, rtp_rx_cb_t callback, void *user_data, enum rtp_transport_type transport_type)
 Initialize a receive-only RTP session.
static int rtp_session_init_tx (struct rtp_session *session, struct net_if *iface, struct net_sockaddr *sock_addr, uint8_t payload_type, enum rtp_transport_type transport_type)
 Initialize a transmit-only RTP session.
int rtp_session_start (struct rtp_session *session)
 Start an RTP session.
int rtp_session_stop (struct rtp_session *session)
 Stop an RTP session.
int rtp_session_add_csrc (struct rtp_session *session, uint32_t csrc)
 Add a contributing source (CSRC) to the session.
int rtp_session_remove_csrc (struct rtp_session *session, uint32_t csrc)
 Remove a contributing source (CSRC) from the session.
int rtp_session_send (struct rtp_session *session, void *data, size_t len, uint32_t delta_ts, uint8_t padding, uint8_t marker, struct rtp_header_extension *hdr_x, uint32_t *timestamp)
 Send an RTP packet with an optional header extension and optional padding.
static int rtp_session_send_simple (struct rtp_session *session, void *data, size_t len, uint32_t delta_ts)
 Send an RTP packet without a header extension, padding or marker.
static uint8_t rtp_header_get_v (const struct rtp_header *h)
 Get the RTP version (V) field.
static uint8_t rtp_header_get_p (const struct rtp_header *h)
 Get the padding (P) flag.
static uint8_t rtp_header_get_x (const struct rtp_header *h)
 Get the extension (X) flag.
static uint8_t rtp_header_get_cc (const struct rtp_header *h)
 Get the CSRC count (CC) field.
static uint8_t rtp_header_get_m (const struct rtp_header *h)
 Get the marker (M) bit.
static uint8_t rtp_header_get_pt (const struct rtp_header *h)
 Get the payload type (PT) field.
static void rtp_header_set_v (struct rtp_header *h, uint8_t value)
 Set the RTP version (V) field.
static void rtp_header_set_p (struct rtp_header *h, uint8_t value)
 Set the padding (P) flag.
static void rtp_header_set_x (struct rtp_header *h, uint8_t value)
 Set the extension (X) flag.
static void rtp_header_set_cc (struct rtp_header *h, uint8_t value)
 Set the CSRC count (CC) field.
static void rtp_header_set_m (struct rtp_header *h, uint8_t value)
 Set the marker (M) bit.
static void rtp_header_set_pt (struct rtp_header *h, uint8_t value)
 Set the payload type (PT) field.

Detailed Description

Version
0.1.0

Macro Definition Documentation

◆ RTP_HDR_CC_MASK

#define RTP_HDR_CC_MASK   GENMASK(3, 0)

#include <zephyr/net/rtp.h>

Mask for the CSRC count (CC) field within rtp_header::vpxcc.

◆ RTP_HDR_M_MASK

#define RTP_HDR_M_MASK   BIT(7)

#include <zephyr/net/rtp.h>

Mask for the marker (M) bit within rtp_header::mpt.

◆ RTP_HDR_P_MASK

#define RTP_HDR_P_MASK   BIT(5)

#include <zephyr/net/rtp.h>

Mask for the padding (P) flag within rtp_header::vpxcc.

◆ RTP_HDR_PT_MASK

#define RTP_HDR_PT_MASK   GENMASK(6, 0)

#include <zephyr/net/rtp.h>

Mask for the payload type (PT) field within rtp_header::mpt.

◆ RTP_HDR_V_MASK

#define RTP_HDR_V_MASK   GENMASK(7, 6)

#include <zephyr/net/rtp.h>

Mask for the version (V) field within rtp_header::vpxcc.

◆ RTP_HDR_X_MASK

#define RTP_HDR_X_MASK   BIT(4)

#include <zephyr/net/rtp.h>

Mask for the extension (X) flag within rtp_header::vpxcc.

◆ RTP_MARKER

#define RTP_MARKER   1

#include <zephyr/net/rtp.h>

Convenience value for the marker argument of rtp_session_send that sets the RTP marker bit.

Pass 0 to clear the bit.

◆ RTP_MAX_CSRC_COUNT

#define RTP_MAX_CSRC_COUNT   CONFIG_RTP_MAX_CSRC_COUNT

#include <zephyr/net/rtp.h>

Maximum number of csrc's that can be stored.

◆ RTP_MIN_HEADER_LEN

#define RTP_MIN_HEADER_LEN   12

#include <zephyr/net/rtp.h>

Minimum RTP header length in bytes, excluding any CSRC list or extension.

◆ RTP_PAYLOAD_TYPE_MAX

#define RTP_PAYLOAD_TYPE_MAX   127

#include <zephyr/net/rtp.h>

Maximum value for the payload type in an RTP packet.

◆ RTP_SESSION_DEFINE

#define RTP_SESSION_DEFINE ( _name,
_local_port )

#include <zephyr/net/rtp.h>

Value:
struct rtp_session _name = {.local_port = _local_port, RTP_SESSION_NAME(_name)}
RTP session state.
Definition rtp.h:230

Define an RTP session.

Declares and zero-initializes a rtp_session variable. Call rtp_session_init to configure the session before starting it with rtp_session_start.

Parameters
_nameName of the rtp_session variable to define.
_local_portLocal UDP port used when transmitting packets. Set to 0 to let the stack select a port automatically (see CONFIG_RTP_LOCAL_PORT_BASE). Only used for RTP_TRANSPORT_NET_PKT.

◆ RTP_VERSION

#define RTP_VERSION   2

#include <zephyr/net/rtp.h>

RTP protocol version 2 as defined in RFC 3550.

Typedef Documentation

◆ rtp_rx_cb_t

typedef void(* rtp_rx_cb_t) (struct rtp_session *session, struct rtp_packet *packet, void *user_data)

#include <zephyr/net/rtp.h>

RTP packet receive callback type.

Called from the network receive context when an RTP packet arrives. Keep the callback short and non-blocking. The packet payload pointer is only valid for the duration of the callback.

The callback may still be invoked concurrently with, or immediately after, a stop of the session's receive path from another thread; a session being stopped is not a guarantee that no further callback is in flight or about to be dispatched. Implementations must tolerate a call landing after they consider the session stopped.

Parameters
sessionPointer to the RTP session that received the packet.
packetPointer to the received RTP packet.
user_dataOpaque user data supplied during session initialization.

Enumeration Type Documentation

◆ rtp_role

enum rtp_role

#include <zephyr/net/rtp.h>

Role of an RTP session.

Enumerator
RTP_ROLE_SINK 

Session receives packets only.

RTP_ROLE_SOURCE 

Session transmits packets only.

RTP_ROLE_BOTH 

Session both transmits and receives packets.

◆ rtp_transport_type

#include <zephyr/net/rtp.h>

Transport backend used by an RTP session.

Passed to rtp_session_init.

Enumerator
RTP_TRANSPORT_NUM 

Shall not be used as a transport type.

Indicator of maximum transport types possible.

Function Documentation

◆ rtp_header_get_cc()

uint8_t rtp_header_get_cc ( const struct rtp_header * h)
inlinestatic

#include <zephyr/net/rtp.h>

Get the CSRC count (CC) field.

Parameters
hRTP header to read.
Returns
CSRC count field value.

◆ rtp_header_get_m()

uint8_t rtp_header_get_m ( const struct rtp_header * h)
inlinestatic

#include <zephyr/net/rtp.h>

Get the marker (M) bit.

Parameters
hRTP header to read.
Returns
Marker bit value.

◆ rtp_header_get_p()

uint8_t rtp_header_get_p ( const struct rtp_header * h)
inlinestatic

#include <zephyr/net/rtp.h>

Get the padding (P) flag.

Parameters
hRTP header to read.
Returns
Padding flag value.

◆ rtp_header_get_pt()

uint8_t rtp_header_get_pt ( const struct rtp_header * h)
inlinestatic

#include <zephyr/net/rtp.h>

Get the payload type (PT) field.

Parameters
hRTP header to read.
Returns
Payload type field value.

◆ rtp_header_get_v()

uint8_t rtp_header_get_v ( const struct rtp_header * h)
inlinestatic

#include <zephyr/net/rtp.h>

Get the RTP version (V) field.

Parameters
hRTP header to read.
Returns
Version field value.

◆ rtp_header_get_x()

uint8_t rtp_header_get_x ( const struct rtp_header * h)
inlinestatic

#include <zephyr/net/rtp.h>

Get the extension (X) flag.

Parameters
hRTP header to read.
Returns
Extension flag value.

◆ rtp_header_set_cc()

void rtp_header_set_cc ( struct rtp_header * h,
uint8_t value )
inlinestatic

#include <zephyr/net/rtp.h>

Set the CSRC count (CC) field.

Parameters
hRTP header to modify.
valueCSRC count field value.

◆ rtp_header_set_m()

void rtp_header_set_m ( struct rtp_header * h,
uint8_t value )
inlinestatic

#include <zephyr/net/rtp.h>

Set the marker (M) bit.

Parameters
hRTP header to modify.
valueMarker bit value.

◆ rtp_header_set_p()

void rtp_header_set_p ( struct rtp_header * h,
uint8_t value )
inlinestatic

#include <zephyr/net/rtp.h>

Set the padding (P) flag.

Parameters
hRTP header to modify.
valuePadding flag value.

◆ rtp_header_set_pt()

void rtp_header_set_pt ( struct rtp_header * h,
uint8_t value )
inlinestatic

#include <zephyr/net/rtp.h>

Set the payload type (PT) field.

Parameters
hRTP header to modify.
valuePayload type field value.

◆ rtp_header_set_v()

void rtp_header_set_v ( struct rtp_header * h,
uint8_t value )
inlinestatic

#include <zephyr/net/rtp.h>

Set the RTP version (V) field.

Parameters
hRTP header to modify.
valueVersion field value.

◆ rtp_header_set_x()

void rtp_header_set_x ( struct rtp_header * h,
uint8_t value )
inlinestatic

#include <zephyr/net/rtp.h>

Set the extension (X) flag.

Parameters
hRTP header to modify.
valueExtension flag value.

◆ rtp_init_header_extension()

int rtp_init_header_extension ( struct rtp_header_extension * hdr_x,
uint16_t definition,
uint8_t * data,
size_t len )

#include <zephyr/net/rtp.h>

Initialize an RTP header extension.

Parameters
hdr_xPointer to the header extension struct to initialize.
definitionProfile-defined extension header identifier.
dataPointer to the extension data.
lenLength of data in bytes; must be aligned to a 32-bit word boundary.
Return values
0On success.
negativeErrno value on failure.

◆ rtp_session_add_csrc()

int rtp_session_add_csrc ( struct rtp_session * session,
uint32_t csrc )

#include <zephyr/net/rtp.h>

Add a contributing source (CSRC) to the session.

Parameters
sessionPointer to the RTP session.
csrcCSRC identifier to add.
Return values
0On success.
negativeErrno value on failure.

◆ rtp_session_init()

int rtp_session_init ( struct rtp_session * session,
struct net_if * iface,
struct net_sockaddr * sock_addr,
enum rtp_role role,
uint8_t payload_type,
rtp_rx_cb_t callback,
void * user_data,
enum rtp_transport_type transport_type )

#include <zephyr/net/rtp.h>

Initialize an RTP session.

Configure a session for transmit, receive, or both, as determined by role.

Parameters
sessionPointer to the RTP session to initialize.
ifaceNetwork interface to use.
sock_addrSession address and port (multicast group or unicast peer). The application should be aware of the fact that unicast sinks accept RTP packets from any sender.
roleWhether the session acts as a sink, source, or both.
payload_typeRTP payload type field value used when transmitting; ignored when role is RTP_ROLE_SINK.
callbackCallback invoked on packet reception; required when role is RTP_ROLE_SINK or RTP_ROLE_BOTH.
user_dataOpaque user data forwarded to callback.
transport_typeTransport backend to use; see rtp_transport_type.
Return values
0On success.
negativeErrno value on failure.

◆ rtp_session_init_rx()

int rtp_session_init_rx ( struct rtp_session * session,
struct net_if * iface,
struct net_sockaddr * sock_addr,
rtp_rx_cb_t callback,
void * user_data,
enum rtp_transport_type transport_type )
inlinestatic

#include <zephyr/net/rtp.h>

Initialize a receive-only RTP session.

Convenience wrapper around rtp_session_init that configures the session for receive only.

Parameters
sessionPointer to the RTP session to initialize.
ifaceNetwork interface to use.
sock_addrSession address and port to listen on.
callbackCallback invoked when a packet is received.
user_dataOpaque user data forwarded to callback.
transport_typeTransport backend to use; see rtp_transport_type.
Return values
0On success.
negativeErrno value on failure.

◆ rtp_session_init_tx()

int rtp_session_init_tx ( struct rtp_session * session,
struct net_if * iface,
struct net_sockaddr * sock_addr,
uint8_t payload_type,
enum rtp_transport_type transport_type )
inlinestatic

#include <zephyr/net/rtp.h>

Initialize a transmit-only RTP session.

Convenience wrapper around rtp_session_init that configures the session for transmit only.

Parameters
sessionPointer to the RTP session to initialize.
ifaceNetwork interface to use.
sock_addrSession address and port to send packets to.
payload_typeRTP payload type field value.
transport_typeTransport backend to use; see rtp_transport_type.
Return values
0On success.
negativeErrno value on failure.

◆ rtp_session_remove_csrc()

int rtp_session_remove_csrc ( struct rtp_session * session,
uint32_t csrc )

#include <zephyr/net/rtp.h>

Remove a contributing source (CSRC) from the session.

Parameters
sessionPointer to the RTP session.
csrcCSRC identifier to remove.
Return values
0On success.
negativeErrno value on failure.

◆ rtp_session_send()

int rtp_session_send ( struct rtp_session * session,
void * data,
size_t len,
uint32_t delta_ts,
uint8_t padding,
uint8_t marker,
struct rtp_header_extension * hdr_x,
uint32_t * timestamp )

#include <zephyr/net/rtp.h>

Send an RTP packet with an optional header extension and optional padding.

Parameters
sessionPointer to the RTP session.
dataPointer to the payload data to send.
lenLength of data in bytes.
delta_tsTimestamp increment to apply; for audio this is typically the number of sample periods covered by the payload.
paddingNumber of padding bytes to append (0–255); pass 0 for no padding.
markerMarker bit value; use RTP_MARKER to set the bit or 0 to clear it.
hdr_xPointer to a header extension, or NULL for no extension.
[out]timestampPointer to store the RTP timestamp used in the packet. Can be left NULL if the timestamp is of no interest for the caller.
Return values
0On success.
negativeErrno value on failure.

◆ rtp_session_send_simple()

int rtp_session_send_simple ( struct rtp_session * session,
void * data,
size_t len,
uint32_t delta_ts )
inlinestatic

#include <zephyr/net/rtp.h>

Send an RTP packet without a header extension, padding or marker.

Convenience wrapper around rtp_session_send.

Parameters
sessionPointer to the RTP session.
dataPointer to the payload data to send.
lenLength of data in bytes.
delta_tsTimestamp increment to apply; for audio this is typically the number of sample periods covered by the payload.
Return values
0On success.
negativeErrno value on failure.

◆ rtp_session_start()

int rtp_session_start ( struct rtp_session * session)

#include <zephyr/net/rtp.h>

Start an RTP session.

Open the network connections and begin processing packets. The session must have been configured with rtp_session_init before calling this function.

Parameters
sessionPointer to the RTP session.
Return values
0On success.
negativeErrno value on failure.

◆ rtp_session_stop()

int rtp_session_stop ( struct rtp_session * session)

#include <zephyr/net/rtp.h>

Stop an RTP session.

Close the network connections and stop processing packets.

Parameters
sessionPointer to the RTP session.
Return values
0On success.
negativeErrno value on failure.