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;
17 idle_func (gpointer data)
20 GTimeVal tfthen, tfnow;
21 GstClockTimeDiff diff;
24 //g_print ("%lld\n", gst_clock_get_time (s_clock));
27 g_get_current_time (&tfthen);
28 busy = gst_bin_iterate (GST_BIN (data));
30 g_get_current_time (&tfnow);
32 diff = GST_TIMEVAL_TO_TIME (tfnow) - GST_TIMEVAL_TO_TIME (tfthen);
35 min = MIN (min, diff);
36 max = MAX (max, diff);
41 g_print ("execution ended after %llu iterations (sum %llu ns, average %llu ns, min %llu ns, max %llu ns)\n",
42 iterations, sum, sum/iterations, min, max);
50 main (int argc, char *argv[])
53 gboolean verbose = FALSE;
54 gchar *exclude_args = NULL;
55 struct poptOption options[] = {
56 {"verbose", 'v', POPT_ARG_NONE | POPT_ARGFLAG_STRIP, &verbose, 0,
57 "do not output status information", NULL},
61 GstElement *pipeline = NULL;
65 gchar *md5string = g_malloc0 (33);
67 free (malloc (8)); /* -lefence */
69 setlocale (LC_ALL, "");
71 gst_init_with_popt_table (&argc, &argv, options);
73 /* make a parseable argvn array */
74 argvn = g_new0 (char *, argc);
75 memcpy (argvn, argv + 1, sizeof (char *) * (argc - 1));
77 /* Check if we have an element already that is called md5sink0
78 in the pipeline; if not, add one */
79 pipeline = (GstElement *) gst_parse_launchv ((const gchar **) argvn, &error);
82 g_warning ("pipeline could not be constructed: %s\n", error->message);
85 g_warning ("pipeline could not be constructed\n");
89 md5sink = gst_bin_get_by_name (GST_BIN (pipeline), "md5sink0");
90 if (md5sink == NULL) {
91 g_print ("adding an md5sink element to the pipeline\n");
92 /* make a null-terminated version of argv with ! md5sink appended
93 * ! is stored in argvn[argc - 1], md5sink in argvn[argc],
94 * NULL pointer in argvn[argc + 1] */
96 argvn = g_new0 (char *, argc + 2);
97 memcpy (argvn, argv + 1, sizeof (char *) * (argc - 1));
98 argvn[argc - 1] = g_strdup_printf ("!");
99 argvn[argc] = g_strdup_printf ("md5sink");
101 (GstElement *) gst_parse_launchv ((const gchar **) argvn, &error);
106 g_warning ("pipeline could not be constructed: %s\n", error->message);
107 g_error_free (error);
109 g_warning ("pipeline could not be constructed\n");
114 gchar **exclude_list = exclude_args ? g_strsplit (exclude_args, ",", 0)
117 g_signal_connect (pipeline, "deep_notify",
118 G_CALLBACK (gst_element_default_deep_notify), exclude_list);
120 g_signal_connect (pipeline, "error",
121 G_CALLBACK (gst_element_default_error), NULL);
123 if (gst_element_set_state (pipeline, GST_STATE_PLAYING) != GST_STATE_SUCCESS) {
124 g_warning ("pipeline doesn't want to play\n");
128 if (!GST_FLAG_IS_SET (GST_OBJECT (pipeline), GST_BIN_SELF_SCHEDULABLE)) {
129 g_idle_add (idle_func, pipeline);
132 gst_element_wait_state_change (pipeline);
135 gst_element_set_state (pipeline, GST_STATE_NULL);
137 /* print out md5sink here */
138 md5sink = gst_bin_get_by_name (GST_BIN (pipeline), "md5sink0");
140 g_object_get (G_OBJECT (md5sink), "md5", &md5string, NULL);
141 printf ("%s\n", md5string);
143 gst_object_unref (GST_OBJECT (pipeline));