1 /* GStreamer unit tests for the SDP support library
2 *
3 * Copyright (C) 2013 Jose Antonio Santos Cadenas <santoscadenas@gmail.com>
4 * Copyright (C) 2013 Kurento
5 * Contact: Miguel París Díaz <mparisdiaz@gmail.com>
6 * Contact: José Antonio Santos Cadenas <santoscadenas@kurento.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <gst/check/gstcheck.h>
29 #include <gst/sdp/gstsdpmessage.h>
30
31 /* *INDENT-OFF* */
32 static const gchar *sdp = "v=0\r\n"
33 "o=- 123456 0 IN IP4 127.0.0.1\r\n"
34 "s=TestSessionToCopy\r\n"
35 "c=IN IP4 127.0.0.1\r\n"
36 "t=0 0\r\n"
37 "a=sendrecv\r\n"
38 "m=video 3434 RTP/AVP 96 97 99\r\n"
39 "a=rtpmap:96 MP4V-ES/90000\r\n"
40 "a=rtpmap:97 H263-1998/90000\r\n"
41 "a=rtpmap:99 H263/90000\r\n"
42 "a=sendrecv\r\n"
43 "m=video 6565 RTP/AVP 98\r\n"
44 "a=rtpmap:98 VP8/90000\r\n"
45 "a=sendrecv\r\n"
46 "m=audio 4545 RTP/AVP 14\r\n"
47 "a=sendrecv\r\n"
48 "m=audio 1010 TCP 14\r\n";
49
50 static const gchar *h264_sdp = "v=0\r\n"
51 "o=- 992782775729845470 2 IN IP4 127.0.0.1\r\n"
52 "s=TestH264\r\n"
53 "t=0 0\r\n"
54 "m=video 9 UDP/TLS/RTP/SAVPF 96\r\n"
55 "c=IN IP4 0.0.0.0\r\n"
56 "a=recvonly\r\n"
57 "a=rtpmap:96 H264/90000\r\n"
58 "a=fmtp:96 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f\r\n";
59
60 static const gchar caps_video_string1[] =
61 "application/x-unknown, media=(string)video, payload=(int)96, "
62 "clock-rate=(int)90000, encoding-name=(string)MP4V-ES";
63
64 static const gchar caps_video_string2[] =
65 "application/x-unknown, media=(string)video, payload=(int)97, "
66 "clock-rate=(int)90000, encoding-name=(string)H263-1998";
67
68 static const gchar caps_audio_string[] =
69 "application/x-unknown, media=(string)audio, payload=(int)14, "
70 "clock-rate=(int)90000";
71
72 static const gchar * sdp_rtcp_fb = "v=0\r\n"
73 "o=- 123456 2 IN IP4 127.0.0.1 \r\n"
74 "s=-\r\n"
75 "t=0 0\r\n"
76 "a=maxptime:60\r\n"
77 "a=sendrecv\r\n"
78 "m=video 1 UDP/TLS/RTP/SAVPF 100 101 102\r\n"
79 "c=IN IP4 1.1.1.1\r\n"
80 "a=rtpmap:100 VP8/90000\r\n"
81 "a=rtcp-fb:100 nack\r\n"
82 "a=rtcp-fb:100 nack pli\r\n"
83 "a=rtcp-fb:100 ccm fir\r\n"
84 "a=rtpmap:101 VP9/90000\r\n"
85 "a=rtcp-fb:101 nack pli\r\n"
86 "a=rtpmap:102 H264/90000\r\n"
87 "a=rtcp-fb:102 ccm fir\r\n"; /* incorrect spacing */
88
89 static const gchar caps_video_rtcp_fb_pt_100[] =
90 "application/x-unknown, media=(string)video, payload=(int)100, "
91 "clock-rate=(int)90000, encoding-name=(string)VP8, "
92 "rtcp-fb-ccm-fir=(boolean)true, rtcp-fb-nack=(boolean)true, "
93 "rtcp-fb-nack-pli=(boolean)true";
94
95 static const gchar caps_video_rtcp_fb_pt_101[] =
96 "application/x-unknown, media=(string)video, payload=(int)101, "
97 "clock-rate=(int)90000, encoding-name=(string)VP9, "
98 "rtcp-fb-nack-pli=(boolean)true";
99
100 static const gchar caps_video_rtcp_fb_pt_102[] =
101 "application/x-unknown, media=(string)video, payload=(int)102, "
102 "clock-rate=(int)90000, encoding-name=(string)H264, "
103 "rtcp-fb-ccm-fir=(boolean)true";
104
105 static const gchar *sdp_rtcp_fb_all = "v=0\r\n"
106 "o=- 123456 2 IN IP4 127.0.0.1 \r\n"
107 "s=-\r\n"
108 "t=0 0\r\n"
109 "a=maxptime:60\r\n"
110 "a=sendrecv\r\n"
111 "m=video 1 UDP/TLS/RTP/SAVPF 100 101 102\r\n"
112 "c=IN IP4 1.1.1.1\r\n"
113 "a=rtpmap:100 VP8/90000\r\n"
114 "a=rtcp-fb:* nack\r\n"
115 "a=rtcp-fb:* nack pli\r\n"
116 "a=rtcp-fb:100 ccm fir\r\n"
117 "a=rtpmap:101 VP9/90000\r\n"
118 "a=rtcp-fb:101 ccm fir\r\n"
119 "a=rtpmap:102 H264/90000\r\n";
120
121 static const gchar caps_video_rtcp_fb_all_pt_100[] =
122 "application/x-unknown, media=(string)video, payload=(int)100, "
123 "clock-rate=(int)90000, encoding-name=(string)VP8, "
124 "rtcp-fb-ccm-fir=(boolean)true, rtcp-fb-nack=(boolean)true, "
125 "rtcp-fb-nack-pli=(boolean)true";
126
127 static const gchar caps_video_rtcp_fb_all_pt_101[] =
128 "application/x-unknown, media=(string)video, payload=(int)101, "
129 "clock-rate=(int)90000, encoding-name=(string)VP9, "
130 "rtcp-fb-ccm-fir=(boolean)true, rtcp-fb-nack=(boolean)true, "
131 "rtcp-fb-nack-pli=(boolean)true";
132
133 static const gchar caps_video_rtcp_fb_all_pt_102[] =
134 "application/x-unknown, media=(string)video, payload=(int)102, "
135 "clock-rate=(int)90000, encoding-name=(string)H264, "
136 "rtcp-fb-nack=(boolean)true, rtcp-fb-nack-pli=(boolean)true";
137
138 static const gchar * sdp_extmap = "v=0\r\n"
139 "o=- 123456 2 IN IP4 127.0.0.1 \r\n"
140 "s=-\r\n"
141 "t=0 0\r\n"
142 "a=maxptime:60\r\n"
143 "a=sendrecv\r\n"
144 "m=video 1 UDP/TLS/RTP/SAVPF 100 101 102\r\n"
145 "c=IN IP4 1.1.1.1\r\n"
146 "a=rtpmap:100 VP8/90000\r\n"
147 "a=extmap:2 urn:ietf:params:rtp-hdrext:toffset\r\n"
148 "a=extmap:3/recvonly http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\n"
149 "a=extmap:4 urn:3gpp:video-orientation attributes\r\n";
150
151 static const gchar caps_video_extmap_pt_100[] =
152 "application/x-unknown, media=(string)video, payload=(int)100, "
153 "clock-rate=(int)90000, encoding-name=(string)VP8, "
154 "extmap-2=urn:ietf:params:rtp-hdrext:toffset, "
155 "extmap-3=(string)<\"recvonly\",\"http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\",\"\">, "
156 "extmap-4=(string)<\"\",\"urn:3gpp:video-orientation\",\"attributes\">";
157
158 static const gchar * sdp_fmtp = "v=0\r\n"
159 "o=ali 1122334455 1122334466 IN IP4 fec.example.com\r\n"
160 "s=Raptor RTP FEC Example\r\n"
161 "t=0 0\r\n"
162 "a=group:FEC-FR S1 R1\r\n"
163 "m=video 30000 RTP/AVP 100\r\n"
164 "c=IN IP4 233.252.0.1/127\r\n"
165 "a=rtpmap:100 MP2T/90000\r\n"
166 "a=fec-source-flow: id=0\r\n"
167 "a=mid:S1\r\n"
168 "m=application 30000 RTP/AVP 110\r\n"
169 "c=IN IP4 233.252.0.2/127\r\n"
170 "a=rtpmap:110 raptorfec/90000\r\n"
171 "a=fmtp:110 raptor-scheme-id=1; Kmax=8192; T=128; P=A; repair-window=200000\r\n"
172 "a=mid:R1\r\n";
173
174 static const gchar caps_video_raptor_fec_pt_100[] =
175 "application/x-unknown, media=(string)video, payload=(int)100, "
176 "clock-rate=(int)90000, encoding-name=(string)MP2T, "
177 "a-fec-source-flow=(string)\"\\ id\\=0\", a-mid=(string)S1";
178
179 static const gchar caps_application_raptor_fec_pt_110[] =
180 "application/x-unknown, media=(string)application, payload=(int)110, "
181 "clock-rate=(int)90000, encoding-name=(string)RAPTORFEC, "
182 "raptor-scheme-id=(string)1, kmax=(string)8192, t=(string)128, p=(string)A, repair-window=(string)200000, "
183 "a-mid=(string)R1";
184
185
186 /* *INDENT-ON* */
187
GST_START_TEST(boxed)188 GST_START_TEST (boxed)
189 {
190 GValue value = G_VALUE_INIT;
191 GValue value_copy = G_VALUE_INIT;
192 GstSDPMessage *message, *copy;
193 gchar *message1_str, *message2_str, *copy_str;
194 const gchar *repeat1[] = { "789", "012", NULL };
195
196 gst_sdp_message_new (&message);
197 gst_sdp_message_parse_buffer ((guint8 *) sdp, -1, message);
198
199 gst_sdp_message_add_time (message, "123", "456", repeat1);
200
201 g_value_init (&value, GST_TYPE_SDP_MESSAGE);
202 g_value_init (&value_copy, GST_TYPE_SDP_MESSAGE);
203
204 g_value_set_boxed (&value, message);
205 message1_str = gst_sdp_message_as_text (message);
206 GST_DEBUG ("message1:\n%s", message1_str);
207 gst_sdp_message_free (message);
208
209 message = g_value_get_boxed (&value);
210 message2_str = gst_sdp_message_as_text (message);
211 GST_DEBUG ("message2:\n%s", message2_str);
212
213 fail_if (g_strcmp0 (message1_str, message2_str) != 0);
214
215 g_value_copy (&value, &value_copy);
216 g_value_reset (&value);
217
218 copy = g_value_dup_boxed (&value_copy);
219 g_value_reset (&value_copy);
220
221 copy_str = gst_sdp_message_as_text (copy);
222 gst_sdp_message_free (copy);
223 GST_DEBUG ("copy:\n%s", copy_str);
224
225 fail_if (g_strcmp0 (message1_str, copy_str));
226
227 g_free (message1_str);
228 g_free (message2_str);
229 g_free (copy_str);
230 }
231
232 GST_END_TEST
GST_START_TEST(copy)233 GST_START_TEST (copy)
234 {
235 GstSDPMessage *message, *copy;
236 glong length = -1;
237 gchar *message_str, *copy_str;
238 const gchar *repeat1[] = { "789", "012", NULL };
239 const gchar *repeat2[] = { "987", "210", NULL };
240
241 gst_sdp_message_new (&message);
242 gst_sdp_message_parse_buffer ((guint8 *) sdp, length, message);
243
244 gst_sdp_message_add_time (message, "123", "456", repeat1);
245 gst_sdp_message_add_time (message, "321", "654", repeat2);
246
247 gst_sdp_message_copy (message, ©);
248
249 message_str = gst_sdp_message_as_text (message);
250 GST_DEBUG ("Original:\n%s", message_str);
251 gst_sdp_message_free (message);
252 copy_str = gst_sdp_message_as_text (copy);
253 gst_sdp_message_free (copy);
254 GST_DEBUG ("Copy:\n%s", copy_str);
255
256 fail_if (g_strcmp0 (copy_str, message_str) != 0);
257 g_free (copy_str);
258 g_free (message_str);
259 }
260
261 GST_END_TEST
GST_START_TEST(modify)262 GST_START_TEST (modify)
263 {
264 GstSDPMessage *message;
265 glong length = -1;
266 const GstSDPMedia *media;
267 const gchar *old_val;
268 const gchar *result;
269 GstSDPAttribute attr;
270
271 gst_sdp_message_new (&message);
272 gst_sdp_message_parse_buffer ((guint8 *) sdp, length, message);
273
274 /* modify session attribute */
275 fail_unless (gst_sdp_message_add_attribute (message,
276 "test_attr_session", "param1=val1") == GST_SDP_OK);
277
278 old_val = gst_sdp_message_get_attribute_val (message, "test_attr_session");
279
280 fail_unless (old_val != NULL);
281 attr.key = g_strdup ("test_attr_session");
282 attr.value = g_strdup_printf ("%s;param2=val2", old_val);
283
284 fail_unless (gst_sdp_message_replace_attribute (message, 0,
285 &attr) == GST_SDP_OK);
286
287 result = gst_sdp_message_get_attribute_val (message, "test_attr_session");
288 fail_unless (result != NULL);
289 fail_unless (g_strcmp0 (result, "param1=val1;param2=val2") == 0);
290
291
292 /* modify media attribute */
293 media = gst_sdp_message_get_media (message, 0);
294 fail_unless (media != NULL);
295
296 fail_unless (gst_sdp_media_add_attribute ((GstSDPMedia *) media,
297 "test_attr_media", "param3=val3") == GST_SDP_OK);
298
299 old_val =
300 gst_sdp_media_get_attribute_val ((GstSDPMedia *) media,
301 "test_attr_media");
302
303 fail_unless (old_val != NULL);
304 attr.key = g_strdup ("test_attr_media");
305 attr.value = g_strdup ("myparam=myval");
306
307 fail_unless (gst_sdp_media_replace_attribute ((GstSDPMedia *) media,
308 0, &attr) == GST_SDP_OK);
309
310 result =
311 gst_sdp_media_get_attribute_val ((GstSDPMedia *) media,
312 "test_attr_media");
313 fail_unless (result != NULL);
314 fail_unless (g_strcmp0 (result, "myparam=myval") == 0);
315
316 gst_sdp_message_free (message);
317 }
318
319 GST_END_TEST
GST_START_TEST(null)320 GST_START_TEST (null)
321 {
322 GstSDPMessage *message;
323 const GstSDPMedia *media;
324 glong length = -1;
325 const gchar *val;
326
327 gst_sdp_message_new (&message);
328 gst_sdp_message_parse_buffer ((guint8 *) sdp, length, message);
329
330 fail_unless (gst_sdp_message_add_attribute (message,
331 "test_attr_session", NULL) == GST_SDP_OK);
332
333 val = gst_sdp_message_get_attribute_val (message, "test_attr_session");
334 fail_unless (val == NULL);
335
336 media = gst_sdp_message_get_media (message, 0);
337
338 fail_unless (gst_sdp_media_add_attribute ((GstSDPMedia *) media,
339 "test_attr_media", NULL) == GST_SDP_OK);
340
341 val = gst_sdp_media_get_attribute_val (media, "test_attr_media");
342 fail_unless (val == NULL);
343
344 gst_sdp_message_free (message);
345 }
346
347 GST_END_TEST
GST_START_TEST(caps_from_media)348 GST_START_TEST (caps_from_media)
349 {
350 GstSDPMessage *message;
351 glong length = -1;
352 const GstSDPMedia *media1, *media2, *media3;
353 GstCaps *caps_video1, *caps_video2, *caps_audio;
354 GstCaps *result_video1, *result_video2, *result_audio;
355
356 gst_sdp_message_new (&message);
357 gst_sdp_message_parse_buffer ((guint8 *) sdp, length, message);
358
359 media1 = gst_sdp_message_get_media (message, 0);
360 fail_unless (media1 != NULL);
361
362 media2 = gst_sdp_message_get_media (message, 1);
363 fail_unless (media2 != NULL);
364
365 media3 = gst_sdp_message_get_media (message, 2);
366 fail_unless (media2 != NULL);
367
368 caps_video1 = gst_sdp_media_get_caps_from_media (media1, 96);
369 caps_video2 = gst_sdp_media_get_caps_from_media (media1, 97);
370 caps_audio = gst_sdp_media_get_caps_from_media (media3, 14);
371
372 result_video1 = gst_caps_from_string (caps_video_string1);
373 fail_unless (gst_caps_is_strictly_equal (caps_video1, result_video1));
374 gst_caps_unref (result_video1);
375 gst_caps_unref (caps_video1);
376
377 result_video2 = gst_caps_from_string (caps_video_string2);
378 fail_unless (gst_caps_is_strictly_equal (caps_video2, result_video2));
379 gst_caps_unref (result_video2);
380 gst_caps_unref (caps_video2);
381
382 result_audio = gst_caps_from_string (caps_audio_string);
383 fail_unless (gst_caps_is_strictly_equal (caps_audio, result_audio));
384 gst_caps_unref (result_audio);
385 gst_caps_unref (caps_audio);
386
387 gst_sdp_message_free (message);
388 }
389
390 GST_END_TEST
GST_START_TEST(media_from_caps)391 GST_START_TEST (media_from_caps)
392 {
393 GstSDPResult ret = GST_SDP_OK;
394 GstSDPMessage *message;
395 glong length = -1;
396 GstSDPMedia *media_video, *media_audio;
397 const GstSDPMedia *result_video, *result_audio;
398 GstCaps *caps_video, *caps_audio;
399 const gchar *media1_text, *media2_text, *media3_text, *media4_text;
400
401 caps_video = gst_caps_from_string (caps_video_string1);
402 caps_audio = gst_caps_from_string (caps_audio_string);
403
404 gst_sdp_media_new (&media_video);
405 fail_unless (media_video != NULL);
406 gst_sdp_media_new (&media_audio);
407 fail_unless (media_audio != NULL);
408
409 ret = gst_sdp_media_set_media_from_caps (caps_video, media_video);
410 fail_unless (ret == GST_SDP_OK);
411 gst_caps_unref (caps_video);
412 ret = gst_sdp_media_set_media_from_caps (caps_audio, media_audio);
413 fail_unless (ret == GST_SDP_OK);
414 gst_caps_unref (caps_audio);
415
416 gst_sdp_message_new (&message);
417 gst_sdp_message_parse_buffer ((guint8 *) sdp, length, message);
418
419 result_video = gst_sdp_message_get_media (message, 0);
420 fail_unless (result_video != NULL);
421
422 result_audio = gst_sdp_message_get_media (message, 2);
423 fail_unless (result_audio != NULL);
424
425 media1_text = gst_sdp_media_get_attribute_val (media_video, "rtpmap");
426 media2_text = gst_sdp_media_get_attribute_val (result_video, "rtpmap");
427 media3_text = gst_sdp_media_get_format (media_audio, 0);
428 media4_text = gst_sdp_media_get_format (result_audio, 0);
429
430 fail_if (g_strcmp0 (media1_text, media2_text) != 0);
431 fail_if (g_strcmp0 (media3_text, media4_text) != 0);
432
433 gst_sdp_media_free (media_video);
434 gst_sdp_media_free (media_audio);
435 gst_sdp_message_free (message);
436 }
437
438 GST_END_TEST
GST_START_TEST(caps_from_media_rtcp_fb)439 GST_START_TEST (caps_from_media_rtcp_fb)
440 {
441 GstSDPMessage *message;
442 glong length = -1;
443 const GstSDPMedia *media1;
444 GstCaps *caps1, *caps2, *caps3;
445 GstCaps *result1, *result2, *result3;
446
447 gst_sdp_message_new (&message);
448 gst_sdp_message_parse_buffer ((guint8 *) sdp_rtcp_fb, length, message);
449
450 media1 = gst_sdp_message_get_media (message, 0);
451 fail_unless (media1 != NULL);
452
453 caps1 = gst_sdp_media_get_caps_from_media (media1, 100);
454 result1 = gst_caps_from_string (caps_video_rtcp_fb_pt_100);
455 fail_unless (gst_caps_is_strictly_equal (caps1, result1));
456
457 gst_caps_unref (result1);
458 gst_caps_unref (caps1);
459
460 caps2 = gst_sdp_media_get_caps_from_media (media1, 101);
461 result2 = gst_caps_from_string (caps_video_rtcp_fb_pt_101);
462 fail_unless (gst_caps_is_strictly_equal (caps2, result2));
463
464 gst_caps_unref (result2);
465 gst_caps_unref (caps2);
466
467 caps3 = gst_sdp_media_get_caps_from_media (media1, 102);
468 result3 = gst_caps_from_string (caps_video_rtcp_fb_pt_102);
469
470 fail_unless (gst_caps_is_strictly_equal (caps3, result3));
471
472 gst_caps_unref (result3);
473 gst_caps_unref (caps3);
474
475 gst_sdp_message_free (message);
476 }
477
478 GST_END_TEST
GST_START_TEST(caps_from_media_rtcp_fb_all)479 GST_START_TEST (caps_from_media_rtcp_fb_all)
480 {
481 GstSDPMessage *message;
482 glong length = -1;
483 const GstSDPMedia *media1;
484 GstCaps *caps1, *caps2, *caps3;
485 GstCaps *result1, *result2, *result3;
486
487 gst_sdp_message_new (&message);
488 gst_sdp_message_parse_buffer ((guint8 *) sdp_rtcp_fb_all, length, message);
489
490 media1 = gst_sdp_message_get_media (message, 0);
491 fail_unless (media1 != NULL);
492
493 caps1 = gst_sdp_media_get_caps_from_media (media1, 100);
494 result1 = gst_caps_from_string (caps_video_rtcp_fb_all_pt_100);
495 fail_unless (gst_caps_is_strictly_equal (caps1, result1));
496
497 gst_caps_unref (result1);
498 gst_caps_unref (caps1);
499
500 caps2 = gst_sdp_media_get_caps_from_media (media1, 101);
501 result2 = gst_caps_from_string (caps_video_rtcp_fb_all_pt_101);
502 fail_unless (gst_caps_is_strictly_equal (caps2, result2));
503
504 gst_caps_unref (result2);
505 gst_caps_unref (caps2);
506
507 caps3 = gst_sdp_media_get_caps_from_media (media1, 102);
508 result3 = gst_caps_from_string (caps_video_rtcp_fb_all_pt_102);
509
510 fail_unless (gst_caps_is_strictly_equal (caps3, result3));
511
512 gst_caps_unref (result3);
513 gst_caps_unref (caps3);
514
515 gst_sdp_message_free (message);
516 }
517
518 GST_END_TEST
GST_START_TEST(media_from_caps_rtcp_fb_pt_100)519 GST_START_TEST (media_from_caps_rtcp_fb_pt_100)
520 {
521 GstSDPResult ret = GST_SDP_OK;
522 GstSDPMessage *message;
523 glong length = -1;
524 GstSDPMedia *media_caps;
525 const GstSDPMedia *media_sdp;
526 GstCaps *caps;
527 const gchar *attr_val_caps1, *attr_val_caps2, *attr_val_caps3;
528 const gchar *attr_val_sdp1, *attr_val_sdp2, *attr_val_sdp3;
529
530 caps = gst_caps_from_string (caps_video_rtcp_fb_pt_100);
531
532 gst_sdp_media_new (&media_caps);
533 fail_unless (media_caps != NULL);
534
535 ret = gst_sdp_media_set_media_from_caps (caps, media_caps);
536 fail_unless (ret == GST_SDP_OK);
537 gst_caps_unref (caps);
538
539 gst_sdp_message_new (&message);
540 gst_sdp_message_parse_buffer ((guint8 *) sdp_rtcp_fb, length, message);
541
542 media_sdp = gst_sdp_message_get_media (message, 0);
543 fail_unless (media_sdp != NULL);
544
545 attr_val_caps1 = gst_sdp_media_get_attribute_val_n (media_caps, "rtcp-fb", 0);
546 attr_val_caps2 = gst_sdp_media_get_attribute_val_n (media_caps, "rtcp-fb", 1);
547 attr_val_caps3 = gst_sdp_media_get_attribute_val_n (media_caps, "rtcp-fb", 2);
548
549 attr_val_sdp1 = gst_sdp_media_get_attribute_val_n (media_sdp, "rtcp-fb", 0);
550 attr_val_sdp2 = gst_sdp_media_get_attribute_val_n (media_sdp, "rtcp-fb", 1);
551 attr_val_sdp3 = gst_sdp_media_get_attribute_val_n (media_sdp, "rtcp-fb", 2);
552
553 fail_if (g_strcmp0 (attr_val_caps1, attr_val_sdp1) != 0);
554 fail_if (g_strcmp0 (attr_val_caps2, attr_val_sdp2) != 0);
555 fail_if (g_strcmp0 (attr_val_caps3, attr_val_sdp3) != 0);
556
557 gst_sdp_media_free (media_caps);
558 gst_sdp_message_free (message);
559 }
560
561 GST_END_TEST
GST_START_TEST(media_from_caps_rtcp_fb_pt_101)562 GST_START_TEST (media_from_caps_rtcp_fb_pt_101)
563 {
564 GstSDPResult ret = GST_SDP_OK;
565 GstSDPMessage *message;
566 glong length = -1;
567 GstSDPMedia *media_caps;
568 const GstSDPMedia *media_sdp;
569 GstCaps *caps;
570 const gchar *attr_val_caps1, *attr_val_sdp1;
571
572 caps = gst_caps_from_string (caps_video_rtcp_fb_pt_101);
573
574 gst_sdp_media_new (&media_caps);
575 fail_unless (media_caps != NULL);
576
577 ret = gst_sdp_media_set_media_from_caps (caps, media_caps);
578 fail_unless (ret == GST_SDP_OK);
579 gst_caps_unref (caps);
580
581 gst_sdp_message_new (&message);
582 gst_sdp_message_parse_buffer ((guint8 *) sdp_rtcp_fb, length, message);
583
584 media_sdp = gst_sdp_message_get_media (message, 0);
585 fail_unless (media_sdp != NULL);
586
587 attr_val_caps1 = gst_sdp_media_get_attribute_val (media_caps, "rtcp-fb");
588 attr_val_sdp1 = gst_sdp_media_get_attribute_val_n (media_sdp, "rtcp-fb", 3);
589
590 fail_if (g_strcmp0 (attr_val_caps1, attr_val_sdp1) != 0);
591
592 gst_sdp_media_free (media_caps);
593 gst_sdp_message_free (message);
594 }
595
596 GST_END_TEST
GST_START_TEST(caps_from_media_extmap)597 GST_START_TEST (caps_from_media_extmap)
598 {
599 GstSDPMessage *message;
600 glong length = -1;
601 const GstSDPMedia *media1;
602 GstCaps *caps1;
603 GstCaps *result1;
604
605 gst_sdp_message_new (&message);
606 gst_sdp_message_parse_buffer ((guint8 *) sdp_extmap, length, message);
607
608 media1 = gst_sdp_message_get_media (message, 0);
609 fail_unless (media1 != NULL);
610
611 caps1 = gst_sdp_media_get_caps_from_media (media1, 100);
612 gst_sdp_media_attributes_to_caps (media1, caps1);
613 result1 = gst_caps_from_string (caps_video_extmap_pt_100);
614 fail_unless (gst_caps_is_strictly_equal (caps1, result1));
615
616 gst_caps_unref (result1);
617 gst_caps_unref (caps1);
618
619 gst_sdp_message_free (message);
620 }
621
622 GST_END_TEST
GST_START_TEST(caps_from_media_fmtp)623 GST_START_TEST (caps_from_media_fmtp)
624 {
625 GstSDPMessage *message;
626 glong length = -1;
627 const GstSDPMedia *media1, *media2;
628 GstCaps *caps1, *caps2;
629 GstCaps *result1, *result2;
630
631 gst_sdp_message_new (&message);
632 gst_sdp_message_parse_buffer ((guint8 *) sdp_fmtp, length, message);
633
634 media1 = gst_sdp_message_get_media (message, 0);
635 fail_unless (media1 != NULL);
636
637 caps1 = gst_sdp_media_get_caps_from_media (media1, 100);
638 gst_sdp_media_attributes_to_caps (media1, caps1);
639 result1 = gst_caps_from_string (caps_video_raptor_fec_pt_100);
640 fail_unless (gst_caps_is_strictly_equal (caps1, result1));
641
642 gst_caps_unref (result1);
643 gst_caps_unref (caps1);
644
645 media2 = gst_sdp_message_get_media (message, 1);
646 fail_unless (media1 != NULL);
647
648 caps2 = gst_sdp_media_get_caps_from_media (media2, 110);
649 gst_sdp_media_attributes_to_caps (media2, caps2);
650 result2 = gst_caps_from_string (caps_application_raptor_fec_pt_110);
651 fail_unless (gst_caps_is_strictly_equal (caps2, result2));
652
653 gst_caps_unref (result2);
654 gst_caps_unref (caps2);
655 gst_sdp_message_free (message);
656 }
657
658 GST_END_TEST
GST_START_TEST(media_from_caps_extmap_pt_100)659 GST_START_TEST (media_from_caps_extmap_pt_100)
660 {
661 GstSDPResult ret = GST_SDP_OK;
662 GstSDPMessage *message;
663 glong length = -1;
664 GstSDPMedia *media_caps;
665 const GstSDPMedia *media_sdp;
666 GstCaps *caps;
667 const gchar *attr_val_caps1, *attr_val_caps2, *attr_val_caps3;
668 const gchar *attr_val_sdp1, *attr_val_sdp2, *attr_val_sdp3;
669
670 caps = gst_caps_from_string (caps_video_extmap_pt_100);
671
672 gst_sdp_media_new (&media_caps);
673 fail_unless (media_caps != NULL);
674
675 ret = gst_sdp_media_set_media_from_caps (caps, media_caps);
676 fail_unless (ret == GST_SDP_OK);
677 gst_caps_unref (caps);
678
679 gst_sdp_message_new (&message);
680 gst_sdp_message_parse_buffer ((guint8 *) sdp_extmap, length, message);
681
682 media_sdp = gst_sdp_message_get_media (message, 0);
683 fail_unless (media_sdp != NULL);
684
685 attr_val_caps1 = gst_sdp_media_get_attribute_val_n (media_caps, "extmap", 0);
686 attr_val_caps2 = gst_sdp_media_get_attribute_val_n (media_caps, "extmap", 1);
687 attr_val_caps3 = gst_sdp_media_get_attribute_val_n (media_caps, "extmap", 2);
688
689 attr_val_sdp1 = gst_sdp_media_get_attribute_val_n (media_sdp, "extmap", 0);
690 attr_val_sdp2 = gst_sdp_media_get_attribute_val_n (media_sdp, "extmap", 1);
691 attr_val_sdp3 = gst_sdp_media_get_attribute_val_n (media_sdp, "extmap", 2);
692
693 fail_if (g_strcmp0 (attr_val_caps1, attr_val_sdp1) != 0);
694 fail_if (g_strcmp0 (attr_val_caps2, attr_val_sdp2) != 0);
695 fail_if (g_strcmp0 (attr_val_caps3, attr_val_sdp3) != 0);
696
697 gst_sdp_media_free (media_caps);
698 gst_sdp_message_free (message);
699 }
700
701 GST_END_TEST
GST_START_TEST(caps_from_media_really_const)702 GST_START_TEST (caps_from_media_really_const)
703 {
704 GstSDPMessage *message;
705 glong length = -1;
706 const GstSDPMedia *media1;
707 gchar *serialized;
708 GstCaps *caps;
709
710 /* BUG: gst_sdp_media_get_caps_from_media() used to modify the media passed
711 * thus violating the const tag */
712
713 gst_sdp_message_new (&message);
714 gst_sdp_message_parse_buffer ((guint8 *) sdp, length, message);
715
716 serialized = gst_sdp_message_as_text (message);
717 fail_unless (g_strcmp0 (serialized, sdp) == 0);
718 g_free (serialized);
719
720 media1 = gst_sdp_message_get_media (message, 0);
721 fail_unless (media1 != NULL);
722
723 caps = gst_sdp_media_get_caps_from_media (media1, 96);
724
725 serialized = gst_sdp_message_as_text (message);
726 fail_unless (g_strcmp0 (serialized, sdp) == 0);
727 g_free (serialized);
728
729 gst_caps_unref (caps);
730
731 gst_sdp_message_free (message);
732 }
733
734 GST_END_TEST
GST_START_TEST(media_from_caps_h264_with_profile_asymmetry_allowed)735 GST_START_TEST (media_from_caps_h264_with_profile_asymmetry_allowed)
736 {
737 GstSDPMessage *message;
738 glong length = -1;
739 const GstSDPMedia *result_video;
740 GstStructure *s_video;
741 GstCaps *caps_video;
742
743 gst_sdp_message_new (&message);
744 gst_sdp_message_parse_buffer ((guint8 *) h264_sdp, length, message);
745
746
747 result_video = gst_sdp_message_get_media (message, 0);
748 fail_unless (result_video != NULL);
749 caps_video = gst_sdp_media_get_caps_from_media (result_video, 96);
750
751 s_video = gst_caps_get_structure (caps_video, 0);
752 fail_if (gst_structure_has_field (s_video, "level-asymmetry-allowed"));
753 fail_if (gst_structure_has_field (s_video, "profile-level-id"));
754 fail_unless_equals_string (gst_structure_get_string (s_video, "profile"),
755 "constrained-baseline");
756
757 gst_caps_unref (caps_video);
758 gst_sdp_message_free (message);
759 }
760
761 GST_END_TEST
762 /*
763 * End of test cases
764 */
765 static Suite *
sdp_suite(void)766 sdp_suite (void)
767 {
768 Suite *s = suite_create ("sdp");
769 TCase *tc_chain = tcase_create ("sdp");
770
771 suite_add_tcase (s, tc_chain);
772 tcase_add_test (tc_chain, copy);
773 tcase_add_test (tc_chain, boxed);
774 tcase_add_test (tc_chain, modify);
775 tcase_add_test (tc_chain, null);
776 tcase_add_test (tc_chain, caps_from_media);
777 tcase_add_test (tc_chain, caps_from_media_really_const);
778 tcase_add_test (tc_chain, media_from_caps);
779 tcase_add_test (tc_chain, caps_from_media_rtcp_fb);
780 tcase_add_test (tc_chain, caps_from_media_rtcp_fb_all);
781 tcase_add_test (tc_chain, caps_from_media_extmap);
782 tcase_add_test (tc_chain, caps_from_media_fmtp);
783 tcase_add_test (tc_chain, media_from_caps_rtcp_fb_pt_100);
784 tcase_add_test (tc_chain, media_from_caps_rtcp_fb_pt_101);
785 tcase_add_test (tc_chain, media_from_caps_extmap_pt_100);
786 tcase_add_test (tc_chain,
787 media_from_caps_h264_with_profile_asymmetry_allowed);
788
789 return s;
790 }
791
792 GST_CHECK_MAIN (sdp);
793