2 * Copyright (C) 2010 Stefan Kost <ensonic@users.sf.net>
4 * capsnego.c: benchmark for caps negotiation
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 /* this benchmark recursively builds a pipeline and meassures the time to go
23 * from ready to paused.
24 * The graph size and type can be controlled with a few commandline args:
25 * -d depth: is the depth of the tree
26 * -c children: is the number of branches on each level
27 * -f <flavour>: can be a=udio/v=ideo and is conttrolling the kind of elements
51 static const gchar *factories[NUM_FLAVOURS][NUM_ELEM] = {
52 {"audiotestsrc", "adder", "volume", "audioconvert"},
53 {"videotestsrc", "videomixer", "videoscale", "ffmpegcolorspace"}
56 static const gchar *sink_pads[NUM_FLAVOURS][NUM_ELEM] = {
57 {NULL, "sink%d", NULL, NULL},
58 {NULL, "sink_%d", NULL, NULL}
63 create_node (GstBin * bin, GstElement * sink, const gchar * sinkpadname,
64 GstElement ** new_sink, gint children, gint flavour)
66 GstElement *mix, *proc, *conv;
69 mix = gst_element_factory_make (factories[flavour][ELEM_MIX], NULL);
71 GST_WARNING ("need element '%s'", factories[flavour][ELEM_MIX]);
75 mix = gst_element_factory_make ("identity", NULL);
77 proc = gst_element_factory_make (factories[flavour][ELEM_PROC], NULL);
79 GST_WARNING ("need element '%s'", factories[flavour][ELEM_PROC]);
82 conv = gst_element_factory_make (factories[flavour][ELEM_CONV], NULL);
84 GST_WARNING ("need element '%s'", factories[flavour][ELEM_CONV]);
87 gst_bin_add_many (bin, mix, proc, conv, NULL);
88 if (!gst_element_link_pads_full (mix, "src", proc, "sink",
89 GST_PAD_LINK_CHECK_NOTHING)
90 || !gst_element_link_pads_full (proc, "src", conv, "sink",
91 GST_PAD_LINK_CHECK_NOTHING)
92 || !gst_element_link_pads_full (conv, "src", sink, sinkpadname,
93 GST_PAD_LINK_CHECK_NOTHING)) {
94 GST_WARNING ("can't link elements");
102 create_nodes (GstBin * bin, GstElement * sink, gint depth, gint children,
105 GstElement *new_sink, *src;
108 for (i = 0; i < children; i++) {
110 if (!create_node (bin, sink, sink_pads[flavour][ELEM_MIX], &new_sink,
111 children, flavour)) {
114 if (!create_nodes (bin, new_sink, depth - 1, children, flavour)) {
118 src = gst_element_factory_make (factories[flavour][ELEM_SRC], NULL);
120 GST_WARNING ("need element '%s'", factories[flavour][ELEM_SRC]);
123 gst_bin_add (bin, src);
124 if (!gst_element_link_pads_full (src, "src", sink,
125 sink_pads[flavour][ELEM_MIX], GST_PAD_LINK_CHECK_NOTHING)) {
126 GST_WARNING ("can't link elements");
135 event_loop (GstElement * bin)
138 GstMessage *msg = NULL;
139 gboolean running = TRUE;
141 bus = gst_element_get_bus (bin);
144 msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1);
146 if (GST_MESSAGE_SRC (msg) == (GstObject *) bin) {
147 GstState old_state, new_state;
149 gst_message_parse_state_changed (msg, &old_state, &new_state, NULL);
150 if (old_state == GST_STATE_READY && new_state == GST_STATE_PAUSED) {
154 gst_message_unref (msg);
160 main (gint argc, gchar * argv[])
163 GstClockTime start, end;
164 GstElement *sink, *new_sink;
166 /* default parameters */
169 gint flavour = FLAVOUR_AUDIO;
170 const gchar *flavour_str = "audio";
172 gst_init (&argc, &argv);
174 /* check command line options */
177 for (arg = 0; arg < argc; arg++) {
178 if (!strcmp (argv[arg], "-d")) {
181 depth = atoi (argv[arg]);
182 } else if (!strcmp (argv[arg], "-c")) {
185 children = atoi (argv[arg]);
186 } else if (!strcmp (argv[arg], "-f")) {
189 flavour_str = argv[arg];
190 switch (*flavour_str) {
192 flavour = FLAVOUR_AUDIO;
195 flavour = FLAVOUR_VIDEO;
206 g_print ("building %s pipeline with depth = %d and children = %d\n",
207 flavour_str, depth, children);
208 start = gst_util_get_timestamp ();
209 bin = GST_BIN (gst_pipeline_new ("pipeline"));
210 sink = gst_element_factory_make ("fakesink", NULL);
211 gst_bin_add (bin, sink);
212 if (!create_node (bin, sink, "sink", &new_sink, children, flavour)) {
215 if (!create_nodes (bin, new_sink, depth, children, flavour)) {
218 end = gst_util_get_timestamp ();
219 g_print ("%" GST_TIME_FORMAT " built pipeline with %d elements\n",
220 GST_TIME_ARGS (end - start), GST_BIN_NUMCHILDREN (bin));
223 g_print ("starting pipeline\n");
224 gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY);
225 GST_DEBUG_BIN_TO_DOT_FILE (bin, GST_DEBUG_GRAPH_SHOW_MEDIA_TYPE, "capsnego");
226 start = gst_util_get_timestamp ();
227 gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED);
228 event_loop (GST_ELEMENT (bin));
229 end = gst_util_get_timestamp ();
230 g_print ("%" GST_TIME_FORMAT " reached paused\n",
231 GST_TIME_ARGS (end - start));
235 gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
236 gst_object_unref (bin);