Various cleanups and leak fixage.
[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 "gstscheduler.h"
27
28 GstElementDetails gst_pipeline_details = {
29   "Pipeline object",
30   "Bin",
31   "Complete pipeline object",
32   VERSION,
33   "Erik Walthinsen <omega@cse.ogi.edu>",
34   "(C) 1999",
35 };
36
37 /* Pipeline signals and args */
38 enum {
39   /* FILL ME */
40   LAST_SIGNAL
41 };
42
43 enum {
44   ARG_0,
45   /* FILL ME */
46 };
47
48
49 static void                     gst_pipeline_class_init         (GstPipelineClass *klass);
50 static void                     gst_pipeline_init               (GstPipeline *pipeline);
51
52 static void                     gst_pipeline_dispose            (GObject *object);
53
54 static GstElementStateReturn    gst_pipeline_change_state       (GstElement *element);
55
56 static GstBinClass *parent_class = NULL;
57 /* static guint gst_pipeline_signals[LAST_SIGNAL] = { 0 }; */
58
59 GType
60 gst_pipeline_get_type (void) {
61   static GType pipeline_type = 0;
62
63   if (!pipeline_type) {
64     static const GTypeInfo pipeline_info = {
65       sizeof(GstPipelineClass),
66       NULL,
67       NULL,
68       (GClassInitFunc)gst_pipeline_class_init,
69       NULL,
70       NULL,
71       sizeof(GstPipeline),
72       0,
73       (GInstanceInitFunc)gst_pipeline_init,
74       NULL
75     };
76     pipeline_type = g_type_register_static (GST_TYPE_BIN, "GstPipeline", &pipeline_info, 0);
77   }
78   return pipeline_type;
79 }
80
81 static void
82 gst_pipeline_class_init (GstPipelineClass *klass)
83 {
84   GObjectClass *gobject_class;
85   GstElementClass *gstelement_class;
86
87   gobject_class = (GObjectClass *)klass;
88   gstelement_class = (GstElementClass*)klass;
89
90   parent_class = g_type_class_ref (gst_bin_get_type ());
91
92   gobject_class->dispose                = GST_DEBUG_FUNCPTR (gst_pipeline_dispose);
93
94   gstelement_class->change_state        = GST_DEBUG_FUNCPTR (gst_pipeline_change_state);
95 }
96
97 static void
98 gst_pipeline_init (GstPipeline *pipeline)
99 {
100   /* we're a manager by default */
101   GST_FLAG_SET (pipeline, GST_BIN_FLAG_MANAGER);
102
103   GST_ELEMENT_SCHED (pipeline) = gst_schedulerfactory_make ("basic", GST_ELEMENT (pipeline));
104
105   gst_object_ref (GST_OBJECT (GST_ELEMENT_SCHED (pipeline)));
106   gst_object_sink (GST_OBJECT (GST_ELEMENT_SCHED (pipeline)));
107
108   GST_DEBUG (GST_CAT_PIPELINE, "pipeline's scheduler is %p\n", GST_ELEMENT_SCHED (pipeline));
109 }
110
111 static void
112 gst_pipeline_dispose (GObject *object)
113 {
114   GstPipeline *pipeline = GST_PIPELINE (object);
115
116   G_OBJECT_CLASS (parent_class)->dispose (object);
117
118   gst_object_unref (GST_OBJECT (GST_ELEMENT_SCHED (pipeline)));
119 }
120
121 /**
122  * gst_pipeline_new:
123  * @name: name of new pipeline
124  *
125  * Create a new pipeline with the given name.
126  *
127  * Returns: newly created GstPipeline
128  */
129 GstElement*
130 gst_pipeline_new (const gchar *name) 
131 {
132   return gst_elementfactory_make ("pipeline", name);
133 }
134
135 static GstElementStateReturn
136 gst_pipeline_change_state (GstElement *element)
137 {
138   if (GST_ELEMENT_CLASS (parent_class)->change_state)
139     return GST_ELEMENT_CLASS (parent_class)->change_state (element);
140
141   return GST_STATE_SUCCESS;
142 }
143