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",
29 "N-to-1 pipe fitting",
31 "Wim Taymans <wim.taymans@chello.be>",
35 /* Aggregator signals and args */
49 GST_PADTEMPLATE_FACTORY (aggregator_src_factory,
56 #define GST_TYPE_AGGREGATOR_SCHED (gst_aggregator_sched_get_type())
58 gst_aggregator_sched_get_type (void)
60 static GType aggregator_sched_type = 0;
61 static GEnumValue aggregator_sched[] = {
62 { AGGREGATOR_LOOP, "1", "Loop Based"},
63 { AGGREGATOR_LOOP_PEEK, "2", "Loop Based Peek"},
64 { AGGREGATOR_LOOP_SELECT, "3", "Loop Based Select"},
65 { AGGREGATOR_CHAIN, "4", "Chain Based"},
68 if (!aggregator_sched_type) {
69 aggregator_sched_type = g_enum_register_static ("GstAggregatorSched", aggregator_sched);
71 return aggregator_sched_type;
74 #define AGGREGATOR_IS_LOOP_BASED(ag) ((ag)->sched != AGGREGATOR_CHAIN)
76 static void gst_aggregator_class_init (GstAggregatorClass *klass);
77 static void gst_aggregator_init (GstAggregator *aggregator);
79 static GstPad* gst_aggregator_request_new_pad (GstElement *element, GstPadTemplate *temp, const
82 static void gst_aggregator_set_property (GObject *object, guint prop_id,
83 const GValue *value, GParamSpec *pspec);
84 static void gst_aggregator_get_property (GObject *object, guint prop_id,
85 GValue *value, GParamSpec *pspec);
87 static void gst_aggregator_chain (GstPad *pad, GstBuffer *buf);
88 static void gst_aggregator_loop (GstElement *element);
90 static GstElementClass *parent_class = NULL;
91 //static guint gst_aggregator_signals[LAST_SIGNAL] = { 0 };
94 gst_aggregator_get_type (void)
96 static GType aggregator_type = 0;
98 if (!aggregator_type) {
99 static const GTypeInfo aggregator_info = {
100 sizeof(GstAggregatorClass),
103 (GClassInitFunc)gst_aggregator_class_init,
106 sizeof(GstAggregator),
108 (GInstanceInitFunc)gst_aggregator_init,
110 aggregator_type = g_type_register_static (GST_TYPE_ELEMENT, "GstAggregator", &aggregator_info, 0);
112 return aggregator_type;
116 gst_aggregator_class_init (GstAggregatorClass *klass)
118 GObjectClass *gobject_class;
119 GstElementClass *gstelement_class;
121 gobject_class = (GObjectClass*) klass;
122 gstelement_class = (GstElementClass*) klass;
124 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
126 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NUM_PADS,
127 g_param_spec_int ("num_pads", "num_pads", "num_pads",
128 0, G_MAXINT, 0, G_PARAM_READABLE));
129 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SILENT,
130 g_param_spec_boolean ("silent", "silent", "silent",
131 FALSE, G_PARAM_READWRITE));
132 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SCHED,
133 g_param_spec_enum ("sched", "sched", "sched",
134 GST_TYPE_AGGREGATOR_SCHED, AGGREGATOR_CHAIN, G_PARAM_READWRITE));
136 gobject_class->set_property = GST_DEBUG_FUNCPTR(gst_aggregator_set_property);
137 gobject_class->get_property = GST_DEBUG_FUNCPTR(gst_aggregator_get_property);
139 gstelement_class->request_new_pad = GST_DEBUG_FUNCPTR(gst_aggregator_request_new_pad);
143 gst_aggregator_init (GstAggregator *aggregator)
145 aggregator->srcpad = gst_pad_new ("src", GST_PAD_SRC);
146 gst_element_add_pad (GST_ELEMENT (aggregator), aggregator->srcpad);
148 aggregator->numsinkpads = 0;
149 aggregator->sinkpads = NULL;
150 aggregator->silent = FALSE;
151 aggregator->sched = AGGREGATOR_LOOP;
155 gst_aggregator_request_new_pad (GstElement *element, GstPadTemplate *templ, const gchar *unused)
159 GstAggregator *aggregator;
161 g_return_val_if_fail (GST_IS_AGGREGATOR (element), NULL);
163 if (templ->direction != GST_PAD_SINK) {
164 g_warning ("gstaggregator: request new pad that is not a SRC pad\n");
168 aggregator = GST_AGGREGATOR (element);
170 name = g_strdup_printf ("sink%d",aggregator->numsinkpads);
172 sinkpad = gst_pad_new_from_template (templ, name);
173 gst_pad_set_chain_function (sinkpad, gst_aggregator_chain);
174 gst_element_add_pad (GST_ELEMENT (aggregator), sinkpad);
176 aggregator->sinkpads = g_list_prepend (aggregator->sinkpads, sinkpad);
177 aggregator->numsinkpads++;
183 gst_aggregator_update_functions (GstAggregator *aggregator)
187 if (AGGREGATOR_IS_LOOP_BASED (aggregator)) {
188 gst_element_set_loop_function (GST_ELEMENT (aggregator), GST_DEBUG_FUNCPTR (gst_aggregator_loop));
191 gst_element_set_loop_function (GST_ELEMENT (aggregator), NULL);
194 pads = aggregator->sinkpads;
196 GstPad *pad = GST_PAD (pads->data);
198 if (AGGREGATOR_IS_LOOP_BASED (aggregator)) {
199 gst_pad_set_get_function (pad, NULL);
202 gst_element_set_loop_function (GST_ELEMENT (aggregator), NULL);
204 pads = g_list_next (pads);
209 gst_aggregator_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
211 GstAggregator *aggregator;
213 /* it's not null if we got it, but it might not be ours */
214 g_return_if_fail (GST_IS_AGGREGATOR (object));
216 aggregator = GST_AGGREGATOR (object);
220 aggregator->silent = g_value_get_boolean (value);
223 aggregator->sched = g_value_get_enum (value);
224 gst_aggregator_update_functions (aggregator);
232 gst_aggregator_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
234 GstAggregator *aggregator;
236 /* it's not null if we got it, but it might not be ours */
237 g_return_if_fail (GST_IS_AGGREGATOR (object));
239 aggregator = GST_AGGREGATOR (object);
243 g_value_set_int (value, aggregator->numsinkpads);
246 g_value_set_boolean (value, aggregator->silent);
249 g_value_set_enum (value, aggregator->sched);
257 gst_aggregator_push (GstAggregator *aggregator, GstPad *pad, GstBuffer *buf, guchar *debug)
259 if (!aggregator->silent)
260 g_print("aggregator: %10.10s ******* (%s:%s)a (%d bytes, %llu) \n",
261 debug, GST_DEBUG_PAD_NAME (pad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf));
263 gst_pad_push (aggregator->srcpad, buf);
267 gst_aggregator_loop (GstElement *element)
269 GstAggregator *aggregator;
273 aggregator = GST_AGGREGATOR (element);
276 if (aggregator->sched == AGGREGATOR_LOOP ||
277 aggregator->sched == AGGREGATOR_LOOP_PEEK) {
278 GList *pads = aggregator->sinkpads;
281 GstPad *pad = GST_PAD (pads->data);
282 pads = g_list_next (pads);
284 if (aggregator->sched == AGGREGATOR_LOOP_PEEK) {
285 buf = gst_pad_peek (pad);
289 g_assert (buf == gst_pad_pull (pad));
293 buf = gst_pad_pull (pad);
296 gst_aggregator_push (aggregator, pad, buf, debug);
300 if (aggregator->sched == AGGREGATOR_LOOP_SELECT) {
303 debug = "loop_select";
305 pad = gst_pad_select (aggregator->sinkpads);
306 buf = gst_pad_pull (pad);
308 gst_aggregator_push (aggregator, pad, buf, debug);
311 g_assert_not_reached ();
314 } while (!GST_ELEMENT_IS_COTHREAD_STOPPING (element));
318 * gst_aggregator_chain:
319 * @pad: the pad to follow
320 * @buf: the buffer to pass
322 * Chain a buffer on a pad.
325 gst_aggregator_chain (GstPad *pad, GstBuffer *buf)
327 GstAggregator *aggregator;
329 g_return_if_fail (pad != NULL);
330 g_return_if_fail (GST_IS_PAD (pad));
331 g_return_if_fail (buf != NULL);
333 aggregator = GST_AGGREGATOR (gst_pad_get_parent (pad));
334 // gst_trace_add_entry (NULL, 0, buf, "aggregator buffer");
336 gst_aggregator_push (aggregator, pad, buf, "chain");
340 gst_aggregator_factory_init (GstElementFactory *factory)
342 gst_elementfactory_add_padtemplate (factory, GST_PADTEMPLATE_GET (aggregator_src_factory));