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 ("Tee pipe fitting",
36 "1-to-N pipe fitting",
37 "Erik Walthinsen <omega@cse.ogi.edu>, "
38 "Wim Taymans <wim.taymans@chello.be>");
40 /* Tee signals and args */
56 GstStaticPadTemplate tee_src_template = GST_STATIC_PAD_TEMPLATE ("src%d",
61 #define _do_init(bla) \
62 GST_DEBUG_CATEGORY_INIT (gst_tee_debug, "tee", 0, "tee element");
64 GST_BOILERPLATE_FULL (GstTee, gst_tee, GstElement, GST_TYPE_ELEMENT, _do_init);
66 static GstPad *gst_tee_request_new_pad (GstElement * element,
67 GstPadTemplate * temp, const gchar * unused);
69 static void gst_tee_set_property (GObject * object, guint prop_id,
70 const GValue * value, GParamSpec * pspec);
71 static void gst_tee_get_property (GObject * object, guint prop_id,
72 GValue * value, GParamSpec * pspec);
74 static void gst_tee_chain (GstPad * pad, GstData * _data);
78 gst_tee_base_init (gpointer g_class)
80 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
82 gst_element_class_set_details (gstelement_class, &gst_tee_details);
83 gst_element_class_add_pad_template (gstelement_class,
84 gst_static_pad_template_get (&tee_src_template));
87 gst_tee_class_init (GstTeeClass * klass)
89 GObjectClass *gobject_class;
90 GstElementClass *gstelement_class;
92 gobject_class = (GObjectClass *) klass;
93 gstelement_class = (GstElementClass *) klass;
96 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_NUM_PADS,
97 g_param_spec_int ("num_pads", "num_pads", "num_pads",
98 0, G_MAXINT, 0, G_PARAM_READABLE));
99 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_SILENT,
100 g_param_spec_boolean ("silent", "silent", "silent",
101 TRUE, G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
102 g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LAST_MESSAGE,
103 g_param_spec_string ("last_message", "last_message", "last_message",
104 NULL, G_PARAM_READABLE));
107 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_tee_set_property);
108 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_tee_get_property);
110 gstelement_class->request_new_pad =
111 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,
121 GST_DEBUG_FUNCPTR (gst_pad_proxy_pad_link));
122 gst_pad_set_getcaps_function (tee->sinkpad,
123 GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
125 tee->last_message = NULL;
128 /* helper compare function */
130 name_pad_compare (gconstpointer a, gconstpointer b)
132 GstPad *pad = (GstPad *) a;
133 gchar *name = (gchar *) b;
135 g_assert (GST_IS_PAD (pad));
137 return strcmp (name, gst_pad_get_name (pad)); /* returns 0 if match */
141 gst_tee_request_new_pad (GstElement * element, GstPadTemplate * templ,
142 const gchar * unused)
150 g_return_val_if_fail (GST_IS_TEE (element), NULL);
152 if (templ->direction != GST_PAD_SRC) {
153 g_warning ("gsttee: request new pad that is not a SRC pad\n");
157 tee = GST_TEE (element);
159 /* try names in order and find one that's not in use atm */
160 pads = gst_element_get_pad_list (element);
164 name = g_strdup_printf ("src%d", i);
165 if (g_list_find_custom ((GList *) pads, (gconstpointer) name,
166 name_pad_compare) != NULL) {
167 /* this name is taken, use the next one */
174 g_free (tee->last_message);
175 tee->last_message = g_strdup_printf ("new pad %s", name);
176 g_object_notify (G_OBJECT (tee), "last_message");
179 srcpad = gst_pad_new_from_template (templ, name);
181 gst_pad_set_link_function (srcpad,
182 GST_DEBUG_FUNCPTR (gst_pad_proxy_pad_link));
183 gst_pad_set_getcaps_function (srcpad,
184 GST_DEBUG_FUNCPTR (gst_pad_proxy_getcaps));
185 gst_element_add_pad (GST_ELEMENT (tee), srcpad);
186 GST_PAD_ELEMENT_PRIVATE (srcpad) = NULL;
188 if (GST_PAD_CAPS (tee->sinkpad)) {
189 gst_pad_try_set_caps (srcpad, GST_PAD_CAPS (tee->sinkpad));
196 gst_tee_set_property (GObject * object, guint prop_id, const GValue * value,
201 /* it's not null if we got it, but it might not be ours */
202 g_return_if_fail (GST_IS_TEE (object));
204 tee = GST_TEE (object);
208 tee->silent = g_value_get_boolean (value);
209 g_object_notify (G_OBJECT (tee), "silent");
212 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
218 gst_tee_get_property (GObject * object, guint prop_id, GValue * value,
223 /* it's not null if we got it, but it might not be ours */
224 g_return_if_fail (GST_IS_TEE (object));
226 tee = GST_TEE (object);
230 g_value_set_int (value, GST_ELEMENT (tee)->numsrcpads);
233 g_value_set_boolean (value, tee->silent);
235 case ARG_LAST_MESSAGE:
236 g_value_set_string ((GValue *) value, tee->last_message);
239 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
246 * @pad: the pad to follow
247 * @buf: the buffer to pass
249 * Chain a buffer on a pad.
252 gst_tee_chain (GstPad * pad, GstData * _data)
254 GstBuffer *buf = GST_BUFFER (_data);
258 g_return_if_fail (pad != NULL);
259 g_return_if_fail (GST_IS_PAD (pad));
260 g_return_if_fail (buf != NULL);
262 tee = GST_TEE (gst_pad_get_parent (pad));
264 gst_buffer_ref_by_count (buf, GST_ELEMENT (tee)->numsrcpads - 1);
266 pads = gst_element_get_pad_list (GST_ELEMENT (tee));
269 GstPad *outpad = GST_PAD (pads->data);
271 pads = g_list_next (pads);
273 if (GST_PAD_DIRECTION (outpad) != GST_PAD_SRC)
277 g_free (tee->last_message);
279 g_strdup_printf ("chain ******* (%s:%s)t (%d bytes, %"
280 G_GUINT64_FORMAT ") %p", GST_DEBUG_PAD_NAME (outpad),
281 GST_BUFFER_SIZE (buf), GST_BUFFER_TIMESTAMP (buf), buf);
282 g_object_notify (G_OBJECT (tee), "last_message");
285 if (GST_PAD_IS_USABLE (outpad))
286 gst_pad_push (outpad, GST_DATA (buf));
288 gst_buffer_unref (buf);