blob: 44a8a309ce35d63f62c012c33c3e19ce4646f283 [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 {
13 unsigned int payload_type;
14 /* Like "GSM", "AMR", "EFR", ... */
15 char subtype_name[16];
16 unsigned int rate;
17 char fmtp[64];
18};
19
20struct sdp_audio_codecs {
21 unsigned int count;
22 struct sdp_audio_codec codec[16];
23};
24
25struct sdp_msg {
26 struct osmo_sockaddr_str rtp;
27 unsigned int ptime;
28 struct sdp_audio_codecs audio_codecs;
29};
30
31#define foreach_sdp_audio_codec(/* struct sdp_audio_codec* */ CODEC, \
32 /* struct sdp_audio_codecs* */ AC) \
33 for (CODEC = (AC)->codec; \
34 (CODEC - (AC)->codec) < OSMO_MIN((AC)->count, ARRAY_SIZE((AC)->codec)); \
35 CODEC++)
36
37const char *sdp_msg_line_end(const char *src);
38
39int sdp_audio_codec_cmp(const struct sdp_audio_codec *a, const struct sdp_audio_codec *b);
40
41struct sdp_audio_codec *sdp_audio_codec_add(struct sdp_audio_codecs *ac, unsigned int payload_type,
42 const char *subtype_name, unsigned int rate, const char *fmtp);
43struct sdp_audio_codec *sdp_audio_codec_add_copy(struct sdp_audio_codecs *ac,
44 const struct sdp_audio_codec *codec);
45int sdp_audio_codec_remove(struct sdp_audio_codecs *ac, const struct sdp_audio_codec *codec);
46struct sdp_audio_codec *sdp_audio_codec_by_payload_type(struct sdp_audio_codecs *ac,
47 unsigned int payload_type, bool create);
48struct sdp_audio_codec *sdp_audio_codec_by_descr(struct sdp_audio_codecs *ac,
49 const struct sdp_audio_codec *codec);
50
51void sdp_audio_codecs_intersection(struct sdp_audio_codecs *ac_dest, const struct sdp_audio_codecs *ac_other,
52 bool translate_payload_type_numbers);
53void sdp_audio_codecs_select(struct sdp_audio_codecs *ac, struct sdp_audio_codec *codec);
54
Neels Hofmeyr9a515e52022-01-13 20:40:12 +010055int sdp_msg_to_sdp_str_buf(char *dst, size_t dst_size, const struct sdp_msg *sdp);
56int sdp_msg_from_sdp_str(struct sdp_msg *sdp, const char *src);
Neels Hofmeyreef45782019-10-21 03:24:04 +020057
Neels Hofmeyr9a515e52022-01-13 20:40:12 +010058int sdp_audio_codec_to_str_buf(char *buf, size_t buflen, const struct sdp_audio_codec *codec);
59char *sdp_audio_codec_to_str_c(void *ctx, const struct sdp_audio_codec *codec);
60const char *sdp_audio_codec_to_str(const struct sdp_audio_codec *codec);
Neels Hofmeyreef45782019-10-21 03:24:04 +020061
Neels Hofmeyr9a515e52022-01-13 20:40:12 +010062int sdp_audio_codecs_to_str_buf(char *buf, size_t buflen, const struct sdp_audio_codecs *ac);
63char *sdp_audio_codecs_to_str_c(void *ctx, const struct sdp_audio_codecs *ac);
64const char *sdp_audio_codecs_to_str(const struct sdp_audio_codecs *ac);
Neels Hofmeyreef45782019-10-21 03:24:04 +020065
Neels Hofmeyr9a515e52022-01-13 20:40:12 +010066int sdp_msg_to_str_buf(char *buf, size_t buflen, const struct sdp_msg *sdp);
67char *sdp_msg_to_str_c(void *ctx, const struct sdp_msg *sdp);
68const char *sdp_msg_to_str(const struct sdp_msg *sdp);