This is a megapatch with the following changes:
[platform/upstream/gstreamer.git] / tests / sched / runxml.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <gst/gst.h>
4
5 static guint outcount, incount;
6
7 static void
8 buffer_handoff_sink (GstElement *src, GstElement *bin)
9 {
10   g_print ("\n\n *** buffer arrived in sink ***\n\n");
11   gst_element_set_state(bin, GST_STATE_NULL);
12
13   outcount++;
14 }
15
16 static void
17 buffer_handoff_src (GstElement *src, GstElement *bin)
18 {
19   g_print ("\n\n *** buffer started in src ***\n\n");
20   incount++;
21 }
22
23 /* eos will be called when the src element has an end of stream */
24 void eos(GstElement *element, gpointer data)
25 {
26   g_print("have eos, quitting\n");
27 }
28
29 int main(int argc,char *argv[]) 
30 {
31   GstXML *xml;
32   GList *toplevelelements;
33   gint i = 1;
34
35   gst_init(&argc,&argv);
36
37   if (argc < 2) {
38     g_print ("usage: %s <xml file>\n", argv[0]);
39     exit (-1);
40   }
41
42   g_print ("\n *** using testfile %s\n", argv[1]);
43
44   xml = gst_xml_new();
45   xml = gst_xml_parse_file (xml, argv[1], NULL);
46
47   toplevelelements = gst_xml_get_topelements (xml);
48
49   while (toplevelelements) {
50     GstElement *bin = (GstElement *)toplevelelements->data;
51     GstElement *src, *sink;
52
53     g_print ("\n ***** testcase %d\n", i++);
54
55     src = gst_bin_get_by_name (GST_BIN (bin), "fakesrc");
56     if (src) {
57       gtk_signal_connect (GTK_OBJECT(src), "handoff",
58                    GTK_SIGNAL_FUNC(buffer_handoff_src), bin);
59     }
60     else {
61       g_print ("could not find src element\n");
62       exit(-1);
63     }
64     
65     sink = gst_bin_get_by_name (GST_BIN (bin), "fakesink");
66     if (sink) {
67       gtk_signal_connect (GTK_OBJECT(sink), "handoff",
68                    GTK_SIGNAL_FUNC(buffer_handoff_sink), bin);
69     }
70     else {
71       g_print ("could not find sink element\n");
72       exit(-1);
73     }
74
75     incount = 0;
76     outcount = 0;
77
78 //    gst_element_set_state(bin, GST_STATE_READY);
79     gst_element_set_state(bin, GST_STATE_PLAYING);
80
81     if (GST_IS_THREAD (bin)) {
82       sleep (1);
83     }
84     else {
85       gst_bin_iterate(GST_BIN(bin));
86     }
87
88     if (outcount != 1 && incount != 1) {
89       g_print ("test failed\n");
90       exit (-1);
91     }
92
93     toplevelelements = g_list_next (toplevelelements);
94   }
95
96   exit(0);
97 }
98