From 5e1a7d9360e1a87aacfc13426a302815b1a62bb2 Mon Sep 17 00:00:00 2001 From: Stefan Kost Date: Wed, 19 May 2010 14:08:26 +0300 Subject: [PATCH] benchmark: add commandline parameters for capsnego Allow to specify the graph size and offer two flavours (audio/video). --- tests/benchmarks/capsnego.c | 135 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 104 insertions(+), 31 deletions(-) diff --git a/tests/benchmarks/capsnego.c b/tests/benchmarks/capsnego.c index 691a697..d76086c 100644 --- a/tests/benchmarks/capsnego.c +++ b/tests/benchmarks/capsnego.c @@ -19,61 +19,94 @@ * Boston, MA 02111-1307, USA. */ +/* this benchmark recursively builds a pipeline and meassures the time to go + * from ready to paused. + * The graph size and type can be controlled with a few commandline args: + * -d depth: is the depth of the tree + * -c children: is the number of branches on each level + * -f : can be a=udio/v=ideo and is conttrolling the kind of elements + * that are used. + */ #include +#include +#include + +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] = { + {"audiotestsrc", "adder", "volume", "audioconvert"}, + {"videotestsrc", "videomixer", "videoscale", "ffmpegcolorspace"} +}; -/* the code below recursively builds a pipeline, the GRAPH_DEPTH is the depth - * of the tree, NUM_CHILDREN is the number of branches on each level - */ -#define GRAPH_DEPTH 4 -#define NUM_CHILDREN 3 static gboolean -create_node (GstBin * bin, GstElement * sink, GstElement ** adder, - GstElement ** vol, GstElement ** ac) +create_node (GstBin * bin, GstElement * sink, GstElement ** new_sink, + gint children, gint flavour) { + GstElement *mix, *proc, *conv; - *adder = gst_element_factory_make ("adder", NULL); - if (!*adder) { - GST_WARNING ("need adder from gst-plugins-base"); - return FALSE; + 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); } - *vol = gst_element_factory_make ("volume", NULL); - if (!*vol) { - GST_WARNING ("need volume from gst-plugins-base"); + proc = gst_element_factory_make (factories[flavour][ELEM_PROC], NULL); + if (!proc) { + GST_WARNING ("need element '%s'", factories[flavour][ELEM_PROC]); return FALSE; } - *ac = gst_element_factory_make ("audioconvert", NULL); - if (!*ac) { - GST_WARNING ("need audioconvert from gst-plugins-base"); + conv = gst_element_factory_make (factories[flavour][ELEM_CONV], NULL); + if (!conv) { + GST_WARNING ("need element '%s'", factories[flavour][ELEM_CONV]); return FALSE; } - gst_bin_add_many (bin, *adder, *vol, *ac, NULL); - if (!gst_element_link_many (*adder, *vol, *ac, sink, NULL)) { + gst_bin_add_many (bin, mix, proc, conv, NULL); + if (!gst_element_link_many (mix, proc, conv, sink, NULL)) { GST_WARNING ("can't link elements"); return FALSE; } + *new_sink = mix; return TRUE; } static gboolean -create_nodes (GstBin * bin, GstElement * sink, gint depth) +create_nodes (GstBin * bin, GstElement * sink, gint depth, gint children, + gint flavour) { - GstElement *adder, *vol, *ac, *src; + GstElement *new_sink, *src; gint i; - for (i = 0; i < NUM_CHILDREN; i++) { + for (i = 0; i < children; i++) { if (depth > 0) { - if (!create_node (bin, sink, &adder, &vol, &ac)) { + if (!create_node (bin, sink, &new_sink, children, flavour)) { return FALSE; } - if (!create_nodes (bin, adder, depth - 1)) { + if (!create_nodes (bin, new_sink, depth - 1, children, flavour)) { return FALSE; } } else { - src = gst_element_factory_make ("audiotestsrc", NULL); + src = gst_element_factory_make (factories[flavour][ELEM_SRC], NULL); if (!src) { - GST_WARNING ("need audiotestsrc from gst-plugins-base"); + GST_WARNING ("need element '%s'", factories[flavour][ELEM_SRC]); return FALSE; } gst_bin_add (bin, src); @@ -116,24 +149,63 @@ main (gint argc, gchar * argv[]) { GstBin *bin; GstClockTime start, end; - GstElement *sink; - GstElement *adder, *vol, *ac; + GstElement *sink, *new_sink; + + /* default parameters */ + gint depth = 4; + gint children = 3; + gint flavour = FLAVOUR_AUDIO; + const gchar *flavour_str = "audio"; gst_init (&argc, &argv); + /* check command line options */ + if (argc) { + gint arg; + for (arg = 0; arg < argc; arg++) { + if (!strcmp (argv[arg], "-d")) { + arg++; + if (arg < argc) + depth = atoi (argv[arg]); + } else if (!strcmp (argv[arg], "-c")) { + arg++; + if (arg < argc) + children = atoi (argv[arg]); + } else if (!strcmp (argv[arg], "-f")) { + arg++; + if (arg < argc) { + flavour_str = argv[arg]; + switch (*flavour_str) { + case 'a': + flavour = FLAVOUR_AUDIO; + break; + case 'v': + flavour = FLAVOUR_VIDEO; + break; + default: + break; + } + } + } + } + } + + /* build pipeline */ bin = GST_BIN (gst_pipeline_new ("pipeline")); - g_print ("building pipeline\n"); + g_print ("building %s pipeline with depth = %d and children = %d\n", + flavour_str, depth, children); sink = gst_element_factory_make ("fakesink", NULL); gst_bin_add (bin, sink); - if (!create_node (bin, sink, &adder, &vol, &ac)) { + if (!create_node (bin, sink, &new_sink, children, flavour)) { goto Error; } - if (!create_nodes (bin, adder, GRAPH_DEPTH)) { + if (!create_nodes (bin, new_sink, depth, children, flavour)) { goto Error; } g_print ("built pipeline with %d elements\n", GST_BIN_NUMCHILDREN (bin)); + /* meassure */ 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"); @@ -144,6 +216,7 @@ main (gint argc, gchar * argv[]) g_print ("%" GST_TIME_FORMAT " reached paused\n", GST_TIME_ARGS (end - start)); + /* clean up */ Error: gst_element_set_state (GST_ELEMENT (bin), GST_STATE_NULL); gst_object_unref (bin); -- 2.7.4