7534907618c704372a4708979e7fe0dd544bb2f1
[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, GstBuffer * buf, 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, GstBuffer * buf, 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
25 eos (GstElement * element, gpointer data)
26 {
27   g_print ("have eos, quitting\n");
28 }
29
30 int
31 main (int argc, char *argv[])
32 {
33   GstXML *xml;
34   GList *toplevelelements;
35   gint i = 1;
36
37   gst_init (&argc, &argv);
38
39   if (argc < 2) {
40     g_print ("usage: %s <xml file>\n", argv[0]);
41     exit (-1);
42   }
43
44   g_print ("\n *** using testfile %s\n", argv[1]);
45
46   xml = gst_xml_new ();
47   gst_xml_parse_file (xml, argv[1], NULL);
48
49   toplevelelements = gst_xml_get_topelements (xml);
50
51   while (toplevelelements) {
52     GstElement *bin = (GstElement *) toplevelelements->data;
53     GstElement *src, *sink;
54
55     g_print ("\n ***** testcase %d\n", i++);
56
57     src = gst_bin_get_by_name (GST_BIN (bin), "fakesrc");
58     if (src) {
59       g_signal_connect (G_OBJECT (src), "handoff",
60           G_CALLBACK (buffer_handoff_src), bin);
61     } else {
62       g_print ("could not find src element\n");
63       exit (-1);
64     }
65
66     sink = gst_bin_get_by_name (GST_BIN (bin), "fakesink");
67     if (sink) {
68       g_signal_connect (G_OBJECT (sink), "handoff",
69           G_CALLBACK (buffer_handoff_sink), bin);
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       g_usleep (G_USEC_PER_SEC);
83     } else {
84       gst_bin_iterate (GST_BIN (bin));
85     }
86
87     if (outcount != 1 && incount != 1) {
88       g_print ("test failed\n");
89       exit (-1);
90     }
91
92     toplevelelements = g_list_next (toplevelelements);
93   }
94
95   exit (0);
96 }