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 | |
Neels Hofmeyr | 0143108 | 2022-07-19 12:16:02 +0200 | [diff] [blame] | 12 | enum 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 Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 20 | struct sdp_audio_codec { |
Neels Hofmeyr | 40d3497 | 2022-07-19 12:15:27 +0200 | [diff] [blame] | 21 | /* Payload type number, like 3 for GSM-FR. */ |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 22 | unsigned int payload_type; |
| 23 | /* Like "GSM", "AMR", "EFR", ... */ |
| 24 | char subtype_name[16]; |
| 25 | unsigned int rate; |
| 26 | char fmtp[64]; |
| 27 | }; |
| 28 | |
| 29 | struct sdp_audio_codecs { |
| 30 | unsigned int count; |
| 31 | struct sdp_audio_codec codec[16]; |
| 32 | }; |
| 33 | |
| 34 | struct sdp_msg { |
| 35 | struct osmo_sockaddr_str rtp; |
| 36 | unsigned int ptime; |
Neels Hofmeyr | 0143108 | 2022-07-19 12:16:02 +0200 | [diff] [blame] | 37 | enum sdp_mode_e mode; |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 38 | 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 | |
| 47 | const char *sdp_msg_line_end(const char *src); |
| 48 | |
Neels Hofmeyr | 2d11682 | 2022-08-06 17:39:04 +0200 | [diff] [blame] | 49 | bool sdp_audio_codec_is_set(const struct sdp_audio_codec *a); |
Neels Hofmeyr | c9e0ca3 | 2022-01-13 18:28:44 +0100 | [diff] [blame] | 50 | int sdp_audio_codec_cmp(const struct sdp_audio_codec *a, const struct sdp_audio_codec *b, |
| 51 | bool cmp_fmtp, bool cmp_payload_type); |
| 52 | int 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 Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 54 | |
Neels Hofmeyr | d20dd22 | 2022-01-14 00:38:42 +0100 | [diff] [blame] | 55 | struct 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); |
| 57 | struct sdp_audio_codec *sdp_audio_codecs_add_copy(struct sdp_audio_codecs *ac, |
| 58 | const struct sdp_audio_codec *codec); |
| 59 | int sdp_audio_codecs_remove(struct sdp_audio_codecs *ac, const struct sdp_audio_codec *codec); |
| 60 | struct sdp_audio_codec *sdp_audio_codecs_by_payload_type(struct sdp_audio_codecs *ac, |
| 61 | unsigned int payload_type, bool create); |
| 62 | struct sdp_audio_codec *sdp_audio_codecs_by_descr(struct sdp_audio_codecs *ac, |
| 63 | const struct sdp_audio_codec *codec); |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 64 | |
| 65 | void sdp_audio_codecs_intersection(struct sdp_audio_codecs *ac_dest, const struct sdp_audio_codecs *ac_other, |
| 66 | bool translate_payload_type_numbers); |
| 67 | void sdp_audio_codecs_select(struct sdp_audio_codecs *ac, struct sdp_audio_codec *codec); |
| 68 | |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 69 | int sdp_msg_to_sdp_str_buf(char *dst, size_t dst_size, const struct sdp_msg *sdp); |
| 70 | 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] | 71 | |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 72 | int sdp_audio_codec_to_str_buf(char *buf, size_t buflen, const struct sdp_audio_codec *codec); |
| 73 | char *sdp_audio_codec_to_str_c(void *ctx, const struct sdp_audio_codec *codec); |
| 74 | 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] | 75 | |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 76 | int sdp_audio_codecs_to_str_buf(char *buf, size_t buflen, const struct sdp_audio_codecs *ac); |
| 77 | char *sdp_audio_codecs_to_str_c(void *ctx, const struct sdp_audio_codecs *ac); |
| 78 | 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] | 79 | |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 80 | int sdp_msg_to_str_buf(char *buf, size_t buflen, const struct sdp_msg *sdp); |
| 81 | char *sdp_msg_to_str_c(void *ctx, const struct sdp_msg *sdp); |
| 82 | const char *sdp_msg_to_str(const struct sdp_msg *sdp); |