mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-11 13:30:05 -05:00
Added argument handling for the slave PCMs.
The configuration root (snd_config) can be specified for the internal routines. The pcm_hooks code was recoded (independent code moved to control/setup.c). Improved the pcm_multi plugin (added master configuration).
This commit is contained in:
parent
61bf03ce70
commit
bf780a25a5
29 changed files with 1179 additions and 1070 deletions
|
|
@ -7,7 +7,7 @@ libpcm_la_SOURCES = atomic.c mask.c interval.c \
|
|||
pcm_route.c pcm_mulaw.c pcm_alaw.c pcm_adpcm.c \
|
||||
pcm_rate.c pcm_plug.c pcm_misc.c pcm_mmap.c pcm_multi.c \
|
||||
pcm_shm.c pcm_file.c pcm_null.c pcm_share.c \
|
||||
pcm_meter.c pcm_hooks.c pcm_surr.c
|
||||
pcm_meter.c pcm_hooks.c
|
||||
noinst_HEADERS = atomic.h pcm_local.h pcm_plugin.h mask.h mask_inline.h \
|
||||
interval.h interval_inline.h plugin_ops.h
|
||||
|
||||
|
|
|
|||
|
|
@ -912,7 +912,7 @@ ssize_t snd_pcm_samples_to_bytes(snd_pcm_t *pcm, int samples)
|
|||
}
|
||||
|
||||
static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
|
||||
snd_config_t *pcm_conf,
|
||||
snd_config_t *root, snd_config_t *pcm_conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
{
|
||||
const char *str;
|
||||
|
|
@ -921,7 +921,8 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
|
|||
snd_config_t *conf, *type_conf = NULL;
|
||||
snd_config_iterator_t i, next;
|
||||
const char *lib = NULL, *open_name = NULL;
|
||||
int (*open_func)(snd_pcm_t **, const char *, snd_config_t *,
|
||||
int (*open_func)(snd_pcm_t **, const char *,
|
||||
snd_config_t *, snd_config_t *,
|
||||
snd_pcm_stream_t, int);
|
||||
void *h;
|
||||
if (snd_config_get_type(pcm_conf) != SND_CONFIG_TYPE_COMPOUND) {
|
||||
|
|
@ -989,7 +990,7 @@ static int snd_pcm_open_conf(snd_pcm_t **pcmp, const char *name,
|
|||
dlclose(h);
|
||||
return -ENXIO;
|
||||
}
|
||||
err = open_func(pcmp, name, pcm_conf, stream, mode);
|
||||
err = open_func(pcmp, name, root, pcm_conf, stream, mode);
|
||||
if (err < 0)
|
||||
return err;
|
||||
return 0;
|
||||
|
|
@ -1057,7 +1058,7 @@ static int snd_pcm_open_noupdate(snd_pcm_t **pcmp, snd_config_t *root,
|
|||
snd_config_delete(tmp_conf);
|
||||
return err;
|
||||
}
|
||||
err = snd_pcm_open_conf(pcmp, name, pcm_conf, stream, mode);
|
||||
err = snd_pcm_open_conf(pcmp, name, root, pcm_conf, stream, mode);
|
||||
if (args)
|
||||
snd_config_delete(pcm_conf);
|
||||
return err;
|
||||
|
|
@ -1083,13 +1084,26 @@ int snd_pcm_open(snd_pcm_t **pcmp, const char *name,
|
|||
}
|
||||
|
||||
#ifndef DOC_HIDDEN
|
||||
int snd_pcm_open_slave(snd_pcm_t **pcmp, snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
int snd_pcm_open_slave(snd_pcm_t **pcmp, snd_config_t *root, snd_config_t *conf,
|
||||
const char *args, snd_pcm_stream_t stream, int mode)
|
||||
{
|
||||
const char *str;
|
||||
if (snd_config_get_string(conf, &str) >= 0)
|
||||
return snd_pcm_open_noupdate(pcmp, snd_config, str, stream, mode);
|
||||
return snd_pcm_open_conf(pcmp, NULL, conf, stream, mode);
|
||||
if (snd_config_get_string(conf, &str) >= 0) {
|
||||
char *tmp;
|
||||
int err;
|
||||
if (args == NULL)
|
||||
return snd_pcm_open_noupdate(pcmp, root, str, stream, mode);
|
||||
tmp = malloc(strlen(str) + 1 + strlen(args) + 1);
|
||||
if (tmp == NULL)
|
||||
return -ENOMEM;
|
||||
strcpy(tmp, str);
|
||||
strcat(tmp, ":");
|
||||
strcat(tmp, args);
|
||||
err = snd_pcm_open_noupdate(pcmp, root, tmp, stream, mode);
|
||||
free(tmp);
|
||||
return err;
|
||||
}
|
||||
return snd_pcm_open_conf(pcmp, NULL, root, conf, stream, mode);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -4304,7 +4318,8 @@ static const char *names[SND_PCM_HW_PARAM_LAST + 1] = {
|
|||
[SND_PCM_HW_PARAM_BUFFER_TIME] = "buffer_time"
|
||||
};
|
||||
|
||||
int snd_pcm_slave_conf(snd_config_t *conf, snd_config_t **pcm_conf,
|
||||
int snd_pcm_slave_conf(snd_config_t *root, snd_config_t *conf,
|
||||
snd_config_t **pcm_conf, const char **pcm_args,
|
||||
unsigned int count, ...)
|
||||
{
|
||||
snd_config_iterator_t i, next;
|
||||
|
|
@ -4319,12 +4334,45 @@ int snd_pcm_slave_conf(snd_config_t *conf, snd_config_t **pcm_conf,
|
|||
int pcm_valid = 0;
|
||||
int err;
|
||||
va_list args;
|
||||
assert(root);
|
||||
assert(conf);
|
||||
assert(pcm_conf);
|
||||
if (snd_config_get_string(conf, &str) >= 0) {
|
||||
err = snd_config_search_alias(snd_config, "pcm_slave", str, &conf);
|
||||
if (err < 0) {
|
||||
SNDERR("unknown pcm_slave %s", str);
|
||||
return err;
|
||||
char *key;
|
||||
const char *args = strchr(str, ':');
|
||||
char *base;
|
||||
if (args) {
|
||||
args++;
|
||||
base = alloca(args - str);
|
||||
memcpy(base, str, args - str - 1);
|
||||
base[args - str - 1] = '\0';
|
||||
key = strchr(base, '.');
|
||||
if (key)
|
||||
*key++ = '\0';
|
||||
} else {
|
||||
key = strchr(str, '.');
|
||||
if (key) {
|
||||
key++;
|
||||
base = alloca(key - str);
|
||||
memcpy(base, str, key - str - 1);
|
||||
base[key - str - 1] = '\0';
|
||||
} else
|
||||
base = (char *) str;
|
||||
}
|
||||
if (key == NULL) {
|
||||
key = base;
|
||||
base = NULL;
|
||||
}
|
||||
err = snd_config_search_alias(root, base, key, &conf);
|
||||
if (err < 0) {
|
||||
(void)(base == NULL && (err = snd_config_search_alias(root, "pcm_slave", key, &conf)));
|
||||
if (err < 0) {
|
||||
SNDERR("unknown pcm_slave %s", str);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
if (pcm_args)
|
||||
*pcm_args = args;
|
||||
}
|
||||
if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) {
|
||||
SNDERR("Invalid slave definition");
|
||||
|
|
@ -4371,7 +4419,7 @@ int snd_pcm_slave_conf(snd_config_t *conf, snd_config_t **pcm_conf,
|
|||
return -EINVAL;
|
||||
}
|
||||
*(snd_pcm_format_t*)fields[k].ptr = f;
|
||||
break;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
err = snd_config_get_integer(n, &v);
|
||||
|
|
@ -4386,7 +4434,7 @@ int snd_pcm_slave_conf(snd_config_t *conf, snd_config_t **pcm_conf,
|
|||
if (k < count)
|
||||
continue;
|
||||
SNDERR("Unknown field %s", id);
|
||||
return -EINVAL;
|
||||
// return -EINVAL;
|
||||
}
|
||||
if (!pcm_valid) {
|
||||
SNDERR("missing field pcm");
|
||||
|
|
|
|||
|
|
@ -548,14 +548,15 @@ int snd_pcm_adpcm_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sfor
|
|||
}
|
||||
|
||||
int _snd_pcm_adpcm_open(snd_pcm_t **pcmp, const char *name,
|
||||
snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
snd_config_t *root, snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
{
|
||||
snd_config_iterator_t i, next;
|
||||
int err;
|
||||
snd_pcm_t *spcm;
|
||||
snd_config_t *slave = NULL, *sconf;
|
||||
snd_pcm_format_t sformat;
|
||||
const char *args;
|
||||
snd_config_for_each(i, next, conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
const char *id = snd_config_get_id(n);
|
||||
|
|
@ -572,7 +573,7 @@ int _snd_pcm_adpcm_open(snd_pcm_t **pcmp, const char *name,
|
|||
SNDERR("slave is not defined");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_pcm_slave_conf(slave, &sconf, 1,
|
||||
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 1,
|
||||
SND_PCM_HW_PARAM_FORMAT, 1, &sformat);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
|
@ -581,7 +582,7 @@ int _snd_pcm_adpcm_open(snd_pcm_t **pcmp, const char *name,
|
|||
SNDERR("invalid slave format");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
|
||||
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_pcm_adpcm_open(pcmp, name, sformat, spcm, 1);
|
||||
|
|
|
|||
|
|
@ -421,14 +421,15 @@ int snd_pcm_alaw_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sform
|
|||
}
|
||||
|
||||
int _snd_pcm_alaw_open(snd_pcm_t **pcmp, const char *name,
|
||||
snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
snd_config_t *root, snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
{
|
||||
snd_config_iterator_t i, next;
|
||||
int err;
|
||||
snd_pcm_t *spcm;
|
||||
snd_config_t *slave = NULL, *sconf;
|
||||
snd_pcm_format_t sformat;
|
||||
const char *args;
|
||||
snd_config_for_each(i, next, conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
const char *id = snd_config_get_id(n);
|
||||
|
|
@ -445,7 +446,7 @@ int _snd_pcm_alaw_open(snd_pcm_t **pcmp, const char *name,
|
|||
SNDERR("slave is not defined");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_pcm_slave_conf(slave, &sconf, 1,
|
||||
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 1,
|
||||
SND_PCM_HW_PARAM_FORMAT, 1, &sformat);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
|
@ -454,7 +455,7 @@ int _snd_pcm_alaw_open(snd_pcm_t **pcmp, const char *name,
|
|||
SNDERR("invalid slave format");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
|
||||
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_pcm_alaw_open(pcmp, name, sformat, spcm, 1);
|
||||
|
|
|
|||
|
|
@ -191,13 +191,14 @@ int snd_pcm_copy_open(snd_pcm_t **pcmp, const char *name, snd_pcm_t *slave, int
|
|||
}
|
||||
|
||||
int _snd_pcm_copy_open(snd_pcm_t **pcmp, const char *name,
|
||||
snd_config_t *conf,
|
||||
snd_config_t *root, snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
{
|
||||
snd_config_iterator_t i, next;
|
||||
int err;
|
||||
snd_pcm_t *spcm;
|
||||
snd_config_t *slave = NULL, *sconf;
|
||||
const char *args;
|
||||
snd_config_for_each(i, next, conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
const char *id = snd_config_get_id(n);
|
||||
|
|
@ -214,10 +215,10 @@ int _snd_pcm_copy_open(snd_pcm_t **pcmp, const char *name,
|
|||
SNDERR("slave is not defined");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_pcm_slave_conf(slave, &sconf, 0);
|
||||
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 0);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
|
||||
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_pcm_copy_open(pcmp, name, spcm, 1);
|
||||
|
|
|
|||
|
|
@ -456,7 +456,7 @@ int snd_pcm_file_open(snd_pcm_t **pcmp, const char *name, const char *fname, int
|
|||
}
|
||||
|
||||
int _snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
|
||||
snd_config_t *conf,
|
||||
snd_config_t *root, snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
{
|
||||
snd_config_iterator_t i, next;
|
||||
|
|
@ -466,6 +466,7 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
|
|||
const char *fname = NULL;
|
||||
const char *format = NULL;
|
||||
long fd = -1;
|
||||
const char *args;
|
||||
snd_config_for_each(i, next, conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
const char *id = snd_config_get_id(n);
|
||||
|
|
@ -501,14 +502,14 @@ int _snd_pcm_file_open(snd_pcm_t **pcmp, const char *name,
|
|||
SNDERR("slave is not defined");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_pcm_slave_conf(slave, &sconf, 0);
|
||||
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 0);
|
||||
if (err < 0)
|
||||
return err;
|
||||
if (!fname && fd < 0) {
|
||||
SNDERR("file is not defined");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
|
||||
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_pcm_file_open(pcmp, name, fname, fd, format, spcm, 1);
|
||||
|
|
|
|||
|
|
@ -433,7 +433,7 @@ int snd_pcm_hook_add_conf(snd_pcm_t *pcm, snd_config_t *conf)
|
|||
}
|
||||
|
||||
int _snd_pcm_hooks_open(snd_pcm_t **pcmp, const char *name,
|
||||
snd_config_t *conf,
|
||||
snd_config_t *root, snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
{
|
||||
snd_config_iterator_t i, next;
|
||||
|
|
@ -441,6 +441,7 @@ int _snd_pcm_hooks_open(snd_pcm_t **pcmp, const char *name,
|
|||
snd_pcm_t *spcm;
|
||||
snd_config_t *slave = NULL, *sconf;
|
||||
snd_config_t *hooks = NULL;
|
||||
const char *args;
|
||||
snd_config_for_each(i, next, conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
const char *id = snd_config_get_id(n);
|
||||
|
|
@ -465,10 +466,10 @@ int _snd_pcm_hooks_open(snd_pcm_t **pcmp, const char *name,
|
|||
SNDERR("slave is not defined");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_pcm_slave_conf(slave, &sconf, 0);
|
||||
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 0);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
|
||||
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_pcm_hooks_open(pcmp, name, spcm, 1);
|
||||
|
|
@ -513,6 +514,17 @@ void *snd_pcm_hook_get_private(snd_pcm_hook_t *hook)
|
|||
return hook->private_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set callback function private data for a PCM hook
|
||||
* \param hook PCM hook handle
|
||||
* \param private_data The private data value
|
||||
*/
|
||||
void snd_pcm_hook_set_private(snd_pcm_hook_t *hook, void *private_data)
|
||||
{
|
||||
assert(hook);
|
||||
hook->private_data = private_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Add a PCM hook at end of hooks chain
|
||||
* \param hookp Returned PCM hook handle
|
||||
|
|
@ -561,578 +573,56 @@ int snd_pcm_hook_remove(snd_pcm_hook_t *hook)
|
|||
return 0;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
unsigned int lock: 1;
|
||||
unsigned int preserve: 1;
|
||||
snd_ctl_elem_id_t *id;
|
||||
snd_ctl_elem_info_t *info;
|
||||
snd_ctl_elem_value_t *val;
|
||||
snd_ctl_elem_value_t *mask;
|
||||
snd_ctl_elem_value_t *old;
|
||||
struct list_head list;
|
||||
} snd_pcm_hook_ctl_elem_t;
|
||||
|
||||
typedef struct {
|
||||
snd_ctl_t *ctl;
|
||||
struct list_head elems;
|
||||
} snd_pcm_hook_ctl_elems_t;
|
||||
|
||||
static int free_elems(snd_pcm_hook_ctl_elems_t *h)
|
||||
{
|
||||
int err;
|
||||
while (!list_empty(&h->elems)) {
|
||||
snd_pcm_hook_ctl_elem_t *elem = list_entry(h->elems.next, snd_pcm_hook_ctl_elem_t, list);
|
||||
snd_ctl_elem_id_free(elem->id);
|
||||
snd_ctl_elem_info_free(elem->info);
|
||||
snd_ctl_elem_value_free(elem->val);
|
||||
snd_ctl_elem_value_free(elem->mask);
|
||||
snd_ctl_elem_value_free(elem->old);
|
||||
list_del(&elem->list);
|
||||
free(elem);
|
||||
}
|
||||
err = snd_ctl_close(h->ctl);
|
||||
if (err < 0)
|
||||
return err;
|
||||
free(h);
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
static int snd_pcm_hook_ctl_elems_hw_params(snd_pcm_hook_t *hook)
|
||||
{
|
||||
snd_pcm_hook_ctl_elems_t *h = snd_pcm_hook_get_private(hook);
|
||||
struct list_head *pos;
|
||||
int err;
|
||||
unsigned int k;
|
||||
list_for_each(pos, &h->elems) {
|
||||
snd_pcm_hook_ctl_elem_t *elem = list_entry(pos, snd_pcm_hook_ctl_elem_t, list);
|
||||
unsigned int count;
|
||||
snd_ctl_elem_type_t type;
|
||||
if (elem->lock) {
|
||||
err = snd_ctl_elem_lock(h->ctl, elem->id);
|
||||
if (err < 0) {
|
||||
SNDERR("Cannot lock ctl elem");
|
||||
return err;
|
||||
}
|
||||
}
|
||||
err = snd_ctl_elem_read(h->ctl, elem->old);
|
||||
if (err < 0) {
|
||||
SNDERR("Cannot read ctl elem");
|
||||
return err;
|
||||
}
|
||||
count = snd_ctl_elem_info_get_count(elem->info);
|
||||
type = snd_ctl_elem_info_get_type(elem->info);
|
||||
switch (type) {
|
||||
case SND_CTL_ELEM_TYPE_BOOLEAN:
|
||||
for (k = 0; k < count; ++k) {
|
||||
int old, val, mask;
|
||||
old = snd_ctl_elem_value_get_boolean(elem->old, k);
|
||||
mask = snd_ctl_elem_value_get_boolean(elem->mask, k);
|
||||
old &= ~mask;
|
||||
if (old) {
|
||||
val = snd_ctl_elem_value_get_boolean(elem->val, k);
|
||||
val |= old;
|
||||
snd_ctl_elem_value_set_boolean(elem->val, k, val);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SND_CTL_ELEM_TYPE_INTEGER:
|
||||
for (k = 0; k < count; ++k) {
|
||||
long old, val, mask;
|
||||
old = snd_ctl_elem_value_get_integer(elem->old, k);
|
||||
mask = snd_ctl_elem_value_get_integer(elem->mask, k);
|
||||
old &= ~mask;
|
||||
if (old) {
|
||||
val = snd_ctl_elem_value_get_integer(elem->val, k);
|
||||
val |= old;
|
||||
snd_ctl_elem_value_set_integer(elem->val, k, val);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SND_CTL_ELEM_TYPE_ENUMERATED:
|
||||
for (k = 0; k < count; ++k) {
|
||||
unsigned int old, val, mask;
|
||||
old = snd_ctl_elem_value_get_enumerated(elem->old, k);
|
||||
mask = snd_ctl_elem_value_get_enumerated(elem->mask, k);
|
||||
old &= ~mask;
|
||||
if (old) {
|
||||
val = snd_ctl_elem_value_get_enumerated(elem->val, k);
|
||||
val |= old;
|
||||
snd_ctl_elem_value_set_enumerated(elem->val, k, val);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SND_CTL_ELEM_TYPE_IEC958:
|
||||
count = sizeof(snd_aes_iec958_t);
|
||||
/* Fall through */
|
||||
case SND_CTL_ELEM_TYPE_BYTES:
|
||||
for (k = 0; k < count; ++k) {
|
||||
unsigned char old, val, mask;
|
||||
old = snd_ctl_elem_value_get_byte(elem->old, k);
|
||||
mask = snd_ctl_elem_value_get_byte(elem->mask, k);
|
||||
old &= ~mask;
|
||||
if (old) {
|
||||
val = snd_ctl_elem_value_get_byte(elem->val, k);
|
||||
val |= old;
|
||||
snd_ctl_elem_value_set_byte(elem->val, k, val);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
}
|
||||
err = snd_ctl_elem_write(h->ctl, elem->val);
|
||||
if (err < 0) {
|
||||
SNDERR("Cannot write ctl elem");
|
||||
return err;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
snd_sctl_t *h = snd_pcm_hook_get_private(hook);
|
||||
return snd_sctl_install(h);
|
||||
}
|
||||
|
||||
static int snd_pcm_hook_ctl_elems_hw_free(snd_pcm_hook_t *hook)
|
||||
{
|
||||
snd_pcm_hook_ctl_elems_t *h = snd_pcm_hook_get_private(hook);
|
||||
struct list_head *pos;
|
||||
int err;
|
||||
list_for_each(pos, &h->elems) {
|
||||
snd_pcm_hook_ctl_elem_t *elem = list_entry(pos, snd_pcm_hook_ctl_elem_t, list);
|
||||
if (elem->lock) {
|
||||
err = snd_ctl_elem_unlock(h->ctl, elem->id);
|
||||
if (err < 0) {
|
||||
SNDERR("Cannot unlock ctl elem");
|
||||
return err;
|
||||
}
|
||||
}
|
||||
if (elem->preserve) {
|
||||
err = snd_ctl_elem_write(h->ctl, elem->old);
|
||||
if (err < 0) {
|
||||
SNDERR("Cannot restore ctl elem");
|
||||
return err;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
snd_sctl_t *h = snd_pcm_hook_get_private(hook);
|
||||
return snd_sctl_remove(h);
|
||||
}
|
||||
|
||||
static int snd_pcm_hook_ctl_elems_close(snd_pcm_hook_t *hook)
|
||||
{
|
||||
snd_pcm_hook_ctl_elems_t *h = snd_pcm_hook_get_private(hook);
|
||||
return free_elems(h);
|
||||
}
|
||||
|
||||
int snd_config_get_iface(snd_config_t *conf)
|
||||
{
|
||||
long v;
|
||||
const char *str;
|
||||
int err;
|
||||
snd_ctl_elem_iface_t idx;
|
||||
err = snd_config_get_integer(conf, &v);
|
||||
if (err >= 0) {
|
||||
if (v < 0 || v > SND_CTL_ELEM_IFACE_LAST) {
|
||||
_invalid_value:
|
||||
SNDERR("Invalid value for %s", snd_config_get_id(conf));
|
||||
return -EINVAL;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
err = snd_config_get_string(conf, &str);
|
||||
if (err < 0) {
|
||||
SNDERR("Invalid type for %s", snd_config_get_id(conf));
|
||||
return -EINVAL;
|
||||
}
|
||||
for (idx = 0; idx <= SND_CTL_ELEM_IFACE_LAST; idx++) {
|
||||
if (strcasecmp(snd_ctl_elem_iface_name(idx), str) == 0)
|
||||
return idx;
|
||||
}
|
||||
goto _invalid_value;
|
||||
}
|
||||
|
||||
int snd_config_get_bool(snd_config_t *conf)
|
||||
{
|
||||
long v;
|
||||
const char *str;
|
||||
int err;
|
||||
unsigned int k;
|
||||
static struct {
|
||||
const char *str;
|
||||
int val;
|
||||
} b[] = {
|
||||
{ "false", 0 },
|
||||
{ "true", 1 },
|
||||
{ "no", 0 },
|
||||
{ "yes", 1 },
|
||||
{ "off", 0 },
|
||||
{ "on", 1 },
|
||||
};
|
||||
err = snd_config_get_integer(conf, &v);
|
||||
if (err >= 0) {
|
||||
if (v < 0 || v > 1) {
|
||||
_invalid_value:
|
||||
SNDERR("Invalid value for %s", snd_config_get_id(conf));
|
||||
return -EINVAL;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
err = snd_config_get_string(conf, &str);
|
||||
if (err < 0) {
|
||||
SNDERR("Invalid type for %s", snd_config_get_id(conf));
|
||||
return -EINVAL;
|
||||
}
|
||||
for (k = 0; k < sizeof(b) / sizeof(*b); k++) {
|
||||
if (strcasecmp(b[k].str, str) == 0)
|
||||
return b[k].val;
|
||||
}
|
||||
goto _invalid_value;
|
||||
}
|
||||
|
||||
int snd_config_get_ctl_elem_enumerated(snd_config_t *n, snd_ctl_t *ctl,
|
||||
snd_ctl_elem_info_t *info)
|
||||
{
|
||||
const char *str;
|
||||
long val;
|
||||
unsigned int idx, items;
|
||||
switch (snd_enum_to_int(snd_config_get_type(n))) {
|
||||
case SND_CONFIG_TYPE_INTEGER:
|
||||
snd_config_get_integer(n, &val);
|
||||
return val;
|
||||
case SND_CONFIG_TYPE_STRING:
|
||||
snd_config_get_string(n, &str);
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
items = snd_ctl_elem_info_get_items(info);
|
||||
for (idx = 0; idx < items; idx++) {
|
||||
int err;
|
||||
snd_ctl_elem_info_set_item(info, idx);
|
||||
err = snd_ctl_elem_info(ctl, info);
|
||||
if (err < 0) {
|
||||
SNDERR("Cannot obtain info for CTL elem");
|
||||
return err;
|
||||
}
|
||||
if (strcmp(str, snd_ctl_elem_info_get_item_name(info)) == 0)
|
||||
return idx;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int snd_config_get_ctl_elem_value(snd_config_t *conf,
|
||||
snd_ctl_t *ctl,
|
||||
snd_ctl_elem_value_t *val,
|
||||
snd_ctl_elem_value_t *mask,
|
||||
snd_ctl_elem_info_t *info)
|
||||
{
|
||||
int err;
|
||||
snd_config_iterator_t i, next;
|
||||
snd_ctl_elem_id_t *id;
|
||||
snd_ctl_elem_type_t type;
|
||||
unsigned int count;
|
||||
long v;
|
||||
long idx;
|
||||
snd_ctl_elem_id_alloca(&id);
|
||||
snd_ctl_elem_value_get_id(val, id);
|
||||
count = snd_ctl_elem_info_get_count(info);
|
||||
type = snd_ctl_elem_info_get_type(info);
|
||||
if (count == 1) {
|
||||
switch (snd_enum_to_int(type)) {
|
||||
case SND_CTL_ELEM_TYPE_BOOLEAN:
|
||||
v = snd_config_get_bool(conf);
|
||||
if (v >= 0) {
|
||||
snd_ctl_elem_value_set_boolean(val, 0, v);
|
||||
if (mask)
|
||||
snd_ctl_elem_value_set_boolean(mask, 0, 1);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case SND_CTL_ELEM_TYPE_INTEGER:
|
||||
err = snd_config_get_integer(conf, &v);
|
||||
if (err == 0) {
|
||||
snd_ctl_elem_value_set_integer(val, 0, v);
|
||||
if (mask)
|
||||
snd_ctl_elem_value_set_integer(mask, 0, ~0L);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case SND_CTL_ELEM_TYPE_ENUMERATED:
|
||||
v = snd_config_get_ctl_elem_enumerated(conf, ctl, info);
|
||||
if (v >= 0) {
|
||||
snd_ctl_elem_value_set_enumerated(val, 0, v);
|
||||
if (mask)
|
||||
snd_ctl_elem_value_set_enumerated(mask, 0, ~0);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case SND_CTL_ELEM_TYPE_BYTES:
|
||||
case SND_CTL_ELEM_TYPE_IEC958:
|
||||
break;
|
||||
default:
|
||||
SNDERR("Unknow control type: %d", snd_enum_to_int(type));
|
||||
return -EINVAL;
|
||||
}
|
||||
}
|
||||
switch (snd_enum_to_int(type)) {
|
||||
case SND_CTL_ELEM_TYPE_IEC958:
|
||||
count = sizeof(snd_aes_iec958_t);
|
||||
/* Fall through */
|
||||
case SND_CTL_ELEM_TYPE_BYTES:
|
||||
{
|
||||
const char *buf;
|
||||
err = snd_config_get_string(conf, &buf);
|
||||
if (err >= 0) {
|
||||
int c1 = 0;
|
||||
unsigned int len = strlen(buf);
|
||||
unsigned int idx = 0;
|
||||
if (len % 2 != 0 || len > count * 2) {
|
||||
_bad_content:
|
||||
SNDERR("bad value content\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
while (*buf) {
|
||||
int c = *buf++;
|
||||
if (c >= '0' && c <= '9')
|
||||
c -= '0';
|
||||
else if (c >= 'a' && c <= 'f')
|
||||
c = c - 'a' + 10;
|
||||
else if (c >= 'A' && c <= 'F')
|
||||
c = c - 'A' + 10;
|
||||
else {
|
||||
goto _bad_content;
|
||||
}
|
||||
if (idx % 2 == 1) {
|
||||
snd_ctl_elem_value_set_byte(val, idx / 2, c1 << 4 | c);
|
||||
if (mask)
|
||||
snd_ctl_elem_value_set_byte(mask, idx / 2, 0xff);
|
||||
} else
|
||||
c1 = c;
|
||||
idx++;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (snd_config_get_type(conf) != SND_CONFIG_TYPE_COMPOUND) {
|
||||
SNDERR("bad value type");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
snd_config_for_each(i, next, conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
err = safe_strtol(snd_config_get_id(n), &idx);
|
||||
if (err < 0 || idx < 0 || (unsigned int) idx >= count) {
|
||||
SNDERR("bad value index");
|
||||
return -EINVAL;
|
||||
}
|
||||
switch (snd_enum_to_int(type)) {
|
||||
case SND_CTL_ELEM_TYPE_BOOLEAN:
|
||||
v = snd_config_get_bool(n);
|
||||
if (v < 0)
|
||||
goto _bad_content;
|
||||
snd_ctl_elem_value_set_boolean(val, idx, v);
|
||||
if (mask)
|
||||
snd_ctl_elem_value_set_boolean(mask, idx, 1);
|
||||
break;
|
||||
case SND_CTL_ELEM_TYPE_INTEGER:
|
||||
err = snd_config_get_integer(n, &v);
|
||||
if (err < 0)
|
||||
goto _bad_content;
|
||||
snd_ctl_elem_value_set_integer(val, idx, v);
|
||||
if (mask)
|
||||
snd_ctl_elem_value_set_integer(mask, idx, ~0L);
|
||||
break;
|
||||
case SND_CTL_ELEM_TYPE_ENUMERATED:
|
||||
v = snd_config_get_ctl_elem_enumerated(n, ctl, info);
|
||||
if (v < 0)
|
||||
goto _bad_content;
|
||||
snd_ctl_elem_value_set_enumerated(val, idx, v);
|
||||
if (mask)
|
||||
snd_ctl_elem_value_set_enumerated(mask, idx, ~0);
|
||||
break;
|
||||
case SND_CTL_ELEM_TYPE_BYTES:
|
||||
case SND_CTL_ELEM_TYPE_IEC958:
|
||||
err = snd_config_get_integer(n, &v);
|
||||
if (err < 0 || v < 0 || v > 255)
|
||||
goto _bad_content;
|
||||
snd_ctl_elem_value_set_byte(val, idx, v);
|
||||
if (mask)
|
||||
snd_ctl_elem_value_set_byte(mask, idx, 0xff);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int add_elem(snd_pcm_hook_ctl_elems_t *h, snd_config_t *conf, snd_pcm_info_t *info)
|
||||
{
|
||||
snd_config_iterator_t i, next;
|
||||
int iface = SND_CTL_ELEM_IFACE_PCM;
|
||||
const char *name = NULL;
|
||||
long index = 0;
|
||||
long device = -1;
|
||||
long subdevice = -1;
|
||||
int lock = 0;
|
||||
int preserve = 0;
|
||||
snd_config_t *value = NULL, *mask = NULL;
|
||||
snd_pcm_hook_ctl_elem_t *elem;
|
||||
int err;
|
||||
snd_config_for_each(i, next, conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
const char *id = snd_config_get_id(n);
|
||||
if (strcmp(id, "comment") == 0)
|
||||
continue;
|
||||
if (strcmp(id, "iface") == 0) {
|
||||
iface = snd_config_get_iface(n);
|
||||
if (iface < 0)
|
||||
return iface;
|
||||
continue;
|
||||
}
|
||||
if (strcmp(id, "name") == 0) {
|
||||
err = snd_config_get_string(n, &name);
|
||||
if (err < 0) {
|
||||
_invalid_type:
|
||||
SNDERR("Invalid type for %s", id);
|
||||
return err;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (strcmp(id, "index") == 0) {
|
||||
err = snd_config_get_integer(n, &index);
|
||||
if (err < 0)
|
||||
goto _invalid_type;
|
||||
continue;
|
||||
}
|
||||
if (strcmp(id, "device") == 0) {
|
||||
err = snd_config_get_integer(n, &device);
|
||||
if (err < 0)
|
||||
goto _invalid_type;
|
||||
continue;
|
||||
}
|
||||
if (strcmp(id, "subdevice") == 0) {
|
||||
err = snd_config_get_integer(n, &subdevice);
|
||||
if (err < 0)
|
||||
goto _invalid_type;
|
||||
continue;
|
||||
}
|
||||
if (strcmp(id, "lock") == 0) {
|
||||
lock = snd_config_get_bool(n);
|
||||
if (lock < 0) {
|
||||
err = lock;
|
||||
_invalid_value:
|
||||
SNDERR("Invalid value for %s", id);
|
||||
return err;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (strcmp(id, "preserve") == 0) {
|
||||
preserve = snd_config_get_bool(n);
|
||||
if (preserve < 0) {
|
||||
err = preserve;
|
||||
goto _invalid_value;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (strcmp(id, "value") == 0) {
|
||||
value = n;
|
||||
continue;
|
||||
}
|
||||
if (strcmp(id, "mask") == 0) {
|
||||
mask = n;
|
||||
continue;
|
||||
}
|
||||
SNDERR("Unknown field %s", id);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!name) {
|
||||
SNDERR("Missing control name");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (!value) {
|
||||
SNDERR("Missing control value");
|
||||
return -EINVAL;
|
||||
}
|
||||
if (device < 0) {
|
||||
if (iface == SND_CTL_ELEM_IFACE_PCM)
|
||||
device = snd_pcm_info_get_device(info);
|
||||
else
|
||||
device = 0;
|
||||
}
|
||||
if (subdevice < 0) {
|
||||
if (iface == SND_CTL_ELEM_IFACE_PCM)
|
||||
subdevice = snd_pcm_info_get_subdevice(info);
|
||||
else
|
||||
subdevice = 0;
|
||||
}
|
||||
elem = calloc(1, sizeof(*elem));
|
||||
if (!elem)
|
||||
return -ENOMEM;
|
||||
err = snd_ctl_elem_id_malloc(&elem->id);
|
||||
if (err < 0)
|
||||
goto _err;
|
||||
err = snd_ctl_elem_info_malloc(&elem->info);
|
||||
if (err < 0)
|
||||
goto _err;
|
||||
err = snd_ctl_elem_value_malloc(&elem->val);
|
||||
if (err < 0)
|
||||
goto _err;
|
||||
err = snd_ctl_elem_value_malloc(&elem->mask);
|
||||
if (err < 0)
|
||||
goto _err;
|
||||
err = snd_ctl_elem_value_malloc(&elem->old);
|
||||
if (err < 0)
|
||||
goto _err;
|
||||
elem->lock = lock;
|
||||
elem->preserve = preserve;
|
||||
snd_ctl_elem_id_set_interface(elem->id, iface);
|
||||
snd_ctl_elem_id_set_name(elem->id, name);
|
||||
snd_ctl_elem_id_set_index(elem->id, index);
|
||||
snd_ctl_elem_id_set_device(elem->id, device);
|
||||
snd_ctl_elem_id_set_subdevice(elem->id, subdevice);
|
||||
snd_ctl_elem_info_set_id(elem->info, elem->id);
|
||||
err = snd_ctl_elem_info(h->ctl, elem->info);
|
||||
if (err < 0) {
|
||||
SNDERR("Cannot obtain info for CTL elem");
|
||||
goto _err;
|
||||
}
|
||||
snd_ctl_elem_value_set_id(elem->val, elem->id);
|
||||
snd_ctl_elem_value_set_id(elem->old, elem->id);
|
||||
if (mask) {
|
||||
err = snd_config_get_ctl_elem_value(value, h->ctl, elem->val, NULL, elem->info);
|
||||
if (err < 0)
|
||||
goto _err;
|
||||
err = snd_config_get_ctl_elem_value(mask, h->ctl, elem->mask, NULL, elem->info);
|
||||
if (err < 0)
|
||||
goto _err;
|
||||
} else {
|
||||
err = snd_config_get_ctl_elem_value(value, h->ctl, elem->val, elem->mask, elem->info);
|
||||
if (err < 0)
|
||||
goto _err;
|
||||
}
|
||||
|
||||
err = snd_config_get_ctl_elem_value(value, h->ctl, elem->val, elem->mask, elem->info);
|
||||
if (err < 0)
|
||||
goto _err;
|
||||
list_add_tail(&elem->list, &h->elems);
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
if (elem->id)
|
||||
snd_ctl_elem_id_free(elem->id);
|
||||
if (elem->info)
|
||||
snd_ctl_elem_info_free(elem->info);
|
||||
if (elem->val)
|
||||
snd_ctl_elem_value_free(elem->val);
|
||||
if (elem->mask)
|
||||
snd_ctl_elem_value_free(elem->mask);
|
||||
if (elem->old)
|
||||
snd_ctl_elem_value_free(elem->old);
|
||||
free(elem);
|
||||
snd_sctl_t *h = snd_pcm_hook_get_private(hook);
|
||||
int err = snd_sctl_free(h);
|
||||
snd_pcm_hook_set_private(hook, NULL);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int snd_pcm_hook_ctl_elems_replace(const char *what, char **dst, void *private_data)
|
||||
{
|
||||
snd_pcm_t *pcm = private_data;
|
||||
snd_pcm_info_t *info;
|
||||
char str[12];
|
||||
long val;
|
||||
int err;
|
||||
|
||||
snd_pcm_info_alloca(&info);
|
||||
err = snd_pcm_info(pcm, info);
|
||||
if (err < 0)
|
||||
return err;
|
||||
if (!strcmp(what, "card")) {
|
||||
val = snd_pcm_info_get_card(info);
|
||||
} else if (!strcmp(what, "device")) {
|
||||
val = snd_pcm_info_get_device(info);
|
||||
} else if (!strcmp(what, "subdevice")) {
|
||||
val = snd_pcm_info_get_subdevice(info);
|
||||
} else
|
||||
return 0; /* empty string */
|
||||
snprintf(str, sizeof(str), "%li", val);
|
||||
str[sizeof(str)-1] = '\0';
|
||||
*dst = strdup(str);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _snd_pcm_hook_ctl_elems_install(snd_pcm_t *pcm, snd_config_t *conf)
|
||||
{
|
||||
int err;
|
||||
|
|
@ -1140,8 +630,7 @@ int _snd_pcm_hook_ctl_elems_install(snd_pcm_t *pcm, snd_config_t *conf)
|
|||
snd_pcm_info_t *info;
|
||||
char ctl_name[16];
|
||||
snd_ctl_t *ctl;
|
||||
snd_pcm_hook_ctl_elems_t *h;
|
||||
snd_config_iterator_t i, next;
|
||||
snd_sctl_t *sctl;
|
||||
snd_pcm_hook_t *h_hw_params = NULL, *h_hw_free = NULL, *h_close = NULL;
|
||||
assert(conf);
|
||||
assert(snd_config_get_type(conf) == SND_CONFIG_TYPE_COMPOUND);
|
||||
|
|
@ -1160,31 +649,19 @@ int _snd_pcm_hook_ctl_elems_install(snd_pcm_t *pcm, snd_config_t *conf)
|
|||
SNDERR("Cannot open CTL %s", ctl_name);
|
||||
return err;
|
||||
}
|
||||
h = calloc(1, sizeof(*h));
|
||||
if (!h) {
|
||||
snd_ctl_close(ctl);
|
||||
err = snd_sctl_build(&sctl, ctl, conf, snd_pcm_hook_ctl_elems_replace, pcm, 0);
|
||||
if (err < 0)
|
||||
return -ENOMEM;
|
||||
}
|
||||
h->ctl = ctl;
|
||||
INIT_LIST_HEAD(&h->elems);
|
||||
snd_config_for_each(i, next, conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
err = add_elem(h, n, info);
|
||||
if (err < 0) {
|
||||
free_elems(h);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
err = snd_pcm_hook_add(&h_hw_params, pcm, SND_PCM_HOOK_TYPE_HW_PARAMS,
|
||||
snd_pcm_hook_ctl_elems_hw_params, h);
|
||||
snd_pcm_hook_ctl_elems_hw_params, sctl);
|
||||
if (err < 0)
|
||||
goto _err;
|
||||
err = snd_pcm_hook_add(&h_hw_free, pcm, SND_PCM_HOOK_TYPE_HW_FREE,
|
||||
snd_pcm_hook_ctl_elems_hw_free, h);
|
||||
snd_pcm_hook_ctl_elems_hw_free, sctl);
|
||||
if (err < 0)
|
||||
goto _err;
|
||||
err = snd_pcm_hook_add(&h_close, pcm, SND_PCM_HOOK_TYPE_CLOSE,
|
||||
snd_pcm_hook_ctl_elems_close, h);
|
||||
snd_pcm_hook_ctl_elems_close, sctl);
|
||||
if (err < 0)
|
||||
goto _err;
|
||||
return 0;
|
||||
|
|
@ -1195,7 +672,6 @@ int _snd_pcm_hook_ctl_elems_install(snd_pcm_t *pcm, snd_config_t *conf)
|
|||
snd_pcm_hook_remove(h_hw_free);
|
||||
if (h_close)
|
||||
snd_pcm_hook_remove(h_close);
|
||||
free_elems(h);
|
||||
snd_sctl_free(sctl);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -659,7 +659,8 @@ int snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name, int card, int device, in
|
|||
return 0;
|
||||
}
|
||||
|
||||
int _snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
|
||||
int _snd_pcm_hw_open(snd_pcm_t **pcmp, const char *name,
|
||||
snd_config_t *root ATTRIBUTE_UNUSED, snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
{
|
||||
snd_config_iterator_t i, next;
|
||||
|
|
|
|||
|
|
@ -326,7 +326,7 @@ int snd_pcm_linear_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sfo
|
|||
}
|
||||
|
||||
int _snd_pcm_linear_open(snd_pcm_t **pcmp, const char *name,
|
||||
snd_config_t *conf,
|
||||
snd_config_t *root, snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
{
|
||||
snd_config_iterator_t i, next;
|
||||
|
|
@ -334,6 +334,7 @@ int _snd_pcm_linear_open(snd_pcm_t **pcmp, const char *name,
|
|||
snd_pcm_t *spcm;
|
||||
snd_config_t *slave = NULL, *sconf;
|
||||
snd_pcm_format_t sformat;
|
||||
const char *args;
|
||||
snd_config_for_each(i, next, conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
const char *id = snd_config_get_id(n);
|
||||
|
|
@ -350,7 +351,7 @@ int _snd_pcm_linear_open(snd_pcm_t **pcmp, const char *name,
|
|||
SNDERR("slave is not defined");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_pcm_slave_conf(slave, &sconf, 1,
|
||||
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 1,
|
||||
SND_PCM_HW_PARAM_FORMAT, 1, &sformat);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
|
@ -358,7 +359,7 @@ int _snd_pcm_linear_open(snd_pcm_t **pcmp, const char *name,
|
|||
SNDERR("slave format is not linear");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
|
||||
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_pcm_linear_open(pcmp, name, sformat, spcm, 1);
|
||||
|
|
|
|||
|
|
@ -527,11 +527,11 @@ int snd_pcm_hw_strategy_simple_choices(snd_pcm_hw_strategy_t *strategy, int orde
|
|||
snd_pcm_hw_strategy_simple_choices_list_t *choices);
|
||||
#endif
|
||||
|
||||
int snd_pcm_slave_conf(snd_config_t *conf, snd_config_t **pcm_conf,
|
||||
unsigned int count, ...);
|
||||
int snd_pcm_slave_conf(snd_config_t *root, snd_config_t *conf, snd_config_t **pcm_conf,
|
||||
const char **args, unsigned int count, ...);
|
||||
|
||||
int snd_pcm_open_slave(snd_pcm_t **pcmp, snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode);
|
||||
int snd_pcm_open_slave(snd_pcm_t **pcmp, snd_config_t *root, snd_config_t *conf,
|
||||
const char *args, snd_pcm_stream_t stream, int mode);
|
||||
int snd_pcm_conf_generic_id(const char *id);
|
||||
|
||||
#define SND_PCM_HW_PARBIT_ACCESS (1U << SND_PCM_HW_PARAM_ACCESS)
|
||||
|
|
@ -575,5 +575,3 @@ int snd_pcm_conf_generic_id(const char *id);
|
|||
(1U << SND_PCM_FORMAT_S32_BE) | \
|
||||
(1U << SND_PCM_FORMAT_U32_LE) | \
|
||||
(1U << SND_PCM_FORMAT_U32_BE))
|
||||
|
||||
int safe_strtol(const char *str, long *val);
|
||||
|
|
|
|||
|
|
@ -734,7 +734,7 @@ static int snd_pcm_meter_add_scope_conf(snd_pcm_t *pcm, const char *name,
|
|||
|
||||
|
||||
int _snd_pcm_meter_open(snd_pcm_t **pcmp, const char *name,
|
||||
snd_config_t *conf,
|
||||
snd_config_t *root, snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
{
|
||||
snd_config_iterator_t i, next;
|
||||
|
|
@ -743,6 +743,7 @@ int _snd_pcm_meter_open(snd_pcm_t **pcmp, const char *name,
|
|||
snd_config_t *slave = NULL, *sconf;
|
||||
long frequency = -1;
|
||||
snd_config_t *scopes = NULL;
|
||||
const char *args;
|
||||
snd_config_for_each(i, next, conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
const char *id = snd_config_get_id(n);
|
||||
|
|
@ -775,10 +776,10 @@ int _snd_pcm_meter_open(snd_pcm_t **pcmp, const char *name,
|
|||
SNDERR("slave is not defined");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_pcm_slave_conf(slave, &sconf, 0);
|
||||
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 0);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
|
||||
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_pcm_meter_open(pcmp, name, frequency > 0 ? (unsigned int) frequency : FREQUENCY, spcm, 1);
|
||||
|
|
|
|||
|
|
@ -436,14 +436,15 @@ int snd_pcm_mulaw_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sfor
|
|||
}
|
||||
|
||||
int _snd_pcm_mulaw_open(snd_pcm_t **pcmp, const char *name,
|
||||
snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
snd_config_t *root, snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
{
|
||||
snd_config_iterator_t i, next;
|
||||
int err;
|
||||
snd_pcm_t *spcm;
|
||||
snd_config_t *slave = NULL, *sconf;
|
||||
snd_pcm_format_t sformat;
|
||||
const char *args;
|
||||
snd_config_for_each(i, next, conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
const char *id = snd_config_get_id(n);
|
||||
|
|
@ -460,7 +461,7 @@ int _snd_pcm_mulaw_open(snd_pcm_t **pcmp, const char *name,
|
|||
SNDERR("slave is not defined");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_pcm_slave_conf(slave, &sconf, 1,
|
||||
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 1,
|
||||
SND_PCM_HW_PARAM_FORMAT, 1, &sformat);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
|
@ -469,7 +470,7 @@ int _snd_pcm_mulaw_open(snd_pcm_t **pcmp, const char *name,
|
|||
SNDERR("invalid slave format");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
|
||||
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_pcm_mulaw_open(pcmp, name, sformat, spcm, 1);
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
unsigned int slaves_count;
|
||||
unsigned int master_slave;
|
||||
snd_pcm_multi_slave_t *slaves;
|
||||
unsigned int channels_count;
|
||||
snd_pcm_multi_channel_t *channels;
|
||||
|
|
@ -575,7 +576,7 @@ snd_pcm_fast_ops_t snd_pcm_multi_fast_ops = {
|
|||
};
|
||||
|
||||
int snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name,
|
||||
unsigned int slaves_count,
|
||||
unsigned int slaves_count, unsigned int master_slave,
|
||||
snd_pcm_t **slaves_pcm, unsigned int *schannels_count,
|
||||
unsigned int channels_count,
|
||||
int *sidxs, unsigned int *schannels,
|
||||
|
|
@ -590,6 +591,7 @@ int snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name,
|
|||
assert(pcmp);
|
||||
assert(slaves_count > 0 && slaves_pcm && schannels_count);
|
||||
assert(channels_count > 0 && sidxs && schannels);
|
||||
assert(master_slave < slaves_count);
|
||||
|
||||
multi = calloc(1, sizeof(snd_pcm_multi_t));
|
||||
if (!multi) {
|
||||
|
|
@ -599,6 +601,7 @@ int snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name,
|
|||
stream = slaves_pcm[0]->stream;
|
||||
|
||||
multi->slaves_count = slaves_count;
|
||||
multi->master_slave = master_slave;
|
||||
multi->slaves = calloc(slaves_count, sizeof(*multi->slaves));
|
||||
multi->channels_count = channels_count;
|
||||
multi->channels = calloc(channels_count, sizeof(*multi->channels));
|
||||
|
|
@ -638,14 +641,15 @@ int snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name,
|
|||
pcm->fast_ops = &snd_pcm_multi_fast_ops;
|
||||
pcm->fast_op_arg = pcm;
|
||||
pcm->private_data = multi;
|
||||
pcm->poll_fd = multi->slaves[0].pcm->poll_fd;
|
||||
pcm->hw_ptr = multi->slaves[0].pcm->hw_ptr;
|
||||
pcm->appl_ptr = multi->slaves[0].pcm->appl_ptr;
|
||||
pcm->poll_fd = multi->slaves[master_slave].pcm->poll_fd;
|
||||
pcm->hw_ptr = multi->slaves[master_slave].pcm->hw_ptr;
|
||||
pcm->appl_ptr = multi->slaves[master_slave].pcm->appl_ptr;
|
||||
*pcmp = pcm;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int _snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
|
||||
int _snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name,
|
||||
snd_config_t *root, snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
{
|
||||
snd_config_iterator_t i, inext, j, jnext;
|
||||
|
|
@ -655,11 +659,13 @@ int _snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
|
|||
unsigned int idx;
|
||||
const char **slaves_id = NULL;
|
||||
snd_config_t **slaves_conf = NULL;
|
||||
const char **slaves_args = NULL;
|
||||
snd_pcm_t **slaves_pcm = NULL;
|
||||
unsigned int *slaves_channels = NULL;
|
||||
int *channels_sidx = NULL;
|
||||
unsigned int *channels_schannel = NULL;
|
||||
unsigned int slaves_count = 0;
|
||||
long master_slave = 0;
|
||||
unsigned int channels_count = 0;
|
||||
snd_config_for_each(i, inext, conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
|
|
@ -682,6 +688,13 @@ int _snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
|
|||
bindings = n;
|
||||
continue;
|
||||
}
|
||||
if (strcmp(id, "master") == 0) {
|
||||
if (snd_config_get_integer(n, &((long)master_slave)) < 0) {
|
||||
SNDERR("Invalid type for %s", id);
|
||||
return -EINVAL;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
SNDERR("Unknown field %s", id);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
|
@ -696,6 +709,10 @@ int _snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
|
|||
snd_config_for_each(i, inext, slaves) {
|
||||
++slaves_count;
|
||||
}
|
||||
if (master_slave < 0 || master_slave >= (long)slaves_count) {
|
||||
SNDERR("Master slave is out of range (0-%u)\n", slaves_count-1);
|
||||
return -EINVAL;
|
||||
}
|
||||
snd_config_for_each(i, inext, bindings) {
|
||||
long cchannel;
|
||||
snd_config_t *m = snd_config_iterator_entry(i);
|
||||
|
|
@ -714,6 +731,7 @@ int _snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
|
|||
}
|
||||
slaves_id = calloc(slaves_count, sizeof(*slaves_id));
|
||||
slaves_conf = calloc(slaves_count, sizeof(*slaves_conf));
|
||||
slaves_args = calloc(slaves_count, sizeof(*slaves_args));
|
||||
slaves_pcm = calloc(slaves_count, sizeof(*slaves_pcm));
|
||||
slaves_channels = calloc(slaves_count, sizeof(*slaves_channels));
|
||||
channels_sidx = calloc(channels_count, sizeof(*channels_sidx));
|
||||
|
|
@ -726,7 +744,7 @@ int _snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
|
|||
snd_config_t *m = snd_config_iterator_entry(i);
|
||||
int channels;
|
||||
slaves_id[idx] = snd_config_get_id(m);
|
||||
err = snd_pcm_slave_conf(m, &slaves_conf[idx], 1,
|
||||
err = snd_pcm_slave_conf(root, m, &slaves_conf[idx], &slaves_args[idx], 1,
|
||||
SND_PCM_HW_PARAM_CHANNELS, 1, &channels);
|
||||
if (err < 0)
|
||||
goto _free;
|
||||
|
|
@ -800,12 +818,12 @@ int _snd_pcm_multi_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
|
|||
}
|
||||
|
||||
for (idx = 0; idx < slaves_count; ++idx) {
|
||||
err = snd_pcm_open_slave(&slaves_pcm[idx], slaves_conf[idx], stream, mode);
|
||||
err = snd_pcm_open_slave(&slaves_pcm[idx], root, slaves_conf[idx], slaves_args[idx], stream, mode);
|
||||
if (err < 0)
|
||||
goto _free;
|
||||
}
|
||||
err = snd_pcm_multi_open(pcmp, name, slaves_count, slaves_pcm,
|
||||
slaves_channels,
|
||||
err = snd_pcm_multi_open(pcmp, name, slaves_count, master_slave,
|
||||
slaves_pcm, slaves_channels,
|
||||
channels_count,
|
||||
channels_sidx, channels_schannel,
|
||||
1);
|
||||
|
|
@ -818,6 +836,8 @@ _free:
|
|||
}
|
||||
if (slaves_conf)
|
||||
free(slaves_conf);
|
||||
if (slaves_args)
|
||||
free(slaves_args);
|
||||
if (slaves_pcm)
|
||||
free(slaves_pcm);
|
||||
if (slaves_channels)
|
||||
|
|
|
|||
|
|
@ -711,7 +711,7 @@ int snd_pcm_plug_open_hw(snd_pcm_t **pcmp, const char *name, int card, int devic
|
|||
#define MAX_CHANNELS 32
|
||||
|
||||
int _snd_pcm_plug_open(snd_pcm_t **pcmp, const char *name,
|
||||
snd_config_t *conf,
|
||||
snd_config_t *root, snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
{
|
||||
snd_config_iterator_t i, next;
|
||||
|
|
@ -721,6 +721,7 @@ int _snd_pcm_plug_open(snd_pcm_t **pcmp, const char *name,
|
|||
snd_config_t *tt = NULL;
|
||||
snd_pcm_route_ttable_entry_t *ttable = NULL;
|
||||
unsigned int cused, sused;
|
||||
const char *args;
|
||||
snd_config_for_each(i, next, conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
const char *id = snd_config_get_id(n);
|
||||
|
|
@ -745,7 +746,7 @@ int _snd_pcm_plug_open(snd_pcm_t **pcmp, const char *name,
|
|||
SNDERR("slave is not defined");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_pcm_slave_conf(slave, &sconf, 0);
|
||||
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 0);
|
||||
if (err < 0)
|
||||
return err;
|
||||
if (tt) {
|
||||
|
|
@ -756,7 +757,7 @@ int _snd_pcm_plug_open(snd_pcm_t **pcmp, const char *name,
|
|||
return err;
|
||||
}
|
||||
|
||||
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
|
||||
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_pcm_plug_open(pcmp, name, ttable, MAX_CHANNELS, cused, sused, spcm, 1);
|
||||
|
|
|
|||
|
|
@ -535,8 +535,8 @@ int snd_pcm_rate_open(snd_pcm_t **pcmp, const char *name, snd_pcm_format_t sform
|
|||
}
|
||||
|
||||
int _snd_pcm_rate_open(snd_pcm_t **pcmp, const char *name,
|
||||
snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
snd_config_t *root, snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
{
|
||||
snd_config_iterator_t i, next;
|
||||
int err;
|
||||
|
|
@ -544,6 +544,7 @@ int _snd_pcm_rate_open(snd_pcm_t **pcmp, const char *name,
|
|||
snd_config_t *slave = NULL, *sconf;
|
||||
snd_pcm_format_t sformat = SND_PCM_FORMAT_UNKNOWN;
|
||||
int srate = -1;
|
||||
const char *args;
|
||||
snd_config_for_each(i, next, conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
const char *id = snd_config_get_id(n);
|
||||
|
|
@ -560,7 +561,7 @@ int _snd_pcm_rate_open(snd_pcm_t **pcmp, const char *name,
|
|||
SNDERR("slave is not defined");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_pcm_slave_conf(slave, &sconf, 2,
|
||||
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 2,
|
||||
SND_PCM_HW_PARAM_FORMAT, 0, &sformat,
|
||||
SND_PCM_HW_PARAM_RATE, 1, &srate);
|
||||
if (err < 0)
|
||||
|
|
@ -570,7 +571,7 @@ int _snd_pcm_rate_open(snd_pcm_t **pcmp, const char *name,
|
|||
SNDERR("slave format is not linear");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
|
||||
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_pcm_rate_open(pcmp, name,
|
||||
|
|
|
|||
|
|
@ -836,7 +836,7 @@ int snd_pcm_route_load_ttable(snd_config_t *tt, snd_pcm_route_ttable_entry_t *tt
|
|||
#define MAX_CHANNELS 32
|
||||
|
||||
int _snd_pcm_route_open(snd_pcm_t **pcmp, const char *name,
|
||||
snd_config_t *conf,
|
||||
snd_config_t *root, snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
{
|
||||
snd_config_iterator_t i, next;
|
||||
|
|
@ -848,6 +848,7 @@ int _snd_pcm_route_open(snd_pcm_t **pcmp, const char *name,
|
|||
snd_config_t *tt = NULL;
|
||||
snd_pcm_route_ttable_entry_t ttable[MAX_CHANNELS*MAX_CHANNELS];
|
||||
unsigned int cused, sused;
|
||||
const char *args;
|
||||
snd_config_for_each(i, next, conf) {
|
||||
snd_config_t *n = snd_config_iterator_entry(i);
|
||||
const char *id = snd_config_get_id(n);
|
||||
|
|
@ -876,7 +877,7 @@ int _snd_pcm_route_open(snd_pcm_t **pcmp, const char *name,
|
|||
SNDERR("ttable is not defined");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_pcm_slave_conf(slave, &sconf, 2,
|
||||
err = snd_pcm_slave_conf(root, slave, &sconf, &args, 2,
|
||||
SND_PCM_HW_PARAM_FORMAT, 0, &sformat,
|
||||
SND_PCM_HW_PARAM_CHANNELS, 0, &schannels);
|
||||
if (err < 0)
|
||||
|
|
@ -892,7 +893,7 @@ int _snd_pcm_route_open(snd_pcm_t **pcmp, const char *name,
|
|||
if (err < 0)
|
||||
return err;
|
||||
|
||||
err = snd_pcm_open_slave(&spcm, sconf, stream, mode);
|
||||
err = snd_pcm_open_slave(&spcm, root, sconf, args, stream, mode);
|
||||
if (err < 0)
|
||||
return err;
|
||||
err = snd_pcm_route_open(pcmp, name, sformat, schannels,
|
||||
|
|
|
|||
|
|
@ -1367,7 +1367,8 @@ int snd_pcm_share_open(snd_pcm_t **pcmp, const char *name, const char *sname,
|
|||
return 0;
|
||||
}
|
||||
|
||||
int _snd_pcm_share_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
|
||||
int _snd_pcm_share_open(snd_pcm_t **pcmp, const char *name,
|
||||
snd_config_t *root, snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
{
|
||||
snd_config_iterator_t i, next;
|
||||
|
|
@ -1413,7 +1414,7 @@ int _snd_pcm_share_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
|
|||
SNDERR("slave is not defined");
|
||||
return -EINVAL;
|
||||
}
|
||||
err = snd_pcm_slave_conf(slave, &sconf, 5,
|
||||
err = snd_pcm_slave_conf(root, slave, &sconf, NULL, 5,
|
||||
SND_PCM_HW_PARAM_CHANNELS, 0, &schannels,
|
||||
SND_PCM_HW_PARAM_FORMAT, 0, &sformat,
|
||||
SND_PCM_HW_PARAM_RATE, 0, &srate,
|
||||
|
|
|
|||
|
|
@ -719,7 +719,8 @@ int is_local(struct hostent *hent)
|
|||
return i < numreqs;
|
||||
}
|
||||
|
||||
int _snd_pcm_shm_open(snd_pcm_t **pcmp, const char *name, snd_config_t *conf,
|
||||
int _snd_pcm_shm_open(snd_pcm_t **pcmp, const char *name,
|
||||
snd_config_t *root ATTRIBUTE_UNUSED, snd_config_t *conf,
|
||||
snd_pcm_stream_t stream, int mode)
|
||||
{
|
||||
snd_config_iterator_t i, next;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue