mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-29 05:40:25 -04:00
Removed snd_config_string_replace function.
Added back modified snd_config_refer_load function.
Added snd_func_private_pcm_subdevice function.
Removed the callback from the snd_sctl_build function (no more required).
Modified alsa.conf to use refer {} blocks again.
Modified card specific conf files to use new snd_func_private_pcm_subdevice function.
This commit is contained in:
parent
2ced309ee8
commit
3a993b4a3e
10 changed files with 304 additions and 314 deletions
|
|
@ -95,10 +95,8 @@ int snd_config_get_ctl_iface(snd_config_t *conf);
|
||||||
|
|
||||||
typedef int (snd_config_string_replace_callback_t)(const char *what, char **dst, void *private_data);
|
typedef int (snd_config_string_replace_callback_t)(const char *what, char **dst, void *private_data);
|
||||||
|
|
||||||
int snd_config_string_replace(const char *src, char idchr,
|
int snd_config_refer_load(snd_config_t **dst, char **name,
|
||||||
snd_config_string_replace_callback_t *callback,
|
snd_config_t *root, snd_config_t *config);
|
||||||
void *private_data,
|
|
||||||
char **dst);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -266,7 +266,6 @@ int snd_card_type_string_to_enum(const char *strid, snd_card_type_t *enumid);
|
||||||
int snd_card_type_enum_to_string(snd_card_type_t enumid, char **strid);
|
int snd_card_type_enum_to_string(snd_card_type_t enumid, char **strid);
|
||||||
|
|
||||||
int snd_sctl_build(snd_sctl_t **ctl, snd_ctl_t *handle, snd_config_t *config,
|
int snd_sctl_build(snd_sctl_t **ctl, snd_ctl_t *handle, snd_config_t *config,
|
||||||
snd_config_string_replace_callback_t *callback,
|
|
||||||
void *private_data, int mode);
|
void *private_data, int mode);
|
||||||
int snd_sctl_free(snd_sctl_t *handle);
|
int snd_sctl_free(snd_sctl_t *handle);
|
||||||
int snd_sctl_install(snd_sctl_t *handle);
|
int snd_sctl_install(snd_sctl_t *handle);
|
||||||
|
|
|
||||||
256
src/alsa.conf
256
src/alsa.conf
|
|
@ -190,26 +190,27 @@ pcm.front {
|
||||||
default 0
|
default 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@func refer
|
refer {
|
||||||
file {
|
file {
|
||||||
@func concat
|
@func concat
|
||||||
strings [
|
strings [
|
||||||
{
|
{
|
||||||
@func datadir
|
@func datadir
|
||||||
}
|
}
|
||||||
"/cards/"
|
"/cards/"
|
||||||
{
|
{
|
||||||
@func card_strtype
|
@func card_strtype
|
||||||
card $CARD
|
card $CARD
|
||||||
}
|
}
|
||||||
".conf"
|
".conf"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
name {
|
name {
|
||||||
@func concat
|
@func concat
|
||||||
strings [
|
strings [
|
||||||
"pcm.front_" $DEV ":CARD=" $CARD
|
"pcm.front_" $DEV ":CARD=" $CARD
|
||||||
]
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -237,26 +238,27 @@ pcm.rear {
|
||||||
default 0
|
default 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@func refer
|
refer {
|
||||||
file {
|
file {
|
||||||
@func concat
|
@func concat
|
||||||
strings [
|
strings [
|
||||||
{
|
{
|
||||||
@func datadir
|
@func datadir
|
||||||
}
|
}
|
||||||
"/cards/"
|
"/cards/"
|
||||||
{
|
{
|
||||||
@func card_strtype
|
@func card_strtype
|
||||||
card $CARD
|
card $CARD
|
||||||
}
|
}
|
||||||
".conf"
|
".conf"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
name {
|
name {
|
||||||
@func concat
|
@func concat
|
||||||
strings [
|
strings [
|
||||||
"pcm.rear_" $DEV ":CARD=" $CARD
|
"pcm.rear_" $DEV ":CARD=" $CARD
|
||||||
]
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -284,26 +286,27 @@ pcm.center_lfe {
|
||||||
default 0
|
default 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@func refer
|
refer {
|
||||||
file {
|
file {
|
||||||
@func concat
|
@func concat
|
||||||
strings [
|
strings [
|
||||||
{
|
{
|
||||||
@func datadir
|
@func datadir
|
||||||
}
|
}
|
||||||
"/cards/"
|
"/cards/"
|
||||||
{
|
{
|
||||||
@func card_strtype
|
@func card_strtype
|
||||||
card $CARD
|
card $CARD
|
||||||
}
|
}
|
||||||
".conf"
|
".conf"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
name {
|
name {
|
||||||
@func concat
|
@func concat
|
||||||
strings [
|
strings [
|
||||||
"pcm.center_lfe_" $DEV ":CARD=" $CARD
|
"pcm.center_lfe_" $DEV ":CARD=" $CARD
|
||||||
]
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -331,26 +334,27 @@ pcm.surround40 {
|
||||||
default 0
|
default 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@func refer
|
refer {
|
||||||
file {
|
file {
|
||||||
@func concat
|
@func concat
|
||||||
strings [
|
strings [
|
||||||
{
|
{
|
||||||
@func datadir
|
@func datadir
|
||||||
}
|
}
|
||||||
"/cards/"
|
"/cards/"
|
||||||
{
|
{
|
||||||
@func card_strtype
|
@func card_strtype
|
||||||
card $CARD
|
card $CARD
|
||||||
}
|
}
|
||||||
".conf"
|
".conf"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
name {
|
name {
|
||||||
@func concat
|
@func concat
|
||||||
strings [
|
strings [
|
||||||
"pcm.surround40_" $DEV ":CARD=" $CARD
|
"pcm.surround40_" $DEV ":CARD=" $CARD
|
||||||
]
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -378,26 +382,27 @@ pcm.surround51 {
|
||||||
default 0
|
default 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@func refer
|
refer {
|
||||||
file {
|
file {
|
||||||
@func concat
|
@func concat
|
||||||
strings [
|
strings [
|
||||||
{
|
{
|
||||||
@func datadir
|
@func datadir
|
||||||
}
|
}
|
||||||
"/cards/"
|
"/cards/"
|
||||||
{
|
{
|
||||||
@func card_strtype
|
@func card_strtype
|
||||||
card $CARD
|
card $CARD
|
||||||
}
|
}
|
||||||
".conf"
|
".conf"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
name {
|
name {
|
||||||
@func concat
|
@func concat
|
||||||
strings [
|
strings [
|
||||||
"pcm.surround51_" $DEV ":CARD=" $CARD
|
"pcm.surround51_" $DEV ":CARD=" $CARD
|
||||||
]
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -445,31 +450,32 @@ pcm.iec958 {
|
||||||
# fs=48000Hz, clock accuracy=1000ppm
|
# fs=48000Hz, clock accuracy=1000ppm
|
||||||
default 0x02
|
default 0x02
|
||||||
}
|
}
|
||||||
@func refer
|
refer {
|
||||||
file {
|
file {
|
||||||
@func concat
|
@func concat
|
||||||
strings [
|
strings [
|
||||||
{
|
{
|
||||||
@func datadir
|
@func datadir
|
||||||
}
|
}
|
||||||
"/cards/"
|
"/cards/"
|
||||||
{
|
{
|
||||||
@func card_strtype
|
@func card_strtype
|
||||||
card $CARD
|
card $CARD
|
||||||
}
|
}
|
||||||
".conf"
|
".conf"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
name {
|
name {
|
||||||
@func concat
|
@func concat
|
||||||
strings [
|
strings [
|
||||||
"pcm.iec958_" $DEV ":"
|
"pcm.iec958_" $DEV ":"
|
||||||
"CARD=" $CARD ","
|
"CARD=" $CARD ","
|
||||||
"AES0=" $AES0 ","
|
"AES0=" $AES0 ","
|
||||||
"AES1=" $AES1 ","
|
"AES1=" $AES1 ","
|
||||||
"AES2=" $AES2 ","
|
"AES2=" $AES2 ","
|
||||||
"AES3=" $AES3
|
"AES3=" $AES3
|
||||||
]
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@ pcm.emu10k1_rear {
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name "EMU10K1 PCM Send Volume"
|
name "EMU10K1 PCM Send Volume"
|
||||||
index = &(subdevice)
|
index { @func private_pcm_subdevice }
|
||||||
lock true
|
lock true
|
||||||
value [ 0 0 0 0 0 0 255 0 0 0 0 255 ]
|
value [ 0 0 0 0 0 0 255 0 0 0 0 255 ]
|
||||||
}
|
}
|
||||||
|
|
@ -118,13 +118,13 @@ pcm.emu10k1_center_lfe {
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name "EMU10K1 PCM Send Volume"
|
name "EMU10K1 PCM Send Volume"
|
||||||
index = &(subdevice)
|
index { @func private_pcm_subdevice }
|
||||||
lock true
|
lock true
|
||||||
value [ 0 0 0 0 255 0 0 0 0 255 0 0 ]
|
value [ 0 0 0 0 255 0 0 0 0 255 0 0 ]
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name "EMU10K1 PCM Send Routing"
|
name "EMU10K1 PCM Send Routing"
|
||||||
index = &(subdevice)
|
index { @func private_pcm_subdevice }
|
||||||
lock true
|
lock true
|
||||||
value [ 0 1 2 3 6 7 0 1 6 7 0 1 ]
|
value [ 0 1 2 3 6 7 0 1 6 7 0 1 ]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ pcm.si7018_rear {
|
||||||
name "PCM Playback Volume"
|
name "PCM Playback Volume"
|
||||||
preserve true
|
preserve true
|
||||||
lock true
|
lock true
|
||||||
|
index { @func private_pcm_subdevice }
|
||||||
value [ 24 24 ]
|
value [ 24 24 ]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -56,21 +56,21 @@ pcm.trid4dwavenx_rear {
|
||||||
hook_args [
|
hook_args [
|
||||||
{
|
{
|
||||||
name "Rear Path"
|
name "Rear Path"
|
||||||
index &(subdevice)
|
index { @func private_pcm_subdevice }
|
||||||
lock true
|
lock true
|
||||||
preserve true
|
preserve true
|
||||||
value true
|
value true
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name "PCM Front Playback Volume"
|
name "PCM Front Playback Volume"
|
||||||
index &(subdevice)
|
index { @func private_pcm_subdevice }
|
||||||
lock true
|
lock true
|
||||||
preserve true
|
preserve true
|
||||||
value [ 0 0 ]
|
value [ 0 0 ]
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
name "PCM Reverb Playback Volume"
|
name "PCM Reverb Playback Volume"
|
||||||
index &(subdevice)
|
index { @func private_pcm_subdevice }
|
||||||
lock true
|
lock true
|
||||||
preserve true
|
preserve true
|
||||||
value [ 127 127 ]
|
value [ 127 127 ]
|
||||||
|
|
|
||||||
170
src/confmisc.c
170
src/confmisc.c
|
|
@ -140,71 +140,89 @@ int snd_config_get_ctl_iface(snd_config_t *conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Expand the dynamic contents
|
* \brief Refer the configuration block to another
|
||||||
* \param src Source string
|
* \param dst new configuration block (if *dst != root -> dst needs to be deleted)
|
||||||
* \param idchr Identification character
|
* \param name the identifier of new configuration block
|
||||||
* \param callback Callback function
|
* \param root the root of all configurations
|
||||||
* \param private_data Private data for the given callback function
|
* \param config redirect configuration
|
||||||
* \param dst Destination string
|
|
||||||
*/
|
*/
|
||||||
int snd_config_string_replace(const char *src, char idchr,
|
int snd_config_refer_load(snd_config_t **dst,
|
||||||
snd_config_string_replace_callback_t *callback,
|
char **name,
|
||||||
void *private_data,
|
snd_config_t *root,
|
||||||
char **dst)
|
snd_config_t *config)
|
||||||
{
|
{
|
||||||
int len = 0, len1, err;
|
int err;
|
||||||
const char *ptr, *end;
|
snd_config_t *result, *c;
|
||||||
char *tmp, *what, *fptr, *rdst = NULL;
|
char *rname;
|
||||||
|
|
||||||
assert(src && idchr && dst);
|
assert(dst);
|
||||||
while (*src != '\0') {
|
assert(name);
|
||||||
ptr = strchr(src, idchr);
|
assert(root);
|
||||||
end = NULL;
|
assert(config);
|
||||||
if (ptr == src && *(ptr + 1) == '(' && (end = strchr(ptr + 2, ')')) != NULL) {
|
if (snd_config_get_type(config) == SND_CONFIG_TYPE_STRING) {
|
||||||
src = end + 1;
|
const char *str;
|
||||||
if (callback == NULL)
|
snd_config_get_string(config, &str);
|
||||||
continue;
|
*name = strdup(str);
|
||||||
len1 = end - (ptr + 2);
|
if (*name == NULL)
|
||||||
if (len1 == 0) /* empty */
|
|
||||||
continue;
|
|
||||||
what = malloc(len1 + 1);
|
|
||||||
memcpy(what, ptr + 2, len1);
|
|
||||||
what[len1] = '\0';
|
|
||||||
fptr = NULL;
|
|
||||||
err = callback(what, &fptr, private_data);
|
|
||||||
free(what);
|
|
||||||
if (err < 0) {
|
|
||||||
if (*dst != NULL)
|
|
||||||
free(*dst);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
if (fptr == NULL) /* empty */
|
|
||||||
continue;
|
|
||||||
len1 = strlen(ptr = fptr);
|
|
||||||
} else {
|
|
||||||
if (ptr == NULL) {
|
|
||||||
len1 = strlen(ptr = src);
|
|
||||||
} else {
|
|
||||||
len1 = ptr - src;
|
|
||||||
ptr = src;
|
|
||||||
}
|
|
||||||
src += len1;
|
|
||||||
fptr = NULL;
|
|
||||||
}
|
|
||||||
tmp = realloc(rdst, len + len1 + 1);
|
|
||||||
if (tmp == NULL) {
|
|
||||||
if (*dst != NULL)
|
|
||||||
free(*dst);
|
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
*dst = root;
|
||||||
memcpy(tmp + len, ptr, len1);
|
return 0;
|
||||||
tmp[len+=len1] = '\0';
|
|
||||||
if (fptr)
|
|
||||||
free(fptr);
|
|
||||||
rdst = tmp;
|
|
||||||
}
|
}
|
||||||
*dst = rdst;
|
if (snd_config_get_type(config) != SND_CONFIG_TYPE_COMPOUND)
|
||||||
|
return -EINVAL;
|
||||||
|
result = root;
|
||||||
|
rname = NULL;
|
||||||
|
if (snd_config_search(config, "file", &c) >= 0) {
|
||||||
|
snd_config_t *rconfig;
|
||||||
|
const char *filename;
|
||||||
|
snd_input_t *input;
|
||||||
|
err = snd_config_copy(&rconfig, root);
|
||||||
|
if (err < 0)
|
||||||
|
return err;
|
||||||
|
if (snd_config_get_type(c) == SND_CONFIG_TYPE_STRING) {
|
||||||
|
snd_config_get_string(c, &filename);
|
||||||
|
} else {
|
||||||
|
err = -EINVAL;
|
||||||
|
__filename_error:
|
||||||
|
snd_config_delete(rconfig);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
err = snd_input_stdio_open(&input, filename, "r");
|
||||||
|
if (err < 0) {
|
||||||
|
SNDERR("Unable to open filename %s: %s", filename, snd_strerror(err));
|
||||||
|
goto __filename_error;
|
||||||
|
}
|
||||||
|
err = snd_config_load(rconfig, input);
|
||||||
|
if (err < 0) {
|
||||||
|
snd_input_close(input);
|
||||||
|
goto __filename_error;
|
||||||
|
}
|
||||||
|
snd_input_close(input);
|
||||||
|
result = rconfig;
|
||||||
|
}
|
||||||
|
if (snd_config_search(config, "name", &c) >= 0) {
|
||||||
|
const char *ptr;
|
||||||
|
if ((err = snd_config_get_string(c, &ptr)) < 0)
|
||||||
|
goto __error;
|
||||||
|
rname = strdup(ptr);
|
||||||
|
if (rname == NULL) {
|
||||||
|
err = -ENOMEM;
|
||||||
|
goto __error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (rname == NULL) {
|
||||||
|
err = -EINVAL;
|
||||||
|
goto __error;
|
||||||
|
}
|
||||||
|
*dst = result;
|
||||||
|
*name = rname;
|
||||||
return 0;
|
return 0;
|
||||||
|
__error:
|
||||||
|
if (rname)
|
||||||
|
free(rname);
|
||||||
|
if (result != root)
|
||||||
|
snd_config_delete(result);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -315,7 +333,6 @@ int snd_func_igetenv(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int snd_func_concat(snd_config_t **dst, snd_config_t *root, snd_config_t *src, void *private_data)
|
int snd_func_concat(snd_config_t **dst, snd_config_t *root, snd_config_t *src, void *private_data)
|
||||||
{
|
{
|
||||||
snd_config_t *n;
|
snd_config_t *n;
|
||||||
|
|
@ -514,7 +531,6 @@ int snd_func_card_id(snd_config_t **dst, snd_config_t *root, snd_config_t *src,
|
||||||
int snd_func_pcm_id(snd_config_t **dst, snd_config_t *root, snd_config_t *src, void *private_data)
|
int snd_func_pcm_id(snd_config_t **dst, snd_config_t *root, snd_config_t *src, void *private_data)
|
||||||
{
|
{
|
||||||
snd_config_t *n;
|
snd_config_t *n;
|
||||||
char *res = NULL;
|
|
||||||
snd_ctl_t *ctl = NULL;
|
snd_ctl_t *ctl = NULL;
|
||||||
snd_pcm_info_t *info;
|
snd_pcm_info_t *info;
|
||||||
long card, device, subdevice = 0;
|
long card, device, subdevice = 0;
|
||||||
|
|
@ -575,21 +591,39 @@ int snd_func_pcm_id(snd_config_t **dst, snd_config_t *root, snd_config_t *src, v
|
||||||
SNDERR("snd_ctl_pcm_info error: %s", snd_strerror(err));
|
SNDERR("snd_ctl_pcm_info error: %s", snd_strerror(err));
|
||||||
goto __error;
|
goto __error;
|
||||||
}
|
}
|
||||||
res = strdup(snd_pcm_info_get_id(info));
|
|
||||||
if (res == NULL) {
|
|
||||||
err = -ENOMEM;
|
|
||||||
goto __error;
|
|
||||||
}
|
|
||||||
err = snd_config_make_string(dst, snd_config_get_id(src));
|
err = snd_config_make_string(dst, snd_config_get_id(src));
|
||||||
if (err >= 0)
|
if (err >= 0)
|
||||||
err = snd_config_set_string(*dst, res);
|
err = snd_config_set_string(*dst, snd_pcm_info_get_id(info));
|
||||||
free(res);
|
|
||||||
__error:
|
__error:
|
||||||
if (ctl)
|
if (ctl)
|
||||||
snd_ctl_close(ctl);
|
snd_ctl_close(ctl);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int snd_func_private_pcm_subdevice(snd_config_t **dst, snd_config_t *root ATTRIBUTE_UNUSED, snd_config_t *src, void *private_data)
|
||||||
|
{
|
||||||
|
char *res = NULL;
|
||||||
|
snd_pcm_info_t *info;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
if (private_data == NULL)
|
||||||
|
return snd_config_copy(dst, src);
|
||||||
|
snd_pcm_info_alloca(&info);
|
||||||
|
err = snd_pcm_info((snd_pcm_t *)private_data, info);
|
||||||
|
if (err < 0) {
|
||||||
|
SNDERR("snd_ctl_pcm_info error: %s", snd_strerror(err));
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
res = strdup(snd_pcm_info_get_id(info));
|
||||||
|
if (res == NULL)
|
||||||
|
return -ENOMEM;
|
||||||
|
err = snd_config_make_integer(dst, snd_config_get_id(src));
|
||||||
|
if (err >= 0)
|
||||||
|
err = snd_config_set_integer(*dst, snd_pcm_info_get_subdevice(info));
|
||||||
|
free(res);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
int snd_func_refer(snd_config_t **dst, snd_config_t *_root, snd_config_t *src, void *private_data)
|
int snd_func_refer(snd_config_t **dst, snd_config_t *_root, snd_config_t *src, void *private_data)
|
||||||
{
|
{
|
||||||
snd_config_t *n;
|
snd_config_t *n;
|
||||||
|
|
|
||||||
|
|
@ -371,74 +371,13 @@ static int snd_config_get_ctl_elem_value(snd_config_t *conf,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int config_replace(snd_config_t *conf,
|
static int add_elem(snd_sctl_t *h, snd_config_t *_conf, void *private_data)
|
||||||
snd_config_string_replace_callback_t *callback,
|
|
||||||
void *private_data, char **res)
|
|
||||||
{
|
|
||||||
int err;
|
|
||||||
char *replace, *tmp;
|
|
||||||
|
|
||||||
err = snd_config_get_ascii(conf, &tmp);
|
|
||||||
if (err < 0)
|
|
||||||
return err;
|
|
||||||
err = snd_config_string_replace(tmp, '&', callback, private_data, &replace);
|
|
||||||
free(tmp);
|
|
||||||
if (err < 0)
|
|
||||||
return err;
|
|
||||||
if (replace == NULL) {
|
|
||||||
SNDERR("Invalid value for '%s'", snd_config_get_id(conf));
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
*res = replace;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int config_replace_integer(snd_config_t *conf,
|
|
||||||
snd_config_string_replace_callback_t *callback,
|
|
||||||
void *private_data, long *res)
|
|
||||||
{
|
|
||||||
char *tmp;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err = config_replace(conf, callback, private_data, &tmp);
|
|
||||||
if (err < 0)
|
|
||||||
return err;
|
|
||||||
err = safe_strtol(tmp, res);
|
|
||||||
if (err < 0) {
|
|
||||||
SNDERR("Invalid value for '%s'", snd_config_get_id(conf));
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int config_replace_bool(snd_config_t *conf,
|
|
||||||
snd_config_string_replace_callback_t *callback,
|
|
||||||
void *private_data, int *res)
|
|
||||||
{
|
|
||||||
char *tmp;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err = config_replace(conf, callback, private_data, &tmp);
|
|
||||||
if (err < 0)
|
|
||||||
return err;
|
|
||||||
err = snd_config_get_bool_ascii(tmp);
|
|
||||||
free(tmp);
|
|
||||||
if (err < 0) {
|
|
||||||
SNDERR("Invalid value for '%s'", snd_config_get_id(conf));
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
*res = err;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int add_elem(snd_sctl_t *h, snd_config_t *conf,
|
|
||||||
snd_config_string_replace_callback_t *callback,
|
|
||||||
void *private_data)
|
|
||||||
{
|
{
|
||||||
|
snd_config_t *conf;
|
||||||
snd_config_iterator_t i, next;
|
snd_config_iterator_t i, next;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
int iface = SND_CTL_ELEM_IFACE_MIXER;
|
int iface = SND_CTL_ELEM_IFACE_MIXER;
|
||||||
char *name = NULL;
|
const char *name = NULL;
|
||||||
long index = 0;
|
long index = 0;
|
||||||
long device = -1;
|
long device = -1;
|
||||||
long subdevice = -1;
|
long subdevice = -1;
|
||||||
|
|
@ -447,50 +386,80 @@ static int add_elem(snd_sctl_t *h, snd_config_t *conf,
|
||||||
snd_config_t *value = NULL, *mask = NULL;
|
snd_config_t *value = NULL, *mask = NULL;
|
||||||
snd_sctl_elem_t *elem = NULL;
|
snd_sctl_elem_t *elem = NULL;
|
||||||
int err;
|
int err;
|
||||||
|
err = snd_config_expand(_conf, _conf, NULL, private_data, &conf);
|
||||||
|
if (err < 0)
|
||||||
|
return err;
|
||||||
snd_config_for_each(i, next, conf) {
|
snd_config_for_each(i, next, conf) {
|
||||||
snd_config_t *n = snd_config_iterator_entry(i);
|
snd_config_t *n = snd_config_iterator_entry(i);
|
||||||
const char *id = snd_config_get_id(n);
|
const char *id = snd_config_get_id(n);
|
||||||
if (strcmp(id, "comment") == 0)
|
if (strcmp(id, "comment") == 0)
|
||||||
continue;
|
continue;
|
||||||
if (strcmp(id, "iface") == 0 || strcmp(id, "interface") == 0) {
|
if (strcmp(id, "iface") == 0 || strcmp(id, "interface") == 0) {
|
||||||
if ((err = config_replace(n, callback, private_data, &tmp)) < 0)
|
const char *ptr;
|
||||||
|
if ((err = snd_config_get_string(n, &ptr)) < 0) {
|
||||||
|
SNDERR("field %s is not a string", id);
|
||||||
goto _err;
|
goto _err;
|
||||||
if ((err = snd_config_get_ctl_iface_ascii(tmp)) < 0) {
|
}
|
||||||
|
if ((err = snd_config_get_ctl_iface_ascii(ptr)) < 0) {
|
||||||
SNDERR("Invalid value for '%s'", id);
|
SNDERR("Invalid value for '%s'", id);
|
||||||
free(tmp);
|
free(tmp);
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
iface = err;
|
iface = err;
|
||||||
free(tmp);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp(id, "name") == 0) {
|
if (strcmp(id, "name") == 0) {
|
||||||
if ((err = config_replace(n, callback, private_data, &name)) < 0)
|
if ((err = snd_config_get_string(n, &name)) < 0) {
|
||||||
|
SNDERR("field %s is not a string", id);
|
||||||
goto _err;
|
goto _err;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp(id, "index") == 0) {
|
if (strcmp(id, "index") == 0) {
|
||||||
if ((err = config_replace_integer(n, callback, private_data, &index)) < 0)
|
if ((err = snd_config_get_integer(n, &index)) < 0) {
|
||||||
|
SNDERR("field %s is not an integer", id);
|
||||||
goto _err;
|
goto _err;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp(id, "device") == 0) {
|
if (strcmp(id, "device") == 0) {
|
||||||
if ((err = config_replace_integer(n, callback, private_data, &device)) < 0)
|
if ((err = snd_config_get_integer(n, &device)) < 0) {
|
||||||
|
SNDERR("field %s is not an integer", id);
|
||||||
goto _err;
|
goto _err;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp(id, "subdevice") == 0) {
|
if (strcmp(id, "subdevice") == 0) {
|
||||||
if ((err = config_replace_integer(n, callback, private_data, &subdevice)) < 0)
|
if ((err = snd_config_get_integer(n, &subdevice)) < 0) {
|
||||||
|
SNDERR("field %s is not an integer", id);
|
||||||
goto _err;
|
goto _err;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp(id, "lock") == 0) {
|
if (strcmp(id, "lock") == 0) {
|
||||||
if ((err = config_replace_bool(n, callback, private_data, &lock)) < 0)
|
if ((err = snd_config_get_ascii(n, &tmp)) < 0) {
|
||||||
|
SNDERR("field %s has an invalid type", id);
|
||||||
goto _err;
|
goto _err;
|
||||||
|
}
|
||||||
|
err = snd_config_get_bool_ascii(tmp);
|
||||||
|
if (err < 0) {
|
||||||
|
SNDERR("field %s is not a boolean", id);
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
lock = err;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp(id, "preserve") == 0) {
|
if (strcmp(id, "preserve") == 0) {
|
||||||
if ((err = config_replace_bool(n, callback, private_data, &preserve)) < 0)
|
if ((err = snd_config_get_ascii(n, &tmp)) < 0) {
|
||||||
|
SNDERR("field %s has an invalid type", id);
|
||||||
goto _err;
|
goto _err;
|
||||||
|
}
|
||||||
|
err = snd_config_get_bool_ascii(tmp);
|
||||||
|
if (err < 0) {
|
||||||
|
SNDERR("field %s is not a boolean", id);
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
preserve = err;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (strcmp(id, "value") == 0) {
|
if (strcmp(id, "value") == 0) {
|
||||||
|
|
@ -568,12 +537,9 @@ static int add_elem(snd_sctl_t *h, snd_config_t *conf,
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
goto _err;
|
goto _err;
|
||||||
list_add_tail(&elem->list, &h->elems);
|
list_add_tail(&elem->list, &h->elems);
|
||||||
return 0;
|
|
||||||
|
|
||||||
_err:
|
_err:
|
||||||
if (name)
|
if (err < 0 && elem) {
|
||||||
free(name);
|
|
||||||
if (elem) {
|
|
||||||
if (elem->id)
|
if (elem->id)
|
||||||
snd_ctl_elem_id_free(elem->id);
|
snd_ctl_elem_id_free(elem->id);
|
||||||
if (elem->info)
|
if (elem->info)
|
||||||
|
|
@ -586,13 +552,12 @@ static int add_elem(snd_sctl_t *h, snd_config_t *conf,
|
||||||
snd_ctl_elem_value_free(elem->old);
|
snd_ctl_elem_value_free(elem->old);
|
||||||
free(elem);
|
free(elem);
|
||||||
}
|
}
|
||||||
|
if (conf)
|
||||||
|
snd_config_delete(conf);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
int snd_sctl_build(snd_sctl_t **sctl, snd_ctl_t *handle, snd_config_t *conf,
|
int snd_sctl_build(snd_sctl_t **sctl, snd_ctl_t *handle, snd_config_t *conf, void *private_data, int mode)
|
||||||
snd_config_string_replace_callback_t *callback,
|
|
||||||
void *private_data,
|
|
||||||
int mode)
|
|
||||||
{
|
{
|
||||||
snd_sctl_t *h;
|
snd_sctl_t *h;
|
||||||
snd_config_iterator_t i, next;
|
snd_config_iterator_t i, next;
|
||||||
|
|
@ -615,7 +580,7 @@ int snd_sctl_build(snd_sctl_t **sctl, snd_ctl_t *handle, snd_config_t *conf,
|
||||||
INIT_LIST_HEAD(&h->elems);
|
INIT_LIST_HEAD(&h->elems);
|
||||||
snd_config_for_each(i, next, conf) {
|
snd_config_for_each(i, next, conf) {
|
||||||
snd_config_t *n = snd_config_iterator_entry(i);
|
snd_config_t *n = snd_config_iterator_entry(i);
|
||||||
err = add_elem(h, n, callback, private_data);
|
err = add_elem(h, n, private_data);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
free_elems(h);
|
free_elems(h);
|
||||||
return err;
|
return err;
|
||||||
|
|
|
||||||
|
|
@ -1001,12 +1001,25 @@ static int snd_pcm_open_noupdate(snd_pcm_t **pcmp, snd_config_t *root,
|
||||||
const char *name, snd_pcm_stream_t stream, int mode)
|
const char *name, snd_pcm_stream_t stream, int mode)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
snd_config_t *pcm_conf;
|
snd_config_t *pcm_conf, *n;
|
||||||
err = snd_config_search_definition(root, "pcm", name, &pcm_conf);
|
err = snd_config_search_definition(root, "pcm", name, &pcm_conf);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
SNDERR("Unknown PCM %s", name);
|
SNDERR("Unknown PCM %s", name);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
if (snd_config_search(pcm_conf, "refer", &n) >= 0) {
|
||||||
|
snd_config_t *refer;
|
||||||
|
char *new_name;
|
||||||
|
err = snd_config_refer_load(&refer, &new_name, root, n);
|
||||||
|
if (err < 0) {
|
||||||
|
SNDERR("Unable to load refered block in PCM %s: %s", name, snd_strerror(err));
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
err = snd_pcm_open_noupdate(pcmp, refer, new_name, stream, mode);
|
||||||
|
if (refer != root)
|
||||||
|
snd_config_delete(refer);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
err = snd_pcm_open_conf(pcmp, name, root, pcm_conf, stream, mode);
|
err = snd_pcm_open_conf(pcmp, name, root, pcm_conf, stream, mode);
|
||||||
snd_config_delete(pcm_conf);
|
snd_config_delete(pcm_conf);
|
||||||
return err;
|
return err;
|
||||||
|
|
|
||||||
|
|
@ -606,32 +606,6 @@ static int snd_pcm_hook_ctl_elems_close(snd_pcm_hook_t *hook)
|
||||||
return err;
|
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 _snd_pcm_hook_ctl_elems_install(snd_pcm_t *pcm, snd_config_t *conf)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
|
|
@ -658,7 +632,7 @@ int _snd_pcm_hook_ctl_elems_install(snd_pcm_t *pcm, snd_config_t *conf)
|
||||||
SNDERR("Cannot open CTL %s", ctl_name);
|
SNDERR("Cannot open CTL %s", ctl_name);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
err = snd_sctl_build(&sctl, ctl, conf, snd_pcm_hook_ctl_elems_replace, pcm, 0);
|
err = snd_sctl_build(&sctl, ctl, conf, pcm, 0);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
err = snd_pcm_hook_add(&h_hw_params, pcm, SND_PCM_HOOK_TYPE_HW_PARAMS,
|
err = snd_pcm_hook_add(&h_hw_params, pcm, SND_PCM_HOOK_TYPE_HW_PARAMS,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue