2 * Farsight Voice+Video library
4 * Copyright 2007 Collabora Ltd,
5 * Copyright 2007 Nokia Corporation
6 * @author: Olivier Crete <olivier.crete@collabora.co.uk>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
33 GST_DEBUG_CATEGORY (valve_debug);
34 #define GST_CAT_DEFAULT (valve_debug)
36 /* elementfactory information */
37 static const GstElementDetails gst_valve_details =
41 "This element drops all packets when drop is TRUE",
42 "Olivier Crete <olivier.crete@collabora.co.uk>");
45 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
50 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
55 /* Valve signals and args */
71 static void gst_valve_set_property (GObject *object,
72 guint prop_id, const GValue * value, GParamSpec * pspec);
73 static void gst_valve_get_property (GObject *object,
74 guint prop_id, GValue *value, GParamSpec *pspec);
76 static gboolean gst_valve_event (GstPad *pad, GstEvent *event);
77 static GstFlowReturn gst_valve_buffer_alloc (GstPad * pad, guint64 offset,
78 guint size, GstCaps * caps, GstBuffer ** buf);
79 static GstFlowReturn gst_valve_chain (GstPad *pad, GstBuffer *buffer);
80 static GstCaps *gst_valve_getcaps (GstPad *pad);
85 GST_DEBUG_CATEGORY_INIT
86 (valve_debug, "valve", 0, "Valve");
89 GST_BOILERPLATE_FULL (GstValve, gst_valve, GstElement,
90 GST_TYPE_ELEMENT, _do_init);
93 gst_valve_base_init (gpointer klass)
95 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
97 gst_element_class_add_pad_template (element_class,
98 gst_static_pad_template_get (&srctemplate));
99 gst_element_class_add_pad_template (element_class,
100 gst_static_pad_template_get (&sinktemplate));
102 gst_element_class_set_details (element_class, &gst_valve_details);
106 gst_valve_class_init (GstValveClass *klass)
108 GObjectClass *gobject_class;
110 gobject_class = (GObjectClass *) klass;
112 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_valve_set_property);
113 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_valve_get_property);
115 g_object_class_install_property (gobject_class, ARG_DROP,
116 g_param_spec_boolean ("drop",
117 "Drops all buffers if TRUE",
118 "If this property if TRUE, the element will drop all buffers, if its FALSE, it will let them through",
119 FALSE, G_PARAM_READWRITE));
121 parent_class = g_type_class_peek_parent (klass);
125 gst_valve_init (GstValve *valve, GstValveClass *klass)
128 valve->discont = FALSE;
130 valve->srcpad = gst_pad_new_from_static_template (&srctemplate, "src");
131 gst_pad_set_getcaps_function (valve->srcpad,
132 GST_DEBUG_FUNCPTR (gst_valve_getcaps));
133 gst_element_add_pad (GST_ELEMENT (valve), valve->srcpad);
135 valve->sinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
136 gst_pad_set_chain_function (valve->sinkpad,
137 GST_DEBUG_FUNCPTR (gst_valve_chain));
138 gst_pad_set_event_function (valve->sinkpad,
139 GST_DEBUG_FUNCPTR (gst_valve_event));
140 gst_pad_set_bufferalloc_function (valve->sinkpad,
141 GST_DEBUG_FUNCPTR (gst_valve_buffer_alloc));
142 gst_pad_set_getcaps_function (valve->sinkpad,
143 GST_DEBUG_FUNCPTR (gst_valve_getcaps));
144 gst_element_add_pad (GST_ELEMENT (valve), valve->sinkpad);
149 gst_valve_set_property (GObject *object,
150 guint prop_id, const GValue *value, GParamSpec *pspec)
152 GstValve *valve = GST_VALVE (object);
156 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
159 GST_OBJECT_LOCK (object);
160 valve->drop = g_value_get_boolean (value);
161 GST_OBJECT_UNLOCK (object);
167 gst_valve_get_property (GObject *object,
168 guint prop_id, GValue *value, GParamSpec *pspec)
170 GstValve *valve = GST_VALVE (object);
174 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
177 GST_OBJECT_LOCK (object);
178 g_value_set_boolean (value, valve->drop);
179 GST_OBJECT_UNLOCK (object);
185 gst_valve_chain (GstPad *pad, GstBuffer *buffer)
187 GstValve *valve = GST_VALVE (gst_pad_get_parent_element (pad));
188 GstFlowReturn ret = GST_FLOW_OK;
191 GST_OBJECT_LOCK (GST_OBJECT (valve));
194 if (!drop && valve->discont)
196 buffer = gst_buffer_make_metadata_writable (buffer);
197 GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
198 valve->discont = FALSE;
200 GST_OBJECT_UNLOCK (GST_OBJECT (valve));
203 gst_buffer_unref (buffer);
205 ret = gst_pad_push (valve->srcpad, buffer);
208 GST_OBJECT_LOCK (GST_OBJECT (valve));
211 GST_OBJECT_UNLOCK (GST_OBJECT (valve));
213 gst_object_unref (valve);
220 gst_valve_event (GstPad *pad, GstEvent *event)
222 GstValve *valve = GST_VALVE (gst_pad_get_parent_element (pad));
226 GST_OBJECT_LOCK (GST_OBJECT (valve));
228 GST_OBJECT_UNLOCK (GST_OBJECT (valve));
231 gst_event_unref (event);
233 ret = gst_pad_push_event (valve->srcpad, event);
235 GST_OBJECT_LOCK (GST_OBJECT (valve));
238 GST_OBJECT_UNLOCK (GST_OBJECT (valve));
240 gst_object_unref (valve);
245 gst_valve_buffer_alloc (GstPad * pad, guint64 offset, guint size,
246 GstCaps * caps, GstBuffer ** buf)
248 GstValve *valve = GST_VALVE (gst_pad_get_parent_element (pad));
249 GstFlowReturn ret = GST_FLOW_OK;
252 GST_OBJECT_LOCK (GST_OBJECT (valve));
254 GST_OBJECT_UNLOCK (GST_OBJECT (valve));
259 ret = gst_pad_alloc_buffer (valve->srcpad, offset, size, caps, buf);
261 GST_OBJECT_LOCK (GST_OBJECT (valve));
264 GST_OBJECT_UNLOCK (GST_OBJECT (valve));
266 gst_object_unref (valve);
273 gst_valve_plugin_init (GstPlugin *plugin)
275 return gst_element_register (plugin, "fsvalve",
276 GST_RANK_MARGINAL, GST_TYPE_VALVE);
279 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
283 gst_valve_plugin_init, VERSION, "LGPL", "Farsight", "http://farsight.sf.net")
286 gst_valve_getcaps (GstPad *pad)
288 GstValve *valve = GST_VALVE (gst_pad_get_parent (pad));
291 if (pad == valve->sinkpad)
292 caps = gst_pad_peer_get_caps (valve->srcpad);
294 caps = gst_pad_peer_get_caps (valve->sinkpad);
297 caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
299 gst_object_unref (valve);