gst/gstelement.h (GstState): Renamed from GstElementState, changed to be a normal...
[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 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  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public
15  * License along with this library; if not, write to the Free
16  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 #include <gst/gst.h>
20
21 #define IDENTITY_COUNT (1000)
22 #define BUFFER_COUNT (1000)
23 #define SRC_ELEMENT "fakesrc"
24 #define SINK_ELEMENT "fakesink"
25
26
27 static GstClockTime
28 gst_get_current_time (void)
29 {
30   GTimeVal tv;
31
32   g_get_current_time (&tv);
33   return GST_TIMEVAL_TO_TIME (tv);
34 }
35
36 gint
37 main (gint argc, gchar * argv[])
38 {
39   GstElement *pipeline, *src, *sink, *current, *last;
40   guint i, buffers = BUFFER_COUNT, identities = IDENTITY_COUNT;
41   GstClockTime start, end;
42   gchar *src_name = SRC_ELEMENT, *sink_name = SINK_ELEMENT;
43
44   gst_init (&argc, &argv);
45
46   if (argc > 1)
47     identities = atoi (argv[1]);
48   if (argc > 2)
49     buffers = atoi (argv[2]);
50   if (argc > 3)
51     src_name = argv[3];
52   if (argc > 4)
53     sink_name = argv[4];
54
55   g_print
56       ("*** benchmarking this pipeline: %s num-buffers=%u ! %u * identity ! %s\n",
57       src_name, buffers, identities, sink_name);
58   start = gst_get_current_time ();
59   pipeline = gst_element_factory_make ("pipeline", NULL);
60   g_assert (pipeline);
61   src = gst_element_factory_make (src_name, NULL);
62   if (!src) {
63     g_print ("no element named \"%s\" found, aborting...\n", src_name);
64     return 1;
65   }
66   g_object_set (src, "num-buffers", buffers, NULL);
67   sink = gst_element_factory_make (sink_name, NULL);
68   if (!sink) {
69     g_print ("no element named \"%s\" found, aborting...\n", sink_name);
70     return 1;
71   }
72   last = src;
73   gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
74   for (i = 0; i < identities; i++) {
75     current = gst_element_factory_make ("identity", NULL);
76     g_assert (current);
77     /* shut this element up (no g_strdup_printf please) */
78     g_object_set (current, "silent", TRUE, NULL);
79     gst_bin_add (GST_BIN (pipeline), current);
80     if (!gst_element_link (last, current))
81       g_assert_not_reached ();
82     last = current;
83   }
84   if (!gst_element_link (last, sink))
85     g_assert_not_reached ();
86   end = gst_get_current_time ();
87   g_print ("%" GST_TIME_FORMAT " - creating %u identity elements\n",
88       GST_TIME_ARGS (end - start), identities);
89
90   start = gst_get_current_time ();
91   if (gst_element_set_state (pipeline,
92           GST_STATE_PLAYING) != GST_STATE_CHANGE_SUCCESS)
93     g_assert_not_reached ();
94   end = gst_get_current_time ();
95   g_print ("%" GST_TIME_FORMAT " - setting pipeline to playing\n",
96       GST_TIME_ARGS (end - start));
97
98   start = gst_get_current_time ();
99   gst_bus_poll (gst_element_get_bus (pipeline),
100       GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
101   end = gst_get_current_time ();
102   g_print ("%" GST_TIME_FORMAT " - putting %u buffers through\n",
103       GST_TIME_ARGS (end - start), buffers);
104
105   start = gst_get_current_time ();
106   g_object_unref (pipeline);
107   end = gst_get_current_time ();
108   g_print ("%" GST_TIME_FORMAT " - unreffing pipeline\n",
109       GST_TIME_ARGS (end - start));
110
111   return 0;
112 }