1 From d1d935579a6248dd10a6681f130404519f815276 Mon Sep 17 00:00:00 2001
2 From: Maemo Multimedia <multimedia@maemo.org>
3 Date: Thu, 22 Jan 2009 09:57:49 +0200
4 Subject: [PATCH] Startup benchmarking test
8 tests/benchmarks/Makefile.am | 4 +
9 tests/benchmarks/startup.c | 255 ++++++++++++++++++++++++++++++++++++++++++
10 3 files changed, 260 insertions(+), 0 deletions(-)
11 create mode 100644 tests/benchmarks/Makefile.am
12 create mode 100644 tests/benchmarks/startup.c
14 diff --git a/configure.ac b/configure.ac
15 index 4de8751..a7e72c6 100644
18 @@ -1003,6 +1003,7 @@ pkgconfig/gstreamer-video-uninstalled.pc
19 pkgconfig/gstreamer-plugins-base.pc
20 pkgconfig/gstreamer-plugins-base-uninstalled.pc
22 +tests/benchmarks/Makefile
24 tests/examples/Makefile
25 tests/examples/app/Makefile
26 diff --git a/tests/benchmarks/Makefile.am b/tests/benchmarks/Makefile.am
28 index 0000000..93a2440
30 +++ b/tests/benchmarks/Makefile.am
32 +noinst_PROGRAMS = startup
34 +AM_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS)
36 diff --git a/tests/benchmarks/startup.c b/tests/benchmarks/startup.c
38 index 0000000..4d39f9d
40 +++ b/tests/benchmarks/startup.c
46 +GList *sink_list = NULL;
47 +GMainLoop *loop = NULL;
48 +GstClockTime generic_start;
49 +GstClockTime generic_end;
50 +GstClockTime null_start;
51 +GstClockTime paused_start;
52 +GstClockTime playing_end;
57 +gst_get_current_time (void)
61 + g_get_current_time (&tv);
62 + return GST_TIMEVAL_TO_TIME (tv);
65 +void dbin_dpad_cb (GstElement* e,
70 + GstElement *pipeline;
72 + gboolean audio = FALSE;
74 + pipeline = (GstElement *) user_data;
76 + padcaps = gst_pad_get_caps (pad);
82 + stru = gst_caps_get_structure ((const GstCaps *) padcaps, 0);
83 + name = gst_structure_get_name (stru);
84 + if (g_strrstr (name, "audio/x-raw")) {
87 + gst_caps_unref (padcaps);
92 + GstElement *conv, *resamp, *sink;
94 + GstPad *spad, *gpad;
96 + printf ("creating audio bin\n");
98 + bin = (GstBin *) gst_bin_new ("abin");
99 + gst_object_ref (bin);
100 + gst_object_sink (bin);
102 + conv = gst_element_factory_make ("audioconvert", "aconv");
103 + resamp = gst_element_factory_make ("audioresample", "aresample");
104 + sink = gst_element_factory_make ("autoaudiosink", "audiosink");
106 + gst_bin_add_many (bin, conv, resamp, sink, NULL);
107 + gst_element_link_pads (conv, "src", resamp, "sink");
108 + gst_element_link_pads (resamp, "src", sink, "sink");
110 + gst_bin_add (GST_BIN_CAST (pipeline), GST_ELEMENT_CAST (bin));
112 + spad = gst_element_get_static_pad (conv, "sink");
113 + gpad = gst_ghost_pad_new ("sink", spad);
114 + gst_element_add_pad (GST_ELEMENT_CAST (bin), gpad);
115 + gst_object_unref (spad);
117 + gst_pad_link (pad, gpad);
118 + sink_list = g_list_append (sink_list, bin);
123 + sink = gst_element_factory_make ("alsasink", "audiosink");
124 + gst_bin_add (GST_BIN_CAST (pipeline), sink);
125 + gst_element_set_state (sink, GST_STATE_PAUSED);
126 + spad = gst_element_get_static_pad (sink, "sink");
127 + gst_pad_link (pad, spad);
128 + gst_object_unref (spad);
129 + sink_list = g_list_append (sink_list, sink);
137 + printf ("creating fakesink for non-audio pad\n");
139 + fsink = gst_element_factory_make ("fakesink", NULL);
140 + sink_list = g_list_append (sink_list, fsink);
141 + gst_element_set_state (fsink, GST_STATE_PAUSED);
142 + gst_bin_add (GST_BIN_CAST (pipeline), fsink);
143 + fsinkpad = gst_element_get_static_pad (fsink, "sink");
144 + gst_pad_link (pad, fsinkpad);
145 + gst_object_unref (fsinkpad);
151 +metadata_bus_async_cb (GstBus *bus, GstMessage *msg, gpointer data)
153 + GError *error = NULL;
154 + GstElement *pipeline = (GstElement *) data;
155 + gboolean stop = FALSE;
157 + switch (GST_MESSAGE_TYPE (msg)) {
158 + case GST_MESSAGE_ERROR:
159 + gst_message_parse_error (msg, &error, NULL);
160 + printf ("ERROR: %s\n", error->message);
161 + g_error_free (error);
164 + case GST_MESSAGE_EOS:
168 + case GST_MESSAGE_STATE_CHANGED:
170 + GstElement *sender = (GstElement *) GST_MESSAGE_SRC (msg);
171 + if (sender == pipeline) {
173 + gst_message_parse_state_changed (msg, NULL, &newstate, NULL);
174 + if (newstate == GST_STATE_PLAYING) {
176 + system ("opcontrol --stop");
177 + printf ("=== PROFILER STOPPED ===\n");
179 + playing_end = gst_get_current_time ();
180 + printf ("Startup time from NULL: %" GST_TIME_FORMAT "\n",
181 + GST_TIME_ARGS (playing_end - null_start));
182 + printf ("Startup time from PAUSED: %" GST_TIME_FORMAT "\n",
183 + GST_TIME_ARGS (playing_end - paused_start));
186 + else if (newstate == GST_STATE_PAUSED) {
187 + paused_start = gst_get_current_time ();
196 + gst_element_set_state (pipeline, GST_STATE_READY);
197 + g_main_loop_quit (loop);
203 +int main(int argc, char **argv)
205 + GstElement *pipeline;
210 + printf ("\nUSAGE: %s <pipeline_type> <profile (0/1)> <URI> [<typefind caps for decodebin2>]\n\n", argv[0]);
211 + printf (" Pipeline type: 0: Hardcoded MP3 pipeline\n");
212 + printf (" 1: Playbin2\n");
213 + printf (" 2: Decodebin2\n\n");
217 + pipe_type = atoi (argv[1]);
218 + profile = atoi (argv[2]);
220 + printf ("============================================================\n");
222 + generic_start = gst_get_current_time ();
223 + gst_init (&argc, &argv);
224 + generic_end = gst_get_current_time ();
226 + printf ("gst_init() time: %" GST_TIME_FORMAT "\n",
227 + GST_TIME_ARGS (generic_end - generic_start));
229 + if (pipe_type == 0) {
230 + GstElement *src, *dec, *sink;
231 + pipeline = gst_element_factory_make ("pipeline", NULL);
232 + src = gst_element_factory_make ("filesrc", NULL);
233 + dec = gst_element_factory_make ("omx_mp3dec", NULL);
234 + sink = gst_element_factory_make ("alsasink", NULL);
235 + gst_bin_add_many (GST_BIN_CAST (pipeline), src, dec, sink, NULL);
236 + gst_element_link_many (src, dec, sink, NULL);
238 + g_object_set (G_OBJECT (src), "location", argv[3], NULL);
239 + g_object_set (G_OBJECT (dec), "use-timestamps", FALSE, NULL);
241 + else if (pipe_type == 1) {
242 + pipeline = gst_element_factory_make ("playbin2", NULL);
243 + g_object_set (G_OBJECT (pipeline), "uri", argv[3], NULL);
244 + g_object_set (G_OBJECT (pipeline), "skip-metadata", TRUE, NULL);
246 + else if (pipe_type == 2) {
247 + GstElement *src, *dec;
250 + pipeline = gst_element_factory_make ("pipeline", NULL);
251 + src = gst_element_factory_make ("filesrc", NULL);
252 + dec = gst_element_factory_make ("decodebin2", NULL);
253 + gst_bin_add_many (GST_BIN_CAST (pipeline), src, dec, NULL);
254 + gst_element_link_many (src, dec, NULL);
256 + g_object_set (G_OBJECT (src), "location", argv[3], NULL);
257 + g_object_set (G_OBJECT (dec), "skip-metadata", TRUE, NULL);
260 + printf ("Setting caps '%s' to skip typefinding!\n", argv[4]);
261 + filecaps = gst_caps_from_string (argv[4]);
262 + g_object_set (G_OBJECT (dec), "sink-caps", filecaps, NULL);
263 + gst_caps_unref (filecaps);
266 + id = g_signal_connect (G_OBJECT (dec), "new-decoded-pad",
267 + G_CALLBACK (dbin_dpad_cb), pipeline);
271 + printf ("Unknown pipeline type\n");
275 + loop = g_main_loop_new (NULL, FALSE);
276 + bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
277 + gst_bus_add_watch (bus, metadata_bus_async_cb, pipeline);
280 + system ("opcontrol --start");
281 + printf ("=== PROFILER RUNNING ===\n");
284 + null_start = gst_get_current_time ();
285 + gst_element_set_state (pipeline, GST_STATE_PLAYING);
286 + g_main_loop_run (loop);
288 + gst_element_set_state (pipeline, GST_STATE_NULL);
289 + gst_object_unref (bus);
290 + gst_object_unref (GST_OBJECT (pipeline));
293 + printf ("============================================================\n");