3 #include <gst/gstparse.h>
7 static int launch_argc;
8 static char **launch_argv;
12 GtkWidget *gtk_socket;
15 typedef void (*found_handler) (GstElement *element, gint xid, void *priv);
18 arg_search (GstBin *bin, gchar *argname, found_handler handler, void *priv)
23 ccargname = g_strdup_printf("::%s",argname);
25 children = gst_bin_get_list(bin);
31 child = GST_ELEMENT (children->data);
32 children = g_list_next (children);
34 if (GST_IS_BIN (child)) arg_search (GST_BIN (child), argname, handler, priv);
38 type = GTK_OBJECT_TYPE (child);
40 while (type != GTK_TYPE_INVALID) {
45 args = gtk_object_query_args(type,&flags,&num_args);
47 for (i=0;i<num_args;i++) {
48 if (strstr(args[i].name,ccargname)) {
49 (handler)(child, gst_util_get_int_arg (GTK_OBJECT (child), argname) ,priv);
52 type = gtk_type_parent(type);
62 idle_func (gpointer data)
64 if (!gst_bin_iterate (GST_BIN (data))) {
68 g_print ("iteration ended\n");
75 handle_have_size (GstElement *element,int width,int height)
78 gtk_widget_set_usize(gtk_socket,width,height);
79 gtk_widget_show_all(window);
84 xid_handler (GstElement *element, gint xid, void *priv)
87 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
89 gtk_socket = gtk_socket_new ();
90 gtk_widget_show(gtk_socket);
92 gtk_container_add(GTK_CONTAINER(window),gtk_socket);
94 gtk_widget_realize(gtk_socket);
95 gtk_socket_steal (GTK_SOCKET (gtk_socket), xid);
97 gtk_object_set(GTK_OBJECT(window),"allow_grow",TRUE,NULL);
98 gtk_object_set(GTK_OBJECT(window),"allow_shrink",TRUE,NULL);
100 gtk_signal_connect (GTK_OBJECT (element), "have_size",
101 GTK_SIGNAL_FUNC (handle_have_size), element);
106 main(int argc, char *argv[])
108 GstElement *pipeline;
112 gboolean save_pipeline = FALSE;
113 gboolean run_pipeline = TRUE;
114 gchar *savefile = "";
116 gst_init (&argc, &argv);
118 if (argc >= 3 && !strcmp(argv[1], "-o")) {
119 save_pipeline = TRUE;
120 run_pipeline = FALSE;
130 pipeline = gst_pipeline_new ("launch");
132 // make a null-terminated version of argv
133 argvn = g_new0 (char *,argc);
134 memcpy (argvn, argv+1, sizeof (char*) * (argc-1));
137 for (i=0; i<argc-1; i++) {
140 split = g_strsplit (argvn[i], " ", 0);
142 argvn[i] = g_strjoinv ("\\ ", split);
145 // join the argvs together
146 cmdline = g_strjoinv (" ", argvn);
147 // free the null-terminated argv
150 // fail if there are no pipes in it (needs pipes for a pipeline
151 if (!strchr(cmdline,'!')) {
152 fprintf(stderr,"ERROR: no pipeline description found on commandline\n");
156 if (gst_parse_launch (cmdline, GST_BIN (pipeline)) < 0){
157 fprintf(stderr,"ERROR: pipeline description could not be parsed\n");
161 #ifndef GST_DISABLE_LOADSAVE
163 xmlSaveFile (savefile, gst_xml_write (pipeline));
167 arg_search(GST_BIN(pipeline),"xid",xid_handler,NULL);
169 fprintf(stderr,"RUNNING pipeline\n");
170 if (gst_element_set_state (pipeline, GST_STATE_PLAYING) != GST_STATE_SUCCESS) {
171 fprintf(stderr,"pipeline doesn't want to play\n");
175 g_idle_add(idle_func,pipeline);
177 g_main_loop_run (g_main_loop_new (NULL, FALSE));
182 gst_element_set_state (pipeline, GST_STATE_NULL);