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.
25 /* the code below recursively builds a pipeline, the GRAPH_DEPTH is the depth
26 * of the tree, NUM_CHILDREN is the number of branches on each level
29 #define NUM_CHILDREN 3
32 create_node (GstBin * bin, GstElement * sink, GstElement ** adder,
33 GstElement ** vol, GstElement ** ac)
36 *adder = gst_element_factory_make ("adder", NULL);
38 GST_WARNING ("need adder from gst-plugins-base");
41 *vol = gst_element_factory_make ("volume", NULL);
43 GST_WARNING ("need volume from gst-plugins-base");
46 *ac = gst_element_factory_make ("audioconvert", NULL);
48 GST_WARNING ("need audioconvert from gst-plugins-base");
51 gst_bin_add_many (bin, *adder, *vol, *ac, NULL);
52 if (!gst_element_link_many (*adder, *vol, *ac, sink, NULL)) {
53 GST_WARNING ("can't link elements");
60 create_nodes (GstBin * bin, GstElement * sink, gint depth)
62 GstElement *adder, *vol, *ac, *src;
65 for (i = 0; i < NUM_CHILDREN; i++) {
67 if (!create_node (bin, sink, &adder, &vol, &ac)) {
70 if (!create_nodes (bin, adder, depth - 1)) {
74 src = gst_element_factory_make ("audiotestsrc", NULL);
76 GST_WARNING ("need audiotestsrc from gst-plugins-base");
79 gst_bin_add (bin, src);
80 if (!gst_element_link (src, sink)) {
81 GST_WARNING ("can't link elements");
90 event_loop (GstElement * bin)
93 GstMessage *msg = NULL;
94 gboolean running = TRUE;
96 bus = gst_element_get_bus (bin);
99 msg = gst_bus_poll (bus, GST_MESSAGE_STATE_CHANGED, -1);
101 if (GST_MESSAGE_SRC (msg) == (GstObject *) bin) {
102 GstState old_state, new_state;
104 gst_message_parse_state_changed (msg, &old_state, &new_state, NULL);
105 if (old_state == GST_STATE_READY && new_state == GST_STATE_PAUSED) {
109 gst_message_unref (msg);
115 main (gint argc, gchar * argv[])
118 GstClockTime start, end;
120 GstElement *adder, *vol, *ac;
122 gst_init (&argc, &argv);
124 bin = GST_BIN (gst_pipeline_new ("pipeline"));
126 g_print ("building pipeline\n");
127 sink = gst_element_factory_make ("fakesink", NULL);
128 gst_bin_add (bin, sink);
129 if (!create_node (bin, sink, &adder, &vol, &ac)) {
132 if (!create_nodes (bin, adder, GRAPH_DEPTH)) {
135 g_print ("built pipeline with %d elements\n", GST_BIN_NUMCHILDREN (bin));
137 g_print ("starting pipeline\n");
138 gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY);
139 GST_DEBUG_BIN_TO_DOT_FILE (bin, GST_DEBUG_GRAPH_SHOW_MEDIA_TYPE, "capsnego");
140 start = gst_util_get_timestamp ();
141 gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED);
142 event_loop (GST_ELEMENT (bin));
143 end = gst_util_get_timestamp ();
144 g_print ("%" GST_TIME_FORMAT " reached paused\n",
145 GST_TIME_ARGS (end - start));
148 gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
149 gst_object_unref (bin);