3 #include <gst/gstparse.h>
6 #include <gst/gstpropsprivate.h>
9 static int launch_argc;
10 static char **launch_argv;
12 static guint64 iterations = 0;
13 static guint64 sum = 0;
14 static guint64 min = G_MAXINT;
15 static guint64 max = 0;
18 idle_func (gpointer data)
21 struct timeval tfthen, tfnow;
24 gettimeofday (&tfthen, (struct timezone *)NULL);
25 busy = gst_bin_iterate (GST_BIN (data));
27 gettimeofday (&tfnow, (struct timezone *)NULL);
29 diff = ((guint64)tfnow.tv_sec*1000000LL+tfnow.tv_usec) -
30 ((guint64)tfthen.tv_sec*1000000LL+tfthen.tv_usec);
33 min = MIN (min, diff);
34 max = MAX (max, diff);
38 g_print ("execution ended after %llu iterations (sum %llu us, average %llu us, min %llu us, max %llu us)\n",
39 iterations, sum, sum/iterations, min, max);
46 property_change_callback (GObject *object, GstObject *orig, GParamSpec *pspec)
48 GValue value = { 0, }; /* the important thing is that value.type = 0 */
51 if (pspec->flags & G_PARAM_READABLE) {
52 g_value_init(&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
53 g_object_get_property (G_OBJECT (orig), pspec->name, &value);
54 /* fix current bug with g_strdup_value_contents not working with gint64 */
55 if (G_IS_PARAM_SPEC_INT64 (pspec))
56 str = g_strdup_printf ("%lld", g_value_get_int64 (&value));
58 str = g_strdup_value_contents (&value);
59 g_print ("%s: %s = %s\n", GST_OBJECT_NAME (orig), pspec->name, str);
61 g_value_unset(&value);
63 g_warning ("Parameter not readable. What's up with that?");
68 error_callback (GObject *object, GstObject *orig, gchar *error)
70 g_print ("ERROR: %s: %s\n", GST_OBJECT_NAME (orig), error);
74 xmllaunch_parse_cmdline (const gchar **argv)
76 GstElement *pipeline = NULL, *e;
80 gchar *element, *property, *value;
84 if (!(arg = argv[0])) {
85 g_print ("usage: gst-xmllaunch <file.xml> [ element.property=value ... ]\n");
90 err = gst_xml_parse_file(xml, arg, NULL);
93 fprintf (stderr, "ERROR: parse of xml file '%s' failed\n", arg);
97 l = gst_xml_get_topelements (xml);
99 fprintf (stderr, "ERROR: no toplevel pipeline element in file '%s'\n", arg);
104 g_warning ("only one toplevel element is supported at this time");
106 pipeline = GST_ELEMENT (l->data);
108 while ((arg = argv[++i])) {
109 element = g_strdup (arg);
110 property = strchr (element, '.');
111 value = strchr (element, '=');
113 if (!(element < property && property < value)) {
114 fprintf (stderr, "ERROR: could not parse command line argument %d: %s", i, element);
122 e = gst_bin_get_by_name (GST_BIN (pipeline), element);
124 g_warning ("element named '%s' not found", element);
126 gst_util_set_object_arg (G_OBJECT (e), property, value);
138 main(int argc, char *argv[])
141 gboolean silent = FALSE;
142 struct poptOption options[] = {
143 {"silent", 's', POPT_ARG_NONE|POPT_ARGFLAG_STRIP, &silent, 0, "do not output status information", NULL},
147 GstElement *pipeline;
149 gboolean save_pipeline = FALSE;
150 gboolean run_pipeline = TRUE;
151 gchar *savefile = "";
153 free (malloc (8)); /* -lefence */
155 gst_init_with_popt_table (&argc, &argv, options);
157 if (argc >= 3 && !strcmp(argv[1], "-o")) {
158 save_pipeline = TRUE;
159 run_pipeline = FALSE;
169 /* make a null-terminated version of argv */
170 argvn = g_new0 (char *,argc);
171 memcpy (argvn, argv+1, sizeof (char*) * (argc-1));
172 if (strstr (argv[0], "gst-xmllaunch")) {
173 pipeline = xmllaunch_parse_cmdline (argvn);
175 pipeline = (GstElement*) gst_parse_launchv (argvn);
179 fprintf(stderr, "ERROR: pipeline could not be constructed\n");
184 g_signal_connect (pipeline, "deep_notify", G_CALLBACK (property_change_callback), NULL);
185 g_signal_connect (pipeline, "error", G_CALLBACK (error_callback), NULL);
187 #ifndef GST_DISABLE_LOADSAVE
189 gst_xml_write_file (GST_ELEMENT (pipeline), fopen (savefile, "w"));
194 gst_buffer_print_stats();
195 fprintf(stderr,"RUNNING pipeline\n");
196 if (gst_element_set_state (pipeline, GST_STATE_PLAYING) != GST_STATE_SUCCESS) {
197 fprintf(stderr,"pipeline doesn't want to play\n");
201 if (!GST_FLAG_IS_SET (GST_OBJECT (pipeline), GST_BIN_SELF_ITERATING)) {
202 g_idle_add (idle_func, pipeline);
205 g_print ("sleeping 100...\n");
209 gst_element_set_state (pipeline, GST_STATE_NULL);
210 gst_buffer_print_stats();
213 gst_object_unref (GST_OBJECT (pipeline));