view include/endp.h @ 27:a0b89c028053

RTP Tx: implement skip operation
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Jul 2024 18:39:24 +0000
parents f71efdd08c33
children 3e01a71b7c7c
line wrap: on
line source

/*
 * twrtp_endp is the big abstraction provided by libtwrtp: a complete
 * RTP endpoint with RTP & RTCP sockets, sending and receiving both types
 * of packets, and incorporating twjit.
 */

#pragma once

#include <stdint.h>
#include <stdbool.h>

#include <osmocom/core/osmo_io.h>
#include <osmocom/core/socket.h>

#include <themwi/rtp/twjit.h>

struct twrtp_endp_tx {
	uint32_t ssrc;
	uint32_t ts;
	uint16_t seq;
	bool started;
	bool restart;
};

struct twrtp_endp_stats {
	uint32_t rx_rtp_pkt;
	uint32_t rx_rtp_badsrc;
	uint32_t rx_rtcp_pkt;
	uint32_t rx_rtcp_badsrc;
	uint32_t tx_rtp_pkt;
	uint32_t tx_rtp_bytes;
	uint32_t tx_rtcp_pkt;
};

struct twrtp_endp {
	/* the root of the matter: the two sockets */
	int rtp_fd;
	int rtcp_fd;
	struct osmo_io_fd *iofd_rtp;
	struct osmo_io_fd *iofd_rtcp;
	struct osmo_sockaddr rtp_remote;
	struct osmo_sockaddr rtcp_remote;
	/* Rx and Tx state */
	struct twrtp_jibuf_inst *twjit;
	/* RTCP Rx structure to be inserted here */
	struct twrtp_endp_tx tx;
	/* always have to have stats */
	struct twrtp_endp_stats stats;
	/* bool flags at the end for structure packing optimization */
	bool register_done;
	bool remote_set;
	bool rx_enable;
};

/* public API functions */

struct twrtp_endp *twrtp_endp_create(void *ctx,
				     struct twrtp_jibuf_config *config);
void twrtp_endp_destroy(struct twrtp_endp *endp);

int twrtp_endp_register_fds(struct twrtp_endp *endp);
int twrtp_endp_bind_ip_port(struct twrtp_endp *endp, const char *ip,
			    uint16_t port);

void twrtp_endp_set_remote_ipv4(struct twrtp_endp *endp,
				const struct in_addr *ip, uint16_t port);

int twrtp_endp_tx_quantum(struct twrtp_endp *endp, const uint8_t *payload,
			  unsigned payload_len, uint8_t payload_type,
			  bool marker, bool auto_marker, bool send_rtcp);
void twrtp_endp_tx_skip(struct twrtp_endp *endp);