1 /* GStreamer LADSPA sink category
2 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
3 * 2001 Steve Baker <stevebaker_org@yahoo.co.uk>
4 * 2003 Andy Wingo <wingo at pobox.com>
5 * Copyright (C) 2005 Wim Taymans <wim@fluendo.com> (fakesink)
6 * Copyright (C) 2013 Juan Manuel Borges CaƱo <juanmabcmail@gmail.com>
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., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
28 #include "gstladspasink.h"
29 #include "gstladspa.h"
30 #include "gstladspautils.h"
31 #include <gst/base/gstbasetransform.h>
35 GST_DEBUG_CATEGORY_EXTERN (ladspa_debug);
36 #define GST_CAT_DEFAULT ladspa_debug
38 #define GST_LADSPA_SINK_CLASS_TAGS "Sink/Audio/LADSPA"
39 #define GST_LADSPA_SINK_DEFAULT_SYNC TRUE
40 #define GST_LADSPA_SINK_DEFAULT_CAN_ACTIVATE_PUSH TRUE
41 #define GST_LADSPA_SINK_DEFAULT_CAN_ACTIVATE_PULL FALSE
42 #define GST_LADSPA_SINK_DEFAULT_NUM_BUFFERS -1
46 GST_LADSPA_SINK_PROP_0,
47 GST_LADSPA_SINK_PROP_CAN_ACTIVATE_PUSH,
48 GST_LADSPA_SINK_PROP_CAN_ACTIVATE_PULL,
49 GST_LADSPA_SINK_PROP_NUM_BUFFERS,
50 GST_LADSPA_SINK_PROP_LAST
53 static GstLADSPASinkClass *gst_ladspa_sink_type_parent_class = NULL;
56 * Boilerplates BaseSink add pad.
59 gst_my_base_sink_class_add_pad_template (GstBaseSinkClass * base_class,
62 GstElementClass *elem_class = GST_ELEMENT_CLASS (base_class);
63 GstPadTemplate *pad_template;
65 g_return_if_fail (GST_IS_CAPS (sinkcaps));
68 gst_pad_template_new (GST_BASE_TRANSFORM_SINK_NAME, GST_PAD_SINK,
69 GST_PAD_ALWAYS, sinkcaps);
70 gst_element_class_add_pad_template (elem_class, pad_template);
74 gst_ladspa_sink_type_set_caps (GstBaseSink * base, GstCaps * caps)
76 GstLADSPASink *ladspa = GST_LADSPA_SINK (base);
79 if (!gst_audio_info_from_caps (&info, caps)) {
80 GST_ERROR_OBJECT (base, "received invalid caps");
84 GST_DEBUG_OBJECT (ladspa, "negotiated to caps %" GST_PTR_FORMAT, caps);
88 return gst_ladspa_setup (&ladspa->ladspa, GST_AUDIO_INFO_RATE (&info));
92 gst_ladspa_sink_type_query (GstBaseSink * base, GstQuery * query)
96 switch (GST_QUERY_TYPE (query)) {
97 case GST_QUERY_SEEKING:{
100 /* we don't supporting seeking */
101 gst_query_parse_seeking (query, &fmt, NULL, NULL, NULL);
102 gst_query_set_seeking (query, fmt, FALSE, 0, -1);
108 GST_BASE_SINK_CLASS (gst_ladspa_sink_type_parent_class)->query
117 gst_ladspa_sink_type_preroll (GstBaseSink * base, GstBuffer * buffer)
119 GstLADSPASink *ladspa = GST_LADSPA_SINK (base);
121 if (ladspa->num_buffers_left == 0) {
122 GST_DEBUG_OBJECT (ladspa, "we are EOS");
130 gst_ladspa_sink_type_render (GstBaseSink * base, GstBuffer * buf)
132 GstLADSPASink *ladspa = GST_LADSPA_SINK (base);
135 if (ladspa->num_buffers_left == 0)
138 if (ladspa->num_buffers_left != -1)
139 ladspa->num_buffers_left--;
141 gst_object_sync_values (GST_OBJECT (ladspa), GST_BUFFER_TIMESTAMP (buf));
143 gst_buffer_map (buf, &info, GST_MAP_READ);
144 gst_ladspa_transform (&ladspa->ladspa, NULL,
145 info.size / sizeof (LADSPA_Data) / ladspa->ladspa.klass->count.audio.in,
147 gst_buffer_unmap (buf, &info);
149 if (ladspa->num_buffers_left == 0)
157 GST_DEBUG_OBJECT (ladspa, "we are EOS");
162 static GstStateChangeReturn
163 gst_ladspa_sink_type_change_state (GstElement * element,
164 GstStateChange transition)
166 GstLADSPASink *ladspa = GST_LADSPA_SINK (element);
167 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
169 switch (transition) {
170 case GST_STATE_CHANGE_READY_TO_PAUSED:
171 ladspa->num_buffers_left = ladspa->num_buffers;
178 GST_ELEMENT_CLASS (gst_ladspa_sink_type_parent_class)->change_state
179 (element, transition);
186 gst_ladspa_sink_type_set_property (GObject * object, guint prop_id,
187 const GValue * value, GParamSpec * pspec)
189 GstLADSPASink *ladspa = GST_LADSPA_SINK (object);
192 case GST_LADSPA_SINK_PROP_CAN_ACTIVATE_PUSH:
193 GST_BASE_SINK (ladspa)->can_activate_push = g_value_get_boolean (value);
195 case GST_LADSPA_SINK_PROP_CAN_ACTIVATE_PULL:
196 GST_BASE_SINK (ladspa)->can_activate_pull = g_value_get_boolean (value);
198 case GST_LADSPA_SINK_PROP_NUM_BUFFERS:
199 ladspa->num_buffers = g_value_get_int (value);
202 gst_ladspa_object_set_property (&ladspa->ladspa, object, prop_id, value,
209 gst_ladspa_sink_type_get_property (GObject * object, guint prop_id,
210 GValue * value, GParamSpec * pspec)
212 GstLADSPASink *ladspa = GST_LADSPA_SINK (object);
215 case GST_LADSPA_SINK_PROP_CAN_ACTIVATE_PUSH:
216 g_value_set_boolean (value, GST_BASE_SINK (ladspa)->can_activate_push);
218 case GST_LADSPA_SINK_PROP_CAN_ACTIVATE_PULL:
219 g_value_set_boolean (value, GST_BASE_SINK (ladspa)->can_activate_pull);
221 case GST_LADSPA_SINK_PROP_NUM_BUFFERS:
222 g_value_set_int (value, ladspa->num_buffers);
225 gst_ladspa_object_get_property (&ladspa->ladspa, object, prop_id, value,
232 gst_ladspa_sink_type_init (GstLADSPASink * ladspa, LADSPA_Descriptor * desc)
234 GstLADSPASinkClass *ladspa_class = GST_LADSPA_SINK_GET_CLASS (ladspa);
235 GstBaseSink *base = GST_BASE_SINK (ladspa);
237 gst_ladspa_init (&ladspa->ladspa, &ladspa_class->ladspa);
239 ladspa->num_buffers = GST_LADSPA_SINK_DEFAULT_NUM_BUFFERS;
241 gst_base_sink_set_sync (base, GST_LADSPA_SINK_DEFAULT_SYNC);
245 gst_ladspa_sink_type_dispose (GObject * object)
247 GstLADSPASink *ladspa = GST_LADSPA_SINK (object);
249 gst_ladspa_cleanup (&ladspa->ladspa);
251 G_OBJECT_CLASS (gst_ladspa_sink_type_parent_class)->dispose (object);
255 gst_ladspa_sink_type_finalize (GObject * object)
257 GstLADSPASink *ladspa = GST_LADSPA_SINK (object);
259 gst_ladspa_finalize (&ladspa->ladspa);
261 G_OBJECT_CLASS (gst_ladspa_sink_type_parent_class)->finalize (object);
265 * It is okay for plugins to 'leak' a one-time allocation. This will be freed when
266 * the application exits. When the plugins are scanned for the first time, this is
267 * done from a separate process to not impose the memory overhead on the calling
268 * application (among other reasons). Hence no need for class_finalize.
271 gst_ladspa_sink_type_base_init (GstLADSPASinkClass * ladspa_class)
273 GObjectClass *object_class = G_OBJECT_CLASS (ladspa_class);
274 GstElementClass *elem_class = GST_ELEMENT_CLASS (ladspa_class);
275 GstBaseSinkClass *base_class = GST_BASE_SINK_CLASS (ladspa_class);
276 LADSPA_Descriptor *desc;
279 g_type_get_qdata (G_OBJECT_CLASS_TYPE (object_class), descriptor_quark);
282 gst_ladspa_class_init (&ladspa_class->ladspa, desc);
284 gst_ladspa_element_class_set_metadata (&ladspa_class->ladspa, elem_class,
285 GST_LADSPA_SINK_CLASS_TAGS);
287 gst_ladspa_sink_type_class_add_pad_template (&ladspa_class->ladspa,
293 gst_ladspa_sink_type_base_finalize (GstLADSPASinkClass * ladspa_class)
295 gst_ladspa_class_finalize (&ladspa_class->ladspa);
299 gst_ladspa_sink_type_class_init (GstLADSPASinkClass * ladspa_class,
300 LADSPA_Descriptor * desc)
302 GObjectClass *object_class = G_OBJECT_CLASS (ladspa_class);
303 GstElementClass *elem_class = GST_ELEMENT_CLASS (ladspa_class);
304 GstBaseSinkClass *base_class = base_class =
305 GST_BASE_SINK_CLASS (ladspa_class);
307 gst_ladspa_sink_type_parent_class = g_type_class_peek_parent (ladspa_class);
309 object_class->dispose = GST_DEBUG_FUNCPTR (gst_ladspa_sink_type_dispose);
310 object_class->finalize = GST_DEBUG_FUNCPTR (gst_ladspa_sink_type_finalize);
311 object_class->set_property =
312 GST_DEBUG_FUNCPTR (gst_ladspa_sink_type_set_property);
313 object_class->get_property =
314 GST_DEBUG_FUNCPTR (gst_ladspa_sink_type_get_property);
316 elem_class->change_state =
317 GST_DEBUG_FUNCPTR (gst_ladspa_sink_type_change_state);
319 base_class->set_caps = GST_DEBUG_FUNCPTR (gst_ladspa_sink_type_set_caps);
320 base_class->preroll = GST_DEBUG_FUNCPTR (gst_ladspa_sink_type_preroll);
321 base_class->render = GST_DEBUG_FUNCPTR (gst_ladspa_sink_type_render);
322 base_class->query = GST_DEBUG_FUNCPTR (gst_ladspa_sink_type_query);
324 g_object_class_install_property (object_class,
325 GST_LADSPA_SINK_PROP_CAN_ACTIVATE_PUSH,
326 g_param_spec_boolean ("can-activate-push", "Can activate push",
327 "Can activate in push mode",
328 GST_LADSPA_SINK_DEFAULT_CAN_ACTIVATE_PUSH,
329 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
331 g_object_class_install_property (object_class,
332 GST_LADSPA_SINK_PROP_CAN_ACTIVATE_PULL,
333 g_param_spec_boolean ("can-activate-pull", "Can activate pull",
334 "Can activate in pull mode",
335 GST_LADSPA_SINK_DEFAULT_CAN_ACTIVATE_PULL,
336 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
338 g_object_class_install_property (object_class,
339 GST_LADSPA_SINK_PROP_NUM_BUFFERS, g_param_spec_int ("num-buffers",
340 "num-buffers", "Number of buffers to accept going EOS", -1, G_MAXINT,
341 GST_LADSPA_SINK_DEFAULT_NUM_BUFFERS,
342 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
344 gst_ladspa_object_class_install_properties (&ladspa_class->ladspa,
345 object_class, GST_LADSPA_SINK_PROP_LAST);
349 G_DEFINE_ABSTRACT_TYPE (GstLADSPASink, gst_ladspa_sink, GST_TYPE_BASE_SINK);
352 gst_ladspa_sink_init (GstLADSPASink * ladspa)
357 gst_ladspa_sink_class_init (GstLADSPASinkClass * ladspa_class)
362 * Construct the type.
365 ladspa_describe_sink_plugin (GstPlugin * plugin,
366 const gchar * filename, const LADSPA_Descriptor * desc)
369 sizeof (GstLADSPASinkClass),
370 (GBaseInitFunc) gst_ladspa_sink_type_base_init,
371 (GBaseFinalizeFunc) gst_ladspa_sink_type_base_finalize,
372 (GClassInitFunc) gst_ladspa_sink_type_class_init,
375 sizeof (GstLADSPASink),
377 (GInstanceInitFunc) gst_ladspa_sink_type_init,
382 tmp = g_strdup_printf ("ladspasink-%s-%s", filename, desc->Label);
383 ladspa_register_plugin (plugin, GST_TYPE_LADSPA_SINK, tmp, &info,
384 descriptor_quark, filename, desc);