diff options
author | Mark Farrugia <mark.farrugia@fiberdyne.com.au> | 2019-01-30 17:50:49 +1100 |
---|---|---|
committer | Mark Farrugia <mark.farrugia@fiberdyne.com.au> | 2019-01-30 17:51:09 +1100 |
commit | c80e9f59a309f428c412c11bf207f186f89ce59e (patch) | |
tree | 19cbfdb14ef5b47abc041075e1adc79bbfe8ee03 | |
parent | 3205195333eb1435bdef8257e0d122c25d0b7e6f (diff) |
Add function to get the ALSA card index for an AVIRT card
From an AVIRT internal card index, we retrieve the ALSA card index.
Signed-off-by: Mark Farrugia <mark.farrugia@fiberdyne.com.au>
-rw-r--r-- | include/avirt/avirt.h | 6 | ||||
-rw-r--r-- | src/avirt-config.c | 40 |
2 files changed, 45 insertions, 1 deletions
diff --git a/include/avirt/avirt.h b/include/avirt/avirt.h index 94f03c5..92eb23c 100644 --- a/include/avirt/avirt.h +++ b/include/avirt/avirt.h @@ -65,4 +65,10 @@ int snd_avirt_card_seal(); */ int snd_avirt_pcm_info(const char *pcm_name, snd_pcm_info_t *pcm_info); +/** + * snd_avirt_card_index_get - Get the ALSA card index for an AVIRT card + * @avirt_idx: The AVIRT internal index (TD MF: perhaps change to UID?) + * @return: The ALSA card index on success, negative ERRNO otherwise + */ +int snd_avirt_card_index_get(int avirt_idx); #endif // _AVIRT_H_ diff --git a/src/avirt-config.c b/src/avirt-config.c index 9bfb4cd..a4a8957 100644 --- a/src/avirt-config.c +++ b/src/avirt-config.c @@ -30,7 +30,7 @@ #define AVIRT_CONFIGFS_PATH_STREAMS "/config/snd-avirt/streams/" #define AVIRT_CONFIGFS_PATH_MAXLEN 64 -#define AVIRT_DEVICE_PATH "/dev/snd/by-path/platform-snd_avirt.0" +#define AVIRT_DEVICE_PATH "/dev/snd/by-path/platform-snd_avirt" #define AVIRT_ERROR(errmsg) \ fprintf(stderr, "AVIRT ERROR: %s\n", errmsg); @@ -123,12 +123,50 @@ static int mount_configfs() return err; } +int snd_avirt_info_get_card(int idx) +{ + int open_dev, err = 0; + snd_ctl_card_info_t *card_info; + char path[64]; + + sprintf(path, AVIRT_DEVICE_PATH ".%d", idx); + open_dev = open(path, O_RDONLY); + if (open_dev < 0) + { + AVIRT_ERROR_V("Could not open device with path: %s", path); + err = -ENODEV; + goto exit_dev; + } + + snd_ctl_card_info_alloca(&card_info); + err = ioctl(open_dev, + SNDRV_CTL_IOCTL_CARD_INFO(snd_ctl_card_info_sizeof()), + card_info); + if (err < 0) + { + AVIRT_ERROR("Could not ioctl card info for AVIRT"); + goto exit_dev; + } + + return snd_ctl_card_info_get_card(card_info); + +exit_dev: + close(open_dev); + + return err; +} + int snd_avirt_pcm_info(const char *pcm_name, snd_pcm_info_t *pcm_info) { int pcm_dev = -1, err = 0; snd_ctl_t *handle; char name[32]; + if (card_index < 0) + card_index = snd_avirt_info_get_card(0); /* TD MF: Dynamically get the AVIRT card number */ + if (card_index < 0) + return card_index; + sprintf(name, "hw:%d", card_index); if ((err = snd_ctl_open(&handle, name, 0)) < 0) { |