Mercurial > audlegacy
annotate src/audacious/pluginenum.c @ 2795:fa6c339cce38 trunk
[svn] - chase r4614.
author | nenolod |
---|---|
date | Thu, 24 May 2007 01:48:28 -0700 |
parents | 637359219e10 |
children | f0c1c8b22c88 |
rev | line source |
---|---|
2313 | 1 /* Audacious - Cross-platform multimedia player |
2 * Copyright (C) 2005-2007 Audacious development team | |
3 * | |
4 * Based on BMP: | |
5 * Copyright (C) 2003-2004 BMP development team | |
6 * | |
7 * Based on XMMS: | |
8 * Copyright (C) 1998-2003 XMMS development team | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; under version 2 of the License. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Public License | |
20 * along with this program; if not, write to the Free Software | |
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 # include "config.h" | |
26 #endif | |
27 | |
28 #ifndef SHARED_SUFFIX | |
29 # define SHARED_SUFFIX G_MODULE_SUFFIX | |
30 #endif | |
31 | |
32 #include "pluginenum.h" | |
33 | |
34 #include <glib.h> | |
35 #include <gmodule.h> | |
36 #include <glib/gprintf.h> | |
37 #include <string.h> | |
38 | |
39 #include "main.h" | |
40 #include "ui_main.h" | |
41 #include "playback.h" | |
42 #include "playlist.h" | |
2373
ad1d7687814c
[svn] made strings.h for existing strings.c, cleanups
mf0102
parents:
2313
diff
changeset
|
43 #include "strings.h" |
2313 | 44 #include "util.h" |
45 | |
46 #include "effect.h" | |
47 #include "general.h" | |
48 #include "input.h" | |
49 #include "output.h" | |
50 #include "visualization.h" | |
51 | |
52 const gchar *plugin_dir_list[] = { | |
53 PLUGINSUBS, | |
54 NULL | |
55 }; | |
56 | |
57 GHashTable *plugin_matrix = NULL; | |
58 GList *lowlevel_list = NULL; | |
59 | |
2623 | 60 extern GList *vfs_transports; |
61 | |
2313 | 62 static gint |
63 inputlist_compare_func(gconstpointer a, gconstpointer b) | |
64 { | |
65 const InputPlugin *ap = a, *bp = b; | |
66 return strcasecmp(ap->description, bp->description); | |
67 } | |
68 | |
69 static gint | |
70 outputlist_compare_func(gconstpointer a, gconstpointer b) | |
71 { | |
72 const OutputPlugin *ap = a, *bp = b; | |
73 return strcasecmp(ap->description, bp->description); | |
74 } | |
75 | |
76 static gint | |
77 effectlist_compare_func(gconstpointer a, gconstpointer b) | |
78 { | |
79 const EffectPlugin *ap = a, *bp = b; | |
80 return strcasecmp(ap->description, bp->description); | |
81 } | |
82 | |
83 static gint | |
84 generallist_compare_func(gconstpointer a, gconstpointer b) | |
85 { | |
86 const GeneralPlugin *ap = a, *bp = b; | |
87 return strcasecmp(ap->description, bp->description); | |
88 } | |
89 | |
90 static gint | |
91 vislist_compare_func(gconstpointer a, gconstpointer b) | |
92 { | |
93 const VisPlugin *ap = a, *bp = b; | |
94 return strcasecmp(ap->description, bp->description); | |
95 } | |
96 | |
97 static gboolean | |
98 plugin_is_duplicate(const gchar * filename) | |
99 { | |
100 GList *l; | |
101 const gchar *basename = g_basename(filename); | |
102 | |
103 /* FIXME: messy stuff */ | |
104 | |
105 for (l = ip_data.input_list; l; l = g_list_next(l)) | |
106 if (!strcmp(basename, g_basename(INPUT_PLUGIN(l->data)->filename))) | |
107 return TRUE; | |
108 | |
109 for (l = op_data.output_list; l; l = g_list_next(l)) | |
110 if (!strcmp(basename, g_basename(OUTPUT_PLUGIN(l->data)->filename))) | |
111 return TRUE; | |
112 | |
113 for (l = ep_data.effect_list; l; l = g_list_next(l)) | |
114 if (!strcmp(basename, g_basename(EFFECT_PLUGIN(l->data)->filename))) | |
115 return TRUE; | |
116 | |
117 for (l = gp_data.general_list; l; l = g_list_next(l)) | |
118 if (!strcmp(basename, g_basename(GENERAL_PLUGIN(l->data)->filename))) | |
119 return TRUE; | |
120 | |
121 for (l = vp_data.vis_list; l; l = g_list_next(l)) | |
122 if (!strcmp(basename, g_basename(VIS_PLUGIN(l->data)->filename))) | |
123 return TRUE; | |
124 | |
125 for (l = lowlevel_list; l; l = g_list_next(l)) | |
126 if (!strcmp(basename, g_basename(VIS_PLUGIN(l->data)->filename))) | |
127 return TRUE; | |
128 | |
129 return FALSE; | |
130 } | |
131 | |
132 | |
133 #define PLUGIN_GET_INFO(x) ((PluginGetInfoFunc)(x))() | |
134 typedef Plugin * (*PluginGetInfoFunc) (void); | |
135 | |
136 static void | |
137 input_plugin_init(Plugin * plugin) | |
138 { | |
139 InputPlugin *p = INPUT_PLUGIN(plugin); | |
140 | |
141 p->get_vis_type = input_get_vis_type; | |
142 p->add_vis_pcm = input_add_vis_pcm; | |
143 | |
144 /* Pretty const casts courtesy of XMMS's plugin.h legacy. Anyone | |
145 else thinks we could use a CONST macro to solve the warnings? | |
146 - descender */ | |
147 p->set_info = (void (*)(gchar *, gint, gint, gint, gint)) playlist_set_info_old_abi; | |
148 p->set_info_text = (void (*)(gchar *)) input_set_info_text; | |
149 p->set_status_buffering = (void (*)(gboolean)) input_set_status_buffering; | |
150 | |
151 ip_data.input_list = g_list_append(ip_data.input_list, p); | |
152 | |
153 g_hash_table_replace(plugin_matrix, g_path_get_basename(p->filename), | |
154 GINT_TO_POINTER(1)); | |
155 } | |
156 | |
157 static void | |
158 output_plugin_init(Plugin * plugin) | |
159 { | |
160 OutputPlugin *p = OUTPUT_PLUGIN(plugin); | |
161 op_data.output_list = g_list_append(op_data.output_list, p); | |
162 } | |
163 | |
164 static void | |
165 effect_plugin_init(Plugin * plugin) | |
166 { | |
167 EffectPlugin *p = EFFECT_PLUGIN(plugin); | |
168 ep_data.effect_list = g_list_append(ep_data.effect_list, p); | |
169 } | |
170 | |
171 static void | |
172 general_plugin_init(Plugin * plugin) | |
173 { | |
174 GeneralPlugin *p = GENERAL_PLUGIN(plugin); | |
175 gp_data.general_list = g_list_append(gp_data.general_list, p); | |
176 } | |
177 | |
178 static void | |
179 vis_plugin_init(Plugin * plugin) | |
180 { | |
181 VisPlugin *p = VIS_PLUGIN(plugin); | |
182 p->disable_plugin = vis_disable_plugin; | |
183 vp_data.vis_list = g_list_append(vp_data.vis_list, p); | |
184 } | |
185 | |
186 static void | |
187 lowlevel_plugin_init(Plugin * plugin) | |
188 { | |
189 LowlevelPlugin *p = LOWLEVEL_PLUGIN(plugin); | |
190 lowlevel_list = g_list_append(lowlevel_list, p); | |
191 } | |
192 | |
193 /* FIXME: Placed here (hopefully) temporarily - descender */ | |
194 | |
195 typedef struct { | |
196 const gchar *name; | |
197 const gchar *id; | |
198 void (*init)(Plugin *); | |
199 } PluginType; | |
200 | |
201 static PluginType plugin_types[] = { | |
202 { "input" , "get_iplugin_info", input_plugin_init }, | |
203 { "output" , "get_oplugin_info", output_plugin_init }, | |
204 { "effect" , "get_eplugin_info", effect_plugin_init }, | |
205 { "general" , "get_gplugin_info", general_plugin_init }, | |
206 { "visualization", "get_vplugin_info", vis_plugin_init }, | |
207 { "lowlevel" , "get_lplugin_info", lowlevel_plugin_init }, | |
208 { NULL, NULL, NULL } | |
209 }; | |
210 | |
211 static void | |
212 add_plugin(const gchar * filename) | |
213 { | |
214 PluginType *type; | |
215 GModule *module; | |
216 gpointer func; | |
217 | |
218 if (plugin_is_duplicate(filename)) | |
219 return; | |
220 | |
2623 | 221 g_message("Loaded plugin (%s)", filename); |
222 | |
2313 | 223 if (!(module = g_module_open(filename, G_MODULE_BIND_LOCAL))) { |
224 printf("Failed to load plugin (%s): %s\n", | |
225 filename, g_module_error()); | |
226 return; | |
227 } | |
228 | |
229 for (type = plugin_types; type->name; type++) | |
230 { | |
231 if (g_module_symbol(module, type->id, &func)) { | |
232 Plugin *plugin = PLUGIN_GET_INFO(func); | |
233 | |
234 plugin->handle = module; | |
235 plugin->filename = g_strdup(filename); | |
236 type->init(PLUGIN_GET_INFO(func)); | |
237 | |
238 return; | |
239 } | |
240 } | |
241 | |
242 printf("Invalid plugin (%s)\n", filename); | |
243 g_module_close(module); | |
244 } | |
245 | |
246 static gboolean | |
247 scan_plugin_func(const gchar * path, const gchar * basename, gpointer data) | |
248 { | |
249 if (!str_has_suffix_nocase(basename, SHARED_SUFFIX)) | |
250 return FALSE; | |
251 | |
252 if (!g_file_test(path, G_FILE_TEST_IS_REGULAR)) | |
253 return FALSE; | |
254 | |
255 add_plugin(path); | |
256 | |
257 return FALSE; | |
258 } | |
259 | |
260 static void | |
261 scan_plugins(const gchar * path) | |
262 { | |
263 dir_foreach(path, scan_plugin_func, NULL, NULL); | |
264 } | |
265 | |
266 void | |
267 plugin_system_init(void) | |
268 { | |
269 gchar *dir, **disabled; | |
270 GList *node; | |
271 OutputPlugin *op; | |
272 InputPlugin *ip; | |
273 LowlevelPlugin *lp; | |
274 gint dirsel = 0, i = 0; | |
275 | |
276 if (!g_module_supported()) { | |
277 report_error("Module loading not supported! Plugins will not be loaded.\n"); | |
278 return; | |
279 } | |
280 | |
2624
840fb578a834
[svn] - [security, backport to 1.3] fix improper comparisons of hashtables used by the plugin loader.
nenolod
parents:
2623
diff
changeset
|
281 plugin_matrix = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, |
2313 | 282 NULL); |
283 | |
284 #ifndef DISABLE_USER_PLUGIN_DIR | |
285 scan_plugins(bmp_paths[BMP_PATH_USER_PLUGIN_DIR]); | |
286 /* | |
287 * This is in a separate loop so if the user puts them in the | |
288 * wrong dir we'll still get them in the right order (home dir | |
289 * first) - Zinx | |
290 */ | |
291 while (plugin_dir_list[dirsel]) { | |
292 dir = g_build_filename(bmp_paths[BMP_PATH_USER_PLUGIN_DIR], | |
293 plugin_dir_list[dirsel++], NULL); | |
294 scan_plugins(dir); | |
295 g_free(dir); | |
296 } | |
297 dirsel = 0; | |
298 #endif | |
299 | |
300 while (plugin_dir_list[dirsel]) { | |
301 dir = g_build_filename(PLUGIN_DIR, plugin_dir_list[dirsel++], NULL); | |
302 scan_plugins(dir); | |
303 g_free(dir); | |
304 } | |
305 | |
306 op_data.output_list = g_list_sort(op_data.output_list, outputlist_compare_func); | |
307 if (!op_data.current_output_plugin | |
308 && g_list_length(op_data.output_list)) { | |
309 op_data.current_output_plugin = op_data.output_list->data; | |
310 } | |
311 | |
312 ip_data.input_list = g_list_sort(ip_data.input_list, inputlist_compare_func); | |
313 | |
314 ep_data.effect_list = g_list_sort(ep_data.effect_list, effectlist_compare_func); | |
315 ep_data.enabled_list = NULL; | |
316 | |
317 gp_data.general_list = g_list_sort(gp_data.general_list, generallist_compare_func); | |
318 gp_data.enabled_list = NULL; | |
319 | |
320 vp_data.vis_list = g_list_sort(vp_data.vis_list, vislist_compare_func); | |
321 vp_data.enabled_list = NULL; | |
322 | |
323 general_enable_from_stringified_list(cfg.enabled_gplugins); | |
324 vis_enable_from_stringified_list(cfg.enabled_vplugins); | |
325 effect_enable_from_stringified_list(cfg.enabled_eplugins); | |
326 | |
327 g_free(cfg.enabled_gplugins); | |
328 cfg.enabled_gplugins = NULL; | |
329 | |
330 g_free(cfg.enabled_vplugins); | |
331 cfg.enabled_vplugins = NULL; | |
332 | |
333 g_free(cfg.enabled_eplugins); | |
334 cfg.enabled_eplugins = NULL; | |
335 | |
336 for (node = op_data.output_list; node; node = g_list_next(node)) { | |
337 op = OUTPUT_PLUGIN(node->data); | |
338 /* | |
339 * Only test basename to avoid problems when changing | |
340 * prefix. We will only see one plugin with the same | |
341 * basename, so this is usually what the user want. | |
342 */ | |
343 if (!strcmp(g_basename(cfg.outputplugin), g_basename(op->filename))) | |
344 op_data.current_output_plugin = op; | |
345 if (op->init) | |
346 op->init(); | |
347 } | |
348 | |
349 for (node = ip_data.input_list; node; node = g_list_next(node)) { | |
350 ip = INPUT_PLUGIN(node->data); | |
351 if (ip->init) | |
352 ip->init(); | |
353 } | |
354 | |
355 for (node = lowlevel_list; node; node = g_list_next(node)) { | |
356 lp = LOWLEVEL_PLUGIN(node->data); | |
357 if (lp->init) | |
358 lp->init(); | |
359 } | |
360 | |
361 if (cfg.disabled_iplugins) { | |
362 disabled = g_strsplit(cfg.disabled_iplugins, ":", 0); | |
363 while (disabled[i]) { | |
364 g_hash_table_replace(plugin_matrix, disabled[i], | |
365 GINT_TO_POINTER(FALSE)); | |
366 i++; | |
367 } | |
368 | |
369 g_free(disabled); | |
370 | |
371 g_free(cfg.disabled_iplugins); | |
372 cfg.disabled_iplugins = NULL; | |
373 } | |
374 } | |
375 | |
376 void | |
377 plugin_system_cleanup(void) | |
378 { | |
379 InputPlugin *ip; | |
380 OutputPlugin *op; | |
381 EffectPlugin *ep; | |
382 GeneralPlugin *gp; | |
383 VisPlugin *vp; | |
384 LowlevelPlugin *lp; | |
385 GList *node; | |
386 | |
387 g_message("Shutting down plugin system"); | |
388 | |
389 if (playback_get_playing()) { | |
390 ip_data.stop = TRUE; | |
391 playback_stop(); | |
392 ip_data.stop = FALSE; | |
393 } | |
394 | |
2623 | 395 /* FIXME: race condition -nenolod */ |
396 op_data.current_output_plugin = NULL; | |
397 | |
2313 | 398 for (node = get_input_list(); node; node = g_list_next(node)) { |
399 ip = INPUT_PLUGIN(node->data); | |
400 if (ip && ip->cleanup) { | |
401 ip->cleanup(); | |
402 GDK_THREADS_LEAVE(); | |
403 while (g_main_context_iteration(NULL, FALSE)); | |
404 GDK_THREADS_ENTER(); | |
405 } | |
406 g_module_close(ip->handle); | |
407 } | |
408 | |
2623 | 409 if (ip_data.input_list != NULL) |
410 { | |
2313 | 411 g_list_free(ip_data.input_list); |
2623 | 412 ip_data.input_list = NULL; |
413 } | |
2313 | 414 |
415 for (node = get_output_list(); node; node = g_list_next(node)) { | |
416 op = OUTPUT_PLUGIN(node->data); | |
417 if (op && op->cleanup) { | |
418 op->cleanup(); | |
419 GDK_THREADS_LEAVE(); | |
420 while (g_main_context_iteration(NULL, FALSE)); | |
421 GDK_THREADS_ENTER(); | |
422 } | |
423 g_module_close(op->handle); | |
424 } | |
425 | |
2623 | 426 if (op_data.output_list != NULL) |
427 { | |
2313 | 428 g_list_free(op_data.output_list); |
2623 | 429 op_data.output_list = NULL; |
430 } | |
2313 | 431 |
432 for (node = get_effect_list(); node; node = g_list_next(node)) { | |
433 ep = EFFECT_PLUGIN(node->data); | |
434 if (ep && ep->cleanup) { | |
435 ep->cleanup(); | |
436 GDK_THREADS_LEAVE(); | |
437 while (g_main_context_iteration(NULL, FALSE)); | |
438 GDK_THREADS_ENTER(); | |
439 } | |
440 g_module_close(ep->handle); | |
441 } | |
442 | |
2623 | 443 if (ep_data.effect_list != NULL) |
444 { | |
2313 | 445 g_list_free(ep_data.effect_list); |
2623 | 446 ep_data.effect_list = NULL; |
2313 | 447 } |
448 | |
449 for (node = get_general_list(); node; node = g_list_next(node)) { | |
450 gp = GENERAL_PLUGIN(node->data); | |
451 if (gp && gp->cleanup) { | |
452 gp->cleanup(); | |
453 GDK_THREADS_LEAVE(); | |
454 while (g_main_context_iteration(NULL, FALSE)); | |
455 GDK_THREADS_ENTER(); | |
456 } | |
457 g_module_close(gp->handle); | |
458 } | |
459 | |
2623 | 460 if (gp_data.general_list != NULL) |
461 { | |
2313 | 462 g_list_free(gp_data.general_list); |
2623 | 463 gp_data.general_list = NULL; |
2313 | 464 } |
465 | |
466 for (node = get_vis_list(); node; node = g_list_next(node)) { | |
467 vp = VIS_PLUGIN(node->data); | |
468 if (vp && vp->cleanup) { | |
469 vp->cleanup(); | |
470 GDK_THREADS_LEAVE(); | |
471 while (g_main_context_iteration(NULL, FALSE)); | |
472 GDK_THREADS_ENTER(); | |
473 } | |
474 g_module_close(vp->handle); | |
475 } | |
476 | |
2623 | 477 if (vp_data.vis_list != NULL) |
478 { | |
2313 | 479 g_list_free(vp_data.vis_list); |
2623 | 480 vp_data.vis_list = NULL; |
481 } | |
2313 | 482 |
483 for (node = lowlevel_list; node; node = g_list_next(node)) { | |
484 lp = LOWLEVEL_PLUGIN(node->data); | |
485 if (lp && lp->cleanup) { | |
486 lp->cleanup(); | |
487 GDK_THREADS_LEAVE(); | |
488 while (g_main_context_iteration(NULL, FALSE)); | |
489 GDK_THREADS_ENTER(); | |
490 } | |
491 g_module_close(lp->handle); | |
492 } | |
493 | |
2623 | 494 if (lowlevel_list != NULL) |
495 { | |
2313 | 496 g_list_free(lowlevel_list); |
2623 | 497 lowlevel_list = NULL; |
498 } | |
499 | |
500 /* XXX: vfs will crash otherwise. -nenolod */ | |
501 if (vfs_transports != NULL) | |
502 { | |
503 g_list_free(vfs_transports); | |
504 vfs_transports = NULL; | |
505 } | |
2682
c3cd6e47faf6
[svn] - make the evil 'reload plugins' button behave a bit better
giacomo
parents:
2624
diff
changeset
|
506 |
c3cd6e47faf6
[svn] - make the evil 'reload plugins' button behave a bit better
giacomo
parents:
2624
diff
changeset
|
507 g_hash_table_destroy( plugin_matrix ); |
2313 | 508 } |