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 GstFlowReturn gst_valve_transform_ip (GstBaseTransform *trans,
78 static gboolean gst_valve_event (GstBaseTransform *trans, GstEvent *event);
79 static GstFlowReturn gst_valve_buffer_alloc (GstPad * pad, guint64 offset,
80 guint size, GstCaps * caps, GstBuffer ** buf);
81 static GstFlowReturn gst_valve_prepare_output_buffer (GstBaseTransform *trans,
82 GstBuffer * in_buf, gint out_size, GstCaps * out_caps,
83 GstBuffer ** out_buf);
88 GST_DEBUG_CATEGORY_INIT
89 (valve_debug, "valve", 0, "Valve");
92 GST_BOILERPLATE_FULL (GstValve, gst_valve, GstBaseTransform,
93 GST_TYPE_BASE_TRANSFORM, _do_init);
96 gst_valve_base_init (gpointer klass)
98 GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
100 gst_element_class_add_pad_template (element_class,
101 gst_static_pad_template_get (&srctemplate));
102 gst_element_class_add_pad_template (element_class,
103 gst_static_pad_template_get (&sinktemplate));
105 gst_element_class_set_details (element_class, &gst_valve_details);
109 gst_valve_class_init (GstValveClass *klass)
111 GObjectClass *gobject_class;
112 GstBaseTransformClass *gstbasetransform_class;
114 gobject_class = (GObjectClass *) klass;
115 gstbasetransform_class = (GstBaseTransformClass *) klass;
117 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_valve_set_property);
118 gobject_class->get_property = GST_DEBUG_FUNCPTR (gst_valve_get_property);
120 gstbasetransform_class->transform_ip =
121 GST_DEBUG_FUNCPTR (gst_valve_transform_ip);
122 gstbasetransform_class->prepare_output_buffer =
123 GST_DEBUG_FUNCPTR (gst_valve_prepare_output_buffer);
124 gstbasetransform_class->event =
125 GST_DEBUG_FUNCPTR (gst_valve_event);
126 gstbasetransform_class->src_event =
127 GST_DEBUG_FUNCPTR (gst_valve_event);
129 g_object_class_install_property (gobject_class, ARG_DROP,
130 g_param_spec_boolean ("drop",
131 "Drops all buffers if TRUE",
132 "If this property if TRUE, the element will drop all buffers, if its FALSE, it will let them through",
133 FALSE, G_PARAM_READWRITE));
135 parent_class = g_type_class_peek_parent (klass);
139 gst_valve_init (GstValve *valve, GstValveClass *klass)
143 valve->discont = FALSE;
145 valve->original_allocfunc =
146 GST_BASE_TRANSFORM (valve)->sinkpad->bufferallocfunc;
148 gst_pad_set_bufferalloc_function (
149 GST_BASE_TRANSFORM (valve)->sinkpad,
150 GST_DEBUG_FUNCPTR(gst_valve_buffer_alloc));
153 #if GST_VERSION_MINOR >= 10 && GST_VERSION_MICRO >= 13
154 gst_base_transform_set_passthrough (GST_BASE_TRANSFORM (valve), FALSE);
161 gst_valve_set_property (GObject *object,
162 guint prop_id, const GValue *value, GParamSpec *pspec)
164 GstValve *valve = GST_VALVE (object);
168 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
171 GST_OBJECT_LOCK (object);
172 valve->drop = g_value_get_boolean (value);
173 GST_OBJECT_UNLOCK (object);
179 gst_valve_get_property (GObject *object,
180 guint prop_id, GValue *value, GParamSpec *pspec)
182 GstValve *valve = GST_VALVE (object);
186 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
189 GST_OBJECT_LOCK (object);
190 g_value_set_boolean (value, valve->drop);
191 GST_OBJECT_UNLOCK (object);
197 gst_valve_prepare_output_buffer (GstBaseTransform *trans, GstBuffer * in_buf,
198 gint out_size, GstCaps * out_caps,
199 GstBuffer ** out_buf)
201 GstValve *valve = GST_VALVE (trans);
202 GstFlowReturn ret = GST_FLOW_OK;
204 GST_OBJECT_LOCK (GST_OBJECT (trans));
207 #if GST_VERSION_MINOR >= 10 && GST_VERSION_MICRO >= 13
208 ret = GST_BASE_TRANSFORM_FLOW_DROPPED;
211 valve->discont = TRUE;
215 /* Always return a reffed buffer, which in case of returning the input
216 * buffer means adding an extra ref to it */
219 if (gst_buffer_is_metadata_writable (in_buf))
221 *out_buf = gst_buffer_ref (in_buf);
225 *out_buf = gst_buffer_create_sub (in_buf, 0, GST_BUFFER_SIZE (in_buf));
227 GST_BUFFER_FLAG_SET (*out_buf, GST_BUFFER_FLAG_DISCONT);
228 valve->discont = FALSE;
232 *out_buf = gst_buffer_ref(in_buf);
235 GST_OBJECT_UNLOCK (GST_OBJECT (trans));
241 gst_valve_transform_ip (GstBaseTransform *trans, GstBuffer *buf)
248 gst_valve_event (GstBaseTransform *trans, GstEvent *event)
250 GstValve *valve = GST_VALVE (trans);
253 GST_OBJECT_LOCK (GST_OBJECT (trans));
256 GST_OBJECT_UNLOCK (GST_OBJECT (trans));
262 gst_valve_buffer_alloc (GstPad * pad, guint64 offset, guint size,
263 GstCaps * caps, GstBuffer ** buf)
265 GstValve *valve = GST_VALVE (gst_pad_get_parent_element (pad));
266 GstFlowReturn ret = GST_FLOW_OK;
268 GST_OBJECT_LOCK (GST_OBJECT (valve));
271 GST_OBJECT_UNLOCK (GST_OBJECT (valve));
272 *buf = gst_buffer_new_and_alloc (size);
273 GST_BUFFER_OFFSET (*buf) = offset;
274 gst_buffer_set_caps (*buf, caps);
278 GstPadBufferAllocFunction allocfunc = valve->original_allocfunc;
279 GST_OBJECT_UNLOCK (GST_OBJECT (valve));
280 ret = allocfunc (pad, offset, size, caps, buf);
283 gst_object_unref (valve);
290 gst_valve_plugin_init (GstPlugin *plugin)
292 return gst_element_register (plugin, "fsvalve",
293 GST_RANK_MARGINAL, GST_TYPE_VALVE);
296 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
300 gst_valve_plugin_init, VERSION, "LGPL", "Farsight", "http://farsight.sf.net")