2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * <2001> Steve Baker <stevebaker_org@yahoo.co.uk>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
24 //#define DEBUG_ENABLED
25 #include "gstladspa.h"
31 static GstPadTemplate*
32 ladspa_src_factory (void)
43 "format", GST_PROPS_STRING ("float"),
44 "layout", GST_PROPS_STRING ("gfloat"),
45 "intercept", GST_PROPS_FLOAT(0.0),
46 "slope", GST_PROPS_FLOAT(1.0),
47 "channels", GST_PROPS_INT (1),
48 "rate", GST_PROPS_INT_RANGE (0,G_MAXINT),
53 static GstPadTemplate*
54 ladspa_sink_factory (void)
65 "format", GST_PROPS_STRING ("float"),
66 "layout", GST_PROPS_STRING ("gfloat"),
67 "intercept", GST_PROPS_FLOAT(0.0),
68 "slope", GST_PROPS_FLOAT(1.0),
69 "channels", GST_PROPS_INT (1),
70 "rate", GST_PROPS_INT_RANGE (0,G_MAXINT),
83 static GstPadTemplate *srctempl, *sinktempl;
85 static void gst_ladspa_class_init (GstLADSPAClass *klass);
86 static void gst_ladspa_init (GstLADSPA *ladspa);
88 //static GstPadNegotiateReturn gst_ladspa_negotiate_sink_mono (GstPad *pad, GstCaps **caps, gpointer *data);
89 //static GstPadNegotiateReturn gst_ladspa_negotiate_src_mono (GstPad *pad, GstCaps **caps, gpointer *data);
90 //static GstPadNegotiateReturn gst_ladspa_negotiate_src_get_mono (GstPad *pad, GstCaps **caps, gpointer *data);
91 static void gst_ladspa_force_caps(GstLADSPA *ladspa, GstPad *pad);
93 static void gst_ladspa_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec);
94 static void gst_ladspa_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec);
96 static gboolean gst_ladspa_instantiate (GstLADSPA *ladspa);
97 static void gst_ladspa_activate(GstLADSPA *ladspa);
98 static void gst_ladspa_deactivate(GstLADSPA *ladspa);
100 static GstElementStateReturn gst_ladspa_change_state (GstElement *element);
101 static void gst_ladspa_loop (GstElement *element);
102 static void gst_ladspa_chain_inplace_mono (GstPad *pad,GstBuffer *buf);
103 static GstBuffer * gst_ladspa_get_mono(GstPad *pad);
104 static GstBuffer * gst_ladspa_get(GstPad *pad);
106 static GstElementClass *parent_class = NULL;
107 //static guint gst_ladspa_signals[LAST_SIGNAL] = { 0 };
109 static GstPlugin *ladspa_plugin;
110 static GHashTable *ladspa_descriptors;
113 gst_ladspa_class_init (GstLADSPAClass *klass)
115 GObjectClass *gobject_class;
116 GstElementClass *gstelement_class;
117 LADSPA_Descriptor *desc;
118 gint i,current_portnum,sinkcount,srccount,controlcount;
120 gint argtype,argperms;
121 GParamSpec *paramspec = NULL;
122 gchar *argname, *tempstr;
124 gobject_class = (GObjectClass*)klass;
125 gstelement_class = (GstElementClass*)klass;
127 gobject_class->set_property = gst_ladspa_set_property;
128 gobject_class->get_property = gst_ladspa_get_property;
130 gstelement_class->change_state = gst_ladspa_change_state;
132 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_LOOP_BASED,
133 g_param_spec_boolean("loop-based","loop-based","loop-based",
134 FALSE,G_PARAM_READWRITE));
136 // look up and store the ladspa descriptor
137 klass->descriptor = g_hash_table_lookup(ladspa_descriptors,GINT_TO_POINTER(G_TYPE_FROM_CLASS(klass)));
138 desc = klass->descriptor;
140 klass->numports = desc->PortCount;
142 klass->numsinkpads = 0;
143 klass->numsrcpads = 0;
144 klass->numcontrols = 0;
146 // walk through the ports, count the input, output and control ports
147 for (i=0;i<desc->PortCount;i++) {
148 if (LADSPA_IS_PORT_AUDIO(desc->PortDescriptors[i]) &&
149 LADSPA_IS_PORT_INPUT(desc->PortDescriptors[i])){
150 klass->numsinkpads++;
153 if (LADSPA_IS_PORT_AUDIO(desc->PortDescriptors[i]) &&
154 LADSPA_IS_PORT_OUTPUT(desc->PortDescriptors[i])){
158 if (LADSPA_IS_PORT_CONTROL(desc->PortDescriptors[i]) &&
159 LADSPA_IS_PORT_INPUT(desc->PortDescriptors[i])){
160 klass->numcontrols++;
164 klass->srcpad_portnums = g_new0(gint,klass->numsrcpads);
165 klass->sinkpad_portnums = g_new0(gint,klass->numsinkpads);
166 klass->control_portnums = g_new0(gint,klass->numcontrols);
171 // walk through the ports, note the portnums for srcpads, sinkpads and control params
172 for (i=0;i<desc->PortCount;i++) {
173 if (LADSPA_IS_PORT_AUDIO(desc->PortDescriptors[i]) &&
174 LADSPA_IS_PORT_INPUT(desc->PortDescriptors[i])){
175 //g_print("input port %d\n", i);
176 klass->sinkpad_portnums[sinkcount++] = i;
179 if (LADSPA_IS_PORT_AUDIO(desc->PortDescriptors[i]) &&
180 LADSPA_IS_PORT_OUTPUT(desc->PortDescriptors[i])){
181 //g_print("output port %d\n", i);
182 klass->srcpad_portnums[srccount++] = i;
185 if (LADSPA_IS_PORT_CONTROL(desc->PortDescriptors[i]) &&
186 LADSPA_IS_PORT_INPUT(desc->PortDescriptors[i])){
187 //g_print("control port %d\n", i);
188 klass->control_portnums[controlcount++] = i;
192 // no sink pads - we'll use get mode and add params for samplerate and buffersize
193 if (klass->numsinkpads == 0 && klass->numsrcpads > 0){
194 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SAMPLERATE,
195 g_param_spec_int("samplerate","samplerate","samplerate",
196 0,G_MAXINT,44100,G_PARAM_READWRITE));
197 g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_BUFFERSIZE,
198 g_param_spec_int("buffersize","buffersize","buffersize",
199 0,G_MAXINT,64,G_PARAM_READWRITE));
203 // now build the contorl info from the control ports
204 klass->control_info = g_new0(ladspa_control_info,klass->numcontrols);
206 for (i=0;i<klass->numcontrols;i++) {
208 current_portnum = klass->control_portnums[i];
210 // short name for hint descriptor
211 hintdesc = desc->PortRangeHints[current_portnum].HintDescriptor;
213 // get the various bits
214 if (LADSPA_IS_HINT_TOGGLED(hintdesc))
215 klass->control_info[i].toggled = TRUE;
216 if (LADSPA_IS_HINT_LOGARITHMIC(hintdesc))
217 klass->control_info[i].logarithmic = TRUE;
218 if (LADSPA_IS_HINT_INTEGER(hintdesc))
219 klass->control_info[i].integer = TRUE;
221 // figure out the argument details
222 if (klass->control_info[i].toggled) argtype = G_TYPE_BOOLEAN;
223 else if (klass->control_info[i].integer) argtype = G_TYPE_INT;
224 else argtype = G_TYPE_FLOAT;
227 if (LADSPA_IS_HINT_BOUNDED_BELOW(hintdesc)) {
228 klass->control_info[i].lower = TRUE;
229 klass->control_info[i].lowerbound =
230 desc->PortRangeHints[current_portnum].LowerBound;
232 if (argtype==G_TYPE_INT) klass->control_info[i].lowerbound = (gfloat)G_MININT;
233 if (argtype==G_TYPE_FLOAT) klass->control_info[i].lowerbound = G_MINFLOAT;
236 if (LADSPA_IS_HINT_BOUNDED_ABOVE(hintdesc)) {
237 klass->control_info[i].upper = TRUE;
238 klass->control_info[i].upperbound =
239 desc->PortRangeHints[current_portnum].UpperBound;
240 if (LADSPA_IS_HINT_SAMPLE_RATE(hintdesc))
241 klass->control_info[i].samplerate = TRUE;
243 if (argtype==G_TYPE_INT) klass->control_info[i].upperbound = (gfloat)G_MAXINT;
244 if (argtype==G_TYPE_FLOAT) klass->control_info[i].upperbound = G_MAXFLOAT;
247 if (LADSPA_IS_PORT_INPUT(desc->PortDescriptors[current_portnum])) {
248 argperms = G_PARAM_READWRITE;
249 klass->control_info[i].writable = TRUE;
251 argperms = G_PARAM_READABLE;
252 klass->control_info[i].writable = FALSE;
255 klass->control_info[i].name = g_strdup(desc->PortNames[current_portnum]);
256 argname = g_strdup(klass->control_info[i].name);
257 /* this is the same thing that param_spec_* will do */
258 g_strcanon (argname, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-", '-');
259 /* satisfy glib2 (argname[0] must be [A-Za-z]) */
260 if (!((argname[0] >= 'a' && argname[0] <= 'z') || (argname[0] >= 'A' && argname[0] <= 'Z'))) {
262 argname = g_strconcat("param-", argname, NULL);
266 /* check for duplicate property names */
267 if (g_object_class_find_property(G_OBJECT_CLASS(klass), argname) != NULL){
269 gchar *numargname = g_strdup_printf("%s_%d",argname,numarg++);
270 while (g_object_class_find_property(G_OBJECT_CLASS(klass), numargname) != NULL){
272 numargname = g_strdup_printf("%s_%d",argname,numarg++);
274 argname = numargname;
277 g_print("adding arg %s from %s\n",argname, klass->control_info[i].name);
279 if (argtype==G_TYPE_BOOLEAN){
280 paramspec = g_param_spec_boolean(argname,argname,argname, FALSE, argperms);
281 } else if (argtype==G_TYPE_INT){
282 paramspec = g_param_spec_int(argname,argname,argname,
283 (gint)klass->control_info[i].lowerbound, (gint)klass->control_info[i].upperbound, 0, argperms);
285 paramspec = g_param_spec_float(argname,argname,argname,
286 klass->control_info[i].lowerbound, klass->control_info[i].upperbound,
287 (klass->control_info[i].lowerbound + klass->control_info[i].upperbound) / 2.0f, argperms);
290 g_object_class_install_property(G_OBJECT_CLASS(klass), i+ARG_LAST, paramspec);
295 gst_ladspa_init (GstLADSPA *ladspa)
297 GstLADSPAClass *oclass = (GstLADSPAClass*)(G_OBJECT_GET_CLASS(ladspa));
299 LADSPA_Descriptor *desc;
300 gint i,sinkcount,srccount,controlcount;
302 desc = oclass->descriptor;
303 ladspa->descriptor = oclass->descriptor;
305 // allocate the various arrays
306 ladspa->srcpads = g_new0(GstPad*,oclass->numsrcpads);
307 ladspa->sinkpads = g_new0(GstPad*,oclass->numsinkpads);
308 ladspa->controls = g_new(gfloat,oclass->numcontrols);
310 // walk through the ports and add all the pads
314 for (i=0;i<desc->PortCount;i++) {
315 if (LADSPA_IS_PORT_AUDIO(desc->PortDescriptors[i]) &&
316 LADSPA_IS_PORT_INPUT(desc->PortDescriptors[i])) {
317 ladspa->sinkpads[sinkcount] = gst_pad_new_from_template
318 (sinktempl, (gchar *)desc->PortNames[i]);
319 gst_element_add_pad(GST_ELEMENT(ladspa),ladspa->sinkpads[sinkcount]);
322 if (LADSPA_IS_PORT_AUDIO(desc->PortDescriptors[i]) &&
323 LADSPA_IS_PORT_OUTPUT(desc->PortDescriptors[i])) {
324 ladspa->srcpads[srccount] = gst_pad_new_from_template
325 (srctempl, (gchar *)desc->PortNames[i]);
326 gst_element_add_pad(GST_ELEMENT(ladspa),ladspa->srcpads[srccount]);
329 if (LADSPA_IS_PORT_CONTROL(desc->PortDescriptors[i]) &&
330 LADSPA_IS_PORT_INPUT(desc->PortDescriptors[i])) {
332 // use the lowerbound as the default value if it exists
333 if (oclass->control_info[controlcount].lower){
334 ladspa->controls[controlcount]=oclass->control_info[controlcount].lowerbound;
336 ladspa->controls[controlcount] = 0.0;
342 ladspa->samplerate = 0;
343 ladspa->buffersize = 0;
344 ladspa->newcaps = FALSE;
345 ladspa->activated = FALSE;
348 if (sinkcount==1 && srccount==1){
349 //g_print("inplace mono chain mode\n");
350 //gst_pad_set_negotiate_function (ladspa->sinkpads[0], gst_ladspa_negotiate_sink_mono);
351 gst_pad_set_chain_function(ladspa->sinkpads[0],gst_ladspa_chain_inplace_mono);
352 //gst_pad_set_negotiate_function (ladspa->srcpads[0], gst_ladspa_negotiate_src_mono);
355 // mono get (no sink pads)
356 if (sinkcount==0 && srccount == 1){
357 //g_print("get mode\n");
358 ladspa->newcaps = TRUE;
359 ladspa->samplerate = 44100;
360 ladspa->buffersize = 64;
361 gst_pad_set_get_function(ladspa->srcpads[0],gst_ladspa_get_mono);
362 //gst_pad_set_negotiate_function (ladspa->srcpads[0], gst_ladspa_negotiate_src_get_mono);
363 gst_ladspa_instantiate(ladspa);
367 if (sinkcount==0 && srccount > 1){
368 //g_print("multi get mode\n");
369 ladspa->newcaps = TRUE;
370 ladspa->samplerate = 44100;
371 ladspa->buffersize = 64;
372 gst_pad_set_get_function(ladspa->srcpads[0],gst_ladspa_get);
373 //gst_pad_set_negotiate_function (ladspa->srcpads[0], gst_ladspa_negotiate_src_get_mono);
374 gst_ladspa_instantiate(ladspa);
375 ladspa->buffers = g_new0(GstBuffer*,oclass->numsrcpads);
380 static GstPadNegotiateReturn
381 gst_ladspa_negotiate_src_mono (GstPad *pad, GstCaps **caps, gpointer *data)
383 GstLADSPA *ladspa = (GstLADSPA*)GST_OBJECT_PARENT (pad);
385 // have to instantiate ladspa plugin when samplerate changes (groan)
386 if (ladspa->samplerate != gst_caps_get_int (*caps, "rate")){
387 ladspa->samplerate = gst_caps_get_int (*caps, "rate");
388 if (!gst_ladspa_instantiate(ladspa)) return GST_PAD_NEGOTIATE_FAIL;
390 return gst_pad_negotiate_proxy (pad, ladspa->sinkpads[0], caps);
393 static GstPadNegotiateReturn
394 gst_ladspa_negotiate_sink_mono (GstPad *pad, GstCaps **caps, gpointer *data)
396 GstLADSPA *ladspa = (GstLADSPA*)GST_OBJECT_PARENT (pad);
398 // have to instantiate ladspa plugin when samplerate changes (groan)
399 if (ladspa->samplerate != gst_caps_get_int (*caps, "rate")){
400 ladspa->samplerate = gst_caps_get_int (*caps, "rate");
401 if (!gst_ladspa_instantiate(ladspa)) return GST_PAD_NEGOTIATE_FAIL;
403 return gst_pad_negotiate_proxy (pad, ladspa->srcpads[0], caps);
406 static GstPadNegotiateReturn
407 gst_ladspa_negotiate_src_get_mono (GstPad *pad, GstCaps **caps, gpointer *data)
410 //g_print("gst_ladspa_negotiate_src_get_mono\n");
412 g_return_val_if_fail (pad != NULL, GST_PAD_NEGOTIATE_FAIL);
413 ladspa = (GstLADSPA*)GST_OBJECT_PARENT (pad);
414 ladspa->samplerate = gst_caps_get_int (*caps, "rate");
415 if (!gst_ladspa_instantiate(ladspa)) return GST_PAD_NEGOTIATE_FAIL;
416 return GST_PAD_NEGOTIATE_AGREE;
418 return GST_PAD_NEGOTIATE_FAIL;
423 gst_ladspa_force_caps(GstLADSPA *ladspa, GstPad *pad) {
425 // g_print("forcing caps\n");
426 gst_pad_try_set_caps (pad, gst_caps_new (
430 "format", GST_PROPS_STRING ("float"),
431 "layout", GST_PROPS_STRING ("gfloat"),
432 "intercept", GST_PROPS_FLOAT(0.0),
433 "slope", GST_PROPS_FLOAT(1.0),
434 "rate", GST_PROPS_INT (ladspa->samplerate),
435 "channels", GST_PROPS_INT (1),
439 ladspa->newcaps=FALSE;
443 gst_ladspa_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
445 GstLADSPA *ladspa = (GstLADSPA*)object;
446 gint cid = prop_id - ARG_LAST;
447 GstLADSPAClass *oclass;
448 ladspa_control_info *control_info;
451 // these are only registered in get mode
454 ladspa->samplerate = g_value_get_int (value);
455 ladspa->newcaps=TRUE;
458 ladspa->buffersize = g_value_get_int (value);
462 // is it a ladspa plugin arg?
466 if (id == ARG_LOOP_BASED) {
467 // we can only do this in NULL state
468 g_return_if_fail (GST_STATE(object) != GST_STATE_NULL);
469 ladspa->loopbased = g_value_get_boolean (value);
470 if (ladspa->loopbased) {
471 gst_element_set_loop_function (GST_ELEMENT (ladspa), gst_ladspa_loop);
473 gst_element_set_loop_function (GST_ELEMENT (ladspa), NULL);
478 oclass = (GstLADSPAClass*)(G_OBJECT_GET_CLASS (object));
480 // verify it exists and is a control (not a port)
481 g_return_if_fail(cid < oclass->numcontrols);
483 control_info = &(oclass->control_info[cid]);
484 g_return_if_fail (control_info->name != NULL);
486 // check to see if it's writable
487 g_return_if_fail (control_info->writable);
489 // g_print("set arg %s to %f\n",control_info->name,ladspa->controls[cid]);
491 // now see what type it is
492 if (control_info->toggled) {
493 if (g_value_get_boolean (value))
494 ladspa->controls[cid] = 1.0;
496 ladspa->controls[cid] = 0.0;
497 } else if (control_info->integer) {
498 val = (gfloat)g_value_get_int (value);
499 ladspa->controls[cid] = val;
501 val = g_value_get_float (value);
502 ladspa->controls[cid] = val;
507 gst_ladspa_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
509 GstLADSPA *ladspa = (GstLADSPA*)object;
510 gint cid = prop_id - ARG_LAST;
511 GstLADSPAClass *oclass = (GstLADSPAClass*)(G_OBJECT_GET_CLASS (object));
512 ladspa_control_info *control_info;
514 // these are only registered in get mode
517 g_value_set_int (value, ladspa->samplerate);
520 g_value_set_int (value, ladspa->buffersize);
525 // verify it exists and is a control (not a port)
526 if (cid >= oclass->numcontrols) return;
527 control_info = &(oclass->control_info[cid]);
528 if (control_info->name == NULL) return;
530 //g_print("got arg %s as %f\n",control_info->name,ladspa->controls[cid]);
532 // now see what type it is
533 if (control_info->toggled) {
534 if (ladspa->controls[cid] == 1.0)
535 g_value_set_boolean (value, TRUE);
537 g_value_set_boolean (value, FALSE);
538 } else if (control_info->integer) {
539 g_value_set_int (value, (gint)ladspa->controls[cid]);
541 g_value_set_float (value, ladspa->controls[cid]);
546 gst_ladspa_instantiate (GstLADSPA *ladspa)
548 LADSPA_Descriptor *desc;
550 GstLADSPAClass *oclass = (GstLADSPAClass*)(G_OBJECT_GET_CLASS (ladspa));
551 gboolean was_activated;
553 desc = ladspa->descriptor;
555 // check for old handle
556 was_activated = ladspa->activated;
557 if (ladspa->handle != NULL){
558 gst_ladspa_deactivate(ladspa);
559 desc->cleanup(ladspa->handle);
562 // instantiate the plugin
563 ladspa->handle = desc->instantiate(desc,ladspa->samplerate);
564 g_return_val_if_fail (ladspa->handle != NULL, FALSE);
566 // walk through the ports and add all the arguments
567 for (i=0;i<oclass->numcontrols;i++) {
568 // connect the argument to the plugin
569 //g_print("added control port %d\n", oclass->control_portnums[i]);
570 desc->connect_port(ladspa->handle,
571 oclass->control_portnums[i],
572 &(ladspa->controls[i]));
575 // reactivate if it was activated before the reinstantiation
577 gst_ladspa_activate(ladspa);
582 static GstElementStateReturn
583 gst_ladspa_change_state (GstElement *element)
585 LADSPA_Descriptor *desc;
586 GstLADSPA *ladspa = (GstLADSPA*)element;
587 // GstLADSPAClass *oclass = (GstLADSPAClass*)(G_OBJECT(ladspa)->klass);
588 desc = ladspa->descriptor;
590 //g_print("changing state\n");
591 switch (GST_STATE_TRANSITION (element)) {
592 case GST_STATE_NULL_TO_READY:
593 gst_ladspa_activate(ladspa);
595 case GST_STATE_READY_TO_NULL:
596 gst_ladspa_deactivate(ladspa);
602 if (GST_ELEMENT_CLASS (parent_class)->change_state)
603 return GST_ELEMENT_CLASS (parent_class)->change_state (element);
605 return GST_STATE_SUCCESS;
609 gst_ladspa_activate(GstLADSPA *ladspa)
611 LADSPA_Descriptor *desc;
612 desc = ladspa->descriptor;
614 if (ladspa->activated){
615 gst_ladspa_deactivate(ladspa);
618 //g_print("activating\n");
620 // activate the plugin (function might be null)
621 if (desc->activate != NULL){
622 desc->activate(ladspa->handle);
625 ladspa->activated = TRUE;
629 gst_ladspa_deactivate(GstLADSPA *ladspa)
631 LADSPA_Descriptor *desc;
632 desc = ladspa->descriptor;
634 //g_print("deactivating\n");
636 // deactivate the plugin (function might be null)
637 if (ladspa->activated && desc->deactivate != NULL){
638 desc->deactivate(ladspa->handle);
640 ladspa->activated = FALSE;
644 gst_ladspa_loop (GstElement *element)
647 GstLADSPA *ladspa = (GstLADSPA *)element;
648 GstLADSPAClass *oclass = (GstLADSPAClass*)(G_OBJECT_GET_CLASS (ladspa));
649 LADSPA_Descriptor *desc;
651 desc = ladspa->descriptor;
652 printf("looping something\n");
654 // first get all the necessary data from the input ports
655 for (i=0;i<oclass->numsinkpads;i++){
656 ladspa->buffers[i] = gst_pad_pull(ladspa->sinkpads[i]);
657 printf("pulling buffer %d\n", i);
660 for (i=0;i<oclass->numsinkpads;i++) {
661 // desc->connect_port(ladspa->handle,i,&(ladspa->controls[i]));
664 for (i=0;i<oclass->numsrcpads && i<oclass->numsinkpads;i++){
665 printf("pushing buffer %d\n", i);
666 gst_pad_push (ladspa->srcpads[i], ladspa->buffers[i]);
667 ladspa->buffers[i] = NULL;
672 gst_ladspa_chain_inplace_mono (GstPad *pad,GstBuffer *buf)
674 LADSPA_Descriptor *desc;
676 unsigned long num_samples;
679 GstLADSPAClass *oclass;
681 g_return_if_fail(pad != NULL);
682 g_return_if_fail(GST_IS_PAD(pad));
683 g_return_if_fail(buf != NULL);
685 ladspa = (GstLADSPA *)gst_pad_get_parent (pad);
686 g_return_if_fail(ladspa != NULL);
688 // this might happen if caps nego hasn't happened
689 g_return_if_fail(ladspa->handle != NULL);
691 oclass = (GstLADSPAClass*)(G_OBJECT_GET_CLASS (ladspa));
692 data=(LADSPA_Data*)GST_BUFFER_DATA(buf);
693 num_samples = GST_BUFFER_SIZE(buf) / sizeof(gfloat);
695 desc = ladspa->descriptor;
697 desc->connect_port(ladspa->handle,oclass->sinkpad_portnums[0],data);
698 desc->connect_port(ladspa->handle,oclass->srcpad_portnums[0],data);
700 desc->run(ladspa->handle,num_samples);
702 desc->connect_port(ladspa->handle,oclass->sinkpad_portnums[0],NULL);
703 desc->connect_port(ladspa->handle,oclass->srcpad_portnums[0],NULL);
705 gst_pad_push (ladspa->srcpads[0], buf);
709 gst_ladspa_get_mono(GstPad *pad)
711 LADSPA_Descriptor *desc;
715 GstLADSPAClass *oclass;
718 g_return_val_if_fail(pad != NULL, NULL);
719 g_return_val_if_fail(GST_IS_PAD(pad), NULL);
721 ladspa = (GstLADSPA *)gst_pad_get_parent (pad);
722 g_return_val_if_fail(ladspa != NULL, NULL);
724 // this might happen if caps nego hasn't happened
725 g_return_val_if_fail(ladspa->handle != NULL, NULL);
727 oclass = (GstLADSPAClass*)(G_OBJECT_GET_CLASS(ladspa));
729 if (ladspa->newcaps) {
730 gst_ladspa_force_caps(ladspa, ladspa->srcpads[0]);
733 buf = gst_buffer_new();
734 g_return_val_if_fail (buf, NULL);
735 data = g_new(LADSPA_Data, ladspa->buffersize);
736 GST_BUFFER_DATA(buf) = (gpointer) data;
737 GST_BUFFER_SIZE(buf) = sizeof(LADSPA_Data) * ladspa->buffersize;
738 GST_BUFFER_TIMESTAMP(buf) = ladspa->timestamp;
740 desc = ladspa->descriptor;
741 desc->connect_port(ladspa->handle,oclass->srcpad_portnums[0],data);
742 desc->run(ladspa->handle,(unsigned long)ladspa->buffersize);
743 desc->connect_port(ladspa->handle,oclass->srcpad_portnums[0],NULL);
749 gst_ladspa_get(GstPad *pad)
751 LADSPA_Descriptor *desc;
755 GstLADSPAClass *oclass;
758 g_return_val_if_fail(pad != NULL, NULL);
759 g_return_val_if_fail(GST_IS_PAD(pad), NULL);
761 ladspa = (GstLADSPA *)gst_pad_get_parent (pad);
762 g_return_val_if_fail(ladspa != NULL, NULL);
764 // this might happen if caps nego hasn't happened
765 g_return_val_if_fail(ladspa->handle != NULL, NULL);
767 oclass = (GstLADSPAClass*)(G_OBJECT_GET_CLASS(ladspa));
769 if (ladspa->newcaps) {
770 gst_ladspa_force_caps(ladspa, ladspa->srcpads[0]);
773 buf = gst_buffer_new();
774 g_return_val_if_fail (buf, NULL);
775 data = g_new(LADSPA_Data, ladspa->buffersize);
776 GST_BUFFER_DATA(buf) = (gpointer) data;
777 GST_BUFFER_SIZE(buf) = sizeof(LADSPA_Data) * ladspa->buffersize;
778 GST_BUFFER_TIMESTAMP(buf) = ladspa->timestamp;
779 ladspa->timestamp+= ladspa->buffersize * ladspa->samplerate * 10^9;
781 desc = ladspa->descriptor;
782 desc->connect_port(ladspa->handle,oclass->srcpad_portnums[0],data);
783 desc->run(ladspa->handle,(unsigned long)ladspa->buffersize);
784 desc->connect_port(ladspa->handle,oclass->srcpad_portnums[0],NULL);
790 ladspa_describe_plugin(const char *pcFullFilename,
791 void *pvPluginHandle,
792 LADSPA_Descriptor_Function pfDescriptorFunction)
794 const LADSPA_Descriptor *desc;
797 GstElementDetails *details;
798 GTypeInfo typeinfo = {
799 sizeof(GstLADSPAClass), NULL,
801 (GClassInitFunc)gst_ladspa_class_init,
806 (GInstanceInitFunc)gst_ladspa_init,
809 GstElementFactory *factory;
811 // walk through all the plugins in this pluginlibrary
813 while ((desc = pfDescriptorFunction(i++))) {
816 // construct the type
817 type_name = g_strdup_printf("ladspa_%s",desc->Label);
818 g_strcanon (type_name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-_+", '-');
819 // if it's already registered, drop it
820 if (g_type_from_name(type_name)) {
824 // create the type now
825 type = g_type_register_static(GST_TYPE_ELEMENT, type_name , &typeinfo, 0);
827 // construct the element details struct
828 details = g_new0(GstElementDetails,1);
829 details->longname = g_strdup(desc->Name);
830 details->klass = "Filter/LADSPA";
831 details->description = details->longname;
832 details->version = g_strdup_printf("%ld",desc->UniqueID);
833 details->author = g_strdup(desc->Maker);
834 details->copyright = g_strdup(desc->Copyright);
836 // register the plugin with gstreamer
837 factory = gst_elementfactory_new(type_name,type,details);
838 g_return_if_fail(factory != NULL);
839 gst_plugin_add_feature (ladspa_plugin, GST_PLUGIN_FEATURE (factory));
841 // add this plugin to the hash
842 g_hash_table_insert(ladspa_descriptors,
843 GINT_TO_POINTER(type),
847 // only add sink padtemplate if there are sinkpads
848 for (j=0;j<desc->PortCount;j++) {
849 if (LADSPA_IS_PORT_AUDIO(desc->PortDescriptors[j]) &&
850 LADSPA_IS_PORT_INPUT(desc->PortDescriptors[j])) {
851 sinktempl = ladspa_sink_factory();
852 gst_elementfactory_add_padtemplate (factory, sinktempl);
857 srctempl = ladspa_src_factory();
858 gst_elementfactory_add_padtemplate (factory, srctempl);
864 plugin_init (GModule *module, GstPlugin *plugin)
867 ladspa_descriptors = g_hash_table_new(NULL,NULL);
868 parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
870 ladspa_plugin = plugin;
872 LADSPAPluginSearch(ladspa_describe_plugin);
877 GstPluginDesc plugin_desc = {