2010-05-19 06:56:51 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2010 Stefan Kost <ensonic@users.sf.net>
|
|
|
|
*
|
|
|
|
* capsnego.c: benchmark for caps negotiation
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
2012-11-03 20:44:48 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2010-05-19 06:56:51 +00:00
|
|
|
*/
|
|
|
|
|
2014-06-20 16:14:52 +00:00
|
|
|
/* This benchmark recursively builds a pipeline and measures the time to go
|
|
|
|
* from READY to PAUSED state.
|
|
|
|
*
|
|
|
|
* The graph size and type can be controlled with a few command line options:
|
|
|
|
*
|
2010-05-19 11:08:26 +00:00
|
|
|
* -d depth: is the depth of the tree
|
|
|
|
* -c children: is the number of branches on each level
|
2014-06-20 16:14:52 +00:00
|
|
|
* -f <flavour>: can be "audio" or "video" and is controlling the kind of
|
|
|
|
* elements that are used.
|
2010-05-19 11:08:26 +00:00
|
|
|
*/
|
2010-05-19 06:56:51 +00:00
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2010-05-19 11:08:26 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
FLAVOUR_AUDIO = 0,
|
|
|
|
FLAVOUR_VIDEO,
|
|
|
|
NUM_FLAVOURS
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ELEM_SRC = 0,
|
|
|
|
ELEM_MIX,
|
|
|
|
ELEM_PROC,
|
|
|
|
ELEM_CONV,
|
|
|
|
NUM_ELEM
|
|
|
|
};
|
|
|
|
|
|
|
|
static const gchar *factories[NUM_FLAVOURS][NUM_ELEM] = {
|
2010-07-06 15:20:40 +00:00
|
|
|
{"audiotestsrc", "adder", "volume", "audioconvert"},
|
2012-09-13 09:35:41 +00:00
|
|
|
{"videotestsrc", "videomixer", "videoscale", "videoconvert"}
|
2010-07-06 15:20:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const gchar *sink_pads[NUM_FLAVOURS][NUM_ELEM] = {
|
2012-09-13 09:35:41 +00:00
|
|
|
{NULL, "sink_%u", NULL, NULL},
|
|
|
|
{NULL, "sink_%u", NULL, NULL}
|
2010-05-19 11:08:26 +00:00
|
|
|
};
|
2010-05-19 06:56:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2010-06-24 10:19:20 +00:00
|
|
|
create_node (GstBin * bin, GstElement * sink, const gchar * sinkpadname,
|
|
|
|
GstElement ** new_sink, gint children, gint flavour)
|
2010-05-19 06:56:51 +00:00
|
|
|
{
|
2010-05-19 11:08:26 +00:00
|
|
|
GstElement *mix, *proc, *conv;
|
2010-05-19 06:56:51 +00:00
|
|
|
|
2010-05-19 11:08:26 +00:00
|
|
|
if (children >= 1) {
|
|
|
|
mix = gst_element_factory_make (factories[flavour][ELEM_MIX], NULL);
|
|
|
|
if (!mix) {
|
|
|
|
GST_WARNING ("need element '%s'", factories[flavour][ELEM_MIX]);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mix = gst_element_factory_make ("identity", NULL);
|
2010-05-19 06:56:51 +00:00
|
|
|
}
|
2010-05-19 11:08:26 +00:00
|
|
|
proc = gst_element_factory_make (factories[flavour][ELEM_PROC], NULL);
|
|
|
|
if (!proc) {
|
|
|
|
GST_WARNING ("need element '%s'", factories[flavour][ELEM_PROC]);
|
2010-05-19 06:56:51 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-05-19 11:08:26 +00:00
|
|
|
conv = gst_element_factory_make (factories[flavour][ELEM_CONV], NULL);
|
|
|
|
if (!conv) {
|
|
|
|
GST_WARNING ("need element '%s'", factories[flavour][ELEM_CONV]);
|
2010-05-19 06:56:51 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-05-19 11:08:26 +00:00
|
|
|
gst_bin_add_many (bin, mix, proc, conv, NULL);
|
2010-06-24 10:19:20 +00:00
|
|
|
if (!gst_element_link_pads_full (mix, "src", proc, "sink",
|
|
|
|
GST_PAD_LINK_CHECK_NOTHING)
|
|
|
|
|| !gst_element_link_pads_full (proc, "src", conv, "sink",
|
|
|
|
GST_PAD_LINK_CHECK_NOTHING)
|
|
|
|
|| !gst_element_link_pads_full (conv, "src", sink, sinkpadname,
|
|
|
|
GST_PAD_LINK_CHECK_NOTHING)) {
|
2010-05-19 06:56:51 +00:00
|
|
|
GST_WARNING ("can't link elements");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-05-19 11:08:26 +00:00
|
|
|
*new_sink = mix;
|
2010-05-19 06:56:51 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2010-05-19 11:08:26 +00:00
|
|
|
create_nodes (GstBin * bin, GstElement * sink, gint depth, gint children,
|
|
|
|
gint flavour)
|
2010-05-19 06:56:51 +00:00
|
|
|
{
|
2010-05-19 11:08:26 +00:00
|
|
|
GstElement *new_sink, *src;
|
2010-05-19 06:56:51 +00:00
|
|
|
gint i;
|
|
|
|
|
2010-05-19 11:08:26 +00:00
|
|
|
for (i = 0; i < children; i++) {
|
2010-05-19 06:56:51 +00:00
|
|
|
if (depth > 0) {
|
2010-07-06 15:20:40 +00:00
|
|
|
if (!create_node (bin, sink, sink_pads[flavour][ELEM_MIX], &new_sink,
|
2010-06-24 10:19:20 +00:00
|
|
|
children, flavour)) {
|
2010-05-19 06:56:51 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2010-05-19 11:08:26 +00:00
|
|
|
if (!create_nodes (bin, new_sink, depth - 1, children, flavour)) {
|
2010-05-19 06:56:51 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
} else {
|
2010-05-19 11:08:26 +00:00
|
|
|
src = gst_element_factory_make (factories[flavour][ELEM_SRC], NULL);
|
2010-05-19 06:56:51 +00:00
|
|
|
if (!src) {
|
2010-05-19 11:08:26 +00:00
|
|
|
GST_WARNING ("need element '%s'", factories[flavour][ELEM_SRC]);
|
2010-05-19 06:56:51 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
gst_bin_add (bin, src);
|
2010-06-24 10:19:20 +00:00
|
|
|
if (!gst_element_link_pads_full (src, "src", sink,
|
2010-07-06 15:20:40 +00:00
|
|
|
sink_pads[flavour][ELEM_MIX], GST_PAD_LINK_CHECK_NOTHING)) {
|
2010-05-19 06:56:51 +00:00
|
|
|
GST_WARNING ("can't link elements");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-06-20 17:34:44 +00:00
|
|
|
event_loop (GstElement * bin)
|
2010-05-19 06:56:51 +00:00
|
|
|
{
|
|
|
|
GstBus *bus;
|
|
|
|
GstMessage *msg = NULL;
|
|
|
|
gboolean running = TRUE;
|
|
|
|
|
|
|
|
bus = gst_element_get_bus (bin);
|
|
|
|
|
|
|
|
while (running) {
|
2010-07-08 11:08:27 +00:00
|
|
|
msg = gst_bus_poll (bus,
|
2014-06-20 17:34:44 +00:00
|
|
|
GST_MESSAGE_ASYNC_DONE | GST_MESSAGE_ERROR | GST_MESSAGE_WARNING, -1);
|
2010-05-19 06:56:51 +00:00
|
|
|
|
2010-07-08 11:08:27 +00:00
|
|
|
switch (GST_MESSAGE_TYPE (msg)) {
|
2014-06-20 17:34:44 +00:00
|
|
|
case GST_MESSAGE_ASYNC_DONE:
|
|
|
|
running = FALSE;
|
2010-07-08 11:08:27 +00:00
|
|
|
break;
|
|
|
|
case GST_MESSAGE_WARNING:{
|
|
|
|
GError *err = NULL;
|
|
|
|
gchar *dbg = NULL;
|
|
|
|
|
|
|
|
gst_message_parse_warning (msg, &err, &dbg);
|
|
|
|
GST_WARNING_OBJECT (GST_MESSAGE_SRC (msg), "%s (%s)", err->message,
|
|
|
|
(dbg ? dbg : "no details"));
|
|
|
|
g_error_free (err);
|
|
|
|
g_free (dbg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_MESSAGE_ERROR:{
|
|
|
|
GError *err = NULL;
|
|
|
|
gchar *dbg = NULL;
|
|
|
|
|
|
|
|
gst_message_parse_error (msg, &err, &dbg);
|
|
|
|
GST_ERROR_OBJECT (GST_MESSAGE_SRC (msg), "%s (%s)", err->message,
|
|
|
|
(dbg ? dbg : "no details"));
|
|
|
|
g_error_free (err);
|
|
|
|
g_free (dbg);
|
2010-05-19 06:56:51 +00:00
|
|
|
running = FALSE;
|
2010-07-08 11:08:27 +00:00
|
|
|
break;
|
2010-05-19 06:56:51 +00:00
|
|
|
}
|
2010-07-08 11:08:27 +00:00
|
|
|
default:
|
|
|
|
break;
|
2010-05-19 06:56:51 +00:00
|
|
|
}
|
|
|
|
gst_message_unref (msg);
|
|
|
|
}
|
2010-07-08 11:08:27 +00:00
|
|
|
gst_object_unref (bus);
|
2010-05-19 06:56:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
|
|
|
main (gint argc, gchar * argv[])
|
|
|
|
{
|
2014-06-20 16:14:52 +00:00
|
|
|
/* default parameters */
|
|
|
|
const gchar *flavour_str = "audio";
|
|
|
|
gint flavour = FLAVOUR_AUDIO;
|
|
|
|
gint children = 3;
|
|
|
|
gint depth = 4;
|
2014-06-20 17:34:44 +00:00
|
|
|
gint loops = 50;
|
2014-06-20 16:14:52 +00:00
|
|
|
|
|
|
|
GOptionContext *ctx;
|
|
|
|
GOptionEntry options[] = {
|
|
|
|
{"children", 'c', 0, G_OPTION_ARG_INT, &children,
|
|
|
|
"Number of children (branches on each level) (default: 3)", NULL},
|
|
|
|
{"depth", 'd', 0, G_OPTION_ARG_INT, &depth,
|
|
|
|
"Depth of pipeline hierarchy tree (default: 4)", NULL},
|
2014-06-20 17:34:44 +00:00
|
|
|
{"flavour", 'f', 0, G_OPTION_ARG_STRING, &flavour_str,
|
2014-06-20 16:14:52 +00:00
|
|
|
"Flavour (video|audio) controlling the kind of elements used "
|
|
|
|
"(default: audio)", NULL},
|
2014-06-20 17:34:44 +00:00
|
|
|
{"loops", 'l', 0, G_OPTION_ARG_INT, &loops,
|
|
|
|
"How many loops to run (default: 50)", NULL},
|
2014-06-20 16:14:52 +00:00
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
GError *err = NULL;
|
2010-05-19 06:56:51 +00:00
|
|
|
GstBin *bin;
|
|
|
|
GstClockTime start, end;
|
2010-05-19 11:08:26 +00:00
|
|
|
GstElement *sink, *new_sink;
|
2014-06-20 17:34:44 +00:00
|
|
|
gint i;
|
2010-05-19 11:08:26 +00:00
|
|
|
|
2014-06-20 16:14:52 +00:00
|
|
|
g_set_prgname ("capsnego");
|
2010-05-19 06:56:51 +00:00
|
|
|
|
2010-05-19 11:08:26 +00:00
|
|
|
/* check command line options */
|
2014-06-20 16:14:52 +00:00
|
|
|
ctx = g_option_context_new ("");
|
|
|
|
g_option_context_add_main_entries (ctx, options, NULL);
|
|
|
|
g_option_context_add_group (ctx, gst_init_get_option_group ());
|
|
|
|
if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
|
|
|
|
g_print ("Error initializing: %s\n", GST_STR_NULL (err->message));
|
|
|
|
return 1;
|
2010-05-19 11:08:26 +00:00
|
|
|
}
|
2014-06-20 16:14:52 +00:00
|
|
|
g_option_context_free (ctx);
|
|
|
|
|
|
|
|
if (strcmp (flavour_str, "video") == 0)
|
|
|
|
flavour = FLAVOUR_VIDEO;
|
2010-05-19 11:08:26 +00:00
|
|
|
|
|
|
|
/* build pipeline */
|
|
|
|
g_print ("building %s pipeline with depth = %d and children = %d\n",
|
|
|
|
flavour_str, depth, children);
|
2010-06-06 18:20:21 +00:00
|
|
|
start = gst_util_get_timestamp ();
|
|
|
|
bin = GST_BIN (gst_pipeline_new ("pipeline"));
|
2010-05-19 06:56:51 +00:00
|
|
|
sink = gst_element_factory_make ("fakesink", NULL);
|
|
|
|
gst_bin_add (bin, sink);
|
2010-06-24 10:19:20 +00:00
|
|
|
if (!create_node (bin, sink, "sink", &new_sink, children, flavour)) {
|
2010-05-19 06:56:51 +00:00
|
|
|
goto Error;
|
|
|
|
}
|
2010-05-19 11:08:26 +00:00
|
|
|
if (!create_nodes (bin, new_sink, depth, children, flavour)) {
|
2010-05-19 06:56:51 +00:00
|
|
|
goto Error;
|
|
|
|
}
|
2010-06-06 18:20:21 +00:00
|
|
|
end = gst_util_get_timestamp ();
|
2010-07-08 11:08:27 +00:00
|
|
|
/* num-threads = num-sources = pow (children, depth) */
|
2010-06-06 18:20:21 +00:00
|
|
|
g_print ("%" GST_TIME_FORMAT " built pipeline with %d elements\n",
|
|
|
|
GST_TIME_ARGS (end - start), GST_BIN_NUMCHILDREN (bin));
|
2010-05-19 06:56:51 +00:00
|
|
|
|
2011-09-07 11:14:38 +00:00
|
|
|
/* measure */
|
2010-05-19 06:56:51 +00:00
|
|
|
g_print ("starting pipeline\n");
|
|
|
|
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY);
|
|
|
|
GST_DEBUG_BIN_TO_DOT_FILE (bin, GST_DEBUG_GRAPH_SHOW_MEDIA_TYPE, "capsnego");
|
2014-06-20 17:34:44 +00:00
|
|
|
|
2010-05-19 06:56:51 +00:00
|
|
|
start = gst_util_get_timestamp ();
|
2014-06-20 17:34:44 +00:00
|
|
|
for (i = 0; i < loops; ++i) {
|
|
|
|
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED);
|
|
|
|
event_loop (GST_ELEMENT (bin));
|
|
|
|
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_READY);
|
|
|
|
}
|
2010-05-19 06:56:51 +00:00
|
|
|
end = gst_util_get_timestamp ();
|
2014-06-20 17:34:44 +00:00
|
|
|
g_print ("%" GST_TIME_FORMAT " reached PAUSED state (%d loop iterations)\n",
|
|
|
|
GST_TIME_ARGS (end - start), loops);
|
2010-05-19 11:08:26 +00:00
|
|
|
/* clean up */
|
2010-05-19 06:56:51 +00:00
|
|
|
Error:
|
|
|
|
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL);
|
|
|
|
gst_object_unref (bin);
|
|
|
|
return 0;
|
|
|
|
}
|