2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wim.taymans@chello.be>
5 * gstaggregator.c: Aggregator element, N in 1 out
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.
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.
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.
23 #include "gstaggregator.h"
26 GstElementDetails gst_aggregator_details = {
27 "Aggregator pipe fitting",
30 "N-to-1 pipe fitting",
32 "Wim Taymans <wim.taymans@chello.be>",
36 /* Aggregator signals and args */
51 GST_PAD_TEMPLATE_FACTORY (aggregator_src_factory,
58 #define GST_TYPE_AGGREGATOR_SCHED (gst_aggregator_sched_get_type())
60 gst_aggregator_sched_get_type (void)
62 static GType aggregator_sched_type = 0;
63 static GEnumValue aggregator_sched[] = {
64 { AGGREGATOR_LOOP, "1", "Loop Based"},
65 { AGGREGATOR_LOOP_SELECT, "3", "Loop Based Select"},
66 { AGGREGATOR_CHAIN, "4", "Chain Based"},
69 if (!aggregator_sched_type) {
70 aggregator_sched_type = g_enum_register_static ("GstAggregatorSched", aggregator_sched);
72 return aggregator_sched_type;
75 #define AGGREGATOR_IS_LOOP_BASED(ag) ((ag)->sched != AGGREGATOR_CHAIN)
77 static void gst_aggregator_class_init (GstAggregatorClass *klass);
78 static void gst_aggregator_init (GstAggregator *aggregator);
80 static GstPad* gst_aggregator_request_new_pad (GstElement *element, GstPadTemplate *temp, const
83 static void gst_aggregator_set_property (GObject *object, guint prop_id,
84 const GValue *value, GParamSpec *pspec);
85 static void gst_aggregator_get_property (GObject *object, guint prop_id,
86 GValue *value, GParamSpec *pspec);
88 static void gst_aggregator_chain (GstPad *pad, GstBuffer *buf);
89 static void gst_aggregator_loop (GstElement *element);
91 static GstElementClass *parent_class = NULL;
92 /*static guint gst_aggregator_signals[LAST_SIGNAL] = { 0 };*/
95 gst_aggregator_get_type (void)
97 static GType aggregator_type = 0;
99 if (!aggregator_type) {
100 static const GTypeInfo aggregator_info = {
101 sizeof(GstAggregatorClass),
104 (GClassInitFunc)gst_aggregator_class_init,
107 sizeof(GstAggregator),
109 (GInstanceInitFunc)gst_aggregator_init,
111 aggregator_type = g_type_register_static (GST_TYPE_ELEMENT, "GstAggregator", &aggregator_info, 0);
113 return aggregator_type;
117 gst_aggregator_class_init (GstAggregatorClass *klass)
119 GObjectClass *gobject_class;
120 GstElementClass *gstelement_class;
122 gobject_class = (GObjectClass*) klass;
123 gstelement_class = (GstElementClass*) klass;
125 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
127 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NUM_PADS,
128 g_param_spec_int ("num_pads", "Num pads", "The number of source pads",
129 0, G_MAXINT, 0, G_PARAM_READABLE));
130 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SILENT,
131 g_param_spec_boolean ("silent", "Silent", "Don't produce messages",
132 FALSE, G_PARAM_READWRITE));
133 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SCHED,
134 g_param_spec_enum ("sched", "Scheduling", "The type of scheduling this element should use",
135 GST_TYPE_AGGREGATOR_SCHED, AGGREGATOR_CHAIN, G_PARAM_READWRITE));
136 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LAST_MESSAGE,
137 g_param_spec_string ("last_message", "Last message", "The current state of the element",
138 NULL, G_PARAM_READABLE));
140 gobject_class->set_property = GST_DEBUG_FUNCPTR(gst_aggregator_set_property);
141 gobject_class->get_property = GST_DEBUG_FUNCPTR(gst_aggregator_get_property);
143 gstelement_class->request_new_pad = GST_DEBUG_FUNCPTR(gst_aggregator_request_new_pad);
147 gst_aggregator_init (GstAggregator *aggregator)
149 aggregator->srcpad = gst_pad_new ("src", GST_PAD_SRC);
150 gst_element_add_pad (GST_ELEMENT (aggregator), aggregator->srcpad);
152 aggregator->numsinkpads = 0;
153 aggregator->sinkpads = NULL;
154 aggregator->silent = FALSE;
155 aggregator->sched = AGGREGATOR_LOOP;
159 gst_aggregator_request_new_pad (GstElement *element, GstPadTemplate *templ, const gchar *unused)
163 GstAggregator *aggregator;
165 g_return_val_if_fail (GST_IS_AGGREGATOR (element), NULL);
167 if (templ->direction != GST_PAD_SINK) {
168 g_warning ("gstaggregator: request new pad that is not a SRC pad\n");
172 aggregator = GST_AGGREGATOR (element);
174 name = g_strdup_printf ("sink%d",aggregator->numsinkpads);
176 sinkpad = gst_pad_new_from_template (templ, name);
179 gst_pad_set_chain_function (sinkpad, gst_aggregator_chain);
180 gst_element_add_pad (GST_ELEMENT (aggregator), sinkpad);
182 aggregator->sinkpads = g_list_prepend (aggregator->sinkpads, sinkpad);
183 aggregator->numsinkpads++;
189 gst_aggregator_update_functions (GstAggregator *aggregator)
193 if (AGGREGATOR_IS_LOOP_BASED (aggregator)) {
194 gst_element_set_loop_function (GST_ELEMENT (aggregator), GST_DEBUG_FUNCPTR (gst_aggregator_loop));
197 gst_element_set_loop_function (GST_ELEMENT (aggregator), NULL);
200 pads = aggregator->sinkpads;
202 GstPad *pad = GST_PAD (pads->data);
204 if (AGGREGATOR_IS_LOOP_BASED (aggregator)) {
205 gst_pad_set_get_function (pad, NULL);
208 gst_element_set_loop_function (GST_ELEMENT (aggregator), NULL);
210 pads = g_list_next (pads);
215 gst_aggregator_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
217 GstAggregator *aggregator;
219 /* it's not null if we got it, but it might not be ours */
220 g_return_if_fail (GST_IS_AGGREGATOR (object));
222 aggregator = GST_AGGREGATOR (object);
226 aggregator->silent = g_value_get_boolean (value);
229 aggregator->sched = g_value_get_enum (value);
230 gst_aggregator_update_functions (aggregator);
238 gst_aggregator_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
240 GstAggregator *aggregator;
242 /* it's not null if we got it, but it might not be ours */
243 g_return_if_fail (GST_IS_AGGREGATOR (object));
245 aggregator = GST_AGGREGATOR (object);
249 g_value_set_int (value, aggregator->numsinkpads);
252 g_value_set_boolean (value, aggregator->silent);
255 g_value_set_enum (value, aggregator->sched);
257 case ARG_LAST_MESSAGE:
258 g_value_set_string (value, aggregator->last_message);
266 gst_aggregator_push (GstAggregator *aggregator, GstPad *pad, GstBuffer *buf, guchar *debug)
268 if (!aggregator->silent) {
269 g_free (aggregator->last_message);
271 aggregator->last_message = g_strdup_printf ("%10.10s ******* (%s:%s)a (%d bytes, %"
272 G_GUINT64_FORMAT ")",
273 debug, GST_DEBUG_PAD_NAME (pad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf));
275 g_object_notify (G_OBJECT (aggregator), "last_message");
278 gst_pad_push (aggregator->srcpad, buf);
282 gst_aggregator_loop (GstElement *element)
284 GstAggregator *aggregator;
288 aggregator = GST_AGGREGATOR (element);
290 if (aggregator->sched == AGGREGATOR_LOOP) {
291 GList *pads = aggregator->sinkpads;
294 GstPad *pad = GST_PAD (pads->data);
295 pads = g_list_next (pads);
297 buf = gst_pad_pull (pad);
300 gst_aggregator_push (aggregator, pad, buf, debug);
304 if (aggregator->sched == AGGREGATOR_LOOP_SELECT) {
307 debug = "loop_select";
309 pad = gst_pad_select (aggregator->sinkpads);
310 buf = gst_pad_pull (pad);
312 gst_aggregator_push (aggregator, pad, buf, debug);
315 g_assert_not_reached ();
321 * gst_aggregator_chain:
322 * @pad: the pad to follow
323 * @buf: the buffer to pass
325 * Chain a buffer on a pad.
328 gst_aggregator_chain (GstPad *pad, GstBuffer *buf)
330 GstAggregator *aggregator;
332 g_return_if_fail (pad != NULL);
333 g_return_if_fail (GST_IS_PAD (pad));
334 g_return_if_fail (buf != NULL);
336 aggregator = GST_AGGREGATOR (gst_pad_get_parent (pad));
337 /* gst_trace_add_entry (NULL, 0, buf, "aggregator buffer");*/
339 gst_aggregator_push (aggregator, pad, buf, "chain");
343 gst_aggregator_factory_init (GstElementFactory *factory)
345 gst_element_factory_add_pad_template (factory, GST_PAD_TEMPLATE_GET (aggregator_src_factory));