FreeCalypso > hg > themwi-rtp-lib
view src/endp_create.c @ 42:334d883b96ba
twrtp_jibuf_create: make config argument const
While this config structure is not a constant in the mathematical
sense of the term (it is expected that vty config changes may happen
while twjit instance is alive), twjit functions never write to it,
only read, hence it is 'const' in the not-quite-mathematical C-standard
sense.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 20 Dec 2024 22:47:20 +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); }