Add new --enable-fast-stack-trash option, defaults to on.
[platform/upstream/gstreamer.git] / gst / gstpipeline.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wtay@chello.be>
4  *
5  * gstpipeline.c: Overall pipeline management element
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public
18  * License along with this library; if not, write to the
19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include "gst_private.h"
24
25 #include "gstpipeline.h"
26 #include "gstlog.h"
27 #include "gstscheduler.h"
28
29 GstElementDetails gst_pipeline_details = {
30   "Pipeline object",
31   "Generic/Bin",
32   "Complete pipeline object",
33   VERSION,
34   "Erik Walthinsen <omega@cse.ogi.edu>",
35   "(C) 1999",
36 };
37
38 /* Pipeline signals and args */
39 enum {
40   /* FILL ME */
41   LAST_SIGNAL
42 };
43
44 enum {
45   ARG_0,
46   /* FILL ME */
47 };
48
49
50 static void                     gst_pipeline_class_init         (GstPipelineClass *klass);
51 static void                     gst_pipeline_init               (GstPipeline *pipeline);
52
53 static void                     gst_pipeline_dispose            (GObject *object);
54
55 static GstElementStateReturn    gst_pipeline_change_state       (GstElement *element);
56
57 static GstBinClass *parent_class = NULL;
58 /* static guint gst_pipeline_signals[LAST_SIGNAL] = { 0 }; */
59
60 GType
61 gst_pipeline_get_type (void) {
62   static GType pipeline_type = 0;
63
64   if (!pipeline_type) {
65     static const GTypeInfo pipeline_info = {
66       sizeof(GstPipelineClass),
67       NULL,
68       NULL,
69       (GClassInitFunc)gst_pipeline_class_init,
70       NULL,
71       NULL,
72       sizeof(GstPipeline),
73       0,
74       (GInstanceInitFunc)gst_pipeline_init,
75       NULL
76     };
77     pipeline_type = g_type_register_static (GST_TYPE_BIN, "GstPipeline", &pipeline_info, 0);
78   }
79   return pipeline_type;
80 }
81
82 static void
83 gst_pipeline_class_init (GstPipelineClass *klass)
84 {
85   GObjectClass *gobject_class;
86   GstElementClass *gstelement_class;
87
88   gobject_class = (GObjectClass *)klass;
89   gstelement_class = (GstElementClass*)klass;
90
91   parent_class = g_type_class_ref (gst_bin_get_type ());
92
93   gobject_class->dispose                = GST_DEBUG_FUNCPTR (gst_pipeline_dispose);
94
95   gstelement_class->change_state        = GST_DEBUG_FUNCPTR (gst_pipeline_change_state);
96 }
97
98 static void
99 gst_pipeline_init (GstPipeline *pipeline)
100 {
101   GstScheduler *scheduler;
102
103   /* pipelines are managing bins */
104   GST_FLAG_SET (pipeline, GST_BIN_FLAG_MANAGER);
105
106   /* get an instance of the default scheduler */
107   scheduler = gst_scheduler_factory_make (NULL, GST_ELEMENT (pipeline));
108
109   /* FIXME need better error handling */
110   if (scheduler == NULL) {
111     const gchar *name = gst_scheduler_factory_get_default_name ();
112
113     g_error ("Critical error: could not get scheduler \"%s\"\n"
114              "Are you sure you have a registry ?\n"
115              "Run gst-register as root if you haven't done so yet.", name);
116   }
117 }
118
119 static void
120 gst_pipeline_dispose (GObject *object)
121 {
122   GstPipeline *pipeline = GST_PIPELINE (object);
123
124   G_OBJECT_CLASS (parent_class)->dispose (object);
125
126   gst_object_replace ((GstObject **)&GST_ELEMENT_SCHED (pipeline), NULL);
127 }
128
129 /**
130  * gst_pipeline_new:
131  * @name: name of new pipeline
132  *
133  * Create a new pipeline with the given name.
134  *
135  * Returns: newly created GstPipeline
136  */
137 GstElement*
138 gst_pipeline_new (const gchar *name) 
139 {
140   return gst_element_factory_make ("pipeline", name);
141 }
142
143 static GstElementStateReturn
144 gst_pipeline_change_state (GstElement *element)
145 {
146   switch (GST_STATE_TRANSITION (element)) {
147     case GST_STATE_NULL_TO_READY:
148       gst_scheduler_setup (GST_ELEMENT_SCHED (element));
149       break;
150     case GST_STATE_READY_TO_PAUSED:
151     case GST_STATE_PAUSED_TO_PLAYING:
152     case GST_STATE_PLAYING_TO_PAUSED:
153     case GST_STATE_PAUSED_TO_READY:
154       break;
155     case GST_STATE_READY_TO_NULL:
156       /* FIXME: calling gst_scheduler_reset() here is bad, since we
157        * might not be in cothread 0 */
158 #if 0
159       if (GST_ELEMENT_SCHED (element)) {
160         gst_scheduler_reset (GST_ELEMENT_SCHED (element));
161       }
162 #endif
163       break;
164   }
165
166   if (GST_ELEMENT_CLASS (parent_class)->change_state)
167     return GST_ELEMENT_CLASS (parent_class)->change_state (element);
168
169   return GST_STATE_SUCCESS;
170 }
171