mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-31 22:25:35 -04:00
Extend snd_card_get_index() to accept also control device name like /dev/snd/controlC0
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
3e30007a19
commit
33ab0b5381
1 changed files with 28 additions and 13 deletions
|
|
@ -39,29 +39,42 @@
|
|||
#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;
|
||||
char control[sizeof(SND_FILE_CONTROL) + 10];
|
||||
|
||||
sprintf(control, SND_FILE_CONTROL, card);
|
||||
snd_ctl_card_info_t info;
|
||||
|
||||
open_dev = snd_open_device(control, O_RDONLY);
|
||||
#ifdef SUPPORT_ALOAD
|
||||
if (open_dev < 0) {
|
||||
char aload[sizeof(SND_FILE_LOAD) + 10];
|
||||
sprintf(aload, SND_FILE_LOAD, card);
|
||||
open_dev = snd_open_device(aload, O_RDONLY);
|
||||
}
|
||||
#endif
|
||||
if (open_dev >= 0) {
|
||||
close (open_dev);
|
||||
return 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);
|
||||
res = snd_card_load2(control);
|
||||
#ifdef SUPPORT_ALOAD
|
||||
if (res < 0) {
|
||||
char aload[sizeof(SND_FILE_LOAD) + 10];
|
||||
sprintf(aload, SND_FILE_LOAD, card);
|
||||
res = snd_card_load2(aload);
|
||||
}
|
||||
#endif
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Try to load the driver for a card.
|
||||
* \param card Card number.
|
||||
|
|
@ -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))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue