libosmo-netif 1.5.1.31-6b3f
Osmocom network interface library
twrtp.h
1/*
2 * Themyscira Wireless RTP endpoint implementation:
3 * public API definition for Osmocom-integrated version.
4 *
5 * This code was contributed to Osmocom Cellular Network Infrastructure
6 * project by Mother Mychaela N. Falconia of Themyscira Wireless.
7 * Mother Mychaela's contributions are NOT subject to copyright:
8 * no rights reserved, all rights relinquished.
9 */
10
11#pragma once
12
13#include <stdint.h>
14#include <stdbool.h>
15#include <osmocom/core/socket.h>
16
17/*
18 * Each instance of twrtp in the present version exists as struct osmo_twrtp.
19 * This structure is opaque, and always constitutes a talloc context.
20 */
21struct osmo_twrtp;
22
23/*
24 * Stats collected during the lifetime of a twrtp instance.
25 */
27 uint32_t rx_rtp_pkt;
28 uint32_t rx_rtp_badsrc;
29 uint32_t rx_rtcp_pkt;
30 uint32_t rx_rtcp_badsrc;
31 uint32_t rx_rtcp_invalid;
32 uint32_t rx_rtcp_wrong_ssrc;
33 uint32_t tx_rtp_pkt;
34 uint32_t tx_rtp_bytes;
35 uint32_t tx_rtcp_pkt;
36};
37
38/* declare structs that are used in our API */
39
40struct msgb;
42struct osmo_twjit_stats;
44
45/* public API functions: create & destroy, local and remote addresses */
46
47struct osmo_twrtp *
48osmo_twrtp_create(void *ctx, uint16_t clock_khz, uint16_t quantum_ms,
49 bool random_ts_seq,
50 const struct osmo_twjit_config *twjit_config);
51void osmo_twrtp_destroy(struct osmo_twrtp *endp);
52
53int osmo_twrtp_supply_fds(struct osmo_twrtp *endp, int rtp_fd, int rtcp_fd);
54
55int osmo_twrtp_bind_local_ipv4(struct osmo_twrtp *endp,
56 const struct in_addr *ip, uint16_t port);
57int osmo_twrtp_bind_local_ipv6(struct osmo_twrtp *endp,
58 const struct in6_addr *ip6, uint16_t port);
59int osmo_twrtp_bind_local_sin(struct osmo_twrtp *endp,
60 const struct sockaddr_in *sin);
61int osmo_twrtp_bind_local_sin6(struct osmo_twrtp *endp,
62 const struct sockaddr_in6 *sin6);
63
64void osmo_twrtp_set_remote_ipv4(struct osmo_twrtp *endp,
65 const struct in_addr *ip, uint16_t port);
66void osmo_twrtp_set_remote_ipv6(struct osmo_twrtp *endp,
67 const struct in6_addr *ip6, uint16_t port);
68void osmo_twrtp_set_remote_sin(struct osmo_twrtp *endp,
69 const struct sockaddr_in *sin);
70void osmo_twrtp_set_remote_sin6(struct osmo_twrtp *endp,
71 const struct sockaddr_in6 *sin6);
72
73/* receiving incoming RTP via twjit */
74
75void osmo_twrtp_twjit_rx_enable(struct osmo_twrtp *endp);
76void osmo_twrtp_twjit_rx_disable(struct osmo_twrtp *endp);
77
78/* output function, to be called by TDM/GSM/etc fixed-timing side */
79struct msgb *osmo_twrtp_twjit_rx_poll(struct osmo_twrtp *endp);
80
81void osmo_twrtp_new_twjit_config(struct osmo_twrtp *endp,
82 const struct osmo_twjit_config *config);
83
84/* receiving incoming RTP without twjit */
85
86/* callback function takes ownership of msgb! */
87typedef void (*osmo_twrtp_raw_rx_cb)(struct osmo_twrtp *endp, void *user_data,
88 struct msgb *msg);
89
90void osmo_twrtp_set_raw_rx_cb(struct osmo_twrtp *endp, osmo_twrtp_raw_rx_cb cb,
91 void *user_data);
92
93/* RTP Tx direction */
94
95int osmo_twrtp_tx_quantum(struct osmo_twrtp *endp, const uint8_t *payload,
96 unsigned payload_len, uint8_t payload_type,
97 bool marker, bool auto_marker, bool send_rtcp);
98void osmo_twrtp_tx_skip(struct osmo_twrtp *endp);
99void osmo_twrtp_tx_restart(struct osmo_twrtp *endp);
100
101int osmo_twrtp_tx_forward(struct osmo_twrtp *endp, struct msgb *msg);
102
103/* support for emitting RTCP SR & RR */
104
105int osmo_twrtp_set_sdes(struct osmo_twrtp *endp, const char *cname,
106 const char *name, const char *email, const char *phone,
107 const char *loc, const char *tool, const char *note);
108void osmo_twrtp_set_auto_rtcp_interval(struct osmo_twrtp *endp,
109 uint16_t interval);
110
111int osmo_twrtp_send_rtcp_rr(struct osmo_twrtp *endp);
112
113/* stats retrieval: valid with or without twjit */
114
115const struct osmo_twrtp_stats *osmo_twrtp_get_stats(struct osmo_twrtp *endp);
116
117/* have we received at least one RTCP RR matching our RTP Tx output? */
118bool osmo_twrtp_got_rtcp_rr(struct osmo_twrtp *endp);
119
120/* retrieving RTCP RR info: valid only if above function returned true */
121uint32_t osmo_twrtp_rr_lost_word(struct osmo_twrtp *endp);
122int32_t osmo_twrtp_rr_lost_cumulative(struct osmo_twrtp *endp);
123uint32_t osmo_twrtp_rr_jitter_last(struct osmo_twrtp *endp);
124uint32_t osmo_twrtp_rr_jitter_max(struct osmo_twrtp *endp);
125
126/* retrieving additional info from twjit layer */
127
128const struct osmo_twjit_stats *
129osmo_twrtp_get_twjit_stats(struct osmo_twrtp *endp);
130
131const struct osmo_twjit_rr_info *
132osmo_twrtp_get_twjit_rr_info(struct osmo_twrtp *endp);
133
134bool osmo_twrtp_twjit_got_input(struct osmo_twrtp *endp);
135
136/* socket-related miscellany */
137
138int osmo_twrtp_set_dscp(struct osmo_twrtp *endp, uint8_t dscp);
139int osmo_twrtp_set_socket_prio(struct osmo_twrtp *endp, int prio);
Definition: twjit.h:26
Definition: twjit.h:74
Definition: twjit.h:42
Definition: twrtp.h:26
Definition: twrtp_private.h:50