2 * Copyright (C) 2012 Wim Taymans <wim.taymans@gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #include <gst/check/gstcheck.h>
22 #include <rtsp-media-factory.h>
24 GST_START_TEST (test_parse_error)
26 GstRTSPMediaFactory *factory;
29 factory = gst_rtsp_media_factory_new ();
31 gst_rtsp_media_factory_set_launch (factory, "foo");
32 fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
33 &url) == GST_RTSP_OK);
34 ASSERT_CRITICAL (gst_rtsp_media_factory_create_element (factory, url));
35 ASSERT_CRITICAL (gst_rtsp_media_factory_construct (factory, url));
37 gst_rtsp_url_free (url);
38 g_object_unref (factory);
43 GST_START_TEST (test_launch)
45 GstRTSPMediaFactory *factory;
49 factory = gst_rtsp_media_factory_new ();
50 fail_if (gst_rtsp_media_factory_is_shared (factory));
51 fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
52 &url) == GST_RTSP_OK);
54 gst_rtsp_media_factory_set_launch (factory,
55 "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
57 element = gst_rtsp_media_factory_create_element (factory, url);
58 fail_unless (GST_IS_BIN (element));
59 fail_if (GST_IS_PIPELINE (element));
60 gst_object_unref (element);
62 gst_rtsp_url_free (url);
63 g_object_unref (factory);
68 GST_START_TEST (test_launch_construct)
70 GstRTSPMediaFactory *factory;
71 GstRTSPMedia *media, *media2;
74 factory = gst_rtsp_media_factory_new ();
75 fail_if (gst_rtsp_media_factory_is_shared (factory));
76 fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
77 &url) == GST_RTSP_OK);
79 gst_rtsp_media_factory_set_launch (factory,
80 "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
82 media = gst_rtsp_media_factory_construct (factory, url);
83 fail_unless (GST_IS_RTSP_MEDIA (media));
85 media2 = gst_rtsp_media_factory_construct (factory, url);
86 fail_unless (GST_IS_RTSP_MEDIA (media2));
87 fail_if (media == media2);
89 g_object_unref (media);
90 g_object_unref (media2);
92 gst_rtsp_url_free (url);
93 g_object_unref (factory);
98 GST_START_TEST (test_shared)
100 GstRTSPMediaFactory *factory;
102 GstRTSPMedia *media, *media2;
105 factory = gst_rtsp_media_factory_new ();
106 gst_rtsp_media_factory_set_shared (factory, TRUE);
107 fail_unless (gst_rtsp_media_factory_is_shared (factory));
109 fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
110 &url) == GST_RTSP_OK);
112 gst_rtsp_media_factory_set_launch (factory,
113 "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
115 element = gst_rtsp_media_factory_create_element (factory, url);
116 fail_unless (GST_IS_BIN (element));
117 fail_if (GST_IS_PIPELINE (element));
118 gst_object_unref (element);
120 media = gst_rtsp_media_factory_construct (factory, url);
121 fail_unless (GST_IS_RTSP_MEDIA (media));
123 media2 = gst_rtsp_media_factory_construct (factory, url);
124 fail_unless (GST_IS_RTSP_MEDIA (media2));
125 fail_unless (media == media2);
127 g_object_unref (media);
128 g_object_unref (media2);
130 gst_rtsp_url_free (url);
131 g_object_unref (factory);
136 GST_START_TEST (test_addresspool)
138 GstRTSPMediaFactory *factory;
142 GstRTSPAddressPool *pool, *tmppool;
143 GstRTSPStream *stream;
144 GstRTSPAddress *addr;
146 factory = gst_rtsp_media_factory_new ();
147 gst_rtsp_media_factory_set_shared (factory, TRUE);
148 fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
149 &url) == GST_RTSP_OK);
151 gst_rtsp_media_factory_set_launch (factory,
152 "( videotestsrc ! rtpvrawpay pt=96 name=pay0 "
153 " audiotestsrc ! audioconvert ! rtpL16pay name=pay1 )");
155 pool = gst_rtsp_address_pool_new ();
156 fail_unless (gst_rtsp_address_pool_add_range (pool,
157 "233.252.0.1", "233.252.0.1", 5000, 5001, 3));
159 gst_rtsp_media_factory_set_address_pool (factory, pool);
161 tmppool = gst_rtsp_media_factory_get_address_pool (factory);
162 fail_unless (pool == tmppool);
163 g_object_unref (tmppool);
165 element = gst_rtsp_media_factory_create_element (factory, url);
166 fail_unless (GST_IS_BIN (element));
167 fail_if (GST_IS_PIPELINE (element));
168 gst_object_unref (element);
170 media = gst_rtsp_media_factory_construct (factory, url);
171 fail_unless (GST_IS_RTSP_MEDIA (media));
173 tmppool = gst_rtsp_media_get_address_pool (media);
174 fail_unless (pool == tmppool);
175 g_object_unref (tmppool);
177 fail_unless (gst_rtsp_media_n_streams (media) == 2);
179 stream = gst_rtsp_media_get_stream (media, 0);
180 fail_unless (stream != NULL);
182 tmppool = gst_rtsp_stream_get_address_pool (stream);
183 fail_unless (pool == tmppool);
184 g_object_unref (tmppool);
186 addr = gst_rtsp_stream_get_multicast_address (stream, G_SOCKET_FAMILY_IPV4);
187 fail_unless (addr != NULL);
188 fail_unless (addr->port == 5000);
189 fail_unless (addr->n_ports == 2);
190 fail_unless (addr->ttl == 3);
191 gst_rtsp_address_free (addr);
193 stream = gst_rtsp_media_get_stream (media, 1);
194 fail_unless (stream != NULL);
196 tmppool = gst_rtsp_stream_get_address_pool (stream);
197 fail_unless (pool == tmppool);
198 g_object_unref (tmppool);
200 addr = gst_rtsp_stream_get_multicast_address (stream, G_SOCKET_FAMILY_IPV4);
201 fail_unless (addr == NULL);
204 g_object_unref (media);
206 g_object_unref (pool);
207 gst_rtsp_url_free (url);
208 g_object_unref (factory);
213 GST_START_TEST (test_permissions)
215 GstRTSPMediaFactory *factory;
216 GstRTSPPermissions *perms;
220 factory = gst_rtsp_media_factory_new ();
221 fail_if (gst_rtsp_media_factory_is_shared (factory));
222 fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
223 &url) == GST_RTSP_OK);
225 gst_rtsp_media_factory_set_launch (factory,
226 "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
228 gst_rtsp_media_factory_add_role (factory, "admin",
229 "media.factory.access", G_TYPE_BOOLEAN, TRUE,
230 "media.factory.construct", G_TYPE_BOOLEAN, TRUE, NULL);
232 perms = gst_rtsp_media_factory_get_permissions (factory);
233 fail_unless (gst_rtsp_permissions_is_allowed (perms, "admin",
234 "media.factory.access"));
235 fail_unless (gst_rtsp_permissions_is_allowed (perms, "admin",
236 "media.factory.construct"));
237 fail_if (gst_rtsp_permissions_is_allowed (perms, "missing",
238 "media.factory.access"));
239 gst_rtsp_permissions_unref (perms);
241 perms = gst_rtsp_permissions_new ();
242 gst_rtsp_permissions_add_role (perms, "user",
243 "media.factory.access", G_TYPE_BOOLEAN, TRUE,
244 "media.factory.construct", G_TYPE_BOOLEAN, FALSE, NULL);
245 gst_rtsp_media_factory_set_permissions (factory, perms);
246 gst_rtsp_permissions_unref (perms);
248 perms = gst_rtsp_media_factory_get_permissions (factory);
249 fail_if (gst_rtsp_permissions_is_allowed (perms, "admin",
250 "media.factory.access"));
251 fail_if (gst_rtsp_permissions_is_allowed (perms, "admin",
252 "media.factory.construct"));
253 fail_unless (gst_rtsp_permissions_is_allowed (perms, "user",
254 "media.factory.access"));
255 fail_if (gst_rtsp_permissions_is_allowed (perms, "user",
256 "media.factory.construct"));
257 fail_if (gst_rtsp_permissions_is_allowed (perms, "missing",
258 "media.factory.access"));
259 gst_rtsp_permissions_unref (perms);
261 media = gst_rtsp_media_factory_construct (factory, url);
262 fail_unless (GST_IS_RTSP_MEDIA (media));
263 perms = gst_rtsp_media_get_permissions (media);
264 fail_if (gst_rtsp_permissions_is_allowed (perms, "admin",
265 "media.factory.access"));
266 fail_if (gst_rtsp_permissions_is_allowed (perms, "admin",
267 "media.factory.construct"));
268 fail_unless (gst_rtsp_permissions_is_allowed (perms, "user",
269 "media.factory.access"));
270 fail_if (gst_rtsp_permissions_is_allowed (perms, "user",
271 "media.factory.construct"));
272 fail_if (gst_rtsp_permissions_is_allowed (perms, "missing",
273 "media.factory.access"));
274 gst_rtsp_permissions_unref (perms);
275 g_object_unref (media);
277 gst_rtsp_url_free (url);
278 g_object_unref (factory);
283 GST_START_TEST (test_reset)
285 GstRTSPMediaFactory *factory;
289 factory = gst_rtsp_media_factory_new ();
290 fail_if (gst_rtsp_media_factory_is_shared (factory));
291 gst_rtsp_url_parse ("rtsp://localhost:8554/test", &url);
293 gst_rtsp_media_factory_set_launch (factory,
294 "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
296 media = gst_rtsp_media_factory_construct (factory, url);
297 fail_unless (GST_IS_RTSP_MEDIA (media));
298 fail_if (gst_rtsp_media_get_suspend_mode (media) !=
299 GST_RTSP_SUSPEND_MODE_NONE);
300 g_object_unref (media);
302 gst_rtsp_media_factory_set_suspend_mode (factory,
303 GST_RTSP_SUSPEND_MODE_RESET);
305 media = gst_rtsp_media_factory_construct (factory, url);
306 fail_unless (GST_IS_RTSP_MEDIA (media));
307 fail_if (gst_rtsp_media_get_suspend_mode (media) !=
308 GST_RTSP_SUSPEND_MODE_RESET);
309 g_object_unref (media);
311 gst_rtsp_url_free (url);
312 g_object_unref (factory);
317 GST_START_TEST (test_mcast_ttl)
319 GstRTSPMediaFactory *factory;
323 GstRTSPStream *stream;
325 factory = gst_rtsp_media_factory_new ();
326 gst_rtsp_media_factory_set_shared (factory, TRUE);
327 fail_unless (gst_rtsp_url_parse ("rtsp://localhost:8554/test",
328 &url) == GST_RTSP_OK);
330 gst_rtsp_media_factory_set_launch (factory,
331 "( videotestsrc ! rtpvrawpay pt=96 name=pay0 "
332 " audiotestsrc ! audioconvert ! rtpL16pay name=pay1 )");
334 /* try to set an invalid ttl and make sure that the default ttl value (255) is
336 gst_rtsp_media_factory_set_max_mcast_ttl (factory, 0);
337 fail_unless (gst_rtsp_media_factory_get_max_mcast_ttl (factory) == 255);
338 gst_rtsp_media_factory_set_max_mcast_ttl (factory, 300);
339 fail_unless (gst_rtsp_media_factory_get_max_mcast_ttl (factory) == 255);
341 /* set a valid ttl value */
342 gst_rtsp_media_factory_set_max_mcast_ttl (factory, 3);
343 fail_unless (gst_rtsp_media_factory_get_max_mcast_ttl (factory) == 3);
345 element = gst_rtsp_media_factory_create_element (factory, url);
346 fail_unless (GST_IS_BIN (element));
347 fail_if (GST_IS_PIPELINE (element));
348 gst_object_unref (element);
350 media = gst_rtsp_media_factory_construct (factory, url);
351 fail_unless (GST_IS_RTSP_MEDIA (media));
353 fail_unless (gst_rtsp_media_n_streams (media) == 2);
354 fail_unless (gst_rtsp_media_get_max_mcast_ttl (media) == 3);
356 /* verify that the correct ttl value has been propageted to the media
358 stream = gst_rtsp_media_get_stream (media, 0);
359 fail_unless (stream != NULL);
360 fail_unless (gst_rtsp_stream_get_max_mcast_ttl (stream) == 3);
362 stream = gst_rtsp_media_get_stream (media, 1);
363 fail_unless (stream != NULL);
364 fail_unless (gst_rtsp_stream_get_max_mcast_ttl (stream) == 3);
366 g_object_unref (media);
368 gst_rtsp_url_free (url);
369 g_object_unref (factory);
375 rtspmediafactory_suite (void)
377 Suite *s = suite_create ("rtspmediafactory");
378 TCase *tc = tcase_create ("general");
380 suite_add_tcase (s, tc);
381 tcase_set_timeout (tc, 20);
382 tcase_add_test (tc, test_parse_error);
383 tcase_add_test (tc, test_launch);
384 tcase_add_test (tc, test_launch_construct);
385 tcase_add_test (tc, test_shared);
386 tcase_add_test (tc, test_addresspool);
387 tcase_add_test (tc, test_permissions);
388 tcase_add_test (tc, test_reset);
389 tcase_add_test (tc, test_mcast_ttl);
394 GST_CHECK_MAIN (rtspmediafactory);