Added gst-plugins-base-subtitles0.10-0.10.34 for Meego Harmattan 1.2
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / debian / patches / 0011-Startup-benchmarking-test.patch
1 From d1d935579a6248dd10a6681f130404519f815276 Mon Sep 17 00:00:00 2001
2 From: Maemo Multimedia <multimedia@maemo.org>
3 Date: Thu, 22 Jan 2009 09:57:49 +0200
4 Subject: [PATCH] Startup benchmarking test
5
6 ---
7  configure.ac                 |    1 +
8  tests/benchmarks/Makefile.am |    4 +
9  tests/benchmarks/startup.c   |  255 ++++++++++++++++++++++++++++++++++++++++++
10  3 files changed, 260 insertions(+), 0 deletions(-)
11  create mode 100644 tests/benchmarks/Makefile.am
12  create mode 100644 tests/benchmarks/startup.c
13
14 diff --git a/configure.ac b/configure.ac
15 index 4de8751..a7e72c6 100644
16 --- a/configure.ac
17 +++ b/configure.ac
18 @@ -1003,6 +1003,7 @@ pkgconfig/gstreamer-video-uninstalled.pc
19  pkgconfig/gstreamer-plugins-base.pc
20  pkgconfig/gstreamer-plugins-base-uninstalled.pc
21  tests/Makefile
22 +tests/benchmarks/Makefile
23  tests/check/Makefile
24  tests/examples/Makefile
25  tests/examples/app/Makefile
26 diff --git a/tests/benchmarks/Makefile.am b/tests/benchmarks/Makefile.am
27 new file mode 100644
28 index 0000000..93a2440
29 --- /dev/null
30 +++ b/tests/benchmarks/Makefile.am
31 @@ -0,0 +1,4 @@
32 +noinst_PROGRAMS = startup
33 +
34 +AM_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_CFLAGS)
35 +LDADD = $(GST_LIBS)
36 diff --git a/tests/benchmarks/startup.c b/tests/benchmarks/startup.c
37 new file mode 100644
38 index 0000000..4d39f9d
39 --- /dev/null
40 +++ b/tests/benchmarks/startup.c
41 @@ -0,0 +1,255 @@
42 +#include <stdio.h>
43 +#include <stdlib.h>
44 +#include <gst/gst.h>
45 +
46 +GList *sink_list = NULL;
47 +GMainLoop *loop = NULL;
48 +GstClockTime generic_start;
49 +GstClockTime generic_end;
50 +GstClockTime null_start;
51 +GstClockTime paused_start;
52 +GstClockTime playing_end;
53 +guint profile = 0;
54 +guint id = 0;
55 +
56 +static GstClockTime
57 +gst_get_current_time (void)
58 +{
59 +  GTimeVal tv;
60 +
61 +  g_get_current_time (&tv);
62 +  return GST_TIMEVAL_TO_TIME (tv);
63 +}
64 +
65 +void dbin_dpad_cb (GstElement* e,
66 +                   GstPad* pad,
67 +                   gboolean cont,
68 +                   gpointer user_data)
69 +{
70 +    GstElement *pipeline;
71 +    GstCaps *padcaps;
72 +    gboolean audio = FALSE;
73 +
74 +    pipeline = (GstElement *) user_data;
75 +
76 +    padcaps = gst_pad_get_caps (pad);
77 +
78 +    if (padcaps) {
79 +        GstStructure *stru;
80 +        const gchar *name;
81 +
82 +        stru = gst_caps_get_structure ((const GstCaps *) padcaps, 0);
83 +        name = gst_structure_get_name (stru);
84 +        if (g_strrstr (name, "audio/x-raw")) {
85 +            audio = TRUE;
86 +        }
87 +        gst_caps_unref (padcaps);
88 +    }
89 +
90 +    if (audio) {
91 +#if 0
92 +        GstElement *conv, *resamp, *sink;
93 +        GstBin *bin;
94 +        GstPad *spad, *gpad;
95 +
96 +        printf ("creating audio bin\n");
97 +
98 +        bin = (GstBin *) gst_bin_new ("abin");
99 +        gst_object_ref (bin);
100 +        gst_object_sink (bin);
101 +
102 +        conv = gst_element_factory_make ("audioconvert", "aconv");
103 +        resamp = gst_element_factory_make ("audioresample", "aresample");
104 +        sink = gst_element_factory_make ("autoaudiosink", "audiosink");
105 +
106 +        gst_bin_add_many (bin, conv, resamp, sink, NULL);
107 +        gst_element_link_pads (conv, "src", resamp, "sink");
108 +        gst_element_link_pads (resamp, "src", sink, "sink");
109 +
110 +        gst_bin_add (GST_BIN_CAST (pipeline), GST_ELEMENT_CAST (bin));
111 +
112 +        spad = gst_element_get_static_pad (conv, "sink");
113 +        gpad = gst_ghost_pad_new ("sink", spad);
114 +        gst_element_add_pad (GST_ELEMENT_CAST (bin), gpad);
115 +        gst_object_unref (spad);
116 +
117 +        gst_pad_link (pad, gpad);
118 +        sink_list = g_list_append (sink_list, bin);
119 +#else
120 +        GstElement *sink;
121 +        GstPad *spad;
122 +
123 +        sink = gst_element_factory_make ("alsasink", "audiosink");
124 +        gst_bin_add (GST_BIN_CAST (pipeline), sink);
125 +        gst_element_set_state (sink, GST_STATE_PAUSED);
126 +        spad = gst_element_get_static_pad (sink, "sink");
127 +        gst_pad_link (pad, spad);
128 +        gst_object_unref (spad);
129 +        sink_list = g_list_append (sink_list, sink);
130 +#endif
131 +
132 +    }
133 +    else {
134 +        GstElement *fsink;
135 +        GstPad *fsinkpad;
136 +
137 +        printf ("creating fakesink for non-audio pad\n");
138 +
139 +        fsink = gst_element_factory_make ("fakesink", NULL);
140 +        sink_list = g_list_append (sink_list, fsink);
141 +        gst_element_set_state (fsink, GST_STATE_PAUSED);
142 +        gst_bin_add (GST_BIN_CAST (pipeline), fsink);
143 +        fsinkpad = gst_element_get_static_pad (fsink, "sink");
144 +        gst_pad_link (pad, fsinkpad);
145 +        gst_object_unref (fsinkpad);
146 +    }
147 +}
148 +
149 +
150 +static gboolean
151 +metadata_bus_async_cb (GstBus *bus, GstMessage *msg, gpointer data)
152 +{
153 +    GError *error = NULL;
154 +    GstElement *pipeline = (GstElement *) data;
155 +    gboolean stop = FALSE;
156 +
157 +    switch (GST_MESSAGE_TYPE (msg)) {
158 +        case GST_MESSAGE_ERROR:
159 +            gst_message_parse_error (msg, &error, NULL);
160 +            printf ("ERROR: %s\n", error->message);
161 +            g_error_free (error);
162 +            stop = TRUE;
163 +            break;
164 +        case GST_MESSAGE_EOS:
165 +            printf ("    EOS\n");
166 +            stop = TRUE;
167 +            break;
168 +        case GST_MESSAGE_STATE_CHANGED:
169 +        {
170 +            GstElement *sender = (GstElement *) GST_MESSAGE_SRC (msg);
171 +            if (sender == pipeline) {
172 +                GstState newstate;
173 +                gst_message_parse_state_changed (msg, NULL, &newstate, NULL);
174 +                if (newstate == GST_STATE_PLAYING) {
175 +                    if (profile) {
176 +                        system ("opcontrol --stop");
177 +                        printf ("=== PROFILER STOPPED ===\n");
178 +                    }
179 +                    playing_end = gst_get_current_time ();
180 +                    printf ("Startup time from NULL:   %" GST_TIME_FORMAT "\n",
181 +                            GST_TIME_ARGS (playing_end - null_start));
182 +                    printf ("Startup time from PAUSED: %" GST_TIME_FORMAT "\n",
183 +                            GST_TIME_ARGS (playing_end - paused_start));
184 +                    stop = TRUE;
185 +                }
186 +                else if (newstate == GST_STATE_PAUSED) {
187 +                    paused_start = gst_get_current_time ();
188 +                }
189 +            }
190 +        }
191 +        default:
192 +            break;
193 +    }
194 +
195 +    if (stop) {
196 +          gst_element_set_state (pipeline, GST_STATE_READY);
197 +          g_main_loop_quit (loop);
198 +    }
199 +
200 +    return TRUE;
201 +}
202 +
203 +int main(int argc, char **argv)
204 +{
205 +    GstElement *pipeline;
206 +    GstBus *bus;
207 +    int pipe_type = 0;
208 +
209 +    if(argc < 4) {
210 +        printf ("\nUSAGE: %s <pipeline_type> <profile (0/1)> <URI> [<typefind caps for decodebin2>]\n\n", argv[0]);
211 +        printf ("  Pipeline type: 0: Hardcoded MP3 pipeline\n");
212 +        printf ("                 1: Playbin2\n");
213 +        printf ("                 2: Decodebin2\n\n");
214 +        exit (1);
215 +    }
216 +
217 +    pipe_type = atoi (argv[1]);
218 +    profile   = atoi (argv[2]);
219 +
220 +    printf ("============================================================\n");
221 +
222 +    generic_start = gst_get_current_time ();
223 +    gst_init (&argc, &argv);
224 +    generic_end = gst_get_current_time ();
225 +
226 +    printf ("gst_init() time:          %" GST_TIME_FORMAT "\n",
227 +            GST_TIME_ARGS (generic_end - generic_start));
228 +
229 +    if (pipe_type == 0) {
230 +        GstElement *src, *dec, *sink;
231 +        pipeline = gst_element_factory_make ("pipeline", NULL);
232 +        src  = gst_element_factory_make ("filesrc", NULL);
233 +        dec  = gst_element_factory_make ("omx_mp3dec", NULL);
234 +        sink = gst_element_factory_make ("alsasink", NULL);
235 +        gst_bin_add_many (GST_BIN_CAST (pipeline), src, dec, sink, NULL);
236 +        gst_element_link_many (src, dec, sink, NULL);
237 +
238 +        g_object_set (G_OBJECT (src), "location", argv[3], NULL);
239 +        g_object_set (G_OBJECT (dec), "use-timestamps", FALSE, NULL);
240 +    }
241 +    else if (pipe_type == 1) {
242 +        pipeline = gst_element_factory_make ("playbin2", NULL);
243 +        g_object_set (G_OBJECT (pipeline), "uri", argv[3], NULL);
244 +        g_object_set (G_OBJECT (pipeline), "skip-metadata", TRUE, NULL);
245 +    }
246 +    else if (pipe_type == 2) {
247 +        GstElement *src, *dec;
248 +        GstCaps *filecaps;
249 +
250 +        pipeline = gst_element_factory_make ("pipeline", NULL);
251 +        src  = gst_element_factory_make ("filesrc", NULL);
252 +        dec  = gst_element_factory_make ("decodebin2", NULL);
253 +        gst_bin_add_many (GST_BIN_CAST (pipeline), src, dec, NULL);
254 +        gst_element_link_many (src, dec, NULL);
255 +
256 +        g_object_set (G_OBJECT (src), "location", argv[3], NULL);
257 +        g_object_set (G_OBJECT (dec), "skip-metadata", TRUE, NULL);
258 +
259 +        if (argc >= 5) {
260 +            printf ("Setting caps '%s' to skip typefinding!\n", argv[4]);
261 +            filecaps = gst_caps_from_string (argv[4]);
262 +            g_object_set (G_OBJECT (dec), "sink-caps", filecaps, NULL);
263 +            gst_caps_unref (filecaps);
264 +        }
265 +
266 +        id = g_signal_connect (G_OBJECT (dec), "new-decoded-pad",
267 +                               G_CALLBACK (dbin_dpad_cb), pipeline);
268 +
269 +    }
270 +    else {
271 +      printf ("Unknown pipeline type\n");
272 +      goto leave;
273 +    }
274 +
275 +    loop = g_main_loop_new (NULL, FALSE);
276 +    bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
277 +    gst_bus_add_watch (bus, metadata_bus_async_cb, pipeline);
278 +
279 +    if (profile) {
280 +        system ("opcontrol --start");
281 +        printf ("=== PROFILER RUNNING ===\n");
282 +    }
283 +
284 +    null_start = gst_get_current_time ();
285 +    gst_element_set_state (pipeline, GST_STATE_PLAYING);
286 +    g_main_loop_run (loop);
287 +
288 +    gst_element_set_state (pipeline, GST_STATE_NULL);
289 +    gst_object_unref (bus);
290 +    gst_object_unref (GST_OBJECT (pipeline));
291 +
292 +leave:
293 +    printf ("============================================================\n");
294 +
295 +    return 0;
296 +}