aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/backends/alsa.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2012-02-13 10:33:53 -0800
committerChris Robinson <[email protected]>2012-02-13 10:33:53 -0800
commit5e1d1a52bae6d22565bdfe7042da29e61197d36c (patch)
treefc248b0c1288a509340458f4e43782bb6c5b082b /Alc/backends/alsa.c
parente394d14cdab07cab5fce75a2e175a3439c8c8edd (diff)
Check for each ALSA prefix config option only as needed
Diffstat (limited to 'Alc/backends/alsa.c')
-rw-r--r--Alc/backends/alsa.c48
1 files changed, 26 insertions, 22 deletions
diff --git a/Alc/backends/alsa.c b/Alc/backends/alsa.c
index fa059e44..4bca3845 100644
--- a/Alc/backends/alsa.c
+++ b/Alc/backends/alsa.c
@@ -290,28 +290,33 @@ static const char *prefix_name(snd_pcm_stream_t stream)
static DevMap *probe_devices(snd_pcm_stream_t stream, ALuint *count)
{
+ const char *main_prefix = "plughw:";
snd_ctl_t *handle;
int card, err, dev, idx;
snd_ctl_card_info_t *info;
snd_pcm_info_t *pcminfo;
DevMap *DevList;
+ ConfigValueStr("alsa", prefix_name(stream), &main_prefix);
+
snd_ctl_card_info_malloc(&info);
snd_pcm_info_malloc(&pcminfo);
- card = -1;
- if((err=snd_card_next(&card)) < 0)
- ERR("Failed to find a card: %s\n", snd_strerror(err));
-
DevList = malloc(sizeof(DevMap) * 1);
DevList[0].name = strdup("ALSA Default");
DevList[0].device = NULL;
idx = 1;
+
+ card = -1;
+ if((err=snd_card_next(&card)) < 0)
+ ERR("Failed to find a card: %s\n", snd_strerror(err));
while(card >= 0)
{
+ const char *card_prefix = main_prefix;
+ const char *cardname, *cardid;
char name[256];
- sprintf(name, "hw:%d", card);
+ snprintf(name, sizeof(name), "hw:%d", card);
if((err = snd_ctl_open(&handle, name, 0)) < 0)
{
ERR("control open (hw:%d): %s\n", card, snd_strerror(err));
@@ -324,10 +329,16 @@ static DevMap *probe_devices(snd_pcm_stream_t stream, ALuint *count)
goto next_card;
}
+ cardname = snd_ctl_card_info_get_name(info);
+ cardid = snd_ctl_card_info_get_id(info);
+
+ snprintf(name, sizeof(name), "%s-%s", prefix_name(stream), cardid);
+ ConfigValueStr("alsa", name, &card_prefix);
+
dev = -1;
while(1)
{
- const char *cname, *dname, *cid;
+ const char *devname;
void *temp;
if(snd_ctl_pcm_next_device(handle, &dev) < 0)
@@ -347,29 +358,22 @@ static DevMap *probe_devices(snd_pcm_stream_t stream, ALuint *count)
temp = realloc(DevList, sizeof(DevMap) * (idx+1));
if(temp)
{
- const char *prefix = "plughw:";
- char devname[128];
+ const char *device_prefix = card_prefix;
+ char device[128];
DevList = temp;
- cname = snd_ctl_card_info_get_name(info);
- dname = snd_pcm_info_get_name(pcminfo);
- cid = snd_ctl_card_info_get_id(info);
+ devname = snd_pcm_info_get_name(pcminfo);
- snprintf(devname, sizeof(devname), "%s-%s-%d", prefix_name(stream), cid, dev);
- if(!ConfigValueStr("alsa", devname, &prefix))
- {
- snprintf(devname, sizeof(devname), "%s-%s", prefix_name(stream), cid);
- if(!ConfigValueStr("alsa", devname, &prefix))
- ConfigValueStr("alsa", prefix_name(stream), &prefix);
- }
+ snprintf(name, sizeof(name), "%s-%s-%d", prefix_name(stream), cardid, dev);
+ ConfigValueStr("alsa", name, &device_prefix);
snprintf(name, sizeof(name), "%s, %s (CARD=%s,DEV=%d)",
- cname, dname, cid, dev);
- snprintf(devname, sizeof(devname), "%sCARD=%s,DEV=%d",
- prefix, cid, dev);
+ cardname, devname, cardid, dev);
+ snprintf(device, sizeof(device), "%sCARD=%s,DEV=%d",
+ device_prefix, cardid, dev);
DevList[idx].name = strdup(name);
- DevList[idx].device = strdup(devname);
+ DevList[idx].device = strdup(device);
idx++;
}
}