2 * Copyright (C) 2005 Andy Wingo <wingo@pobox.com>
4 * simple_launch_lines.c: Unit test for simple pipelines
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.
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.
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., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
23 #include <gst/check/gstcheck.h>
25 #ifndef GST_DISABLE_PARSE
28 setup_pipeline (const gchar * pipe_descr)
32 GST_LOG ("pipeline: %s", pipe_descr);
33 pipeline = gst_parse_launch (pipe_descr, NULL);
34 g_return_val_if_fail (GST_IS_PIPELINE (pipeline), NULL);
40 * @pipe: the pipeline to run
41 * @desc: the description for use in messages
42 * @events: is a mask of expected events
43 * @tevent: is the expected terminal event.
45 * the poll call will time out after half a second.
48 run_pipeline (GstElement * pipe, const gchar * descr,
49 GstMessageType events, GstMessageType tevent)
53 GstMessageType revent;
54 GstStateChangeReturn ret;
57 bus = gst_element_get_bus (pipe);
60 fail_if (gst_element_set_state (pipe, GST_STATE_PLAYING) ==
61 GST_STATE_CHANGE_FAILURE, "Could not set pipeline %s to playing", descr);
62 ret = gst_element_get_state (pipe, NULL, NULL, 10 * GST_SECOND);
63 if (ret == GST_STATE_CHANGE_ASYNC) {
64 g_critical ("Pipeline '%s' failed to go to PLAYING fast enough", descr);
66 } else if (ret != GST_STATE_CHANGE_SUCCESS) {
67 g_critical ("Pipeline '%s' failed to go into PLAYING state", descr);
72 message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 2);
75 /* always have to pop the message before getting back into poll */
77 revent = GST_MESSAGE_TYPE (message);
78 gst_message_unref (message);
80 revent = GST_MESSAGE_UNKNOWN;
83 if (revent == tevent) {
85 } else if (revent == GST_MESSAGE_UNKNOWN) {
86 g_critical ("Unexpected timeout in gst_bus_poll, looking for %d: %s",
89 } else if (revent & events) {
93 ("Unexpected message received of type %d, '%s', looking for %d: %s",
94 revent, gst_message_type_get_name (revent), tevent, descr);
98 fail_if (gst_element_set_state (pipe, GST_STATE_NULL) ==
99 GST_STATE_CHANGE_FAILURE, "Could not set pipeline %s to NULL", descr);
100 gst_element_get_state (pipe, NULL, NULL, GST_CLOCK_TIME_NONE);
101 gst_object_unref (pipe);
103 gst_bus_set_flushing (bus, TRUE);
104 gst_object_unref (bus);
107 GST_START_TEST (test_element_negotiation)
111 /* Ensures that filtering buffers with unknown caps down to fixed-caps
112 * will apply those caps to the buffers.
113 * see http://bugzilla.gnome.org/show_bug.cgi?id=315126 */
114 s = "fakesrc num-buffers=2 ! "
115 "audio/x-raw-int,width=16,depth=16,rate=22050,channels=1,"
116 "signed=(boolean)true,endianness=1234 ! "
117 "audioconvert ! audio/x-raw-int,width=16,depth=16,rate=22050,channels=1 "
119 run_pipeline (setup_pipeline (s), s,
120 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
121 GST_MESSAGE_UNKNOWN);
123 #ifdef HAVE_LIBVISUAL
124 s = "audiotestsrc num-buffers=30 ! tee name=t ! alsasink t. ! audioconvert ! "
125 "libvisual_lv_scope ! ffmpegcolorspace ! xvimagesink";
126 run_pipeline (setup_pipeline (s), s,
127 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
128 GST_MESSAGE_UNKNOWN);
134 GST_START_TEST (test_basetransform_based)
136 /* Each of these tests is to check whether various basetransform based
137 * elements can select output caps when not allowed to do passthrough
138 * and going to a generic sink such as fakesink or filesink */
141 /* Check that videoscale can pick a height given only a width */
142 s = "videotestsrc num-buffers=2 ! "
143 "video/x-raw-yuv,format=(fourcc)I420,width=320,height=240 ! "
144 "videoscale ! video/x-raw-yuv,width=640 ! fakesink";
145 run_pipeline (setup_pipeline (s), s,
146 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
147 GST_MESSAGE_UNKNOWN);
149 /* Test that ffmpegcolorspace can pick an output format that isn't
150 * passthrough without completely specified output caps */
151 s = "videotestsrc num-buffers=2 ! "
152 "video/x-raw-yuv,format=(fourcc)I420,width=320,height=240 ! "
153 "ffmpegcolorspace ! video/x-raw-rgb ! fakesink";
154 run_pipeline (setup_pipeline (s), s,
155 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
156 GST_MESSAGE_UNKNOWN);
158 /* Check that audioresample can pick a samplerate to use from a
159 * range that doesn't include the input */
160 s = "audiotestsrc num-buffers=2 ! "
161 "audio/x-raw-int,width=16,depth=16,rate=8000 ! "
162 "audioresample ! audio/x-raw-int,rate=[16000,48000] ! fakesink";
163 run_pipeline (setup_pipeline (s), s,
164 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
165 GST_MESSAGE_UNKNOWN);
167 /* Check that audioconvert can pick a depth to use, given a width */
168 s = "audiotestsrc num-buffers=30 ! audio/x-raw-int,width=16,depth=16 ! "
169 "audioconvert ! " "audio/x-raw-int,width=32 ! fakesink";
170 run_pipeline (setup_pipeline (s), s,
171 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
172 GST_MESSAGE_UNKNOWN);
174 /* Check that videoscale doesn't claim to be able to transform input in
175 * formats it can't handle for a given scaling method; ffmpegcolorspace
176 * should then make sure a format that can be handled is chosen (4-tap
177 * scaling is not implemented for RGB and packed yuv currently) */
178 s = "videotestsrc num-buffers=2 ! video/x-raw-rgb,width=64,height=64 ! "
179 "ffmpegcolorspace ! videoscale method=4-tap ! ffmpegcolorspace ! "
180 "video/x-raw-rgb,width=32,height=32,framerate=(fraction)30/1,"
181 "pixel-aspect-ratio=(fraction)1/1,bpp=(int)24,depth=(int)24,"
182 "red_mask=(int)16711680,green_mask=(int)65280,blue_mask=(int)255,"
183 "endianness=(int)4321 ! fakesink";
184 run_pipeline (setup_pipeline (s), s,
185 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
186 GST_MESSAGE_UNKNOWN);
187 s = "videotestsrc num-buffers=2 ! video/x-raw-yuv,format=(fourcc)AYUV,"
188 "width=64,height=64 ! ffmpegcolorspace ! videoscale method=4-tap ! "
189 "ffmpegcolorspace ! video/x-raw-yuv,format=(fourcc)AYUV,width=32,"
190 "height=32 ! fakesink";
191 run_pipeline (setup_pipeline (s), s,
192 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
193 GST_MESSAGE_UNKNOWN);
194 /* make sure nothing funny happens in passthrough mode (we don't check that
195 * passthrough mode is chosen though) */
196 s = "videotestsrc num-buffers=2 ! video/x-raw-yuv,format=(fourcc)I420,"
197 "width=64,height=64 ! ffmpegcolorspace ! videoscale method=4-tap ! "
198 "ffmpegcolorspace ! video/x-raw-yuv,format=(fourcc)I420,width=32,"
199 "height=32 ! fakesink";
200 run_pipeline (setup_pipeline (s), s,
201 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
202 GST_MESSAGE_UNKNOWN);
207 #endif /* #ifndef GST_DISABLE_PARSE */
209 simple_launch_lines_suite (void)
211 Suite *s = suite_create ("Pipelines");
212 TCase *tc_chain = tcase_create ("linear");
214 /* time out after 60s, not the default 3 */
215 tcase_set_timeout (tc_chain, 60);
217 suite_add_tcase (s, tc_chain);
218 #ifndef GST_DISABLE_PARSE
219 tcase_add_test (tc_chain, test_element_negotiation);
220 tcase_add_test (tc_chain, test_basetransform_based);
226 main (int argc, char **argv)
230 Suite *s = simple_launch_lines_suite ();
231 SRunner *sr = srunner_create (s);
233 gst_check_init (&argc, &argv);
235 srunner_run_all (sr, CK_NORMAL);
236 nf = srunner_ntests_failed (sr);