• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* GStreamer
2  * Copyright (C) 2005 Luca Ognibene <luogni@tin.it>
3  * Based (copied) on simple_launch_lines.c
4  *
5  * libavcodec-locking.c: Unit test for libavcodec's locks
6  *
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.
11  *
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.
16  *
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., 51 Franklin St, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 
24 #include <gst/check/gstcheck.h>
25 #include <stdlib.h>
26 
27 #define NUM_SINKS 10
28 
29 static GstElement *
setup_pipeline(const gchar * pipe_descr)30 setup_pipeline (const gchar * pipe_descr)
31 {
32   GstElement *pipeline;
33 
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
run_pipeline(GstElement * pipe,const gchar * descr,GstMessageType events,GstMessageType tevent)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   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");
65     goto done;
66   }
67 
68   while (1) {
69     message = gst_bus_poll (bus, GST_MESSAGE_ANY, GST_SECOND / 2);
70 
71     /* always have to pop the message before getting back into poll */
72     if (message) {
73       revent = GST_MESSAGE_TYPE (message);
74       gst_message_unref (message);
75     } else {
76       revent = GST_MESSAGE_UNKNOWN;
77     }
78 
79     if (revent == tevent) {
80       break;
81     } else if (revent == GST_MESSAGE_UNKNOWN) {
82       g_critical ("Unexpected timeout in gst_bus_poll, looking for %d: %s",
83           tevent, descr);
84       break;
85     } else if (revent & events) {
86       continue;
87     }
88     g_critical
89         ("Unexpected message received of type %d, '%s', looking for %d: %s",
90         revent, gst_message_type_get_name (revent), tevent, descr);
91   }
92 
93 done:
94   gst_element_set_state (pipe, GST_STATE_NULL);
95   gst_object_unref (pipe);
96 }
97 
GST_START_TEST(test_libavcodec_locks)98 GST_START_TEST (test_libavcodec_locks)
99 {
100   gchar *sink[NUM_SINKS + 1], *s, *sinks;
101   gint i;
102 
103   for (i = 0; i < NUM_SINKS; i++)
104     sink[i] =
105         g_strdup_printf
106         (" t.src_%u ! queue ! avenc_mpeg4 ! avdec_mpeg4 ! fakesink sync=true",
107         i);
108 
109   sink[NUM_SINKS] = NULL;
110 
111   sinks = g_strjoinv (" ", sink);
112 
113   s = g_strdup_printf
114       ("videotestsrc ! video/x-raw,format=(string)I420,width=320,height=240,framerate=(fraction)10/1 ! tee name=t %s",
115       sinks);
116 
117   run_pipeline (setup_pipeline (s), s,
118       GST_MESSAGE_ANY & ~(GST_MESSAGE_ERROR | GST_MESSAGE_WARNING),
119       GST_MESSAGE_UNKNOWN);
120   g_free (s);
121 
122   for (i = 0; i < NUM_SINKS; i++)
123     g_free (sink[i]);
124   g_free (sinks);
125 }
126 
127 GST_END_TEST;
128 
129 static Suite *
simple_launch_lines_suite(void)130 simple_launch_lines_suite (void)
131 {
132   gint timeout = 0;
133 
134   Suite *s = suite_create ("Pipelines");
135   TCase *tc_chain = tcase_create ("linear");
136 
137   if (g_getenv ("CK_DEFAULT_TIMEOUT"))
138     timeout = atoi (g_getenv ("CK_DEFAULT_TIMEOUT"));
139 
140   if (timeout == 0)
141     timeout = 3;
142 
143   /* set multiple of default timeout (random magic value) */
144   tcase_set_timeout (tc_chain, timeout * 12);
145 
146   suite_add_tcase (s, tc_chain);
147 
148 #ifndef GST_DISABLE_PARSE
149   /* only run this if we haven't been configured with --disable-encoders */
150   if (gst_registry_check_feature_version (gst_registry_get (), "avenc_mpeg4",
151           GST_VERSION_MAJOR, GST_VERSION_MINOR, 0)) {
152     tcase_add_test (tc_chain, test_libavcodec_locks);
153   } else {
154     g_print ("******* Skipping libavcodec_locks test, no encoder available\n");
155   }
156 #endif
157 
158   return s;
159 }
160 
161 GST_CHECK_MAIN (simple_launch_lines);
162