gst-inspect: fix unused-const-variable error in windows
[platform/upstream/gstreamer.git] / tests / benchmarks / mass-elements.c
1 /*
2  * Copyright (C) 2004 Benjamin Otte <otte@gnome.org>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19
20 #include <stdlib.h>
21 #include <gst/gst.h>
22
23 #define IDENTITY_COUNT (1000)
24 #define BUFFER_COUNT (1000)
25 #define SRC_ELEMENT "fakesrc"
26 #define SINK_ELEMENT "fakesink"
27
28
29 gint
30 main (gint argc, gchar * argv[])
31 {
32   GstMessage *msg;
33   GstElement *pipeline, *src, *sink, *current, *last;
34   guint i, buffers = BUFFER_COUNT, identities = IDENTITY_COUNT;
35   GstClockTime start, end;
36   const gchar *src_name = SRC_ELEMENT, *sink_name = SINK_ELEMENT;
37
38   gst_init (&argc, &argv);
39
40   if (argc > 1)
41     identities = atoi (argv[1]);
42   if (argc > 2)
43     buffers = atoi (argv[2]);
44   if (argc > 3)
45     src_name = argv[3];
46   if (argc > 4)
47     sink_name = argv[4];
48
49   g_print
50       ("*** benchmarking this pipeline: %s num-buffers=%u ! %u * identity ! %s\n",
51       src_name, buffers, identities, sink_name);
52   start = gst_util_get_timestamp ();
53   pipeline = gst_element_factory_make ("pipeline", NULL);
54   g_assert (pipeline);
55   src = gst_element_factory_make (src_name, NULL);
56   if (!src) {
57     g_print ("no element named \"%s\" found, aborting...\n", src_name);
58     return 1;
59   }
60   g_object_set (src, "num-buffers", buffers, NULL);
61   sink = gst_element_factory_make (sink_name, NULL);
62   if (!sink) {
63     g_print ("no element named \"%s\" found, aborting...\n", sink_name);
64     return 1;
65   }
66   last = src;
67   gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
68   for (i = 0; i < identities; i++) {
69     current = gst_element_factory_make ("identity", NULL);
70     g_assert (current);
71     /* shut this element up (no g_strdup_printf please) */
72     g_object_set (current, "silent", TRUE, NULL);
73     gst_bin_add (GST_BIN (pipeline), current);
74     if (!gst_element_link (last, current))
75       g_assert_not_reached ();
76     last = current;
77   }
78   if (!gst_element_link (last, sink))
79     g_assert_not_reached ();
80   end = gst_util_get_timestamp ();
81   g_print ("%" GST_TIME_FORMAT " - creating %u identity elements\n",
82       GST_TIME_ARGS (end - start), identities);
83
84   start = gst_util_get_timestamp ();
85   if (gst_element_set_state (pipeline,
86           GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
87     g_assert_not_reached ();
88   if (gst_element_get_state (pipeline, NULL, NULL,
89           GST_CLOCK_TIME_NONE) == GST_STATE_CHANGE_FAILURE)
90     g_assert_not_reached ();
91   end = gst_util_get_timestamp ();
92   g_print ("%" GST_TIME_FORMAT " - setting pipeline to playing\n",
93       GST_TIME_ARGS (end - start));
94
95   start = gst_util_get_timestamp ();
96   msg = gst_bus_poll (gst_element_get_bus (pipeline),
97       GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
98   end = gst_util_get_timestamp ();
99   gst_message_unref (msg);
100   g_print ("%" GST_TIME_FORMAT " - putting %u buffers through\n",
101       GST_TIME_ARGS (end - start), buffers);
102
103   start = gst_util_get_timestamp ();
104   if (gst_element_set_state (pipeline,
105           GST_STATE_NULL) != GST_STATE_CHANGE_SUCCESS)
106     g_assert_not_reached ();
107   end = gst_util_get_timestamp ();
108   g_print ("%" GST_TIME_FORMAT " - setting pipeline to NULL\n",
109       GST_TIME_ARGS (end - start));
110
111   start = gst_util_get_timestamp ();
112   g_object_unref (pipeline);
113   end = gst_util_get_timestamp ();
114   g_print ("%" GST_TIME_FORMAT " - unreffing pipeline\n",
115       GST_TIME_ARGS (end - start));
116
117   return 0;
118 }