10 static guint64 iterations = 0;
11 static guint64 sum = 0;
12 static guint64 min = G_MAXINT64;
13 static guint64 max = 0;
14 static GstClock *s_clock;
15 static GMainLoop *loop;
18 idle_func (gpointer data)
21 GTimeVal tfthen, tfnow;
22 GstClockTimeDiff diff;
25 //g_print ("%lld\n", gst_clock_get_time (s_clock));
28 g_get_current_time (&tfthen);
29 busy = gst_bin_iterate (GST_BIN (data));
31 g_get_current_time (&tfnow);
33 diff = GST_TIMEVAL_TO_TIME (tfnow) - GST_TIMEVAL_TO_TIME (tfthen);
36 min = MIN (min, diff);
37 max = MAX (max, diff);
40 g_main_loop_quit (loop);
41 g_main_loop_unref (loop);
43 g_print ("execution ended after %llu iterations (sum %llu ns, average %llu ns, min %llu ns, max %llu ns)\n",
44 iterations, sum, sum/iterations, min, max);
52 main (int argc, char *argv[])
55 gboolean verbose = FALSE;
56 gchar *exclude_args = NULL;
57 struct poptOption options[] = {
58 {"verbose", 'v', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &verbose, 0,
59 "do not output status information", NULL},
63 GstElement *pipeline = NULL;
67 gchar *md5string = g_malloc0 (33);
69 free (malloc (8)); /* -lefence */
71 setlocale (LC_ALL, "");
73 gst_init_with_popt_table (&argc, &argv, options);
75 /* make a parseable argvn array */
76 argvn = g_new0 (char *, argc);
77 memcpy (argvn, argv + 1, sizeof (char *) * (argc - 1));
79 /* Check if we have an element already that is called md5sink0
80 in the pipeline; if not, add one */
81 pipeline = (GstElement *) gst_parse_launchv ((const gchar **) argvn, &error);
84 g_warning ("pipeline could not be constructed: %s\n", error->message);
87 g_warning ("pipeline could not be constructed\n");
91 md5sink = gst_bin_get_by_name (GST_BIN (pipeline), "md5sink0");
92 if (md5sink == NULL) {
93 g_print ("adding an md5sink element to the pipeline\n");
94 /* make a null-terminated version of argv with ! md5sink appended
95 * ! is stored in argvn[argc - 1], md5sink in argvn[argc],
96 * NULL pointer in argvn[argc + 1] */
98 argvn = g_new0 (char *, argc + 2);
99 memcpy (argvn, argv + 1, sizeof (char *) * (argc - 1));
100 argvn[argc - 1] = g_strdup_printf ("!");
101 argvn[argc] = g_strdup_printf ("md5sink");
103 (GstElement *) gst_parse_launchv ((const gchar **) argvn, &error);
108 g_warning ("pipeline could not be constructed: %s\n", error->message);
109 g_error_free (error);
111 g_warning ("pipeline could not be constructed\n");
116 gchar **exclude_list = exclude_args ? g_strsplit (exclude_args, ",", 0)
119 g_signal_connect (pipeline, "deep_notify",
120 G_CALLBACK (gst_element_default_deep_notify), exclude_list);
122 g_signal_connect (pipeline, "error",
123 G_CALLBACK (gst_element_default_error), NULL);
125 if (gst_element_set_state (pipeline, GST_STATE_PLAYING) != GST_STATE_SUCCESS) {
126 g_warning ("pipeline doesn't want to play\n");
130 if (!GST_FLAG_IS_SET (GST_OBJECT (pipeline), GST_BIN_SELF_SCHEDULABLE)) {
131 g_idle_add (idle_func, pipeline);
132 loop = g_main_loop_new (NULL, FALSE);
133 g_main_loop_run (loop);
135 gst_element_wait_state_change (pipeline);
138 gst_element_set_state (pipeline, GST_STATE_NULL);
140 /* print out md5sink here */
141 md5sink = gst_bin_get_by_name (GST_BIN (pipeline), "md5sink0");
143 g_object_get (G_OBJECT (md5sink), "md5", &md5string, NULL);
144 printf ("%s\n", md5string);
146 gst_object_unref (GST_OBJECT (pipeline));