blob: cf1e56055f4d58232e12eae82ffd4db32ffe2951 [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
12struct sdp_audio_codec {
Neels Hofmeyr40d34972022-07-19 12:15:27 +020013 /* Payload type number, like 3 for GSM-FR. */
Neels Hofmeyreef45782019-10-21 03:24:04 +020014 unsigned int payload_type;
15 /* Like "GSM", "AMR", "EFR", ... */
16 char subtype_name[16];
17 unsigned int rate;
18 char fmtp[64];
19};
20
21struct sdp_audio_codecs {
22 unsigned int count;
23 struct sdp_audio_codec codec[16];
24};
25
26struct sdp_msg {
27 struct osmo_sockaddr_str rtp;
28 unsigned int ptime;
29 struct sdp_audio_codecs audio_codecs;
30};
31
32#define foreach_sdp_audio_codec(/* struct sdp_audio_codec* */ CODEC, \
33 /* struct sdp_audio_codecs* */ AC) \
34 for (CODEC = (AC)->codec; \
35 (CODEC - (AC)->codec) < OSMO_MIN((AC)->count, ARRAY_SIZE((AC)->codec)); \
36 CODEC++)
37
38const char *sdp_msg_line_end(const char *src);
39
Neels Hofmeyr2d116822022-08-06 17:39:04 +020040bool sdp_audio_codec_is_set(const struct sdp_audio_codec *a);
Neels Hofmeyrc9e0ca32022-01-13 18:28:44 +010041int sdp_audio_codec_cmp(const struct sdp_audio_codec *a, const struct sdp_audio_codec *b,
42 bool cmp_fmtp, bool cmp_payload_type);
43int sdp_audio_codecs_cmp(const struct sdp_audio_codecs *a, const struct sdp_audio_codecs *b,
44 bool cmp_fmtp, bool cmp_payload_type);
Neels Hofmeyreef45782019-10-21 03:24:04 +020045
Neels Hofmeyrd20dd222022-01-14 00:38:42 +010046struct sdp_audio_codec *sdp_audio_codecs_add(struct sdp_audio_codecs *ac, unsigned int payload_type,
47 const char *subtype_name, unsigned int rate, const char *fmtp);
48struct sdp_audio_codec *sdp_audio_codecs_add_copy(struct sdp_audio_codecs *ac,
49 const struct sdp_audio_codec *codec);
50int sdp_audio_codecs_remove(struct sdp_audio_codecs *ac, const struct sdp_audio_codec *codec);
51struct sdp_audio_codec *sdp_audio_codecs_by_payload_type(struct sdp_audio_codecs *ac,
52 unsigned int payload_type, bool create);
53struct sdp_audio_codec *sdp_audio_codecs_by_descr(struct sdp_audio_codecs *ac,
54 const struct sdp_audio_codec *codec);
Neels Hofmeyreef45782019-10-21 03:24:04 +020055
56void sdp_audio_codecs_intersection(struct sdp_audio_codecs *ac_dest, const struct sdp_audio_codecs *ac_other,
57 bool translate_payload_type_numbers);
58void sdp_audio_codecs_select(struct sdp_audio_codecs *ac, struct sdp_audio_codec *codec);
59
Neels Hofmeyr9a515e52022-01-13 20:40:12 +010060int sdp_msg_to_sdp_str_buf(char *dst, size_t dst_size, const struct sdp_msg *sdp);
61int sdp_msg_from_sdp_str(struct sdp_msg *sdp, const char *src);
Neels Hofmeyreef45782019-10-21 03:24:04 +020062
Neels Hofmeyr9a515e52022-01-13 20:40:12 +010063int sdp_audio_codec_to_str_buf(char *buf, size_t buflen, const struct sdp_audio_codec *codec);
64char *sdp_audio_codec_to_str_c(void *ctx, const struct sdp_audio_codec *codec);
65const char *sdp_audio_codec_to_str(const struct sdp_audio_codec *codec);
Neels Hofmeyreef45782019-10-21 03:24:04 +020066
Neels Hofmeyr9a515e52022-01-13 20:40:12 +010067int sdp_audio_codecs_to_str_buf(char *buf, size_t buflen, const struct sdp_audio_codecs *ac);
68char *sdp_audio_codecs_to_str_c(void *ctx, const struct sdp_audio_codecs *ac);
69const char *sdp_audio_codecs_to_str(const struct sdp_audio_codecs *ac);
Neels Hofmeyreef45782019-10-21 03:24:04 +020070
Neels Hofmeyr9a515e52022-01-13 20:40:12 +010071int sdp_msg_to_str_buf(char *buf, size_t buflen, const struct sdp_msg *sdp);
72char *sdp_msg_to_str_c(void *ctx, const struct sdp_msg *sdp);
73const char *sdp_msg_to_str(const struct sdp_msg *sdp);