blob: 1b905b7efea90d28327b01f89e3a8dd49ae99924 [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
7extern const struct value_string sdp_msg_payload_type_names[];
8static inline const char *sdp_msg_payload_type_name(unsigned int payload_type)
9{ return get_value_string(sdp_msg_payload_type_names, payload_type); }
10int sdp_subtype_name_to_payload_type(const char *subtype_name);
11
Neels Hofmeyr01431082022-07-19 12:16:02 +020012enum sdp_mode_e {
13 SDP_MODE_UNSET = 0,
14 SDP_MODE_SENDONLY = 1,
15 SDP_MODE_RECVONLY = 2,
16 SDP_MODE_SENDRECV = 3,
17 SDP_MODE_INACTIVE = 4,
18};
19
Neels Hofmeyreef45782019-10-21 03:24:04 +020020struct sdp_audio_codec {
Neels Hofmeyr40d34972022-07-19 12:15:27 +020021 /* Payload type number, like 3 for GSM-FR. */
Neels Hofmeyreef45782019-10-21 03:24:04 +020022 unsigned int payload_type;
23 /* Like "GSM", "AMR", "EFR", ... */
24 char subtype_name[16];
25 unsigned int rate;
26 char fmtp[64];
27};
28
29struct sdp_audio_codecs {
30 unsigned int count;
31 struct sdp_audio_codec codec[16];
32};
33
34struct sdp_msg {
35 struct osmo_sockaddr_str rtp;
36 unsigned int ptime;
Neels Hofmeyr01431082022-07-19 12:16:02 +020037 enum sdp_mode_e mode;
Neels Hofmeyreef45782019-10-21 03:24:04 +020038 struct sdp_audio_codecs audio_codecs;
39};
40
41#define foreach_sdp_audio_codec(/* struct sdp_audio_codec* */ CODEC, \
42 /* struct sdp_audio_codecs* */ AC) \
43 for (CODEC = (AC)->codec; \
44 (CODEC - (AC)->codec) < OSMO_MIN((AC)->count, ARRAY_SIZE((AC)->codec)); \
45 CODEC++)
46
47const char *sdp_msg_line_end(const char *src);
48
Neels Hofmeyr2d116822022-08-06 17:39:04 +020049bool sdp_audio_codec_is_set(const struct sdp_audio_codec *a);
Neels Hofmeyrc9e0ca32022-01-13 18:28:44 +010050int sdp_audio_codec_cmp(const struct sdp_audio_codec *a, const struct sdp_audio_codec *b,
51 bool cmp_fmtp, bool cmp_payload_type);
52int sdp_audio_codecs_cmp(const struct sdp_audio_codecs *a, const struct sdp_audio_codecs *b,
53 bool cmp_fmtp, bool cmp_payload_type);
Neels Hofmeyreef45782019-10-21 03:24:04 +020054
Neels Hofmeyrd20dd222022-01-14 00:38:42 +010055struct sdp_audio_codec *sdp_audio_codecs_add(struct sdp_audio_codecs *ac, unsigned int payload_type,
56 const char *subtype_name, unsigned int rate, const char *fmtp);
57struct sdp_audio_codec *sdp_audio_codecs_add_copy(struct sdp_audio_codecs *ac,
58 const struct sdp_audio_codec *codec);
59int sdp_audio_codecs_remove(struct sdp_audio_codecs *ac, const struct sdp_audio_codec *codec);
60struct sdp_audio_codec *sdp_audio_codecs_by_payload_type(struct sdp_audio_codecs *ac,
61 unsigned int payload_type, bool create);
62struct sdp_audio_codec *sdp_audio_codecs_by_descr(struct sdp_audio_codecs *ac,
63 const struct sdp_audio_codec *codec);
Neels Hofmeyreef45782019-10-21 03:24:04 +020064
65void sdp_audio_codecs_intersection(struct sdp_audio_codecs *ac_dest, const struct sdp_audio_codecs *ac_other,
66 bool translate_payload_type_numbers);
67void sdp_audio_codecs_select(struct sdp_audio_codecs *ac, struct sdp_audio_codec *codec);
68
Neels Hofmeyr9a515e52022-01-13 20:40:12 +010069int sdp_msg_to_sdp_str_buf(char *dst, size_t dst_size, const struct sdp_msg *sdp);
70int sdp_msg_from_sdp_str(struct sdp_msg *sdp, const char *src);
Neels Hofmeyreef45782019-10-21 03:24:04 +020071
Neels Hofmeyr9a515e52022-01-13 20:40:12 +010072int sdp_audio_codec_to_str_buf(char *buf, size_t buflen, const struct sdp_audio_codec *codec);
73char *sdp_audio_codec_to_str_c(void *ctx, const struct sdp_audio_codec *codec);
74const char *sdp_audio_codec_to_str(const struct sdp_audio_codec *codec);
Neels Hofmeyreef45782019-10-21 03:24:04 +020075
Neels Hofmeyr9a515e52022-01-13 20:40:12 +010076int sdp_audio_codecs_to_str_buf(char *buf, size_t buflen, const struct sdp_audio_codecs *ac);
77char *sdp_audio_codecs_to_str_c(void *ctx, const struct sdp_audio_codecs *ac);
78const char *sdp_audio_codecs_to_str(const struct sdp_audio_codecs *ac);
Neels Hofmeyreef45782019-10-21 03:24:04 +020079
Neels Hofmeyr9a515e52022-01-13 20:40:12 +010080int sdp_msg_to_str_buf(char *buf, size_t buflen, const struct sdp_msg *sdp);
81char *sdp_msg_to_str_c(void *ctx, const struct sdp_msg *sdp);
82const char *sdp_msg_to_str(const struct sdp_msg *sdp);