Mercurial > audlegacy
annotate audacious/pluginenum.c @ 1563:c4640c88942d trunk
[svn] - lowlevel plugin stuff
| author | nenolod |
|---|---|
| date | Thu, 10 Aug 2006 20:35:10 -0700 |
| parents | 411b4aaf928b |
| children | e513069caf71 |
| 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 |
| 0 | 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 | |
| 1459 | 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 0 | 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> | |
| 32 | |
| 33 #include "controlsocket.h" | |
| 34 #include "main.h" | |
|
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
687
diff
changeset
|
35 #include "mainwin.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; | |
| 1563 | 52 GList *lowlevel_list = NULL; |
| 0 | 53 |
| 54 static gint | |
| 55 inputlist_compare_func(gconstpointer a, gconstpointer b) | |
| 56 { | |
| 57 const InputPlugin *ap = a, *bp = b; | |
| 58 return strcasecmp(ap->description, bp->description); | |
| 59 } | |
| 60 | |
| 61 static gint | |
| 62 outputlist_compare_func(gconstpointer a, gconstpointer b) | |
| 63 { | |
| 64 const OutputPlugin *ap = a, *bp = b; | |
| 65 return strcasecmp(ap->description, bp->description); | |
| 66 } | |
| 67 | |
| 68 static gint | |
| 69 effectlist_compare_func(gconstpointer a, gconstpointer b) | |
| 70 { | |
| 71 const EffectPlugin *ap = a, *bp = b; | |
| 72 return strcasecmp(ap->description, bp->description); | |
| 73 } | |
| 74 | |
| 75 static gint | |
| 76 generallist_compare_func(gconstpointer a, gconstpointer b) | |
| 77 { | |
| 78 const GeneralPlugin *ap = a, *bp = b; | |
| 79 return strcasecmp(ap->description, bp->description); | |
| 80 } | |
| 81 | |
| 82 static gint | |
| 83 vislist_compare_func(gconstpointer a, gconstpointer b) | |
| 84 { | |
| 85 const VisPlugin *ap = a, *bp = b; | |
| 86 return strcasecmp(ap->description, bp->description); | |
| 87 } | |
| 88 | |
| 89 static gboolean | |
| 90 plugin_is_duplicate(const gchar * filename) | |
| 91 { | |
| 92 GList *l; | |
| 93 const gchar *basename = g_basename(filename); | |
| 94 | |
| 95 /* FIXME: messy stuff */ | |
| 96 | |
| 97 for (l = ip_data.input_list; l; l = g_list_next(l)) | |
| 98 if (!strcmp(basename, g_basename(INPUT_PLUGIN(l->data)->filename))) | |
| 99 return TRUE; | |
| 100 | |
| 101 for (l = op_data.output_list; l; l = g_list_next(l)) | |
| 102 if (!strcmp(basename, g_basename(OUTPUT_PLUGIN(l->data)->filename))) | |
| 103 return TRUE; | |
| 104 | |
| 105 for (l = ep_data.effect_list; l; l = g_list_next(l)) | |
| 106 if (!strcmp(basename, g_basename(EFFECT_PLUGIN(l->data)->filename))) | |
| 107 return TRUE; | |
| 108 | |
| 109 for (l = gp_data.general_list; l; l = g_list_next(l)) | |
| 110 if (!strcmp(basename, g_basename(GENERAL_PLUGIN(l->data)->filename))) | |
| 111 return TRUE; | |
| 112 | |
| 113 for (l = vp_data.vis_list; l; l = g_list_next(l)) | |
| 114 if (!strcmp(basename, g_basename(VIS_PLUGIN(l->data)->filename))) | |
| 115 return TRUE; | |
| 116 | |
| 1563 | 117 for (l = lowlevel_list; l; l = g_list_next(l)) |
| 118 if (!strcmp(basename, g_basename(VIS_PLUGIN(l->data)->filename))) | |
| 119 return TRUE; | |
| 120 | |
| 0 | 121 return FALSE; |
| 122 } | |
| 123 | |
| 124 | |
| 125 #define PLUGIN_GET_INFO(x) ((PluginGetInfoFunc)(x))() | |
| 126 typedef Plugin * (*PluginGetInfoFunc) (void); | |
| 127 | |
| 128 static void | |
| 129 input_plugin_init(Plugin * plugin) | |
| 130 { | |
| 131 InputPlugin *p = INPUT_PLUGIN(plugin); | |
| 132 | |
| 133 p->get_vis_type = input_get_vis_type; | |
| 134 p->add_vis_pcm = input_add_vis_pcm; | |
| 135 | |
| 136 /* Pretty const casts courtesy of XMMS's plugin.h legacy. Anyone | |
| 137 else thinks we could use a CONST macro to solve the warnings? | |
| 138 - descender */ | |
| 139 p->set_info = (void (*)(gchar *, gint, gint, gint, gint)) playlist_set_info; | |
| 140 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
|
141 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
|
142 |
| 0 | 143 ip_data.input_list = g_list_append(ip_data.input_list, p); |
| 144 | |
| 145 g_hash_table_replace(plugin_matrix, g_path_get_basename(p->filename), | |
| 146 GINT_TO_POINTER(1)); | |
| 147 } | |
| 148 | |
| 149 static void | |
| 150 output_plugin_init(Plugin * plugin) | |
| 151 { | |
| 152 OutputPlugin *p = OUTPUT_PLUGIN(plugin); | |
| 153 op_data.output_list = g_list_append(op_data.output_list, p); | |
| 154 } | |
| 155 | |
| 156 static void | |
| 157 effect_plugin_init(Plugin * plugin) | |
| 158 { | |
| 159 EffectPlugin *p = EFFECT_PLUGIN(plugin); | |
| 160 ep_data.effect_list = g_list_append(ep_data.effect_list, p); | |
| 161 } | |
| 162 | |
| 163 static void | |
| 164 general_plugin_init(Plugin * plugin) | |
| 165 { | |
| 166 GeneralPlugin *p = GENERAL_PLUGIN(plugin); | |
| 167 p->xmms_session = ctrlsocket_get_session_id(); | |
| 168 gp_data.general_list = g_list_append(gp_data.general_list, p); | |
| 169 } | |
| 170 | |
| 171 static void | |
| 172 vis_plugin_init(Plugin * plugin) | |
| 173 { | |
| 174 VisPlugin *p = VIS_PLUGIN(plugin); | |
| 175 p->xmms_session = ctrlsocket_get_session_id(); | |
| 176 p->disable_plugin = vis_disable_plugin; | |
| 177 vp_data.vis_list = g_list_append(vp_data.vis_list, p); | |
| 178 } | |
| 179 | |
| 1563 | 180 static void |
| 181 lowlevel_plugin_init(Plugin * plugin) | |
| 182 { | |
| 183 LowlevelPlugin *p = LOWLEVEL_PLUGIN(plugin); | |
| 184 lowlevel_list = g_list_append(lowlevel_list, p); | |
| 185 } | |
| 0 | 186 |
| 187 /* FIXME: Placed here (hopefully) temporarily - descender */ | |
| 188 | |
| 189 typedef struct { | |
| 190 const gchar *name; | |
| 191 const gchar *id; | |
| 192 void (*init)(Plugin *); | |
| 193 } PluginType; | |
| 194 | |
| 195 static PluginType plugin_types[] = { | |
| 196 { "input" , "get_iplugin_info", input_plugin_init }, | |
| 197 { "output" , "get_oplugin_info", output_plugin_init }, | |
| 198 { "effect" , "get_eplugin_info", effect_plugin_init }, | |
| 199 { "general" , "get_gplugin_info", general_plugin_init }, | |
| 200 { "visualization", "get_vplugin_info", vis_plugin_init }, | |
| 1563 | 201 { "lowlevel" , "get_lplugin_info", lowlevel_plugin_init }, |
| 0 | 202 { NULL, NULL, NULL } |
| 203 }; | |
| 204 | |
| 205 static void | |
| 206 add_plugin(const gchar * filename) | |
| 207 { | |
| 208 PluginType *type; | |
| 209 GModule *module; | |
| 210 gpointer func; | |
| 211 | |
| 212 if (plugin_is_duplicate(filename)) | |
| 213 return; | |
| 214 | |
| 834 | 215 if (!(module = g_module_open(filename, 0))) { |
| 12 | 216 printf("Failed to load plugin (%s): %s\n", |
| 0 | 217 filename, g_module_error()); |
| 218 return; | |
| 219 } | |
| 220 | |
| 221 for (type = plugin_types; type->name; type++) | |
| 222 { | |
| 223 if (g_module_symbol(module, type->id, &func)) { | |
| 224 Plugin *plugin = PLUGIN_GET_INFO(func); | |
| 225 | |
| 226 plugin->handle = module; | |
| 227 plugin->filename = g_strdup(filename); | |
| 228 type->init(PLUGIN_GET_INFO(func)); | |
| 229 | |
| 230 return; | |
| 231 } | |
| 232 } | |
| 233 | |
| 12 | 234 printf("Invalid plugin (%s)\n", filename); |
| 0 | 235 g_module_close(module); |
| 236 } | |
| 237 | |
| 238 static gboolean | |
| 239 scan_plugin_func(const gchar * path, const gchar * basename, gpointer data) | |
| 240 { | |
| 241 if (!str_has_suffix_nocase(basename, G_MODULE_SUFFIX)) | |
| 242 return FALSE; | |
| 243 | |
| 244 if (!g_file_test(path, G_FILE_TEST_IS_REGULAR)) | |
| 245 return FALSE; | |
| 246 | |
| 247 add_plugin(path); | |
| 248 | |
| 249 return FALSE; | |
| 250 } | |
| 251 | |
| 252 static void | |
| 253 scan_plugins(const gchar * path) | |
| 254 { | |
| 255 dir_foreach(path, scan_plugin_func, NULL, NULL); | |
| 256 } | |
| 257 | |
| 258 void | |
| 259 plugin_system_init(void) | |
| 260 { | |
| 261 gchar *dir, **disabled; | |
| 262 GList *node; | |
| 263 OutputPlugin *op; | |
| 264 InputPlugin *ip; | |
| 265 gint dirsel = 0, i = 0; | |
| 266 | |
| 267 if (!g_module_supported()) { | |
|
781
12c47704b4b5
[svn] Add error reporting for many places, patch by external contributor Derek
nenolod
parents:
687
diff
changeset
|
268 report_error("Module loading not supported! Plugins will not be loaded.\n"); |
| 0 | 269 return; |
| 270 } | |
| 271 | |
| 272 plugin_matrix = g_hash_table_new_full(g_str_hash, g_int_equal, g_free, | |
| 273 NULL); | |
| 274 | |
| 275 #ifndef DISABLE_USER_PLUGIN_DIR | |
| 276 scan_plugins(bmp_paths[BMP_PATH_USER_PLUGIN_DIR]); | |
| 277 /* | |
| 278 * This is in a separate loop so if the user puts them in the | |
| 279 * wrong dir we'll still get them in the right order (home dir | |
| 280 * first) - Zinx | |
| 281 */ | |
| 282 while (plugin_dir_list[dirsel]) { | |
| 283 dir = g_build_filename(bmp_paths[BMP_PATH_USER_PLUGIN_DIR], | |
| 284 plugin_dir_list[dirsel++], NULL); | |
| 285 scan_plugins(dir); | |
| 286 g_free(dir); | |
| 287 } | |
| 288 dirsel = 0; | |
| 289 #endif | |
| 290 | |
| 291 while (plugin_dir_list[dirsel]) { | |
| 292 dir = g_build_filename(PLUGIN_DIR, plugin_dir_list[dirsel++], NULL); | |
| 293 scan_plugins(dir); | |
| 294 g_free(dir); | |
| 295 } | |
| 296 | |
| 297 op_data.output_list = g_list_sort(op_data.output_list, outputlist_compare_func); | |
| 298 if (!op_data.current_output_plugin | |
| 299 && g_list_length(op_data.output_list)) { | |
| 300 op_data.current_output_plugin = op_data.output_list->data; | |
| 301 } | |
| 302 | |
| 303 ip_data.input_list = g_list_sort(ip_data.input_list, inputlist_compare_func); | |
| 304 | |
| 305 ep_data.effect_list = g_list_sort(ep_data.effect_list, effectlist_compare_func); | |
| 306 ep_data.enabled_list = NULL; | |
| 307 | |
| 308 gp_data.general_list = g_list_sort(gp_data.general_list, generallist_compare_func); | |
| 309 gp_data.enabled_list = NULL; | |
| 310 | |
| 311 vp_data.vis_list = g_list_sort(vp_data.vis_list, vislist_compare_func); | |
| 312 vp_data.enabled_list = NULL; | |
| 313 | |
| 314 general_enable_from_stringified_list(cfg.enabled_gplugins); | |
| 315 vis_enable_from_stringified_list(cfg.enabled_vplugins); | |
| 316 effect_enable_from_stringified_list(cfg.enabled_eplugins); | |
| 317 | |
| 318 g_free(cfg.enabled_gplugins); | |
| 319 cfg.enabled_gplugins = NULL; | |
| 320 | |
| 321 g_free(cfg.enabled_vplugins); | |
| 322 cfg.enabled_vplugins = NULL; | |
| 323 | |
| 324 g_free(cfg.enabled_eplugins); | |
| 325 cfg.enabled_eplugins = NULL; | |
| 326 | |
| 327 for (node = op_data.output_list; node; node = g_list_next(node)) { | |
| 328 op = OUTPUT_PLUGIN(node->data); | |
| 329 /* | |
| 330 * Only test basename to avoid problems when changing | |
| 331 * prefix. We will only see one plugin with the same | |
| 332 * basename, so this is usually what the user want. | |
| 333 */ | |
| 334 if (!strcmp(g_basename(cfg.outputplugin), g_basename(op->filename))) | |
| 335 op_data.current_output_plugin = op; | |
| 336 if (op->init) | |
| 337 op->init(); | |
| 338 } | |
| 339 | |
| 340 for (node = ip_data.input_list; node; node = g_list_next(node)) { | |
| 341 ip = INPUT_PLUGIN(node->data); | |
| 342 if (ip->init) | |
| 343 ip->init(); | |
| 344 } | |
| 345 | |
| 346 if (cfg.disabled_iplugins) { | |
| 347 disabled = g_strsplit(cfg.disabled_iplugins, ":", 0); | |
| 348 while (disabled[i]) { | |
| 349 g_hash_table_replace(plugin_matrix, disabled[i], | |
| 350 GINT_TO_POINTER(FALSE)); | |
| 351 i++; | |
| 352 } | |
| 353 | |
| 354 g_free(disabled); | |
| 355 | |
| 356 g_free(cfg.disabled_iplugins); | |
| 357 cfg.disabled_iplugins = NULL; | |
| 358 } | |
| 359 } | |
| 360 | |
| 361 void | |
| 362 plugin_system_cleanup(void) | |
| 363 { | |
| 364 InputPlugin *ip; | |
| 365 OutputPlugin *op; | |
| 366 EffectPlugin *ep; | |
| 367 GeneralPlugin *gp; | |
| 368 VisPlugin *vp; | |
| 1563 | 369 LowlevelPlugin *lp; |
| 0 | 370 GList *node; |
| 371 | |
| 372 g_message("Shutting down plugin system"); | |
| 373 | |
| 906 | 374 if (bmp_playback_get_playing()) { |
| 375 ip_data.stop = TRUE; | |
| 0 | 376 bmp_playback_stop(); |
| 906 | 377 ip_data.stop = FALSE; |
| 378 } | |
| 0 | 379 |
| 380 for (node = get_input_list(); node; node = g_list_next(node)) { | |
| 381 ip = INPUT_PLUGIN(node->data); | |
| 382 if (ip && ip->cleanup) { | |
| 383 ip->cleanup(); | |
| 384 GDK_THREADS_LEAVE(); | |
| 385 while (g_main_iteration(FALSE)); | |
| 386 GDK_THREADS_ENTER(); | |
| 387 } | |
| 388 g_module_close(ip->handle); | |
| 389 } | |
| 390 | |
| 391 if (ip_data.input_list) | |
| 392 g_list_free(ip_data.input_list); | |
| 393 | |
| 394 for (node = get_output_list(); node; node = g_list_next(node)) { | |
| 395 op = OUTPUT_PLUGIN(node->data); | |
| 309 | 396 if (op && op->cleanup) { |
| 397 op->cleanup(); | |
| 398 GDK_THREADS_LEAVE(); | |
| 399 while (g_main_iteration(FALSE)); | |
| 400 GDK_THREADS_ENTER(); | |
| 401 } | |
| 0 | 402 g_module_close(op->handle); |
| 403 } | |
| 404 | |
| 405 if (op_data.output_list) | |
| 406 g_list_free(op_data.output_list); | |
| 407 | |
| 408 for (node = get_effect_list(); node; node = g_list_next(node)) { | |
| 409 ep = EFFECT_PLUGIN(node->data); | |
| 410 if (ep && ep->cleanup) { | |
| 411 ep->cleanup(); | |
| 412 GDK_THREADS_LEAVE(); | |
| 413 while (g_main_iteration(FALSE)); | |
| 414 GDK_THREADS_ENTER(); | |
| 415 } | |
| 416 g_module_close(ep->handle); | |
| 417 } | |
| 418 | |
| 419 if (ep_data.effect_list) | |
| 420 g_list_free(ep_data.effect_list); | |
| 421 | |
| 422 for (node = get_general_enabled_list(); node; node = g_list_next(node)) { | |
| 423 gp = GENERAL_PLUGIN(node->data); | |
| 424 enable_general_plugin(g_list_index(gp_data.general_list, gp), FALSE); | |
| 425 } | |
| 426 | |
| 427 if (gp_data.enabled_list) | |
| 428 g_list_free(gp_data.enabled_list); | |
| 429 | |
| 430 GDK_THREADS_LEAVE(); | |
| 431 while (g_main_iteration(FALSE)); | |
| 432 GDK_THREADS_ENTER(); | |
| 433 | |
| 434 for (node = get_general_list(); node; node = g_list_next(node)) { | |
| 435 gp = GENERAL_PLUGIN(node->data); | |
|
650
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
436 if (gp && gp->cleanup) { |
|
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
437 gp->cleanup(); |
|
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
438 GDK_THREADS_LEAVE(); |
|
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
439 while (g_main_iteration(FALSE)); |
|
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
440 GDK_THREADS_ENTER(); |
|
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
441 } |
| 0 | 442 g_module_close(gp->handle); |
| 443 } | |
| 444 | |
| 445 if (gp_data.general_list) | |
| 446 g_list_free(gp_data.general_list); | |
| 447 | |
| 448 for (node = get_vis_enabled_list(); node; node = g_list_next(node)) { | |
| 449 vp = VIS_PLUGIN(node->data); | |
| 450 enable_vis_plugin(g_list_index(vp_data.vis_list, vp), FALSE); | |
| 451 } | |
| 452 | |
| 453 if (vp_data.enabled_list) | |
| 454 g_list_free(vp_data.enabled_list); | |
| 455 | |
| 456 GDK_THREADS_LEAVE(); | |
| 457 while (g_main_iteration(FALSE)); | |
| 458 GDK_THREADS_ENTER(); | |
| 459 | |
| 460 for (node = get_vis_list(); node; node = g_list_next(node)) { | |
| 461 vp = VIS_PLUGIN(node->data); | |
|
650
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
462 if (vp && vp->cleanup) { |
|
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
463 vp->cleanup(); |
|
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
464 GDK_THREADS_LEAVE(); |
|
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
465 while (g_main_iteration(FALSE)); |
|
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
466 GDK_THREADS_ENTER(); |
|
980d651da2fc
[svn] Actually use the cleanup hooks on general & visualization plugins.
chainsaw
parents:
538
diff
changeset
|
467 } |
| 0 | 468 g_module_close(vp->handle); |
| 469 } | |
| 470 | |
| 471 if (vp_data.vis_list) | |
| 472 g_list_free(vp_data.vis_list); | |
| 1563 | 473 |
| 474 for (node = lowlevel_list; node; node = g_list_next(node)) { | |
| 475 lp = LOWLEVEL_PLUGIN(node->data); | |
| 476 if (lp && lp->cleanup) { | |
| 477 lp->cleanup(); | |
| 478 GDK_THREADS_LEAVE(); | |
| 479 while (g_main_iteration(FALSE)); | |
| 480 GDK_THREADS_ENTER(); | |
| 481 } | |
| 482 g_module_close(lp->handle); | |
| 483 } | |
| 484 | |
| 485 if (lowlevel_list) | |
| 486 g_list_free(lowlevel_list); | |
| 0 | 487 } |
