changeset 2398:684a26ccca54

check input fmt thoughtfully
author Eugene Zagidullin <e.asphyx@gmail.com>
date Sat, 16 Feb 2008 01:36:41 +0300
parents 763d8f49612b
children dd2c14a4c9f1
files src/alsa/audio.c
diffstat 1 files changed, 9 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/alsa/audio.c	Fri Feb 15 21:52:09 2008 +0900
+++ b/src/alsa/audio.c	Sat Feb 16 01:36:41 2008 +0300
@@ -80,7 +80,6 @@
 };
 
 static struct snd_format *inputf = NULL;
-static struct snd_format *effectf = NULL;
 static struct snd_format *outputf = NULL;
 
 static int alsa_setup(struct snd_format *f);
@@ -287,8 +286,6 @@
 
 	g_free(inputf);
 	inputf = NULL;
-	g_free(effectf);
-	effectf = NULL;
 	g_free(outputf);
 	outputf = NULL;
 
@@ -730,8 +727,7 @@
 int alsa_open(AFormat fmt, int rate, int nch)
 {
 	debug("Opening device");
-	inputf = snd_format_from_xmms(fmt, rate, nch);
-	effectf = snd_format_from_xmms(fmt, rate, nch);
+	if((inputf = snd_format_from_xmms(fmt, rate, nch)) == NULL) return 0;
 
 	if (alsa_cfg.debug)
 		snd_output_stdio_attach(&logs, stdout, 0);
@@ -779,6 +775,7 @@
 {
 	struct snd_format *f = g_malloc(sizeof(struct snd_format));
 	size_t i;
+        int found = 0;
 
 	f->xmms_format = fmt;
 	f->format = SND_PCM_FORMAT_UNKNOWN;
@@ -788,9 +785,15 @@
 		{
 			printf("match!\n");
 			f->format = format_table[i].alsa;
+                        found = 1;
 			break;
 		}
 
+        if(!found) {
+            g_free(f);
+            return NULL;
+        }
+
 	/* Get rid of _NE */
 	for (i = 0; i < sizeof(format_table) / sizeof(format_table[0]); i++)
 		if (format_table[i].alsa == f->format)
@@ -820,6 +823,7 @@
 
 	g_free(outputf);
 	outputf = snd_format_from_xmms(f->xmms_format, f->rate, f->channels);
+        if(outputf == NULL) return -1;
 
 	debug("Opening device: %s", alsa_cfg.pcm_device);
 	/* FIXME: Can snd_pcm_open() return EAGAIN? */