# HG changeset patch # User Mychaela Falconia # Date 1720318441 0 # Node ID b8cb5146e5b4aebb5093ef95c9df59b38cded95f # Parent ec50018cc4eaead7a6be40a889f2bbf500bbb453 endp: beginning diff -r ec50018cc4ea -r b8cb5146e5b4 include/endp.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/endp.h Sun Jul 07 02:14:01 2024 +0000 @@ -0,0 +1,60 @@ +/* + * 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 +#include + +#include +#include + +#include + +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); diff -r ec50018cc4ea -r b8cb5146e5b4 src/Makefile --- a/src/Makefile Sun Jul 07 00:15:00 2024 +0000 +++ b/src/Makefile Sun Jul 07 02:14:01 2024 +0000 @@ -1,10 +1,10 @@ -OBJS= bind_fdpair.o twjit.o twjit_in.o twjit_out.o twjit_vty.o +OBJS= bind_fdpair.o endp_create.o twjit.o twjit_in.o twjit_out.o twjit_vty.o LIB= libtwrtp.a include ../config.defs CPPFLAGS=-I../build-inc ${OSMO_INCLUDE} -HDRS= ../include/twjit.h +HDRS= ../include/endp.h ../include/twjit.h endp_internal.h all: ${LIB} diff -r ec50018cc4ea -r b8cb5146e5b4 src/endp_create.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/endp_create.c Sun Jul 07 02:14:01 2024 +0000 @@ -0,0 +1,60 @@ +/* + * Create and destroy functions for twrtp_endp. + */ + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include "endp_internal.h" + +struct twrtp_endp *twrtp_endp_create(void *ctx, + struct twrtp_jibuf_config *config) +{ + struct twrtp_endp *endp; + + endp = talloc_zero(ctx, struct twrtp_endp); + if (!endp) + return NULL; + + endp->iofd_rtp = osmo_iofd_setup(endp, -1, NULL, + OSMO_IO_FD_MODE_RECVFROM_SENDTO, + &_twrtp_endp_iops_rtp, endp); + if (!endp->iofd_rtp) { + talloc_free(endp); + return NULL; + } + + endp->iofd_rtcp = osmo_iofd_setup(endp, -1, NULL, + OSMO_IO_FD_MODE_RECVFROM_SENDTO, + &_twrtp_endp_iops_rtcp, endp); + if (!endp->iofd_rtcp) { + osmo_iofd_free(endp->iofd_rtp); + talloc_free(endp); + return NULL; + } + + endp->twjit = twrtp_jibuf_create(endp, config); + if (!endp->twjit) { + osmo_iofd_free(endp->iofd_rtp); + osmo_iofd_free(endp->iofd_rtcp); + talloc_free(endp); + return NULL; + } + + return endp; +} + +void twrtp_endp_destroy(struct twrtp_endp *endp) +{ + osmo_iofd_free(endp->iofd_rtp); + osmo_iofd_free(endp->iofd_rtcp); + twrtp_jibuf_destroy(endp->twjit); + talloc_free(endp); +} diff -r ec50018cc4ea -r b8cb5146e5b4 src/endp_internal.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/endp_internal.h Sun Jul 07 02:14:01 2024 +0000 @@ -0,0 +1,10 @@ +/* + * Internal declarations for twrtp_endp library component. + */ + +#pragma once + +#include + +extern const struct osmo_io_ops _twrtp_endp_iops_rtp; +extern const struct osmo_io_ops _twrtp_endp_iops_rtcp;