mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2026-03-20 05:33:44 -04:00
ucm: find-card,find-device - add UCM variable support for arguments (Syntax 9)
Add variable support for all lookup arguments in find-card and find-device
substitutions. Variables are identified by $ prefix and only enabled for
Syntax 9+ to maintain backward compatibility.
Modified arguments with variable support:
- find-card: field, regex
- find-device: type, field, stream, regex
Example usage:
${find-card:field=$FieldName,regex=$Pattern,return=number}
${find-device:type=$DevType,stream=$StreamType,field=$FieldName,regex=$Pattern}
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
c5d903b0b4
commit
a74521f371
2 changed files with 46 additions and 12 deletions
|
|
@ -663,6 +663,7 @@ Usage example:
|
||||||
|
|
||||||
~~~{.html}
|
~~~{.html}
|
||||||
${find-card:field=name,regex='^acp$',return=number}
|
${find-card:field=name,regex='^acp$',return=number}
|
||||||
|
${find-card:field=$FieldName,regex=$Pattern,return=number}
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
@ -670,8 +671,8 @@ Arguments:
|
||||||
Argument | Description
|
Argument | Description
|
||||||
---------------------|-----------------------
|
---------------------|-----------------------
|
||||||
return | return value type (id, number), id is the default
|
return | return value type (id, number), id is the default
|
||||||
field | field for the lookup (id, driver, name, longname, mixername, components)
|
field | field for the lookup (id, driver, name, longname, mixername, components) or variable name ($var) [**Syntax 9**]
|
||||||
regex | regex string for the field match
|
regex | regex string for the field match or variable name ($var) [**Syntax 9**]
|
||||||
|
|
||||||
#### Find device substitution
|
#### Find device substitution
|
||||||
|
|
||||||
|
|
@ -679,16 +680,17 @@ Usage example:
|
||||||
|
|
||||||
~~~{.html}
|
~~~{.html}
|
||||||
${find-device:type=pcm,field=name,regex='DMIC'}
|
${find-device:type=pcm,field=name,regex='DMIC'}
|
||||||
|
${find-device:type=$DevType,stream=$StreamType,field=$FieldName,regex=$Pattern}
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
|
|
||||||
Argument | Description
|
Argument | Description
|
||||||
---------------------|-----------------------
|
---------------------|-----------------------
|
||||||
type | device type (pcm)
|
type | device type (pcm) or variable name ($var) [**Syntax 9**]
|
||||||
stream | stream type (playback, capture), playback is default
|
stream | stream type (playback, capture), playback is default; variable name ($var) supported in **Syntax 9**
|
||||||
field | field for the lookup (id, name, subname)
|
field | field for the lookup (id, name, subname) or variable name ($var) [**Syntax 9**]
|
||||||
regex | regex string for the field match
|
regex | regex string for the field match or variable name ($var) [**Syntax 9**]
|
||||||
|
|
||||||
#### Card info substitution
|
#### Card info substitution
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -325,7 +325,7 @@ static char *rval_lookup_main(snd_use_case_mgr_t *uc_mgr,
|
||||||
snd_config_t *config, *d;
|
snd_config_t *config, *d;
|
||||||
struct lookup_fcn *fcn;
|
struct lookup_fcn *fcn;
|
||||||
struct lookup_iterate *curr;
|
struct lookup_iterate *curr;
|
||||||
const char *s;
|
const char *s, *tmp;
|
||||||
char *result;
|
char *result;
|
||||||
regmatch_t match[1];
|
regmatch_t match[1];
|
||||||
regex_t re;
|
regex_t re;
|
||||||
|
|
@ -349,6 +349,12 @@ static char *rval_lookup_main(snd_use_case_mgr_t *uc_mgr,
|
||||||
}
|
}
|
||||||
if (snd_config_get_string(d, &s))
|
if (snd_config_get_string(d, &s))
|
||||||
goto null;
|
goto null;
|
||||||
|
if (s[0] == '$' && uc_mgr->conf_format >= 9) {
|
||||||
|
tmp = s + 1;
|
||||||
|
s = uc_mgr_get_variable(uc_mgr, tmp);
|
||||||
|
if (s == NULL)
|
||||||
|
goto var_not_found;
|
||||||
|
}
|
||||||
for (fcn = iter->fcns ; fcn; fcn++) {
|
for (fcn = iter->fcns ; fcn; fcn++) {
|
||||||
if (strcasecmp(fcn->name, s) == 0) {
|
if (strcasecmp(fcn->name, s) == 0) {
|
||||||
iter->fcn = fcn->fcn;
|
iter->fcn = fcn->fcn;
|
||||||
|
|
@ -365,6 +371,12 @@ static char *rval_lookup_main(snd_use_case_mgr_t *uc_mgr,
|
||||||
}
|
}
|
||||||
if (snd_config_get_string(d, &s))
|
if (snd_config_get_string(d, &s))
|
||||||
goto null;
|
goto null;
|
||||||
|
if (s[0] == '$' && uc_mgr->conf_format >= 9) {
|
||||||
|
tmp = s + 1;
|
||||||
|
s = uc_mgr_get_variable(uc_mgr, tmp);
|
||||||
|
if (s == NULL)
|
||||||
|
goto var_not_found;
|
||||||
|
}
|
||||||
err = regcomp(&re, s, REG_EXTENDED | REG_ICASE);
|
err = regcomp(&re, s, REG_EXTENDED | REG_ICASE);
|
||||||
if (err) {
|
if (err) {
|
||||||
snd_error(UCM, "Regex '%s' compilation failed (code %d)", s, err);
|
snd_error(UCM, "Regex '%s' compilation failed (code %d)", s, err);
|
||||||
|
|
@ -387,6 +399,8 @@ fin:
|
||||||
if (iter->done)
|
if (iter->done)
|
||||||
iter->done(iter);
|
iter->done(iter);
|
||||||
return result;
|
return result;
|
||||||
|
var_not_found:
|
||||||
|
snd_error(UCM, "lookup: variable '%s' not found", tmp);
|
||||||
null:
|
null:
|
||||||
result = NULL;
|
result = NULL;
|
||||||
goto fin;
|
goto fin;
|
||||||
|
|
@ -500,7 +514,8 @@ static char *rval_pcm_lookup_return(struct lookup_iterate *iter,
|
||||||
return strdup(num);
|
return strdup(num);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int rval_pcm_lookup_init(struct lookup_iterate *iter,
|
static int rval_pcm_lookup_init(snd_use_case_mgr_t *uc_mgr,
|
||||||
|
struct lookup_iterate *iter,
|
||||||
snd_config_t *config)
|
snd_config_t *config)
|
||||||
{
|
{
|
||||||
static struct lookup_fcn pcm_fcns[] = {
|
static struct lookup_fcn pcm_fcns[] = {
|
||||||
|
|
@ -510,12 +525,20 @@ static int rval_pcm_lookup_init(struct lookup_iterate *iter,
|
||||||
{ 0 },
|
{ 0 },
|
||||||
};
|
};
|
||||||
snd_config_t *d;
|
snd_config_t *d;
|
||||||
const char *s;
|
const char *s, *tmp;
|
||||||
snd_pcm_info_t *pcminfo;
|
snd_pcm_info_t *pcminfo;
|
||||||
snd_pcm_stream_t stream = SND_PCM_STREAM_PLAYBACK;
|
snd_pcm_stream_t stream = SND_PCM_STREAM_PLAYBACK;
|
||||||
|
|
||||||
if (snd_config_search(config, "stream", &d) == 0 &&
|
if (snd_config_search(config, "stream", &d) == 0 &&
|
||||||
snd_config_get_string(d, &s) == 0) {
|
snd_config_get_string(d, &s) == 0) {
|
||||||
|
if (s[0] == '$' && uc_mgr->conf_format >= 9) {
|
||||||
|
tmp = s + 1;
|
||||||
|
s = uc_mgr_get_variable(uc_mgr, tmp);
|
||||||
|
if (s == NULL) {
|
||||||
|
snd_error(UCM, "pcm lookup: variable '%s' not found", tmp);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (strcasecmp(s, "playback") == 0)
|
if (strcasecmp(s, "playback") == 0)
|
||||||
stream = SND_PCM_STREAM_PLAYBACK;
|
stream = SND_PCM_STREAM_PLAYBACK;
|
||||||
else if (strcasecmp(s, "capture") == 0)
|
else if (strcasecmp(s, "capture") == 0)
|
||||||
|
|
@ -544,13 +567,14 @@ static int rval_device_lookup_init(snd_use_case_mgr_t *uc_mgr,
|
||||||
{
|
{
|
||||||
static struct {
|
static struct {
|
||||||
const char *name;
|
const char *name;
|
||||||
int (*init)(struct lookup_iterate *iter, snd_config_t *config);
|
int (*init)(snd_use_case_mgr_t *uc_mgr, struct lookup_iterate *iter,
|
||||||
|
snd_config_t *config);
|
||||||
} *t, types[] = {
|
} *t, types[] = {
|
||||||
{ .name = "pcm", .init = rval_pcm_lookup_init },
|
{ .name = "pcm", .init = rval_pcm_lookup_init },
|
||||||
{ 0 }
|
{ 0 }
|
||||||
};
|
};
|
||||||
snd_config_t *d;
|
snd_config_t *d;
|
||||||
const char *s;
|
const char *s, *tmp;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (snd_config_search(config, "ctl", &d) || snd_config_get_string(d, &s)) {
|
if (snd_config_search(config, "ctl", &d) || snd_config_get_string(d, &s)) {
|
||||||
|
|
@ -570,9 +594,17 @@ static int rval_device_lookup_init(snd_use_case_mgr_t *uc_mgr,
|
||||||
snd_error(UCM, "Missing device type!");
|
snd_error(UCM, "Missing device type!");
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
if (s[0] == '$' && uc_mgr->conf_format >= 9) {
|
||||||
|
tmp = s + 1;
|
||||||
|
s = uc_mgr_get_variable(uc_mgr, tmp);
|
||||||
|
if (s == NULL) {
|
||||||
|
snd_error(UCM, "device lookup: variable '%s' not found", tmp);
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
for (t = types; t->name; t++)
|
for (t = types; t->name; t++)
|
||||||
if (strcasecmp(t->name, s) == 0)
|
if (strcasecmp(t->name, s) == 0)
|
||||||
return t->init(iter, config);
|
return t->init(uc_mgr, iter, config);
|
||||||
snd_error(UCM, "Device type '%s' is invalid", s);
|
snd_error(UCM, "Device type '%s' is invalid", s);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue