diff --git a/src/pcm/pcm.c b/src/pcm/pcm.c index 1064044c..22d10a74 100644 --- a/src/pcm/pcm.c +++ b/src/pcm/pcm.c @@ -2479,6 +2479,18 @@ static const char *const build_in_pcms[] = { NULL }; +// helper funcion used below +int file_exists(const char * filename) +{ + FILE * file; + if (file = fopen(filename, "r")) + { + fclose(file); + return 1; + } + return 0; +} + static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name, snd_config_t *pcm_root, snd_config_t *pcm_conf, snd_pcm_stream_t stream, int mode) @@ -2573,13 +2585,37 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name, build_in++; } if (*build_in == NULL) { - buf1 = malloc(strlen(str) + sizeof(ALSA_PLUGIN_DIR) + 32); - if (buf1 == NULL) { - err = -ENOMEM; - goto _err; + + // try to locate plugin in one of ALSA_PLUGIN_DIRS which is colon separated list of paths + char *pdirs = getenv("ALSA_PLUGIN_DIRS"); + if (pdirs) { // env var set? + while (1) { + char *dir_tok = strtok(pdirs, ":"); + if (dir_tok == NULL) + break; + buf1 = malloc(strlen(str) + strlen(dir_tok) + 32); + if (buf1 == NULL) { + err = -ENOMEM; + goto _err; + } + + sprintf(buf1, "%s/libasound_module_pcm_%s.so", dir_tok, str); + + if (file_exists(buf1)) { + lib = buf1; + break; + } + pdirs = NULL; + } + } else { + buf1 = malloc(strlen(str) + sizeof(ALSA_PLUGIN_DIR) + 32); + if (buf1 == NULL) { + err = -ENOMEM; + goto _err; + } + lib = buf1; + sprintf(buf1, "%s/libasound_module_pcm_%s.so", ALSA_PLUGIN_DIR, str); } - lib = buf1; - sprintf(buf1, "%s/libasound_module_pcm_%s.so", ALSA_PLUGIN_DIR, str); } } #ifndef PIC