mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-11 13:30:05 -05:00
Extended parameterization. Marked with @ all fields with special use
This commit is contained in:
parent
cf325c68e3
commit
54daf2f16d
16 changed files with 315 additions and 349 deletions
|
|
@ -942,11 +942,11 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
|
|||
SNDERR("Invalid type for %s", snd_config_get_id(conf));
|
||||
return err;
|
||||
}
|
||||
err = snd_config_search_alias(snd_config, "pcm_type", str, &type_conf);
|
||||
err = snd_config_search_definition(snd_config, "pcm_type", str, &type_conf);
|
||||
if (err >= 0) {
|
||||
if (snd_config_get_type(type_conf) != SND_CONFIG_TYPE_COMPOUND) {
|
||||
SNDERR("Invalid type for PCM type %s definition", str);
|
||||
return -EINVAL;
|
||||
goto _err;
|
||||
}
|
||||
snd_config_for_each(i, next, type_conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
|
|
@ -957,7 +957,7 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
|
|||
err = snd_config_get_string(n, &lib);
|
||||
if (err < 0) {
|
||||
SNDERR("Invalid type for %s", id);
|
||||
return -EINVAL;
|
||||
goto _err;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
@ -965,11 +965,13 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
|
|||
err = snd_config_get_string(n, &open_name);
|
||||
if (err < 0) {
|
||||
SNDERR("Invalid type for %s", id);
|
||||
return -EINVAL;
|
||||
goto _err;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
SNDERR("Unknown field %s", id);
|
||||
_err:
|
||||
snd_config_delete(type_conf);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
|
@ -980,11 +982,14 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
|
|||
if (!lib)
|
||||
lib = ALSA_LIB;
|
||||
h = dlopen(lib, RTLD_NOW);
|
||||
if (h)
|
||||
open_func = dlsym(h, open_name);
|
||||
if (type_conf)
|
||||
snd_config_delete(type_conf);
|
||||
if (!h) {
|
||||
SNDERR("Cannot open shared library %s", lib);
|
||||
return -ENOENT;
|
||||
}
|
||||
open_func = dlsym(h, open_name);
|
||||
if (!open_func) {
|
||||
SNDERR("symbol %s is not defined inside %s", open_name, lib);
|
||||
dlclose(h);
|
||||
|
|
@ -1000,43 +1005,10 @@ static int snd_pcm_open_noupdate(snd_pcm_t **pcmp, snd_config_t *root,
|
|||
const char *name, snd_pcm_stream_t stream, int mode)
|
||||
{
|
||||
int err;
|
||||
snd_config_t *pcm_conf;
|
||||
char *base, *key;
|
||||
const char *args = strchr(name, ':');
|
||||
snd_config_t *conf;
|
||||
if (args) {
|
||||
args++;
|
||||
base = alloca(args - name);
|
||||
memcpy(base, name, args - name - 1);
|
||||
base[args - name - 1] = '\0';
|
||||
key = strchr(base, '.');
|
||||
if (key)
|
||||
*key++ = '\0';
|
||||
} else {
|
||||
key = strchr(name, '.');
|
||||
if (key) {
|
||||
key++;
|
||||
base = alloca(key - name);
|
||||
memcpy(base, name, key - name - 1);
|
||||
base[key - name - 1] = '\0';
|
||||
} else
|
||||
base = (char *) name;
|
||||
}
|
||||
if (key == NULL) {
|
||||
key = base;
|
||||
base = NULL;
|
||||
}
|
||||
err = snd_config_search_alias(root, base, key, &pcm_conf);
|
||||
snd_config_t *pcm_conf, *conf;
|
||||
err = snd_config_search_definition(root, "pcm", name, &pcm_conf);
|
||||
if (err < 0) {
|
||||
(void)(base == NULL && (err = snd_config_search_alias(root, "pcm", key, &pcm_conf)));
|
||||
if (err < 0) {
|
||||
SNDERR("Unknown PCM %s", name);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
err = snd_config_expand(pcm_conf, args, NULL, &pcm_conf);
|
||||
if (err < 0) {
|
||||
SNDERR("Could not expand configuration for %s: %s", name, snd_strerror(err));
|
||||
SNDERR("Unknown PCM %s", name);
|
||||
return err;
|
||||
}
|
||||
if (snd_config_search(pcm_conf, "refer", &conf) >= 0) {
|
||||
|
|
@ -1044,8 +1016,7 @@ static int snd_pcm_open_noupdate(snd_pcm_t **pcmp, snd_config_t *root,
|
|||
int conf_free_tmp;
|
||||
char *refer_name = NULL;
|
||||
err = snd_config_refer_load(root, conf, &refer_name, &tmp_conf, &conf_free_tmp);
|
||||
if (args)
|
||||
snd_config_delete(pcm_conf);
|
||||
snd_config_delete(pcm_conf);
|
||||
if (err < 0) {
|
||||
SNDERR("Refer load error for %s: %s", name, snd_strerror(err));
|
||||
return err;
|
||||
|
|
@ -4318,16 +4289,18 @@ int snd_pcm_slave_conf(snd_config_t *root, snd_config_t *conf,
|
|||
unsigned int k;
|
||||
snd_config_t *pcm_conf = NULL;
|
||||
int err;
|
||||
int to_free = 0;
|
||||
va_list args;
|
||||
assert(root);
|
||||
assert(conf);
|
||||
assert(_pcm_conf);
|
||||
if (snd_config_get_string(conf, &str) >= 0) {
|
||||
err = snd_config_search_alias(conf, "pcm_slave", str, &conf);
|
||||
err = snd_config_search_definition(root, "pcm_slave", str, &conf);
|
||||
if (err < 0) {
|
||||
SNDERR("Configuration pcm_slave.%s was not found\n", str);
|
||||
SNDERR("Invalid slave definition");
|
||||
return -EINVAL;
|
||||
}
|
||||
to_free = 1;
|
||||
}
|
||||
if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) {
|
||||
SNDERR("Invalid slave definition");
|
||||
|
|
@ -4365,12 +4338,13 @@ int snd_pcm_slave_conf(snd_config_t *root, snd_config_t *conf,
|
|||
if (err < 0) {
|
||||
_invalid:
|
||||
SNDERR("invalid type for %s", id);
|
||||
return err;
|
||||
goto _err;
|
||||
}
|
||||
f = snd_pcm_format_value(str);
|
||||
if (f == SND_PCM_FORMAT_UNKNOWN) {
|
||||
SNDERR("unknown format");
|
||||
return -EINVAL;
|
||||
err = -EINVAL;
|
||||
goto _err;
|
||||
}
|
||||
*(snd_pcm_format_t*)fields[k].ptr = f;
|
||||
break;
|
||||
|
|
@ -4388,20 +4362,27 @@ int snd_pcm_slave_conf(snd_config_t *root, snd_config_t *conf,
|
|||
if (k < count)
|
||||
continue;
|
||||
SNDERR("Unknown field %s", id);
|
||||
// return -EINVAL;
|
||||
err = -EINVAL;
|
||||
goto _err;
|
||||
}
|
||||
if (!pcm_conf) {
|
||||
SNDERR("missing field pcm");
|
||||
return -EINVAL;
|
||||
err = -EINVAL;
|
||||
goto _err;
|
||||
}
|
||||
for (k = 0; k < count; ++k) {
|
||||
if (fields[k].mandatory && !fields[k].valid) {
|
||||
SNDERR("missing field %s", names[fields[k].index]);
|
||||
return -EINVAL;
|
||||
err = -EINVAL;
|
||||
goto _err;
|
||||
}
|
||||
}
|
||||
*_pcm_conf = pcm_conf;
|
||||
return 0;
|
||||
_err:
|
||||
if (to_free)
|
||||
snd_config_delete(conf);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -335,13 +335,6 @@ int snd_pcm_hook_add_conf(snd_pcm_t *pcm, snd_config_t *conf)
|
|||
snd_config_iterator_t i, next;
|
||||
int (*install_func)(snd_pcm_t *pcm, snd_config_t *args);
|
||||
void *h;
|
||||
if (snd_config_get_string(conf, &str) >= 0) {
|
||||
err = snd_config_search_alias(snd_config, "pcm_hook", str, &conf);
|
||||
if (err < 0) {
|
||||
SNDERR("unknown pcm_hook %s", str);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) {
|
||||
SNDERR("Invalid hook definition");
|
||||
return -EINVAL;
|
||||
|
|
@ -371,11 +364,11 @@ int snd_pcm_hook_add_conf(snd_pcm_t *pcm, snd_config_t *conf)
|
|||
SNDERR("Invalid type for %s", snd_config_get_id(type));
|
||||
return err;
|
||||
}
|
||||
err = snd_config_search_alias(snd_config, "pcm_hook_type", str, &type);
|
||||
err = snd_config_search_definition(snd_config, "pcm_hook_type", str, &type);
|
||||
if (err >= 0) {
|
||||
if (snd_config_get_type(type) != SND_CONFIG_TYPE_COMPOUND) {
|
||||
SNDERR("Invalid type for PCM type %s definition", str);
|
||||
return -EINVAL;
|
||||
goto _err;
|
||||
}
|
||||
snd_config_for_each(i, next, type) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
|
|
@ -386,7 +379,7 @@ int snd_pcm_hook_add_conf(snd_pcm_t *pcm, snd_config_t *conf)
|
|||
err = snd_config_get_string(n, &lib);
|
||||
if (err < 0) {
|
||||
SNDERR("Invalid type for %s", id);
|
||||
return -EINVAL;
|
||||
goto _err;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
@ -394,11 +387,13 @@ int snd_pcm_hook_add_conf(snd_pcm_t *pcm, snd_config_t *conf)
|
|||
err = snd_config_get_string(n, &install);
|
||||
if (err < 0) {
|
||||
SNDERR("Invalid type for %s", id);
|
||||
return -EINVAL;
|
||||
goto _err;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
SNDERR("Unknown field %s", id);
|
||||
_err:
|
||||
snd_config_delete(type);
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
|
|
@ -408,25 +403,30 @@ int snd_pcm_hook_add_conf(snd_pcm_t *pcm, snd_config_t *conf)
|
|||
}
|
||||
if (!lib)
|
||||
lib = ALSA_LIB;
|
||||
if (args && snd_config_get_string(args, &str) >= 0) {
|
||||
err = snd_config_search_alias(snd_config, "hook_args", str, &args);
|
||||
if (err < 0) {
|
||||
SNDERR("unknown hook_args %s", str);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
h = dlopen(lib, RTLD_NOW);
|
||||
if (h)
|
||||
install_func = dlsym(h, install);
|
||||
if (type)
|
||||
snd_config_delete(type);
|
||||
if (!h) {
|
||||
SNDERR("Cannot open shared library %s", lib);
|
||||
return -ENOENT;
|
||||
}
|
||||
install_func = dlsym(h, install);
|
||||
if (!install_func) {
|
||||
SNDERR("symbol %s is not defined inside %s", install, lib);
|
||||
dlclose(h);
|
||||
return -ENXIO;
|
||||
}
|
||||
err = install_func(pcm, args);
|
||||
if (args && snd_config_get_string(args, &str) >= 0) {
|
||||
err = snd_config_search_definition(snd_config, "hook_args", str, &args);
|
||||
if (err < 0) {
|
||||
SNDERR("unknown hook_args %s", str);
|
||||
return err;
|
||||
}
|
||||
err = install_func(pcm, args);
|
||||
snd_config_delete(args);
|
||||
} else
|
||||
err = install_func(pcm, args);
|
||||
if (err < 0)
|
||||
return err;
|
||||
return 0;
|
||||
|
|
@ -480,7 +480,17 @@ int _snd_pcm_hooks_open(snd_pcm_t **pcmp, const char *name,
|
|||
return 0;
|
||||
snd_config_for_each(i, next, hooks) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
err = snd_pcm_hook_add_conf(*pcmp, n);
|
||||
const char *str;
|
||||
if (snd_config_get_string(n, &str) >= 0) {
|
||||
err = snd_config_search_definition(snd_config, "pcm_hook", str, &n);
|
||||
if (err < 0) {
|
||||
SNDERR("unknown pcm_hook %s", str);
|
||||
return err;
|
||||
}
|
||||
err = snd_pcm_hook_add_conf(*pcmp, n);
|
||||
snd_config_delete(n);
|
||||
} else
|
||||
err = snd_pcm_hook_add_conf(*pcmp, n);
|
||||
if (err < 0) {
|
||||
snd_pcm_close(*pcmp);
|
||||
return err;
|
||||
|
|
|
|||
|
|
@ -663,29 +663,23 @@ static int snd_pcm_meter_add_scope_conf(snd_pcm_t *pcm, const char *name,
|
|||
snd_config_t *);
|
||||
void *h;
|
||||
int err;
|
||||
err = snd_config_get_string(conf, &str);
|
||||
if (err >= 0) {
|
||||
err = snd_config_search_alias(snd_config, "pcm_scope", str, &conf);
|
||||
if (err < 0) {
|
||||
SNDERR("unknown pcm_scope %s", str);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
int to_free = 0;
|
||||
if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) {
|
||||
SNDERR("Invalid type for scope %s", str);
|
||||
return -EINVAL;
|
||||
err = -EINVAL;
|
||||
goto _err;
|
||||
}
|
||||
err = snd_config_search(conf, "type", &c);
|
||||
if (err < 0) {
|
||||
SNDERR("type is not defined");
|
||||
return err;
|
||||
goto _err;
|
||||
}
|
||||
err = snd_config_get_string(c, &str);
|
||||
if (err < 0) {
|
||||
SNDERR("Invalid type for %s", snd_config_get_id(c));
|
||||
return err;
|
||||
goto _err;
|
||||
}
|
||||
err = snd_config_search_alias(snd_config, "pcm_scope_type", str, &type_conf);
|
||||
err = snd_config_search_definition(snd_config, "pcm_scope_type", str, &type_conf);
|
||||
if (err >= 0) {
|
||||
snd_config_for_each(i, next, type_conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
|
|
@ -696,7 +690,7 @@ static int snd_pcm_meter_add_scope_conf(snd_pcm_t *pcm, const char *name,
|
|||
err = snd_config_get_string(n, &lib);
|
||||
if (err < 0) {
|
||||
SNDERR("Invalid type for %s", id);
|
||||
return -EINVAL;
|
||||
goto _err1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
@ -704,12 +698,13 @@ static int snd_pcm_meter_add_scope_conf(snd_pcm_t *pcm, const char *name,
|
|||
err = snd_config_get_string(n, &open_name);
|
||||
if (err < 0) {
|
||||
SNDERR("Invalid type for %s", id);
|
||||
return -EINVAL;
|
||||
goto _err1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
SNDERR("Unknown field %s", id);
|
||||
return -EINVAL;
|
||||
err = -EINVAL;
|
||||
goto _err1;
|
||||
}
|
||||
}
|
||||
if (!open_name) {
|
||||
|
|
@ -721,15 +716,24 @@ static int snd_pcm_meter_add_scope_conf(snd_pcm_t *pcm, const char *name,
|
|||
h = dlopen(lib, RTLD_NOW);
|
||||
if (!h) {
|
||||
SNDERR("Cannot open shared library %s", lib);
|
||||
return -ENOENT;
|
||||
err = -ENOENT;
|
||||
goto _err1;
|
||||
}
|
||||
open_func = dlsym(h, open_name);
|
||||
if (type_conf)
|
||||
snd_config_delete(type_conf);
|
||||
if (!open_func) {
|
||||
SNDERR("symbol %s is not defined inside %s", open_name, lib);
|
||||
dlclose(h);
|
||||
return -ENXIO;
|
||||
goto _err;
|
||||
}
|
||||
return open_func(pcm, name, conf);
|
||||
_err1:
|
||||
snd_config_delete(type_conf);
|
||||
_err:
|
||||
if (to_free)
|
||||
snd_config_delete(conf);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -791,7 +795,17 @@ int _snd_pcm_meter_open(snd_pcm_t **pcmp, const char *name,
|
|||
snd_config_for_each(i, next, scopes) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
const char *id = snd_config_get_id(n);
|
||||
err = snd_pcm_meter_add_scope_conf(*pcmp, id, n);
|
||||
const char *str;
|
||||
if (snd_config_get_string(n, &str) >= 0) {
|
||||
err = snd_config_search_definition(snd_config, "pcm_scope", str, &n);
|
||||
if (err < 0) {
|
||||
SNDERR("unknown pcm_scope %s", str);
|
||||
return err;
|
||||
}
|
||||
err = snd_pcm_meter_add_scope_conf(*pcmp, id, n);
|
||||
snd_config_delete(n);
|
||||
} else
|
||||
err = snd_pcm_meter_add_scope_conf(*pcmp, id, n);
|
||||
if (err < 0) {
|
||||
snd_pcm_close(*pcmp);
|
||||
return err;
|
||||
|
|
|
|||
|
|
@ -1414,7 +1414,7 @@ int _snd_pcm_share_open(snd_pcm_t **pcmp, const char *name,
|
|||
SNDERR("slave is not defined");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_pcm_slave_conf(root, slave, &sconf, NULL, 5,
|
||||
err = snd_pcm_slave_conf(root, slave, &sconf, 5,
|
||||
SND_PCM_HW_PARAM_CHANNELS, 0, &schannels,
|
||||
SND_PCM_HW_PARAM_FORMAT, 0, &sformat,
|
||||
SND_PCM_HW_PARAM_RATE, 0, &srate,
|
||||
|
|
|
|||
|
|
@ -765,14 +765,14 @@ int _snd_pcm_shm_open(snd_pcm_t **pcmp, const char *name,
|
|||
SNDERR("server is not defined");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_config_search_alias(snd_config, "server", server, &sconfig);
|
||||
err = snd_config_search_definition(snd_config, "server", server, &sconfig);
|
||||
if (err < 0) {
|
||||
SNDERR("Unknown server %s", server);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (snd_config_get_type(sconfig) != SND_CONFIG_TYPE_COMPOUND) {
|
||||
SNDERR("Invalid type for server %s definition", server);
|
||||
return -EINVAL;
|
||||
goto _err;
|
||||
}
|
||||
snd_config_for_each(i, next, sconfig) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
|
|
@ -783,7 +783,7 @@ int _snd_pcm_shm_open(snd_pcm_t **pcmp, const char *name,
|
|||
err = snd_config_get_string(n, &host);
|
||||
if (err < 0) {
|
||||
SNDERR("Invalid type for %s", id);
|
||||
return -EINVAL;
|
||||
goto _err;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
@ -791,7 +791,7 @@ int _snd_pcm_shm_open(snd_pcm_t **pcmp, const char *name,
|
|||
err = snd_config_get_string(n, &sockname);
|
||||
if (err < 0) {
|
||||
SNDERR("Invalid type for %s", id);
|
||||
return -EINVAL;
|
||||
goto _err;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
@ -799,32 +799,36 @@ int _snd_pcm_shm_open(snd_pcm_t **pcmp, const char *name,
|
|||
err = snd_config_get_integer(n, &port);
|
||||
if (err < 0) {
|
||||
SNDERR("Invalid type for %s", id);
|
||||
return -EINVAL;
|
||||
goto _err;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
SNDERR("Unknown field %s", id);
|
||||
_err:
|
||||
snd_config_delete(sconfig);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!host) {
|
||||
SNDERR("host is not defined");
|
||||
return -EINVAL;
|
||||
goto _err;
|
||||
}
|
||||
if (!sockname) {
|
||||
SNDERR("socket is not defined");
|
||||
return -EINVAL;
|
||||
goto _err;
|
||||
}
|
||||
h = gethostbyname(host);
|
||||
if (!h) {
|
||||
SNDERR("Cannot resolve %s", host);
|
||||
return -EINVAL;
|
||||
goto _err;
|
||||
}
|
||||
local = is_local(h);
|
||||
if (!local) {
|
||||
SNDERR("%s is not the local host", host);
|
||||
return -EINVAL;
|
||||
}
|
||||
return snd_pcm_shm_open(pcmp, name, sockname, pcm_name, stream, mode);
|
||||
err = snd_pcm_shm_open(pcmp, name, sockname, pcm_name, stream, mode);
|
||||
snd_config_delete(sconfig);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue