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