blob: 5bc01440f90a2a4f163739a6e39cea5679b90d2f [file] [log] [blame]
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01001#pragma once
2
3#include <stdint.h>
4#include <stdbool.h>
5
6#include <osmocom/core/sockaddr_str.h>
7#include <osmocom/mgcp_client/mgcp_client.h>
Neels Hofmeyr62bfa372022-10-31 18:51:07 +01008#include <osmocom/msc/sdp_msg.h>
Neels Hofmeyrc4628a32018-12-07 14:47:34 +01009
10struct gsm_trans;
11
12struct osmo_fsm_inst;
13struct call_leg;
14struct osmo_mgcpc_ep;
15struct osmo_mgcpc_ep_ci;
16
17enum rtp_direction {
18 RTP_TO_RAN,
19 RTP_TO_CN,
20};
21
22extern const struct value_string rtp_direction_names[];
23static inline const char *rtp_direction_name(enum rtp_direction val)
24{ return get_value_string(rtp_direction_names, val); }
25
26/* A single bidirectional RTP hop between remote and MGW's local RTP port. */
27struct rtp_stream {
28 struct osmo_fsm_inst *fi;
Andreas Eversbergbcb4d6b2023-07-05 15:03:19 +020029 uint32_t event_avail;
30 uint32_t event_estab;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010031 enum rtp_direction dir;
32
33 uint32_t call_id;
34
35 /* Backpointer for callers (optional) */
36 struct gsm_trans *for_trans;
37
38 struct osmo_sockaddr_str local;
39 struct osmo_sockaddr_str remote;
40 bool remote_sent_to_mgw;
41
Neels Hofmeyr62bfa372022-10-31 18:51:07 +010042 bool codecs_known;
43 struct sdp_audio_codecs codecs;
44 bool codecs_sent_to_mgw;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010045
46 struct osmo_mgcpc_ep_ci *ci;
47
48 enum mgcp_connection_mode crcx_conn_mode;
Andreas Eversberg58fe2e02023-06-21 12:37:18 +020049 bool mode_sent_to_mgw;
Pau Espin Pedrola3cdab42019-05-09 17:54:08 +020050
51 /* configured to use Osmux */
52 bool use_osmux;
53 /* Allocated by our MGW, negative means invalid, not yet known */
54 int local_osmux_cid;
55 /* Allocated by BSC MGW, negative means invalid, not yet known */
56 int remote_osmux_cid;
57 /* Whether remote_osmux_cid has been communicated to MGW */
58 bool remote_osmux_cid_sent_to_mgw;
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010059};
60
61#define RTP_STREAM_FMT "local=" RTP_IP_PORT_FMT ",remote=" RTP_IP_PORT_FMT
62#define RTP_STREAM_ARGS(RS) RTP_IP_PORT_ARGS(&(RS)->local), RTP_IP_PORT_ARGS(&(RS)->remote),
63
Andreas Eversbergbcb4d6b2023-07-05 15:03:19 +020064struct rtp_stream *rtp_stream_alloc(struct osmo_fsm_inst *parent_fi, uint32_t event_gone, uint32_t event_avail,
65 uint32_t event_estab, enum rtp_direction dir, uint32_t call_id,
66 struct gsm_trans *for_trans);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010067
68int rtp_stream_ensure_ci(struct rtp_stream *rtps, struct osmo_mgcpc_ep *at_endpoint);
69int rtp_stream_do_mdcx(struct rtp_stream *rtps);
70
Neels Hofmeyr62bfa372022-10-31 18:51:07 +010071bool rtp_stream_set_codecs_from_mgcp_codec(struct rtp_stream *rtps, enum mgcp_codecs codec);
72void rtp_stream_set_one_codec(struct rtp_stream *rtps, const struct sdp_audio_codec *codec);
73void rtp_stream_set_codecs(struct rtp_stream *rtps, const struct sdp_audio_codecs *codecs);
Andreas Eversberg58fe2e02023-06-21 12:37:18 +020074void rtp_stream_set_mode(struct rtp_stream *rtps, enum mgcp_connection_mode mode);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010075void rtp_stream_set_remote_addr(struct rtp_stream *rtps, const struct osmo_sockaddr_str *r);
Neels Hofmeyr8dd16462022-01-13 20:06:53 +010076void rtp_stream_set_remote_addr_and_codecs(struct rtp_stream *rtps, const struct sdp_msg *sdp);
Pau Espin Pedrola3cdab42019-05-09 17:54:08 +020077void rtp_stream_set_remote_osmux_cid(struct rtp_stream *rtps, uint8_t osmux_cid);
Neels Hofmeyrc4628a32018-12-07 14:47:34 +010078int rtp_stream_commit(struct rtp_stream *rtps);
79
80void rtp_stream_release(struct rtp_stream *rtps);
81
82bool rtp_stream_is_established(struct rtp_stream *rtps);