Update for _get_state() API change.
[platform/upstream/gstreamer.git] / 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., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22
23 #include <gst/check/gstcheck.h>
24
25
26 static GstElement *
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
46 run_pipeline (GstElement * pipe, const gchar * descr,
47     GstMessageType events, GstMessageType tevent)
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   ret = gst_element_set_state (pipe, GST_STATE_PLAYING);
59   ret = gst_element_get_state (pipe, NULL, NULL, GST_CLOCK_TIME_NONE);
60   if (ret != GST_STATE_CHANGE_SUCCESS) {
61     g_critical ("Couldn't set pipeline to PLAYING");
62     goto done;
63   }
64
65   while (1) {
66     message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 2);
67
68
69     /* always have to pop the message before getting back into poll */
70     if (message) {
71       revent = GST_MESSAGE_TYPE (message);
72       gst_message_unref (message);
73     } else {
74       revent = GST_MESSAGE_UNKNOWN;
75     }
76
77     if (revent == tevent) {
78       break;
79     } else if (revent == GST_MESSAGE_UNKNOWN) {
80       g_critical ("Unexpected timeout in gst_bus_poll, looking for %d: %s",
81           tevent, descr);
82       break;
83     } else if (revent & events) {
84       continue;
85     }
86     g_critical ("Unexpected message received of type %d, looking for %d: %s",
87         revent, tevent, descr);
88   }
89
90 done:
91   gst_element_set_state (pipe, GST_STATE_NULL);
92   gst_object_unref (pipe);
93 }
94
95 GST_START_TEST (test_element_negotiation)
96 {
97   gchar *s;
98
99   /* see http://bugzilla.gnome.org/show_bug.cgi?id=315126 */
100   s = "fakesrc ! audio/x-raw-int,width=16,depth=16,rate=22050,channels=1 ! audioconvert ! audio/x-raw-int,width=16,depth=16,rate=22050,channels=1 ! fakesink";
101   run_pipeline (setup_pipeline (s), s,
102       GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
103       GST_MESSAGE_UNKNOWN);
104
105 #ifdef HAVE_LIBVISUAL
106   s = "sinesrc ! tee name=t ! alsasink t. ! audioconvert ! libvisual_lv_scope ! ffmpegcolorspace ! xvimagesink";
107   run_pipeline (setup_pipeline (s), s,
108       GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
109       GST_MESSAGE_UNKNOWN);
110 #endif
111 }
112
113 GST_END_TEST
114 GST_START_TEST (test_basetransform_based)
115 {
116   /* Each of these tests is to check whether various basetransform based elements can
117    * select output caps when not allowed to do passthrough and going to a generic sink
118    * such as fakesink or filesink */
119   const gchar *s;
120
121   /* Check that videoscale can pick a height given only a width */
122   s = "videotestsrc ! video/x-raw-yuv,format=(fourcc)I420,width=320,height=240 ! " "videoscale ! video/x-raw-yuv,width=640 ! fakesink";
123   run_pipeline (setup_pipeline (s), s,
124       GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
125       GST_MESSAGE_UNKNOWN);
126
127   /* Test that ffmpegcolorspace can pick an output format that isn't passthrough without 
128    * completely specified output caps */
129   s = "videotestsrc ! video/x-raw-yuv,format=(fourcc)I420,width=320,height=240 ! " "ffmpegcolorspace ! video/x-raw-rgb ! fakesink";
130   run_pipeline (setup_pipeline (s), s,
131       GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
132       GST_MESSAGE_UNKNOWN);
133
134   /* Check that audioresample can pick a samplerate to use from a 
135    * range that doesn't include the input */
136   s = "sinesrc ! audio/x-raw-int,width=16,depth=16,rate=8000 ! audioresample ! "
137       "audio/x-raw-int,rate=[16000,48000] ! fakesink";
138   run_pipeline (setup_pipeline (s), s,
139       GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
140       GST_MESSAGE_UNKNOWN);
141
142   /* Check that audioconvert can pick a depth to use, given a width */
143   s = "sinesrc ! audio/x-raw-int,width=16,depth=16 ! audioconvert ! "
144       "audio/x-raw-int,width=32 ! fakesink";
145   run_pipeline (setup_pipeline (s), s,
146       GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
147       GST_MESSAGE_UNKNOWN);
148 }
149 GST_END_TEST Suite *
150 simple_launch_lines_suite (void)
151 {
152   Suite *s = suite_create ("Pipelines");
153   TCase *tc_chain = tcase_create ("linear");
154
155   /* time out after 20s, not the default 3 */
156   tcase_set_timeout (tc_chain, 20);
157
158   suite_add_tcase (s, tc_chain);
159 //  tcase_add_test (tc_chain, test_element_negotiation);
160   tcase_add_test (tc_chain, test_basetransform_based);
161   return s;
162 }
163
164 int
165 main (int argc, char **argv)
166 {
167   int nf;
168
169   Suite *s = simple_launch_lines_suite ();
170   SRunner *sr = srunner_create (s);
171
172   gst_check_init (&argc, &argv);
173
174   srunner_run_all (sr, CK_NORMAL);
175   nf = srunner_ntests_failed (sr);
176   srunner_free (sr);
177
178   return nf;
179 }