Mercurial > audlegacy
annotate src/audacious/pluginenum.c @ 2709:47ea8eedd428 trunk
[svn] - drop controlsocket code. this probably does not compile yet.
| author | nenolod |
|---|---|
| date | Wed, 09 May 2007 14:03:11 -0700 |
| parents | c3cd6e47faf6 |
| children | c35913222440 |
| 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); | |
|
2709
47ea8eedd428
[svn] - drop controlsocket code. this probably does not compile yet.
nenolod
parents:
2682
diff
changeset
|
175 p->xmms_session = -1; |
| 2313 | 176 gp_data.general_list = g_list_append(gp_data.general_list, p); |
| 177 } | |
| 178 | |
| 179 static void | |
| 180 vis_plugin_init(Plugin * plugin) | |
| 181 { | |
| 182 VisPlugin *p = VIS_PLUGIN(plugin); | |
|
2709
47ea8eedd428
[svn] - drop controlsocket code. this probably does not compile yet.
nenolod
parents:
2682
diff
changeset
|
183 p->xmms_session = -1; |
| 2313 | 184 p->disable_plugin = vis_disable_plugin; |
| 185 vp_data.vis_list = g_list_append(vp_data.vis_list, p); | |
| 186 } | |
| 187 | |
| 188 static void | |
| 189 lowlevel_plugin_init(Plugin * plugin) | |
| 190 { | |
| 191 LowlevelPlugin *p = LOWLEVEL_PLUGIN(plugin); | |
| 192 lowlevel_list = g_list_append(lowlevel_list, p); | |
| 193 } | |
| 194 | |
| 195 /* FIXME: Placed here (hopefully) temporarily - descender */ | |
| 196 | |
| 197 typedef struct { | |
| 198 const gchar *name; | |
| 199 const gchar *id; | |
| 200 void (*init)(Plugin *); | |
| 201 } PluginType; | |
| 202 | |
| 203 static PluginType plugin_types[] = { | |
| 204 { "input" , "get_iplugin_info", input_plugin_init }, | |
| 205 { "output" , "get_oplugin_info", output_plugin_init }, | |
| 206 { "effect" , "get_eplugin_info", effect_plugin_init }, | |
| 207 { "general" , "get_gplugin_info", general_plugin_init }, | |
| 208 { "visualization", "get_vplugin_info", vis_plugin_init }, | |
| 209 { "lowlevel" , "get_lplugin_info", lowlevel_plugin_init }, | |
| 210 { NULL, NULL, NULL } | |
| 211 }; | |
| 212 | |
| 213 static void | |
| 214 add_plugin(const gchar * filename) | |
| 215 { | |
| 216 PluginType *type; | |
| 217 GModule *module; | |
| 218 gpointer func; | |
| 219 | |
| 220 if (plugin_is_duplicate(filename)) | |
| 221 return; | |
| 222 | |
| 2623 | 223 g_message("Loaded plugin (%s)", filename); |
| 224 | |
| 2313 | 225 if (!(module = g_module_open(filename, G_MODULE_BIND_LOCAL))) { |
| 226 printf("Failed to load plugin (%s): %s\n", | |
| 227 filename, g_module_error()); | |
| 228 return; | |
| 229 } | |
| 230 | |
| 231 for (type = plugin_types; type->name; type++) | |
| 232 { | |
| 233 if (g_module_symbol(module, type->id, &func)) { | |
| 234 Plugin *plugin = PLUGIN_GET_INFO(func); | |
| 235 | |
| 236 plugin->handle = module; | |
| 237 plugin->filename = g_strdup(filename); | |
| 238 type->init(PLUGIN_GET_INFO(func)); | |
| 239 | |
| 240 return; | |
| 241 } | |
| 242 } | |
| 243 | |
| 244 printf("Invalid plugin (%s)\n", filename); | |
| 245 g_module_close(module); | |
| 246 } | |
| 247 | |
| 248 static gboolean | |
| 249 scan_plugin_func(const gchar * path, const gchar * basename, gpointer data) | |
| 250 { | |
| 251 if (!str_has_suffix_nocase(basename, SHARED_SUFFIX)) | |
| 252 return FALSE; | |
| 253 | |
| 254 if (!g_file_test(path, G_FILE_TEST_IS_REGULAR)) | |
| 255 return FALSE; | |
| 256 | |
| 257 add_plugin(path); | |
| 258 | |
| 259 return FALSE; | |
| 260 } | |
| 261 | |
| 262 static void | |
| 263 scan_plugins(const gchar * path) | |
| 264 { | |
| 265 dir_foreach(path, scan_plugin_func, NULL, NULL); | |
| 266 } | |
| 267 | |
| 268 void | |
| 269 plugin_system_init(void) | |
| 270 { | |
| 271 gchar *dir, **disabled; | |
| 272 GList *node; | |
| 273 OutputPlugin *op; | |
| 274 InputPlugin *ip; | |
| 275 LowlevelPlugin *lp; | |
| 276 gint dirsel = 0, i = 0; | |
| 277 | |
| 278 if (!g_module_supported()) { | |
| 279 report_error("Module loading not supported! Plugins will not be loaded.\n"); | |
| 280 return; | |
| 281 } | |
| 282 | |
|
2624
840fb578a834
[svn] - [security, backport to 1.3] fix improper comparisons of hashtables used by the plugin loader.
nenolod
parents:
2623
diff
changeset
|
283 plugin_matrix = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, |
| 2313 | 284 NULL); |
| 285 | |
| 286 #ifndef DISABLE_USER_PLUGIN_DIR | |
| 287 scan_plugins(bmp_paths[BMP_PATH_USER_PLUGIN_DIR]); | |
| 288 /* | |
| 289 * This is in a separate loop so if the user puts them in the | |
| 290 * wrong dir we'll still get them in the right order (home dir | |
| 291 * first) - Zinx | |
| 292 */ | |
| 293 while (plugin_dir_list[dirsel]) { | |
| 294 dir = g_build_filename(bmp_paths[BMP_PATH_USER_PLUGIN_DIR], | |
| 295 plugin_dir_list[dirsel++], NULL); | |
| 296 scan_plugins(dir); | |
| 297 g_free(dir); | |
| 298 } | |
| 299 dirsel = 0; | |
| 300 #endif | |
| 301 | |
| 302 while (plugin_dir_list[dirsel]) { | |
| 303 dir = g_build_filename(PLUGIN_DIR, plugin_dir_list[dirsel++], NULL); | |
| 304 scan_plugins(dir); | |
| 305 g_free(dir); | |
| 306 } | |
| 307 | |
| 308 op_data.output_list = g_list_sort(op_data.output_list, outputlist_compare_func); | |
| 309 if (!op_data.current_output_plugin | |
| 310 && g_list_length(op_data.output_list)) { | |
| 311 op_data.current_output_plugin = op_data.output_list->data; | |
| 312 } | |
| 313 | |
| 314 ip_data.input_list = g_list_sort(ip_data.input_list, inputlist_compare_func); | |
| 315 | |
| 316 ep_data.effect_list = g_list_sort(ep_data.effect_list, effectlist_compare_func); | |
| 317 ep_data.enabled_list = NULL; | |
| 318 | |
| 319 gp_data.general_list = g_list_sort(gp_data.general_list, generallist_compare_func); | |
| 320 gp_data.enabled_list = NULL; | |
| 321 | |
| 322 vp_data.vis_list = g_list_sort(vp_data.vis_list, vislist_compare_func); | |
| 323 vp_data.enabled_list = NULL; | |
| 324 | |
| 325 general_enable_from_stringified_list(cfg.enabled_gplugins); | |
| 326 vis_enable_from_stringified_list(cfg.enabled_vplugins); | |
| 327 effect_enable_from_stringified_list(cfg.enabled_eplugins); | |
| 328 | |
| 329 g_free(cfg.enabled_gplugins); | |
| 330 cfg.enabled_gplugins = NULL; | |
| 331 | |
| 332 g_free(cfg.enabled_vplugins); | |
| 333 cfg.enabled_vplugins = NULL; | |
| 334 | |
| 335 g_free(cfg.enabled_eplugins); | |
| 336 cfg.enabled_eplugins = NULL; | |
| 337 | |
| 338 for (node = op_data.output_list; node; node = g_list_next(node)) { | |
| 339 op = OUTPUT_PLUGIN(node->data); | |
| 340 /* | |
| 341 * Only test basename to avoid problems when changing | |
| 342 * prefix. We will only see one plugin with the same | |
| 343 * basename, so this is usually what the user want. | |
| 344 */ | |
| 345 if (!strcmp(g_basename(cfg.outputplugin), g_basename(op->filename))) | |
| 346 op_data.current_output_plugin = op; | |
| 347 if (op->init) | |
| 348 op->init(); | |
| 349 } | |
| 350 | |
| 351 for (node = ip_data.input_list; node; node = g_list_next(node)) { | |
| 352 ip = INPUT_PLUGIN(node->data); | |
| 353 if (ip->init) | |
| 354 ip->init(); | |
| 355 } | |
| 356 | |
| 357 for (node = lowlevel_list; node; node = g_list_next(node)) { | |
| 358 lp = LOWLEVEL_PLUGIN(node->data); | |
| 359 if (lp->init) | |
| 360 lp->init(); | |
| 361 } | |
| 362 | |
| 363 if (cfg.disabled_iplugins) { | |
| 364 disabled = g_strsplit(cfg.disabled_iplugins, ":", 0); | |
| 365 while (disabled[i]) { | |
| 366 g_hash_table_replace(plugin_matrix, disabled[i], | |
| 367 GINT_TO_POINTER(FALSE)); | |
| 368 i++; | |
| 369 } | |
| 370 | |
| 371 g_free(disabled); | |
| 372 | |
| 373 g_free(cfg.disabled_iplugins); | |
| 374 cfg.disabled_iplugins = NULL; | |
| 375 } | |
| 376 } | |
| 377 | |
| 378 void | |
| 379 plugin_system_cleanup(void) | |
| 380 { | |
| 381 InputPlugin *ip; | |
| 382 OutputPlugin *op; | |
| 383 EffectPlugin *ep; | |
| 384 GeneralPlugin *gp; | |
| 385 VisPlugin *vp; | |
| 386 LowlevelPlugin *lp; | |
| 387 GList *node; | |
| 388 | |
| 389 g_message("Shutting down plugin system"); | |
| 390 | |
| 391 if (playback_get_playing()) { | |
| 392 ip_data.stop = TRUE; | |
| 393 playback_stop(); | |
| 394 ip_data.stop = FALSE; | |
| 395 } | |
| 396 | |
| 2623 | 397 /* FIXME: race condition -nenolod */ |
| 398 op_data.current_output_plugin = NULL; | |
| 399 | |
| 2313 | 400 for (node = get_input_list(); node; node = g_list_next(node)) { |
| 401 ip = INPUT_PLUGIN(node->data); | |
| 402 if (ip && ip->cleanup) { | |
| 403 ip->cleanup(); | |
| 404 GDK_THREADS_LEAVE(); | |
| 405 while (g_main_context_iteration(NULL, FALSE)); | |
| 406 GDK_THREADS_ENTER(); | |
| 407 } | |
| 408 g_module_close(ip->handle); | |
| 409 } | |
| 410 | |
| 2623 | 411 if (ip_data.input_list != NULL) |
| 412 { | |
| 2313 | 413 g_list_free(ip_data.input_list); |
| 2623 | 414 ip_data.input_list = NULL; |
| 415 } | |
| 2313 | 416 |
| 417 for (node = get_output_list(); node; node = g_list_next(node)) { | |
| 418 op = OUTPUT_PLUGIN(node->data); | |
| 419 if (op && op->cleanup) { | |
| 420 op->cleanup(); | |
| 421 GDK_THREADS_LEAVE(); | |
| 422 while (g_main_context_iteration(NULL, FALSE)); | |
| 423 GDK_THREADS_ENTER(); | |
| 424 } | |
| 425 g_module_close(op->handle); | |
| 426 } | |
| 427 | |
| 2623 | 428 if (op_data.output_list != NULL) |
| 429 { | |
| 2313 | 430 g_list_free(op_data.output_list); |
| 2623 | 431 op_data.output_list = NULL; |
| 432 } | |
| 2313 | 433 |
| 434 for (node = get_effect_list(); node; node = g_list_next(node)) { | |
| 435 ep = EFFECT_PLUGIN(node->data); | |
| 436 if (ep && ep->cleanup) { | |
| 437 ep->cleanup(); | |
| 438 GDK_THREADS_LEAVE(); | |
| 439 while (g_main_context_iteration(NULL, FALSE)); | |
| 440 GDK_THREADS_ENTER(); | |
| 441 } | |
| 442 g_module_close(ep->handle); | |
| 443 } | |
| 444 | |
| 2623 | 445 if (ep_data.effect_list != NULL) |
| 446 { | |
| 2313 | 447 g_list_free(ep_data.effect_list); |
| 2623 | 448 ep_data.effect_list = NULL; |
| 2313 | 449 } |
| 450 | |
| 451 for (node = get_general_list(); node; node = g_list_next(node)) { | |
| 452 gp = GENERAL_PLUGIN(node->data); | |
| 453 if (gp && gp->cleanup) { | |
| 454 gp->cleanup(); | |
| 455 GDK_THREADS_LEAVE(); | |
| 456 while (g_main_context_iteration(NULL, FALSE)); | |
| 457 GDK_THREADS_ENTER(); | |
| 458 } | |
| 459 g_module_close(gp->handle); | |
| 460 } | |
| 461 | |
| 2623 | 462 if (gp_data.general_list != NULL) |
| 463 { | |
| 2313 | 464 g_list_free(gp_data.general_list); |
| 2623 | 465 gp_data.general_list = NULL; |
| 2313 | 466 } |
| 467 | |
| 468 for (node = get_vis_list(); node; node = g_list_next(node)) { | |
| 469 vp = VIS_PLUGIN(node->data); | |
| 470 if (vp && vp->cleanup) { | |
| 471 vp->cleanup(); | |
| 472 GDK_THREADS_LEAVE(); | |
| 473 while (g_main_context_iteration(NULL, FALSE)); | |
| 474 GDK_THREADS_ENTER(); | |
| 475 } | |
| 476 g_module_close(vp->handle); | |
| 477 } | |
| 478 | |
| 2623 | 479 if (vp_data.vis_list != NULL) |
| 480 { | |
| 2313 | 481 g_list_free(vp_data.vis_list); |
| 2623 | 482 vp_data.vis_list = NULL; |
| 483 } | |
| 2313 | 484 |
| 485 for (node = lowlevel_list; node; node = g_list_next(node)) { | |
| 486 lp = LOWLEVEL_PLUGIN(node->data); | |
| 487 if (lp && lp->cleanup) { | |
| 488 lp->cleanup(); | |
| 489 GDK_THREADS_LEAVE(); | |
| 490 while (g_main_context_iteration(NULL, FALSE)); | |
| 491 GDK_THREADS_ENTER(); | |
| 492 } | |
| 493 g_module_close(lp->handle); | |
| 494 } | |
| 495 | |
| 2623 | 496 if (lowlevel_list != NULL) |
| 497 { | |
| 2313 | 498 g_list_free(lowlevel_list); |
| 2623 | 499 lowlevel_list = NULL; |
| 500 } | |
| 501 | |
| 502 /* XXX: vfs will crash otherwise. -nenolod */ | |
| 503 if (vfs_transports != NULL) | |
| 504 { | |
| 505 g_list_free(vfs_transports); | |
| 506 vfs_transports = NULL; | |
| 507 } | |
|
2682
c3cd6e47faf6
[svn] - make the evil 'reload plugins' button behave a bit better
giacomo
parents:
2624
diff
changeset
|
508 |
|
c3cd6e47faf6
[svn] - make the evil 'reload plugins' button behave a bit better
giacomo
parents:
2624
diff
changeset
|
509 g_hash_table_destroy( plugin_matrix ); |
| 2313 | 510 } |
