ladspa: add LIBDIR/ladspa to search path and make path more portable

Use glib defines for searchpath separators. Filter searchpath to avoid scanning
path entries twice. Fix the return in ladspa_plugin_directory_search to return
wheter we found a plugin.
This commit is contained in:
Stefan Kost 2009-03-04 15:05:48 +02:00
parent 86c5975ebe
commit 070ffb6940
2 changed files with 97 additions and 9 deletions

View file

@ -227,6 +227,10 @@ GST_LICENSE="LGPL"
AC_DEFINE_UNQUOTED(GST_LICENSE, "$GST_LICENSE", [GStreamer license]) AC_DEFINE_UNQUOTED(GST_LICENSE, "$GST_LICENSE", [GStreamer license])
AC_SUBST(GST_LICENSE) AC_SUBST(GST_LICENSE)
dnl define LIBDIR so we can inform people where we live
AS_AC_EXPAND(LIBDIR, $libdir)
AC_DEFINE_UNQUOTED(LIBDIR, "$LIBDIR", [library dir])
dnl set location of plugin directory dnl set location of plugin directory
AG_GST_SET_PLUGINDIR AG_GST_SET_PLUGINDIR

View file

@ -29,7 +29,6 @@
#include "gstladspa.h" #include "gstladspa.h"
#include <ladspa.h> /* main ladspa sdk include file */ #include <ladspa.h> /* main ladspa sdk include file */
#include "utils.h" /* ladspa sdk utility functions */
/* 1.0 and the 1.1 preliminary headers don't define a version, but 1.1 final /* 1.0 and the 1.1 preliminary headers don't define a version, but 1.1 final
does */ does */
@ -39,6 +38,11 @@
#define GST_LADSPA_DESCRIPTOR_QDATA g_quark_from_static_string("ladspa-descriptor") #define GST_LADSPA_DESCRIPTOR_QDATA g_quark_from_static_string("ladspa-descriptor")
#define GST_LADSPA_DEFAULT_PATH \
"/usr/lib/ladspa" G_SEARCHPATH_SEPARATOR_S \
"/usr/local/lib/ladspa" G_SEARCHPATH_SEPARATOR_S \
LIBDIR "/ladspa"
static void gst_ladspa_set_property (GObject * object, guint prop_id, static void gst_ladspa_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec); const GValue * value, GParamSpec * pspec);
static void gst_ladspa_get_property (GObject * object, guint prop_id, static void gst_ladspa_get_property (GObject * object, guint prop_id,
@ -568,15 +572,14 @@ gst_ladspa_process (GstSignalProcessor * gsp, guint nframes)
} }
static void static void
ladspa_describe_plugin (const char *pcFullFilename, ladspa_describe_plugin (LADSPA_Descriptor_Function descriptor_function)
void *pvPluginHandle, LADSPA_Descriptor_Function pfDescriptorFunction)
{ {
const LADSPA_Descriptor *desc; const LADSPA_Descriptor *desc;
gint i; gint i;
/* walk through all the plugins in this pluginlibrary */ /* walk through all the plugins in this pluginlibrary */
i = 0; i = 0;
while ((desc = pfDescriptorFunction (i++))) { while ((desc = descriptor_function (i++))) {
gchar *type_name; gchar *type_name;
GTypeInfo typeinfo = { GTypeInfo typeinfo = {
sizeof (GstLADSPAClass), sizeof (GstLADSPAClass),
@ -614,6 +617,90 @@ ladspa_describe_plugin (const char *pcFullFilename,
} }
} }
/* search just the one directory.
*/
static gboolean
ladspa_plugin_directory_search (const char *dir_name)
{
GDir *dir;
gchar *file_name;
const gchar *entry_name;
LADSPA_Descriptor_Function descriptor_function;
GModule *plugin;
gboolean ok = FALSE;
GST_INFO ("scanning directory \"%s\"", dir_name);
dir = g_dir_open (dir_name, 0, NULL);
if (!dir)
return FALSE;
while ((entry_name = g_dir_read_name (dir))) {
file_name = g_build_filename (dir_name, entry_name, NULL);
plugin =
g_module_open (file_name, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL);
if (plugin) {
/* the file is a shared library */
if (g_module_symbol (plugin, "ladspa_descriptor",
(gpointer *) & descriptor_function)) {
/* we've found a ladspa_descriptor function, now introspect it. */
ladspa_describe_plugin (descriptor_function);
ok = TRUE;
} else {
/* it was a library, but not a LADSPA one. Unload it. */
g_module_close (plugin);
}
}
g_free (file_name);
}
g_dir_close (dir);
return ok;
}
/* search the plugin path
*/
static gboolean
ladspa_plugin_path_search (void)
{
const char *search_path;
char *ladspa_path;
gchar **paths;
gint i, j, path_entries;
gboolean res = FALSE, skip;
search_path = g_getenv ("LADSPA_PATH");
if (search_path) {
ladspa_path =
g_strdup_printf ("%s" G_SEARCHPATH_SEPARATOR_S GST_LADSPA_DEFAULT_PATH,
search_path);
} else {
ladspa_path = g_strdup (GST_LADSPA_DEFAULT_PATH);
}
paths = g_strsplit (ladspa_path, G_SEARCHPATH_SEPARATOR_S, 0);
path_entries = g_strv_length (paths);
GST_INFO ("%d dirs in search paths \"%s\"", path_entries, ladspa_path);
for (i = 0; i < path_entries; i++) {
skip = FALSE;
for (j = 0; j < i; j++) {
if (!strcmp (paths[i], paths[j])) {
skip = TRUE;
break;
}
}
if (skip)
break;
res |= ladspa_plugin_directory_search (paths[i]);
}
g_strfreev (paths);
g_free (ladspa_path);
return res;
}
static gboolean static gboolean
plugin_init (GstPlugin * plugin) plugin_init (GstPlugin * plugin)
{ {
@ -622,16 +709,13 @@ plugin_init (GstPlugin * plugin)
gst_plugin_add_dependency_simple (plugin, gst_plugin_add_dependency_simple (plugin,
"LADSPA_PATH", "LADSPA_PATH",
"/usr/lib/ladspa:/usr/local/lib/ladspa", GST_LADSPA_DEFAULT_PATH, NULL, GST_PLUGIN_DEPENDENCY_FLAG_NONE);
NULL, GST_PLUGIN_DEPENDENCY_FLAG_NONE);
parent_class = g_type_class_ref (GST_TYPE_SIGNAL_PROCESSOR); parent_class = g_type_class_ref (GST_TYPE_SIGNAL_PROCESSOR);
ladspa_plugin = plugin; ladspa_plugin = plugin;
LADSPAPluginSearch (ladspa_describe_plugin); return ladspa_plugin_path_search ();
return TRUE;
} }
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR, GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,