view src/endp_create.c @ 37:8f1700a42ca5 default tip

set_remote: add functions for IPv6 and for sockaddr_{in,in6} A convenient way to pass in remote end address as struct sockaddr_in is needed for tw-border-mgw; IPv6 support will be needed in order to bring twrtp_endp into Osmocom mainline.
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 23 Nov 2024 19:08:28 +0000
parents 84d427017d2f
children
line wrap: on
line source

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

#include <stdint.h>
#include <stdbool.h>
#include <stdlib.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;
	}

	endp->tx.ssrc = random();
	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);
}