changeset 3003:8b7a44631121

Add hardware_present probe for a meaningful return code. Probe priority 1.
author Tony Vroon <chainsaw@gentoo.org>
date Sat, 28 Feb 2009 02:34:13 +0000
parents bf2d87afa006
children 8867d3491f60
files src/alsa/alsa.c src/alsa/alsa.h src/alsa/audio.c
diffstat 3 files changed, 23 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- 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,
--- 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);
 
--- 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)