22355c714883fbff1294bdaccb71c4efb99ab3c4
[platform/upstream/gstreamer.git] / tests / probes / probetest.c
1 #include <gst/gst.h>
2
3 static GstElement *src1, *src2, *sink, *pipeline, *bin;
4 static gint state = 0;
5
6 static gboolean
7 notify (GstProbe * probe, GstData ** data, gpointer user_data)
8 {
9   switch (state) {
10     case 0:
11       if (GST_BUFFER_TIMESTAMP (*data) == 10) {
12         gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PAUSED);
13
14         gst_element_unlink_pads (GST_ELEMENT (src1), "src", sink, "sink");
15         gst_bin_add (GST_BIN (bin), src2);
16         gst_bin_remove (GST_BIN (bin), src1);
17         gst_element_link_pads (GST_ELEMENT (src2), "src", sink, "sink");
18         gst_element_set_state (GST_ELEMENT (bin), GST_STATE_PLAYING);
19         state++;
20         gst_data_unref (*data);
21         return FALSE;
22       }
23       break;
24     case 1:
25       GST_BUFFER_TIMESTAMP (*data) = GST_BUFFER_TIMESTAMP (*data) + 10;
26       if (GST_BUFFER_TIMESTAMP (*data) == 20) {
27         gst_data_unref (*data);
28         *data = GST_DATA (gst_event_new (GST_EVENT_EOS));
29         gst_element_set_state (src2, GST_STATE_PAUSED);
30         return TRUE;
31       }
32       break;
33     default:
34       break;
35   }
36
37   return TRUE;
38 }
39
40 int
41 main (int argc, gchar * argv[])
42 {
43   gst_init (&argc, &argv);
44
45   pipeline = gst_pipeline_new ("main_pipeline");
46   bin = gst_bin_new ("control");
47
48   src1 = gst_element_factory_make ("fakesrc", "src1");
49   src2 = gst_element_factory_make ("fakesrc", "src2");
50
51   gst_bin_add (GST_BIN (bin), src1);
52
53   sink = gst_element_factory_make ("fakesink", "sink");
54   gst_bin_add (GST_BIN (pipeline), sink);
55   gst_bin_add (GST_BIN (pipeline), bin);
56
57   gst_element_link_pads (GST_ELEMENT (src1), "src", sink, "sink");
58
59   g_signal_connect (pipeline, "deep_notify",
60       G_CALLBACK (gst_element_default_deep_notify), NULL);
61   g_signal_connect (pipeline, "error", G_CALLBACK (gst_element_default_error),
62       NULL);
63
64   gst_pad_add_probe (gst_element_get_pad (src1, "src"),
65       gst_probe_new (FALSE, notify, NULL));
66
67   gst_pad_add_probe (gst_element_get_pad (src2, "src"),
68       gst_probe_new (FALSE, notify, NULL));
69
70   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
71
72   while (gst_bin_iterate (GST_BIN (pipeline)));
73
74   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
75
76   gst_object_unref (GST_OBJECT (pipeline));
77
78   return 0;
79 }