5 static guint64 iterations = 0;
6 static guint64 sum = 0;
7 static guint64 min = G_MAXINT64;
8 static guint64 max = 0;
9 static GstClock *s_clock;
12 idle_func (gpointer data)
15 GTimeVal tfthen, tfnow;
16 GstClockTimeDiff diff;
19 //g_print ("%lld\n", gst_clock_get_time (s_clock));
22 g_get_current_time (&tfthen);
23 busy = gst_bin_iterate (GST_BIN (data));
25 g_get_current_time (&tfnow);
27 diff = GST_TIMEVAL_TO_TIME (tfnow) -
28 GST_TIMEVAL_TO_TIME (tfthen);
31 min = MIN (min, diff);
32 max = MAX (max, diff);
36 g_print ("execution ended after %llu iterations (sum %llu ns, average %llu ns, min %llu ns, max %llu ns)\n",
37 iterations, sum, sum/iterations, min, max);
44 xmllaunch_parse_cmdline (const gchar **argv)
46 GstElement *pipeline = NULL, *e;
50 gchar *element, *property, *value;
54 if (!(arg = argv[0])) {
55 g_print ("usage: gst-xmllaunch <file.xml> [ element.property=value ... ]\n");
60 err = gst_xml_parse_file(xml, arg, NULL);
63 fprintf (stderr, "ERROR: parse of xml file '%s' failed\n", arg);
67 l = gst_xml_get_topelements (xml);
69 fprintf (stderr, "ERROR: no toplevel pipeline element in file '%s'\n", arg);
74 g_warning ("only one toplevel element is supported at this time");
76 pipeline = GST_ELEMENT (l->data);
78 while ((arg = argv[++i])) {
79 element = g_strdup (arg);
80 property = strchr (element, '.');
81 value = strchr (element, '=');
83 if (!(element < property && property < value)) {
84 fprintf (stderr, "ERROR: could not parse command line argument %d: %s", i, element);
92 e = gst_bin_get_by_name (GST_BIN (pipeline), element);
94 g_warning ("element named '%s' not found", element);
96 gst_util_set_object_arg (G_OBJECT (e), property, value);
108 main(int argc, char *argv[])
111 gboolean silent = FALSE;
112 gchar *savefile = NULL;
113 gchar *exclude_args = NULL;
114 struct poptOption options[] = {
115 {"silent", 's', POPT_ARG_NONE|POPT_ARGFLAG_STRIP, &silent, 0,
116 "do not output status information", NULL},
117 {"exclude", 'X', POPT_ARG_STRING|POPT_ARGFLAG_STRIP, &exclude_args, 0,
118 "do not output status information of TYPE", "TYPE1,TYPE2,..."},
119 {"output", 'o', POPT_ARG_STRING|POPT_ARGFLAG_STRIP, &savefile, 0,
120 "save xml representation of pipeline to FILE and exit", "FILE"},
124 GstElement *pipeline;
126 GError *error = NULL;
128 free (malloc (8)); /* -lefence */
130 gst_init_with_popt_table (&argc, &argv, options);
132 /* make a null-terminated version of argv */
133 argvn = g_new0 (char*, argc);
134 memcpy (argvn, argv+1, sizeof (char*) * (argc-1));
135 if (strstr (argv[0], "gst-xmllaunch")) {
136 pipeline = xmllaunch_parse_cmdline ((const gchar**)argvn);
138 pipeline = (GstElement*) gst_parse_launchv ((const gchar**)argvn, &error);
145 fprintf(stderr, "ERROR: pipeline could not be constructed: %s\n", error->message);
147 fprintf(stderr, "ERROR: pipeline could not be constructed\n");
153 gchar **exclude_list = exclude_args ? g_strsplit (exclude_args, ",", 0) : NULL;
154 g_signal_connect (pipeline, "deep_notify", G_CALLBACK (gst_element_default_deep_notify), exclude_list);
156 g_signal_connect (pipeline, "error", G_CALLBACK (gst_element_default_error), NULL);
158 #ifndef GST_DISABLE_LOADSAVE
160 gst_xml_write_file (GST_ELEMENT (pipeline), fopen (savefile, "w"));
165 gst_buffer_print_stats();
166 gst_event_print_stats();
168 fprintf(stderr,"RUNNING pipeline\n");
169 if (gst_element_set_state (pipeline, GST_STATE_PLAYING) != GST_STATE_SUCCESS) {
170 fprintf(stderr,"pipeline doesn't want to play\n");
174 s_clock = gst_bin_get_clock (GST_BIN (pipeline));
176 if (!GST_FLAG_IS_SET (GST_OBJECT (pipeline), GST_BIN_SELF_SCHEDULABLE)) {
177 g_idle_add (idle_func, pipeline);
180 g_print ("waiting for the state change...\n");
181 gst_element_wait_state_change (pipeline);
182 g_print ("got the state change...\n");
185 gst_element_set_state (pipeline, GST_STATE_NULL);
186 gst_buffer_print_stats();
187 gst_event_print_stats();
190 gst_object_unref (GST_OBJECT (pipeline));