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
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2011-09-07 11:14:38 +00:00
|
|
|
/* this benchmark recursively builds a pipeline and measures the time to go
|
2010-05-19 11:08:26 +00:00
|
|
|
* 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 <flavour>: can be a=udio/v=ideo and is conttrolling the kind of elements
|
|
|
|
* that are used.
|
|
|
|
*/
|
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"},
|
|
|
|
{"videotestsrc", "videomixer", "videoscale", "ffmpegcolorspace"}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const gchar *sink_pads[NUM_FLAVOURS][NUM_ELEM] = {
|
|
|
|
{NULL, "sink%d", NULL, NULL},
|
|
|
|
{NULL, "sink_%d", 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
|
2010-07-08 11:08:27 +00:00
|
|
|
event_loop (GstElement * bin, GstClockTime start)
|
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,
|
|
|
|
GST_MESSAGE_STATE_CHANGED | 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)) {
|
|
|
|
case GST_MESSAGE_STATE_CHANGED:
|
|
|
|
if (GST_MESSAGE_SRC (msg) == (GstObject *) bin) {
|
|
|
|
GstState old_state, new_state;
|
|
|
|
GstClockTime end;
|
2010-05-19 06:56:51 +00:00
|
|
|
|
2010-07-08 11:08:27 +00:00
|
|
|
gst_message_parse_state_changed (msg, &old_state, &new_state, NULL);
|
|
|
|
|
|
|
|
end = gst_util_get_timestamp ();
|
|
|
|
g_print ("%" GST_TIME_FORMAT " state change on the bin: %s -> %s\n",
|
|
|
|
GST_TIME_ARGS (end - start),
|
|
|
|
gst_element_state_get_name (old_state),
|
|
|
|
gst_element_state_get_name (new_state));
|
|
|
|
|
|
|
|
if (old_state == GST_STATE_READY && new_state == GST_STATE_PAUSED) {
|
|
|
|
running = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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[])
|
|
|
|
{
|
|
|
|
GstBin *bin;
|
|
|
|
GstClockTime start, end;
|
2010-05-19 11:08:26 +00:00
|
|
|
GstElement *sink, *new_sink;
|
|
|
|
|
|
|
|
/* default parameters */
|
|
|
|
gint depth = 4;
|
|
|
|
gint children = 3;
|
|
|
|
gint flavour = FLAVOUR_AUDIO;
|
|
|
|
const gchar *flavour_str = "audio";
|
2010-05-19 06:56:51 +00:00
|
|
|
|
|
|
|
gst_init (&argc, &argv);
|
|
|
|
|
2010-05-19 11:08:26 +00:00
|
|
|
/* 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 */
|
|
|
|
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");
|
|
|
|
start = gst_util_get_timestamp ();
|
|
|
|
gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED);
|
2010-07-08 11:08:27 +00:00
|
|
|
event_loop (GST_ELEMENT (bin), start);
|
2010-05-19 06:56:51 +00:00
|
|
|
end = gst_util_get_timestamp ();
|
|
|
|
g_print ("%" GST_TIME_FORMAT " reached paused\n",
|
|
|
|
GST_TIME_ARGS (end - start));
|
|
|
|
|
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;
|
|
|
|
}
|