blob: 537713c76441b982f738e7092624e32b591131ac [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
Neels Hofmeyrc9e0ca32022-01-13 18:28:44 +010039int sdp_audio_codec_cmp(const struct sdp_audio_codec *a, const struct sdp_audio_codec *b,
40 bool cmp_fmtp, bool cmp_payload_type);
41int sdp_audio_codecs_cmp(const struct sdp_audio_codecs *a, const struct sdp_audio_codecs *b,
42 bool cmp_fmtp, bool cmp_payload_type);
Neels Hofmeyreef45782019-10-21 03:24:04 +020043
44struct sdp_audio_codec *sdp_audio_codec_add(struct sdp_audio_codecs *ac, unsigned int payload_type,
45 const char *subtype_name, unsigned int rate, const char *fmtp);
46struct sdp_audio_codec *sdp_audio_codec_add_copy(struct sdp_audio_codecs *ac,
47 const struct sdp_audio_codec *codec);
48int sdp_audio_codec_remove(struct sdp_audio_codecs *ac, const struct sdp_audio_codec *codec);
49struct sdp_audio_codec *sdp_audio_codec_by_payload_type(struct sdp_audio_codecs *ac,
50 unsigned int payload_type, bool create);
51struct sdp_audio_codec *sdp_audio_codec_by_descr(struct sdp_audio_codecs *ac,
52 const struct sdp_audio_codec *codec);
53
54void sdp_audio_codecs_intersection(struct sdp_audio_codecs *ac_dest, const struct sdp_audio_codecs *ac_other,
55 bool translate_payload_type_numbers);
56void sdp_audio_codecs_select(struct sdp_audio_codecs *ac, struct sdp_audio_codec *codec);
57
Neels Hofmeyr9a515e52022-01-13 20:40:12 +010058int sdp_msg_to_sdp_str_buf(char *dst, size_t dst_size, const struct sdp_msg *sdp);
59int sdp_msg_from_sdp_str(struct sdp_msg *sdp, const char *src);
Neels Hofmeyreef45782019-10-21 03:24:04 +020060
Neels Hofmeyr9a515e52022-01-13 20:40:12 +010061int sdp_audio_codec_to_str_buf(char *buf, size_t buflen, const struct sdp_audio_codec *codec);
62char *sdp_audio_codec_to_str_c(void *ctx, const struct sdp_audio_codec *codec);
63const char *sdp_audio_codec_to_str(const struct sdp_audio_codec *codec);
Neels Hofmeyreef45782019-10-21 03:24:04 +020064
Neels Hofmeyr9a515e52022-01-13 20:40:12 +010065int sdp_audio_codecs_to_str_buf(char *buf, size_t buflen, const struct sdp_audio_codecs *ac);
66char *sdp_audio_codecs_to_str_c(void *ctx, const struct sdp_audio_codecs *ac);
67const char *sdp_audio_codecs_to_str(const struct sdp_audio_codecs *ac);
Neels Hofmeyreef45782019-10-21 03:24:04 +020068
Neels Hofmeyr9a515e52022-01-13 20:40:12 +010069int sdp_msg_to_str_buf(char *buf, size_t buflen, const struct sdp_msg *sdp);
70char *sdp_msg_to_str_c(void *ctx, const struct sdp_msg *sdp);
71const char *sdp_msg_to_str(const struct sdp_msg *sdp);