Added gst-plugins-base-subtitles0.10-0.10.34 for Meego Harmattan 1.2
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / tests / old / examples / seek / chained.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4 #include <stdlib.h>
5 #include <gst/gst.h>
6 #include <string.h>
7
8 static GstElement *bin;
9
10 static void
11 unlinked (GstPad * pad, GstPad * peerpad, GstElement * pipeline)
12 {
13   gst_element_set_state (pipeline, GST_STATE_PAUSED);
14   gst_bin_remove (GST_BIN (pipeline), bin);
15   gst_element_set_state (bin, GST_STATE_READY);
16   gst_element_set_state (pipeline, GST_STATE_PLAYING);
17 }
18
19 static void
20 new_pad (GstElement * elem, GstPad * newpad, GstElement * pipeline)
21 {
22   GstScheduler *sched;
23   GstClock *clock;
24
25   g_print ("new pad %s\n", gst_pad_get_name (newpad));
26
27   gst_element_set_state (pipeline, GST_STATE_PAUSED);
28   gst_bin_add (GST_BIN (pipeline), bin);
29
30   sched = gst_element_get_scheduler (GST_ELEMENT (pipeline));
31   clock = gst_scheduler_get_clock (sched);
32   gst_scheduler_set_clock (sched, clock);
33
34   gst_pad_link (newpad, gst_element_get_pad (bin, "sink"));
35
36   g_signal_connect (G_OBJECT (newpad), "unlinked", G_CALLBACK (unlinked),
37       pipeline);
38
39   gst_element_set_state (pipeline, GST_STATE_PLAYING);
40 }
41
42 int
43 main (int argc, char **argv)
44 {
45   GstElement *pipeline;
46   GstElement *filesrc;
47   GstElement *oggdemux;
48   GstElement *vorbisdec;
49   GstElement *audioconvert;
50   GstElement *audiosink;
51
52   gst_init (&argc, &argv);
53
54   if (argc < 2) {
55     g_print ("usage: %s <oggfile>\n", argv[0]);
56     return (-1);
57   }
58
59   pipeline = gst_pipeline_new ("pipeline");
60
61   filesrc = gst_element_factory_make ("filesrc", "filesrc");
62   g_assert (filesrc);
63   g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
64
65   oggdemux = gst_element_factory_make ("oggdemux", "oggdemux");
66   g_assert (oggdemux);
67
68   gst_bin_add (GST_BIN (pipeline), filesrc);
69   gst_bin_add (GST_BIN (pipeline), oggdemux);
70
71   gst_element_link_pads (filesrc, "src", oggdemux, "sink");
72
73   g_signal_connect (G_OBJECT (oggdemux), "new_pad", G_CALLBACK (new_pad),
74       pipeline);
75
76   bin = gst_bin_new ("bin");
77   vorbisdec = gst_element_factory_make ("vorbisdec", "vorbisdec");
78   g_assert (vorbisdec);
79   audioconvert = gst_element_factory_make ("audioconvert", "audioconvert");
80   g_assert (audioconvert);
81   audiosink = gst_element_factory_make (DEFAULT_AUDIOSINK, DEFAULT_AUDIOSINK);
82   g_assert (audiosink);
83   gst_bin_add (GST_BIN (bin), vorbisdec);
84   gst_bin_add (GST_BIN (bin), audioconvert);
85   gst_bin_add (GST_BIN (bin), audiosink);
86
87   gst_element_link_pads (vorbisdec, "src", audioconvert, "sink");
88   gst_element_link_pads (audioconvert, "src", audiosink, "sink");
89
90   gst_element_add_ghost_pad (bin, gst_element_get_pad (vorbisdec, "sink"),
91       "sink");
92
93   g_object_ref (G_OBJECT (bin));
94
95   g_signal_connect (pipeline, "deep_notify",
96       G_CALLBACK (gst_element_default_deep_notify), NULL);
97
98   gst_element_set_state (pipeline, GST_STATE_PLAYING);
99
100   while (gst_bin_iterate (GST_BIN (pipeline)))
101     /* nop */ ;
102
103   /* stop probe */
104   gst_element_set_state (pipeline, GST_STATE_NULL);
105
106   return 0;
107 }