Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 1 | /* 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 | |
| 7 | extern const struct value_string sdp_msg_payload_type_names[]; |
| 8 | static inline const char *sdp_msg_payload_type_name(unsigned int payload_type) |
| 9 | { return get_value_string(sdp_msg_payload_type_names, payload_type); } |
| 10 | int sdp_subtype_name_to_payload_type(const char *subtype_name); |
| 11 | |
| 12 | struct 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 | |
| 20 | struct sdp_audio_codecs { |
| 21 | unsigned int count; |
| 22 | struct sdp_audio_codec codec[16]; |
| 23 | }; |
| 24 | |
| 25 | struct 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 | |
| 37 | const char *sdp_msg_line_end(const char *src); |
| 38 | |
Neels Hofmeyr | c9e0ca3 | 2022-01-13 18:28:44 +0100 | [diff] [blame] | 39 | int sdp_audio_codec_cmp(const struct sdp_audio_codec *a, const struct sdp_audio_codec *b, |
| 40 | bool cmp_fmtp, bool cmp_payload_type); |
| 41 | int 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 Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 43 | |
Neels Hofmeyr | d20dd22 | 2022-01-14 00:38:42 +0100 | [diff] [blame] | 44 | struct sdp_audio_codec *sdp_audio_codecs_add(struct sdp_audio_codecs *ac, unsigned int payload_type, |
| 45 | const char *subtype_name, unsigned int rate, const char *fmtp); |
| 46 | struct sdp_audio_codec *sdp_audio_codecs_add_copy(struct sdp_audio_codecs *ac, |
| 47 | const struct sdp_audio_codec *codec); |
| 48 | int sdp_audio_codecs_remove(struct sdp_audio_codecs *ac, const struct sdp_audio_codec *codec); |
| 49 | struct sdp_audio_codec *sdp_audio_codecs_by_payload_type(struct sdp_audio_codecs *ac, |
| 50 | unsigned int payload_type, bool create); |
| 51 | struct sdp_audio_codec *sdp_audio_codecs_by_descr(struct sdp_audio_codecs *ac, |
| 52 | const struct sdp_audio_codec *codec); |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 53 | |
| 54 | void sdp_audio_codecs_intersection(struct sdp_audio_codecs *ac_dest, const struct sdp_audio_codecs *ac_other, |
| 55 | bool translate_payload_type_numbers); |
| 56 | void sdp_audio_codecs_select(struct sdp_audio_codecs *ac, struct sdp_audio_codec *codec); |
| 57 | |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 58 | int sdp_msg_to_sdp_str_buf(char *dst, size_t dst_size, const struct sdp_msg *sdp); |
| 59 | int sdp_msg_from_sdp_str(struct sdp_msg *sdp, const char *src); |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 60 | |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 61 | int sdp_audio_codec_to_str_buf(char *buf, size_t buflen, const struct sdp_audio_codec *codec); |
| 62 | char *sdp_audio_codec_to_str_c(void *ctx, const struct sdp_audio_codec *codec); |
| 63 | const char *sdp_audio_codec_to_str(const struct sdp_audio_codec *codec); |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 64 | |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 65 | int sdp_audio_codecs_to_str_buf(char *buf, size_t buflen, const struct sdp_audio_codecs *ac); |
| 66 | char *sdp_audio_codecs_to_str_c(void *ctx, const struct sdp_audio_codecs *ac); |
| 67 | const char *sdp_audio_codecs_to_str(const struct sdp_audio_codecs *ac); |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 68 | |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 69 | int sdp_msg_to_str_buf(char *buf, size_t buflen, const struct sdp_msg *sdp); |
| 70 | char *sdp_msg_to_str_c(void *ctx, const struct sdp_msg *sdp); |
| 71 | const char *sdp_msg_to_str(const struct sdp_msg *sdp); |