docs/: Dist the overrides files.
[platform/upstream/gstreamer.git] / tests / benchmarks / complexity.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 BUFFER_COUNT (1000)
22 #define SRC_ELEMENT "fakesrc"
23 #define SINK_ELEMENT "fakesink"
24
25
26 static GstClockTime
27 gst_get_current_time (void)
28 {
29   GTimeVal tv;
30
31   g_get_current_time (&tv);
32   return GST_TIMEVAL_TO_TIME (tv);
33 }
34
35 gint
36 main (gint argc, gchar * argv[])
37 {
38   GstElement *pipeline, *src, *e;
39   GSList *saved_src_list, *src_list, *new_src_list;
40   guint complexity_order, n_elements, i, j, max_this_level;
41   GstClockTime start, end;
42   gboolean all_srcs_linked;
43
44   gst_init (&argc, &argv);
45
46   if (argc != 3) {
47     g_print ("usage: %s COMPLEXITY_ORDER N_ELEMENTS\n", argv[0]);
48     return 1;
49   }
50
51   complexity_order = atoi (argv[1]);
52   n_elements = atoi (argv[2]);
53
54   start = gst_get_current_time ();
55
56   pipeline = gst_element_factory_make ("pipeline", NULL);
57   g_assert (pipeline);
58
59   e = gst_element_factory_make ("fakesrc", NULL);
60   g_object_set (e, "num-buffers", BUFFER_COUNT, NULL);
61   g_object_set (e, "silent", TRUE, NULL);
62   gst_bin_add (GST_BIN (pipeline), e);
63   src_list = saved_src_list = g_slist_append (NULL, e);
64
65   new_src_list = NULL;
66
67   max_this_level = 1;
68   j = 0;
69   i = 0;
70   all_srcs_linked = FALSE;
71   for (i = 0, j = 0; i < n_elements; i++, j++) {
72     if (j >= max_this_level) {
73       g_slist_free (saved_src_list);
74       saved_src_list = g_slist_reverse (new_src_list);
75       new_src_list = NULL;
76       j = 0;
77       all_srcs_linked = FALSE;
78       max_this_level *= complexity_order;
79     }
80
81     if (!src_list) {
82       if (j)
83         all_srcs_linked = TRUE;
84       src_list = saved_src_list;
85     }
86
87     src = (GstElement *) src_list->data;
88     src_list = src_list->next;
89
90     if (i + max_this_level < n_elements) {
91       e = gst_element_factory_make ("tee", NULL);
92     } else {
93       e = gst_element_factory_make ("fakesink", NULL);
94       g_object_set (e, "preroll-queue-len", 1, NULL);
95     }
96     g_object_set (e, "silent", TRUE, NULL);
97     new_src_list = g_slist_prepend (new_src_list, e);
98
99     gst_bin_add (GST_BIN (pipeline), e);
100     if (!gst_element_link (src, e))
101       g_assert_not_reached ();
102   }
103
104   g_slist_free (saved_src_list);
105   g_slist_free (new_src_list);
106
107   end = gst_get_current_time ();
108   g_print ("%" GST_TIME_FORMAT " - creating and linking %d elements\n",
109       GST_TIME_ARGS (end - start), i);
110
111   start = gst_get_current_time ();
112   if (gst_element_set_state (pipeline, GST_STATE_PLAYING) != GST_STATE_SUCCESS)
113     g_assert_not_reached ();
114   end = gst_get_current_time ();
115   g_print ("%" GST_TIME_FORMAT " - setting pipeline to playing\n",
116       GST_TIME_ARGS (end - start));
117
118   start = gst_get_current_time ();
119   gst_bus_poll (gst_element_get_bus (pipeline),
120       GST_MESSAGE_EOS | GST_MESSAGE_ERROR, -1);
121   end = gst_get_current_time ();
122   g_print ("%" GST_TIME_FORMAT " - putting %u buffers through\n",
123       GST_TIME_ARGS (end - start), BUFFER_COUNT);
124
125   start = gst_get_current_time ();
126   g_object_unref (pipeline);
127   end = gst_get_current_time ();
128   g_print ("%" GST_TIME_FORMAT " - unreffing pipeline\n",
129       GST_TIME_ARGS (end - start));
130
131   return 0;
132 }