5 * Copyright (C) Robert Ham 2002, 2003 (node@users.sourceforge.net)
7 * Modification for MLT:
8 * Copyright (C) 2004 Ushodaya Enterprises Limited
9 * Author: Dan Dennedy <dan@dennedy.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
37 #include <sys/types.h>
40 #include "plugin_mgr.h"
41 #include "plugin_desc.h"
42 #include "framework/mlt_log.h"
43 #include "framework/mlt_factory.h"
46 plugin_is_valid (const LADSPA_Descriptor * descriptor)
49 unsigned long icount = 0;
50 unsigned long ocount = 0;
52 for (i = 0; i < descriptor->PortCount; i++)
54 if (!LADSPA_IS_PORT_AUDIO (descriptor->PortDescriptors[i]))
57 if (LADSPA_IS_PORT_INPUT (descriptor->PortDescriptors[i]))
63 if (icount == 0 || ocount == 0)
70 plugin_mgr_get_object_file_plugins (plugin_mgr_t * plugin_mgr, const char * filename)
74 LADSPA_Descriptor_Function get_descriptor;
75 const LADSPA_Descriptor * descriptor;
76 unsigned long plugin_index;
77 plugin_desc_t * desc, * other_desc = NULL;
82 /* open the object file */
83 dl_handle = dlopen (filename, RTLD_NOW|RTLD_GLOBAL);
86 mlt_log_warning( NULL, "%s: error opening shared object file '%s': %s\n",
87 __FUNCTION__, filename, dlerror());
92 /* get the get_descriptor function */
93 dlerror (); /* clear the error report */
95 get_descriptor = (LADSPA_Descriptor_Function)
96 dlsym (dl_handle, "ladspa_descriptor");
100 mlt_log_warning( NULL, "%s: error finding ladspa_descriptor symbol in object file '%s': %s\n",
101 __FUNCTION__, filename, dlerr);
107 while ( (descriptor = get_descriptor (plugin_index)) )
109 if (!plugin_is_valid (descriptor))
116 /* check it doesn't already exist */
118 for (list = plugin_mgr->all_plugins; list; list = g_slist_next (list))
120 other_desc = (plugin_desc_t *) list->data;
122 if (other_desc->id == descriptor->UniqueID)
131 mlt_log_info( NULL, "Plugin %ld exists in both '%s' and '%s'; using version in '%s'\n",
132 descriptor->UniqueID, other_desc->object_file, filename, other_desc->object_file);
138 desc = plugin_desc_new_with_descriptor (filename, plugin_index, descriptor);
139 plugin_mgr->all_plugins = g_slist_append (plugin_mgr->all_plugins, desc);
141 plugin_mgr->plugin_count++;
143 /* print in the splash screen */
144 /* mlt_log_verbose( NULL, "Loaded plugin '%s'\n", desc->name); */
147 err = dlclose (dl_handle);
150 mlt_log_warning( NULL, "%s: error closing object file '%s': %s\n",
151 __FUNCTION__, filename, dlerror ());
156 plugin_mgr_get_dir_plugins (plugin_mgr_t * plugin_mgr, const char * dir)
159 struct dirent * dir_entry;
164 dir_stream = opendir (dir);
167 /* mlt_log_warning( NULL, "%s: error opening directory '%s': %s\n",
168 __FUNCTION__, dir, strerror (errno)); */
172 dirlen = strlen (dir);
174 while ( (dir_entry = readdir (dir_stream)) )
178 if (strcmp (dir_entry->d_name, ".") == 0 ||
179 mlt_properties_get (plugin_mgr->blacklist, dir_entry->d_name) ||
180 strcmp (dir_entry->d_name, "..") == 0)
183 file_name = g_malloc (dirlen + 1 + strlen (dir_entry->d_name) + 1);
185 strcpy (file_name, dir);
186 if (file_name[dirlen - 1] == '/')
187 strcpy (file_name + dirlen, dir_entry->d_name);
190 file_name[dirlen] = '/';
191 strcpy (file_name + dirlen + 1, dir_entry->d_name);
194 stat (file_name, &info);
195 if (S_ISDIR (info.st_mode))
196 plugin_mgr_get_dir_plugins (plugin_mgr, file_name);
198 plugin_mgr_get_object_file_plugins (plugin_mgr, file_name);
203 err = closedir (dir_stream);
205 mlt_log_warning( NULL, "%s: error closing directory '%s': %s\n",
206 __FUNCTION__, dir, strerror (errno));
210 plugin_mgr_get_path_plugins (plugin_mgr_t * plugin_mgr)
212 char * ladspa_path, * dir;
214 ladspa_path = g_strdup (getenv ("LADSPA_PATH"));
218 ladspa_path = malloc (strlen (mlt_environment("MLT_DATA")) + strlen ("\\..\\..\\lib\\ladspa") + 1);
219 strcpy (ladspa_path, mlt_environment("MLT_DATA"));
220 strcat (ladspa_path, "\\..\\..\\lib\\ladspa");
221 printf("LADSPA_PATH=%s\n", ladspa_path);
224 ladspa_path = g_strdup ("lib/ladspa:/usr/local/lib/ladspa:/usr/lib/ladspa:/usr/lib64/ladspa");
227 dir = strtok (ladspa_path, ":");
229 plugin_mgr_get_dir_plugins (plugin_mgr, dir);
230 while ((dir = strtok (NULL, ":")));
232 g_free (ladspa_path);
236 plugin_mgr_sort (gconstpointer a, gconstpointer b)
238 const plugin_desc_t * da;
239 const plugin_desc_t * db;
240 da = (const plugin_desc_t *) a;
241 db = (const plugin_desc_t *) b;
243 return strcasecmp (da->name, db->name);
250 char dirname[PATH_MAX];
252 pm = g_malloc (sizeof (plugin_mgr_t));
253 pm->all_plugins = NULL;
255 pm->plugin_count = 0;
257 snprintf (dirname, PATH_MAX, "%s/jackrack/blacklist.txt", mlt_environment ("MLT_DATA"));
258 pm->blacklist = mlt_properties_load (dirname);
259 plugin_mgr_get_path_plugins (pm);
261 if (!pm->all_plugins)
262 mlt_log_warning( NULL, "No LADSPA plugins were found!\n\nCheck your LADSPA_PATH environment variable.\n");
264 pm->all_plugins = g_slist_sort (pm->all_plugins, plugin_mgr_sort);
270 plugin_mgr_destroy (plugin_mgr_t * plugin_mgr)
274 for (list = plugin_mgr->all_plugins; list; list = g_slist_next (list))
275 plugin_desc_destroy ((plugin_desc_t *) list->data);
277 g_slist_free (plugin_mgr->plugins);
278 g_slist_free (plugin_mgr->all_plugins);
284 plugin_mgr_set_plugins (plugin_mgr_t * plugin_mgr, unsigned long rack_channels)
287 plugin_desc_t * desc;
289 /* clear the current plugins */
290 g_slist_free (plugin_mgr->plugins);
291 plugin_mgr->plugins = NULL;
293 for (list = plugin_mgr->all_plugins; list; list = g_slist_next (list))
295 desc = (plugin_desc_t *) list->data;
297 if (plugin_desc_get_copies (desc, rack_channels) != 0)
298 plugin_mgr->plugins = g_slist_append (plugin_mgr->plugins, desc);
302 static plugin_desc_t *
303 plugin_mgr_find_desc (plugin_mgr_t * plugin_mgr, GSList * plugins, unsigned long id)
306 plugin_desc_t * desc;
308 for (list = plugins; list; list = g_slist_next (list))
310 desc = (plugin_desc_t *) list->data;
320 plugin_mgr_get_desc (plugin_mgr_t * plugin_mgr, unsigned long id)
322 return plugin_mgr_find_desc (plugin_mgr, plugin_mgr->plugins, id);
326 plugin_mgr_get_any_desc (plugin_mgr_t * plugin_mgr, unsigned long id)
328 return plugin_mgr_find_desc (plugin_mgr, plugin_mgr->all_plugins, id);