blob: ca32e3c5d505222888e7167b1cdeeca93bc8f3f0 [file] [log] [blame]
Neels Hofmeyr63881a32022-01-13 18:34:52 +01001/* Filter/overlay codec selections for a voice call, across MS, RAN and CN limitations */
2/*
Vadim Yanitskiy999a5932023-05-18 17:22:26 +07003 * (C) 2019-2022 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
Neels Hofmeyr63881a32022-01-13 18:34:52 +01004 * All Rights Reserved
5 *
6 * Author: Neels Hofmeyr
7 *
8 * SPDX-License-Identifier: GPL-2.0+
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20#pragma once
21
22#include <osmocom/gsm/gsm_utils.h>
23#include <osmocom/gsm/mncc.h>
24#include <osmocom/mgcp_client/mgcp_client.h>
25
26#include <osmocom/msc/sdp_msg.h>
27
28struct gsm0808_speech_codec_list;
29
30/* Combine various codec selections to obtain a resulting set of codecs allowed by all of them.
31 * Members reflect the different entities/stages that select codecs in a voice call.
32 * Call codec_filter_run() and obtain the resulting set of codecs in codec_filter.result. */
33struct codec_filter {
34 /* The fixed set of codecs available on the RAN type, per definition. */
35 struct sdp_audio_codecs ran;
36 /* The codecs advertised by the MS Bearer Capabilities */
37 struct sdp_audio_codecs ms;
38 /* If known, the set of codecs the current RAN cell allows / has available.
39 * This may not be available if the BSC does not issue this information early enough.
40 * Should be ignored if empty. */
41 struct sdp_audio_codecs bss;
42
43 /* SDP as last received from the remote call leg. */
44 struct sdp_msg remote;
45
46 /* After a channel was assigned, this reflects the chosen codec. */
47 struct sdp_audio_codec assignment;
48
49 /* Resulting choice of supported codecs, usually the intersection of the above,
50 * and the local RTP address to be sent to the remote call leg.
51 * The RTP address:port in result.rtp is not modified by codec_filter_run() -- set it once. */
52 struct sdp_msg result;
53};
54
Neels Hofmeyr63881a32022-01-13 18:34:52 +010055void codec_filter_set_ran(struct codec_filter *codec_filter, enum osmo_rat_type ran_type);
Neels Hofmeyr63881a32022-01-13 18:34:52 +010056void codec_filter_set_bss(struct codec_filter *codec_filter,
57 const struct gsm0808_speech_codec_list *codec_list_bss_supported);
58int codec_filter_set_remote(struct codec_filter *codec_filter, const char *remote_sdp);
59void codec_filter_set_local_rtp(struct codec_filter *codec_filter, const struct osmo_sockaddr_str *rtp);
60int codec_filter_run(struct codec_filter *codec_filter);
61
62int codec_filter_to_str_buf(char *buf, size_t buflen, const struct codec_filter *codec_filter);
63char *codec_filter_to_str_c(void *ctx, const struct codec_filter *codec_filter);
64const char *codec_filter_to_str(const struct codec_filter *codec_filter);