1 | #include <gst/gst.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <string.h> |
---|
4 | |
---|
5 | /* FIXME: WTF does this do? */ |
---|
6 | |
---|
7 | static guint64 max = 0, min = -1, total = 0; |
---|
8 | static guint count = 0; |
---|
9 | static guint print_del = 1; |
---|
10 | static guint iterations = 0; |
---|
11 | static guint mhz = 0; |
---|
12 | |
---|
13 | void |
---|
14 | handoff_src (GstElement * src, GstBuffer * buf, gpointer user_data) |
---|
15 | { |
---|
16 | gst_trace_read_tsc (&GST_BUFFER_TIMESTAMP (buf)); |
---|
17 | } |
---|
18 | |
---|
19 | void |
---|
20 | handoff_sink (GstElement * sink, GstBuffer * buf, gpointer user_data) |
---|
21 | { |
---|
22 | guint64 end, d, avg; |
---|
23 | guint avg_ns; |
---|
24 | |
---|
25 | gst_trace_read_tsc (&end); |
---|
26 | d = end - GST_BUFFER_TIMESTAMP (buf); |
---|
27 | if (d > max) |
---|
28 | max = d; |
---|
29 | if (d < min) |
---|
30 | min = d; |
---|
31 | total += d; |
---|
32 | count++; |
---|
33 | avg = total / count; |
---|
34 | avg_ns = (guint) (1000.0 * (double) avg / (double) mhz); |
---|
35 | |
---|
36 | if ((count % print_del) == 0) { |
---|
37 | g_print ("%07d:%08" G_GUINT64_FORMAT " min:%08" G_GUINT64_FORMAT " max:%08" |
---|
38 | G_GUINT64_FORMAT " avg:%08" G_GUINT64_FORMAT " avg-s:0.%09d\r", count, |
---|
39 | d, min, max, avg, avg_ns); |
---|
40 | } |
---|
41 | } |
---|
42 | |
---|
43 | GstElement * |
---|
44 | identity_add (GstPipeline * pipeline, GstElement * first, int count) |
---|
45 | { |
---|
46 | GstElement *last, *ident; |
---|
47 | int i; |
---|
48 | char buf[20]; |
---|
49 | |
---|
50 | last = first; |
---|
51 | |
---|
52 | for (i = 0; i < count; i++) { |
---|
53 | snprintf (buf, 20, "identity_%03d", i); |
---|
54 | ident = gst_element_factory_make ("identity", buf); |
---|
55 | g_return_val_if_fail (ident != NULL, NULL); |
---|
56 | g_object_set (G_OBJECT (ident), "silent", TRUE, NULL); |
---|
57 | gst_bin_add (GST_BIN (pipeline), GST_ELEMENT (ident)); |
---|
58 | gst_pad_link (gst_element_get_pad (last, "src"), |
---|
59 | gst_element_get_pad (ident, "sink")); |
---|
60 | last = ident; |
---|
61 | } |
---|
62 | |
---|
63 | return last; |
---|
64 | } |
---|
65 | |
---|
66 | GstElement * |
---|
67 | fakesrc (void) |
---|
68 | { |
---|
69 | GstElement *src; |
---|
70 | |
---|
71 | src = gst_element_factory_make ("fakesrc", "src"); |
---|
72 | g_return_val_if_fail (src != NULL, NULL); |
---|
73 | g_object_set (G_OBJECT (src), "silent", TRUE, NULL); |
---|
74 | g_object_set (G_OBJECT (src), "num_buffers", iterations, NULL); |
---|
75 | g_signal_connect (G_OBJECT (src), "handoff", G_CALLBACK (handoff_src), NULL); |
---|
76 | |
---|
77 | return src; |
---|
78 | } |
---|
79 | |
---|
80 | GstElement * |
---|
81 | fakesink (void) |
---|
82 | { |
---|
83 | GstElement *sink; |
---|
84 | |
---|
85 | sink = gst_element_factory_make ("fakesink", "fakesink"); |
---|
86 | g_return_val_if_fail (sink != NULL, NULL); |
---|
87 | g_object_set (G_OBJECT (sink), "silent", TRUE, NULL); |
---|
88 | g_signal_connect (G_OBJECT (sink), |
---|
89 | "handoff", G_CALLBACK (handoff_sink), NULL); |
---|
90 | |
---|
91 | return sink; |
---|
92 | } |
---|
93 | |
---|
94 | GstPipeline * |
---|
95 | simple (int argc, int argi, char *argv[]) |
---|
96 | { |
---|
97 | GstPipeline *pipeline; |
---|
98 | GstElement *last, *src, *sink; |
---|
99 | int idents; |
---|
100 | |
---|
101 | if ((argc - argi) < 1) { |
---|
102 | fprintf (stderr, "bad params"); |
---|
103 | return NULL; |
---|
104 | } |
---|
105 | idents = atoi (argv[argi]); |
---|
106 | if ((argc - argi) == 2) { |
---|
107 | gst_scheduler_factory_set_default_name (argv[argi + 1]); |
---|
108 | } |
---|
109 | |
---|
110 | pipeline = GST_PIPELINE (gst_pipeline_new ("pipeline")); |
---|
111 | g_return_val_if_fail (pipeline != NULL, NULL); |
---|
112 | |
---|
113 | src = fakesrc (); |
---|
114 | gst_bin_add (GST_BIN (pipeline), GST_ELEMENT (src)); |
---|
115 | last = identity_add (pipeline, src, idents); |
---|
116 | sink = fakesink (); |
---|
117 | gst_bin_add (GST_BIN (pipeline), GST_ELEMENT (sink)); |
---|
118 | gst_pad_link (gst_element_get_pad (last, "src"), |
---|
119 | gst_element_get_pad (sink, "sink")); |
---|
120 | |
---|
121 | return pipeline; |
---|
122 | } |
---|
123 | |
---|
124 | GstPipeline * |
---|
125 | queue (int argc, int argi, char *argv[]) |
---|
126 | { |
---|
127 | GstPipeline *pipeline; |
---|
128 | GstElement *last, *src, *sink, *src_thr, *src_q, *sink_q, *sink_thr; |
---|
129 | int idents; |
---|
130 | |
---|
131 | if ((argc - argi) < 1) { |
---|
132 | fprintf (stderr, "bad params"); |
---|
133 | return NULL; |
---|
134 | } |
---|
135 | idents = atoi (argv[argi]); |
---|
136 | |
---|
137 | if ((argc - argi) == 2) { |
---|
138 | gst_scheduler_factory_set_default_name (argv[argi + 1]); |
---|
139 | } |
---|
140 | |
---|
141 | pipeline = GST_PIPELINE (gst_pipeline_new ("pipeline")); |
---|
142 | g_return_val_if_fail (pipeline != NULL, NULL); |
---|
143 | |
---|
144 | src_thr = GST_ELEMENT (gst_thread_new ("src_thread")); |
---|
145 | g_return_val_if_fail (src_thr != NULL, NULL); |
---|
146 | |
---|
147 | src = fakesrc (); |
---|
148 | g_return_val_if_fail (src != NULL, NULL); |
---|
149 | gst_bin_add (GST_BIN (src_thr), GST_ELEMENT (src)); |
---|
150 | |
---|
151 | src_q = gst_element_factory_make ("queue", "src_q"); |
---|
152 | g_return_val_if_fail (src_q != NULL, NULL); |
---|
153 | gst_bin_add (GST_BIN (src_thr), GST_ELEMENT (src_q)); |
---|
154 | gst_pad_link (gst_element_get_pad (src, "src"), |
---|
155 | gst_element_get_pad (src_q, "sink")); |
---|
156 | |
---|
157 | gst_bin_add (GST_BIN (pipeline), GST_ELEMENT (src_thr)); |
---|
158 | |
---|
159 | last = identity_add (pipeline, src_q, idents); |
---|
160 | |
---|
161 | sink_q = gst_element_factory_make ("queue", "sink_q"); |
---|
162 | g_return_val_if_fail (sink_q != NULL, NULL); |
---|
163 | gst_bin_add (GST_BIN (pipeline), GST_ELEMENT (sink_q)); |
---|
164 | gst_pad_link (gst_element_get_pad (last, "src"), |
---|
165 | gst_element_get_pad (sink_q, "sink")); |
---|
166 | |
---|
167 | sink_thr = GST_ELEMENT (gst_thread_new ("sink_thread")); |
---|
168 | g_return_val_if_fail (sink_thr != NULL, NULL); |
---|
169 | |
---|
170 | sink = fakesink (); |
---|
171 | g_return_val_if_fail (sink != NULL, NULL); |
---|
172 | gst_bin_add (GST_BIN (sink_thr), GST_ELEMENT (sink)); |
---|
173 | |
---|
174 | gst_bin_add (GST_BIN (pipeline), GST_ELEMENT (sink_thr)); |
---|
175 | |
---|
176 | gst_pad_link (gst_element_get_pad (sink_q, "src"), |
---|
177 | gst_element_get_pad (sink, "sink")); |
---|
178 | |
---|
179 | return pipeline; |
---|
180 | } |
---|
181 | |
---|
182 | struct test |
---|
183 | { |
---|
184 | char *name; |
---|
185 | char *params; |
---|
186 | GstPipeline *(*func) (int argc, int argi, char *argv[]); |
---|
187 | }; |
---|
188 | |
---|
189 | static struct test tests[] = { |
---|
190 | {"simple", "ident_count [scheduler_name]", simple}, |
---|
191 | {"queue", "ident_count [scheduler_name]", queue}, |
---|
192 | {NULL, NULL, NULL} |
---|
193 | }; |
---|
194 | |
---|
195 | int |
---|
196 | main (int argc, char *argv[]) |
---|
197 | { |
---|
198 | GstPipeline *pipeline; |
---|
199 | int i; |
---|
200 | char *name; |
---|
201 | |
---|
202 | gst_init (&argc, &argv); |
---|
203 | |
---|
204 | if (argc < 3) { |
---|
205 | fprintf (stderr, |
---|
206 | "usage: %s iterations print_del mhz test_name [test_params...]\n", |
---|
207 | argv[0]); |
---|
208 | for (i = 0; tests[i].name; i++) { |
---|
209 | fprintf (stderr, " %s %s\n", tests[i].name, tests[i].params); |
---|
210 | } |
---|
211 | exit (1); |
---|
212 | } else { |
---|
213 | iterations = atoi (argv[1]); |
---|
214 | print_del = atoi (argv[2]); |
---|
215 | mhz = atoi (argv[3]); |
---|
216 | name = argv[4]; |
---|
217 | } |
---|
218 | |
---|
219 | pipeline = NULL; |
---|
220 | for (i = 0; tests[i].name && !pipeline; i++) { |
---|
221 | if (!strcmp (name, tests[i].name)) { |
---|
222 | pipeline = tests[i].func (argc, 5, argv); |
---|
223 | } |
---|
224 | } |
---|
225 | g_return_val_if_fail (pipeline != NULL, -1); |
---|
226 | |
---|
227 | /*xmlSaveFile("lat.gst", gst_xml_write(GST_ELEMENT(pipeline))); */ |
---|
228 | |
---|
229 | gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); |
---|
230 | |
---|
231 | while (count < iterations) { |
---|
232 | gst_bin_iterate (GST_BIN (pipeline)); |
---|
233 | } |
---|
234 | g_print ("\n"); |
---|
235 | |
---|
236 | return 0; |
---|
237 | } |
---|