Tizen 2.0 Release
[framework/multimedia/gst-plugins-good0.10.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., 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21
22 #include <gst/check/gstcheck.h>
23
24 #ifndef GST_DISABLE_PARSE
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, 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
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 becouse 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   /*s = FAKESRC " ! ! rtpac3depay ! " FAKESINK */
217   /*s = FAKESRC " ! ! asteriskh263 ! " FAKESINK; */
218   /*s = FAKESRC " ! ! rtpmpvdepay ! " FAKESINK; */
219   /*s = FAKESRC " ! ! rtpmp4adepay ! " FAKESINK; */
220   /*s = FAKESRC " ! ! rtpsv3vdepay ! " FAKESINK; */
221 }
222
223 GST_END_TEST
224 GST_START_TEST (test_video_encoders_decoders)
225 {
226   const gchar *s;
227   GstState target_state = GST_STATE_PLAYING;
228
229   /* no is-live on the source because we actually want to preroll since
230    * run_pipeline only goes into PAUSED */
231 #define ENC_DEC_PIPELINE_STRING(bufcount, enc, dec) "videotestsrc num-buffers=" bufcount " ! " enc " ! " dec " ! fakesink"
232 #define DEFAULT_BUFCOUNT "5"
233
234   s = ENC_DEC_PIPELINE_STRING (DEFAULT_BUFCOUNT, "jpegenc", "jpegdec");
235   run_pipeline (setup_pipeline (s), s,
236       GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
237       GST_MESSAGE_UNKNOWN, target_state);
238
239   s = ENC_DEC_PIPELINE_STRING (DEFAULT_BUFCOUNT, "pngenc", "pngdec");
240   run_pipeline (setup_pipeline (s), s,
241       GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
242       GST_MESSAGE_UNKNOWN, target_state);
243
244   s = ENC_DEC_PIPELINE_STRING (DEFAULT_BUFCOUNT, "smokeenc", "smokedec");
245   run_pipeline (setup_pipeline (s), s,
246       GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
247       GST_MESSAGE_UNKNOWN, target_state);
248 }
249
250 GST_END_TEST
251 #endif /* #ifndef GST_DISABLE_PARSE */
252 static Suite *
253 simple_launch_lines_suite (void)
254 {
255   Suite *s = suite_create ("Pipelines");
256   TCase *tc_chain = tcase_create ("linear");
257
258   /* time out after 60s, not the default 3 */
259   tcase_set_timeout (tc_chain, 60);
260
261   suite_add_tcase (s, tc_chain);
262 #ifndef GST_DISABLE_PARSE
263   tcase_add_test (tc_chain, test_rtp_payloaders);
264   tcase_add_test (tc_chain, test_video_encoders_decoders);
265 #endif
266   return s;
267 }
268
269 int
270 main (int argc, char **argv)
271 {
272   int nf;
273
274   Suite *s = simple_launch_lines_suite ();
275   SRunner *sr = srunner_create (s);
276
277   gst_check_init (&argc, &argv);
278
279   srunner_run_all (sr, CK_NORMAL);
280   nf = srunner_ntests_failed (sr);
281   srunner_free (sr);
282
283   return nf;
284 }