2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wim.taymans@chello.be>
5 * gstaggregator.c: Aggregator element, one in N 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 */
48 GST_PADTEMPLATE_FACTORY (aggregator_src_factory,
55 static void gst_aggregator_class_init (GstAggregatorClass *klass);
56 static void gst_aggregator_init (GstAggregator *aggregator);
58 static GstPad* gst_aggregator_request_new_pad (GstElement *element, GstPadTemplate *temp);
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);
65 static void gst_aggregator_chain (GstPad *pad, GstBuffer *buf);
67 static GstElementClass *parent_class = NULL;
68 //static guint gst_aggregator_signals[LAST_SIGNAL] = { 0 };
71 gst_aggregator_get_type (void)
73 static GType aggregator_type = 0;
75 if (!aggregator_type) {
76 static const GTypeInfo aggregator_info = {
77 sizeof(GstAggregatorClass),
80 (GClassInitFunc)gst_aggregator_class_init,
83 sizeof(GstAggregator),
85 (GInstanceInitFunc)gst_aggregator_init,
87 aggregator_type = g_type_register_static (GST_TYPE_ELEMENT, "GstAggregator", &aggregator_info, 0);
89 return aggregator_type;
93 gst_aggregator_class_init (GstAggregatorClass *klass)
95 GObjectClass *gobject_class;
96 GstElementClass *gstelement_class;
98 gobject_class = (GObjectClass*) klass;
99 gstelement_class = (GstElementClass*) klass;
101 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
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));
110 gobject_class->set_property = gst_aggregator_set_property;
111 gobject_class->get_property = gst_aggregator_get_property;
113 gstelement_class->request_new_pad = gst_aggregator_request_new_pad;
117 gst_aggregator_init (GstAggregator *aggregator)
119 aggregator->srcpad = gst_pad_new ("src", GST_PAD_SINK);
120 gst_element_add_pad (GST_ELEMENT (aggregator), aggregator->srcpad);
122 aggregator->numsinkpads = 0;
123 aggregator->sinkpads = NULL;
124 aggregator->silent = FALSE;
128 gst_aggregator_request_new_pad (GstElement *element, GstPadTemplate *templ)
132 GstAggregator *aggregator;
134 g_return_val_if_fail (GST_IS_AGGREGATOR (element), NULL);
136 if (templ->direction != GST_PAD_SINK) {
137 g_warning ("gstaggregator: request new pad that is not a SRC pad\n");
141 aggregator = GST_AGGREGATOR (element);
143 name = g_strdup_printf ("sink%d",aggregator->numsinkpads);
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);
149 aggregator->sinkpads = g_slist_prepend (aggregator->sinkpads, sinkpad);
150 aggregator->numsinkpads++;
156 gst_aggregator_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
158 GstAggregator *aggregator;
160 /* it's not null if we got it, but it might not be ours */
161 g_return_if_fail (GST_IS_AGGREGATOR (object));
163 aggregator = GST_AGGREGATOR (object);
167 aggregator->silent = g_value_get_boolean (value);
175 gst_aggregator_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
177 GstAggregator *aggregator;
179 /* it's not null if we got it, but it might not be ours */
180 g_return_if_fail (GST_IS_AGGREGATOR (object));
182 aggregator = GST_AGGREGATOR (object);
186 g_value_set_int (value, aggregator->numsinkpads);
189 g_value_set_boolean (value, aggregator->silent);
197 * gst_aggregator_chain:
198 * @pad: the pad to follow
199 * @buf: the buffer to pass
201 * Chain a buffer on a pad.
204 gst_aggregator_chain (GstPad *pad, GstBuffer *buf)
206 GstAggregator *aggregator;
208 g_return_if_fail (pad != NULL);
209 g_return_if_fail (GST_IS_PAD (pad));
210 g_return_if_fail (buf != NULL);
212 aggregator = GST_AGGREGATOR (gst_pad_get_parent (pad));
213 gst_trace_add_entry (NULL, 0, buf, "aggregator buffer");
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));
219 gst_pad_push (aggregator->srcpad, buf);
223 gst_aggregator_factory_init (GstElementFactory *factory)
225 gst_elementfactory_add_padtemplate (factory, GST_PADTEMPLATE_GET (aggregator_src_factory));