mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-03 09:01:52 -05:00
ucm: add PlaybackCTL and CaptureCTL default values when they are not set
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
This commit is contained in:
parent
c01e3d30b8
commit
530e8ea4c6
3 changed files with 76 additions and 28 deletions
|
|
@ -882,6 +882,45 @@ static int set_device(snd_use_case_mgr_t *uc_mgr,
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int add_auto_value(snd_use_case_mgr_t *uc_mgr, const char *key, char *value)
|
||||||
|
{
|
||||||
|
char *s;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
err = get_value1(uc_mgr, &value, &uc_mgr->value_list, key);
|
||||||
|
if (err == -ENOENT) {
|
||||||
|
s = strdup(value);
|
||||||
|
if (s == NULL)
|
||||||
|
return -ENOMEM;
|
||||||
|
return uc_mgr_add_value(&uc_mgr->value_list, key, s);
|
||||||
|
} else if (err < 0) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
free(value);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int add_auto_values(snd_use_case_mgr_t *uc_mgr)
|
||||||
|
{
|
||||||
|
struct ctl_list *ctl_list;
|
||||||
|
const char *id;
|
||||||
|
char buf[40];
|
||||||
|
int err;
|
||||||
|
|
||||||
|
ctl_list = uc_mgr_get_one_ctl(uc_mgr);
|
||||||
|
if (ctl_list) {
|
||||||
|
id = snd_ctl_card_info_get_id(ctl_list->ctl_info);
|
||||||
|
snprintf(buf, sizeof(buf), "hw:%s", id);
|
||||||
|
err = add_auto_value(uc_mgr, "PlaybackCTL", buf);
|
||||||
|
if (err < 0)
|
||||||
|
return err;
|
||||||
|
err = add_auto_value(uc_mgr, "CaptureCTL", buf);
|
||||||
|
if (err < 0)
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Init sound card use case manager.
|
* \brief Init sound card use case manager.
|
||||||
* \param uc_mgr Returned use case manager pointer
|
* \param uc_mgr Returned use case manager pointer
|
||||||
|
|
@ -920,6 +959,10 @@ int snd_use_case_mgr_open(snd_use_case_mgr_t **uc_mgr,
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = add_auto_values(mgr);
|
||||||
|
if (err < 0)
|
||||||
|
goto err;
|
||||||
|
|
||||||
*uc_mgr = mgr;
|
*uc_mgr = mgr;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -548,6 +548,26 @@ static int parse_sequence(snd_use_case_mgr_t *uc_mgr,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
int uc_mgr_add_value(struct list_head *base, const char *key, char *val)
|
||||||
|
{
|
||||||
|
struct ucm_value *curr;
|
||||||
|
|
||||||
|
curr = calloc(1, sizeof(struct ucm_value));
|
||||||
|
if (curr == NULL)
|
||||||
|
return -ENOMEM;
|
||||||
|
curr->name = strdup(key);
|
||||||
|
if (curr->name == NULL) {
|
||||||
|
free(curr);
|
||||||
|
return -ENOMEM;
|
||||||
|
}
|
||||||
|
list_add_tail(&curr->list, base);
|
||||||
|
curr->data = val;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Parse values.
|
* Parse values.
|
||||||
*
|
*
|
||||||
|
|
@ -564,13 +584,9 @@ static int parse_value(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED,
|
||||||
struct list_head *base,
|
struct list_head *base,
|
||||||
snd_config_t *cfg)
|
snd_config_t *cfg)
|
||||||
{
|
{
|
||||||
struct ucm_value *curr;
|
|
||||||
snd_config_iterator_t i;
|
snd_config_iterator_t i;
|
||||||
snd_config_t *n;
|
snd_config_t *n;
|
||||||
char buf[64];
|
char *s;
|
||||||
long l;
|
|
||||||
long long ll;
|
|
||||||
double d;
|
|
||||||
snd_config_type_t type;
|
snd_config_type_t type;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
|
@ -593,35 +609,19 @@ static int parse_value(snd_use_case_mgr_t *uc_mgr ATTRIBUTE_UNUSED,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* alloc new value */
|
|
||||||
curr = calloc(1, sizeof(struct ucm_value));
|
|
||||||
if (curr == NULL)
|
|
||||||
return -ENOMEM;
|
|
||||||
list_add_tail(&curr->list, base);
|
|
||||||
curr->name = strdup(id);
|
|
||||||
if (curr->name == NULL)
|
|
||||||
return -ENOMEM;
|
|
||||||
type = snd_config_get_type(n);
|
type = snd_config_get_type(n);
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SND_CONFIG_TYPE_INTEGER:
|
case SND_CONFIG_TYPE_INTEGER:
|
||||||
snd_config_get_integer(n, &l);
|
|
||||||
snprintf(buf, sizeof(buf), "%li", l);
|
|
||||||
__buf:
|
|
||||||
curr->data = malloc(strlen(buf) + 1);
|
|
||||||
if (curr->data == NULL)
|
|
||||||
return -ENOMEM;
|
|
||||||
strcpy(curr->data, buf);
|
|
||||||
break;
|
|
||||||
case SND_CONFIG_TYPE_INTEGER64:
|
case SND_CONFIG_TYPE_INTEGER64:
|
||||||
snd_config_get_integer64(n, &ll);
|
|
||||||
snprintf(buf, sizeof(buf), "%lli", ll);
|
|
||||||
goto __buf;
|
|
||||||
case SND_CONFIG_TYPE_REAL:
|
case SND_CONFIG_TYPE_REAL:
|
||||||
snd_config_get_real(n, &d);
|
err = snd_config_get_ascii(n, &s);
|
||||||
snprintf(buf, sizeof(buf), "%-16g", d);
|
if (err < 0) {
|
||||||
goto __buf;
|
uc_error("error: unable to parse value for id '%s': %s!", id, snd_strerror(err));
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case SND_CONFIG_TYPE_STRING:
|
case SND_CONFIG_TYPE_STRING:
|
||||||
err = parse_string(n, &curr->data);
|
err = parse_string(n, &s);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
uc_error("error: unable to parse a string for id '%s'!", id);
|
uc_error("error: unable to parse a string for id '%s'!", id);
|
||||||
return err;
|
return err;
|
||||||
|
|
@ -631,6 +631,9 @@ __buf:
|
||||||
uc_error("error: invalid type %i in Value compound '%s'", type, id);
|
uc_error("error: invalid type %i in Value compound '%s'", type, id);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
err = uc_mgr_add_value(base, id, s);
|
||||||
|
if (err < 0)
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -266,6 +266,8 @@ struct ctl_list *uc_mgr_get_one_ctl(snd_use_case_mgr_t *uc_mgr);
|
||||||
snd_ctl_t *uc_mgr_get_ctl(snd_use_case_mgr_t *uc_mgr);
|
snd_ctl_t *uc_mgr_get_ctl(snd_use_case_mgr_t *uc_mgr);
|
||||||
void uc_mgr_free_ctl_list(snd_use_case_mgr_t *uc_mgr);
|
void uc_mgr_free_ctl_list(snd_use_case_mgr_t *uc_mgr);
|
||||||
|
|
||||||
|
int uc_mgr_add_value(struct list_head *base, const char *key, char *val);
|
||||||
|
|
||||||
int uc_mgr_get_substituted_value(snd_use_case_mgr_t *uc_mgr,
|
int uc_mgr_get_substituted_value(snd_use_case_mgr_t *uc_mgr,
|
||||||
char **_rvalue,
|
char **_rvalue,
|
||||||
const char *value);
|
const char *value);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue