diff options
author | Nedko Arnaudov <nedko@arnaudov.name> | 2012-11-24 06:02:56 +0200 |
---|---|---|
committer | Nedko Arnaudov <nedko@arnaudov.name> | 2012-11-24 06:02:56 +0200 |
commit | e02d7358da82a84647cb5cd71de23a75640ef506 (patch) | |
tree | 7f9f73b33dd67e088b390519ff6f2bbc5f029000 | |
parent | de2bb9d27d41f7ec5dc0c67f82379824e9d01236 (diff) | |
download | jack1-control_device_name_fixes.tar.gz |
We recommend using symbolic names like hw:Live but when subdevices are usedcontrol_device_name_fixes
regcomp() was failing to parse them. This changeset improves the algorithm
by using less assumptions.
This commit is a backport of similar (but bigger) commit in jack2.
b3394f4dcec1f707403796615d7bb6f0944183a3
-rw-r--r-- | drivers/alsa/alsa_driver.c | 48 |
1 files changed, 32 insertions, 16 deletions
diff --git a/drivers/alsa/alsa_driver.c b/drivers/alsa/alsa_driver.c index 05581ee..9e98548 100644 --- a/drivers/alsa/alsa_driver.c +++ b/drivers/alsa/alsa_driver.c @@ -96,30 +96,47 @@ alsa_driver_check_capabilities (alsa_driver_t *driver) return 0; } +static char* +get_control_device_name(const char * device_name) +{ + char * ctl_name; + const char * comma; + + /* the user wants a hw or plughw device, the ctl name + * should be hw:x where x is the card identification. + * We skip the subdevice suffix that starts with comma */ + + if (strncasecmp(device_name, "plughw:", 7) == 0) { + /* skip the "plug" prefix" */ + device_name += 4; + } + + comma = strchr(device_name, ','); + if (comma == NULL) { + ctl_name = strdup(device_name); + if (ctl_name == NULL) { + jack_error("strdup(\"%s\") failed.", device_name); + } + } else { + ctl_name = strndup(device_name, comma - device_name); + if (ctl_name == NULL) { + jack_error("strndup(\"%s\", %u) failed.", device_name, (unsigned int)(comma - device_name)); + } + } + + return ctl_name; +} + static int alsa_driver_check_card_type (alsa_driver_t *driver) { int err; snd_ctl_card_info_t *card_info; char * ctl_name; - regex_t expression; snd_ctl_card_info_alloca (&card_info); - regcomp(&expression,"(plug)?hw:[0-9](,[0-9])?",REG_ICASE|REG_EXTENDED); - - if (!regexec(&expression,driver->alsa_name_playback,0,NULL,0)) { - /* the user wants a hw or plughw device, the ctl name - * should be hw:x where x is the card number */ - - char tmp[5]; - strncpy(tmp,strstr(driver->alsa_name_playback,"hw"),4); - tmp[4]='\0'; - jack_info("control device %s",tmp); - ctl_name = strdup(tmp); - } else { - ctl_name = strdup(driver->alsa_name_playback); - } + ctl_name = get_control_device_name(driver->alsa_name_playback); // XXX: I don't know the "right" way to do this. Which to use // driver->alsa_name_playback or driver->alsa_name_capture. @@ -134,7 +151,6 @@ alsa_driver_check_card_type (alsa_driver_t *driver) driver->alsa_driver = strdup(snd_ctl_card_info_get_driver (card_info)); - regfree(&expression); free(ctl_name); return alsa_driver_check_capabilities (driver); |