# HG changeset patch # User Tony Vroon # Date 1235788453 0 # Node ID 8b7a446311210a21402bf4467ad5780c05f3f2ee # Parent bf2d87afa006631d4d154f88e1345aa4032e44f9 Add hardware_present probe for a meaningful return code. Probe priority 1. diff -r bf2d87afa006 -r 8b7a44631121 src/alsa/alsa.c --- a/src/alsa/alsa.c Sat Mar 28 17:29:21 2009 +0900 +++ b/src/alsa/alsa.c Sat Feb 28 02:34:13 2009 +0000 @@ -39,8 +39,14 @@ } -static void alsa_init(void) +static OutputPluginInitStatus alsa_init(void) { + if (dlopen("libasound.so.2", RTLD_NOW | RTLD_GLOBAL) == NULL) + { + g_message("Cannot load alsa library: %s", dlerror()); + return OUTPUT_PLUGIN_INIT_FAIL; + } + mcs_handle_t *cfgfile; memset(&alsa_cfg, 0, sizeof (alsa_cfg)); @@ -66,10 +72,11 @@ aud_cfg_db_get_bool(cfgfile, ALSA_CFGID, "debug", &alsa_cfg.debug); aud_cfg_db_close(cfgfile); - if (dlopen("libasound.so.2", RTLD_NOW | RTLD_GLOBAL) == NULL) + if (!alsa_hardware_present()) { - g_message("Cannot load alsa library: %s", dlerror()); - /* FIXME, this plugin wont work... */ + return OUTPUT_PLUGIN_INIT_NO_DEVICES; + } else { + return OUTPUT_PLUGIN_INIT_FOUND_DEVICES; } } @@ -77,6 +84,7 @@ static OutputPlugin alsa_op = { .description = "ALSA Output Plugin", + .probe_priority = 1, .init = alsa_init, .cleanup = alsa_cleanup, .about = alsa_about, diff -r bf2d87afa006 -r 8b7a44631121 src/alsa/alsa.h --- a/src/alsa/alsa.h Sat Mar 28 17:29:21 2009 +0900 +++ b/src/alsa/alsa.h Sat Feb 28 02:34:13 2009 +0000 @@ -57,6 +57,7 @@ void alsa_about(void); void alsa_configure(void); +gint alsa_hardware_present(void); gint alsa_get_mixer(snd_mixer_t **mixer, gint card); void alsa_save_config(void); diff -r bf2d87afa006 -r 8b7a44631121 src/alsa/audio.c --- a/src/alsa/audio.c Sat Mar 28 17:29:21 2009 +0900 +++ b/src/alsa/audio.c Sat Feb 28 02:34:13 2009 +0000 @@ -129,6 +129,16 @@ } } +int alsa_hardware_present(void) +{ + gint card = -1, err; + + if ((err = snd_card_next(&card)) != 0) + return 0; + + return 1; +} + int alsa_playing(void) { if (!going || paused || alsa_pcm == NULL)