2 * GStreamer Funnel element
4 * Copyright 2007 Collabora Ltd.
5 * @author: Olivier Crete <olivier.crete@collabora.co.uk>
6 * Copyright 2007 Nokia Corp.
8 * gstfunnel.c: Simple Funnel element
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 * SECTION:element-funnel
28 * Takes packets from various input sinks into one output source.
30 * funnel always outputs a single, open ended segment from
31 * 0 with in %GST_FORMAT_TIME and outputs the buffers of the
32 * different sinkpads with timestamps that are set to the
33 * running time for that stream. funnel does not synchronize
34 * the different input streams but simply forwards all buffers
35 * immediately when they arrive.
43 #include "gstfunnel.h"
45 GST_DEBUG_CATEGORY_STATIC (gst_funnel_debug);
46 #define GST_CAT_DEFAULT gst_funnel_debug
48 static GstStaticPadTemplate funnel_sink_template =
49 GST_STATIC_PAD_TEMPLATE ("sink_%u",
54 static GstStaticPadTemplate funnel_src_template =
55 GST_STATIC_PAD_TEMPLATE ("src",
61 GST_DEBUG_CATEGORY_INIT (gst_funnel_debug, "funnel", 0, "funnel element");
62 #define gst_funnel_parent_class parent_class
63 G_DEFINE_TYPE_WITH_CODE (GstFunnel, gst_funnel, GST_TYPE_ELEMENT, _do_init);
65 static GstPad *gst_funnel_request_new_pad (GstElement * element,
66 GstPadTemplate * templ, const gchar * name, const GstCaps * caps);
67 static void gst_funnel_release_pad (GstElement * element, GstPad * pad);
69 static GstFlowReturn gst_funnel_sink_chain (GstPad * pad, GstObject * parent,
71 static gboolean gst_funnel_sink_event (GstPad * pad, GstObject * parent,
75 gst_funnel_dispose (GObject * object)
77 GstFunnel *funnel = GST_FUNNEL (object);
80 gst_object_replace ((GstObject **) & funnel->last_sinkpad, NULL);
83 for (item = GST_ELEMENT_PADS (object); item; item = g_list_next (item)) {
84 GstPad *pad = GST_PAD (item->data);
86 if (GST_PAD_IS_SINK (pad)) {
87 gst_element_release_request_pad (GST_ELEMENT (object), pad);
92 G_OBJECT_CLASS (parent_class)->dispose (object);
96 gst_funnel_class_init (GstFunnelClass * klass)
98 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
99 GstElementClass *gstelement_class = GST_ELEMENT_CLASS (klass);
101 gobject_class->dispose = GST_DEBUG_FUNCPTR (gst_funnel_dispose);
103 gst_element_class_set_static_metadata (gstelement_class,
104 "Funnel pipe fitting", "Generic", "N-to-1 pipe fitting",
105 "Olivier Crete <olivier.crete@collabora.co.uk>");
107 gst_element_class_add_pad_template (gstelement_class,
108 gst_static_pad_template_get (&funnel_sink_template));
109 gst_element_class_add_pad_template (gstelement_class,
110 gst_static_pad_template_get (&funnel_src_template));
112 gstelement_class->request_new_pad =
113 GST_DEBUG_FUNCPTR (gst_funnel_request_new_pad);
114 gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_funnel_release_pad);
118 gst_funnel_init (GstFunnel * funnel)
120 funnel->srcpad = gst_pad_new_from_static_template (&funnel_src_template,
122 gst_pad_use_fixed_caps (funnel->srcpad);
124 gst_element_add_pad (GST_ELEMENT (funnel), funnel->srcpad);
128 gst_funnel_request_new_pad (GstElement * element, GstPadTemplate * templ,
129 const gchar * name, const GstCaps * caps)
133 GST_DEBUG_OBJECT (element, "requesting pad");
135 sinkpad = gst_pad_new_from_static_template (&funnel_sink_template, name);
137 gst_pad_set_chain_function (sinkpad,
138 GST_DEBUG_FUNCPTR (gst_funnel_sink_chain));
139 gst_pad_set_event_function (sinkpad,
140 GST_DEBUG_FUNCPTR (gst_funnel_sink_event));
142 GST_OBJECT_FLAG_SET (sinkpad, GST_PAD_FLAG_PROXY_CAPS);
143 GST_OBJECT_FLAG_SET (sinkpad, GST_PAD_FLAG_PROXY_ALLOCATION);
145 gst_pad_set_active (sinkpad, TRUE);
147 gst_element_add_pad (element, sinkpad);
153 gst_funnel_all_sinkpads_eos_unlocked (GstFunnel * funnel)
155 GstElement *element = GST_ELEMENT_CAST (funnel);
158 if (element->numsinkpads == 0)
161 for (item = element->sinkpads; item != NULL; item = g_list_next (item)) {
162 GstPad *sinkpad = item->data;
165 eos = gst_pad_get_sticky_event (sinkpad, GST_EVENT_EOS, 0);
167 gst_event_unref (eos);
177 gst_funnel_release_pad (GstElement * element, GstPad * pad)
179 GstFunnel *funnel = GST_FUNNEL (element);
181 gboolean send_eos = FALSE;
183 GST_DEBUG_OBJECT (funnel, "releasing pad");
185 gst_pad_set_active (pad, FALSE);
187 eos = gst_pad_get_sticky_event (pad, GST_EVENT_EOS, 0);
189 gst_event_unref (eos);
191 gst_element_remove_pad (GST_ELEMENT_CAST (funnel), pad);
193 GST_OBJECT_LOCK (funnel);
194 if (eos == NULL && gst_funnel_all_sinkpads_eos_unlocked (funnel)) {
195 GST_DEBUG_OBJECT (funnel, "Pad removed. All others are EOS. Sending EOS");
198 GST_OBJECT_UNLOCK (funnel);
201 if (!gst_pad_push_event (funnel->srcpad, gst_event_new_eos ()))
202 GST_WARNING_OBJECT (funnel, "Failure pushing EOS");
206 forward_events (GstPad * pad, GstEvent ** event, gpointer user_data)
208 GstPad *srcpad = user_data;
210 if (GST_EVENT_TYPE (*event) != GST_EVENT_EOS)
211 gst_pad_push_event (srcpad, gst_event_ref (*event));
217 gst_funnel_sink_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
220 GstFunnel *funnel = GST_FUNNEL (parent);
222 GST_DEBUG_OBJECT (funnel, "received buffer %p", buffer);
224 GST_PAD_STREAM_LOCK (funnel->srcpad);
226 if (funnel->last_sinkpad != pad) {
227 gst_object_replace ((GstObject **) & funnel->last_sinkpad,
230 gst_pad_sticky_events_foreach (pad, forward_events, funnel->srcpad);
233 res = gst_pad_push (funnel->srcpad, buffer);
235 GST_PAD_STREAM_UNLOCK (funnel->srcpad);
237 GST_LOG_OBJECT (funnel, "handled buffer %s", gst_flow_get_name (res));
243 gst_funnel_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
245 GstFunnel *funnel = GST_FUNNEL (parent);
246 gboolean forward = TRUE;
248 gboolean unlock = FALSE;
250 if (GST_EVENT_IS_STICKY (event)) {
252 GST_PAD_STREAM_LOCK (funnel->srcpad);
254 if (pad != funnel->last_sinkpad)
259 res = gst_pad_push_event (funnel->srcpad, event);
261 gst_event_unref (event);
264 GST_PAD_STREAM_UNLOCK (funnel->srcpad);