2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2000 Wim Taymans <wim.taymans@chello.be>
5 * gsttee.c: Tee 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.
26 GstElementDetails gst_tee_details = {
29 "1-to-N pipe fitting",
31 "Erik Walthinsen <omega@cse.ogi.edu>\n"
32 "Wim Taymans <wim.taymans@chello.be>",
36 /* Tee signals and args */
49 GST_PADTEMPLATE_FACTORY (tee_src_factory,
56 static void gst_tee_class_init (GstTeeClass *klass);
57 static void gst_tee_init (GstTee *tee);
59 static GstPad* gst_tee_request_new_pad (GstElement *element, GstPadTemplate *temp, const gchar *unused);
61 static void gst_tee_set_property (GObject *object, guint prop_id,
62 const GValue *value, GParamSpec *pspec);
63 static void gst_tee_get_property (GObject *object, guint prop_id,
64 GValue *value, GParamSpec *pspec);
66 static void gst_tee_chain (GstPad *pad, GstBuffer *buf);
68 static GstElementClass *parent_class = NULL;
69 //static guint gst_tee_signals[LAST_SIGNAL] = { 0 };
72 gst_tee_get_type(void) {
73 static GType tee_type = 0;
76 static const GTypeInfo tee_info = {
77 sizeof(GstTeeClass), NULL,
79 (GClassInitFunc)gst_tee_class_init,
84 (GInstanceInitFunc)gst_tee_init,
86 tee_type = g_type_register_static (GST_TYPE_ELEMENT, "GstTee", &tee_info, 0);
92 gst_tee_class_init (GstTeeClass *klass)
94 GObjectClass *gobject_class;
95 GstElementClass *gstelement_class;
97 gobject_class = (GObjectClass*)klass;
98 gstelement_class = (GstElementClass*)klass;
100 parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
102 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NUM_PADS,
103 g_param_spec_int ("num_pads", "num_pads", "num_pads",
104 0, G_MAXINT, 0, G_PARAM_READABLE));
105 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SILENT,
106 g_param_spec_boolean ("silent", "silent", "silent",
107 FALSE, G_PARAM_READWRITE));
111 gobject_class->set_property = GST_DEBUG_FUNCPTR(gst_tee_set_property);
112 gobject_class->get_property = GST_DEBUG_FUNCPTR(gst_tee_get_property);
114 gstelement_class->request_new_pad = GST_DEBUG_FUNCPTR(gst_tee_request_new_pad);
118 gst_tee_init (GstTee *tee)
120 tee->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
121 gst_element_add_pad (GST_ELEMENT (tee), tee->sinkpad);
122 gst_pad_set_chain_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_tee_chain));
130 gst_tee_request_new_pad (GstElement *element, GstPadTemplate *templ, const gchar *unused)
136 g_return_val_if_fail (GST_IS_TEE (element), NULL);
138 if (templ->direction != GST_PAD_SRC) {
139 g_warning ("gsttee: request new pad that is not a SRC pad\n");
143 tee = GST_TEE (element);
145 name = g_strdup_printf ("src%d",tee->numsrcpads);
147 srcpad = gst_pad_new_from_template (templ, name);
148 gst_element_add_pad (GST_ELEMENT (tee), srcpad);
150 tee->srcpads = g_slist_prepend (tee->srcpads, srcpad);
157 gst_tee_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
161 /* it's not null if we got it, but it might not be ours */
162 g_return_if_fail (GST_IS_TEE (object));
164 tee = GST_TEE (object);
168 tee->silent = g_value_get_boolean (value);
176 gst_tee_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
180 /* it's not null if we got it, but it might not be ours */
181 g_return_if_fail (GST_IS_TEE (object));
183 tee = GST_TEE (object);
187 g_value_set_int (value, tee->numsrcpads);
190 g_value_set_boolean (value, tee->silent);
199 * @pad: the pad to follow
200 * @buf: the buffer to pass
202 * Chain a buffer on a pad.
205 gst_tee_chain (GstPad *pad, GstBuffer *buf)
211 g_return_if_fail (pad != NULL);
212 g_return_if_fail (GST_IS_PAD (pad));
213 g_return_if_fail (buf != NULL);
215 tee = GST_TEE (gst_pad_get_parent (pad));
216 // gst_trace_add_entry (NULL, 0, buf, "tee buffer");
218 for (i=0; i<tee->numsrcpads-1; i++)
219 gst_buffer_ref (buf);
221 srcpads = tee->srcpads;
223 GstPad *outpad = GST_PAD (srcpads->data);
224 srcpads = g_slist_next (srcpads);
227 g_print("tee: chain ******* (%s:%s)t (%d bytes, %llu) \n",
228 GST_DEBUG_PAD_NAME (outpad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf));
230 gst_pad_push (outpad, buf);
235 gst_tee_factory_init (GstElementFactory *factory)
237 gst_elementfactory_add_padtemplate (factory, GST_PADTEMPLATE_GET (tee_src_factory));