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 gst_rtsp_url_parse ("rtsp://localhost:8554/test", &url);
33 ASSERT_CRITICAL (gst_rtsp_media_factory_create_element (factory, url));
34 ASSERT_CRITICAL (gst_rtsp_media_factory_construct (factory, url));
36 gst_rtsp_url_free (url);
37 g_object_unref (factory);
42 GST_START_TEST (test_launch)
44 GstRTSPMediaFactory *factory;
48 factory = gst_rtsp_media_factory_new ();
49 fail_if (gst_rtsp_media_factory_is_shared (factory));
50 gst_rtsp_url_parse ("rtsp://localhost:8554/test", &url);
52 gst_rtsp_media_factory_set_launch (factory,
53 "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
55 element = gst_rtsp_media_factory_create_element (factory, url);
56 fail_unless (GST_IS_BIN (element));
57 fail_if (GST_IS_PIPELINE (element));
58 gst_object_unref (element);
60 gst_rtsp_url_free (url);
61 g_object_unref (factory);
66 GST_START_TEST (test_launch_construct)
68 GstRTSPMediaFactory *factory;
69 GstRTSPMedia *media, *media2;
72 factory = gst_rtsp_media_factory_new ();
73 fail_if (gst_rtsp_media_factory_is_shared (factory));
74 gst_rtsp_url_parse ("rtsp://localhost:8554/test", &url);
76 gst_rtsp_media_factory_set_launch (factory,
77 "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
79 media = gst_rtsp_media_factory_construct (factory, url);
80 fail_unless (GST_IS_RTSP_MEDIA (media));
82 media2 = gst_rtsp_media_factory_construct (factory, url);
83 fail_unless (GST_IS_RTSP_MEDIA (media2));
84 fail_if (media == media2);
86 g_object_unref (media);
87 g_object_unref (media2);
89 gst_rtsp_url_free (url);
90 g_object_unref (factory);
95 GST_START_TEST (test_shared)
97 GstRTSPMediaFactory *factory;
99 GstRTSPMedia *media, *media2;
102 factory = gst_rtsp_media_factory_new ();
103 gst_rtsp_media_factory_set_shared (factory, TRUE);
104 fail_unless (gst_rtsp_media_factory_is_shared (factory));
106 gst_rtsp_url_parse ("rtsp://localhost:8554/test", &url);
108 gst_rtsp_media_factory_set_launch (factory,
109 "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
111 element = gst_rtsp_media_factory_create_element (factory, url);
112 fail_unless (GST_IS_BIN (element));
113 fail_if (GST_IS_PIPELINE (element));
114 gst_object_unref (element);
116 media = gst_rtsp_media_factory_construct (factory, url);
117 fail_unless (GST_IS_RTSP_MEDIA (media));
119 media2 = gst_rtsp_media_factory_construct (factory, url);
120 fail_unless (GST_IS_RTSP_MEDIA (media2));
121 fail_unless (media == media2);
123 g_object_unref (media);
124 g_object_unref (media2);
126 gst_rtsp_url_free (url);
127 g_object_unref (factory);
132 GST_START_TEST (test_addresspool)
134 GstRTSPMediaFactory *factory;
138 GstRTSPAddressPool *pool, *tmppool;
139 GstRTSPStream *stream;
140 GstRTSPAddress *addr;
142 factory = gst_rtsp_media_factory_new ();
143 gst_rtsp_media_factory_set_shared (factory, TRUE);
144 gst_rtsp_url_parse ("rtsp://localhost:8554/test", &url);
146 gst_rtsp_media_factory_set_launch (factory,
147 "( videotestsrc ! rtpvrawpay pt=96 name=pay0 "
148 " audiotestsrc ! audioconvert ! rtpL16pay name=pay1 )");
150 pool = gst_rtsp_address_pool_new ();
151 fail_unless (gst_rtsp_address_pool_add_range (pool,
152 "233.252.0.1", "233.252.0.1", 5000, 5001, 3));
154 gst_rtsp_media_factory_set_address_pool (factory, pool);
156 tmppool = gst_rtsp_media_factory_get_address_pool (factory);
157 fail_unless (pool == tmppool);
158 g_object_unref (tmppool);
160 element = gst_rtsp_media_factory_create_element (factory, url);
161 fail_unless (GST_IS_BIN (element));
162 fail_if (GST_IS_PIPELINE (element));
163 gst_object_unref (element);
165 media = gst_rtsp_media_factory_construct (factory, url);
166 fail_unless (GST_IS_RTSP_MEDIA (media));
168 tmppool = gst_rtsp_media_get_address_pool (media);
169 fail_unless (pool == tmppool);
170 g_object_unref (tmppool);
172 fail_unless (gst_rtsp_media_n_streams (media) == 2);
174 stream = gst_rtsp_media_get_stream (media, 0);
175 fail_unless (stream != NULL);
177 tmppool = gst_rtsp_stream_get_address_pool (stream);
178 fail_unless (pool == tmppool);
179 g_object_unref (tmppool);
181 addr = gst_rtsp_stream_get_address (stream);
182 fail_unless (addr != NULL);
183 fail_unless (addr->port == 5000);
184 fail_unless (addr->n_ports == 2);
185 fail_unless (addr->ttl == 3);
186 gst_rtsp_address_free (addr);
188 stream = gst_rtsp_media_get_stream (media, 1);
189 fail_unless (stream != NULL);
191 tmppool = gst_rtsp_stream_get_address_pool (stream);
192 fail_unless (pool == tmppool);
193 g_object_unref (tmppool);
195 addr = gst_rtsp_stream_get_address (stream);
196 fail_unless (addr == NULL);
199 g_object_unref (media);
201 g_object_unref (pool);
202 gst_rtsp_url_free (url);
203 g_object_unref (factory);
209 rtspmediafactory_suite (void)
211 Suite *s = suite_create ("rtspmediafactory");
212 TCase *tc = tcase_create ("general");
214 suite_add_tcase (s, tc);
215 tcase_set_timeout (tc, 20);
216 tcase_add_test (tc, test_parse_error);
217 tcase_add_test (tc, test_launch);
218 tcase_add_test (tc, test_launch_construct);
219 tcase_add_test (tc, test_shared);
220 tcase_add_test (tc, test_addresspool);
225 GST_CHECK_MAIN (rtspmediafactory);