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);
214 rtspmediafactory_suite (void)
216 Suite *s = suite_create ("rtspmediafactory");
217 TCase *tc = tcase_create ("general");
219 suite_add_tcase (s, tc);
220 tcase_set_timeout (tc, 20);
221 tcase_add_test (tc, test_parse_error);
222 tcase_add_test (tc, test_launch);
223 tcase_add_test (tc, test_launch_construct);
224 tcase_add_test (tc, test_shared);
225 tcase_add_test (tc, test_addresspool);
230 GST_CHECK_MAIN (rtspmediafactory);