1 /* GStreamer
2 * Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
3 *
4 * simple_launch_lines.c: Unit test for simple pipelines
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22 #include <gst/check/gstcheck.h>
23
24 #ifndef GST_DISABLE_PARSE
25
26 static GstElement *
setup_pipeline(const gchar * pipe_descr)27 setup_pipeline (const gchar * pipe_descr)
28 {
29 GstElement *pipeline;
30
31 pipeline = gst_parse_launch (pipe_descr, NULL);
32 g_return_val_if_fail (GST_IS_PIPELINE (pipeline), NULL);
33 return pipeline;
34 }
35
36 /*
37 * run_pipeline:
38 * @pipe: the pipeline to run
39 * @desc: the description for use in messages
40 * @events: is a mask of expected events
41 * @tevent: is the expected terminal event.
42 *
43 * the poll call will time out after half a second.
44 */
45 static void
run_pipeline(GstElement * pipe,const gchar * descr,GstMessageType events,GstMessageType tevent,GstState target_state)46 run_pipeline (GstElement * pipe, const gchar * descr,
47 GstMessageType events, GstMessageType tevent, GstState target_state)
48 {
49 GstBus *bus;
50 GstMessage *message;
51 GstMessageType revent;
52 GstStateChangeReturn ret;
53
54 g_assert (pipe);
55 bus = gst_element_get_bus (pipe);
56 g_assert (bus);
57
58 fail_if (gst_element_set_state (pipe, target_state) ==
59 GST_STATE_CHANGE_FAILURE, "Could not set pipeline %s to playing", descr);
60 ret = gst_element_get_state (pipe, NULL, NULL, 10 * GST_SECOND);
61 if (ret == GST_STATE_CHANGE_ASYNC) {
62 g_critical ("Pipeline '%s' failed to go to PAUSED fast enough", descr);
63 goto done;
64 } else if ((ret != GST_STATE_CHANGE_SUCCESS)
65 && (ret != GST_STATE_CHANGE_NO_PREROLL)) {
66 g_critical ("Pipeline '%s' failed to go into PAUSED state (%s)", descr,
67 gst_element_state_change_return_get_name (ret));
68 goto done;
69 }
70
71 while (1) {
72 message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 2);
73
74 /* always have to pop the message before getting back into poll */
75 if (message) {
76 revent = GST_MESSAGE_TYPE (message);
77 gst_message_unref (message);
78 } else {
79 revent = GST_MESSAGE_UNKNOWN;
80 }
81
82 if (revent == tevent) {
83 break;
84 } else if (revent == GST_MESSAGE_UNKNOWN) {
85 g_critical ("Unexpected timeout in gst_bus_poll, looking for %d: %s",
86 tevent, descr);
87 break;
88 } else if (revent & events) {
89 continue;
90 }
91 g_critical
92 ("Unexpected message received of type %d, '%s', looking for %d: %s",
93 revent, gst_message_type_get_name (revent), tevent, descr);
94 }
95
96 done:
97 fail_if (gst_element_set_state (pipe, GST_STATE_NULL) ==
98 GST_STATE_CHANGE_FAILURE, "Could not set pipeline %s to NULL", descr);
99 gst_element_get_state (pipe, NULL, NULL, GST_CLOCK_TIME_NONE);
100 gst_object_unref (pipe);
101
102 gst_bus_set_flushing (bus, TRUE);
103 gst_object_unref (bus);
104 }
105
GST_START_TEST(test_rtp_payloaders)106 GST_START_TEST (test_rtp_payloaders)
107 {
108 const gchar *s;
109
110 /* FIXME: going to playing would be nice, but thet leads to lot of failure */
111 GstState target_state = GST_STATE_PAUSED;
112
113 /* we use is-live here to avoid preroll */
114 #define PIPELINE_STRING(bufcount, bufsize, pl, dpl) "fakesrc is-live=true num-buffers=" bufcount " filltype=2 sizetype=2 sizemax=" bufsize " ! " pl " ! " dpl " ! fakesink"
115 #define DEFAULT_BUFCOUNT "5"
116 #define DEFAULT_BUFSIZE "16"
117
118 s = PIPELINE_STRING (DEFAULT_BUFCOUNT, DEFAULT_BUFSIZE, "rtpilbcpay",
119 "rtpilbcdepay");
120 run_pipeline (setup_pipeline (s), s,
121 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
122 GST_MESSAGE_UNKNOWN, target_state);
123
124 s = PIPELINE_STRING (DEFAULT_BUFCOUNT, DEFAULT_BUFSIZE, "rtpgsmpay",
125 "rtpgsmdepay");
126 run_pipeline (setup_pipeline (s), s,
127 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
128 GST_MESSAGE_UNKNOWN, target_state);
129
130 /* This one needs a bit different buffer size than others or it doesn't work. */
131 s = PIPELINE_STRING (DEFAULT_BUFCOUNT, "52", "rtpamrpay", "rtpamrdepay");
132 run_pipeline (setup_pipeline (s), s,
133 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
134 GST_MESSAGE_UNKNOWN, target_state);
135
136 s = PIPELINE_STRING (DEFAULT_BUFCOUNT, DEFAULT_BUFSIZE, "rtppcmapay",
137 "rtppcmadepay");
138 run_pipeline (setup_pipeline (s), s,
139 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
140 GST_MESSAGE_UNKNOWN, target_state);
141
142 s = PIPELINE_STRING (DEFAULT_BUFCOUNT, DEFAULT_BUFSIZE, "rtppcmupay",
143 "rtppcmudepay");
144 run_pipeline (setup_pipeline (s), s,
145 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
146 GST_MESSAGE_UNKNOWN, target_state);
147
148 s = PIPELINE_STRING (DEFAULT_BUFCOUNT, DEFAULT_BUFSIZE, "rtpmpapay",
149 "rtpmpadepay");
150 run_pipeline (setup_pipeline (s), s,
151 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
152 GST_MESSAGE_UNKNOWN, target_state);
153
154 s = PIPELINE_STRING (DEFAULT_BUFCOUNT, DEFAULT_BUFSIZE, "rtph263ppay",
155 "rtph263pdepay");
156 run_pipeline (setup_pipeline (s), s,
157 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
158 GST_MESSAGE_UNKNOWN, target_state);
159
160 s = PIPELINE_STRING (DEFAULT_BUFCOUNT, DEFAULT_BUFSIZE, "rtph263pay",
161 "rtph263depay");
162 run_pipeline (setup_pipeline (s), s,
163 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
164 GST_MESSAGE_UNKNOWN, target_state);
165
166 s = PIPELINE_STRING (DEFAULT_BUFCOUNT, DEFAULT_BUFSIZE, "rtph264pay",
167 "rtph264depay");
168 run_pipeline (setup_pipeline (s), s,
169 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
170 GST_MESSAGE_UNKNOWN, target_state);
171
172 s = PIPELINE_STRING (DEFAULT_BUFCOUNT, DEFAULT_BUFSIZE, "rtpL16pay",
173 "rtpL16depay");
174 run_pipeline (setup_pipeline (s), s,
175 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
176 GST_MESSAGE_UNKNOWN, target_state);
177
178 s = PIPELINE_STRING (DEFAULT_BUFCOUNT, DEFAULT_BUFSIZE, "rtpmp2tpay",
179 "rtpmp2tdepay");
180 run_pipeline (setup_pipeline (s), s,
181 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
182 GST_MESSAGE_UNKNOWN, target_state);
183
184 s = PIPELINE_STRING (DEFAULT_BUFCOUNT, DEFAULT_BUFSIZE, "rtpmp4vpay",
185 "rtpmp4vdepay");
186 run_pipeline (setup_pipeline (s), s,
187 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
188 GST_MESSAGE_UNKNOWN, target_state);
189
190 s = PIPELINE_STRING (DEFAULT_BUFCOUNT, DEFAULT_BUFSIZE, "rtpmp4gpay",
191 "rtpmp4gdepay");
192 run_pipeline (setup_pipeline (s), s,
193 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
194 GST_MESSAGE_UNKNOWN, target_state);
195
196 /* Cannot be tested with fakesrc because speex payloader requires a valid header?! */
197 /*
198 s = PIPELINE_STRING(DEFAULT_BUFCOUNT, DEFAULT_BUFSIZE, "rtpspeexpay", "rtpspeexdepay");
199 run_pipeline (setup_pipeline (s), s,
200 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
201 GST_MESSAGE_UNKNOWN, target_state);
202 */
203
204 s = PIPELINE_STRING (DEFAULT_BUFCOUNT, DEFAULT_BUFSIZE, "rtptheorapay",
205 "rtptheoradepay");
206 run_pipeline (setup_pipeline (s), s,
207 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
208 GST_MESSAGE_UNKNOWN, target_state);
209
210 s = PIPELINE_STRING (DEFAULT_BUFCOUNT, DEFAULT_BUFSIZE, "rtpvorbispay",
211 "rtpvorbisdepay");
212 run_pipeline (setup_pipeline (s), s,
213 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
214 GST_MESSAGE_UNKNOWN, target_state);
215
216 #define J2K_TEST_FILE_PATH GST_TEST_FILES_PATH G_DIR_SEPARATOR_S "gradient.j2k"
217 #define J2KCAPS "image/x-jpc,sampling=YCbCr-4:2:0,width=720,height=576,pixel-aspect-ratio=1/1,framerate=30/1"
218 {
219 GstElement *pipeline, *src;
220 GstFlowReturn flow = GST_FLOW_OK;
221 GstBuffer *buf;
222 gchar *data;
223 gsize len;
224
225 s = "appsrc caps=" J2KCAPS " name=src ! rtpj2kpay ! rtpj2kdepay ! fakesink";
226
227 fail_unless (g_file_get_contents (J2K_TEST_FILE_PATH, &data, &len, NULL));
228 buf = gst_buffer_new_wrapped (data, len);
229 pipeline = setup_pipeline (s);
230 src = gst_bin_get_by_name (GST_BIN (pipeline), "src");
231 g_object_set (src, "format", GST_FORMAT_TIME, NULL);
232 g_signal_emit_by_name (src, "push-buffer", buf, &flow);
233 gst_buffer_unref (buf);
234 fail_unless_equals_int (flow, GST_FLOW_OK);
235 g_signal_emit_by_name (src, "end-of-stream", &flow);
236 gst_object_unref (src);
237 run_pipeline (pipeline, s,
238 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
239 GST_MESSAGE_UNKNOWN, target_state);
240 }
241
242 /*s = FAKESRC " ! ! rtpac3depay ! " FAKESINK */
243 /*s = FAKESRC " ! ! asteriskh263 ! " FAKESINK; */
244 /*s = FAKESRC " ! ! rtpmpvdepay ! " FAKESINK; */
245 /*s = FAKESRC " ! ! rtpmp4adepay ! " FAKESINK; */
246 /*s = FAKESRC " ! ! rtpsv3vdepay ! " FAKESINK; */
247 }
248
249 GST_END_TEST;
250
251 static gboolean
have_elements(const gchar * element1,const gchar * element2)252 have_elements (const gchar * element1, const gchar * element2)
253 {
254 return gst_registry_check_feature_version (gst_registry_get (), element1,
255 GST_VERSION_MAJOR, GST_VERSION_MINOR, 0) &&
256 gst_registry_check_feature_version (gst_registry_get (), element2,
257 GST_VERSION_MAJOR, GST_VERSION_MINOR, 0);
258 }
259
GST_START_TEST(test_video_encoders_decoders)260 GST_START_TEST (test_video_encoders_decoders)
261 {
262 const gchar *s;
263 GstState target_state = GST_STATE_PLAYING;
264
265 /* no is-live on the source because we actually want to preroll since
266 * run_pipeline only goes into PAUSED */
267 #define ENC_DEC_PIPELINE_STRING(bufcount, enc, dec) "videotestsrc num-buffers=" bufcount " ! " enc " ! " dec " ! fakesink"
268 #define DEFAULT_BUFCOUNT "5"
269
270 if (have_elements ("jpegenc", "jpegdec")) {
271 s = ENC_DEC_PIPELINE_STRING (DEFAULT_BUFCOUNT, "jpegenc", "jpegdec");
272 run_pipeline (setup_pipeline (s), s,
273 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
274 GST_MESSAGE_UNKNOWN, target_state);
275 }
276
277 if (have_elements ("pngenc", "pngdec")) {
278 s = ENC_DEC_PIPELINE_STRING (DEFAULT_BUFCOUNT, "pngenc", "pngdec");
279 run_pipeline (setup_pipeline (s), s,
280 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
281 GST_MESSAGE_UNKNOWN, target_state);
282 }
283
284 if (have_elements ("smokeenc", "smokedec")) {
285 s = ENC_DEC_PIPELINE_STRING (DEFAULT_BUFCOUNT, "smokeenc", "smokedec");
286 run_pipeline (setup_pipeline (s), s,
287 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
288 GST_MESSAGE_UNKNOWN, target_state);
289 }
290 }
291
292 GST_END_TEST;
293
294 #define VIDEOMIXER_PIPELINE \
295 "videomixer name=mix background=transparent ! fakesink " \
296 "videotestsrc num-buffers=50 ! " \
297 " video/x-raw,format=RGBA, width=200,height=200,framerate=10/1 ! " \
298 " videoconvert ! mix.sink_1 " \
299 "videotestsrc num-buffers=50 pattern=smpte ! " \
300 " video/x-raw,format=RGBA, width=720,height=480,framerate=10/1 ! " \
301 " videoconvert ! mix.sink_0 "
302
GST_START_TEST(test_videomixer)303 GST_START_TEST (test_videomixer)
304 {
305 run_pipeline (setup_pipeline (VIDEOMIXER_PIPELINE), VIDEOMIXER_PIPELINE,
306 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
307 GST_MESSAGE_UNKNOWN, GST_STATE_PLAYING);
308 }
309
310 GST_END_TEST;
311
312 #endif /* #ifndef GST_DISABLE_PARSE */
313 static Suite *
simple_launch_lines_suite(void)314 simple_launch_lines_suite (void)
315 {
316 Suite *s = suite_create ("Pipelines");
317 TCase *tc_chain = tcase_create ("linear");
318
319 /* time out after 60s, not the default 3 */
320 tcase_set_timeout (tc_chain, 60);
321
322 suite_add_tcase (s, tc_chain);
323 #ifndef GST_DISABLE_PARSE
324 tcase_add_test (tc_chain, test_rtp_payloaders);
325 tcase_add_test (tc_chain, test_video_encoders_decoders);
326 /* FIXME: very rarely fails, maybe because of negotiation issues? */
327 tcase_add_test (tc_chain, test_videomixer);
328 #endif
329 return s;
330 }
331
332 GST_CHECK_MAIN (simple_launch_lines);
333