2 * Copyright (C) 2004 Benjamin Otte <otte@gnome.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
23 #define IDENTITY_COUNT (1000)
24 #define BUFFER_COUNT (1000)
25 #define SRC_ELEMENT "fakesrc"
26 #define SINK_ELEMENT "fakesink"
30 gst_get_current_time (void)
34 g_get_current_time (&tv);
35 return GST_TIMEVAL_TO_TIME (tv);
39 main (gint argc, gchar * argv[])
41 GstElement *pipeline, *src, *sink, *current, *last;
42 guint i, buffers = BUFFER_COUNT, identities = IDENTITY_COUNT;
43 GstClockTime start, end;
44 gchar *src_name = SRC_ELEMENT, *sink_name = SINK_ELEMENT;
46 gst_init (&argc, &argv);
49 identities = atoi (argv[1]);
51 buffers = atoi (argv[2]);
58 ("*** benchmarking this pipeline: %s num-buffers=%u ! %u * identity ! %s\n",
59 src_name, buffers, identities, sink_name);
60 start = gst_get_current_time ();
61 pipeline = gst_element_factory_make ("pipeline", NULL);
63 src = gst_element_factory_make (src_name, NULL);
65 g_print ("no element named \"%s\" found, aborting...\n", src_name);
68 g_object_set (src, "num-buffers", buffers, NULL);
69 sink = gst_element_factory_make (sink_name, NULL);
71 g_print ("no element named \"%s\" found, aborting...\n", sink_name);
75 gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
76 for (i = 0; i < identities; i++) {
77 current = gst_element_factory_make ("identity", NULL);
79 /* shut this element up (no g_strdup_printf please) */
80 g_object_set (current, "silent", TRUE, NULL);
81 gst_bin_add (GST_BIN (pipeline), current);
82 if (!gst_element_link (last, current))
83 g_assert_not_reached ();
86 if (!gst_element_link (last, sink))
87 g_assert_not_reached ();
88 end = gst_get_current_time ();
89 g_print ("%" GST_TIME_FORMAT " - creating %u identity elements\n",
90 GST_TIME_ARGS (end - start), identities);
92 start = gst_get_current_time ();
93 if (gst_element_set_state (pipeline,
94 GST_STATE_PLAYING) != GST_STATE_CHANGE_SUCCESS)
95 g_assert_not_reached ();
96 end = gst_get_current_time ();
97 g_print ("%" GST_TIME_FORMAT " - setting pipeline to playing\n",
98 GST_TIME_ARGS (end - start));
100 start = gst_get_current_time ();
101 gst_bus_poll (gst_element_get_bus (pipeline),
102 GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
103 end = gst_get_current_time ();
104 g_print ("%" GST_TIME_FORMAT " - putting %u buffers through\n",
105 GST_TIME_ARGS (end - start), buffers);
107 start = gst_get_current_time ();
108 g_object_unref (pipeline);
109 end = gst_get_current_time ();
110 g_print ("%" GST_TIME_FORMAT " - unreffing pipeline\n",
111 GST_TIME_ARGS (end - start));