annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * Create and destroy functions for twrtp_endp.
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <stdint.h>
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdbool.h>
24
84d427017d2f endp: implement RTP Tx
Mychaela Falconia <falcon@freecalypso.org>
parents: 19
diff changeset
7 #include <stdlib.h>
19
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <osmocom/core/talloc.h>
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <osmocom/core/osmo_io.h>
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <osmocom/core/utils.h>
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <themwi/rtp/endp.h>
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <themwi/rtp/twjit.h>
38
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
15 #include <themwi/rtp/rtp_basic_hdr.h>
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
16 #include <themwi/rtp/rtcp_defs.h>
19
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "endp_internal.h"
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
38
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
19 /* We need to know maximum expected sizes of RTP and RTCP Rx packets
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
20 * for osmo_io msgb allocation. For RTP, the largest packet size in
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
21 * 3GPP and IP-PSTN applications is 176 bytes: 12 bytes of RTP header
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
22 * plus 160 bytes of payload for 20 ms of uncompressed G.711 audio
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
23 * or CSData. Of course there may be other applications that use
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
24 * larger RTP packets, in which case we may have to add an API function
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
25 * that overrides our default msgb alloc size setting - but let's
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
26 * cross that bridge if and when we actually have such users.
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
27 *
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
28 * In case of RTCP, we fully process all received packets inside
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
29 * the present library, hence we can set osmo_io msgb alloc size
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
30 * based on what our RTCP Rx code can parse and make use of. Any
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
31 * additional RTCP Rx data, such as very long SDES strings, will
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
32 * simply be truncated at osmo_io level - but the subsequent parsing
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
33 * code will never get to those bits anyway.
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
34 */
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
35
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
36 #define MAX_RTP_RX_PACKET (sizeof(struct rtp_basic_hdr) + 160)
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
37 #define MAX_RTCP_RX_PACKET (sizeof(struct rtcp_sr_rr_hdr) + \
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
38 sizeof(struct rtcp_sr_block) + \
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
39 sizeof(struct rtcp_rr_block) * 31)
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
40
19
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 struct twrtp_endp *twrtp_endp_create(void *ctx,
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 struct twrtp_jibuf_config *config)
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 {
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 struct twrtp_endp *endp;
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 endp = talloc_zero(ctx, struct twrtp_endp);
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (!endp)
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 return NULL;
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 endp->iofd_rtp = osmo_iofd_setup(endp, -1, NULL,
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 OSMO_IO_FD_MODE_RECVFROM_SENDTO,
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 &_twrtp_endp_iops_rtp, endp);
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 if (!endp->iofd_rtp) {
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 talloc_free(endp);
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 return NULL;
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }
38
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
57 osmo_iofd_set_alloc_info(endp->iofd_rtp, MAX_RTP_RX_PACKET, 0);
19
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 endp->iofd_rtcp = osmo_iofd_setup(endp, -1, NULL,
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 OSMO_IO_FD_MODE_RECVFROM_SENDTO,
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 &_twrtp_endp_iops_rtcp, endp);
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 if (!endp->iofd_rtcp) {
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 osmo_iofd_free(endp->iofd_rtp);
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 talloc_free(endp);
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 return NULL;
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
38
781f491f20dd set sensible osmo_io msgb alloc sizes for RTP & RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents: 24
diff changeset
67 osmo_iofd_set_alloc_info(endp->iofd_rtcp, MAX_RTCP_RX_PACKET, 0);
19
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 endp->twjit = twrtp_jibuf_create(endp, config);
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 if (!endp->twjit) {
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 osmo_iofd_free(endp->iofd_rtp);
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 osmo_iofd_free(endp->iofd_rtcp);
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 talloc_free(endp);
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 return NULL;
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 }
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76
24
84d427017d2f endp: implement RTP Tx
Mychaela Falconia <falcon@freecalypso.org>
parents: 19
diff changeset
77 endp->tx.ssrc = random();
19
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 return endp;
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 }
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 void twrtp_endp_destroy(struct twrtp_endp *endp)
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 {
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 osmo_iofd_free(endp->iofd_rtp);
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 osmo_iofd_free(endp->iofd_rtcp);
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 twrtp_jibuf_destroy(endp->twjit);
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 talloc_free(endp);
b8cb5146e5b4 endp: beginning
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 }