parts of the patch submitted in bug #113913
[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 "gstinfo.h"
27 #include "gstscheduler.h"
28
29 static GstElementDetails gst_pipeline_details = GST_ELEMENT_DETAILS (
30   "Pipeline object",
31   "Generic/Bin",
32   "Complete pipeline object",
33   "Erik Walthinsen <omega@cse.ogi.edu>"
34 );
35
36 /* Pipeline signals and args */
37 enum {
38   /* FILL ME */
39   LAST_SIGNAL
40 };
41
42 enum {
43   ARG_0
44   /* FILL ME */
45 };
46
47
48 static void                     gst_pipeline_base_init          (gpointer       g_class);
49 static void                     gst_pipeline_class_init         (gpointer       g_class, 
50                                                                  gpointer       class_data);
51 static void                     gst_pipeline_init               (GTypeInstance *instance, 
52                                                                  gpointer       g_class);
53
54 static void                     gst_pipeline_dispose            (GObject *      object);
55
56 static GstElementStateReturn    gst_pipeline_change_state       (GstElement *   element);
57
58 static GstBinClass *parent_class = NULL;
59 /* static guint gst_pipeline_signals[LAST_SIGNAL] = { 0 }; */
60
61 GType
62 gst_pipeline_get_type (void) {
63   static GType pipeline_type = 0;
64
65   if (!pipeline_type) {
66     static const GTypeInfo pipeline_info = {
67       sizeof(GstPipelineClass),
68       gst_pipeline_base_init,
69       NULL,
70       (GClassInitFunc)gst_pipeline_class_init,
71       NULL,
72       NULL,
73       sizeof(GstPipeline),
74       0,
75       gst_pipeline_init,
76       NULL
77     };
78     pipeline_type = g_type_register_static (GST_TYPE_BIN, "GstPipeline", &pipeline_info, 0);
79   }
80   return pipeline_type;
81 }
82
83 static void
84 gst_pipeline_base_init (gpointer g_class)
85 {
86   GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
87   
88   gst_element_class_set_details (gstelement_class, &gst_pipeline_details);
89 }
90
91 static void
92 gst_pipeline_class_init (gpointer g_class, gpointer class_data)
93 {
94   GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
95   GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
96   GstPipelineClass *klass = GST_PIPELINE_CLASS (g_class);
97
98   parent_class = g_type_class_peek_parent (klass);
99
100   gobject_class->dispose                = GST_DEBUG_FUNCPTR (gst_pipeline_dispose);
101
102   gstelement_class->change_state        = GST_DEBUG_FUNCPTR (gst_pipeline_change_state);
103 }
104
105 static void
106 gst_pipeline_init (GTypeInstance *instance, gpointer g_class)
107 {
108   GstScheduler *scheduler;
109   GstPipeline *pipeline = GST_PIPELINE (instance);
110   
111   /* pipelines are managing bins */
112   GST_FLAG_SET (pipeline, GST_BIN_FLAG_MANAGER);
113
114   /* get an instance of the default scheduler */
115   scheduler = gst_scheduler_factory_make (NULL, GST_ELEMENT (pipeline));
116
117   /* FIXME need better error handling */
118   if (scheduler == NULL) {
119     const gchar *name = gst_scheduler_factory_get_default_name ();
120
121     g_error ("Critical error: could not get scheduler \"%s\"\n"
122              "Are you sure you have a registry ?\n"
123              "Run gst-register as root if you haven't done so yet.", name);
124   }
125 }
126
127 static void
128 gst_pipeline_dispose (GObject *object)
129 {
130   GstPipeline *pipeline = GST_PIPELINE (object);
131
132   G_OBJECT_CLASS (parent_class)->dispose (object);
133
134   gst_object_replace ((GstObject **)&GST_ELEMENT_SCHED (pipeline), NULL);
135 }
136
137 /**
138  * gst_pipeline_new:
139  * @name: name of new pipeline
140  *
141  * Create a new pipeline with the given name.
142  *
143  * Returns: newly created GstPipeline
144  */
145 GstElement*
146 gst_pipeline_new (const gchar *name) 
147 {
148   return gst_element_factory_make ("pipeline", name);
149 }
150
151 static GstElementStateReturn
152 gst_pipeline_change_state (GstElement *element)
153 {
154   switch (GST_STATE_TRANSITION (element)) {
155     case GST_STATE_NULL_TO_READY:
156       gst_scheduler_setup (GST_ELEMENT_SCHED (element));
157       break;
158     case GST_STATE_READY_TO_PAUSED:
159     case GST_STATE_PAUSED_TO_PLAYING:
160     case GST_STATE_PLAYING_TO_PAUSED:
161     case GST_STATE_PAUSED_TO_READY:
162       break;
163     case GST_STATE_READY_TO_NULL:
164       /* FIXME: calling gst_scheduler_reset() here is bad, since we
165        * might not be in cothread 0 */
166 #if 0
167       if (GST_ELEMENT_SCHED (element)) {
168         gst_scheduler_reset (GST_ELEMENT_SCHED (element));
169       }
170 #endif
171       break;
172   }
173
174   if (GST_ELEMENT_CLASS (parent_class)->change_state)
175     return GST_ELEMENT_CLASS (parent_class)->change_state (element);
176
177   return GST_STATE_SUCCESS;
178 }
179