benchmark: capsnego: use GOptionContext for option parsing

This commit is contained in:
Tim-Philipp Müller 2014-06-20 17:14:52 +01:00
parent 4043fc3a44
commit 4e12c4528f

View file

@ -19,13 +19,15 @@
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
/* this benchmark recursively builds a pipeline and measures the time to go /* This benchmark recursively builds a pipeline and measures the time to go
* from ready to paused. * from READY to PAUSED state.
* The graph size and type can be controlled with a few commandline args: *
* The graph size and type can be controlled with a few command line options:
*
* -d depth: is the depth of the tree * -d depth: is the depth of the tree
* -c children: is the number of branches on each level * -c children: is the number of branches on each level
* -f <flavour>: can be a=udio/v=ideo and is conttrolling the kind of elements * -f <flavour>: can be "audio" or "video" and is controlling the kind of
* that are used. * elements that are used.
*/ */
#include <gst/gst.h> #include <gst/gst.h>
@ -195,52 +197,45 @@ event_loop (GstElement * bin, GstClockTime start)
gst_object_unref (bus); gst_object_unref (bus);
} }
gint gint
main (gint argc, gchar * argv[]) main (gint argc, gchar * argv[])
{ {
/* default parameters */
const gchar *flavour_str = "audio";
gint flavour = FLAVOUR_AUDIO;
gint children = 3;
gint depth = 4;
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},
{"flavour", 0, 0, G_OPTION_ARG_STRING, &flavour_str,
"Flavour (video|audio) controlling the kind of elements used "
"(default: audio)", NULL},
{NULL}
};
GError *err = NULL;
GstBin *bin; GstBin *bin;
GstClockTime start, end; GstClockTime start, end;
GstElement *sink, *new_sink; GstElement *sink, *new_sink;
/* default parameters */ g_set_prgname ("capsnego");
gint depth = 4;
gint children = 3;
gint flavour = FLAVOUR_AUDIO;
const gchar *flavour_str = "audio";
gst_init (&argc, &argv);
/* check command line options */ /* check command line options */
if (argc) { ctx = g_option_context_new ("");
gint arg; g_option_context_add_main_entries (ctx, options, NULL);
for (arg = 0; arg < argc; arg++) { g_option_context_add_group (ctx, gst_init_get_option_group ());
if (!strcmp (argv[arg], "-d")) { if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
arg++; g_print ("Error initializing: %s\n", GST_STR_NULL (err->message));
if (arg < argc) return 1;
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;
}
}
}
}
} }
g_option_context_free (ctx);
if (strcmp (flavour_str, "video") == 0)
flavour = FLAVOUR_VIDEO;
/* build pipeline */ /* build pipeline */
g_print ("building %s pipeline with depth = %d and children = %d\n", g_print ("building %s pipeline with depth = %d and children = %d\n",