FreeCalypso > hg > themwi-rtp-lib
annotate include/endp.h @ 37:8f1700a42ca5 default tip
set_remote: add functions for IPv6 and for sockaddr_{in,in6}
A convenient way to pass in remote end address as struct sockaddr_in
is needed for tw-border-mgw; IPv6 support will be needed in order to
bring twrtp_endp into Osmocom mainline.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 23 Nov 2024 19:08:28 +0000 |
parents | c0ce22777694 |
children |
rev | line source |
---|---|
19 | 1 /* |
2 * twrtp_endp is the big abstraction provided by libtwrtp: a complete | |
3 * RTP endpoint with RTP & RTCP sockets, sending and receiving both types | |
4 * of packets, and incorporating twjit. | |
5 */ | |
6 | |
7 #pragma once | |
8 | |
9 #include <stdint.h> | |
10 #include <stdbool.h> | |
11 | |
12 #include <osmocom/core/osmo_io.h> | |
13 #include <osmocom/core/socket.h> | |
29
3e01a71b7c7c
implement RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
14 #include <osmocom/core/timer.h> |
19 | 15 |
16 #include <themwi/rtp/twjit.h> | |
17 | |
18 struct twrtp_endp_tx { | |
19 uint32_t ssrc; | |
20 uint32_t ts; | |
21 uint16_t seq; | |
22 bool started; | |
23 bool restart; | |
24 }; | |
25 | |
29
3e01a71b7c7c
implement RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
26 struct twrtp_endp_rtcp_rx { |
3e01a71b7c7c
implement RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
27 uint32_t sr_ssrc; |
3e01a71b7c7c
implement RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
28 uint16_t sr_ntp_sec; |
3e01a71b7c7c
implement RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
29 uint16_t sr_ntp_fract; |
3e01a71b7c7c
implement RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
30 struct timespec sr_rx_time; |
3e01a71b7c7c
implement RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
31 uint32_t rr_lost_word; |
3e01a71b7c7c
implement RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
32 uint32_t rr_jitter; |
3e01a71b7c7c
implement RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
33 bool got_sr; |
3e01a71b7c7c
implement RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
34 bool got_rr; |
3e01a71b7c7c
implement RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
35 }; |
3e01a71b7c7c
implement RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
36 |
32
aa97e77e7de6
implement RTCP Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
37 struct twrtp_endp_rtcp_tx { |
aa97e77e7de6
implement RTCP Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
38 uint32_t last_received; |
aa97e77e7de6
implement RTCP Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
39 uint32_t last_expected; |
aa97e77e7de6
implement RTCP Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
40 }; |
aa97e77e7de6
implement RTCP Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
41 |
19 | 42 struct twrtp_endp_stats { |
43 uint32_t rx_rtp_pkt; | |
44 uint32_t rx_rtp_badsrc; | |
45 uint32_t rx_rtcp_pkt; | |
46 uint32_t rx_rtcp_badsrc; | |
29
3e01a71b7c7c
implement RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
47 uint32_t rx_rtcp_invalid; |
3e01a71b7c7c
implement RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
48 uint32_t rx_rtcp_wrong_ssrc; |
19 | 49 uint32_t tx_rtp_pkt; |
50 uint32_t tx_rtp_bytes; | |
51 uint32_t tx_rtcp_pkt; | |
52 }; | |
53 | |
54 struct twrtp_endp { | |
55 /* the root of the matter: the two sockets */ | |
56 int rtp_fd; | |
57 int rtcp_fd; | |
58 struct osmo_io_fd *iofd_rtp; | |
59 struct osmo_io_fd *iofd_rtcp; | |
60 struct osmo_sockaddr rtp_remote; | |
61 struct osmo_sockaddr rtcp_remote; | |
62 /* Rx and Tx state */ | |
63 struct twrtp_jibuf_inst *twjit; | |
32
aa97e77e7de6
implement RTCP Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
64 struct twrtp_endp_tx tx; |
29
3e01a71b7c7c
implement RTCP Rx
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
65 struct twrtp_endp_rtcp_rx rtcp_rx; |
32
aa97e77e7de6
implement RTCP Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
30
diff
changeset
|
66 struct twrtp_endp_rtcp_tx rtcp_tx; |
30
9fd693f234f8
definitions for RTCP SDES
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
67 uint8_t *sdes_buf; |
9fd693f234f8
definitions for RTCP SDES
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
68 uint16_t sdes_len; |
9fd693f234f8
definitions for RTCP SDES
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
69 uint16_t auto_rtcp_interval; |
33
e70e7b266f89
hook in RTCP output
Mychaela Falconia <falcon@freecalypso.org>
parents:
32
diff
changeset
|
70 uint16_t auto_rtcp_count; |
19 | 71 /* always have to have stats */ |
72 struct twrtp_endp_stats stats; | |
73 /* bool flags at the end for structure packing optimization */ | |
74 bool register_done; | |
75 bool remote_set; | |
76 bool rx_enable; | |
77 }; | |
78 | |
79 /* public API functions */ | |
80 | |
81 struct twrtp_endp *twrtp_endp_create(void *ctx, | |
82 struct twrtp_jibuf_config *config); | |
20
695fdb670d30
implement twrtp_endp_register_fds()
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
83 void twrtp_endp_destroy(struct twrtp_endp *endp); |
19 | 84 |
20
695fdb670d30
implement twrtp_endp_register_fds()
Mychaela Falconia <falcon@freecalypso.org>
parents:
19
diff
changeset
|
85 int twrtp_endp_register_fds(struct twrtp_endp *endp); |
21
2032201bd034
implement twrtp_endp_bind_ip_port()
Mychaela Falconia <falcon@freecalypso.org>
parents:
20
diff
changeset
|
86 int twrtp_endp_bind_ip_port(struct twrtp_endp *endp, const char *ip, |
2032201bd034
implement twrtp_endp_bind_ip_port()
Mychaela Falconia <falcon@freecalypso.org>
parents:
20
diff
changeset
|
87 uint16_t port); |
22
587437b62ed5
implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
88 |
587437b62ed5
implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
89 void twrtp_endp_set_remote_ipv4(struct twrtp_endp *endp, |
587437b62ed5
implement twrtp_endp_set_remote_ipv4()
Mychaela Falconia <falcon@freecalypso.org>
parents:
21
diff
changeset
|
90 const struct in_addr *ip, uint16_t port); |
37
8f1700a42ca5
set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents:
35
diff
changeset
|
91 void twrtp_endp_set_remote_ipv6(struct twrtp_endp *endp, |
8f1700a42ca5
set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents:
35
diff
changeset
|
92 const struct in6_addr *ip6, uint16_t port); |
8f1700a42ca5
set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents:
35
diff
changeset
|
93 void twrtp_endp_set_remote_sin(struct twrtp_endp *endp, |
8f1700a42ca5
set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents:
35
diff
changeset
|
94 const struct sockaddr_in *sin); |
8f1700a42ca5
set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents:
35
diff
changeset
|
95 void twrtp_endp_set_remote_sin6(struct twrtp_endp *endp, |
8f1700a42ca5
set_remote: add functions for IPv6 and for sockaddr_{in,in6}
Mychaela Falconia <falcon@freecalypso.org>
parents:
35
diff
changeset
|
96 const struct sockaddr_in6 *sin6); |
24
84d427017d2f
endp: implement RTP Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
97 |
84d427017d2f
endp: implement RTP Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
98 int twrtp_endp_tx_quantum(struct twrtp_endp *endp, const uint8_t *payload, |
84d427017d2f
endp: implement RTP Tx
Mychaela Falconia <falcon@freecalypso.org>
parents:
22
diff
changeset
|
99 unsigned payload_len, uint8_t payload_type, |
26
f71efdd08c33
RTP Tx: add auto_marker mode of operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
24
diff
changeset
|
100 bool marker, bool auto_marker, bool send_rtcp); |
27
a0b89c028053
RTP Tx: implement skip operation
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
101 void twrtp_endp_tx_skip(struct twrtp_endp *endp); |
30
9fd693f234f8
definitions for RTCP SDES
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
102 |
9fd693f234f8
definitions for RTCP SDES
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
103 int twrtp_endp_set_sdes(struct twrtp_endp *endp, const char *cname, |
9fd693f234f8
definitions for RTCP SDES
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
104 const char *name, const char *email, const char *phone, |
9fd693f234f8
definitions for RTCP SDES
Mychaela Falconia <falcon@freecalypso.org>
parents:
29
diff
changeset
|
105 const char *loc, const char *tool, const char *note); |
34
fc77c3482084
add function for sending RTCP RR
Mychaela Falconia <falcon@freecalypso.org>
parents:
33
diff
changeset
|
106 int twrtp_endp_send_rtcp_rr(struct twrtp_endp *endp); |
35
c0ce22777694
add helper functions for DSCP and socket priority
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
107 |
c0ce22777694
add helper functions for DSCP and socket priority
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
108 int twrtp_endp_set_dscp(struct twrtp_endp *endp, uint8_t dscp); |
c0ce22777694
add helper functions for DSCP and socket priority
Mychaela Falconia <falcon@freecalypso.org>
parents:
34
diff
changeset
|
109 int twrtp_endp_set_socket_prio(struct twrtp_endp *endp, int prio); |