Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 1 | /* Minimalistic SDP parse/compose implementation, focused on GSM audio codecs */ |
| 2 | /* |
Vadim Yanitskiy | 999a593 | 2023-05-18 17:22:26 +0700 | [diff] [blame] | 3 | * (C) 2019 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de> |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 4 | * All Rights Reserved |
| 5 | * |
| 6 | * SPDX-License-Identifier: AGPL-3.0+ |
| 7 | * |
| 8 | * Author: Neels Hofmeyr |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU Affero General Public License as published by |
| 12 | * the Free Software Foundation; either version 3 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU Affero General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Affero General Public License |
| 21 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | */ |
| 23 | |
| 24 | #include <string.h> |
| 25 | #include <errno.h> |
| 26 | |
| 27 | #include <osmocom/core/utils.h> |
| 28 | #include <osmocom/core/logging.h> |
| 29 | |
| 30 | #include <osmocom/msc/debug.h> |
| 31 | #include <osmocom/msc/sdp_msg.h> |
| 32 | |
Neels Hofmeyr | 2d11682 | 2022-08-06 17:39:04 +0200 | [diff] [blame] | 33 | bool sdp_audio_codec_is_set(const struct sdp_audio_codec *a) |
| 34 | { |
| 35 | return a && a->subtype_name[0]; |
| 36 | } |
| 37 | |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 38 | /* Compare name, rate and fmtp, returning typical cmp result: 0 on match, and -1 / 1 on mismatch. |
Neels Hofmeyr | c9e0ca3 | 2022-01-13 18:28:44 +0100 | [diff] [blame] | 39 | * If cmp_fmtp is false, do *not* compare the fmtp string; if true, compare fmtp 1:1 as strings. |
| 40 | * If cmp_payload_type is false, do *not* compare the payload_type number. |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 41 | * The fmtp is only string-compared -- e.g. if AMR parameters appear in a different order, it amounts to a mismatch even |
| 42 | * though all parameters are the same. */ |
Neels Hofmeyr | c9e0ca3 | 2022-01-13 18:28:44 +0100 | [diff] [blame] | 43 | int sdp_audio_codec_cmp(const struct sdp_audio_codec *a, const struct sdp_audio_codec *b, |
| 44 | bool cmp_fmtp, bool cmp_payload_type) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 45 | { |
Neels Hofmeyr | c9e0ca3 | 2022-01-13 18:28:44 +0100 | [diff] [blame] | 46 | int cmp; |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 47 | if (a == b) |
| 48 | return 0; |
| 49 | if (!a) |
| 50 | return -1; |
| 51 | if (!b) |
| 52 | return 1; |
Neels Hofmeyr | c9e0ca3 | 2022-01-13 18:28:44 +0100 | [diff] [blame] | 53 | cmp = strncmp(a->subtype_name, b->subtype_name, sizeof(a->subtype_name)); |
| 54 | if (cmp) |
| 55 | return cmp; |
| 56 | cmp = OSMO_CMP(a->rate, b->rate); |
| 57 | if (cmp) |
| 58 | return cmp; |
| 59 | if (cmp_fmtp) { |
| 60 | cmp = strncmp(a->fmtp, b->fmtp, sizeof(a->fmtp)); |
| 61 | if (cmp) |
| 62 | return cmp; |
| 63 | } |
| 64 | if (cmp_payload_type) { |
| 65 | cmp = OSMO_CMP(a->payload_type, b->payload_type); |
| 66 | if (cmp) |
| 67 | return cmp; |
| 68 | } |
| 69 | return 0; |
| 70 | } |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 71 | |
Neels Hofmeyr | c9e0ca3 | 2022-01-13 18:28:44 +0100 | [diff] [blame] | 72 | /* Compare two lists of audio codecs, returning typical cmp result: 0 on match, and -1 / 1 on mismatch. |
| 73 | * The ordering in the two lists may differ, except that the first codec in 'a' must also be the first codec in 'b'. |
| 74 | * This is because the first codec typically expresses the preferred codec to use. |
| 75 | * If cmp_fmtp is false, do *not* compare the fmtp strings; if true, compare fmtp 1:1 as strings. |
| 76 | * If cmp_payload_type is false, do *not* compare the payload_type numbers. |
| 77 | * The fmtp is only string-compared -- e.g. if AMR parameters appear in a different order, it amounts to a mismatch even |
| 78 | * though all parameters are the same. */ |
| 79 | int sdp_audio_codecs_cmp(const struct sdp_audio_codecs *a, const struct sdp_audio_codecs *b, |
| 80 | bool cmp_fmtp, bool cmp_payload_type) |
| 81 | { |
| 82 | const struct sdp_audio_codec *codec_a; |
| 83 | const struct sdp_audio_codec *codec_b; |
| 84 | int cmp; |
| 85 | if (a == b) |
| 86 | return 0; |
| 87 | if (!a) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 88 | return -1; |
Neels Hofmeyr | c9e0ca3 | 2022-01-13 18:28:44 +0100 | [diff] [blame] | 89 | if (!b) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 90 | return 1; |
| 91 | |
Neels Hofmeyr | c9e0ca3 | 2022-01-13 18:28:44 +0100 | [diff] [blame] | 92 | cmp = OSMO_CMP(a->count, b->count); |
| 93 | if (cmp) |
| 94 | return cmp; |
| 95 | |
| 96 | if (!a->count) |
| 97 | return 0; |
| 98 | |
| 99 | /* The first codec is the "chosen" codec and should match. The others may appear in different order. */ |
| 100 | cmp = sdp_audio_codec_cmp(&a->codec[0], &b->codec[0], cmp_fmtp, cmp_payload_type); |
| 101 | if (cmp) |
| 102 | return cmp; |
| 103 | |
| 104 | /* See if each codec in a is also present in b */ |
| 105 | foreach_sdp_audio_codec(codec_a, a) { |
| 106 | bool match_found = false; |
| 107 | foreach_sdp_audio_codec(codec_b, b) { |
| 108 | if (!sdp_audio_codec_cmp(codec_a, codec_b, cmp_fmtp, cmp_payload_type)) { |
| 109 | match_found = true; |
| 110 | break; |
| 111 | } |
| 112 | } |
| 113 | if (!match_found) |
| 114 | return -1; |
| 115 | } |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 116 | |
| 117 | return 0; |
| 118 | } |
| 119 | |
| 120 | /* Given a predefined fixed payload_type number, add an SDP audio codec entry, if not present yet. |
| 121 | * The payload_type must exist in sdp_msg_payload_type_names. |
| 122 | * Return the audio codec created or already existing for this payload type number. |
| 123 | */ |
Neels Hofmeyr | d20dd22 | 2022-01-14 00:38:42 +0100 | [diff] [blame] | 124 | struct sdp_audio_codec *sdp_audio_codecs_add(struct sdp_audio_codecs *ac, unsigned int payload_type, |
| 125 | const char *subtype_name, unsigned int rate, const char *fmtp) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 126 | { |
| 127 | struct sdp_audio_codec *codec; |
| 128 | |
| 129 | /* Does an entry already exist? */ |
Neels Hofmeyr | d20dd22 | 2022-01-14 00:38:42 +0100 | [diff] [blame] | 130 | codec = sdp_audio_codecs_by_payload_type(ac, payload_type, false); |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 131 | if (codec) { |
| 132 | /* Already exists, sanity check */ |
| 133 | if (!codec->subtype_name[0]) |
| 134 | OSMO_STRLCPY_ARRAY(codec->subtype_name, subtype_name); |
| 135 | else if (strcmp(codec->subtype_name, subtype_name)) { |
| 136 | /* There already is an entry with this payload_type number but a mismatching subtype_name. That is |
| 137 | * weird, rather abort. */ |
| 138 | return NULL; |
| 139 | } |
| 140 | if (codec->rate != rate |
| 141 | || (fmtp && strcmp(fmtp, codec->fmtp))) { |
| 142 | /* Mismatching details. Rather abort */ |
| 143 | return NULL; |
| 144 | } |
| 145 | return codec; |
| 146 | } |
| 147 | |
| 148 | /* None exists, create codec entry for this payload type number */ |
Neels Hofmeyr | d20dd22 | 2022-01-14 00:38:42 +0100 | [diff] [blame] | 149 | codec = sdp_audio_codecs_by_payload_type(ac, payload_type, true); |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 150 | /* NULL means unable to add an entry */ |
| 151 | if (!codec) |
| 152 | return NULL; |
| 153 | |
| 154 | OSMO_STRLCPY_ARRAY(codec->subtype_name, subtype_name); |
| 155 | if (fmtp) |
| 156 | OSMO_STRLCPY_ARRAY(codec->fmtp, fmtp); |
Neels Hofmeyr | 8ff00e7 | 2023-03-04 03:56:46 +0100 | [diff] [blame] | 157 | codec->rate = rate; |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 158 | return codec; |
| 159 | } |
| 160 | |
Neels Hofmeyr | d20dd22 | 2022-01-14 00:38:42 +0100 | [diff] [blame] | 161 | struct sdp_audio_codec *sdp_audio_codecs_add_copy(struct sdp_audio_codecs *ac, const struct sdp_audio_codec *codec) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 162 | { |
Neels Hofmeyr | d20dd22 | 2022-01-14 00:38:42 +0100 | [diff] [blame] | 163 | return sdp_audio_codecs_add(ac, codec->payload_type, codec->subtype_name, codec->rate, |
| 164 | codec->fmtp[0] ? codec->fmtp : NULL); |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 165 | } |
| 166 | |
Neels Hofmeyr | 40d3497 | 2022-07-19 12:15:27 +0200 | [diff] [blame] | 167 | /* Find or create an entry for the given payload_type number in the given list of codecs. |
| 168 | * If the given payload_type number is already present in ac, return the first matching entry. |
| 169 | * If no such payload_type number is present: a) return NULL if create == false; |
| 170 | * b) If create == true, add a mostly empty codec entry to the end of ac with the given payload_type number, and return |
| 171 | * the created entry. |
| 172 | * If create == true, a NULL return value means that there was no unused entry left in ac to add this payload_type. |
| 173 | */ |
Neels Hofmeyr | d20dd22 | 2022-01-14 00:38:42 +0100 | [diff] [blame] | 174 | struct sdp_audio_codec *sdp_audio_codecs_by_payload_type(struct sdp_audio_codecs *ac, unsigned int payload_type, |
| 175 | bool create) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 176 | { |
| 177 | struct sdp_audio_codec *codec; |
| 178 | foreach_sdp_audio_codec(codec, ac) { |
| 179 | if (codec->payload_type == payload_type) |
| 180 | return codec; |
| 181 | } |
| 182 | |
| 183 | if (!create) |
| 184 | return NULL; |
| 185 | |
| 186 | /* Not found; codec points after the last entry now. */ |
| 187 | if ((codec - ac->codec) >= ARRAY_SIZE(ac->codec)) |
| 188 | return NULL; |
| 189 | |
| 190 | *codec = (struct sdp_audio_codec){ |
| 191 | .payload_type = payload_type, |
| 192 | .rate = 8000, |
| 193 | }; |
| 194 | |
| 195 | ac->count = (codec - ac->codec) + 1; |
| 196 | return codec; |
| 197 | } |
| 198 | |
Neels Hofmeyr | c9e0ca3 | 2022-01-13 18:28:44 +0100 | [diff] [blame] | 199 | /* Return a given sdp_msg's codec entry that matches the subtype_name and rate of the given codec, or NULL if no |
| 200 | * match is found. Comparison is made by sdp_audio_codec_cmp(cmp_payload_type=false). */ |
Neels Hofmeyr | d20dd22 | 2022-01-14 00:38:42 +0100 | [diff] [blame] | 201 | struct sdp_audio_codec *sdp_audio_codecs_by_descr(struct sdp_audio_codecs *ac, const struct sdp_audio_codec *codec) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 202 | { |
| 203 | struct sdp_audio_codec *i; |
| 204 | foreach_sdp_audio_codec(i, ac) { |
Neels Hofmeyr | c9e0ca3 | 2022-01-13 18:28:44 +0100 | [diff] [blame] | 205 | if (!sdp_audio_codec_cmp(i, codec, false, false)) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 206 | return i; |
| 207 | } |
| 208 | return NULL; |
| 209 | } |
| 210 | |
| 211 | /* Remove the codec entry pointed at by 'codec'. 'codec' must point at an entry of 'sdp' (to use an external codec |
Neels Hofmeyr | d20dd22 | 2022-01-14 00:38:42 +0100 | [diff] [blame] | 212 | * instance, use sdp_audio_codecs_by_descr()). |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 213 | * Return 0 on success, -ENOENT if codec does not point at the sdp->codec array. */ |
Neels Hofmeyr | d20dd22 | 2022-01-14 00:38:42 +0100 | [diff] [blame] | 214 | int sdp_audio_codecs_remove(struct sdp_audio_codecs *ac, const struct sdp_audio_codec *codec) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 215 | { |
| 216 | struct sdp_audio_codec *i; |
| 217 | if ((codec < ac->codec) |
| 218 | || ((codec - ac->codec) >= OSMO_MIN(ac->count, ARRAY_SIZE(ac->codec)))) |
| 219 | return -ENOENT; |
| 220 | |
| 221 | /* Move all following entries one up */ |
| 222 | ac->count--; |
| 223 | foreach_sdp_audio_codec(i, ac) { |
| 224 | if (i < codec) |
| 225 | continue; |
| 226 | *i = *(i+1); |
| 227 | } |
| 228 | return 0; |
| 229 | } |
| 230 | |
Neels Hofmeyr | 0143108 | 2022-07-19 12:16:02 +0200 | [diff] [blame] | 231 | static const char * const sdp_mode_str[] = { |
| 232 | [SDP_MODE_UNSET] = "-", |
| 233 | [SDP_MODE_SENDONLY] = "sendonly", |
| 234 | [SDP_MODE_RECVONLY] = "recvonly", |
| 235 | [SDP_MODE_SENDRECV] = "sendrecv", |
| 236 | [SDP_MODE_INACTIVE] = "inactive", |
| 237 | }; |
| 238 | |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 239 | /* Convert struct sdp_msg to the actual SDP protocol representation */ |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 240 | int sdp_msg_to_sdp_str_buf(char *dst, size_t dst_size, const struct sdp_msg *sdp) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 241 | { |
| 242 | const struct sdp_audio_codec *codec; |
| 243 | struct osmo_strbuf sb = { .buf = dst, .len = dst_size }; |
Neels Hofmeyr | 6d9b485 | 2022-09-05 16:02:50 +0200 | [diff] [blame] | 244 | const char *ip; |
| 245 | char ipv; |
| 246 | |
| 247 | if (!sdp) { |
| 248 | OSMO_STRBUF_PRINTF(sb, "%s", ""); |
| 249 | return sb.chars_needed; |
| 250 | } |
| 251 | |
| 252 | ip = sdp->rtp.ip[0] ? sdp->rtp.ip : "0.0.0.0"; |
| 253 | ipv = (osmo_ip_str_type(ip) == AF_INET6) ? '6' : '4'; |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 254 | |
| 255 | OSMO_STRBUF_PRINTF(sb, |
| 256 | "v=0\r\n" |
Pau Espin Pedrol | eeda9e1 | 2020-09-03 22:11:03 +0200 | [diff] [blame] | 257 | "o=OsmoMSC 0 0 IN IP%c %s\r\n" |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 258 | "s=GSM Call\r\n" |
Pau Espin Pedrol | eeda9e1 | 2020-09-03 22:11:03 +0200 | [diff] [blame] | 259 | "c=IN IP%c %s\r\n" |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 260 | "t=0 0\r\n" |
| 261 | "m=audio %d RTP/AVP", |
Pau Espin Pedrol | eeda9e1 | 2020-09-03 22:11:03 +0200 | [diff] [blame] | 262 | ipv, ip, ipv, ip, |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 263 | sdp->rtp.port); |
| 264 | |
| 265 | /* Append all payload type numbers to 'm=audio <port> RTP/AVP 3 4 112' line */ |
| 266 | foreach_sdp_audio_codec(codec, &sdp->audio_codecs) |
| 267 | OSMO_STRBUF_PRINTF(sb, " %d", codec->payload_type); |
| 268 | OSMO_STRBUF_PRINTF(sb, "\r\n"); |
| 269 | |
| 270 | /* Add details for all codecs */ |
| 271 | foreach_sdp_audio_codec(codec, &sdp->audio_codecs) { |
Neels Hofmeyr | 5b1f9a2 | 2022-08-06 17:40:52 +0200 | [diff] [blame] | 272 | if (!sdp_audio_codec_is_set(codec)) |
| 273 | continue; |
| 274 | OSMO_STRBUF_PRINTF(sb, "a=rtpmap:%d %s/%d\r\n", codec->payload_type, codec->subtype_name, |
| 275 | codec->rate > 0 ? codec->rate : 8000); |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 276 | if (codec->fmtp[0]) |
| 277 | OSMO_STRBUF_PRINTF(sb, "a=fmtp:%d %s\r\n", codec->payload_type, codec->fmtp); |
| 278 | } |
| 279 | |
| 280 | OSMO_STRBUF_PRINTF(sb, "a=ptime:%d\r\n", sdp->ptime > 0? sdp->ptime : 20); |
| 281 | |
Neels Hofmeyr | 0143108 | 2022-07-19 12:16:02 +0200 | [diff] [blame] | 282 | if (sdp->mode != SDP_MODE_UNSET && sdp->mode < ARRAY_SIZE(sdp_mode_str)) |
| 283 | OSMO_STRBUF_PRINTF(sb, "a=%s\r\n", sdp_mode_str[sdp->mode]); |
| 284 | |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 285 | return sb.chars_needed; |
| 286 | } |
| 287 | |
| 288 | /* Return the first line ending (or the end of the string) at or after the given string position. */ |
| 289 | const char *sdp_msg_line_end(const char *src) |
| 290 | { |
| 291 | const char *line_end = strchr(src, '\r'); |
| 292 | if (!line_end) |
| 293 | line_end = strchr(src, '\n'); |
| 294 | if (!line_end) |
| 295 | line_end = src + strlen(src); |
| 296 | return line_end; |
| 297 | } |
| 298 | |
| 299 | /* parse a line like 'a=rtpmap:0 PCMU/8000', 'a=fmtp:112 octet-align=1; mode-set=4', 'a=ptime:20'. |
| 300 | * The src should point at the character after 'a=', e.g. at the start of 'rtpmap', 'fmtp', 'ptime' |
| 301 | */ |
| 302 | int sdp_parse_attrib(struct sdp_msg *sdp, const char *src) |
| 303 | { |
| 304 | unsigned int payload_type; |
| 305 | struct sdp_audio_codec *codec; |
| 306 | #define A_RTPMAP "rtpmap:" |
| 307 | #define A_FMTP "fmtp:" |
| 308 | #define A_PTIME "ptime:" |
| 309 | #define A_RTCP "rtcp:" |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 310 | |
| 311 | if (osmo_str_startswith(src, A_RTPMAP)) { |
Neels Hofmeyr | 40d3497 | 2022-07-19 12:15:27 +0200 | [diff] [blame] | 312 | /* "a=rtpmap:3 GSM/8000" */ |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 313 | char *audio_name; |
| 314 | unsigned int channels = 1; |
| 315 | if (sscanf(src, A_RTPMAP "%u", &payload_type) != 1) |
| 316 | return -EINVAL; |
| 317 | |
| 318 | audio_name = strchr(src, ' '); |
| 319 | if (!audio_name || audio_name >= sdp_msg_line_end(src)) |
| 320 | return -EINVAL; |
| 321 | |
Neels Hofmeyr | d20dd22 | 2022-01-14 00:38:42 +0100 | [diff] [blame] | 322 | codec = sdp_audio_codecs_by_payload_type(&sdp->audio_codecs, payload_type, true); |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 323 | if (!codec) |
| 324 | return -ENOSPC; |
| 325 | |
| 326 | if (sscanf(audio_name, " %31[^/]/%u/%u", codec->subtype_name, &codec->rate, &channels) < 1) |
| 327 | return -EINVAL; |
| 328 | |
| 329 | if (channels != 1) |
| 330 | return -ENOTSUP; |
| 331 | } |
| 332 | |
| 333 | else if (osmo_str_startswith(src, A_FMTP)) { |
Neels Hofmeyr | 40d3497 | 2022-07-19 12:15:27 +0200 | [diff] [blame] | 334 | /* "a=fmtp:112 octet-align=1;mode-set=0,1,2,3" */ |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 335 | char *fmtp_str; |
| 336 | const char *line_end = sdp_msg_line_end(src); |
| 337 | if (sscanf(src, A_FMTP "%u", &payload_type) != 1) |
| 338 | return -EINVAL; |
| 339 | |
| 340 | fmtp_str = strchr(src, ' '); |
| 341 | if (!fmtp_str) |
| 342 | return -EINVAL; |
| 343 | fmtp_str++; |
| 344 | if (fmtp_str >= line_end) |
| 345 | return -EINVAL; |
| 346 | |
Neels Hofmeyr | d20dd22 | 2022-01-14 00:38:42 +0100 | [diff] [blame] | 347 | codec = sdp_audio_codecs_by_payload_type(&sdp->audio_codecs, payload_type, true); |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 348 | if (!codec) |
| 349 | return -ENOSPC; |
| 350 | |
| 351 | /* (+1 because osmo_strlcpy() interprets it as size including the '\0') */ |
| 352 | osmo_strlcpy(codec->fmtp, fmtp_str, line_end - fmtp_str + 1); |
| 353 | } |
| 354 | |
| 355 | else if (osmo_str_startswith(src, A_PTIME)) { |
Neels Hofmeyr | 40d3497 | 2022-07-19 12:15:27 +0200 | [diff] [blame] | 356 | /* "a=ptime:20" */ |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 357 | if (sscanf(src, A_PTIME "%u", &sdp->ptime) != 1) |
| 358 | return -EINVAL; |
| 359 | |
| 360 | } |
| 361 | |
| 362 | else if (osmo_str_startswith(src, A_RTCP)) { |
| 363 | /* TODO? */ |
| 364 | } |
| 365 | |
Neels Hofmeyr | 0143108 | 2022-07-19 12:16:02 +0200 | [diff] [blame] | 366 | else if (osmo_str_startswith(src, sdp_mode_str[SDP_MODE_SENDRECV])) { |
Neels Hofmeyr | 40d3497 | 2022-07-19 12:15:27 +0200 | [diff] [blame] | 367 | /* "a=sendrecv" */ |
Neels Hofmeyr | 0143108 | 2022-07-19 12:16:02 +0200 | [diff] [blame] | 368 | sdp->mode = SDP_MODE_SENDRECV; |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 369 | } |
| 370 | |
Neels Hofmeyr | 0143108 | 2022-07-19 12:16:02 +0200 | [diff] [blame] | 371 | else if (osmo_str_startswith(src, sdp_mode_str[SDP_MODE_SENDONLY])) { |
Neels Hofmeyr | 40d3497 | 2022-07-19 12:15:27 +0200 | [diff] [blame] | 372 | /* "a=sendonly" */ |
Neels Hofmeyr | 0143108 | 2022-07-19 12:16:02 +0200 | [diff] [blame] | 373 | sdp->mode = SDP_MODE_SENDONLY; |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 374 | } |
| 375 | |
Neels Hofmeyr | 0143108 | 2022-07-19 12:16:02 +0200 | [diff] [blame] | 376 | else if (osmo_str_startswith(src, sdp_mode_str[SDP_MODE_RECVONLY])) { |
Neels Hofmeyr | 40d3497 | 2022-07-19 12:15:27 +0200 | [diff] [blame] | 377 | /* "a=recvonly" */ |
Neels Hofmeyr | 0143108 | 2022-07-19 12:16:02 +0200 | [diff] [blame] | 378 | sdp->mode = SDP_MODE_RECVONLY; |
| 379 | } |
| 380 | |
| 381 | else if (osmo_str_startswith(src, sdp_mode_str[SDP_MODE_INACTIVE])) { |
| 382 | /* "a=inactive" */ |
| 383 | sdp->mode = SDP_MODE_INACTIVE; |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | return 0; |
| 387 | } |
| 388 | |
| 389 | const struct value_string sdp_msg_payload_type_names[] = { |
| 390 | { 0, "PCMU" }, |
| 391 | { 3, "GSM" }, |
| 392 | { 8, "PCMA" }, |
| 393 | { 18, "G729" }, |
| 394 | { 110, "GSM-EFR" }, |
| 395 | { 111, "GSM-HR-08" }, |
| 396 | { 112, "AMR" }, |
| 397 | { 113, "AMR-WB" }, |
| 398 | {} |
| 399 | }; |
| 400 | |
| 401 | /* Return payload type number matching given string ("AMR", "GSM", ...) or negative if not found. */ |
| 402 | int sdp_subtype_name_to_payload_type(const char *subtype_name) |
| 403 | { |
| 404 | return get_string_value(sdp_msg_payload_type_names, subtype_name); |
| 405 | } |
| 406 | |
| 407 | /* Parse a line like 'm=audio 16398 RTP/AVP 0 3 8 96 112', starting after the '=' */ |
| 408 | static int sdp_parse_media_description(struct sdp_msg *sdp, const char *src) |
| 409 | { |
| 410 | unsigned int port; |
| 411 | int i; |
| 412 | const char *payload_type_str; |
| 413 | const char *line_end = sdp_msg_line_end(src); |
| 414 | if (sscanf(src, "audio %u RTP/AVP", &port) < 1) |
| 415 | return -ENOTSUP; |
| 416 | |
Vadim Yanitskiy | 40b11c9 | 2020-02-09 04:04:54 +0700 | [diff] [blame] | 417 | if (port > 0xffff) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 418 | return -EINVAL; |
| 419 | |
| 420 | sdp->rtp.port = port; |
| 421 | |
| 422 | /* skip "audio 12345 RTP/AVP ", i.e. 3 spaces on */ |
| 423 | payload_type_str = src; |
| 424 | for (i = 0; i < 3; i++) { |
| 425 | payload_type_str = strchr(payload_type_str, ' '); |
| 426 | if (!payload_type_str) |
| 427 | return -EINVAL; |
| 428 | while (*payload_type_str == ' ') |
| 429 | payload_type_str++; |
| 430 | if (payload_type_str >= line_end) |
| 431 | return -EINVAL; |
| 432 | } |
| 433 | |
| 434 | /* Parse listing of payload type numbers after "RTP/AVP" */ |
| 435 | while (payload_type_str < line_end) { |
| 436 | unsigned int payload_type; |
| 437 | struct sdp_audio_codec *codec; |
| 438 | const char *subtype_name; |
| 439 | if (sscanf(payload_type_str, "%u", &payload_type) < 1) |
| 440 | return -EINVAL; |
| 441 | |
Neels Hofmeyr | d20dd22 | 2022-01-14 00:38:42 +0100 | [diff] [blame] | 442 | codec = sdp_audio_codecs_by_payload_type(&sdp->audio_codecs, payload_type, true); |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 443 | if (!codec) |
| 444 | return -ENOSPC; |
| 445 | |
| 446 | /* Fill in subtype name for fixed payload types */ |
| 447 | subtype_name = get_value_string_or_null(sdp_msg_payload_type_names, codec->payload_type); |
| 448 | if (subtype_name) |
| 449 | OSMO_STRLCPY_ARRAY(codec->subtype_name, subtype_name); |
| 450 | |
| 451 | payload_type_str = strchr(payload_type_str, ' '); |
| 452 | if (!payload_type_str) |
| 453 | payload_type_str = line_end; |
| 454 | while (*payload_type_str == ' ') |
| 455 | payload_type_str++; |
| 456 | } |
| 457 | |
| 458 | return 0; |
| 459 | } |
| 460 | |
| 461 | /* parse a line like 'c=IN IP4 192.168.11.151' starting after the '=' */ |
| 462 | static int sdp_parse_connection_info(struct sdp_msg *sdp, const char *src) |
| 463 | { |
| 464 | char ipv[10]; |
| 465 | char addr_str[INET6_ADDRSTRLEN]; |
| 466 | if (sscanf(src, "IN %s %s", ipv, addr_str) < 2) |
| 467 | return -EINVAL; |
| 468 | |
| 469 | /* supporting only IPv4 */ |
| 470 | if (strcmp(ipv, "IP4")) |
| 471 | return -ENOTSUP; |
| 472 | |
| 473 | osmo_sockaddr_str_from_str(&sdp->rtp, addr_str, sdp->rtp.port); |
| 474 | return 0; |
| 475 | } |
| 476 | |
| 477 | /* Parse SDP string into struct sdp_msg. Return 0 on success, negative on error. */ |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 478 | 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] | 479 | { |
| 480 | const char *pos; |
| 481 | *sdp = (struct sdp_msg){}; |
| 482 | |
| 483 | for (pos = src; pos && *pos; pos++) { |
| 484 | char attrib; |
| 485 | int rc = 0; |
| 486 | |
| 487 | if (*pos == '\r' || *pos == '\n') |
| 488 | continue; |
| 489 | |
| 490 | /* Expecting only lines starting with 'X='. Not being too strict about it is probably alright. */ |
| 491 | if (pos[1] != '=') |
| 492 | goto next_line; |
| 493 | |
| 494 | attrib = *pos; |
| 495 | pos += 2; |
| 496 | switch (attrib) { |
| 497 | /* a=... */ |
| 498 | case 'a': |
| 499 | rc = sdp_parse_attrib(sdp, pos); |
| 500 | break; |
| 501 | case 'm': |
| 502 | rc = sdp_parse_media_description(sdp, pos); |
| 503 | break; |
| 504 | case 'c': |
| 505 | rc = sdp_parse_connection_info(sdp, pos); |
| 506 | break; |
| 507 | default: |
| 508 | /* ignore any other parameters */ |
| 509 | break; |
| 510 | } |
| 511 | |
| 512 | if (rc) { |
| 513 | size_t line_len; |
| 514 | const char *line_end = sdp_msg_line_end(pos); |
| 515 | pos -= 2; |
| 516 | line_len = line_end - pos; |
| 517 | switch (rc) { |
| 518 | case -EINVAL: |
| 519 | LOGP(DMNCC, LOGL_ERROR, |
| 520 | "Failed to parse SDP: invalid line: %s\n", osmo_quote_str(pos, line_len)); |
| 521 | break; |
| 522 | case -ENOSPC: |
| 523 | LOGP(DMNCC, LOGL_ERROR, |
| 524 | "Failed to parse SDP: no more space for: %s\n", osmo_quote_str(pos, line_len)); |
| 525 | break; |
| 526 | case -ENOTSUP: |
| 527 | LOGP(DMNCC, LOGL_ERROR, |
| 528 | "Failed to parse SDP: not supported: %s\n", osmo_quote_str(pos, line_len)); |
| 529 | break; |
| 530 | default: |
| 531 | LOGP(DMNCC, LOGL_ERROR, |
| 532 | "Failed to parse SDP: %s\n", osmo_quote_str(pos, line_len)); |
| 533 | break; |
| 534 | } |
| 535 | return rc; |
| 536 | } |
| 537 | next_line: |
| 538 | pos = strstr(pos, "\r\n"); |
| 539 | if (!pos) |
| 540 | break; |
| 541 | } |
| 542 | |
| 543 | return 0; |
| 544 | } |
| 545 | |
| 546 | /* Leave only those codecs in 'ac_dest' that are also present in 'ac_other'. |
Neels Hofmeyr | c9e0ca3 | 2022-01-13 18:28:44 +0100 | [diff] [blame] | 547 | * The matching is made by sdp_audio_codec_cmp(cmp_payload_type=false), i.e. payload_type numbers are not compared and |
| 548 | * fmtp parameters are compared 1:1 as plain strings. |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 549 | * If translate_payload_type_numbers has an effect if ac_dest and ac_other have mismatching payload_type numbers for the |
| 550 | * same SDP codec descriptions. If translate_payload_type_numbers is true, take the payload_type numbers from ac_other. |
| 551 | * If false, keep payload_type numbers in ac_dest unchanged. */ |
| 552 | void sdp_audio_codecs_intersection(struct sdp_audio_codecs *ac_dest, const struct sdp_audio_codecs *ac_other, |
| 553 | bool translate_payload_type_numbers) |
| 554 | { |
| 555 | int i; |
| 556 | for (i = 0; i < ac_dest->count; i++) { |
| 557 | struct sdp_audio_codec *codec = &ac_dest->codec[i]; |
| 558 | struct sdp_audio_codec *other; |
| 559 | OSMO_ASSERT(i < ARRAY_SIZE(ac_dest->codec)); |
| 560 | |
Neels Hofmeyr | d20dd22 | 2022-01-14 00:38:42 +0100 | [diff] [blame] | 561 | other = sdp_audio_codecs_by_descr((struct sdp_audio_codecs *)ac_other, codec); |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 562 | |
| 563 | if (!other) { |
Neels Hofmeyr | d20dd22 | 2022-01-14 00:38:42 +0100 | [diff] [blame] | 564 | OSMO_ASSERT(sdp_audio_codecs_remove(ac_dest, codec) == 0); |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 565 | i--; |
| 566 | continue; |
| 567 | } |
| 568 | |
| 569 | /* Doing payload_type number translation of part of the intersection because it makes the algorithm |
| 570 | * simpler: we already know ac_dest is a subset of ac_other, and there is no need to resolve payload |
| 571 | * type number conflicts. */ |
| 572 | if (translate_payload_type_numbers) |
| 573 | codec->payload_type = other->payload_type; |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | /* Make sure the given codec is listed as the first codec. 'codec' must be an actual codec entry of the given audio |
| 578 | * codecs list. */ |
| 579 | void sdp_audio_codecs_select(struct sdp_audio_codecs *ac, struct sdp_audio_codec *codec) |
| 580 | { |
| 581 | struct sdp_audio_codec tmp; |
| 582 | struct sdp_audio_codec *pos; |
| 583 | OSMO_ASSERT((codec >= ac->codec) |
| 584 | && ((codec - ac->codec) < OSMO_MIN(ac->count, ARRAY_SIZE(ac->codec)))); |
| 585 | |
| 586 | /* Already the first? */ |
| 587 | if (codec == ac->codec) |
| 588 | return; |
| 589 | |
| 590 | tmp = *codec; |
| 591 | for (pos = codec - 1; pos >= ac->codec; pos--) |
| 592 | pos[1] = pos[0]; |
| 593 | |
| 594 | ac->codec[0] = tmp; |
| 595 | return; |
| 596 | } |
| 597 | |
| 598 | /* Short single-line representation of an SDP audio codec, convenient for logging. |
| 599 | * Like "AMR/8000:octet-align=1#122" */ |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 600 | int sdp_audio_codec_to_str_buf(char *buf, size_t buflen, const struct sdp_audio_codec *codec) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 601 | { |
| 602 | struct osmo_strbuf sb = { .buf = buf, .len = buflen }; |
| 603 | OSMO_STRBUF_PRINTF(sb, "%s", codec->subtype_name); |
Neels Hofmeyr | 99ab7c5 | 2022-01-13 19:04:59 +0100 | [diff] [blame] | 604 | if (codec->rate != 8000) |
| 605 | OSMO_STRBUF_PRINTF(sb, "/%u", codec->rate); |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 606 | if (codec->fmtp[0]) |
| 607 | OSMO_STRBUF_PRINTF(sb, ":%s", codec->fmtp); |
Neels Hofmeyr | 99ab7c5 | 2022-01-13 19:04:59 +0100 | [diff] [blame] | 608 | OSMO_STRBUF_PRINTF(sb, "#%d", codec->payload_type); |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 609 | return sb.chars_needed; |
| 610 | } |
| 611 | |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 612 | char *sdp_audio_codec_to_str_c(void *ctx, const struct sdp_audio_codec *codec) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 613 | { |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 614 | OSMO_NAME_C_IMPL(ctx, 32, "sdp_audio_codec_to_str_c-ERROR", sdp_audio_codec_to_str_buf, codec) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 615 | } |
| 616 | |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 617 | 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] | 618 | { |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 619 | return sdp_audio_codec_to_str_c(OTC_SELECT, codec); |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | /* Short single-line representation of a list of SDP audio codecs, convenient for logging */ |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 623 | int sdp_audio_codecs_to_str_buf(char *buf, size_t buflen, const struct sdp_audio_codecs *ac) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 624 | { |
| 625 | struct osmo_strbuf sb = { .buf = buf, .len = buflen }; |
| 626 | const struct sdp_audio_codec *codec; |
| 627 | if (!ac->count) |
| 628 | OSMO_STRBUF_PRINTF(sb, "(no-codecs)"); |
| 629 | foreach_sdp_audio_codec(codec, ac) { |
| 630 | bool first = (codec == ac->codec); |
| 631 | if (!first) |
| 632 | OSMO_STRBUF_PRINTF(sb, ","); |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 633 | OSMO_STRBUF_APPEND(sb, sdp_audio_codec_to_str_buf, codec); |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 634 | } |
| 635 | return sb.chars_needed; |
| 636 | } |
| 637 | |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 638 | char *sdp_audio_codecs_to_str_c(void *ctx, const struct sdp_audio_codecs *ac) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 639 | { |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 640 | OSMO_NAME_C_IMPL(ctx, 128, "sdp_audio_codecs_to_str_c-ERROR", sdp_audio_codecs_to_str_buf, ac) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 641 | } |
| 642 | |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 643 | 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] | 644 | { |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 645 | return sdp_audio_codecs_to_str_c(OTC_SELECT, ac); |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | /* Short single-line representation of an SDP message, convenient for logging */ |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 649 | int sdp_msg_to_str_buf(char *buf, size_t buflen, const struct sdp_msg *sdp) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 650 | { |
| 651 | struct osmo_strbuf sb = { .buf = buf, .len = buflen }; |
| 652 | if (!sdp) { |
| 653 | OSMO_STRBUF_PRINTF(sb, "NULL"); |
| 654 | return sb.chars_needed; |
| 655 | } |
| 656 | |
| 657 | OSMO_STRBUF_PRINTF(sb, OSMO_SOCKADDR_STR_FMT, OSMO_SOCKADDR_STR_FMT_ARGS(&sdp->rtp)); |
| 658 | OSMO_STRBUF_PRINTF(sb, "{"); |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 659 | OSMO_STRBUF_APPEND(sb, sdp_audio_codecs_to_str_buf, &sdp->audio_codecs); |
Oliver Smith | 1063213 | 2023-05-12 12:14:22 +0200 | [diff] [blame] | 660 | if (sdp->bearer_services.count) { |
| 661 | OSMO_STRBUF_PRINTF(sb, ","); |
| 662 | OSMO_STRBUF_APPEND(sb, csd_bs_list_to_str_buf, &sdp->bearer_services); |
| 663 | } |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 664 | OSMO_STRBUF_PRINTF(sb, "}"); |
| 665 | return sb.chars_needed; |
| 666 | } |
| 667 | |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 668 | char *sdp_msg_to_str_c(void *ctx, const struct sdp_msg *sdp) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 669 | { |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 670 | OSMO_NAME_C_IMPL(ctx, 128, "sdp_msg_to_str_c-ERROR", sdp_msg_to_str_buf, sdp) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 671 | } |
| 672 | |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 673 | const char *sdp_msg_to_str(const struct sdp_msg *sdp) |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 674 | { |
Neels Hofmeyr | 9a515e5 | 2022-01-13 20:40:12 +0100 | [diff] [blame] | 675 | return sdp_msg_to_str_c(OTC_SELECT, sdp); |
Neels Hofmeyr | eef4578 | 2019-10-21 03:24:04 +0200 | [diff] [blame] | 676 | } |
Oliver Smith | 1063213 | 2023-05-12 12:14:22 +0200 | [diff] [blame] | 677 | |
| 678 | void sdp_audio_codecs_set_csd(struct sdp_audio_codecs *ac) |
| 679 | { |
| 680 | *ac = (struct sdp_audio_codecs){ |
| 681 | .count = 1, |
| 682 | .codec = {{ |
| 683 | .payload_type = 120, |
| 684 | .subtype_name = "CLEARMODE", |
| 685 | .rate = 8000, |
| 686 | }}, |
| 687 | }; |
| 688 | } |