FreeCalypso > hg > themwi-rtp-lib
diff src/endp_create.c @ 19:b8cb5146e5b4
endp: beginning
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 07 Jul 2024 02:14:01 +0000 |
parents | |
children | 84d427017d2f |
line wrap: on
line diff
--- /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 <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); +}