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
176#ifdef CONFIG_RTP_TRANSPORT_SOCKET
180 RTP_TRANSPORT_SOCKET,
182#ifdef CONFIG_RTP_TRANSPORT_NET_PKT
187 RTP_TRANSPORT_NET_PKT,
196BUILD_ASSERT(
RTP_TRANSPORT_NUM > 0,
"Please select at least 1 RTP transport backend");
207#ifdef CONFIG_RTP_TRANSPORT_SOCKET
215#ifdef CONFIG_RTP_TRANSPORT_NET_PKT
218 struct net_conn_handle *net_handle_rtp;
256#if CONFIG_RTP_LOG_LEVEL >= LOG_LEVEL_DBG
263#if CONFIG_RTP_LOG_LEVEL >= LOG_LEVEL_DBG
264#define RTP_SESSION_NAME(_name) .name = STRINGIFY(_name),
266#define RTP_SESSION_NAME(_name)
283#define RTP_SESSION_DEFINE(_name, _local_port) \
284 struct rtp_session _name = {.local_port = _local_port, RTP_SESSION_NAME(_name)}
369 NULL, transport_type);
469 __ASSERT_NO_MSG(h != NULL);
483 __ASSERT_NO_MSG(h != NULL);
497 __ASSERT_NO_MSG(h != NULL);
511 __ASSERT_NO_MSG(h != NULL);
525 __ASSERT_NO_MSG(h != NULL);
539 __ASSERT_NO_MSG(h != NULL);
552 __ASSERT_NO_MSG(h != NULL);
566 __ASSERT_NO_MSG(h != NULL);
580 __ASSERT_NO_MSG(h != NULL);
594 __ASSERT_NO_MSG(h != NULL);
608 __ASSERT_NO_MSG(h != NULL);
622 __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:620
rtp_transport_type
Transport backend used by an RTP session.
Definition rtp.h:175
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:537
static void rtp_header_set_cc(struct rtp_header *h, uint8_t value)
Set the CSRC count (CC) field.
Definition rtp.h:592
static uint8_t rtp_header_get_m(const struct rtp_header *h)
Get the marker (M) bit.
Definition rtp.h:523
static void rtp_header_set_m(struct rtp_header *h, uint8_t value)
Set the marker (M) bit.
Definition rtp.h:606
static void rtp_header_set_x(struct rtp_header *h, uint8_t value)
Set the extension (X) flag.
Definition rtp.h:578
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:454
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:341
#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:509
#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:140
#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:495
static uint8_t rtp_header_get_p(const struct rtp_header *h)
Get the padding (P) flag.
Definition rtp.h:481
#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:467
#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:564
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:364
#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:144
static void rtp_header_set_v(struct rtp_header *h, uint8_t value)
Set the RTP version (V) field.
Definition rtp.h:550
@ RTP_TRANSPORT_NUM
Shall not be used as a transport type.
Definition rtp.h:193
@ RTP_ROLE_BOTH
Session both transmits and receives packets.
Definition rtp.h:150
@ RTP_ROLE_SOURCE
Session transmits packets only.
Definition rtp.h:148
@ RTP_ROLE_SINK
Session receives packets only.
Definition rtp.h:146
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:3572
Network Interface structure.
Definition net_if.h:744
(Generalized) Precision Time Protocol Timestamp format.
Definition ptp_time.h:111
Generic sockaddr struct.
Definition net_ip.h:455
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:154
void * user_data
Opaque user data forwarded to callback.
Definition rtp.h:171
rtp_rx_cb_t callback
Callback invoked upon packet reception; required when role is RTP_ROLE_SINK or RTP_ROLE_BOTH.
Definition rtp.h:169
struct net_sockaddr_storage sock_addr
Session address and port (multicast group address or unicast peer).
Definition rtp.h:159
enum rtp_role role
Role of the session: sink, source, or both.
Definition rtp.h:161
uint8_t payload_type
RTP payload type field value used when transmitting.
Definition rtp.h:164
struct net_if * iface
Network interface used by the session.
Definition rtp.h:156
RTP session state.
Definition rtp.h:230
uint32_t timestamp
Current RTP timestamp, advanced with each transmitted packet.
Definition rtp.h:242
uint16_t local_port
Local UDP port used when transmitting; 0 to auto-select (see CONFIG_RTP_LOCAL_PORT_BASE).
Definition rtp.h:249
struct rtp_transport transport
Transport info.
Definition rtp.h:232
size_t csrc_len
Number of active entries in csrc.
Definition rtp.h:254
const char * name
Human-readable session name used in debug log messages.
Definition rtp.h:258
struct k_mutex lock
Mutex protecting concurrent access to session state.
Definition rtp.h:237
uint32_t csrc[CONFIG_RTP_MAX_CSRC_COUNT]
Contributing source (CSRC) identifier list.
Definition rtp.h:252
uint16_t sequence_number
Sequence number of the next packet to be transmitted.
Definition rtp.h:244
struct rtp_session_context rtp_context
Session configuration context.
Definition rtp.h:234
uint32_t ssrc
Synchronization source (SSRC) identifier for this session.
Definition rtp.h:240
Internal transport state embedded in rtp_session.
Definition rtp.h:201
enum rtp_transport_type type
Active transport backend for this session.
Definition rtp.h:203