Extend snd_card_get_index() to accept also control device name like /dev/snd/controlC0
authorJaroslav Kysela <perex@perex.cz>
Tue, 12 May 2009 06:06:41 +0000 (08:06 +0200)
committerJaroslav Kysela <perex@perex.cz>
Tue, 12 May 2009 06:06:41 +0000 (08:06 +0200)
Signed-off-by: Jaroslav Kysela <perex@perex.cz>

src/control/cards.c

index 4d2c739..aec823e 100644 (file)
 #define SND_FILE_LOAD          ALOAD_DEVICE_DIRECTORY "aloadC%i"
 #endif
 
-static int snd_card_load1(int card)
+static int snd_card_load2(const char *control)
 {
        int open_dev;
+       snd_ctl_card_info_t info;
+
+       open_dev = snd_open_device(control, O_RDONLY);
+       if (open_dev >= 0) {
+               if (ioctl(open_dev, SNDRV_CTL_IOCTL_CARD_INFO, &info) < 0) {
+                       int err = -errno;
+                       close(open_dev);
+                       return err;
+               }
+               close(open_dev);
+               return info.card;
+       } else {
+               return -errno;
+       }
+}
+
+static int snd_card_load1(int card)
+{
+       int res;
        char control[sizeof(SND_FILE_CONTROL) + 10];
 
        sprintf(control, SND_FILE_CONTROL, card);
-
-       open_dev = snd_open_device(control, O_RDONLY);
+       res = snd_card_load2(control);
 #ifdef SUPPORT_ALOAD
-       if (open_dev < 0) {
+       if (res < 0) {
                char aload[sizeof(SND_FILE_LOAD) + 10];
                sprintf(aload, SND_FILE_LOAD, card);
-               open_dev = snd_open_device(aload, O_RDONLY);
+               res = snd_card_load2(aload);
        }
 #endif
-       if (open_dev >= 0) {
-               close (open_dev);
-               return 0;
-       } else {
-               return -errno;
-       }
+       return res;
 }
 
 /**
@@ -127,6 +140,8 @@ int snd_card_get_index(const char *string)
                        return card;
                return err;
        }
+       if (string[0] == '/')   /* device name */
+               return snd_card_load2(string);
        for (card = 0; card < 32; card++) {
 #ifdef SUPPORT_ALOAD
                if (! snd_card_load(card))