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));
81 g_object_unref (media);
83 media2 = gst_rtsp_media_factory_construct (factory, url);
84 fail_unless (GST_IS_RTSP_MEDIA (media2));
85 fail_if (media == media2);
86 g_object_unref (media2);
88 gst_rtsp_url_free (url);
89 g_object_unref (factory);
94 GST_START_TEST (test_shared)
96 GstRTSPMediaFactory *factory;
98 GstRTSPMedia *media, *media2;
101 factory = gst_rtsp_media_factory_new ();
102 gst_rtsp_media_factory_set_shared (factory, TRUE);
103 fail_unless (gst_rtsp_media_factory_is_shared (factory));
105 gst_rtsp_url_parse ("rtsp://localhost:8554/test", &url);
107 gst_rtsp_media_factory_set_launch (factory,
108 "( videotestsrc ! rtpvrawpay pt=96 name=pay0 )");
110 element = gst_rtsp_media_factory_create_element (factory, url);
111 fail_unless (GST_IS_BIN (element));
112 fail_if (GST_IS_PIPELINE (element));
113 gst_object_unref (element);
115 media = gst_rtsp_media_factory_construct (factory, url);
116 fail_unless (GST_IS_RTSP_MEDIA (media));
118 media2 = gst_rtsp_media_factory_construct (factory, url);
119 fail_unless (GST_IS_RTSP_MEDIA (media2));
120 fail_unless (media == media2);
122 g_object_unref (media);
123 g_object_unref (media2);
125 gst_rtsp_url_free (url);
126 g_object_unref (factory);
131 GST_START_TEST (test_addresspool)
133 GstRTSPMediaFactory *factory;
137 GstRTSPAddressPool *pool, *tmppool;
138 GstRTSPStream *stream;
139 GstRTSPAddress *addr;
141 factory = gst_rtsp_media_factory_new ();
142 gst_rtsp_media_factory_set_shared (factory, TRUE);
143 gst_rtsp_url_parse ("rtsp://localhost:8554/test", &url);
145 gst_rtsp_media_factory_set_launch (factory,
146 "( videotestsrc ! rtpvrawpay pt=96 name=pay0 "
147 " audiotestsrc ! audioconvert ! rtpL16pay name=pay1 )");
149 pool = gst_rtsp_address_pool_new ();
150 fail_unless (gst_rtsp_address_pool_add_range (pool,
151 "233.252.0.1", "233.252.0.1", 5000, 5001, 3));
153 gst_rtsp_media_factory_set_address_pool (factory, pool);
155 tmppool = gst_rtsp_media_factory_get_address_pool (factory);
156 fail_unless (pool == tmppool);
157 g_object_unref (tmppool);
159 element = gst_rtsp_media_factory_create_element (factory, url);
160 fail_unless (GST_IS_BIN (element));
161 fail_if (GST_IS_PIPELINE (element));
162 gst_object_unref (element);
164 media = gst_rtsp_media_factory_construct (factory, url);
165 fail_unless (GST_IS_RTSP_MEDIA (media));
167 tmppool = gst_rtsp_media_get_address_pool (media);
168 fail_unless (pool == tmppool);
169 g_object_unref (tmppool);
171 fail_unless (gst_rtsp_media_n_streams (media) == 2);
173 stream = gst_rtsp_media_get_stream (media, 0);
174 fail_unless (stream != NULL);
176 tmppool = gst_rtsp_stream_get_address_pool (stream);
177 fail_unless (pool == tmppool);
178 g_object_unref (tmppool);
180 addr = gst_rtsp_stream_get_address (stream);
181 fail_unless (addr != NULL);
182 fail_unless (addr->port == 5000);
183 fail_unless (addr->n_ports == 2);
184 fail_unless (addr->ttl == 3);
185 gst_rtsp_address_free (addr);
187 stream = gst_rtsp_media_get_stream (media, 1);
188 fail_unless (stream != NULL);
190 tmppool = gst_rtsp_stream_get_address_pool (stream);
191 fail_unless (pool == tmppool);
192 g_object_unref (tmppool);
194 addr = gst_rtsp_stream_get_address (stream);
195 fail_unless (addr == NULL);
198 g_object_unref (media);
200 g_object_unref (pool);
201 gst_rtsp_url_free (url);
202 g_object_unref (factory);
208 rtspmediafactory_suite (void)
210 Suite *s = suite_create ("rtspmediafactory");
211 TCase *tc = tcase_create ("general");
213 suite_add_tcase (s, tc);
214 tcase_set_timeout (tc, 20);
215 tcase_add_test (tc, test_parse_error);
216 tcase_add_test (tc, test_launch);
217 tcase_add_test (tc, test_launch_construct);
218 tcase_add_test (tc, test_shared);
219 tcase_add_test (tc, test_addresspool);
224 GST_CHECK_MAIN (rtspmediafactory);