Some code cleanups.
[platform/upstream/gstreamer.git] / gst / elements / gstaggregator.c
1 /* GStreamer
2  * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3  *                    2000 Wim Taymans <wim.taymans@chello.be>
4  *
5  * gstaggregator.c: Aggregator element, one in N out
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 "gstaggregator.h"
24
25
26 GstElementDetails gst_aggregator_details = {
27   "Aggregator pipe fitting",
28   "Aggregator",
29   "N-to-1 pipe fitting",
30   VERSION,
31   "Wim Taymans <wim.taymans@chello.be>",
32   "(C) 2001",
33 };
34
35 /* Aggregator signals and args */
36 enum {
37   /* FILL ME */
38   LAST_SIGNAL
39 };
40
41 enum {
42   ARG_0,
43   ARG_NUM_PADS,
44   ARG_SILENT,
45   /* FILL ME */
46 };
47
48 GST_PADTEMPLATE_FACTORY (aggregator_src_factory,
49   "sink%d",
50   GST_PAD_SINK,
51   GST_PAD_REQUEST,
52   NULL                  /* no caps */
53 );
54
55 static void     gst_aggregator_class_init       (GstAggregatorClass *klass);
56 static void     gst_aggregator_init             (GstAggregator *aggregator);
57
58 static GstPad*  gst_aggregator_request_new_pad  (GstElement *element, GstPadTemplate *temp);
59
60 static void     gst_aggregator_set_property     (GObject *object, guint prop_id, 
61                                                  const GValue *value, GParamSpec *pspec);
62 static void     gst_aggregator_get_property     (GObject *object, guint prop_id, 
63                                                  GValue *value, GParamSpec *pspec);
64
65 static void     gst_aggregator_chain            (GstPad *pad, GstBuffer *buf);
66
67 static GstElementClass *parent_class = NULL;
68 //static guint gst_aggregator_signals[LAST_SIGNAL] = { 0 };
69
70 GType
71 gst_aggregator_get_type (void) 
72 {
73   static GType aggregator_type = 0;
74
75   if (!aggregator_type) {
76     static const GTypeInfo aggregator_info = {
77       sizeof(GstAggregatorClass),      
78       NULL,
79       NULL,
80       (GClassInitFunc)gst_aggregator_class_init,
81       NULL,
82       NULL,
83       sizeof(GstAggregator),
84       0,
85       (GInstanceInitFunc)gst_aggregator_init,
86     };
87     aggregator_type = g_type_register_static (GST_TYPE_ELEMENT, "GstAggregator", &aggregator_info, 0);
88   }
89   return aggregator_type;
90 }
91
92 static void
93 gst_aggregator_class_init (GstAggregatorClass *klass) 
94 {
95   GObjectClass *gobject_class;
96   GstElementClass *gstelement_class;
97
98   gobject_class = (GObjectClass*) klass;
99   gstelement_class = (GstElementClass*) klass;
100
101   parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
102
103   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NUM_PADS,
104     g_param_spec_int ("num_pads", "num_pads", "num_pads",
105                       0, G_MAXINT, 0, G_PARAM_READABLE)); 
106   g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SILENT,
107     g_param_spec_boolean ("silent", "silent", "silent",
108                       FALSE, G_PARAM_READWRITE)); 
109
110   gobject_class->set_property = gst_aggregator_set_property;
111   gobject_class->get_property = gst_aggregator_get_property;
112
113   gstelement_class->request_new_pad = gst_aggregator_request_new_pad;
114 }
115
116 static void 
117 gst_aggregator_init (GstAggregator *aggregator) 
118 {
119   aggregator->srcpad = gst_pad_new ("src", GST_PAD_SINK);
120   gst_element_add_pad (GST_ELEMENT (aggregator), aggregator->srcpad);
121
122   aggregator->numsinkpads = 0;
123   aggregator->sinkpads = NULL;
124   aggregator->silent = FALSE;
125 }
126
127 static GstPad*
128 gst_aggregator_request_new_pad (GstElement *element, GstPadTemplate *templ) 
129 {
130   gchar *name;
131   GstPad *sinkpad;
132   GstAggregator *aggregator;
133
134   g_return_val_if_fail (GST_IS_AGGREGATOR (element), NULL);
135
136   if (templ->direction != GST_PAD_SINK) {
137     g_warning ("gstaggregator: request new pad that is not a SRC pad\n");
138     return NULL;
139   }
140
141   aggregator = GST_AGGREGATOR (element);
142
143   name = g_strdup_printf ("sink%d",aggregator->numsinkpads);
144   
145   sinkpad = gst_pad_new_from_template (templ, name);
146   gst_pad_set_chain_function (sinkpad, gst_aggregator_chain);
147   gst_element_add_pad (GST_ELEMENT (aggregator), sinkpad);
148   
149   aggregator->sinkpads = g_slist_prepend (aggregator->sinkpads, sinkpad);
150   aggregator->numsinkpads++;
151   
152   return sinkpad;
153 }
154
155 static void
156 gst_aggregator_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
157 {
158   GstAggregator *aggregator;
159
160   /* it's not null if we got it, but it might not be ours */
161   g_return_if_fail (GST_IS_AGGREGATOR (object));
162
163   aggregator = GST_AGGREGATOR (object);
164
165   switch (prop_id) {
166     case ARG_SILENT:
167       aggregator->silent = g_value_get_boolean (value);
168       break;
169     default:
170       break;
171   }
172 }
173
174 static void
175 gst_aggregator_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
176 {
177   GstAggregator *aggregator;
178
179   /* it's not null if we got it, but it might not be ours */
180   g_return_if_fail (GST_IS_AGGREGATOR (object));
181
182   aggregator = GST_AGGREGATOR (object);
183
184   switch (prop_id) {
185     case ARG_NUM_PADS:
186       g_value_set_int (value, aggregator->numsinkpads);
187       break;
188     case ARG_SILENT:
189       g_value_set_boolean (value, aggregator->silent);
190       break;
191     default:
192       break;
193   }
194 }
195
196 /**
197  * gst_aggregator_chain:
198  * @pad: the pad to follow
199  * @buf: the buffer to pass
200  *
201  * Chain a buffer on a pad.
202  */
203 static void 
204 gst_aggregator_chain (GstPad *pad, GstBuffer *buf) 
205 {
206   GstAggregator *aggregator;
207
208   g_return_if_fail (pad != NULL);
209   g_return_if_fail (GST_IS_PAD (pad));
210   g_return_if_fail (buf != NULL);
211
212   aggregator = GST_AGGREGATOR (gst_pad_get_parent (pad));
213   gst_trace_add_entry (NULL, 0, buf, "aggregator buffer");
214
215   if (!aggregator->silent)
216     g_print("aggregator: chain ******* (%s:%s)a (%d bytes, %llu) \n",
217                GST_DEBUG_PAD_NAME (pad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf));
218
219   gst_pad_push (aggregator->srcpad, buf);
220 }
221
222 gboolean
223 gst_aggregator_factory_init (GstElementFactory *factory)
224 {
225   gst_elementfactory_add_padtemplate (factory, GST_PADTEMPLATE_GET (aggregator_src_factory));
226
227   return TRUE;
228 }
229