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 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 * General Public License for more details.
14 * You should have received a copy of the GNU General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #define IDENTITY_COUNT (1000)
22 #define BUFFER_COUNT (1000)
23 #define SRC_ELEMENT "fakesrc"
24 #define SINK_ELEMENT "fakesink"
28 gst_get_current_time (void)
32 g_get_current_time (&tv);
33 return GST_TIMEVAL_TO_TIME (tv);
37 main (gint argc, gchar * argv[])
39 GstElement *pipeline, *src, *sink, *current, *last;
40 guint i, buffers = BUFFER_COUNT, identities = IDENTITY_COUNT;
41 GstClockTime start, end;
42 gchar *src_name = SRC_ELEMENT, *sink_name = SINK_ELEMENT;
44 gst_init (&argc, &argv);
47 identities = atoi (argv[1]);
49 buffers = atoi (argv[2]);
56 ("*** benchmarking this pipeline: %s num-buffers=%u ! %u * identity ! %s\n",
57 src_name, buffers, identities, sink_name);
58 start = gst_get_current_time ();
59 pipeline = gst_element_factory_make ("pipeline", NULL);
61 src = gst_element_factory_make (src_name, NULL);
63 g_print ("no element named \"%s\" found, aborting...\n", src_name);
66 g_object_set (src, "num-buffers", buffers, NULL);
67 sink = gst_element_factory_make (sink_name, NULL);
69 g_print ("no element named \"%s\" found, aborting...\n", sink_name);
73 gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
74 for (i = 0; i < identities; i++) {
75 current = gst_element_factory_make ("identity", NULL);
77 /* shut this element up (no g_strdup_printf please) */
78 g_object_set (current, "silent", TRUE, NULL);
79 gst_bin_add (GST_BIN (pipeline), current);
80 if (!gst_element_link (last, current))
81 g_assert_not_reached ();
84 if (!gst_element_link (last, sink))
85 g_assert_not_reached ();
86 end = gst_get_current_time ();
87 g_print ("%" GST_TIME_FORMAT " - creating %u identity elements\n",
88 GST_TIME_ARGS (end - start), identities);
90 start = gst_get_current_time ();
91 if (gst_element_set_state (pipeline,
92 GST_STATE_PLAYING) != GST_STATE_CHANGE_SUCCESS)
93 g_assert_not_reached ();
94 end = gst_get_current_time ();
95 g_print ("%" GST_TIME_FORMAT " - setting pipeline to playing\n",
96 GST_TIME_ARGS (end - start));
98 start = gst_get_current_time ();
99 gst_bus_poll (gst_element_get_bus (pipeline),
100 GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
101 end = gst_get_current_time ();
102 g_print ("%" GST_TIME_FORMAT " - putting %u buffers through\n",
103 GST_TIME_ARGS (end - start), buffers);
105 start = gst_get_current_time ();
106 g_object_unref (pipeline);
107 end = gst_get_current_time ();
108 g_print ("%" GST_TIME_FORMAT " - unreffing pipeline\n",
109 GST_TIME_ARGS (end - start));