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"));
217 ladspa_path = g_strdup ("lib\\ladspa");
219 ladspa_path = g_strdup ("/usr/local/lib/ladspa:/usr/lib/ladspa:/usr/lib64/ladspa");
222 dir = strtok (ladspa_path, ":");
224 plugin_mgr_get_dir_plugins (plugin_mgr, dir);
225 while ((dir = strtok (NULL, ":")));
227 g_free (ladspa_path);
231 plugin_mgr_sort (gconstpointer a, gconstpointer b)
233 const plugin_desc_t * da;
234 const plugin_desc_t * db;
235 da = (const plugin_desc_t *) a;
236 db = (const plugin_desc_t *) b;
238 return strcasecmp (da->name, db->name);
245 char dirname[PATH_MAX];
247 pm = g_malloc (sizeof (plugin_mgr_t));
248 pm->all_plugins = NULL;
250 pm->plugin_count = 0;
252 snprintf (dirname, PATH_MAX, "%s/jackrack/blacklist.txt", mlt_environment ("MLT_DATA"));
253 pm->blacklist = mlt_properties_load (dirname);
254 plugin_mgr_get_path_plugins (pm);
256 if (!pm->all_plugins)
257 mlt_log_warning( NULL, "No LADSPA plugins were found!\n\nCheck your LADSPA_PATH environment variable.\n");
259 pm->all_plugins = g_slist_sort (pm->all_plugins, plugin_mgr_sort);
265 plugin_mgr_destroy (plugin_mgr_t * plugin_mgr)
269 for (list = plugin_mgr->all_plugins; list; list = g_slist_next (list))
270 plugin_desc_destroy ((plugin_desc_t *) list->data);
272 g_slist_free (plugin_mgr->plugins);
273 g_slist_free (plugin_mgr->all_plugins);
279 plugin_mgr_set_plugins (plugin_mgr_t * plugin_mgr, unsigned long rack_channels)
282 plugin_desc_t * desc;
284 /* clear the current plugins */
285 g_slist_free (plugin_mgr->plugins);
286 plugin_mgr->plugins = NULL;
288 for (list = plugin_mgr->all_plugins; list; list = g_slist_next (list))
290 desc = (plugin_desc_t *) list->data;
292 if (plugin_desc_get_copies (desc, rack_channels) != 0)
293 plugin_mgr->plugins = g_slist_append (plugin_mgr->plugins, desc);
297 static plugin_desc_t *
298 plugin_mgr_find_desc (plugin_mgr_t * plugin_mgr, GSList * plugins, unsigned long id)
301 plugin_desc_t * desc;
303 for (list = plugins; list; list = g_slist_next (list))
305 desc = (plugin_desc_t *) list->data;
315 plugin_mgr_get_desc (plugin_mgr_t * plugin_mgr, unsigned long id)
317 return plugin_mgr_find_desc (plugin_mgr, plugin_mgr->plugins, id);
321 plugin_mgr_get_any_desc (plugin_mgr_t * plugin_mgr, unsigned long id)
323 return plugin_mgr_find_desc (plugin_mgr, plugin_mgr->all_plugins, id);