tests/benchmarks/: Change licence to LGPL as granted by Benjamin and Andy.
[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., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, 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 static GstClockTime
30 gst_get_current_time (void)
31 {
32   GTimeVal tv;
33
34   g_get_current_time (&tv);
35   return GST_TIMEVAL_TO_TIME (tv);
36 }
37
38 gint
39 main (gint argc, gchar * argv[])
40 {
41   GstElement *pipeline, *src, *sink, *current, *last;
42   guint i, buffers = BUFFER_COUNT, identities = IDENTITY_COUNT;
43   GstClockTime start, end;
44   gchar *src_name = SRC_ELEMENT, *sink_name = SINK_ELEMENT;
45
46   gst_init (&argc, &argv);
47
48   if (argc > 1)
49     identities = atoi (argv[1]);
50   if (argc > 2)
51     buffers = atoi (argv[2]);
52   if (argc > 3)
53     src_name = argv[3];
54   if (argc > 4)
55     sink_name = argv[4];
56
57   g_print
58       ("*** benchmarking this pipeline: %s num-buffers=%u ! %u * identity ! %s\n",
59       src_name, buffers, identities, sink_name);
60   start = gst_get_current_time ();
61   pipeline = gst_element_factory_make ("pipeline", NULL);
62   g_assert (pipeline);
63   src = gst_element_factory_make (src_name, NULL);
64   if (!src) {
65     g_print ("no element named \"%s\" found, aborting...\n", src_name);
66     return 1;
67   }
68   g_object_set (src, "num-buffers", buffers, NULL);
69   sink = gst_element_factory_make (sink_name, NULL);
70   if (!sink) {
71     g_print ("no element named \"%s\" found, aborting...\n", sink_name);
72     return 1;
73   }
74   last = src;
75   gst_bin_add_many (GST_BIN (pipeline), src, sink, NULL);
76   for (i = 0; i < identities; i++) {
77     current = gst_element_factory_make ("identity", NULL);
78     g_assert (current);
79     /* shut this element up (no g_strdup_printf please) */
80     g_object_set (current, "silent", TRUE, NULL);
81     gst_bin_add (GST_BIN (pipeline), current);
82     if (!gst_element_link (last, current))
83       g_assert_not_reached ();
84     last = current;
85   }
86   if (!gst_element_link (last, sink))
87     g_assert_not_reached ();
88   end = gst_get_current_time ();
89   g_print ("%" GST_TIME_FORMAT " - creating %u identity elements\n",
90       GST_TIME_ARGS (end - start), identities);
91
92   start = gst_get_current_time ();
93   if (gst_element_set_state (pipeline,
94           GST_STATE_PLAYING) != GST_STATE_CHANGE_SUCCESS)
95     g_assert_not_reached ();
96   end = gst_get_current_time ();
97   g_print ("%" GST_TIME_FORMAT " - setting pipeline to playing\n",
98       GST_TIME_ARGS (end - start));
99
100   start = gst_get_current_time ();
101   gst_bus_poll (gst_element_get_bus (pipeline),
102       GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
103   end = gst_get_current_time ();
104   g_print ("%" GST_TIME_FORMAT " - putting %u buffers through\n",
105       GST_TIME_ARGS (end - start), buffers);
106
107   start = gst_get_current_time ();
108   g_object_unref (pipeline);
109   end = gst_get_current_time ();
110   g_print ("%" GST_TIME_FORMAT " - unreffing pipeline\n",
111       GST_TIME_ARGS (end - start));
112
113   return 0;
114 }