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., 51 Franklin St, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #include <gst/check/gstcheck.h>
24 #include <gst/audio/audio-format.h>
26 #ifndef GST_DISABLE_PARSE
29 setup_pipeline (const gchar * pipe_descr)
33 GST_LOG ("pipeline: %s", pipe_descr);
34 pipeline = gst_parse_launch (pipe_descr, NULL);
35 g_return_val_if_fail (GST_IS_PIPELINE (pipeline), NULL);
41 * @pipe: the pipeline to run
42 * @desc: the description for use in messages
43 * @events: is a mask of expected events
44 * @tevent: is the expected terminal event.
46 * the poll call will time out after half a second.
49 run_pipeline (GstElement * pipe, const gchar * descr,
50 GstMessageType events, GstMessageType tevent)
54 GstMessageType revent;
55 GstStateChangeReturn ret;
58 bus = gst_element_get_bus (pipe);
61 fail_if (gst_element_set_state (pipe, GST_STATE_PLAYING) ==
62 GST_STATE_CHANGE_FAILURE, "Could not set pipeline %s to playing", descr);
63 ret = gst_element_get_state (pipe, NULL, NULL, 10 * GST_SECOND);
64 if (ret == GST_STATE_CHANGE_ASYNC) {
65 g_critical ("Pipeline '%s' failed to go to PLAYING fast enough", descr);
67 } else if (ret != GST_STATE_CHANGE_SUCCESS) {
68 g_critical ("Pipeline '%s' failed to go into PLAYING state", descr);
73 message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 2);
76 /* always have to pop the message before getting back into poll */
78 revent = GST_MESSAGE_TYPE (message);
79 gst_message_unref (message);
81 revent = GST_MESSAGE_UNKNOWN;
84 if (revent == tevent) {
86 } else if (revent == GST_MESSAGE_UNKNOWN) {
87 g_critical ("Unexpected timeout in gst_bus_poll, looking for %d: %s",
90 } else if (revent & events) {
94 ("Unexpected message received of type %d, '%s', looking for %d: %s",
95 revent, gst_message_type_get_name (revent), tevent, descr);
99 fail_if (gst_element_set_state (pipe, GST_STATE_NULL) ==
100 GST_STATE_CHANGE_FAILURE, "Could not set pipeline %s to NULL", descr);
101 gst_element_get_state (pipe, NULL, NULL, GST_CLOCK_TIME_NONE);
102 gst_object_unref (pipe);
104 gst_bus_set_flushing (bus, TRUE);
105 gst_object_unref (bus);
108 GST_START_TEST (test_element_negotiation)
112 /* Ensures that filtering buffers with unknown caps down to fixed-caps
113 * will apply those caps to the buffers.
114 * see http://bugzilla.gnome.org/show_bug.cgi?id=315126 */
115 s = "fakesrc num-buffers=2 ! "
116 "audio/x-raw,format=" GST_AUDIO_NE (S16) ",rate=22050,channels=1 "
118 "! audio/x-raw,format=" GST_AUDIO_NE (S16) ",rate=22050,channels=1 "
120 run_pipeline (setup_pipeline (s), s,
121 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
122 GST_MESSAGE_UNKNOWN);
124 #ifdef HAVE_LIBVISUAL
125 s = "audiotestsrc num-buffers=30 ! tee name=t ! alsasink t. ! audioconvert ! "
126 "libvisual_lv_scope ! videoconvert ! xvimagesink";
127 run_pipeline (setup_pipeline (s), s,
128 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
129 GST_MESSAGE_UNKNOWN);
135 GST_START_TEST (test_basetransform_based)
137 /* Each of these tests is to check whether various basetransform based
138 * elements can select output caps when not allowed to do passthrough
139 * and going to a generic sink such as fakesink or filesink */
142 /* Check that videoscale can pick a height given only a width */
143 s = "videotestsrc num-buffers=2 ! "
144 "video/x-raw,format=(string)I420,width=320,height=240 ! "
145 "videoscale ! video/x-raw,width=640 ! fakesink";
146 run_pipeline (setup_pipeline (s), s,
147 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
148 GST_MESSAGE_UNKNOWN);
150 /* Test that videoconvert can pick an output format that isn't
151 * passthrough without completely specified output caps */
152 s = "videotestsrc num-buffers=2 ! "
153 "video/x-raw,format=(string)I420,width=320,height=240 ! "
154 "videoconvert ! video/x-raw,format=(string)RGB ! fakesink";
155 run_pipeline (setup_pipeline (s), s,
156 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
157 GST_MESSAGE_UNKNOWN);
159 /* Check that audioresample can pick a samplerate to use from a
160 * range that doesn't include the input */
161 s = "audiotestsrc num-buffers=2 ! "
162 "audio/x-raw,format=" GST_AUDIO_NE (S16) ",rate=8000 ! "
163 "audioresample ! audio/x-raw,rate=[16000,48000] ! fakesink";
164 run_pipeline (setup_pipeline (s), s,
165 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
166 GST_MESSAGE_UNKNOWN);
168 /* Check that audioconvert can pick a depth to use, given a width */
169 s = "audiotestsrc num-buffers=30 ! audio/x-raw,format=" GST_AUDIO_NE (S16)
170 " ! audioconvert ! " "audio/x-raw,format=" GST_AUDIO_NE (S32)
172 run_pipeline (setup_pipeline (s), s,
173 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
174 GST_MESSAGE_UNKNOWN);
176 /* Check that videoscale doesn't claim to be able to transform input in
177 * formats it can't handle for a given scaling method; videoconvert
178 * should then make sure a format that can be handled is chosen (4-tap
179 * scaling is not implemented for RGB and packed yuv currently) */
180 s = "videotestsrc num-buffers=2 ! video/x-raw,format=(string)ARGB64 ! "
181 "videoconvert ! videoscale method=4-tap ! videoconvert ! "
182 "video/x-raw,format=(string)RGB, width=32,height=32,framerate=(fraction)30/1,"
183 "pixel-aspect-ratio=(fraction)1/1 ! 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,format=(string)AYUV,"
188 "width=64,height=64 ! videoconvert ! videoscale method=4-tap ! "
189 "videoconvert ! video/x-raw,format=(string)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,format=(string)I420,"
197 "width=64,height=64 ! videoconvert ! videoscale method=4-tap ! "
198 "videoconvert ! video/x-raw,format=(string)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);
204 s = "videotestsrc num-buffers=2 ! "
205 "video/x-raw,format=(string)Y41B,interlace-mode=interlaced ! "
206 "videoconvert ! video/x-raw,format=UYVY ! " "fakesink";
207 run_pipeline (setup_pipeline (s), s,
208 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
209 GST_MESSAGE_UNKNOWN);
214 #endif /* #ifndef GST_DISABLE_PARSE */
216 simple_launch_lines_suite (void)
218 Suite *s = suite_create ("Pipelines");
219 TCase *tc_chain = tcase_create ("linear");
221 /* time out after 60s, not the default 3 */
222 tcase_set_timeout (tc_chain, 60);
224 suite_add_tcase (s, tc_chain);
225 #ifndef GST_DISABLE_PARSE
226 tcase_add_test (tc_chain, test_element_negotiation);
227 tcase_add_test (tc_chain, test_basetransform_based);
233 main (int argc, char **argv)
237 Suite *s = simple_launch_lines_suite ();
238 SRunner *sr = srunner_create (s);
240 gst_check_init (&argc, &argv);
242 srunner_run_all (sr, CK_NORMAL);
243 nf = srunner_ntests_failed (sr);