FreeCalypso > hg > themwi-rtp-lib
annotate src/endp_create.c @ 43:8cdfef36d9db default tip
twrtp_endp_create: make config argument const
This argument is passed through to twrtp_jibuf_create(). We made it
const in the latter function, now do the same with the wrapper.
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Fri, 20 Dec 2024 23:01:06 +0000 |
| parents | 781f491f20dd |
| children |
| rev | line source |
|---|---|
| 19 | 1 /* |
| 2 * Create and destroy functions for twrtp_endp. | |
| 3 */ | |
| 4 | |
| 5 #include <stdint.h> | |
| 6 #include <stdbool.h> | |
|
24
84d427017d2f
endp: implement RTP Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
7 #include <stdlib.h> |
| 19 | 8 |
| 9 #include <osmocom/core/talloc.h> | |
| 10 #include <osmocom/core/osmo_io.h> | |
| 11 #include <osmocom/core/utils.h> | |
| 12 | |
| 13 #include <themwi/rtp/endp.h> | |
| 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 | 17 #include "endp_internal.h" |
| 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 | 41 struct twrtp_endp *twrtp_endp_create(void *ctx, |
|
43
8cdfef36d9db
twrtp_endp_create: make config argument const
Mychaela Falconia <falcon@freecalypso.org>
parents:
38
diff
changeset
|
42 const struct twrtp_jibuf_config *config) |
| 19 | 43 { |
| 44 struct twrtp_endp *endp; | |
| 45 | |
| 46 endp = talloc_zero(ctx, struct twrtp_endp); | |
| 47 if (!endp) | |
| 48 return NULL; | |
| 49 | |
| 50 endp->iofd_rtp = osmo_iofd_setup(endp, -1, NULL, | |
| 51 OSMO_IO_FD_MODE_RECVFROM_SENDTO, | |
| 52 &_twrtp_endp_iops_rtp, endp); | |
| 53 if (!endp->iofd_rtp) { | |
| 54 talloc_free(endp); | |
| 55 return NULL; | |
| 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 | 58 |
| 59 endp->iofd_rtcp = osmo_iofd_setup(endp, -1, NULL, | |
| 60 OSMO_IO_FD_MODE_RECVFROM_SENDTO, | |
| 61 &_twrtp_endp_iops_rtcp, endp); | |
| 62 if (!endp->iofd_rtcp) { | |
| 63 osmo_iofd_free(endp->iofd_rtp); | |
| 64 talloc_free(endp); | |
| 65 return NULL; | |
| 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 | 68 |
| 69 endp->twjit = twrtp_jibuf_create(endp, config); | |
| 70 if (!endp->twjit) { | |
| 71 osmo_iofd_free(endp->iofd_rtp); | |
| 72 osmo_iofd_free(endp->iofd_rtcp); | |
| 73 talloc_free(endp); | |
| 74 return NULL; | |
| 75 } | |
| 76 | |
|
24
84d427017d2f
endp: implement RTP Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
77 endp->tx.ssrc = random(); |
| 19 | 78 return endp; |
| 79 } | |
| 80 | |
| 81 void twrtp_endp_destroy(struct twrtp_endp *endp) | |
| 82 { | |
| 83 osmo_iofd_free(endp->iofd_rtp); | |
| 84 osmo_iofd_free(endp->iofd_rtcp); | |
| 85 twrtp_jibuf_destroy(endp->twjit); | |
| 86 talloc_free(endp); | |
| 87 } |
