From d0ca621a753e964b208b0aa853bcd08732b3b0c5 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Sat, 30 Jan 1999 18:35:52 +0000 Subject: [PATCH] Changes for auto loader.. --- include/control.h | 1 + src/control/cards.c | 24 ++++++++++++++++++++++-- src/control/control.c | 11 ++++++++--- src/mixer/mixer.c | 8 ++++++-- src/pcm/pcm.c | 8 ++++++-- src/pcm/pcm_loopback.c | 8 ++++++-- src/rawmidi/rawmidi.c | 8 ++++++-- src/seq/seq.c | 9 +++++++-- 8 files changed, 62 insertions(+), 15 deletions(-) diff --git a/include/control.h b/include/control.h index 7bc33f05..c5cd4c09 100644 --- a/include/control.h +++ b/include/control.h @@ -9,6 +9,7 @@ extern "C" { #endif +int snd_card_load(int card); int snd_cards(void); unsigned int snd_cards_mask(void); int snd_card_name(const char *name); diff --git a/src/control/cards.c b/src/control/cards.c index 2af073da..22821da5 100644 --- a/src/control/cards.c +++ b/src/control/cards.c @@ -30,6 +30,22 @@ #define SND_FILE_CONTROL "/dev/snd/control%i" +int snd_card_load(int card) +{ + int open_dev; + char control[32]; + char aload[32]; + + sprintf (control, "/dev/snd/control%d",card); + sprintf (aload, "/dev/aload%d", card); + + if ((open_dev=open(control, O_RDONLY)) < 0) { + close(open(aload, O_RDONLY)); + } else { + close (open_dev); + } +} + int snd_cards(void) { int idx, count; @@ -59,9 +75,13 @@ unsigned int snd_cards_mask(void) if (save_mask) return save_mask; for (idx = 0, mask = 0; idx < SND_CARDS; idx++) { + snd_card_load(idx); sprintf(filename, SND_FILE_CONTROL, idx); - if ((fd = open(filename, O_RDWR)) < 0) - continue; + if ((fd = open(filename, O_RDWR)) < 0) { + snd_card_load(idx); + if ((fd = open(filename, O_RDWR)) < 0) + continue; + } close(fd); mask |= 1 << idx; } diff --git a/src/control/control.c b/src/control/control.c index 520c1a12..90e32fa9 100644 --- a/src/control/control.c +++ b/src/control/control.c @@ -42,12 +42,17 @@ int snd_ctl_open(void **handle, int card) char filename[32]; snd_ctl_t *ctl; - *handle = NULL; + *handle = NULL; + if (card < 0 || card >= SND_CARDS) return -EINVAL; sprintf(filename, SND_FILE_CONTROL, card); - if ((fd = open(filename, O_RDWR)) < 0) - return -errno; + if ((fd = open(filename, O_RDWR)) < 0) { + snd_card_load(card); + if ((fd = open(filename, O_RDWR)) < 0) + return -errno; + } + if (ioctl(fd, SND_CTL_IOCTL_PVERSION, &ver) < 0) { close(fd); return -errno; diff --git a/src/mixer/mixer.c b/src/mixer/mixer.c index 8d38b4ed..fedfd80d 100644 --- a/src/mixer/mixer.c +++ b/src/mixer/mixer.c @@ -44,11 +44,15 @@ int snd_mixer_open(void **handle, int card, int device) snd_mixer_t *mixer; *handle = NULL; + if (card < 0 || card >= SND_CARDS) return -EINVAL; sprintf(filename, SND_FILE_MIXER, card, device); - if ((fd = open(filename, O_RDWR)) < 0) - return -errno; + if ((fd = open(filename, O_RDWR)) < 0) { + snd_card_load(card); + if ((fd = open(filename, O_RDWR)) < 0) + return -errno; + } if (ioctl(fd, SND_MIXER_IOCTL_PVERSION, &ver) < 0) { close(fd); return -errno; diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index 6640527a..88f18597 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -44,11 +44,15 @@ int snd_pcm_open(void **handle, int card, int device, int mode) snd_pcm_t *pcm; *handle = NULL; + if (card < 0 || card >= SND_CARDS) return -EINVAL; sprintf(filename, SND_FILE_PCM, card, device); - if ((fd = open(filename, mode)) < 0) - return -errno; + if ((fd = open(filename, mode)) < 0) { + snd_card_load(card); + if ((fd = open(filename, mode)) < 0) + return -errno; + } if (ioctl(fd, SND_PCM_IOCTL_PVERSION, &ver) < 0) { close(fd); return -errno; diff --git a/src/pcm/pcm_loopback.c b/src/pcm/pcm_loopback.c index 1e6aa38d..6db219c7 100644 --- a/src/pcm/pcm_loopback.c +++ b/src/pcm/pcm_loopback.c @@ -44,12 +44,16 @@ int snd_pcm_loopback_open(void **handle, int card, int device, int mode) snd_pcm_loopback_t *lb; *handle = NULL; + if (card < 0 || card >= SND_CARDS) return -EINVAL; sprintf(filename, SND_FILE_PCM_LB, card, device, mode == SND_PCM_LB_OPEN_RECORD ? "r" : "p"); - if ((fd = open(filename, mode)) < 0) - return -errno; + if ((fd = open(filename, mode)) < 0) { + snd_card_load(card); + if ((fd = open(filename, mode)) < 0) + return -errno; + } if (ioctl(fd, SND_PCM_IOCTL_PVERSION, &ver) < 0) { close(fd); return -errno; diff --git a/src/rawmidi/rawmidi.c b/src/rawmidi/rawmidi.c index 0af624d6..6b3ac9a5 100644 --- a/src/rawmidi/rawmidi.c +++ b/src/rawmidi/rawmidi.c @@ -44,11 +44,15 @@ int snd_rawmidi_open(void **handle, int card, int device, int mode) snd_rawmidi_t *rmidi; *handle = NULL; + if (card < 0 || card >= SND_CARDS) return -EINVAL; sprintf(filename, SND_FILE_RAWMIDI, card, device); - if ((fd = open(filename, mode)) < 0) - return -errno; + if ((fd = open(filename, mode)) < 0) { + snd_card_load(card); + if ((fd = open(filename, mode)) < 0) + return -errno; + } if (ioctl(fd, SND_RAWMIDI_IOCTL_PVERSION, &ver) < 0) { close(fd); return -errno; diff --git a/src/seq/seq.c b/src/seq/seq.c index a88497a2..31b538ca 100644 --- a/src/seq/seq.c +++ b/src/seq/seq.c @@ -60,9 +60,14 @@ int snd_seq_open(void **handle, int mode) snd_seq_t *seq; *handle = NULL; + sprintf(filename, SND_FILE_SEQ); - if ((fd = open(filename, mode)) < 0) - return -errno; + if ((fd = open(filename, mode)) < 0) { + /* try load all soundcard modules */ + snd_cards_mask(); + if ((fd = open(filename, mode)) < 0) + return -errno; + } if (ioctl(fd, SND_SEQ_IOCTL_PVERSION, &ver) < 0) { close(fd); return -errno; -- 2.47.1