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