blob: e3879f6affbd2953180fc353d77c68a83c3d6cd2 [file] [log] [blame]
Neels Hofmeyreef45782019-10-21 03:24:04 +02001/* Minimalistic SDP parse/compose API, focused on GSM audio codecs */
2#pragma once
3
4#include <osmocom/core/utils.h>
5#include <osmocom/core/sockaddr_str.h>
6
Oliver Smith10632132023-05-12 12:14:22 +02007#include <osmocom/msc/csd_bs.h>
8
Neels Hofmeyreef45782019-10-21 03:24:04 +02009extern const struct value_string sdp_msg_payload_type_names[];
10static inline const char *sdp_msg_payload_type_name(unsigned int payload_type)
11{ return get_value_string(sdp_msg_payload_type_names, payload_type); }
12int sdp_subtype_name_to_payload_type(const char *subtype_name);
13
Neels Hofmeyr01431082022-07-19 12:16:02 +020014enum sdp_mode_e {
15 SDP_MODE_UNSET = 0,
16 SDP_MODE_SENDONLY = 1,
17 SDP_MODE_RECVONLY = 2,
18 SDP_MODE_SENDRECV = 3,
19 SDP_MODE_INACTIVE = 4,
20};
21
Neels Hofmeyreef45782019-10-21 03:24:04 +020022struct sdp_audio_codec {
Neels Hofmeyr40d34972022-07-19 12:15:27 +020023 /* Payload type number, like 3 for GSM-FR. */
Neels Hofmeyreef45782019-10-21 03:24:04 +020024 unsigned int payload_type;
25 /* Like "GSM", "AMR", "EFR", ... */
26 char subtype_name[16];
27 unsigned int rate;
Neels Hofmeyr82fad5d2023-12-08 05:53:23 +010028 char fmtp[256];
Neels Hofmeyreef45782019-10-21 03:24:04 +020029};
30
31struct sdp_audio_codecs {
32 unsigned int count;
33 struct sdp_audio_codec codec[16];
34};
35
36struct sdp_msg {
37 struct osmo_sockaddr_str rtp;
38 unsigned int ptime;
Neels Hofmeyr01431082022-07-19 12:16:02 +020039 enum sdp_mode_e mode;
Neels Hofmeyreef45782019-10-21 03:24:04 +020040 struct sdp_audio_codecs audio_codecs;
Oliver Smith10632132023-05-12 12:14:22 +020041 struct csd_bs_list bearer_services;
Neels Hofmeyreef45782019-10-21 03:24:04 +020042};
43
Neels Hofmeyrc8bf8952024-01-29 02:25:55 +010044#define sdp_audio_codecs_foreach(/* struct sdp_audio_codec* */ CODEC, \
45 /* struct sdp_audio_codecs* */ AC) \
Neels Hofmeyreef45782019-10-21 03:24:04 +020046 for (CODEC = (AC)->codec; \
47 (CODEC - (AC)->codec) < OSMO_MIN((AC)->count, ARRAY_SIZE((AC)->codec)); \
48 CODEC++)
49
50const char *sdp_msg_line_end(const char *src);
51
Neels Hofmeyr2d116822022-08-06 17:39:04 +020052bool sdp_audio_codec_is_set(const struct sdp_audio_codec *a);
Neels Hofmeyrc9e0ca32022-01-13 18:28:44 +010053int sdp_audio_codec_cmp(const struct sdp_audio_codec *a, const struct sdp_audio_codec *b,
54 bool cmp_fmtp, bool cmp_payload_type);
55int sdp_audio_codecs_cmp(const struct sdp_audio_codecs *a, const struct sdp_audio_codecs *b,
56 bool cmp_fmtp, bool cmp_payload_type);
Neels Hofmeyreef45782019-10-21 03:24:04 +020057
Neels Hofmeyrd20dd222022-01-14 00:38:42 +010058struct sdp_audio_codec *sdp_audio_codecs_add(struct sdp_audio_codecs *ac, unsigned int payload_type,
59 const char *subtype_name, unsigned int rate, const char *fmtp);
60struct sdp_audio_codec *sdp_audio_codecs_add_copy(struct sdp_audio_codecs *ac,
61 const struct sdp_audio_codec *codec);
62int sdp_audio_codecs_remove(struct sdp_audio_codecs *ac, const struct sdp_audio_codec *codec);
63struct sdp_audio_codec *sdp_audio_codecs_by_payload_type(struct sdp_audio_codecs *ac,
64 unsigned int payload_type, bool create);
65struct sdp_audio_codec *sdp_audio_codecs_by_descr(struct sdp_audio_codecs *ac,
66 const struct sdp_audio_codec *codec);
Neels Hofmeyreef45782019-10-21 03:24:04 +020067
68void sdp_audio_codecs_intersection(struct sdp_audio_codecs *ac_dest, const struct sdp_audio_codecs *ac_other,
69 bool translate_payload_type_numbers);
70void sdp_audio_codecs_select(struct sdp_audio_codecs *ac, struct sdp_audio_codec *codec);
71
Neels Hofmeyr9a515e52022-01-13 20:40:12 +010072int sdp_msg_to_sdp_str_buf(char *dst, size_t dst_size, const struct sdp_msg *sdp);
73int sdp_msg_from_sdp_str(struct sdp_msg *sdp, const char *src);
Neels Hofmeyreef45782019-10-21 03:24:04 +020074
Neels Hofmeyr9a515e52022-01-13 20:40:12 +010075int sdp_audio_codec_to_str_buf(char *buf, size_t buflen, const struct sdp_audio_codec *codec);
76char *sdp_audio_codec_to_str_c(void *ctx, const struct sdp_audio_codec *codec);
77const char *sdp_audio_codec_to_str(const struct sdp_audio_codec *codec);
Neels Hofmeyreef45782019-10-21 03:24:04 +020078
Neels Hofmeyr9a515e52022-01-13 20:40:12 +010079int sdp_audio_codecs_to_str_buf(char *buf, size_t buflen, const struct sdp_audio_codecs *ac);
80char *sdp_audio_codecs_to_str_c(void *ctx, const struct sdp_audio_codecs *ac);
81const char *sdp_audio_codecs_to_str(const struct sdp_audio_codecs *ac);
Neels Hofmeyreef45782019-10-21 03:24:04 +020082
Neels Hofmeyr9a515e52022-01-13 20:40:12 +010083int sdp_msg_to_str_buf(char *buf, size_t buflen, const struct sdp_msg *sdp);
84char *sdp_msg_to_str_c(void *ctx, const struct sdp_msg *sdp);
85const char *sdp_msg_to_str(const struct sdp_msg *sdp);
Oliver Smith10632132023-05-12 12:14:22 +020086
87void sdp_audio_codecs_set_csd(struct sdp_audio_codecs *ac);