view src/endp_create.c @ 22:587437b62ed5

implement twrtp_endp_set_remote_ipv4()
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Jul 2024 04:33:55 +0000
parents b8cb5146e5b4
children 84d427017d2f
line wrap: on
line source

/*
 * Create and destroy functions for twrtp_endp.
 */

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

#include <osmocom/core/talloc.h>
#include <osmocom/core/osmo_io.h>
#include <osmocom/core/utils.h>

#include <themwi/rtp/endp.h>
#include <themwi/rtp/twjit.h>
#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);
}