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[])
42 GstElement *pipeline, *src, *sink, *current, *last;
43 guint i, buffers = BUFFER_COUNT, identities = IDENTITY_COUNT;
44 GstClockTime start, end;
45 const gchar *src_name = SRC_ELEMENT, *sink_name = SINK_ELEMENT;
47 gst_init (&argc, &argv);
50 identities = atoi (argv[1]);
52 buffers = atoi (argv[2]);
59 ("*** benchmarking this pipeline: %s num-buffers=%u ! %u * identity ! %s\n",
60 src_name, buffers, identities, sink_name);
61 start = gst_get_current_time ();
62 pipeline = gst_element_factory_make ("pipeline", NULL);
64 src = gst_element_factory_make (src_name, NULL);
66 g_print ("no element named \"%s\" found, aborting...\n", src_name);
69 g_object_set (src, "num-buffers", buffers, NULL);
70 sink = gst_element_factory_make (sink_name, NULL);
72 g_print ("no element named \"%s\" found, aborting...\n", sink_name);
76 gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
77 for (i = 0; i < identities; i++) {
78 current = gst_element_factory_make ("identity", NULL);
80 /* shut this element up (no g_strdup_printf please) */
81 g_object_set (current, "silent", TRUE, NULL);
82 gst_bin_add (GST_BIN (pipeline), current);
83 if (!gst_element_link (last, current))
84 g_assert_not_reached ();
87 if (!gst_element_link (last, sink))
88 g_assert_not_reached ();
89 end = gst_get_current_time ();
90 g_print ("%" GST_TIME_FORMAT " - creating %u identity elements\n",
91 GST_TIME_ARGS (end - start), identities);
93 start = gst_get_current_time ();
94 if (gst_element_set_state (pipeline,
95 GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
96 g_assert_not_reached ();
97 if (gst_element_get_state (pipeline, NULL, NULL,
98 GST_CLOCK_TIME_NONE) == GST_STATE_CHANGE_FAILURE)
99 g_assert_not_reached ();
100 end = gst_get_current_time ();
101 g_print ("%" GST_TIME_FORMAT " - setting pipeline to playing\n",
102 GST_TIME_ARGS (end - start));
104 start = gst_get_current_time ();
105 msg = gst_bus_poll (gst_element_get_bus (pipeline),
106 GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
107 end = gst_get_current_time ();
108 gst_message_unref (msg);
109 g_print ("%" GST_TIME_FORMAT " - putting %u buffers through\n",
110 GST_TIME_ARGS (end - start), buffers);
112 start = gst_get_current_time ();
113 if (gst_element_set_state (pipeline,
114 GST_STATE_NULL) != GST_STATE_CHANGE_SUCCESS)
115 g_assert_not_reached ();
116 end = gst_get_current_time ();
117 g_print ("%" GST_TIME_FORMAT " - setting pipeline to NULL\n",
118 GST_TIME_ARGS (end - start));
120 start = gst_get_current_time ();
121 g_object_unref (pipeline);
122 end = gst_get_current_time ();
123 g_print ("%" GST_TIME_FORMAT " - unreffing pipeline\n",
124 GST_TIME_ARGS (end - start));