blob: 3b502a9133f7f8b10133410671390f8a3d56d2e3 [file] [log] [blame]
Neels Hofmeyrb2ce7482022-01-13 18:17:56 +01001/* Routines for translation between codec representations: SDP, CC/BSSMAP variants, MGCP, MNCC */
2#pragma once
3
4#include <osmocom/gsm/protocol/gsm_04_08.h>
5#include <osmocom/gsm/protocol/gsm_08_08.h>
6#include <osmocom/mgcp_client/mgcp_client.h>
7#include <osmocom/msc/sdp_msg.h>
8#include <osmocom/gsm/mncc.h>
9
10#define NO_MGCP_CODEC 0xffffffff
11
12extern const struct gsm_mncc_bearer_cap bearer_cap_empty;
13
14enum codec_frhr {
15 CODEC_FRHR_NONE = 0,
16 CODEC_FRHR_FR,
17 CODEC_FRHR_HR,
18};
19
20struct codec_mapping {
21 /* The sdp.payload_type number in a mapping is not necessarily imperative, but may just reflect the usual
22 * payload type number for a given codec. */
23 struct sdp_audio_codec sdp;
24 /* The id that mgcp_client.h uses for this codec. Must be set in each mapping, because 0 means PCMU. */
25 enum mgcp_codecs mgcp;
26 /* Nr of used entries in speech_ver[] below. */
27 unsigned int speech_ver_count;
28 /* Entries to add to Speech Version lists when this codec is present, if any. */
29 enum gsm48_bcap_speech_ver speech_ver[8];
30 /* If applicable, one of GSM_TCHF_FRAME, GSM_TCHF_FRAME_EFR, GSM_TCHH_FRAME, GSM_TCH_FRAME_AMR; or zero. */
31 uint32_t mncc_payload_msg_type;
32 /* Set to true if gsm0808_speech_codec below reflects a meaningful value. */
33 bool has_gsm0808_speech_codec;
34 struct gsm0808_speech_codec gsm0808_speech_codec;
35 /* If applicable, entries to add to Permitted Speech lists when this codec is present; or zero. */
36 enum gsm0808_permitted_speech perm_speech;
37 /* If applicable, indicator whether this codec can work on a GERAN half-rate lchan, or whether full-rate is
38 * required. Leave zero when this codec does not apply to GERAN. */
39 enum codec_frhr frhr;
40};
41
42const struct codec_mapping *codec_mapping_by_speech_ver(enum gsm48_bcap_speech_ver speech_ver);
43const struct codec_mapping *codec_mapping_by_gsm0808_speech_codec_type(enum gsm0808_speech_codec_type sct);
44const struct codec_mapping *codec_mapping_by_gsm0808_speech_codec(const struct gsm0808_speech_codec *sc);
45const struct codec_mapping *codec_mapping_by_perm_speech(enum gsm0808_permitted_speech perm_speech);
46const struct codec_mapping *codec_mapping_by_subtype_name(const char *subtype_name);
47const struct codec_mapping *codec_mapping_by_mgcp_codec(enum mgcp_codecs mgcp);
48
49int bearer_cap_add_speech_ver(struct gsm_mncc_bearer_cap *bearer_cap, enum gsm48_bcap_speech_ver speech_ver);
50int sdp_audio_codec_add_to_bearer_cap(struct gsm_mncc_bearer_cap *bearer_cap, const struct sdp_audio_codec *codec);
51int sdp_audio_codecs_to_bearer_cap(struct gsm_mncc_bearer_cap *bearer_cap, const struct sdp_audio_codecs *ac);
52int bearer_cap_set_radio(struct gsm_mncc_bearer_cap *bearer_cap);
53
54struct sdp_audio_codec *sdp_audio_codecs_add_speech_ver(struct sdp_audio_codecs *ac,
55 enum gsm48_bcap_speech_ver speech_ver);
56struct sdp_audio_codec *sdp_audio_codecs_add_mgcp_codec(struct sdp_audio_codecs *ac, enum mgcp_codecs mgcp_codec);
57void sdp_audio_codecs_from_bearer_cap(struct sdp_audio_codecs *ac, const struct gsm_mncc_bearer_cap *bc);
58
Neels Hofmeyrcefe5942023-11-17 04:11:19 +010059int sdp_audio_codec_to_speech_codec_list(struct gsm0808_speech_codec_list *scl, const struct sdp_audio_codec *codec);
Neels Hofmeyrb2ce7482022-01-13 18:17:56 +010060void sdp_audio_codecs_to_speech_codec_list(struct gsm0808_speech_codec_list *cl, const struct sdp_audio_codecs *ac);
61void sdp_audio_codecs_from_speech_codec_list(struct sdp_audio_codecs *ac, const struct gsm0808_speech_codec_list *cl);
62
63int sdp_audio_codecs_to_gsm0808_channel_type(struct gsm0808_channel_type *ct, const struct sdp_audio_codecs *ac);
64
65enum mgcp_codecs sdp_audio_codec_to_mgcp_codec(const struct sdp_audio_codec *codec);