blob: 4798ae0072a04d43d18295b61158e0715b3f57d3 [file] [log] [blame]
Neels Hofmeyreef45782019-10-21 03:24:04 +02001#include <stdio.h>
2#include <string.h>
3#include <osmocom/core/utils.h>
4#include <osmocom/msc/sdp_msg.h>
5
6struct sdp_test_data {
7 const char *sdp_input;
8 const char *expect_sdp_str;
9};
10
11static void dump_sdp(const char *str, const char *prefix)
12{
13 while (str && *str) {
14 const char *line_end = sdp_msg_line_end(str);
15 while (*line_end == '\r' || *line_end == '\n')
16 line_end++;
17 printf("%s%s\n", prefix, osmo_escape_str(str, line_end - str));
18 str = line_end;
19 }
20}
21
22struct sdp_test_data sdp_tests[] = {
23 {
24 "v=0\r\n"
25 "o=- 5628250 5628250 IN IP4 192.168.11.121\r\n"
26 "s=-\r\n"
27 "c=IN IP4 192.168.11.121\r\n"
28 "t=0 0\r\n"
29 "m=audio 10020 RTP/AVP 18 0 2 4 8 96 97 98 100 101\r\n"
30 "a=rtpmap:18 G729/8000\r\n"
31 "a=rtpmap:0 PCMU/8000\r\n"
32 "a=rtpmap:2 G726-32/8000\r\n"
33 "a=rtpmap:4 G723/8000\r\n"
34 "a=rtpmap:8 PCMA/8000\r\n"
35 "a=rtpmap:96 G726-40/8000\r\n"
36 "a=rtpmap:97 G726-24/8000\r\n"
37 "a=rtpmap:98 G726-16/8000\r\n"
38 "a=rtpmap:100 NSE/8000\r\n"
39 "a=fmtp:100 192-193\r\n"
40 "a=rtpmap:101 telephone-event/8000\r\n"
41 "a=fmtp:101 0-15\r\n"
42 "a=ptime:20\r\n"
43 "a=sendrecv\r\n"
44 ,
45 "v=0\r\n"
46 "o=OsmoMSC 0 0 IN IP4 192.168.11.121\r\n"
47 "s=GSM Call\r\n"
48 "c=IN IP4 192.168.11.121\r\n"
49 "t=0 0\r\n"
50 "m=audio 10020 RTP/AVP 18 0 2 4 8 96 97 98 100 101\r\n"
51 "a=rtpmap:18 G729/8000\r\n"
52 "a=rtpmap:0 PCMU/8000\r\n"
53 "a=rtpmap:2 G726-32/8000\r\n"
54 "a=rtpmap:4 G723/8000\r\n"
55 "a=rtpmap:8 PCMA/8000\r\n"
56 "a=rtpmap:96 G726-40/8000\r\n"
57 "a=rtpmap:97 G726-24/8000\r\n"
58 "a=rtpmap:98 G726-16/8000\r\n"
59 "a=rtpmap:100 NSE/8000\r\n"
60 "a=fmtp:100 192-193\r\n"
61 "a=rtpmap:101 telephone-event/8000\r\n"
62 "a=fmtp:101 0-15\r\n"
63 "a=ptime:20\r\n"
Neels Hofmeyr01431082022-07-19 12:16:02 +020064 "a=sendrecv\r\n"
Neels Hofmeyreef45782019-10-21 03:24:04 +020065 ,
66 },
67 {
68 "v=0\r\n"
69 "o=FooBar 1565090289 1565090290 IN IP4 192.168.11.151\r\n"
70 "s=FooBar\r\n"
71 "c=IN IP4 192.168.11.151\r\n"
72 "t=0 0\r\n"
73 "m=audio 16398 RTP/AVP 98\r\n"
74 "a=rtpmap:98 AMR/8000\r\n"
75 "a=fmtp:98 octet-align=1; mode-set=4\r\n"
76 "a=ptime:20\r\n"
77 "a=rtcp:16399 IN IP4 192.168.11.151\r\n"
78 ,
79 "v=0\r\n"
80 "o=OsmoMSC 0 0 IN IP4 192.168.11.151\r\n"
81 "s=GSM Call\r\n"
82 "c=IN IP4 192.168.11.151\r\n"
83 "t=0 0\r\n"
84 "m=audio 16398 RTP/AVP 98\r\n"
85 "a=rtpmap:98 AMR/8000\r\n"
86 "a=fmtp:98 octet-align=1; mode-set=4\r\n"
87 "a=ptime:20\r\n"
88 ,
89 },
90 {
91 "v=0\r\n"
92 "o=FooBar 1565090289 1565090290 IN IP4 192.168.11.151\r\n"
93 "s=FooBar\r\n"
94 "c=IN IP4 192.168.11.140\r\n"
95 "t=0 0\r\n"
96 "m=audio 30436 RTP/AVP 18 0 4 8 101\r\n"
97 "a=rtpmap:18 G729/8000\r\n"
98 "a=rtpmap:0 PCMU/8000\r\n"
99 "a=rtpmap:4 G723/8000\r\n"
100 "a=rtpmap:8 PCMA/8000\r\n"
101 "a=rtpmap:101 telephone-event/8000\r\n"
102 "a=fmtp:101 0-15\r\n"
103 "a=sendrecv\r\n"
104 "a=rtcp:30437\r\n"
105 "a=ptime:20\r\n"
106 ,
107 "v=0\r\n"
108 "o=OsmoMSC 0 0 IN IP4 192.168.11.140\r\n" /* <- NOTE: loses the 'o=' address, uses only 'c=' */
109 "s=GSM Call\r\n"
110 "c=IN IP4 192.168.11.140\r\n"
111 "t=0 0\r\n"
112 "m=audio 30436 RTP/AVP 18 0 4 8 101\r\n"
113 "a=rtpmap:18 G729/8000\r\n"
114 "a=rtpmap:0 PCMU/8000\r\n"
115 "a=rtpmap:4 G723/8000\r\n"
116 "a=rtpmap:8 PCMA/8000\r\n"
117 "a=rtpmap:101 telephone-event/8000\r\n"
118 "a=fmtp:101 0-15\r\n"
119 "a=ptime:20\r\n"
Neels Hofmeyr01431082022-07-19 12:16:02 +0200120 "a=sendrecv\r\n"
Neels Hofmeyreef45782019-10-21 03:24:04 +0200121 ,
122 },
123};
124
125void test_parse_and_compose()
126{
127 int i;
128 bool ok = true;
129
130 printf("\n\n%s\n", __func__);
131
132 for (i = 0; i < ARRAY_SIZE(sdp_tests); i++) {
133 struct sdp_test_data *t = &sdp_tests[i];
134 struct sdp_msg sdp = {};
135 char str[1024];
136 printf("\n[%d]\n", i);
137 dump_sdp(t->sdp_input, "sdp input: ");
138
Neels Hofmeyr7a5c8b52023-03-13 04:45:09 +0100139 OSMO_ASSERT(sdp_msg_from_sdp_str(&sdp, t->sdp_input) == 0);
Neels Hofmeyr9a515e52022-01-13 20:40:12 +0100140 sdp_msg_to_sdp_str_buf(str, sizeof(str), &sdp);
Neels Hofmeyreef45782019-10-21 03:24:04 +0200141
Neels Hofmeyr9a515e52022-01-13 20:40:12 +0100142 dump_sdp(str, "sdp_msg_to_sdp_str_buf: ");
Neels Hofmeyreef45782019-10-21 03:24:04 +0200143 if (strcmp(str, t->expect_sdp_str)) {
144 int j;
145 ok = false;
146 printf("ERROR:\n");
147 dump_sdp(t->expect_sdp_str, "expect_sdp_str: ");
148 for (j = 0; t->expect_sdp_str[j]; j++) {
149 if (t->expect_sdp_str[j] != str[j]) {
150 printf("ERROR at position %d, at:\n", j);
151 dump_sdp(str + j, " mismatch: ");
152 break;
153 }
154 }
155 } else
156 printf("[%d] ok\n", i);
157 }
158
159 OSMO_ASSERT(ok);
160}
161
162struct sdp_intersect_test_data {
163 const char *descr;
164 const char *sdp_a;
165 const char *sdp_b;
166 const char *expect_intersection;
167};
168
169#define SDP_1 \
170 "v=0\r\n" \
171 "o=OsmoMSC 0 0 IN IP4 23.42.23.42\r\n" \
172 "s=GSM Call\r\n" \
173 "c=IN IP4 23.42.23.42\r\n" \
174 "t=0 0\r\n" \
175 "m=audio 30436 RTP/AVP 112 3 111 110\r\n" \
176 "a=rtpmap:112 AMR/8000\r\n" \
177 "a=fmtp:112 octet-align=1\r\n" \
178 "a=rtpmap:3 GSM/8000\r\n" \
179 "a=rtpmap:111 GSM-HR-08/8000\r\n" \
180 "a=rtpmap:110 GSM-EFR/8000\r\n" \
181 "a=ptime:20\r\n"
182
183#define SDP_2 \
184 "v=0\r\n" \
185 "o=OsmoMSC 0 0 IN IP4 23.42.23.42\r\n" \
186 "s=GSM Call\r\n" \
187 "c=IN IP4 23.42.23.42\r\n" \
188 "t=0 0\r\n" \
189 "m=audio 30436 RTP/AVP 112 110\r\n" \
190 "a=rtpmap:112 AMR/8000\r\n" \
191 "a=fmtp:112 octet-align=1\r\n" \
192 "a=rtpmap:110 GSM-EFR/8000\r\n" \
193 "a=ptime:20\r\n"
194
195#define SDP_3 \
196 "v=0\r\n" \
197 "o=OsmoMSC 0 0 IN IP4 23.42.23.42\r\n" \
198 "s=GSM Call\r\n" \
199 "c=IN IP4 23.42.23.42\r\n" \
200 "t=0 0\r\n" \
201 "m=audio 30436 RTP/AVP 3 111\r\n" \
202 "a=rtpmap:3 GSM/8000\r\n" \
203 "a=rtpmap:111 GSM-HR-08/8000\r\n" \
204 "a=ptime:20\r\n"
205
206
207struct sdp_intersect_test_data sdp_intersect_tests[] = {
208 {
209 "identical codecs lead to no change"
210 ,
211 SDP_1
212 ,
213 "c=IN IP4 5.6.7.8\r\n" \
214 "m=audio 12345 RTP/AVP 112 3 111 110\r\n"
215 "a=rtpmap:112 AMR/8000\r\n"
216 "a=fmtp:112 octet-align=1\r\n"
217 "a=rtpmap:3 GSM/8000\r\n"
218 "a=rtpmap:111 GSM-HR-08/8000\r\n"
219 "a=rtpmap:110 GSM-EFR/8000\r\n"
220 ,
221 SDP_1
222 },
223 {
224 "identical codecs in different order also lead to no change"
225 ,
226 SDP_1
227 ,
228 "c=IN IP4 5.6.7.8\r\n" \
229 "m=audio 12345 RTP/AVP 3 110 111 112\r\n"
230 "a=rtpmap:3 GSM/8000\r\n"
231 "a=rtpmap:110 GSM-EFR/8000\r\n"
232 "a=rtpmap:111 GSM-HR-08/8000\r\n"
233 "a=rtpmap:112 AMR/8000\r\n"
234 "a=fmtp:112 octet-align=1\r\n"
235 ,
236 SDP_1
237 },
238 {
239 "identical codecs with mismatching payload type numbers also lead to no change"
240 ,
241 SDP_1
242 ,
243 "c=IN IP4 5.6.7.8\r\n" \
244 "m=audio 12345 RTP/AVP 96 97 98 99\r\n"
245 "a=rtpmap:96 GSM/8000\r\n"
246 "a=rtpmap:97 GSM-EFR/8000\r\n"
247 "a=rtpmap:98 GSM-HR-08/8000\r\n"
248 "a=rtpmap:99 AMR/8000\r\n"
249 "a=fmtp:99 octet-align=1\r\n"
250 ,
251 SDP_1
252 },
253 {
254 "identical codecs plus some extra codecs also lead to no change"
255 ,
256 SDP_1
257 ,
258 "c=IN IP4 5.6.7.8\r\n" \
259 "m=audio 12345 RTP/AVP 8 0 96 97 98 99\r\n"
260 "a=rtpmap:8 PCMA/8000\r\n"
261 "a=rtpmap:0 PCMU/8000\r\n"
262 "a=rtpmap:96 GSM/8000\r\n"
263 "a=rtpmap:97 GSM-EFR/8000\r\n"
264 "a=rtpmap:98 GSM-HR-08/8000\r\n"
265 "a=rtpmap:99 AMR/8000\r\n"
266 "a=fmtp:99 octet-align=1\r\n"
267 ,
268 SDP_1
269 },
270 {
271 "some codecs removed",
272 SDP_1,
273 SDP_2,
274 SDP_2,
275 },
276 {
277 "other codecs removed",
278 SDP_1,
279 SDP_3,
280 SDP_3,
281 },
282 {
283 "all codecs removed",
284 SDP_1
285 ,
286 "s=empty"
287 ,
288 "v=0\r\n" \
289 "o=OsmoMSC 0 0 IN IP4 23.42.23.42\r\n" \
290 "s=GSM Call\r\n" \
291 "c=IN IP4 23.42.23.42\r\n" \
292 "t=0 0\r\n" \
293 "m=audio 30436 RTP/AVP\r\n" \
294 "a=ptime:20\r\n"
295 },
296 {
297 "some real world test case"
298 ,
299 "v=0\r\n"
300 "o=OsmoMSC 0 0 IN IP4 0.0.0.0\r\n"
301 "s=GSM Call\r\n"
302 "c=IN IP4 0.0.0.0\r\n"
303 "t=0 0\r\n"
304 "m=audio 0 RTP/AVP 112 113 110 3 111\r\n"
305 "a=rtpmap:112 AMR/8000\r\n"
306 "a=fmtp:112 octet-align=1;mode-set=0,1,2,3\r\n"
307 "a=rtpmap:113 AMR-WB/8000\r\n"
308 "a=fmtp:113 octet-align=1\r\n"
309 "a=rtpmap:110 GSM-EFR/8000\r\n"
310 "a=rtpmap:3 GSM/8000\r\n"
311 "a=rtpmap:111 GSM-HR-08/8000\r\n"
312 "a=ptime:20\r\n"
313 ,
314 "v=0\r\n"
315 "o=OsmoMSC 0 0 IN IP4 0.0.0.0\r\n"
316 "s=GSM Call\r\n"
317 "c=IN IP4 0.0.0.0\r\n"
318 "t=0 0\r\n"
319 "m=audio 0 RTP/AVP 112 113 110 3 111\r\n"
320 "a=rtpmap:112 AMR/8000\r\n"
321 "a=fmtp:112 octet-align=1;mode-set=0,1,2,3\r\n"
322 "a=rtpmap:113 AMR-WB/8000\r\n"
323 "a=fmtp:113 octet-align=1\r\n"
324 "a=rtpmap:110 GSM-EFR/8000\r\n"
325 "a=rtpmap:3 GSM/8000\r\n"
326 "a=rtpmap:111 GSM-HR-08/8000\r\n"
327 "a=ptime:20\r\n"
328 ,
329 "v=0\r\n"
330 "o=OsmoMSC 0 0 IN IP4 0.0.0.0\r\n"
331 "s=GSM Call\r\n"
332 "c=IN IP4 0.0.0.0\r\n"
333 "t=0 0\r\n"
334 "m=audio 0 RTP/AVP 112 113 110 3 111\r\n"
335 "a=rtpmap:112 AMR/8000\r\n"
336 "a=fmtp:112 octet-align=1;mode-set=0,1,2,3\r\n"
337 "a=rtpmap:113 AMR-WB/8000\r\n"
338 "a=fmtp:113 octet-align=1\r\n"
339 "a=rtpmap:110 GSM-EFR/8000\r\n"
340 "a=rtpmap:3 GSM/8000\r\n"
341 "a=rtpmap:111 GSM-HR-08/8000\r\n"
342 "a=ptime:20\r\n"
343 }
344};
345
346const char *sdp_msg_logstr(const struct sdp_msg *sdp)
347{
348 static char buf[1024];
Neels Hofmeyr9a515e52022-01-13 20:40:12 +0100349 sdp_msg_to_sdp_str_buf(buf, sizeof(buf), sdp);
Neels Hofmeyreef45782019-10-21 03:24:04 +0200350 return buf;
351}
352
353static void test_intersect()
354{
355 int i;
356 bool ok = true;
357 int rc;
358
359 printf("\n\n%s\n", __func__);
360
361 for (i = 0; i < ARRAY_SIZE(sdp_intersect_tests); i++) {
362 struct sdp_intersect_test_data *t = &sdp_intersect_tests[i];
363 struct sdp_msg sdp_a = {};
364 struct sdp_msg sdp_b = {};
365 char str[1024];
366 printf("\n[%d] %s\n", i, t->descr);
367 dump_sdp(t->sdp_a, "SDP A: ");
368 dump_sdp(t->sdp_b, " SDP B: ");
369
Neels Hofmeyr9a515e52022-01-13 20:40:12 +0100370 rc = sdp_msg_from_sdp_str(&sdp_a, t->sdp_a);
Neels Hofmeyreef45782019-10-21 03:24:04 +0200371 if (rc) {
372 printf("ERROR parsing SDP A: %d\n", rc);
373 break;
374 }
375 dump_sdp(sdp_msg_logstr(&sdp_a), "parsed SDP A: ");
Neels Hofmeyr9a515e52022-01-13 20:40:12 +0100376 rc = sdp_msg_from_sdp_str(&sdp_b, t->sdp_b);
Neels Hofmeyreef45782019-10-21 03:24:04 +0200377 if (rc) {
378 printf("ERROR parsing SDP A: %d\n", rc);
379 break;
380 }
381 dump_sdp(sdp_msg_logstr(&sdp_b), "parsed SDP B: ");
382 sdp_audio_codecs_intersection(&sdp_a.audio_codecs, &sdp_b.audio_codecs, false);
Neels Hofmeyr9a515e52022-01-13 20:40:12 +0100383 sdp_msg_to_sdp_str_buf(str, sizeof(str), &sdp_a);
Neels Hofmeyreef45782019-10-21 03:24:04 +0200384
385 dump_sdp(str, "sdp_msg_intersection(a,b): ");
386 if (strcmp(str, t->expect_intersection)) {
387 int j;
388 ok = false;
389 printf("ERROR:\n");
390 dump_sdp(t->expect_intersection, "expect_intersection: ");
391 for (j = 0; t->expect_intersection[j]; j++) {
392 if (t->expect_intersection[j] != str[j]) {
393 printf("ERROR at position %d, at:\n", j);
394 dump_sdp(str + j, " mismatch: ");
395 break;
396 }
397 }
398 } else
399 printf("[%d] ok\n", i);
400 }
401
402 OSMO_ASSERT(ok);
403}
404
405struct sdp_select_test_data {
406 const char *sdp;
407 unsigned int select_payload_type;
408 const char *expect_sdp;
409};
410
411struct sdp_select_test_data sdp_select_tests[] = {
412 {
413 "v=0\r\n"
414 "o=OsmoMSC 0 0 IN IP4 23.42.23.42\r\n"
415 "s=GSM Call\r\n"
416 "c=IN IP4 23.42.23.42\r\n"
417 "t=0 0\r\n"
418 "m=audio 30436 RTP/AVP 112 3 111 110\r\n"
419 "a=rtpmap:112 AMR/8000\r\n"
420 "a=fmtp:112 octet-align=1\r\n"
421 "a=rtpmap:3 GSM/8000\r\n"
422 "a=rtpmap:111 GSM-HR-08/8000\r\n"
423 "a=rtpmap:110 GSM-EFR/8000\r\n"
424 "a=ptime:20\r\n"
425 ,
426 112,
427 NULL
428 },
429 {
430 "v=0\r\n"
431 "o=OsmoMSC 0 0 IN IP4 23.42.23.42\r\n"
432 "s=GSM Call\r\n"
433 "c=IN IP4 23.42.23.42\r\n"
434 "t=0 0\r\n"
435 "m=audio 30436 RTP/AVP 112 3 111 110\r\n"
436 "a=rtpmap:112 AMR/8000\r\n"
437 "a=fmtp:112 octet-align=1\r\n"
438 "a=rtpmap:3 GSM/8000\r\n"
439 "a=rtpmap:111 GSM-HR-08/8000\r\n"
440 "a=rtpmap:110 GSM-EFR/8000\r\n"
441 "a=ptime:20\r\n"
442 ,
443 3,
444 "v=0\r\n"
445 "o=OsmoMSC 0 0 IN IP4 23.42.23.42\r\n"
446 "s=GSM Call\r\n"
447 "c=IN IP4 23.42.23.42\r\n"
448 "t=0 0\r\n"
449 "m=audio 30436 RTP/AVP 3 112 111 110\r\n"
450 "a=rtpmap:3 GSM/8000\r\n"
451 "a=rtpmap:112 AMR/8000\r\n"
452 "a=fmtp:112 octet-align=1\r\n"
453 "a=rtpmap:111 GSM-HR-08/8000\r\n"
454 "a=rtpmap:110 GSM-EFR/8000\r\n"
455 "a=ptime:20\r\n"
456 },
457 {
458 "v=0\r\n"
459 "o=OsmoMSC 0 0 IN IP4 23.42.23.42\r\n"
460 "s=GSM Call\r\n"
461 "c=IN IP4 23.42.23.42\r\n"
462 "t=0 0\r\n"
463 "m=audio 30436 RTP/AVP 112 3 111 110\r\n"
464 "a=rtpmap:112 AMR/8000\r\n"
465 "a=fmtp:112 octet-align=1\r\n"
466 "a=rtpmap:3 GSM/8000\r\n"
467 "a=rtpmap:111 GSM-HR-08/8000\r\n"
468 "a=rtpmap:110 GSM-EFR/8000\r\n"
469 "a=ptime:20\r\n"
470 ,
471 111,
472 "v=0\r\n"
473 "o=OsmoMSC 0 0 IN IP4 23.42.23.42\r\n"
474 "s=GSM Call\r\n"
475 "c=IN IP4 23.42.23.42\r\n"
476 "t=0 0\r\n"
477 "m=audio 30436 RTP/AVP 111 112 3 110\r\n"
478 "a=rtpmap:111 GSM-HR-08/8000\r\n"
479 "a=rtpmap:112 AMR/8000\r\n"
480 "a=fmtp:112 octet-align=1\r\n"
481 "a=rtpmap:3 GSM/8000\r\n"
482 "a=rtpmap:110 GSM-EFR/8000\r\n"
483 "a=ptime:20\r\n"
484 },
485 {
486 "v=0\r\n"
487 "o=OsmoMSC 0 0 IN IP4 23.42.23.42\r\n"
488 "s=GSM Call\r\n"
489 "c=IN IP4 23.42.23.42\r\n"
490 "t=0 0\r\n"
491 "m=audio 30436 RTP/AVP 112 3 111 110\r\n"
492 "a=rtpmap:112 AMR/8000\r\n"
493 "a=fmtp:112 octet-align=1\r\n"
494 "a=rtpmap:3 GSM/8000\r\n"
495 "a=rtpmap:111 GSM-HR-08/8000\r\n"
496 "a=rtpmap:110 GSM-EFR/8000\r\n"
497 "a=ptime:20\r\n"
498 ,
499 110,
500 "v=0\r\n"
501 "o=OsmoMSC 0 0 IN IP4 23.42.23.42\r\n"
502 "s=GSM Call\r\n"
503 "c=IN IP4 23.42.23.42\r\n"
504 "t=0 0\r\n"
505 "m=audio 30436 RTP/AVP 110 112 3 111\r\n"
506 "a=rtpmap:110 GSM-EFR/8000\r\n"
507 "a=rtpmap:112 AMR/8000\r\n"
508 "a=fmtp:112 octet-align=1\r\n"
509 "a=rtpmap:3 GSM/8000\r\n"
510 "a=rtpmap:111 GSM-HR-08/8000\r\n"
511 "a=ptime:20\r\n"
512 },
513
514};
515
516static void test_select()
517{
518 int i;
519 bool ok = true;
520 int rc;
521
522 printf("\n\n%s\n", __func__);
523
524 for (i = 0; i < ARRAY_SIZE(sdp_select_tests); i++) {
525 struct sdp_select_test_data *t = &sdp_select_tests[i];
526 struct sdp_msg sdp = {};
527 struct sdp_audio_codec *codec;
528 char buf[1024];
Oliver Smithd0980a42023-06-22 11:55:08 +0200529 const char *expect_sdp;
530
Neels Hofmeyreef45782019-10-21 03:24:04 +0200531 printf("\n[%d]\n", i);
Neels Hofmeyr9a515e52022-01-13 20:40:12 +0100532 rc = sdp_msg_from_sdp_str(&sdp, t->sdp);
Neels Hofmeyreef45782019-10-21 03:24:04 +0200533 if (rc) {
534 printf("ERROR parsing SDP: %d\n", rc);
535 break;
536 }
Neels Hofmeyr9a515e52022-01-13 20:40:12 +0100537 printf("SDP: %s\n", sdp_audio_codecs_to_str(&sdp.audio_codecs));
Neels Hofmeyrd20dd222022-01-14 00:38:42 +0100538 codec = sdp_audio_codecs_by_payload_type(&sdp.audio_codecs, t->select_payload_type, false);
Neels Hofmeyreef45782019-10-21 03:24:04 +0200539 OSMO_ASSERT(codec);
Neels Hofmeyr9a515e52022-01-13 20:40:12 +0100540 printf("Select: %s\n", sdp_audio_codec_to_str(codec));
Neels Hofmeyreef45782019-10-21 03:24:04 +0200541
542 sdp_audio_codecs_select(&sdp.audio_codecs, codec);
543
Neels Hofmeyr9a515e52022-01-13 20:40:12 +0100544 printf("SDP: %s\n", sdp_audio_codecs_to_str(&sdp.audio_codecs));
545 sdp_msg_to_sdp_str_buf(buf, sizeof(buf), &sdp);
Neels Hofmeyreef45782019-10-21 03:24:04 +0200546
Oliver Smithd0980a42023-06-22 11:55:08 +0200547 expect_sdp = t->expect_sdp ? : t->sdp;
548 if (strcmp(buf, expect_sdp)) {
Neels Hofmeyreef45782019-10-21 03:24:04 +0200549 int j;
550 ok = false;
551 printf("ERROR:\n");
552 dump_sdp(buf, "selection result: ");
Oliver Smithd0980a42023-06-22 11:55:08 +0200553 dump_sdp(expect_sdp, "expect result: ");
554 for (j = 0; expect_sdp[j]; j++) {
555 if (expect_sdp[j] != buf[j]) {
Neels Hofmeyreef45782019-10-21 03:24:04 +0200556 printf("ERROR at position %d, at:\n", j);
557 dump_sdp(buf + j, " mismatch: ");
558 break;
559 }
560 }
561 } else
562 printf("[%d] ok\n", i);
563 }
564
565 OSMO_ASSERT(ok);
566}
567
568int main(void)
569{
570 test_parse_and_compose();
571 test_intersect();
572 test_select();
573 return 0;
574}