68f71002ad3346e1b90d05a9d46f235ae0fcc532
[platform/upstream/gstreamer.git] / tests / check / pipelines / simple-launch-lines.c
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
23 #include <gst/check/gstcheck.h>
24 #include <gst/audio/audio-format.h>
25
26 #ifndef GST_DISABLE_PARSE
27
28 static GstElement *
29 setup_pipeline (const gchar * pipe_descr)
30 {
31   GstElement *pipeline;
32
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);
36   return pipeline;
37 }
38
39 /* 
40  * run_pipeline:
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.
45  *
46  * the poll call will time out after half a second.
47  */
48 static void
49 run_pipeline (GstElement * pipe, const gchar * descr,
50     GstMessageType events, GstMessageType tevent)
51 {
52   GstBus *bus;
53   GstMessage *message;
54   GstMessageType revent;
55   GstStateChangeReturn ret;
56
57   g_assert (pipe);
58   bus = gst_element_get_bus (pipe);
59   g_assert (bus);
60
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);
66     goto done;
67   } else if (ret != GST_STATE_CHANGE_SUCCESS) {
68     g_critical ("Pipeline '%s' failed to go into PLAYING state", descr);
69     goto done;
70   }
71
72   while (1) {
73     message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 2);
74
75
76     /* always have to pop the message before getting back into poll */
77     if (message) {
78       revent = GST_MESSAGE_TYPE (message);
79       gst_message_unref (message);
80     } else {
81       revent = GST_MESSAGE_UNKNOWN;
82     }
83
84     if (revent == tevent) {
85       break;
86     } else if (revent == GST_MESSAGE_UNKNOWN) {
87       g_critical ("Unexpected timeout in gst_bus_poll, looking for %d: %s",
88           tevent, descr);
89       break;
90     } else if (revent & events) {
91       continue;
92     }
93     g_critical
94         ("Unexpected message received of type %d, '%s', looking for %d: %s",
95         revent, gst_message_type_get_name (revent), tevent, descr);
96   }
97
98 done:
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);
103
104   gst_bus_set_flushing (bus, TRUE);
105   gst_object_unref (bus);
106 }
107
108 GST_START_TEST (test_element_negotiation)
109 {
110   const gchar *s;
111
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 "
117       "! audioconvert "
118       "! audio/x-raw,format=" GST_AUDIO_NE (S16) ",rate=22050,channels=1 "
119       "! fakesink";
120   run_pipeline (setup_pipeline (s), s,
121       GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
122       GST_MESSAGE_UNKNOWN);
123
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);
130 #endif
131 }
132
133 GST_END_TEST;
134
135 GST_START_TEST (test_basetransform_based)
136 {
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 */
140   const gchar *s;
141
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);
149
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);
158
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);
167
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)
171       " ! fakesink";
172   run_pipeline (setup_pipeline (s), s,
173       GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
174       GST_MESSAGE_UNKNOWN);
175
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);
203
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);
210 }
211
212 GST_END_TEST;
213
214 #endif /* #ifndef GST_DISABLE_PARSE */
215 static Suite *
216 simple_launch_lines_suite (void)
217 {
218   Suite *s = suite_create ("Pipelines");
219   TCase *tc_chain = tcase_create ("linear");
220
221   /* time out after 60s, not the default 3 */
222   tcase_set_timeout (tc_chain, 60);
223
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);
228 #endif
229   return s;
230 }
231
232 int
233 main (int argc, char **argv)
234 {
235   int nf;
236
237   Suite *s = simple_launch_lines_suite ();
238   SRunner *sr = srunner_create (s);
239
240   gst_check_init (&argc, &argv);
241
242   srunner_run_all (sr, CK_NORMAL);
243   nf = srunner_ntests_failed (sr);
244   srunner_free (sr);
245
246   return nf;
247 }