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