2 * Copyright (C) 2005 Luca Ognibene <luogni@tin.it>
3 * Based (copied) on simple_launch_lines.c
5 * ffmpeg-lock.c: Unit test for libavcodec's locks
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
24 #include <gst/check/gstcheck.h>
30 setup_pipeline (const gchar * 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 ret = gst_element_set_state (pipe, GST_STATE_PLAYING);
62 ret = gst_element_get_state (pipe, NULL, NULL, GST_CLOCK_TIME_NONE);
63 if (ret != GST_STATE_CHANGE_SUCCESS) {
64 g_critical ("Couldn't set pipeline to PLAYING");
69 message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 2);
71 /* always have to pop the message before getting back into poll */
73 revent = GST_MESSAGE_TYPE (message);
74 gst_message_unref (message);
76 revent = GST_MESSAGE_UNKNOWN;
79 if (revent == tevent) {
81 } else if (revent == GST_MESSAGE_UNKNOWN) {
82 g_critical ("Unexpected timeout in gst_bus_poll, looking for %d: %s",
85 } else if (revent & events) {
89 ("Unexpected message received of type %d, '%s', looking for %d: %s",
90 revent, gst_message_type_get_name (revent), tevent, descr);
94 gst_element_set_state (pipe, GST_STATE_NULL);
95 gst_object_unref (pipe);
98 GST_START_TEST (test_libavcodec_locks)
100 gchar *sink[NUM_SINKS + 1], *s, *sinks;
103 for (i = 0; i < NUM_SINKS; i++)
106 (" t.src%d ! queue ! ffenc_mpeg4 ! ffdec_mpeg4 ! fakesink sync=true",
109 sink[NUM_SINKS] = NULL;
111 sinks = g_strjoinv (" ", sink);
114 ("videotestsrc ! video/x-raw-yuv,format=(fourcc)I420,width=320,height=240,framerate=(fraction)10/1 ! tee name=t %s",
117 run_pipeline (setup_pipeline (s), s,
118 GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
119 GST_MESSAGE_UNKNOWN);
122 for (i = 0; i < NUM_SINKS; i++)
130 simple_launch_lines_suite (void)
134 Suite *s = suite_create ("Pipelines");
135 TCase *tc_chain = tcase_create ("linear");
137 if (g_getenv ("CK_DEFAULT_TIMEOUT"))
138 timeout = atoi (g_getenv ("CK_DEFAULT_TIMEOUT"));
143 /* set multiple of default timeout (random magic value) */
144 tcase_set_timeout (tc_chain, timeout * 12);
146 suite_add_tcase (s, tc_chain);
148 #ifndef GST_DISABLE_PARSE
149 /* only run this if we haven't been configured with --disable-encoders */
150 if (gst_default_registry_check_feature_version ("ffenc_mpeg4",
151 GST_VERSION_MAJOR, GST_VERSION_MINOR, 0)) {
152 tcase_add_test (tc_chain, test_libavcodec_locks);
154 g_print ("******* Skipping libavcodec_locks test, no encoder available\n");
162 main (int argc, char **argv)
168 gst_check_init (&argc, &argv);
170 s = simple_launch_lines_suite ();
171 sr = srunner_create (s);
173 srunner_run_all (sr, CK_NORMAL);
174 nf = srunner_ntests_failed (sr);