FreeCalypso > hg > themwi-rtp-lib
view src/endp_create.c @ 40:d73b6ec27ae6
twjit: allow starting fill level to be 1
In most use cases, the smallest useful setting for starting fill level
is 2. However, our job is to provide mechanism rather than policy,
and the theoretical minimum is 1 - so let's support the latter
configuration.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 20 Dec 2024 20:07:01 +0000 |
parents | 781f491f20dd |
children | 8cdfef36d9db |
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 <themwi/rtp/rtp_basic_hdr.h> #include <themwi/rtp/rtcp_defs.h> #include "endp_internal.h" /* We need to know maximum expected sizes of RTP and RTCP Rx packets * for osmo_io msgb allocation. For RTP, the largest packet size in * 3GPP and IP-PSTN applications is 176 bytes: 12 bytes of RTP header * plus 160 bytes of payload for 20 ms of uncompressed G.711 audio * or CSData. Of course there may be other applications that use * larger RTP packets, in which case we may have to add an API function * that overrides our default msgb alloc size setting - but let's * cross that bridge if and when we actually have such users. * * In case of RTCP, we fully process all received packets inside * the present library, hence we can set osmo_io msgb alloc size * based on what our RTCP Rx code can parse and make use of. Any * additional RTCP Rx data, such as very long SDES strings, will * simply be truncated at osmo_io level - but the subsequent parsing * code will never get to those bits anyway. */ #define MAX_RTP_RX_PACKET (sizeof(struct rtp_basic_hdr) + 160) #define MAX_RTCP_RX_PACKET (sizeof(struct rtcp_sr_rr_hdr) + \ sizeof(struct rtcp_sr_block) + \ sizeof(struct rtcp_rr_block) * 31) 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; } osmo_iofd_set_alloc_info(endp->iofd_rtp, MAX_RTP_RX_PACKET, 0); 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; } osmo_iofd_set_alloc_info(endp->iofd_rtcp, MAX_RTCP_RX_PACKET, 0); 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); }