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.
31 GST_DEBUG_CATEGORY_STATIC (gst_tee_debug);
32 #define GST_CAT_DEFAULT gst_tee_debug
34 GstElementDetails gst_tee_details = GST_ELEMENT_DETAILS (
37 "1-to-N pipe fitting",
38 "Erik Walthinsen <omega@cse.ogi.edu>, "
39 "Wim Taymans <wim.taymans@chello.be>"
42 /* Tee signals and args */
56 GstStaticPadTemplate tee_src_template = GST_STATIC_PAD_TEMPLATE (
63 #define _do_init(bla) \
64 GST_DEBUG_CATEGORY_INIT (gst_tee_debug, "tee", 0, "tee element");
66 GST_BOILERPLATE_FULL (GstTee, gst_tee, GstElement, GST_TYPE_ELEMENT, _do_init);
68 static GstPad* gst_tee_request_new_pad (GstElement *element, GstPadTemplate *temp, const gchar *unused);
70 static void gst_tee_set_property (GObject *object, guint prop_id,
71 const GValue *value, GParamSpec *pspec);
72 static void gst_tee_get_property (GObject *object, guint prop_id,
73 GValue *value, GParamSpec *pspec);
75 static void gst_tee_chain (GstPad *pad, GstData *_data);
79 gst_tee_base_init (gpointer g_class)
81 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
83 gst_element_class_set_details (gstelement_class, &gst_tee_details);
84 gst_element_class_add_pad_template (gstelement_class,
85 gst_static_pad_template_get (&tee_src_template));
88 gst_tee_class_init (GstTeeClass *klass)
90 GObjectClass *gobject_class;
91 GstElementClass *gstelement_class;
93 gobject_class = (GObjectClass*)klass;
94 gstelement_class = (GstElementClass*)klass;
97 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NUM_PADS,
98 g_param_spec_int ("num_pads", "num_pads", "num_pads",
99 0, G_MAXINT, 0, G_PARAM_READABLE));
100 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SILENT,
101 g_param_spec_boolean ("silent", "silent", "silent",
102 FALSE, G_PARAM_READWRITE));
103 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LAST_MESSAGE,
104 g_param_spec_string ("last_message", "last_message", "last_message",
105 NULL, G_PARAM_READABLE));
108 gobject_class->set_property = GST_DEBUG_FUNCPTR(gst_tee_set_property);
109 gobject_class->get_property = GST_DEBUG_FUNCPTR(gst_tee_get_property);
111 gstelement_class->request_new_pad = GST_DEBUG_FUNCPTR(gst_tee_request_new_pad);
115 gst_tee_init (GstTee *tee)
117 tee->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
118 gst_element_add_pad (GST_ELEMENT (tee), tee->sinkpad);
119 gst_pad_set_chain_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_tee_chain));
120 gst_pad_set_link_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_pad_proxy_pad_link));
121 gst_pad_set_getcaps_function (tee->sinkpad, GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
124 tee->last_message = NULL;
127 /* helper compare function */
128 gint name_pad_compare (gconstpointer a, gconstpointer b)
130 GstPad* pad = (GstPad*) a;
131 gchar *name = (gchar *) b;
133 g_assert (GST_IS_PAD (pad));
135 return strcmp (name, gst_pad_get_name (pad)); /* returns 0 if match */
139 gst_tee_request_new_pad (GstElement *element, GstPadTemplate *templ, const gchar *unused)
147 g_return_val_if_fail (GST_IS_TEE (element), NULL);
149 if (templ->direction != GST_PAD_SRC) {
150 g_warning ("gsttee: request new pad that is not a SRC pad\n");
154 tee = GST_TEE (element);
156 /* try names in order and find one that's not in use atm */
157 pads = gst_element_get_pad_list (element);
162 name = g_strdup_printf ("src%d", i);
163 if (g_list_find_custom ((GList *)pads, (gconstpointer) name, name_pad_compare) != NULL)
165 /* this name is taken, use the next one */
172 g_free (tee->last_message);
173 tee->last_message = g_strdup_printf ("new pad %s", name);
174 g_object_notify (G_OBJECT (tee), "last_message");
177 srcpad = gst_pad_new_from_template (templ, name);
179 gst_pad_set_link_function (srcpad, GST_DEBUG_FUNCPTR (gst_pad_proxy_pad_link));
180 gst_pad_set_getcaps_function (srcpad, GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
181 gst_element_add_pad (GST_ELEMENT (tee), srcpad);
182 GST_PAD_ELEMENT_PRIVATE (srcpad) = NULL;
184 if (GST_PAD_CAPS (tee->sinkpad)) {
185 gst_pad_try_set_caps (srcpad, GST_PAD_CAPS (tee->sinkpad));
192 gst_tee_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
196 /* it's not null if we got it, but it might not be ours */
197 g_return_if_fail (GST_IS_TEE (object));
199 tee = GST_TEE (object);
203 tee->silent = g_value_get_boolean (value);
204 g_object_notify (G_OBJECT (tee), "silent");
207 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
213 gst_tee_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
217 /* it's not null if we got it, but it might not be ours */
218 g_return_if_fail (GST_IS_TEE (object));
220 tee = GST_TEE (object);
224 g_value_set_int (value, GST_ELEMENT (tee)->numsrcpads);
227 g_value_set_boolean (value, tee->silent);
229 case ARG_LAST_MESSAGE:
230 g_value_set_string ((GValue *) value, tee->last_message);
233 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
240 * @pad: the pad to follow
241 * @buf: the buffer to pass
243 * Chain a buffer on a pad.
246 gst_tee_chain (GstPad *pad, GstData *_data)
248 GstBuffer *buf = GST_BUFFER (_data);
252 g_return_if_fail (pad != NULL);
253 g_return_if_fail (GST_IS_PAD (pad));
254 g_return_if_fail (buf != NULL);
256 tee = GST_TEE (gst_pad_get_parent (pad));
258 gst_buffer_ref_by_count (buf, GST_ELEMENT (tee)->numsrcpads - 1);
260 pads = gst_element_get_pad_list (GST_ELEMENT (tee));
263 GstPad *outpad = GST_PAD (pads->data);
264 pads = g_list_next (pads);
266 if (GST_PAD_DIRECTION (outpad) != GST_PAD_SRC)
270 g_free (tee->last_message);
271 tee->last_message = g_strdup_printf ("chain ******* (%s:%s)t (%d bytes, %"
272 G_GUINT64_FORMAT ") %p",
273 GST_DEBUG_PAD_NAME (outpad), GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf), buf);
274 g_object_notify (G_OBJECT (tee), "last_message");
277 if (GST_PAD_IS_USABLE (outpad))
278 gst_pad_push (outpad, GST_DATA (buf));
280 gst_buffer_unref (buf);