12#ifndef ZEPHYR_INCLUDE_NET_RTP_H_
13#define ZEPHYR_INCLUDE_NET_RTP_H_
20#ifdef CONFIG_NET_PKT_TIMESTAMP
42#define RTP_MIN_HEADER_LEN 12
45#define RTP_PAYLOAD_TYPE_MAX 127
53#define RTP_HDR_V_MASK GENMASK(7, 6)
55#define RTP_HDR_P_MASK BIT(5)
57#define RTP_HDR_X_MASK BIT(4)
59#define RTP_HDR_CC_MASK GENMASK(3, 0)
61#define RTP_HDR_M_MASK BIT(7)
63#define RTP_HDR_PT_MASK GENMASK(6, 0)
65#if defined(CONFIG_RTP_MAX_CSRC_COUNT) || defined(__DOXYGEN__)
67#define RTP_MAX_CSRC_COUNT CONFIG_RTP_MAX_CSRC_COUNT
69#define RTP_MAX_CSRC_COUNT 0
113#ifdef CONFIG_NET_PKT_TIMESTAMP
178#ifdef CONFIG_RTP_TRANSPORT_SOCKET
182 RTP_TRANSPORT_SOCKET,
184#ifdef CONFIG_RTP_TRANSPORT_NET_PKT
189 RTP_TRANSPORT_NET_PKT,
198BUILD_ASSERT(
RTP_TRANSPORT_NUM > 0,
"Please select at least 1 RTP transport backend");
209#ifdef CONFIG_RTP_TRANSPORT_SOCKET
217#ifdef CONFIG_RTP_TRANSPORT_NET_PKT
220 struct net_conn_handle *net_handle_rtp;
258#if defined(CONFIG_SRTP) || defined(__DOXYGEN__)
267#if CONFIG_RTP_LOG_LEVEL >= LOG_LEVEL_DBG
274#if CONFIG_RTP_LOG_LEVEL >= LOG_LEVEL_DBG
275#define RTP_SESSION_NAME(_name) .name = STRINGIFY(_name),
277#define RTP_SESSION_NAME(_name)
294#define RTP_SESSION_DEFINE(_name, _local_port) \
295 struct rtp_session _name = {.local_port = _local_port, RTP_SESSION_NAME(_name)}
385 NULL, transport_type);
476#if defined(CONFIG_SRTP) || defined(__DOXYGEN__)
549 __ASSERT_NO_MSG(h != NULL);
563 __ASSERT_NO_MSG(h != NULL);
577 __ASSERT_NO_MSG(h != NULL);
591 __ASSERT_NO_MSG(h != NULL);
605 __ASSERT_NO_MSG(h != NULL);
619 __ASSERT_NO_MSG(h != NULL);
632 __ASSERT_NO_MSG(h != NULL);
646 __ASSERT_NO_MSG(h != NULL);
660 __ASSERT_NO_MSG(h != NULL);
674 __ASSERT_NO_MSG(h != NULL);
688 __ASSERT_NO_MSG(h != NULL);
702 __ASSERT_NO_MSG(h != NULL);
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 void rtp_header_set_pt(struct rtp_header *h, uint8_t value)
Set the payload type (PT) field.
Definition rtp.h:700
rtp_transport_type
Transport backend used by an RTP session.
Definition rtp.h:177
int rtp_session_set_srtp(struct rtp_session *session, const struct srtp_policy *tx_policy, const struct srtp_policy *rx_policy, struct srtp_session_ctx *srtp_ctx)
Enable SRTP protection on an RTP session.
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.
static uint8_t rtp_header_get_pt(const struct rtp_header *h)
Get the payload type (PT) field.
Definition rtp.h:617
static void rtp_header_set_cc(struct rtp_header *h, uint8_t value)
Set the CSRC count (CC) field.
Definition rtp.h:672
static uint8_t rtp_header_get_m(const struct rtp_header *h)
Get the marker (M) bit.
Definition rtp.h:603
static void rtp_header_set_m(struct rtp_header *h, uint8_t value)
Set the marker (M) bit.
Definition rtp.h:686
static void rtp_header_set_x(struct rtp_header *h, uint8_t value)
Set the extension (X) flag.
Definition rtp.h:658
int rtp_session_start(struct rtp_session *session)
Start an RTP session.
int rtp_session_add_csrc(struct rtp_session *session, uint32_t csrc)
Add a contributing source (CSRC) to the session.
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.
Definition rtp.h:470
int rtp_session_clear_srtp(struct rtp_session *session)
Disable SRTP protection on 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.
Definition rtp.h:357
#define RTP_HDR_X_MASK
Mask for the extension (X) flag within rtp_header::vpxcc.
Definition rtp.h:57
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.
int rtp_session_remove_csrc(struct rtp_session *session, uint32_t csrc)
Remove a contributing source (CSRC) from the session.
static uint8_t rtp_header_get_cc(const struct rtp_header *h)
Get the CSRC count (CC) field.
Definition rtp.h:589
#define RTP_HDR_PT_MASK
Mask for the payload type (PT) field within rtp_header::mpt.
Definition rtp.h:63
#define RTP_HDR_P_MASK
Mask for the padding (P) flag within rtp_header::vpxcc.
Definition rtp.h:55
void(* rtp_rx_cb_t)(struct rtp_session *session, struct rtp_packet *packet, void *user_data)
RTP packet receive callback type.
Definition rtp.h:142
#define RTP_HDR_V_MASK
Mask for the version (V) field within rtp_header::vpxcc.
Definition rtp.h:53
int rtp_session_stop(struct rtp_session *session)
Stop an RTP session.
static uint8_t rtp_header_get_x(const struct rtp_header *h)
Get the extension (X) flag.
Definition rtp.h:575
static uint8_t rtp_header_get_p(const struct rtp_header *h)
Get the padding (P) flag.
Definition rtp.h:561
#define RTP_HDR_CC_MASK
Mask for the CSRC count (CC) field within rtp_header::vpxcc.
Definition rtp.h:59
static uint8_t rtp_header_get_v(const struct rtp_header *h)
Get the RTP version (V) field.
Definition rtp.h:547
#define RTP_MAX_CSRC_COUNT
Maximum number of csrc's that can be stored.
Definition rtp.h:67
static void rtp_header_set_p(struct rtp_header *h, uint8_t value)
Set the padding (P) flag.
Definition rtp.h:644
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.
Definition rtp.h:380
#define RTP_HDR_M_MASK
Mask for the marker (M) bit within rtp_header::mpt.
Definition rtp.h:61
rtp_role
Role of an RTP session.
Definition rtp.h:146
static void rtp_header_set_v(struct rtp_header *h, uint8_t value)
Set the RTP version (V) field.
Definition rtp.h:630
@ RTP_TRANSPORT_NUM
Shall not be used as a transport type.
Definition rtp.h:195
@ RTP_ROLE_BOTH
Session both transmits and receives packets.
Definition rtp.h:152
@ RTP_ROLE_SOURCE
Session transmits packets only.
Definition rtp.h:150
@ RTP_ROLE_SINK
Session receives packets only.
Definition rtp.h:148
Header file for the logging core.
BSD Sockets compatible API definitions.
Network context definitions.
Public API for network interface.
IPv6 and IPv4 definitions.
Public functions for the Precision Time Protocol time specification.
#define FIELD_PREP(mask, value)
Definition silabs-pinctrl-siwx91x.h:15
#define FIELD_GET(mask, value)
Definition silabs-pinctrl-siwx91x.h:14
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Kernel mutex structure.
Definition kernel.h:3774
Network Interface structure.
Definition net_if.h:875
(Generalized) Precision Time Protocol Timestamp format.
Definition ptp_time.h:111
Generic sockaddr struct.
Definition net_ip.h:462
Decoded RTP packet with header and payload separated.
Definition rtp.h:105
uint8_t * payload
Pointer to the packet payload.
Definition rtp.h:109
struct rtp_header header
Parsed RTP header.
Definition rtp.h:107
size_t payload_len
Length of the payload in bytes.
Definition rtp.h:111
RTP session configuration context.
Definition rtp.h:156
void * user_data
Opaque user data forwarded to callback.
Definition rtp.h:173
rtp_rx_cb_t callback
Callback invoked upon packet reception; required when role is RTP_ROLE_SINK or RTP_ROLE_BOTH.
Definition rtp.h:171
struct net_sockaddr_storage sock_addr
Session address and port (multicast group address or unicast peer).
Definition rtp.h:161
enum rtp_role role
Role of the session: sink, source, or both.
Definition rtp.h:163
uint8_t payload_type
RTP payload type field value used when transmitting.
Definition rtp.h:166
struct net_if * iface
Network interface used by the session.
Definition rtp.h:158
RTP session state.
Definition rtp.h:232
uint32_t timestamp
Current RTP timestamp, advanced with each transmitted packet.
Definition rtp.h:244
uint16_t local_port
Local UDP port used when transmitting; 0 to auto-select (see <code class='doxyxref' data-stype='kcon...
Definition rtp.h:251
struct rtp_transport transport
Transport info.
Definition rtp.h:234
size_t csrc_len
Number of active entries in csrc.
Definition rtp.h:256
const char * name
Human-readable session name used in debug log messages.
Definition rtp.h:269
struct k_mutex lock
Mutex protecting concurrent access to session state.
Definition rtp.h:239
uint32_t csrc[CONFIG_RTP_MAX_CSRC_COUNT]
Contributing source (CSRC) identifier list.
Definition rtp.h:254
uint16_t sequence_number
Sequence number of the next packet to be transmitted.
Definition rtp.h:246
struct rtp_session_context rtp_context
Session configuration context.
Definition rtp.h:236
struct srtp_session_ctx * srtp
SRTP state installed with rtp_session_set_srtp; NULL when the session runs plain RTP.
Definition rtp.h:264
uint32_t ssrc
Synchronization source (SSRC) identifier for this session.
Definition rtp.h:242
Internal transport state embedded in rtp_session.
Definition rtp.h:203
enum rtp_transport_type type
Active transport backend for this session.
Definition rtp.h:205
SRTP stream protection policy.
Definition srtp.h:89
SRTP state of an RTP session.
Definition srtp.h:279