summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Sauer <ensonic@users.sf.net>2013-05-27 23:07:16 +0200
committerStefan Sauer <ensonic@users.sf.net>2013-05-28 10:27:17 +0200
commitf65bdac49bf60de98b608bcb0851e34533c80352 (patch)
tree66677528bafc02d0166ee6c84433202f585a9cc7
parent407f3e1856e3d7e79c9d743e4ae92538b6dad290 (diff)
downloadgstreamer-plugins-bad-f65bdac49bf60de98b608bcb0851e34533c80352.tar.gz
ladspa: use the registry cache for plugin details
Split the introspection and registration part. This way we only need to open all plugins when updating the registry. When reading the registry we can register the elements entierly from the cache.
-rw-r--r--ext/ladspa/gstladspa.c144
-rw-r--r--ext/ladspa/gstladspa.h3
-rw-r--r--ext/ladspa/gstladspafilter.c25
-rw-r--r--ext/ladspa/gstladspafilter.h3
-rw-r--r--ext/ladspa/gstladspasink.c21
-rw-r--r--ext/ladspa/gstladspasink.h3
-rw-r--r--ext/ladspa/gstladspasource.c39
-rw-r--r--ext/ladspa/gstladspasource.h3
-rw-r--r--ext/ladspa/gstladspautils.c135
-rw-r--r--ext/ladspa/gstladspautils.h16
10 files changed, 212 insertions, 180 deletions
diff --git a/ext/ladspa/gstladspa.c b/ext/ladspa/gstladspa.c
index 0acb245f6..f412ce35f 100644
--- a/ext/ladspa/gstladspa.c
+++ b/ext/ladspa/gstladspa.c
@@ -130,7 +130,6 @@
#include "gstladspasink.h"
#include <gst/gst-i18n-plugin.h>
-#include <gmodule.h>
#include <string.h>
#include <ladspa.h>
#ifdef HAVE_LRDF
@@ -153,29 +152,107 @@ GST_DEBUG_CATEGORY (ladspa_debug);
"/usr/local/lib/ladspa" G_SEARCHPATH_SEPARATOR_S \
LIBDIR "/ladspa"
-GQuark descriptor_quark = 0;
+GstStructure *ladspa_meta_all = NULL;
static void
-ladspa_describe_plugin (GstPlugin * plugin,
- const gchar * filename, LADSPA_Descriptor_Function descriptor_function)
+ladspa_plugin_register_element (GstPlugin * plugin, GstStructure * ladspa_meta)
+{
+ guint audio_in, audio_out;
+
+ gst_structure_get_uint (ladspa_meta, "audio-in", &audio_in);
+ gst_structure_get_uint (ladspa_meta, "audio-out", &audio_out);
+
+ if (audio_in == 0) {
+ ladspa_register_source_element (plugin, ladspa_meta);
+ } else if (audio_out == 0) {
+ ladspa_register_sink_element (plugin, ladspa_meta);
+ } else {
+ ladspa_register_filter_element (plugin, ladspa_meta);
+ }
+}
+
+static void
+ladspa_count_ports (const LADSPA_Descriptor * descriptor,
+ guint * audio_in, guint * audio_out, guint * control_in,
+ guint * control_out)
+{
+ guint i;
+
+ *audio_in = *audio_out = *control_in = *control_out = 0;
+
+ for (i = 0; i < descriptor->PortCount; i++) {
+ LADSPA_PortDescriptor p = descriptor->PortDescriptors[i];
+
+ if (LADSPA_IS_PORT_AUDIO (p)) {
+ if (LADSPA_IS_PORT_INPUT (p))
+ (*audio_in)++;
+ else
+ (*audio_out)++;
+ } else if (LADSPA_IS_PORT_CONTROL (p)) {
+ if (LADSPA_IS_PORT_INPUT (p))
+ (*control_in)++;
+ else
+ (*control_out)++;
+ }
+ }
+}
+
+static void
+ladspa_describe_plugin (const gchar * file_name, const gchar * entry_name,
+ LADSPA_Descriptor_Function descriptor_function)
{
const LADSPA_Descriptor *desc;
guint i;
/* walk through all the plugins in this plugin library */
for (i = 0; (desc = descriptor_function (i)); i++) {
+ GstStructure *ladspa_meta = NULL;
+ GValue value = { 0, };
+ gchar *tmp;
+ gchar *type_name;
guint audio_in, audio_out, control_in, control_out;
/* count ports of this plugin */
ladspa_count_ports (desc, &audio_in, &audio_out, &control_in, &control_out);
- /* categorize and register it */
- if (audio_in == 0)
- ladspa_describe_source_plugin (plugin, filename, desc);
- else if (audio_out == 0)
- ladspa_describe_sink_plugin (plugin, filename, desc);
- else
- ladspa_describe_filter_plugin (plugin, filename, desc);
+ /* categorize */
+ if (audio_in == 0 && audio_out == 0) {
+ GST_WARNING ("Skipping control only element (%s:%lu/%s)",
+ entry_name, desc->UniqueID, desc->Label);
+ continue;
+ } else if (audio_in == 0) {
+ tmp = g_strdup_printf ("ladspasrc-%s-%s", entry_name, desc->Label);
+ } else if (audio_out == 0) {
+ tmp = g_strdup_printf ("ladspasink-%s-%s", entry_name, desc->Label);
+ } else {
+ tmp = g_strdup_printf ("ladspa-%s-%s", entry_name, desc->Label);
+ }
+ type_name = g_ascii_strdown (tmp, -1);
+ g_free (tmp);
+ g_strcanon (type_name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-+", '-');
+
+ /* check if the type is already registered */
+ if (g_type_from_name (type_name)) {
+ GST_WARNING ("Plugin identifier collision for %s (%s:%lu/%s)", type_name,
+ entry_name, desc->UniqueID, desc->Label);
+ g_free (type_name);
+ continue;
+ }
+
+ ladspa_meta = gst_structure_new_empty ("ladspa");
+ gst_structure_set (ladspa_meta,
+ "plugin-filename", G_TYPE_STRING, file_name,
+ "element-ix", G_TYPE_UINT, i,
+ "element-type-name", G_TYPE_STRING, type_name,
+ "audio-in", G_TYPE_UINT, audio_in,
+ "audio-out", G_TYPE_UINT, audio_out,
+ "control-in", G_TYPE_UINT, control_in,
+ "control-out", G_TYPE_UINT, control_out, NULL);
+
+ g_value_init (&value, GST_TYPE_STRUCTURE);
+ g_value_set_boxed (&value, ladspa_meta);
+ gst_structure_set_value (ladspa_meta_all, type_name, &value);
+ g_value_unset (&value);
}
}
@@ -235,7 +312,7 @@ ladspa_plugin_directory_search (GstPlugin * ladspa_plugin, const char *dir_name)
(gpointer *) & descriptor_function)) {
/* we've found a ladspa_descriptor function, now introspect it. */
GST_INFO ("describe %s", file_name);
- ladspa_describe_plugin (ladspa_plugin, entry_name, descriptor_function);
+ ladspa_describe_plugin (file_name, entry_name, descriptor_function);
ok = TRUE;
} else {
/* it was a library, but not a LADSPA one. Unload it. */
@@ -322,6 +399,9 @@ ladspa_plugin_path_search (GstPlugin * plugin)
static gboolean
plugin_init (GstPlugin * plugin)
{
+ gboolean res = FALSE;
+ gint n = 0;
+
#ifdef ENABLE_NLS
GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE,
LOCALEDIR);
@@ -331,8 +411,6 @@ plugin_init (GstPlugin * plugin)
GST_DEBUG_CATEGORY_INIT (ladspa_debug, "ladspa", 0, "LADSPA plugins");
- descriptor_quark = g_quark_from_static_string ("ladspa-descriptor");
-
gst_plugin_add_dependency_simple (plugin,
"LADSPA_PATH",
GST_LADSPA_DEFAULT_PATH, NULL, GST_PLUGIN_DEPENDENCY_FLAG_NONE);
@@ -341,8 +419,44 @@ plugin_init (GstPlugin * plugin)
lrdf_init ();
#endif
- if (!ladspa_plugin_path_search (plugin))
+ ladspa_meta_all = (GstStructure *) gst_plugin_get_cache_data (plugin);
+ if (ladspa_meta_all) {
+ n = gst_structure_n_fields (ladspa_meta_all);
+ }
+ GST_INFO ("%d entries in cache", n);
+ if (!n) {
+ ladspa_meta_all = gst_structure_new_empty ("ladspa");
+ res = ladspa_plugin_path_search (plugin);
+ if (res) {
+ n = gst_structure_n_fields (ladspa_meta_all);
+ GST_INFO ("%d entries after scanning", n);
+ gst_plugin_set_cache_data (plugin, ladspa_meta_all);
+ }
+ } else {
+ res = TRUE;
+ }
+
+ if (n) {
+ gint i;
+ const gchar *name;
+ const GValue *value;
+
+ GST_INFO ("register types");
+
+ for (i = 0; i < n; i++) {
+ name = gst_structure_nth_field_name (ladspa_meta_all, i);
+ value = gst_structure_get_value (ladspa_meta_all, name);
+ if (G_VALUE_TYPE (value) == GST_TYPE_STRUCTURE) {
+ GstStructure *ladspa_meta = g_value_get_boxed (value);
+
+ ladspa_plugin_register_element (plugin, ladspa_meta);
+ }
+ }
+ }
+
+ if (!res) {
GST_WARNING ("no LADSPA plugins found, check LADSPA_PATH");
+ }
/* we don't want to fail, even if there are no elements registered */
return TRUE;
diff --git a/ext/ladspa/gstladspa.h b/ext/ladspa/gstladspa.h
index 727b56cda..f93ab4eb7 100644
--- a/ext/ladspa/gstladspa.h
+++ b/ext/ladspa/gstladspa.h
@@ -1,6 +1,7 @@
/* GStreamer
* Copyright (C) 1999 Erik Walthinsen <omega@cse.ogi.edu>
* Copyright (C) 2013 Juan Manuel Borges Caño <juanmabcmail@gmail.com>
+ * 2013 Stefan Sauer <ensonic@users.sf.net>
*
* gstladspa.h: Header for LADSPA plugin
*
@@ -27,7 +28,7 @@
G_BEGIN_DECLS
-extern GQuark descriptor_quark;
+extern GstStructure *ladspa_meta_all;
G_END_DECLS
diff --git a/ext/ladspa/gstladspafilter.c b/ext/ladspa/gstladspafilter.c
index af64b2118..d1b853b6e 100644
--- a/ext/ladspa/gstladspafilter.c
+++ b/ext/ladspa/gstladspafilter.c
@@ -236,8 +236,8 @@ gst_ladspa_filter_type_init (GstLADSPAFilter * ladspa, LADSPA_Descriptor * desc)
gst_base_transform_set_in_place (base,
ladspa_class->ladspa.count.audio.in ==
ladspa_class->ladspa.count.audio.out
- && !LADSPA_IS_INPLACE_BROKEN (ladspa_class->ladspa.
- descriptor->Properties));
+ && !LADSPA_IS_INPLACE_BROKEN (ladspa_class->ladspa.descriptor->
+ Properties));
}
@@ -270,16 +270,11 @@ gst_ladspa_filter_type_finalize (GObject * object)
static void
gst_ladspa_filter_type_base_init (GstLADSPAFilterClass * ladspa_class)
{
- GObjectClass *object_class = G_OBJECT_CLASS (ladspa_class);
GstElementClass *elem_class = GST_ELEMENT_CLASS (ladspa_class);
GstAudioFilterClass *audio_class = GST_AUDIO_FILTER_CLASS (ladspa_class);
- LADSPA_Descriptor *desc;
-
- desc =
- g_type_get_qdata (G_OBJECT_CLASS_TYPE (object_class), descriptor_quark);
- g_assert (desc);
- gst_ladspa_class_init (&ladspa_class->ladspa, desc);
+ gst_ladspa_class_init (&ladspa_class->ladspa,
+ G_TYPE_FROM_CLASS (ladspa_class));
gst_ladspa_element_class_set_metadata (&ladspa_class->ladspa, elem_class,
GST_LADSPA_FILTER_CLASS_TAGS);
@@ -345,8 +340,7 @@ gst_ladspa_filter_class_init (GstLADSPAFilterClass * ladspa_class)
* Construct the type.
*/
void
-ladspa_describe_filter_plugin (GstPlugin * plugin,
- const gchar * filename, const LADSPA_Descriptor * desc)
+ladspa_register_filter_element (GstPlugin * plugin, GstStructure * ladspa_meta)
{
GTypeInfo info = {
sizeof (GstLADSPAFilterClass),
@@ -354,16 +348,11 @@ ladspa_describe_filter_plugin (GstPlugin * plugin,
(GBaseFinalizeFunc) gst_ladspa_filter_type_base_finalize,
(GClassInitFunc) gst_ladspa_filter_type_class_init,
NULL,
- desc,
+ NULL,
sizeof (GstLADSPAFilter),
0,
(GInstanceInitFunc) gst_ladspa_filter_type_init,
NULL
};
- gchar *tmp;
-
- tmp = g_strdup_printf ("ladspa-%s-%s", filename, desc->Label);
- ladspa_register_plugin (plugin, GST_TYPE_LADSPA_FILTER, tmp, &info,
- descriptor_quark, filename, desc);
- g_free (tmp);
+ ladspa_register_element (plugin, GST_TYPE_LADSPA_FILTER, &info, ladspa_meta);
}
diff --git a/ext/ladspa/gstladspafilter.h b/ext/ladspa/gstladspafilter.h
index 94c0ddaa5..577330a90 100644
--- a/ext/ladspa/gstladspafilter.h
+++ b/ext/ladspa/gstladspafilter.h
@@ -60,8 +60,7 @@ GType
gst_ladspa_filter_get_type (void);
void
-ladspa_describe_filter_plugin (GstPlugin * plugin,
- const gchar * filename, const LADSPA_Descriptor * desc);
+ladspa_register_filter_element (GstPlugin * plugin, GstStructure *ladspa_meta);
void
gst_my_audio_filter_class_add_pad_templates (GstAudioFilterClass * audio_class,
diff --git a/ext/ladspa/gstladspasink.c b/ext/ladspa/gstladspasink.c
index 620379aac..3cb321c79 100644
--- a/ext/ladspa/gstladspasink.c
+++ b/ext/ladspa/gstladspasink.c
@@ -270,16 +270,11 @@ gst_ladspa_sink_type_finalize (GObject * object)
static void
gst_ladspa_sink_type_base_init (GstLADSPASinkClass * ladspa_class)
{
- GObjectClass *object_class = G_OBJECT_CLASS (ladspa_class);
GstElementClass *elem_class = GST_ELEMENT_CLASS (ladspa_class);
GstBaseSinkClass *base_class = GST_BASE_SINK_CLASS (ladspa_class);
- LADSPA_Descriptor *desc;
-
- desc =
- g_type_get_qdata (G_OBJECT_CLASS_TYPE (object_class), descriptor_quark);
- g_assert (desc);
- gst_ladspa_class_init (&ladspa_class->ladspa, desc);
+ gst_ladspa_class_init (&ladspa_class->ladspa,
+ G_TYPE_FROM_CLASS (ladspa_class));
gst_ladspa_element_class_set_metadata (&ladspa_class->ladspa, elem_class,
GST_LADSPA_SINK_CLASS_TAGS);
@@ -362,8 +357,7 @@ gst_ladspa_sink_class_init (GstLADSPASinkClass * ladspa_class)
* Construct the type.
*/
void
-ladspa_describe_sink_plugin (GstPlugin * plugin,
- const gchar * filename, const LADSPA_Descriptor * desc)
+ladspa_register_sink_element (GstPlugin * plugin, GstStructure * ladspa_meta)
{
GTypeInfo info = {
sizeof (GstLADSPASinkClass),
@@ -371,16 +365,11 @@ ladspa_describe_sink_plugin (GstPlugin * plugin,
(GBaseFinalizeFunc) gst_ladspa_sink_type_base_finalize,
(GClassInitFunc) gst_ladspa_sink_type_class_init,
NULL,
- desc,
+ NULL,
sizeof (GstLADSPASink),
0,
(GInstanceInitFunc) gst_ladspa_sink_type_init,
NULL
};
- gchar *tmp;
-
- tmp = g_strdup_printf ("ladspasink-%s-%s", filename, desc->Label);
- ladspa_register_plugin (plugin, GST_TYPE_LADSPA_SINK, tmp, &info,
- descriptor_quark, filename, desc);
- g_free (tmp);
+ ladspa_register_element (plugin, GST_TYPE_LADSPA_SINK, &info, ladspa_meta);
}
diff --git a/ext/ladspa/gstladspasink.h b/ext/ladspa/gstladspasink.h
index 6bed7f075..f781b481e 100644
--- a/ext/ladspa/gstladspasink.h
+++ b/ext/ladspa/gstladspasink.h
@@ -66,8 +66,7 @@ GType
gst_ladspa_sink_get_type (void);
void
-ladspa_describe_sink_plugin (GstPlugin * plugin,
- const gchar * filename, const LADSPA_Descriptor * desc);
+ladspa_register_sink_element (GstPlugin * plugin, GstStructure *ladspa_meta);
void
gst_my_base_sink_class_add_pad_template (GstBaseSinkClass * base_class,
diff --git a/ext/ladspa/gstladspasource.c b/ext/ladspa/gstladspasource.c
index 202004cdf..943da62ce 100644
--- a/ext/ladspa/gstladspasource.c
+++ b/ext/ladspa/gstladspasource.c
@@ -451,8 +451,7 @@ gst_ladspa_source_type_get_property (GObject * object, guint prop_id,
}
static void
-gst_ladspa_source_type_init (GstLADSPASource * ladspa,
- LADSPA_Descriptor * desc)
+gst_ladspa_source_type_init (GstLADSPASource * ladspa, LADSPA_Descriptor * desc)
{
GstLADSPASourceClass *ladspa_class = GST_LADSPA_SOURCE_GET_CLASS (ladspa);
@@ -500,16 +499,11 @@ gst_ladspa_source_type_finalize (GObject * object)
static void
gst_ladspa_source_type_base_init (GstLADSPASourceClass * ladspa_class)
{
- GObjectClass *object_class = G_OBJECT_CLASS (ladspa_class);
GstElementClass *elem_class = GST_ELEMENT_CLASS (ladspa_class);
GstBaseSrcClass *base_class = GST_BASE_SRC_CLASS (ladspa_class);
- LADSPA_Descriptor *desc;
-
- desc =
- g_type_get_qdata (G_OBJECT_CLASS_TYPE (object_class), descriptor_quark);
- g_assert (desc);
- gst_ladspa_class_init (&ladspa_class->ladspa, desc);
+ gst_ladspa_class_init (&ladspa_class->ladspa,
+ G_TYPE_FROM_CLASS (ladspa_class));
gst_ladspa_element_class_set_metadata (&ladspa_class->ladspa, elem_class,
GST_LADSPA_SOURCE_CLASS_TAGS);
@@ -531,27 +525,22 @@ gst_ladspa_source_type_class_init (GstLADSPASourceClass * ladspa_class,
GObjectClass *object_class = (GObjectClass *) ladspa_class;
GstBaseSrcClass *base_class = (GstBaseSrcClass *) ladspa_class;
- gst_ladspa_source_type_parent_class =
- g_type_class_peek_parent (ladspa_class);
+ gst_ladspa_source_type_parent_class = g_type_class_peek_parent (ladspa_class);
- object_class->dispose =
- GST_DEBUG_FUNCPTR (gst_ladspa_source_type_dispose);
- object_class->finalize =
- GST_DEBUG_FUNCPTR (gst_ladspa_source_type_finalize);
+ object_class->dispose = GST_DEBUG_FUNCPTR (gst_ladspa_source_type_dispose);
+ object_class->finalize = GST_DEBUG_FUNCPTR (gst_ladspa_source_type_finalize);
object_class->set_property =
GST_DEBUG_FUNCPTR (gst_ladspa_source_type_set_property);
object_class->get_property =
GST_DEBUG_FUNCPTR (gst_ladspa_source_type_get_property);
- base_class->set_caps =
- GST_DEBUG_FUNCPTR (gst_ladspa_source_type_set_caps);
+ base_class->set_caps = GST_DEBUG_FUNCPTR (gst_ladspa_source_type_set_caps);
base_class->fixate = GST_DEBUG_FUNCPTR (gst_ladspa_source_type_fixate);
base_class->is_seekable =
GST_DEBUG_FUNCPTR (gst_ladspa_source_type_is_seekable);
base_class->do_seek = GST_DEBUG_FUNCPTR (gst_ladspa_source_type_do_seek);
base_class->query = GST_DEBUG_FUNCPTR (gst_ladspa_source_type_query);
- base_class->get_times =
- GST_DEBUG_FUNCPTR (gst_ladspa_source_type_get_times);
+ base_class->get_times = GST_DEBUG_FUNCPTR (gst_ladspa_source_type_get_times);
base_class->start = GST_DEBUG_FUNCPTR (gst_ladspa_source_type_start);
base_class->stop = GST_DEBUG_FUNCPTR (gst_ladspa_source_type_stop);
base_class->fill = GST_DEBUG_FUNCPTR (gst_ladspa_source_type_fill);
@@ -609,8 +598,7 @@ gst_ladspa_source_class_init (GstLADSPASourceClass * ladspa_class)
* Construct the type.
*/
void
-ladspa_describe_source_plugin (GstPlugin * plugin,
- const gchar * filename, const LADSPA_Descriptor * desc)
+ladspa_register_source_element (GstPlugin * plugin, GstStructure * ladspa_meta)
{
GTypeInfo info = {
sizeof (GstLADSPASourceClass),
@@ -618,16 +606,11 @@ ladspa_describe_source_plugin (GstPlugin * plugin,
(GBaseFinalizeFunc) gst_ladspa_source_type_base_finalize,
(GClassInitFunc) gst_ladspa_source_type_class_init,
NULL,
- desc,
+ NULL,
sizeof (GstLADSPASource),
0,
(GInstanceInitFunc) gst_ladspa_source_type_init,
NULL
};
- gchar *tmp;
-
- tmp = g_strdup_printf ("ladspasrc-%s-%s", filename, desc->Label);
- ladspa_register_plugin (plugin, GST_TYPE_LADSPA_SOURCE, tmp, &info,
- descriptor_quark, filename, desc);
- g_free (tmp);
+ ladspa_register_element (plugin, GST_TYPE_LADSPA_SOURCE, &info, ladspa_meta);
}
diff --git a/ext/ladspa/gstladspasource.h b/ext/ladspa/gstladspasource.h
index 15df9ba8c..ca3a2941c 100644
--- a/ext/ladspa/gstladspasource.h
+++ b/ext/ladspa/gstladspasource.h
@@ -78,8 +78,7 @@ GType
gst_ladspa_source_get_type (void);
void
-ladspa_describe_source_plugin (GstPlugin * plugin,
- const gchar * filename, const LADSPA_Descriptor * desc);
+ladspa_register_source_element (GstPlugin * plugin, GstStructure *ladspa_meta);
void
gst_my_base_source_class_add_pad_template (GstBaseSrcClass * base_class,
diff --git a/ext/ladspa/gstladspautils.c b/ext/ladspa/gstladspautils.c
index 902bc03a7..c358b5ed8 100644
--- a/ext/ladspa/gstladspautils.c
+++ b/ext/ladspa/gstladspautils.c
@@ -2,7 +2,8 @@
* Copyright (C) 1999 Erik Walthinsen <omega@cse.ogi.edu>
* 2001 Steve Baker <stevebaker_org@yahoo.co.uk>
* 2003 Andy Wingo <wingo at pobox.com>
- * Copyright (C) 2013 Juan Manuel Borges Caño <juanmabcmail@gmail.com>
+ * 2013 Juan Manuel Borges Caño <juanmabcmail@gmail.com>
+ * 2013 Stefan Sauer <ensonic@users.sf.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -49,6 +50,7 @@
#include "config.h"
#endif
+#include "gstladspa.h"
#include "gstladspautils.h"
#include "gstladspafilter.h"
#include "gstladspasource.h"
@@ -286,12 +288,10 @@ static gchar *
gst_ladspa_object_class_get_param_name (GstLADSPAClass * ladspa_class,
GObjectClass * object_class, unsigned long portnum)
{
- LADSPA_Descriptor *desc;
+ const LADSPA_Descriptor *desc = ladspa_class->descriptor;
gchar *name, **namev, **v, *tmp;
guint i;
- desc = ladspa_class->descriptor;
-
/* beauty in the mess */
name = g_strdup ("");
namev = g_strsplit_set (desc->PortNames[portnum], "[]()", 0);
@@ -342,14 +342,12 @@ static GParamSpec *
gst_ladspa_object_class_get_param_spec (GstLADSPAClass * ladspa_class,
GObjectClass * object_class, unsigned long portnum)
{
- LADSPA_Descriptor *desc;
+ const LADSPA_Descriptor *desc = ladspa_class->descriptor;
GParamSpec *ret;
gchar *name;
gint hintdesc, perms;
gfloat lower, upper, def;
- desc = ladspa_class->descriptor;
-
name =
gst_ladspa_object_class_get_param_name (ladspa_class, object_class,
portnum);
@@ -544,7 +542,7 @@ void
gst_ladspa_element_class_set_metadata (GstLADSPAClass * ladspa_class,
GstElementClass * elem_class, const gchar * ladspa_class_tags)
{
- LADSPA_Descriptor *desc = ladspa_class->descriptor;
+ const LADSPA_Descriptor *desc = ladspa_class->descriptor;
gchar *longname, *author, *extra_ladspa_class_tags = NULL, *tmp;
#ifdef HAVE_LRDF
gchar *uri;
@@ -564,7 +562,7 @@ gst_ladspa_element_class_set_metadata (GstLADSPAClass * ladspa_class,
"Andy Wingo <wingo at pobox.com>",
"Steve Baker <stevebaker_org@yahoo.co.uk>",
"Erik Walthinsen <omega@cse.ogi.edu>",
- "Stefan Kost <ensonic@users.sf.net>",
+ "Stefan Sauer <ensonic@users.sf.net>",
"Wim Taymans <wim@fluendo.com>", NULL);
g_free (tmp);
@@ -760,30 +758,35 @@ gst_ladspa_finalize (GstLADSPA * ladspa)
}
void
-gst_ladspa_class_init (GstLADSPAClass * ladspa_class,
- LADSPA_Descriptor * descriptor)
+gst_ladspa_class_init (GstLADSPAClass * ladspa_class, GType type)
{
- guint mapper;
- struct
- {
- struct
- {
- guint in, out;
- } control;
- struct
- {
- guint in, out;
- } audio;
- } count;
+ guint mapper, ix;
+ guint audio_in = 0, audio_out = 0, control_in = 0, control_out = 0;
+ const GValue *value =
+ gst_structure_get_value (ladspa_meta_all, g_type_name (type));
+ GstStructure *ladspa_meta = g_value_get_boxed (value);
+ const gchar *file_name;
+ LADSPA_Descriptor_Function descriptor_function;
GST_DEBUG ("LADSPA initializing class");
- ladspa_class->descriptor = descriptor;
- ladspa_class->properties = 1;
-
- ladspa_count_ports (ladspa_class->descriptor, &ladspa_class->count.audio.in,
- &ladspa_class->count.audio.out, &ladspa_class->count.control.in,
+ file_name = gst_structure_get_string (ladspa_meta, "plugin-filename");
+ ladspa_class->plugin =
+ g_module_open (file_name, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
+ g_module_symbol (ladspa_class->plugin, "ladspa_descriptor",
+ (gpointer *) & descriptor_function);
+ gst_structure_get_uint (ladspa_meta, "element-ix", &ix);
+
+ ladspa_class->descriptor = descriptor_function (ix);
+ gst_structure_get_uint (ladspa_meta, "audio-in",
+ &ladspa_class->count.audio.in);
+ gst_structure_get_uint (ladspa_meta, "audio-out",
+ &ladspa_class->count.audio.out);
+ gst_structure_get_uint (ladspa_meta, "control-in",
+ &ladspa_class->count.control.in);
+ gst_structure_get_uint (ladspa_meta, "control-out",
&ladspa_class->count.control.out);
+ ladspa_class->properties = 1;
ladspa_class->map.audio.in =
g_new0 (unsigned long, ladspa_class->count.audio.in);
@@ -795,29 +798,27 @@ gst_ladspa_class_init (GstLADSPAClass * ladspa_class,
ladspa_class->map.control.out =
g_new0 (unsigned long, ladspa_class->count.control.out);
- count.audio.in = count.audio.out = count.control.in = count.control.out = 0;
-
for (mapper = 0; mapper < ladspa_class->descriptor->PortCount; mapper++) {
LADSPA_PortDescriptor p = ladspa_class->descriptor->PortDescriptors[mapper];
if (LADSPA_IS_PORT_AUDIO (p)) {
if (LADSPA_IS_PORT_INPUT (p))
- ladspa_class->map.audio.in[count.audio.in++] = mapper;
+ ladspa_class->map.audio.in[audio_in++] = mapper;
else
- ladspa_class->map.audio.out[count.audio.out++] = mapper;
+ ladspa_class->map.audio.out[audio_out++] = mapper;
} else if (LADSPA_IS_PORT_CONTROL (p)) {
if (LADSPA_IS_PORT_INPUT (p))
- ladspa_class->map.control.in[count.control.in++] = mapper;
+ ladspa_class->map.control.in[control_in++] = mapper;
else
- ladspa_class->map.control.out[count.control.out++] = mapper;
+ ladspa_class->map.control.out[control_out++] = mapper;
}
}
- g_assert (count.control.out == ladspa_class->count.control.out);
- g_assert (count.control.in == ladspa_class->count.control.in);
+ g_assert (control_out == ladspa_class->count.control.out);
+ g_assert (control_in == ladspa_class->count.control.in);
- g_assert (count.audio.out == ladspa_class->count.audio.out);
- g_assert (count.audio.in == ladspa_class->count.audio.in);
+ g_assert (audio_out == ladspa_class->count.audio.out);
+ g_assert (audio_in == ladspa_class->count.audio.in);
}
void
@@ -834,61 +835,21 @@ gst_ladspa_class_finalize (GstLADSPAClass * ladspa_class)
ladspa_class->map.audio.out = NULL;
g_free (ladspa_class->map.audio.in);
ladspa_class->map.audio.in = NULL;
-}
-void
-ladspa_count_ports (const LADSPA_Descriptor * descriptor,
- guint * audio_in, guint * audio_out, guint * control_in,
- guint * control_out)
-{
- guint i;
-
- *audio_in = *audio_out = *control_in = *control_out = 0;
-
- for (i = 0; i < descriptor->PortCount; i++) {
- LADSPA_PortDescriptor p = descriptor->PortDescriptors[i];
-
- if (LADSPA_IS_PORT_AUDIO (p)) {
- if (LADSPA_IS_PORT_INPUT (p))
- (*audio_in)++;
- else
- (*audio_out)++;
- } else if (LADSPA_IS_PORT_CONTROL (p)) {
- if (LADSPA_IS_PORT_INPUT (p))
- (*control_in)++;
- else
- (*control_out)++;
- }
- }
+ g_module_close (ladspa_class->plugin);
+ ladspa_class->plugin = NULL;
}
/*
- * Register the type.
+ * Create the type & register the element.
*/
void
-ladspa_register_plugin (GstPlugin * plugin, GType parent_type,
- const gchar * tmp, const GTypeInfo * info, GQuark descriptor_quark,
- const gchar * filename, const LADSPA_Descriptor * desc)
+ladspa_register_element (GstPlugin * plugin, GType parent_type,
+ const GTypeInfo * info, GstStructure * ladspa_meta)
{
- gchar *name;
- GType type;
-
- name = g_ascii_strdown (tmp, -1);
- g_strcanon (name, G_CSET_A_2_Z G_CSET_a_2_z G_CSET_DIGITS "-+", '-');
-
- /* if it's not already registered, do it */
- if (!g_type_from_name (name)) {
- /* create the type now */
- type = g_type_register_static (parent_type, name, info, 0);
+ const gchar *type_name =
+ gst_structure_get_string (ladspa_meta, "element-type-name");
- /* base init is expected to initialize dynamic data */
- g_type_set_qdata (type, descriptor_quark, (gpointer) desc);
-
- /* register the element */
- gst_element_register (plugin, name, GST_RANK_NONE, type);
- } else
- GST_WARNING ("Plugin identifier collision for %s (%s:%lu/%s)", name,
- filename, desc->UniqueID, desc->Label);
-
- g_free (name);
+ gst_element_register (plugin, type_name, GST_RANK_NONE,
+ g_type_register_static (parent_type, type_name, info, 0));
}
diff --git a/ext/ladspa/gstladspautils.h b/ext/ladspa/gstladspautils.h
index 7ab5e1d76..050cbaa56 100644
--- a/ext/ladspa/gstladspautils.h
+++ b/ext/ladspa/gstladspautils.h
@@ -1,5 +1,6 @@
/* GStreamer
* Copyright (C) 2013 Juan Manuel Borges Caño <juanmabcmail@gmail.com>
+ * 2013 Stefan Sauer <ensonic@users.sf.net>
*
* gstladspautils.h: Header for LADSPA plugin utils
*
@@ -22,6 +23,7 @@
#ifndef __GST_LADSPA_UTILS_H__
#define __GST_LADSPA_UTILS_H__
+#include <gmodule.h>
#include <gst/gst.h>
#include <gst/audio/gstaudiofilter.h>
#include <gst/base/gstbasesrc.h>
@@ -63,7 +65,8 @@ struct _GstLADSPAClass
{
guint properties;
- LADSPA_Descriptor *descriptor;
+ GModule *plugin;
+ const LADSPA_Descriptor *descriptor;
struct
{
@@ -141,19 +144,14 @@ void
gst_ladspa_finalize (GstLADSPA * ladspa);
void
-gst_ladspa_class_init (GstLADSPAClass * ladspa_class, LADSPA_Descriptor * desc);
+gst_ladspa_class_init (GstLADSPAClass * ladspa_class, GType type);
void
gst_ladspa_class_finalize (GstLADSPAClass * ladspa_class);
void
-ladspa_count_ports (const LADSPA_Descriptor * desc, guint * audio_in,
- guint * audio_out, guint * control_in, guint * control_out);
-
-void
-ladspa_register_plugin (GstPlugin * plugin, GType parent_type,
- const gchar * tmp, const GTypeInfo * info, GQuark descriptor_quark,
- const gchar * filename, const LADSPA_Descriptor * desc);
+ladspa_register_element (GstPlugin * plugin, GType parent_type,
+ const GTypeInfo * info, GstStructure * ladspa_meta);
G_END_DECLS